Skip to:
Content

BuddyPress.org


Ignore:
Timestamp:
05/17/2023 11:14:06 AM (22 months ago)
Author:
imath
Message:

Deprecate BP Legacy widgets

Deprecate all classes, functions, JavaScripts and files related to Legacy Widgets. Legacy Widgets are now available from the BP Classic plugin.

See #8869
Closes https://github.com/buddypress/buddypress/pull/99

File:
1 edited

Legend:

Unmodified
Added
Removed
  • trunk/src/bp-friends/classes/class-bp-core-friends-widget.php

    r13443 r13481  
    66 * @subpackage FriendsWidget
    77 * @since 1.9.0
     8 * @deprecated 12.0.0
    89 */
    910
     
    1112defined( 'ABSPATH' ) || exit;
    1213
     14_deprecated_file( basename( __FILE__ ), '12.0.0', '', __( 'BuddyPress does not include Legacy Widgets anymore, you can restore it using the BP Classic plugin', 'buddypress' ) );
     15
    1316/**
    1417 * The User Friends widget class.
    1518 *
    1619 * @since 1.9.0
     20 * @deprecated 12.0.0
    1721 */
    18 class BP_Core_Friends_Widget extends WP_Widget {
     22class BP_Core_Friends_Widget {
    1923
    2024    /**
     
    2327     * @since 1.9.0
    2428     * @since 9.0.0 Adds the `show_instance_in_rest` property to Widget options.
     29     * @deprecated 12.0.0
    2530     */
    2631    public function __construct() {
    27         $widget_ops = array(
    28             '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' ),
    29             'classname'                   => 'widget_bp_core_friends_widget buddypress widget',
    30             'customize_selective_refresh' => true,
    31             'show_instance_in_rest'       => true,
    32         );
    33         parent::__construct( false, $name = _x( '(BuddyPress) Friends', 'widget name', 'buddypress' ), $widget_ops );
    34 
    35         if ( is_customize_preview() || bp_is_widget_block_active( '', $this->id_base ) ) {
    36             add_action( 'bp_enqueue_scripts', array( $this, 'enqueue_scripts' ) );
    37         }
     32        _deprecated_function( __METHOD__, '12.0.0' );
    3833    }
    3934
     
    4237     *
    4338     * @since 2.6.0
     39     * @deprecated 12.0.0
    4440     */
    4541    public function enqueue_scripts() {
    46         $min = bp_core_get_minified_asset_suffix();
    47         wp_enqueue_script( 'bp_core_widget_friends-js', buddypress()->plugin_url . "bp-friends/js/widget-friends{$min}.js", array( 'jquery' ), bp_get_version() );
     42        _deprecated_function( __METHOD__, '12.0.0' );
    4843    }
    4944
     
    5247     *
    5348     * @since 1.9.0
     49     * @deprecated 12.0.0
    5450     *
    5551     * @global BP_Core_Members_Template $members_template The main member template loop class.
     
    5955     */
    6056    public function widget( $args, $instance ) {
    61         global $members_template;
    62 
    63         extract( $args );
    64 
    65         if ( ! bp_displayed_user_id() ) {
    66             return;
    67         }
    68 
    69         $user_id           = bp_displayed_user_id();
    70         $friends_slug      = bp_get_friends_slug();
    71         $link              = bp_displayed_user_url(
    72             array(
    73                 'single_item_component' => bp_rewrites_get_slug( 'members', 'member_' . $friends_slug, $friends_slug ),
    74             )
    75         );
    76         $instance['title'] = sprintf( __( "%s's Friends", 'buddypress' ), bp_get_displayed_user_fullname() );
    77 
    78         if ( empty( $instance['friend_default'] ) ) {
    79             $instance['friend_default'] = 'active';
    80         }
    81 
    82         /**
    83          * Filters the Friends widget title.
    84          *
    85          * @since 1.8.0
    86          * @since 2.3.0 Added 'instance' and 'id_base' to arguments passed to filter.
    87          *
    88          * @param string $title    The widget title.
    89          * @param array  $instance The settings for the particular instance of the widget.
    90          * @param string $id_base  Root ID for all widgets of this type.
    91          */
    92         $title = apply_filters( 'widget_title', $instance['title'], $instance, $this->id_base );
    93 
    94         echo $before_widget;
    95 
    96         $title = $instance['link_title'] ? '<a href="' . esc_url( $link ) . '">' . esc_html( $title ) . '</a>' : esc_html( $title );
    97 
    98         echo $before_title . $title . $after_title;
    99 
    100         $members_args = array(
    101             'user_id'         => absint( $user_id ),
    102             'type'            => sanitize_text_field( $instance['friend_default'] ),
    103             'max'             => absint( $instance['max_friends'] ),
    104             'populate_extras' => 1,
    105         );
    106 
    107         // Back up the global.
    108         $old_members_template = $members_template;
    109 
    110         ?>
    111 
    112         <?php if ( bp_has_members( $members_args ) ) : ?>
    113             <div class="item-options" id="friends-list-options">
    114                 <a href="<?php bp_members_directory_permalink(); ?>" id="newest-friends" <?php if ( $instance['friend_default'] == 'newest' ) : ?>class="selected"<?php endif; ?>><?php _e( 'Newest', 'buddypress' ); ?></a>
    115                 | <a href="<?php bp_members_directory_permalink(); ?>" id="recently-active-friends" <?php if ( $instance['friend_default'] == 'active' ) : ?>class="selected"<?php endif; ?>><?php _e( 'Active', 'buddypress' ); ?></a>
    116                 | <a href="<?php bp_members_directory_permalink(); ?>" id="popular-friends" <?php if ( $instance['friend_default'] == 'popular' ) : ?>class="selected"<?php endif; ?>><?php _e( 'Popular', 'buddypress' ); ?></a>
    117             </div>
    118 
    119             <ul id="friends-list" class="item-list">
    120                 <?php while ( bp_members() ) : bp_the_member(); ?>
    121                     <li class="vcard">
    122                         <div class="item-avatar">
    123                             <a href="<?php bp_member_permalink(); ?>" class="bp-tooltip" data-bp-tooltip="<?php bp_member_name(); ?>"><?php bp_member_avatar(); ?></a>
    124                         </div>
    125 
    126                         <div class="item">
    127                             <div class="item-title fn"><a href="<?php bp_member_permalink(); ?>"><?php bp_member_name(); ?></a></div>
    128                             <div class="item-meta">
    129                                 <?php if ( 'newest' == $instance['friend_default'] ) : ?>
    130                                     <span class="activity" data-livestamp="<?php bp_core_iso8601_date( bp_get_member_registered( array( 'relative' => false ) ) ); ?>"><?php bp_member_registered(); ?></span>
    131                                 <?php elseif ( 'active' == $instance['friend_default'] ) : ?>
    132                                     <span class="activity" data-livestamp="<?php bp_core_iso8601_date( bp_get_member_last_active( array( 'relative' => false ) ) ); ?>"><?php bp_member_last_active(); ?></span>
    133                                 <?php else : ?>
    134                                     <span class="activity"><?php bp_member_total_friend_count(); ?></span>
    135                                 <?php endif; ?>
    136                             </div>
    137                         </div>
    138                     </li>
    139 
    140                 <?php endwhile; ?>
    141             </ul>
    142             <?php wp_nonce_field( 'bp_core_widget_friends', '_wpnonce-friends' ); ?>
    143             <input type="hidden" name="friends_widget_max" id="friends_widget_max" value="<?php echo absint( $instance['max_friends'] ); ?>" />
    144 
    145         <?php else: ?>
    146 
    147             <div class="widget-error">
    148                 <?php _e( 'Sorry, no members were found.', 'buddypress' ); ?>
    149             </div>
    150 
    151         <?php endif; ?>
    152 
    153         <?php echo $after_widget;
    154 
    155         // Restore the global.
    156         $members_template = $old_members_template;
     57        _deprecated_function( __METHOD__, '12.0.0' );
    15758    }
    15859
     
    16162     *
    16263     * @since 1.9.0
     64     * @deprecated 12.0.0
    16365     *
    16466     * @param array $new_instance The parameters saved by the user.
     
    16769     */
    16870    public function update( $new_instance, $old_instance ) {
    169         $instance = $old_instance;
    170 
    171         $instance['max_friends']    = absint( $new_instance['max_friends'] );
    172         $instance['friend_default'] = sanitize_text_field( $new_instance['friend_default'] );
    173         $instance['link_title']     = ! empty( $new_instance['link_title'] );
    174 
    175         return $instance;
     71        _deprecated_function( __METHOD__, '12.0.0' );
    17672    }
    17773
     
    18076     *
    18177     * @since 1.9.0
     78     * @deprecated 12.0.0
    18279     *
    18380     * @param array $instance The saved widget settings.
    18481     */
    18582    public function form( $instance ) {
    186         $defaults = array(
    187             'max_friends'    => 5,
    188             'friend_default' => 'active',
    189             'link_title'     => false,
    190         );
    191 
    192         $instance = bp_parse_args(
    193             (array) $instance,
    194             $defaults
    195         );
    196 
    197         $max_friends    = $instance['max_friends'];
    198         $friend_default = $instance['friend_default'];
    199         $link_title     = (bool) $instance['link_title'];
    200         ?>
    201 
    202         <p><label for="<?php echo $this->get_field_id( 'link_title' ); ?>"><input type="checkbox" name="<?php echo $this->get_field_name('link_title'); ?>" id="<?php echo $this->get_field_id( 'link_title' ); ?>" value="1" <?php checked( $link_title ); ?> /> <?php _e( 'Link widget title to Members directory', 'buddypress' ); ?></label></p>
    203 
    204         <p><label for="<?php echo $this->get_field_id( 'max_friends' ); ?>"><?php esc_html_e( 'Max friends to show:', 'buddypress' ); ?> <input class="widefat" id="<?php echo $this->get_field_id( 'max_friends' ); ?>" name="<?php echo $this->get_field_name( 'max_friends' ); ?>" type="text" value="<?php echo absint( $max_friends ); ?>" style="width: 30%" /></label></p>
    205 
    206         <p>
    207             <label for="<?php echo $this->get_field_id( 'friend_default' ) ?>"><?php esc_html_e( 'Default friends to show:', 'buddypress' ); ?></label>
    208             <select name="<?php echo $this->get_field_name( 'friend_default' ); ?>" id="<?php echo $this->get_field_id( 'friend_default' ); ?>">
    209                 <option value="newest" <?php selected( $friend_default, 'newest' ); ?>><?php esc_html_e( 'Newest', 'buddypress' ); ?></option>
    210                 <option value="active" <?php selected( $friend_default, 'active' ); ?>><?php esc_html_e( 'Active', 'buddypress' ); ?></option>
    211                 <option value="popular"  <?php selected( $friend_default, 'popular' ); ?>><?php esc_html_e( 'Popular', 'buddypress' ); ?></option>
    212             </select>
    213         </p>
    214     <?php
     83        _deprecated_function( __METHOD__, '12.0.0' );
    21584    }
    21685}
Note: See TracChangeset for help on using the changeset viewer.