Skip to:
Content

BuddyPress.org

Changeset 10793


Ignore:
Timestamp:
05/19/2016 09:21:46 PM (4 years ago)
Author:
r-a-y
Message:

Widgets: Add support for WP Customizer's selective refresh.

This functionality is available as of WordPress 4.5.0.

For more details, view the WP development post:
https://make.wordpress.org/core/2016/03/22/implementing-selective-refresh-support-for-widgets/

Props lakrisgubben.
Fixes #7030.

Location:
trunk/src
Files:
11 edited

Legend:

Unmodified
Added
Removed
  • trunk/src/bp-blogs/classes/class-bp-blogs-recent-posts-widget.php

    r10553 r10793  
    2121    public function __construct() {
    2222        $widget_ops = array(
    23             'description' => __( 'A list of recently published posts from across your network.', 'buddypress' ),
    24             'classname'   => 'widget_bp_blogs_widget buddypress widget',
     23            'description'                 => __( 'A list of recently published posts from across your network.', 'buddypress' ),
     24            'classname'                   => 'widget_bp_blogs_widget buddypress widget',
     25            'customize_selective_refresh' => true,
    2526        );
    2627        parent::__construct( false, $name = _x( '(BuddyPress) Recent Networkwide Posts', 'widget name', 'buddypress' ), $widget_ops );
  • trunk/src/bp-core/classes/class-bp-core-login-widget.php

    r10591 r10793  
    2828            _x( '(BuddyPress) Log In', 'Title of the login widget', 'buddypress' ),
    2929            array(
    30                 'description' => __( 'Show a Log In form to logged-out visitors, and a Log Out link to those who are logged in.', 'buddypress' ),
    31                 'classname' => 'widget_bp_core_login_widget buddypress widget',
     30                'description'                 => __( 'Show a Log In form to logged-out visitors, and a Log Out link to those who are logged in.', 'buddypress' ),
     31                'classname'                   => 'widget_bp_core_login_widget buddypress widget',
     32                'customize_selective_refresh' => true,
    3233            )
    3334        );
  • trunk/src/bp-core/js/widget-members.js

    r9819 r10793  
    11jQuery(document).ready( function() {
     2    member_widget_click_handler();
     3
     4    // WP 4.5 - Customizer selective refresh support.
     5    if ( 'undefined' !== typeof wp && wp.customize && wp.customize.selectiveRefresh ) {
     6        wp.customize.selectiveRefresh.bind( 'partial-content-rendered', function() {
     7            member_widget_click_handler();
     8        } );
     9    }
     10});
     11
     12function member_widget_click_handler() {
    213    jQuery('.widget div#members-list-options a').on('click',
    314        function() {
     
    2435        }
    2536    );
    26 });
     37}
    2738
    2839function member_widget_response(response) {
  • trunk/src/bp-friends/classes/class-bp-core-friends-widget.php

    r10613 r10793  
    2525    function __construct() {
    2626        $widget_ops = array(
    27             'description' => __( 'A dynamic list of recently active, popular, and newest Friends of the displayed member.  Widget is only shown when viewing a member profile.', 'buddypress' ),
    28             'classname' => 'widget_bp_core_friends_widget buddypress widget',
     27            'description'                 => __( 'A dynamic list of recently active, popular, and newest Friends of the displayed member.  Widget is only shown when viewing a member profile.', 'buddypress' ),
     28            'classname'                   => 'widget_bp_core_friends_widget buddypress widget',
     29            'customize_selective_refresh' => true,
    2930        );
    3031        parent::__construct( false, $name = _x( '(BuddyPress) Friends', 'widget name', 'buddypress' ), $widget_ops );
     32
     33        if ( is_customize_preview() || is_active_widget( false, false, $this->id_base ) && ! is_admin() && ! is_network_admin() ) {
     34            $min = bp_core_get_minified_asset_suffix();
     35            wp_enqueue_script( 'bp_core_widget_friends-js', buddypress()->plugin_url . "bp-friends/js/widget-friends{$min}.js", array( 'jquery' ), bp_get_version() );
     36        }
    3137
    3238    }
     
    4854            return;
    4955        }
    50 
    51         $min = bp_core_get_minified_asset_suffix();
    52         wp_enqueue_script( 'bp_core_widget_friends-js', buddypress()->plugin_url . "bp-friends/js/widget-friends{$min}.js", array( 'jquery' ), bp_get_version() );
    5356
    5457        $user_id = bp_displayed_user_id();
  • trunk/src/bp-friends/js/widget-friends.js

    r9819 r10793  
    11jQuery(document).ready( function() {
     2    friend_widget_click_handler();
     3
     4    // WP 4.5 - Customizer selective refresh support.
     5    if ( 'undefined' !== typeof wp && wp.customize && wp.customize.selectiveRefresh ) {
     6        wp.customize.selectiveRefresh.bind( 'partial-content-rendered', function() {
     7            friend_widget_click_handler();
     8        } );
     9    }
     10});
     11
     12function friend_widget_click_handler() {
    213    jQuery('.widget div#friends-list-options a').on('click',
    314        function() {
     
    2435        }
    2536    );
    26 });
     37}
    2738
    2839function friend_widget_response(response) {
  • trunk/src/bp-groups/classes/class-bp-groups-widget.php

    r10613 r10793  
    2525    public function __construct() {
    2626        $widget_ops = array(
    27             'description' => __( 'A dynamic list of recently active, popular, and newest groups', 'buddypress' ),
    28             'classname' => 'widget_bp_groups_widget buddypress widget',
     27            'description'                 => __( 'A dynamic list of recently active, popular, and newest groups', 'buddypress' ),
     28            'classname'                   => 'widget_bp_groups_widget buddypress widget',
     29            'customize_selective_refresh' => true,
    2930        );
    3031        parent::__construct( false, _x( '(BuddyPress) Groups', 'widget name', 'buddypress' ), $widget_ops );
    3132
    32         if ( is_active_widget( false, false, $this->id_base ) && ! is_admin() && ! is_network_admin() ) {
     33        if ( is_customize_preview() || is_active_widget( false, false, $this->id_base ) && ! is_admin() && ! is_network_admin() ) {
    3334            $min = bp_core_get_minified_asset_suffix();
    3435            wp_enqueue_script( 'groups_widget_groups_list-js', buddypress()->plugin_url . "bp-groups/js/widget-groups{$min}.js", array( 'jquery' ), bp_get_version() );
  • trunk/src/bp-groups/js/widget-groups.js

    r9819 r10793  
    11jQuery(document).ready( function() {
     2    groups_widget_click_handler();
     3
     4    // WP 4.5 - Customizer selective refresh support.
     5    if ( 'undefined' !== typeof wp && wp.customize && wp.customize.selectiveRefresh ) {
     6        wp.customize.selectiveRefresh.bind( 'partial-content-rendered', function() {
     7            groups_widget_click_handler();
     8        } );
     9    }
     10});
     11
     12function groups_widget_click_handler() {
    213    jQuery('.widget div#groups-list-options a').on('click',
    314        function() {
     
    2435        }
    2536    );
    26 });
     37}
    2738
    2839function groups_widget_response(response) {
  • trunk/src/bp-members/classes/class-bp-core-members-widget.php

    r10711 r10793  
    3131        // Call WP_Widget constructor.
    3232        parent::__construct( false, $name, array(
    33             'description' => $description,
    34             'classname'   => 'widget_bp_core_members_widget buddypress widget',
     33            'description'                 => $description,
     34            'classname'                   => 'widget_bp_core_members_widget buddypress widget',
     35            'customize_selective_refresh' => true,
    3536        ) );
    3637
    3738        // Maybe enqueue JS for widget.
    38         if ( is_active_widget( false, false, $this->id_base ) && ! is_admin() && ! is_network_admin() ) {
     39        if ( is_customize_preview() || is_active_widget( false, false, $this->id_base ) && ! is_admin() && ! is_network_admin() ) {
    3940            wp_enqueue_script( 'bp-widget-members' );
    4041        }
  • trunk/src/bp-members/classes/class-bp-core-recently-active-widget.php

    r10711 r10793  
    2727        $description = __( 'Profile photos of recently active members', 'buddypress' );
    2828        parent::__construct( false, $name, array(
    29             'description' => $description,
    30             'classname'   => 'widget_bp_core_recently_active_widget buddypress widget',
     29            'description'                 => $description,
     30            'classname'                   => 'widget_bp_core_recently_active_widget buddypress widget',
     31            'customize_selective_refresh' => true,
    3132        ) );
    3233    }
  • trunk/src/bp-members/classes/class-bp-core-whos-online-widget.php

    r10711 r10793  
    2727        $description = __( 'Profile photos of online users', 'buddypress' );
    2828        parent::__construct( false, $name, array(
    29             'description' => $description,
    30             'classname' => 'widget_bp_core_whos_online_widget buddypress widget',
     29            'description'                 => $description,
     30            'classname'                   => 'widget_bp_core_whos_online_widget buddypress widget',
     31            'customize_selective_refresh' => true,
    3132        ) );
    3233    }
  • trunk/src/bp-messages/classes/class-bp-messages-sitewide-notices-widget.php

    r10522 r10793  
    2626            __( '(BuddyPress) Sitewide Notices', 'buddypress' ),
    2727            array(
    28                 'classname'   => 'widget_bp_core_sitewide_messages buddypress widget',
    29                 'description' => __( 'Display Sitewide Notices posted by the site administrator', 'buddypress' ),
     28                'classname'                   => 'widget_bp_core_sitewide_messages buddypress widget',
     29                'description'                 => __( 'Display Sitewide Notices posted by the site administrator', 'buddypress' ),
     30                'customize_selective_refresh' => true,
    3031            )
    3132        );
Note: See TracChangeset for help on using the changeset viewer.