Skip to content

Commit 75abbfa

Browse files
committed
Make Gravatar, RSS Links, Top Posts, Upcoming Events and WordPress Posts widgets compatible with selective refresh.
1 parent 2615f00 commit 75abbfa

5 files changed

Lines changed: 50 additions & 17 deletions

File tree

‎modules/widgets/gravatar-profile.php‎

Lines changed: 29 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -22,13 +22,18 @@ function __construct() {
2222
apply_filters( 'jetpack_widget_name', __( 'Gravatar Profile', 'jetpack' ) ),
2323
array(
2424
'classname' => 'widget-grofile grofile',
25-
'description' => __( 'Display a mini version of your Gravatar Profile', 'jetpack' )
25+
'description' => __( 'Display a mini version of your Gravatar Profile', 'jetpack' ),
26+
'customize_selective_refresh' => true,
2627
)
2728
);
2829

2930
if ( is_admin() ) {
3031
add_action( 'admin_footer-widgets.php', array( $this, 'admin_script' ) );
3132
}
33+
34+
if ( is_customize_preview() ) {
35+
add_action( 'wp_enqueue_scripts', array( $this, 'enqueue_scripts' ) );
36+
}
3237
}
3338

3439
function widget( $args, $instance ) {
@@ -69,19 +74,8 @@ function widget( $args, $instance ) {
6974
) );
7075
$gravatar_url = add_query_arg( 's', 320, $profile['thumbnailUrl'] ); // the default grav returned by grofiles is super small
7176

72-
wp_enqueue_style(
73-
'gravatar-profile-widget',
74-
plugins_url( 'gravatar-profile.css', __FILE__ ),
75-
array(),
76-
'20120711'
77-
);
78-
79-
wp_enqueue_style(
80-
'gravatar-card-services',
81-
is_ssl() ? 'https://secure.gravatar.com/css/services.css' : 'http://s.gravatar.com/css/services.css',
82-
array(),
83-
defined( 'GROFILES__CACHE_BUSTER' ) ? GROFILES__CACHE_BUSTER : gmdate( 'YW' )
84-
);
77+
// Enqueue front end assets.
78+
$this->enqueue_scripts();
8579

8680
?>
8781
<img src="<?php echo esc_url( $gravatar_url ); ?>" class="grofile-thumbnail no-grav" alt="<?php echo esc_attr( $profile['displayName'] ); ?>" />
@@ -221,6 +215,27 @@ function display_accounts( $accounts = array() ) {
221215
<?php
222216
}
223217

218+
/**
219+
* Enqueue CSS and JavaScript.
220+
*
221+
* @since 3.10
222+
*/
223+
function enqueue_scripts() {
224+
wp_enqueue_style(
225+
'gravatar-profile-widget',
226+
plugins_url( 'gravatar-profile.css', __FILE__ ),
227+
array(),
228+
'20120711'
229+
);
230+
231+
wp_enqueue_style(
232+
'gravatar-card-services',
233+
is_ssl() ? 'https://secure.gravatar.com/css/services.css' : 'http://s.gravatar.com/css/services.css',
234+
array(),
235+
defined( 'GROFILES__CACHE_BUSTER' ) ? GROFILES__CACHE_BUSTER : gmdate( 'YW' )
236+
);
237+
}
238+
224239
function form( $instance ) {
225240
$title = isset( $instance['title'] ) ? $instance['title'] : '';
226241
$email = isset( $instance['email'] ) ? $instance['email'] : '';

‎modules/widgets/rsslinks-widget.php‎

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -11,7 +11,8 @@ class Jetpack_RSS_Links_Widget extends WP_Widget {
1111
function __construct() {
1212
$widget_ops = array(
1313
'classname' => 'widget_rss_links',
14-
'description' => __( "Links to your blog's RSS feeds", 'jetpack' )
14+
'description' => __( "Links to your blog's RSS feeds", 'jetpack' ),
15+
'customize_selective_refresh' => true,
1516
);
1617
parent::__construct(
1718
'rss_links',

‎modules/widgets/top-posts.php‎

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -36,12 +36,13 @@ function __construct() {
3636
apply_filters( 'jetpack_widget_name', __( 'Top Posts &amp; Pages', 'jetpack' ) ),
3737
array(
3838
'description' => __( 'Shows your most viewed posts and pages.', 'jetpack' ),
39+
'customize_selective_refresh' => true,
3940
)
4041
);
4142

4243
$this->default_title = __( 'Top Posts &amp; Pages', 'jetpack' );
4344

44-
if ( is_active_widget( false, false, $this->id_base ) ) {
45+
if ( is_active_widget( false, false, $this->id_base ) || is_customize_preview() ) {
4546
add_action( 'wp_enqueue_scripts', array( $this, 'enqueue_style' ) );
4647
}
4748

‎modules/widgets/upcoming-events.php‎

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -8,6 +8,7 @@ function __construct() {
88
apply_filters( 'jetpack_widget_name', __( 'Upcoming Events', 'jetpack' ) ),
99
array(
1010
'description' => __( 'Display upcoming events from an iCalendar feed.', 'jetpack' ),
11+
'customize_selective_refresh' => true,
1112
)
1213
);
1314
if ( is_active_widget( false, false, $this->id_base ) ) {

‎modules/widgets/wordpress-post-widget.php‎

Lines changed: 16 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -145,8 +145,13 @@ public function __construct() {
145145
apply_filters( 'jetpack_widget_name', __( 'Display WordPress Posts', 'jetpack' ) ),
146146
array(
147147
'description' => __( 'Displays a list of recent posts from another WordPress.com or Jetpack-enabled blog.', 'jetpack' ),
148+
'customize_selective_refresh' => true,
148149
)
149150
);
151+
152+
if ( is_customize_preview() ) {
153+
add_action( 'wp_enqueue_scripts', array( $this, 'enqueue_scripts' ) );
154+
}
150155
}
151156

152157
/**
@@ -727,7 +732,8 @@ public function widget( $args, $instance ) {
727732
/** This filter is documented in core/src/wp-includes/default-widgets.php */
728733
$title = apply_filters( 'widget_title', $instance['title'] );
729734

730-
wp_enqueue_style( 'jetpack_display_posts_widget', plugins_url( 'wordpress-post-widget/style.css', __FILE__ ) );
735+
// Enqueue front end assets.
736+
$this->enqueue_scripts();
731737

732738
echo $args['before_widget'];
733739

@@ -882,6 +888,15 @@ public function extract_errors_from_blog_data( $blog_data ) {
882888
return $errors;
883889
}
884890

891+
/**
892+
* Enqueue CSS and JavaScript.
893+
*
894+
* @since 3.10
895+
*/
896+
public function enqueue_scripts() {
897+
wp_enqueue_style( 'jetpack_display_posts_widget', plugins_url( 'wordpress-post-widget/style.css', __FILE__ ) );
898+
}
899+
885900
/**
886901
* Display the widget administration form.
887902
*

0 commit comments

Comments
 (0)