Add new Social Icons widget and deprecate old Social Media Icons widget#7454
Add new Social Icons widget and deprecate old Social Media Icons widget#7454thomasguillot wants to merge 772 commits intomasterfrom
Conversation
|
Working on a review now. CircleCI was removed -- do we have a good way to rerun it without? We'll likely also need to |
modules/widgets/social-icons.php
Outdated
| public function __construct() { | ||
| $widget_ops = array( | ||
| 'classname' => 'jetpack_widget_social_icons', | ||
| 'description' => esc_html__( 'Add social-media icons to your site.', 'jetpack' ), |
There was a problem hiding this comment.
Could we be escaping too early here? Would this string get escaped when actually used?
I'm concerned both with double escaping, and wrong-context escaping, if it's later used in an attribute and then gets re-escaped for that.
modules/widgets/social-icons.php
Outdated
| 'customize_selective_refresh' => true, | ||
| ); | ||
|
|
||
| parent::__construct( 'jetpack_widget_social_icons', esc_html__( 'Social Icons', 'jetpack' ), $widget_ops ); |
There was a problem hiding this comment.
Could we be escaping too early here? Would this string get escaped when actually used?
I'm concerned both with double escaping, and wrong-context escaping, if it's later used in an attribute and then gets re-escaped for that.
modules/widgets/social-icons.php
Outdated
| parent::__construct( 'jetpack_widget_social_icons', esc_html__( 'Social Icons', 'jetpack' ), $widget_ops ); | ||
|
|
||
| $this->defaults = array( | ||
| 'title' => esc_html__( 'Follow Us', 'jetpack' ), |
There was a problem hiding this comment.
Could we be escaping too early here?
modules/widgets/social-icons.php
Outdated
| add_action( 'admin_enqueue_scripts', array( $this, 'enqueue_admin_scripts' ) ); | ||
| add_action( 'admin_print_footer_scripts', array( $this, 'render_admin_js' ) ); | ||
| add_action( 'wp_enqueue_scripts', array( $this, 'enqueue_icon_scripts' ) ); | ||
| add_action( 'wp_footer', array( $this, 'jetpack_social_menu_include_svg_icons' ), 9999 ); |
There was a problem hiding this comment.
This looks bad.
Wouldn't this result in the SVGs printing on every wp_footer regardless of whether or not the widget is ever actually used, let alone used on that page (due to either multiple sidebars or widget visibility)?
modules/widgets/social-icons.php
Outdated
| * Script & styles for admin widget form. | ||
| */ | ||
| public function enqueue_admin_scripts() { | ||
| wp_enqueue_script( 'jetpack-widget-social-icons-script', plugins_url( 'social-icons/social-icons-admin.js', __FILE__ ), array( 'jquery-ui-sortable' ), '20170506' ); |
There was a problem hiding this comment.
Wouldn't this enqueue these scripts for every admin page, including like ... post-new.php?
modules/widgets/social-icons.php
Outdated
| $icon_count = count( $new_instance['url-icons'] ); | ||
| $instance['icons'] = array(); | ||
|
|
||
| for ( $i = 0; $i < $icon_count; $i++ ) { |
There was a problem hiding this comment.
Why is this a for instead of a foreach?
modules/widgets/social-icons.php
Outdated
| * @return string|void | ||
| */ | ||
| public function form( $instance ) { | ||
| $instance = wp_parse_args( (array) $instance, $this->defaults ); |
There was a problem hiding this comment.
Again, why cast to an array? wp_parse_args is designed to accept arg=val&arg2=val2 and the like. This would break that.
modules/widgets/social-icons.php
Outdated
| $instance = wp_parse_args( (array) $instance, $this->defaults ); | ||
| $title = sanitize_text_field( $instance['title'] ); | ||
| $sizes = array( | ||
| 'small' => esc_html__( 'Small', 'jetpack' ), |
There was a problem hiding this comment.
I think we're escaping this too early, potentially double escaping.
modules/widgets/social-icons.php
Outdated
| </p> | ||
|
|
||
| <?php | ||
| $support = 'https://en.support.wordpress.com/widgets/social-media-icons-widget/#available-icons'; |
There was a problem hiding this comment.
Should this maybe be a switch statement instead?
| <?php | ||
| } | ||
|
|
||
| /** |
There was a problem hiding this comment.
Note to self: This is as far as I got in my review, pick up from here later tonight.
|
|
||
| <p class="jetpack-widget-social-icons-remove-item"> | ||
| <a class="jetpack-widget-social-icons-remove-item-button" href="javascript:;"> | ||
| <?php esc_html_e( 'Remove', 'jetpack' ); ?> |
There was a problem hiding this comment.
This may need a translator note?
modules/widgets/social-icons.php
Outdated
| * @access public | ||
| * @return void | ||
| */ | ||
| function jetpack_widget_social_icons_load() { |
There was a problem hiding this comment.
This could be a static method in the actual class, instead of being in the global namespace, but either way. Not really a blocker, just a thought.
modules/widgets/social-icons.php
Outdated
| } | ||
| add_action( 'widgets_init', 'jetpack_widget_social_icons_load' ); | ||
|
|
||
| if ( ! function_exists( 'jetpack_social_menu_get_svg' ) ) : |
There was a problem hiding this comment.
Why is this in a function_exists? Do we have an alternate version wpcom side or the like?
modules/widgets/social-icons.php
Outdated
| function jetpack_social_menu_get_svg( $args = array() ) { | ||
| // Make sure $args are an array. | ||
| if ( empty( $args ) ) { | ||
| return esc_html__( 'Please define default parameters in the form of an array.', 'jetpack' ); |
There was a problem hiding this comment.
Should this maybe be an error_log instead of printing on the front end? Unsure.
modules/widgets/social-icons.php
Outdated
| $svg = '<svg class="icon icon-' . esc_attr( $args['icon'] ) . '"' . $aria_hidden . ' role="img">'; | ||
|
|
||
| /* | ||
| * Display the icon. |
There was a problem hiding this comment.
Note: So this just prints a reference to the icon that is elsewhere in the DOM. Doesn't read the file in or anything.
| font: 400 20px/1 dashicons; | ||
| vertical-align: middle; | ||
| -webkit-transition: all .2s; | ||
| transition: all .2s; |
There was a problem hiding this comment.
Missing leading zero on the .2s
|
|
||
| // Live preview update. | ||
| function livePreviewUpdate( button ) { | ||
| if ( ! $( 'body' ).hasClass( 'wp-customizer' ) || ! button.length ) { |
There was a problem hiding this comment.
May be more efficient to use document.body or -- if jQuery is needed -- $( document.body ) instead of passing in a string element selector? Unsure if jQuery has some optimization behind the scenes for this already.
| } ); | ||
|
|
||
| // Event handler for widget open button. | ||
| $( document ).on( 'click', 'div.widget[id*="jetpack_widget_social_icons"] .widget-title, div.widget[id*="jetpack_widget_social_icons"] .widget-action', function() { |
There was a problem hiding this comment.
Yay for consistently using double quotes around attribute selector values! 👍
|
|
||
| .jetpack_widget_social_icons svg { | ||
| color: inherit; | ||
| fill: currentColor; |
There was a problem hiding this comment.
| */ | ||
| function wpcom_social_media_icons_widget_load_widget() { | ||
| // [DEPRECATION]: Only register widget if active widget exists already | ||
| $has_widget = is_active_widget( false, false, 'wpcom_social_media_icons_widget', false ); |
There was a problem hiding this comment.
Are we sure this works? Testing if a widget is active before registering it?
Also, it seems like this may be more efficient to cache in a transient rather than having WordPress scan through every sidebar on every page load. That's probably a blocker.
|
^^ there's the end of the review. Please ping me in Slack if you have any questions, I'd be delighted to work with anyone and answer any questions about my remarks. <3 |
|
Howdy @georgestephanis, I'll be having a look at this and will tackle the fixes accordingly. I'll keep you posted on Slack if I have any questions. Thanks! |
|
This would fix #7433 |
jeherve
left a comment
There was a problem hiding this comment.
A few changes to keep the new widget more in line with the old one.
modules/widgets/social-icons.php
Outdated
| 'customize_selective_refresh' => true, | ||
| ); | ||
|
|
||
| parent::__construct( 'jetpack_widget_social_icons', __( 'Social Icons', 'jetpack' ), $widget_ops ); |
There was a problem hiding this comment.
Could you add the jetpack_widget_name filter here, like so?
/** This filter is documented in modules/widgets/facebook-likebox.php */
apply_filters( 'jetpack_widget_name', __( 'Social Icons', 'jetpack' ) ),
modules/widgets/social-icons.php
Outdated
| return; | ||
| } | ||
|
|
||
| // Define SVG sprite file in Jetpack -- NEEDS TESTING |
There was a problem hiding this comment.
I must admit I'm not super clear on the differences between the svg we have in our Theme Tools and social logos, that we use for Jetpack Sharing buttons:
https://github.com/Automattic/jetpack/tree/master/_inc/social-logos
Is that SVG sprite the same as the one available here?
https://github.com/Automattic/social-logos/tree/master/svg-sprite
Could we use the icon font instead, since it may be loaded by the sharing buttons on most pages where the widget (or the social menu) will also be displayed? It would be better for performance, and we would only have to update the icon font when the social logos get updated.
What do you think?
There was a problem hiding this comment.
This is the same SVG file used for the Social Menus: https://github.com/Automattic/jetpack/blob/master/modules/theme-tools/social-menu/social-menu.svg
It's much more flexible than an icon font and it supports more social networks.
|
|
||
| <?php if ( ! empty( $icon['url'] ) ) : ?> | ||
| <li class="jetpack-social-widget-item"> | ||
| <a href="<?php echo esc_url( $icon['url'], array( 'http', 'https', 'mailto', 'skype' ) ); ?>"<?php echo $new_tab; ?>> |
There was a problem hiding this comment.
We used to have a jetpack_social_media_icons_widget_profile_link filter in the old widget. Maybe we should add it here too?
https://developer.jetpack.com/hooks/jetpack_social_media_icons_widget_profile_link/
| ), | ||
| ); | ||
|
|
||
| return $social_links_icons; |
There was a problem hiding this comment.
Should we allow folks to customize that list so they can add their own icon, as we used to allow with jetpack_social_media_icons_widget_array?
https://developer.jetpack.com/hooks/jetpack_social_media_icons_widget_array/
There was a problem hiding this comment.
We already support much more social networks than the old widget. Also, for consistency reason, I would not recommend adding a filter here.
Same with jetpack_social_media_icons_widget_profile_link and jetpack_social_media_icons_widget_output
| <?php | ||
| endif; | ||
|
|
||
| echo $args['after_widget']; |
There was a problem hiding this comment.
Could you add the jetpack_stats_extra action here, like we do for other widgets?
| <?php | ||
| endif; | ||
|
|
||
| echo $args['after_widget']; |
There was a problem hiding this comment.
We also add a jetpack_social_media_icons_widget_output filter here so folks could customize the whole output. Maybe we should do the same in that new widget?
https://developer.jetpack.com/hooks/jetpack_social_media_icons_widget_output/
* Add V1.2 Plugin Endpoints * simply eveything * Updates as requested.. These change need to be tested better. * Stash things? * Add log back in. Refactor to use the _response_format_v1_2 format array. * Remove the .com only api endpoints. From jetpack Remove * Add log to plugin format method * Minor fixes * minor code fixes
* Shortcodes: remove aws domain from Mailchimp shortcode. Fixes #7945 To test, create a Maichimp form as explained here: https://en.support.wordpress.com/mailchimp/ Then try to embed it into one of your posts or pages, when logged in as an editor. You should see the form transform into a shortcode on save. Make sure the form is displayed properly on the site. * Mailchimp: save a shortcode when pasting a form code in the widget Fixes #7960 Fixes #7990 - The widget now calls the shortcode file even when the shortcodes are not active, so you do not need to activate the shortcode module for this to work. - On save, the widget uses the reversal function provided in the shortcode to save a valid shortcode. - That shortcode is then displayed in the widget, as before. * Mailchimp shortcode: update failing unit test.
CLI: Do not change directory within partner scripts
Recently we added some bug fixes. This introduced a bug where we would always be returning an error when we install an plugin. This PR fixes this by making sure that $error is being checked for the empty case.
Plugin API: Installing plugins always returns an error.
This parameter has been present since 4.2 and by applying the filter here, we are currently breaking all callbacks that expect the $instance
* Sync: Fix issue with syncing raw URLs for multisites * Sync: Fix failing test after updating multisite logic
This ensures that nested blocks are replaced first (e.g. code inside shortcodes).
…#8392) * Hide all mentions of VaultPress is rewind is available but not active * removed commented code
* First pass -- VaultPress deactivation if Rewind is running. I may (probably will) need to revisit where in the `$features` array I'm checking to see if Rewind is enabled. * Add the file to the included list for 3rd-party * Retool to new method to check for Rewind availability. * Update is_rewind_enabled() method to read the correct data for determining status of Rewind * VaultPress Murder * faulty logic
* Dashboard: fix issue where Jetpack version at the footer was shown as undefined since data wasn't available on the static page. This will now show `Jetpack` when the version is unavailable and the complete Jetpack version xx when it's available.
To keep in line with WPCOM, I’d like to add the new Social Icons widget. You can add this widget to any site and you should have a new widget as seen on its documentation page (https://en.support.wordpress.com/widgets/social-media-icons-widget/). The old widget should become unavailable to sites not using it. If they do then we add a “(Deprecated)” to the label. In `social-icons.php`, L72, we use the same `social-menu.svg` file as the one used for the Social Menu.
* Fix double escaping * Remove browser prefix from CSS * Use `document.body` in admin JS * Move Social Icons functions (SVG, icons and label) inside the widget class * Only load admin scripts when needed (widget.php and customizer) * Only load SVG footer file when widget is active * Use `is_file()` instead of `file_exists()` to check if the SVG icons file exists * Use `stripos()` instead of `strpos` to parse the URL * Use a `switch` statement instead of `if` to detect `get_locale` * Set the default icon (chain) outside the `foreach` loop * Refactor `get_supported_icons()` and only use one function for icon name and label instead of 2 * Fix `esc_url` for Skype links `skype:` * Add option to open links in a new tab * Add transient to old widget to check if it's active or not
… using `empty()` with arbitrary expressions
…etpack into social-icons-widget
|
Looks like something went wrong with that rebase @thomasguillot. Could you give it another try? |
…et. Closes #7454 Closing previous PR/branch and opening a new one due to an issue with a rebase.
|
I've opened a new PR, #8498, as I'm not quite sure what happened here and this is a mess. |
…et (#8498) * Add new Social Icons widget and deprecate old Social Media Icons widget. Closes #7454 Closing previous PR/branch and opening a new one due to an issue with a rebase. * Social Media Icons: Remove the strict type check to only register widget if active widget exists already * Social Icons widget: Set target attribute for the link Will set the target attribute to `_blank` or `_self` depending on the new tab option being ticked or not.
Fixes #3776
Fixes #7433
To keep in line with WPCOM, I’d like to add the new Social Icons
widget. You can add this widget to any site and you should have a new
widget as seen on its documentation page
(https://en.support.wordpress.com/widgets/social-media-icons-widget/).
The old widget should become unavailable to sites not using it. If they
do then we add a “(Deprecated)” to the label.
In
social-icons.php, L72, we use the samesocial-menu.svgfile asthe one used for the Social Menu.