Skip to:
Content

BuddyPress.org

Changeset 13136


Ignore:
Timestamp:
11/01/2021 06:13:15 PM (5 years ago)
Author:
imath
Message:

BP Nouveau: improve the Members' directory primary nav's text

The Nouveau template pack will from now on update the Members's directory primary nav's text according to the members displayed list. The 'All Members' text will only be used when filtering this list alphabetically. When using the default filter (last active), this text will now be 'Active Members'. Finally, when filtering the list using the "Newest registered" option, this text will now be 'Newest Members'.

We believe this improvement can avoid the confusion we often make about this nav's count information. To be sure to get the 'All Members' count right, you need to sort the list alphabetically.

Props ketan_chawda

Fixes #8101

Location:
trunk/src/bp-templates/bp-nouveau
Files:
3 edited

Legend:

Unmodified
Added
Removed
  • trunk/src/bp-templates/bp-nouveau/includes/ajax.php

    r12908 r13136  
    44 *
    55 * @since 3.0.0
    6  * @version 8.0.0
     6 * @version 10.0.0
    77 */
    88
     
    2222        }
    2323
    24         if ( empty( $_POST['object'] ) ) {
    25                 wp_send_json_error();
    26         }
     24        $post_vars = bp_parse_args(
     25                $_POST,
     26                array(
     27                        'action'   => '',
     28                        'object'   => '',
     29                        'scope'    => '',
     30                        'filter'   => '',
     31                        'nonce'    => '',
     32                        'template' => '',
     33                )
     34        );
    2735
    28         $object = sanitize_title( $_POST['object'] );
     36        $object = sanitize_title( $post_vars['object'] );
    2937
    3038        // Bail if object is not an active component to prevent arbitrary file inclusion.
     
    3442
    3543        // Nonce check!
    36         if ( empty( $_POST['nonce'] ) || ! wp_verify_nonce( $_POST['nonce'], 'bp_nouveau_' . $object ) ) {
     44        if ( ! $post_vars['nonce'] || ! wp_verify_nonce( $post_vars['nonce'], 'bp_nouveau_' . $object ) ) {
    3745                wp_send_json_error();
    3846        }
     
    4250        if ( 'activity' === $object ) {
    4351                $scope = '';
    44                 if ( ! empty( $_POST['scope'] ) ) {
    45                         $scope = sanitize_text_field( $_POST['scope'] );
     52                if ( $post_vars['scope'] ) {
     53                        $scope = sanitize_text_field( $post_vars['scope'] );
    4654                }
    4755
     
    99107
    100108        // Get the template path based on the 'template' variable via the AJAX request.
    101         $template = isset( $_POST['template'] ) ? wp_unslash( $_POST['template'] ) : '';
     109        $template = '';
     110        if ( $post_vars['template'] ) {
     111                $template = wp_unslash( $post_vars['template'] );
     112        }
    102113
    103114        switch ( $template ) {
     
    141152        ob_end_clean();
    142153
     154        /**
     155         * Add additional info to the Ajax response.
     156         *
     157         * @since 10.0.0
     158         *
     159         * @param array $value     An associative array with additional information to include in the Ajax response.
     160         * @param array $post_vars An associative array containing the Ajax request arguments.
     161         */
     162        $additional_info = apply_filters( "bp_nouveau_{$object}_ajax_object_template_response", array(), $post_vars );
     163        if ( $additional_info ) {
     164                // Prevents content overrides.
     165                if ( isset( $additional_info['contents'] ) ) {
     166                        unset( $additional_info['contents'] );
     167                }
     168
     169                $result = array_merge( $result, $additional_info );
     170        }
     171
    143172        // Locate the object template.
    144173        wp_send_json_success( $result );
  • trunk/src/bp-templates/bp-nouveau/includes/members/functions.php

    r12921 r13136  
    44 *
    55 * @since 3.0.0
    6  * @version 8.0.0
     6 * @version 10.0.0
    77 */
    88
     
    530530        return $nav->get_primary();
    531531}
     532
     533/**
     534 * Includes additional information about the Members loop Ajax response.
     535 *
     536 * @since 10.0.0
     537 *
     538 * @param array $additional_info An associative array with additional information to include in the Ajax response.
     539 * @param array $args            The Ajax query arguments.
     540 * @return array                 Additional information about the members loop.
     541 */
     542function bp_nouveau_members_loop_additional_info( $additional_info = array(), $args = array() ) {
     543        if ( ! isset( $GLOBALS['members_template'] ) || ! $GLOBALS['members_template'] ) {
     544                return $additional_info;
     545        }
     546
     547        $members_template = $GLOBALS['members_template'];
     548
     549        if ( isset( $members_template->member_count ) && 'all' === $args['scope'] ) {
     550                $additional_info['totalItems'] = bp_core_number_format( $members_template->member_count );
     551                $additional_info['navLabel']   = esc_html__( 'All Members', 'buddypress' );
     552
     553                $nav_labels = array(
     554                        'active' => esc_html__( 'Active Members', 'buddypress' ),
     555                        'newest' => esc_html__( 'Newest Members', 'buddypress' ),
     556                );
     557
     558                if ( isset( $nav_labels[ $args['filter'] ] ) ) {
     559                        $additional_info['navLabel'] = $nav_labels[ $args['filter'] ];
     560                }
     561        }
     562
     563        return $additional_info;
     564}
     565add_filter( 'bp_nouveau_members_ajax_object_template_response', 'bp_nouveau_members_loop_additional_info', 10, 2 );
  • trunk/src/bp-templates/bp-nouveau/js/buddypress-nouveau.js

    r12890 r13136  
    307307                                }
    308308
    309                                 $( self.objectNavParent + ' [data-bp-scope="' + data.scope + '"]' ).removeClass( 'loading' );
     309                                var selectedObjectNavParent = $( self.objectNavParent + ' [data-bp-scope="' + data.scope + '"]' );
     310
     311                                selectedObjectNavParent.removeClass( 'loading' );
     312
     313                                if ( response.data && response.data.totalItems && response.data.navLabel ) {
     314                                        selectedObjectNavParent.find( 'a' ).first().html(
     315                                                response.data.navLabel + ' '
     316                                        ).append( $( '<span></span>' ).addClass( 'count' ).html( response.data.totalItems ) );
     317                                }
    310318
    311319                                if ( 'reset' !== data.method ) {
Note: See TracChangeset for help on using the changeset viewer.