Widgets: Porting of WP.com's EU Cookie Law Banner#6881
Conversation
zinigor
left a comment
There was a problem hiding this comment.
Overall this looks good, I see you have added textdomains for translations and namespaced functions. I have pointed out one minor thing, and have not yet tested the code. When you consider that the code is ready to test, feel free to remove the In Progress label and use the Needs Review label instead. One of the maintainers will test and review the code and will either assign a Ready to Merge label, or point out problems and put it back In Progress. In the former case the PR will be merged by another maintainer, in the latter you will need to make adjustments accordingly.
Thanks for doing this, we really appreciate the help! :)
modules/widgets/eu-cookie-law.php
Outdated
|
|
||
| do_action( 'jetpack_stats_extra', 'widget_view', 'eu_cookie_law' ); | ||
|
|
||
| echo 'CIAO'; |
There was a problem hiding this comment.
I'm pretty sure that's not supposed to be here :)
There was a problem hiding this comment.
That's totally required by EU laws!
|
@zinigor thanks for giving a look! |
| _e( 'To find out more, as well as how to remove or block these, see here:', 'jetpack' ); | ||
| echo ' '; | ||
| } else { | ||
| echo esc_html( $instance['customtext'] ), ' '; |
There was a problem hiding this comment.
One thing that I notice is that you should put ,' ' in the brackets, and you should replace the empty space with jetpack textdomain.
I started this this widget while ago, but I hadn't enough time to complete it. Feel free to use any codeblock you like master...Stoyan0v:add/eu-cookie-law-widget
| echo esc_html( $instance['customtext'] ), ' '; | ||
| } ?> | ||
|
|
||
| <a href="<?php echo esc_attr( |
There was a problem hiding this comment.
I think that using esc_url is better option here.
And also it will be nice if you move the logic outside of the esc_attr function.
jeherve
left a comment
There was a problem hiding this comment.
I left a few comments that should hopefully help a bit! Let me know if you have any questions.
modules/widgets/eu-cookie-law.php
Outdated
| function __construct() { | ||
| parent::__construct( | ||
| 'eu_cookie_law_widget', | ||
| apply_filters( 'jetpack_widget_name', esc_html__( 'EU Cookie Law Banner', 'jetpack' ) ), |
There was a problem hiding this comment.
All code in Jetpack is parsed after each release to build our codex:
http://developer.jetpack.com/
The codex references all actions and hooks in Jetpack, in order to help third-party developers who would like to customize Jetpack.
That means that you'll need to add docblocks for each one of the hooks you add in Jetpack. In this specific case, since the filter isn't new, this should do the trick:
/** This filter is documented in modules/widgets/facebook-likebox.php */
modules/widgets/eu-cookie-law.php
Outdated
| 'customtext' => '', | ||
| 'color-scheme' => 'default', | ||
| 'policy-url' => 'default', | ||
| 'default-policy-url' => 'https://en.support.wordpress.com/cookies', |
There was a problem hiding this comment.
Since Jetpack and WordPress.com use different cookies, you'll probably need to create a new support doc on jetpack.com for this widget.
modules/widgets/eu-cookie-law.php
Outdated
| 'custom-policy-url' => '', | ||
| 'policy-link-text' => __( 'Our Cookie Policy', 'jetpack' ), | ||
| 'button' => __( 'Close and accept', 'jetpack' ), | ||
| 'default-text' => __( 'Privacy & Cookies: This site uses cookies from WordPress.com and selected partners. ', 'jetpack' ), |
There was a problem hiding this comment.
Since this site is self-hosted, it doesn't use cookies from WordPress.com (at least not for logged out readers).
There was a problem hiding this comment.
All these should use the safest esc_html__
modules/widgets/eu-cookie-law.php
Outdated
| public function widget( $args, $instance ) { | ||
| $this->instance = wp_parse_args( $instance, $this->defaults ); | ||
|
|
||
| do_action( 'jetpack_stats_extra', 'widget_view', 'eu_cookie_law' ); |
There was a problem hiding this comment.
/** This action is already documented in modules/widgets/gravatar-profile.php */
modules/widgets/eu-cookie-law.php
Outdated
| require( dirname( __FILE__ ) . '/eu-cookie-law/footer.php' ); | ||
| } | ||
|
|
||
| public function form( $instance ) { |
There was a problem hiding this comment.
It would be a nice plus to add docblocks before each one of your functions. If you install phpcs, you'll see that it complains when no comments are added:
https://github.com/Automattic/jetpack/blob/master/docs/coding-guidelines.md#general
There was a problem hiding this comment.
I had to disable phpcs since it complained about the name of every class file. 😄
modules/widgets/eu-cookie-law.php
Outdated
| } | ||
|
|
||
| function enqueue_style() { | ||
| wp_enqueue_style( 'eu-cookie-law-style', plugins_url( 'eu-cookie-law/style.css', __FILE__ ), array(), '20170403' ); |
| </div> | ||
|
|
||
| <script type="text/javascript"> | ||
| jQuery( function( $ ) { |
There was a problem hiding this comment.
We rely on jQuery here, but we didn't make sure it was actually enqueued on the page before.
There was a problem hiding this comment.
I believe I should just enqueue this script and pass the values I need from PHP (cookie name and validity) in data attributes instead.
|
|
||
| <p class="small"> | ||
| <?php _e( 'It is your own responsibility to ensure that your site complies with the relevant laws.', 'jetpack' ); ?> | ||
| <a href=""> |
eliorivero
left a comment
There was a problem hiding this comment.
Hi @Copons, good work spearheading this!
In addition to the comments:
- the radio button to set a custom text can't be checked:
- the button label in dark color scheme isn't visible
- please introduce Selective Refresh support for this widgets like the other Jetpack widgets have
modules/widgets/eu-cookie-law.php
Outdated
| 'custom-policy-url' => '', | ||
| 'policy-link-text' => __( 'Our Cookie Policy', 'jetpack' ), | ||
| 'button' => __( 'Close and accept', 'jetpack' ), | ||
| 'default-text' => __( 'Privacy & Cookies: This site uses cookies from WordPress.com and selected partners. ', 'jetpack' ), |
There was a problem hiding this comment.
All these should use the safest esc_html__
modules/widgets/eu-cookie-law.php
Outdated
| 'custom-policy-url' => '', | ||
| 'policy-link-text' => __( 'Our Cookie Policy', 'jetpack' ), | ||
| 'button' => __( 'Close and accept', 'jetpack' ), | ||
| 'default-text' => __( 'Privacy & Cookies: This site uses cookies from WordPress.com and selected partners. ', 'jetpack' ), |
There was a problem hiding this comment.
There's a space at the end of the translatable string.
| ?> | ||
| <br /> | ||
| <?php | ||
| _e( 'To find out more, as well as how to remove or block these, see here:', 'jetpack' ); |
There was a problem hiding this comment.
This and all similar cases could use the safest esc_html_e
| } | ||
|
|
||
| var expireTime = new Date(); | ||
| expireTime.setTime( expireTime.getTime() + <?php echo $cookie_validity * 1000; ?> ); |
| var expireTime = new Date(); | ||
| expireTime.setTime( expireTime.getTime() + <?php echo $cookie_validity * 1000; ?> ); | ||
|
|
||
| document.cookie = '<?php echo $cookie_name; ?>=' + expireTime.getTime() + ';path=/;expires=' + expireTime.toGMTString(); |
| @@ -0,0 +1,195 @@ | |||
| <p> | |||
| <strong> | |||
| <?php echo _x( 'Hide the banner', 'action', 'jetpack' ); ?> | |||
| </ul> | ||
| <textarea | ||
| class="widefat" | ||
| name="<?php echo $this->get_field_name( 'text' ); ?>" |
There was a problem hiding this comment.
Needs esc_attr like it's done right below in the placeholder attribute.
| <label> | ||
| <input | ||
| <?php checked( $instance['hide'], 'button' ); ?> | ||
| name="<?php echo $this->get_field_name( 'hide' ); ?>" |
There was a problem hiding this comment.
This and other similar cases need esc_attr.
|
Thanks @eliorivero! I didn't expect such a thorough review on an in-progress PR. |
|
@eliorivero The various bugs on custom texts should be fixed but I cannot reproduce the dark color scheme button: May I ask you what browser/OS you're using? |
|
@jeherve I've discovered that there already is a Cookies policy page in JP, so I've simply replaced the old link with this one. Related to this, I've removed the WP.com mention in the default banner text. Unfortunately, it becomes very short and ugly, but that's an easily fixable copy issue. |
|
@Copons looking great! Sorry I forgot to mention this the first time: I got the white text on light grey button using TwentyTwelve theme. Chrome on El Capitan. Same thing happens in Firefox. |
|
@eliorivero Thanks! Going to look into it. |
|
@eliorivero It was a problem with Twenty Twelve styles that used |
|
@sirbrillig At some point I got the same issue you're mentioning here, don't remember on what theme but likely on Twenty Seventeen, so this might be the solution for your problem. I gave it a quick look at Twenty Thirteen and I'd say that the problem there is that the footer area (called "Main Widget Area") is laid out via Masonry that adds an inline |
|
oh! You're right about the home page sidebar! Good thinking. As for Twenty Thirteen, yeah, I don't have any good ideas. In any case it's the same as dotcom. |
|
@zinigor @jeherve @eliorivero anything else needed here? We're hoping to get it in for deadline next Tues, thanks! |
|
@kwight If you've reviewed and tested it, and are happy with it, do not hesitate to approve the PR. Someone else from Pit Crew will come along and test it again as well so it can be merged. |
kwight
left a comment
There was a problem hiding this comment.
Checked form radio buttons, color scheme, overriding default texts, all looks good and ready to merge 👍
dereksmart
left a comment
There was a problem hiding this comment.
Other than the missing link, this looks good and tests well!
|
|
||
| <p class="small"> | ||
| <?php esc_html_e( 'It is your own responsibility to ensure that your site complies with the relevant laws.', 'jetpack' ); ?> | ||
| <a href=""> |
|
@dereksmart Damn! I totally forgot about it. On .com this is a link to a support page. |
|
Works fine! |
* Changelog: initial commit for 4.9 release. * Changelog: add #6929 * Changelog: move old changelogs to changelog.txt * Readme: restore deleted release post link. The post is now live. * Changelog: add #6853 * Changelog: add #6856 * Changelog: add #6857 * Changelog: add #6884 * Changelog: add #6885 * Changelog: add #6892 * Changelog: add #6894 * Changelog: add #6898 * Changelog: add #6899 * Changelog: add #6900 * Changelog: add #6909 * Changelog: add #6927 * Changelog: add #6947 * Chagelog: add #6958 * Changelog: add #6961 * Changelog: add #6963 * Changelog: add #6965 * Changelog: add #6986 * Changelog: add #7000 * Changelog: add #7013 * Changelog: add #7015 * Changelog: add #7019 * Changelog: add #7028 * Changelog: add #6998 * Changelog: add #6999 * Changelog: add #7044 * Changelog: add #6881 * Changelog: add #6922 * Changelog: add #6940 * Changelog: add #6962 * Changelog: add #6942 * Changelog: add #6959 * Changelog: add #7018 * Changelog: add #6948 * Changelog: add #6657 * Changelog: add #7030 * Changelog: add #7048 * Changelog: add #7031 * Changelog: add #6990 * Changelog: add #6957 * Changelog: add #7027






This is my first PR in the effort of filling the gaps between Jetpack and WP.com, to smooth the AT process out.
I'm not completely sure about the Jetpack coding standards (file, classes and variables naming conventions, documentation) as apparently different widgets have different standards, so if you have any suggestions I'll be happy to implement them ASAP.
Changes proposed in this Pull Request:
Testing instructions: