Skip to:
Content

BuddyPress.org


Ignore:
Timestamp:
06/04/2024 02:32:30 AM (21 months ago)
Author:
espellcaste
Message:

WPCS: Part XI: miscellaneous fixes for some of the files of the core component.

Follow-up to [13903]

See #9164 and #7228

File:
1 edited

Legend:

Unmodified
Added
Removed
  • trunk/src/bp-core/bp-core-filters.php

    r13878 r13904  
    4141 *           v--WordPress Actions       v--BuddyPress Sub-actions
    4242 */
    43 add_filter( 'request',                 'bp_request',             10    );
    44 add_filter( 'template_include',        'bp_template_include',    10    );
    45 add_filter( 'login_redirect',          'bp_login_redirect',      10, 3 );
    46 add_filter( 'map_meta_cap',            'bp_map_meta_caps',      10, 4 );
     43add_filter( 'request', 'bp_request', 10 );
     44add_filter( 'template_include', 'bp_template_include', 10 );
     45add_filter( 'login_redirect', 'bp_login_redirect', 10, 3 );
     46add_filter( 'map_meta_cap', 'bp_map_meta_caps', 10, 4 );
    4747
    4848// Add some filters to feedback messages.
    49 add_filter( 'bp_core_render_message_content', 'wptexturize'       );
    50 add_filter( 'bp_core_render_message_content', 'convert_smilies'   );
    51 add_filter( 'bp_core_render_message_content', 'convert_chars'     );
    52 add_filter( 'bp_core_render_message_content', 'wpautop'           );
     49add_filter( 'bp_core_render_message_content', 'wptexturize' );
     50add_filter( 'bp_core_render_message_content', 'convert_smilies' );
     51add_filter( 'bp_core_render_message_content', 'convert_chars' );
     52add_filter( 'bp_core_render_message_content', 'wpautop' );
    5353add_filter( 'bp_core_render_message_content', 'shortcode_unautop' );
    54 add_filter( 'bp_core_render_message_content', 'wp_kses_data', 5   );
     54add_filter( 'bp_core_render_message_content', 'wp_kses_data', 5 );
    5555
    5656// Emails.
     
    7070 * bp_template_include() works and do something similar. :)
    7171 */
    72 add_filter( 'bp_template_include',   'bp_template_include_theme_supports', 2, 1 );
    73 add_filter( 'bp_template_include',   'bp_template_include_theme_compat',  4, 2 );
     72add_filter( 'bp_template_include', 'bp_template_include_theme_supports', 2, 1 );
     73add_filter( 'bp_template_include', 'bp_template_include_theme_compat', 4, 2 );
    7474
    7575// Filter BuddyPress template locations.
     
    132132
    133133    // Bail if not the root blog.
    134     if ( ! bp_is_root_blog() )
     134    if ( ! bp_is_root_blog() ) {
    135135        return $pages;
     136    }
    136137
    137138    $bp = buddypress();
    138139
    139     if ( !empty( $bp->pages->activate ) )
     140    if ( ! empty( $bp->pages->activate ) ) {
    140141        $pages[] = $bp->pages->activate->id;
    141 
    142     if ( !empty( $bp->pages->register ) )
     142    }
     143
     144    if ( ! empty( $bp->pages->register ) ) {
    143145        $pages[] = $bp->pages->register->id;
     146    }
    144147
    145148    /**
     
    169172    }
    170173
    171     if ( 'page' != $object->name ) {
     174    if ( 'page' !== $object->name ) {
    172175        return $object;
    173176    }
    174177
    175     $bp = buddypress();
     178    $bp    = buddypress();
    176179    $pages = array();
    177180
     
    270273
    271274    // Get the WP page.
    272     $page   = get_post( $item->object_id );
     275    $page = get_post( $item->object_id );
    273276
    274277    // See if we should add our highlight CSS classes for the page.
     
    285288 *
    286289 * @param array $comments The array of comments supplied to the comments template.
    287  * @param int   $post_id  The post ID.
    288290 * @return array $comments The modified comment array.
    289291 */
    290 function bp_core_filter_comments( $comments, $post_id ) {
     292function bp_core_filter_comments( $comments ) {
    291293    global $wpdb;
    292294
     
    303305    $user_ids = implode( ',', wp_parse_id_list( $user_ids ) );
    304306
    305     if ( ! $userdata = $wpdb->get_results( "SELECT ID as user_id, user_login, user_nicename FROM {$wpdb->users} WHERE ID IN ({$user_ids})" ) ) {
     307    $userdata = $wpdb->get_results( "SELECT ID as user_id, user_login, user_nicename FROM {$wpdb->users} WHERE ID IN ({$user_ids})" );
     308    if ( ! $userdata ) {
    306309        return $comments;
    307310    }
    308311
    309312    foreach ( (array) $userdata as $user ) {
    310         $users[$user->user_id] = bp_members_get_user_url( $user->user_id );
     313        $users[ $user->user_id ] = bp_members_get_user_url( $user->user_id );
    311314    }
    312315
    313316    foreach ( (array) $comments as $i => $comment ) {
    314317        if ( ! empty( $comment->user_id ) ) {
    315             if ( ! empty( $users[$comment->user_id] ) ) {
    316                 $comments[$i]->comment_author_url = $users[$comment->user_id];
     318            if ( ! empty( $users[ $comment->user_id ] ) ) {
     319                $comments[ $i ]->comment_author_url = $users[ $comment->user_id ];
    317320            }
    318321        }
     
    321324    return $comments;
    322325}
    323 add_filter( 'comments_array', 'bp_core_filter_comments', 10, 2 );
     326add_filter( 'comments_array', 'bp_core_filter_comments' );
    324327
    325328/**
     
    339342
    340343    // Only modify the redirect if we're on the main BP blog.
    341     if ( !bp_is_root_blog() ) {
     344    if ( ! bp_is_root_blog() ) {
    342345        return $redirect_to;
    343346    }
    344347
    345348    // Only modify the redirect once the user is logged in.
    346     if ( !is_a( $user, 'WP_User' ) ) {
     349    if ( ! is_a( $user, 'WP_User' ) ) {
    347350        return $redirect_to;
    348351    }
     
    369372    // logged-in user has any business to conduct in the Dashboard before allowing the
    370373    // redirect to go through.
    371     if ( !empty( $redirect_to ) && ( false === strpos( $redirect_to, 'wp-admin' ) || user_can( $user, 'edit_posts' ) ) ) {
     374    if ( ! empty( $redirect_to ) && ( false === strpos( $redirect_to, 'wp-admin' ) || user_can( $user, 'edit_posts' ) ) ) {
    372375        return $redirect_to;
    373376    }
     
    400403function bp_email_plaintext_entity_decode( $retval, $prop, $transform ) {
    401404    switch ( $prop ) {
    402         case 'content_plaintext' :
    403         case 'subject' :
     405        case 'content_plaintext':
     406        case 'subject':
    404407            // Only decode if 'replace-tokens' is the current type.
    405408            if ( 'replace-tokens' === $transform ) {
     
    408411                return $retval;
    409412            }
    410             break;
    411 
    412         default :
     413        default:
    413414            return $retval;
    414             break;
    415415    }
    416416}
     
    435435
    436436    // Don't touch the email when a user is registered by the site admin.
    437     if ( ( is_admin() || is_network_admin() ) && buddypress()->members->admin->signups_page != get_current_screen()->id ) {
     437    if ( ( is_admin() || is_network_admin() ) && buddypress()->members->admin->signups_page !== get_current_screen()->id ) {
    438438        return $welcome_email;
    439439    }
     
    473473
    474474    // Don't touch the email when a user is registered by the site admin.
    475     if ( ( is_admin() || is_network_admin() ) && buddypress()->members->admin->signups_page != get_current_screen()->id ) {
     475    if ( ( is_admin() || is_network_admin() ) && buddypress()->members->admin->signups_page !== get_current_screen()->id ) {
    476476        return $welcome_email;
    477477    }
    478478
    479479    // Don't touch the email if we don't have a custom registration template.
    480     if ( ! bp_has_custom_signup_page() )
     480    if ( ! bp_has_custom_signup_page() ) {
    481481        return $welcome_email;
     482    }
    482483
    483484    // [User Set] Replaces $password in welcome email; Represents value set by user.
     
    506507function bp_core_activation_signup_blog_notification( $domain, $path, $title, $user, $user_email, $key ) {
    507508    $is_signup_resend = false;
    508     if ( is_admin() && buddypress()->members->admin->signups_page == get_current_screen()->id ) {
     509    if ( is_admin() && buddypress()->members->admin->signups_page === get_current_screen()->id ) {
    509510        // The admin is just approving/sending/resending the verification email.
    510511        $is_signup_resend = true;
     
    571572
    572573        // If the user is created from the WordPress Add User screen, don't send BuddyPress signup notifications.
    573         if( in_array( get_current_screen()->id, array( 'user', 'user-network' ) ) ) {
     574        if ( in_array( get_current_screen()->id, array( 'user', 'user-network' ), true ) ) {
    574575            // If the Super Admin want to skip confirmation email.
    575             if ( isset( $_POST[ 'noconfirmation' ] ) && is_super_admin() ) {
     576            if ( isset( $_POST['noconfirmation'] ) && is_super_admin() ) {
    576577                return false;
    577578
    578             // WordPress will manage the signup process.
     579                // WordPress will manage the signup process.
    579580            } else {
    580581                return $user;
    581582            }
    582583
    583         // The site admin is approving/resending from the "manage signups" screen.
    584         } elseif ( buddypress()->members->admin->signups_page == get_current_screen()->id ) {
     584            // The site admin is approving/resending from the "manage signups" screen.
     585        } elseif ( buddypress()->members->admin->signups_page === get_current_screen()->id ) {
    585586            /*
    586587             * There can be a case where the user was created without the skip confirmation
     
    599600    }
    600601
    601     $user_id = 0;
     602    $user_id     = 0;
    602603    $user_object = get_user_by( 'login', $user );
    603604    if ( $user_object ) {
     
    732733    return apply_filters( 'bp_modify_page_title', $new_title, $title, $sep, $seplocation );
    733734}
    734 add_filter( 'wp_title',             'bp_modify_page_title', 20, 3 );
    735 add_filter( 'bp_modify_page_title', 'wptexturize'                 );
    736 add_filter( 'bp_modify_page_title', 'convert_chars'               );
    737 add_filter( 'bp_modify_page_title', 'esc_html'                    );
     735add_filter( 'wp_title', 'bp_modify_page_title', 20, 3 );
     736add_filter( 'bp_modify_page_title', 'wptexturize' );
     737add_filter( 'bp_modify_page_title', 'convert_chars' );
     738add_filter( 'bp_modify_page_title', 'esc_html' );
    738739
    739740/**
     
    760761    // We don't need to sanitize this as WordPress will take care of it.
    761762    $bp_title = array(
    762         'title' => join( " $sep ", $bp_title_parts )
     763        'title' => join( " $sep ", $bp_title_parts ),
    763764    );
    764765
     
    799800            $menu_item->url  = $menu_item->guid;
    800801
    801             if ( ! in_array( array( 'bp-menu', 'bp-'. $menu_item->post_excerpt .'-nav' ), $menu_item->classes ) ) {
     802            if ( ! in_array( array( 'bp-menu', 'bp-' . $menu_item->post_excerpt . '-nav' ), $menu_item->classes ) ) {
    802803                $menu_item->classes[] = 'bp-menu';
    803                 $menu_item->classes[] = 'bp-'. $menu_item->post_excerpt .'-nav';
     804                $menu_item->classes[] = 'bp-' . $menu_item->post_excerpt . '-nav';
    804805            }
    805806        }
     
    812813
    813814    if ( is_array( $menu_classes ) ) {
    814         $menu_classes = implode( ' ', $menu_item->classes);
     815        $menu_classes = implode( ' ', $menu_item->classes );
    815816    }
    816817
     
    825826
    826827    switch ( $matches[1] ) {
    827         case 'login' :
     828        case 'login':
    828829            if ( is_user_logged_in() ) {
    829830                $menu_item->_invalid = true;
     
    834835            break;
    835836
    836         case 'logout' :
     837        case 'logout':
    837838            if ( ! is_user_logged_in() ) {
    838839                $menu_item->_invalid = true;
     
    844845
    845846        // Don't show the Register link to logged-in users.
    846         case 'register' :
     847        case 'register':
    847848            if ( is_user_logged_in() ) {
    848849                $menu_item->_invalid = true;
     
    867868        $menu_item->_invalid = true;
    868869
    869     // Highlight the current page.
     870        // Highlight the current page.
    870871    } else {
    871872        $current = bp_get_requested_url();
     
    930931 */
    931932function bp_customizer_nav_menus_set_item_types( $item_types = array() ) {
    932     $item_types = array_merge( $item_types, array(
    933         'bp_loggedin_nav' => array(
    934             'title'  => _x( 'BuddyPress (logged-in)', 'customizer menu section title', 'buddypress' ),
    935             'type'   => 'bp_nav',
    936             'object' => 'bp_loggedin_nav',
    937         ),
    938         'bp_loggedout_nav' => array(
    939             'title'  => _x( 'BuddyPress (logged-out)', 'customizer menu section title', 'buddypress' ),
    940             'type'   => 'bp_nav',
    941             'object' => 'bp_loggedout_nav',
    942         ),
    943     ) );
     933    $item_types = array_merge(
     934        $item_types,
     935        array(
     936            'bp_loggedin_nav'  => array(
     937                'title'  => _x( 'BuddyPress (logged-in)', 'customizer menu section title', 'buddypress' ),
     938                'type'   => 'bp_nav',
     939                'object' => 'bp_loggedin_nav',
     940            ),
     941            'bp_loggedout_nav' => array(
     942                'title'  => _x( 'BuddyPress (logged-out)', 'customizer menu section title', 'buddypress' ),
     943                'type'   => 'bp_nav',
     944                'object' => 'bp_loggedout_nav',
     945            ),
     946        )
     947    );
    944948
    945949    return $item_types;
     
    10531057        for ( $i = 0; $i < count( $quoted_matches[0] ); $i++ ) {
    10541058            $quote_pos = strpos( $q, '__QUOTE__' );
    1055             $q = substr_replace( $q, $quoted_matches[0][ $i ], $quote_pos, 9 );
     1059            $q         = substr_replace( $q, $quoted_matches[0][ $i ], $quote_pos, 9 );
    10561060        }
    10571061    }
     
    10831087 * @since 7.0.0
    10841088 *
    1085  * @string $content Content to inject attribute into.
     1089 * @param string $content Content to inject attribute into.
    10861090 * @return string
    10871091 */
     
    10911095    }
    10921096
    1093     $content = str_replace( '<img ',    '<img loading="lazy" ',    $content );
     1097    $content = str_replace( '<img ', '<img loading="lazy" ', $content );
    10941098    $content = str_replace( '<iframe ', '<iframe loading="lazy" ', $content );
    10951099
     
    11491153    preg_match_all( '#<a[^>]+>#i', $value, $links, PREG_SET_ORDER );
    11501154    foreach ( $links as $link ) {
    1151         $new_link = $link = array_shift( $link );
     1155        $link     = array_shift( $link );
     1156        $new_link = $link;
    11521157
    11531158        // Add/modify style property.
     
    12321237
    12331238    // Default values for tokens set conditionally below.
    1234     $tokens['email.preheader']     = '';
    1235     $tokens['recipient.email']     = '';
    1236     $tokens['recipient.name']      = '';
    1237     $tokens['recipient.username']  = '';
     1239    $tokens['email.preheader']    = '';
     1240    $tokens['recipient.email']    = '';
     1241    $tokens['recipient.name']     = '';
     1242    $tokens['recipient.username'] = '';
    12381243
    12391244    // Who is the email going to?
     
    13051310     * @param string $template Path to current template (probably single.php).
    13061311     */
    1307     $email_template = apply_filters( 'bp_core_render_email_template',
     1312    $email_template = apply_filters(
     1313        'bp_core_render_email_template',
    13081314        bp_locate_template( bp_email_get_template( get_queried_object() ), false ),
    13091315        $template
     
    13151321
    13161322    ob_start();
    1317     include( $email_template );
     1323    include $email_template;
    13181324    $template = ob_get_contents();
    13191325    ob_end_clean();
     
    13641370 */
    13651371function bp_get_post_type_link( $link = '', $post = null ) {
    1366     if (  'rewrites' === bp_core_get_query_parser() && 'buddypress' === get_post_type( $post ) ) {
     1372    if ( 'rewrites' === bp_core_get_query_parser() && 'buddypress' === get_post_type( $post ) ) {
    13671373        $bp_pages = (array) buddypress()->pages;
    13681374
Note: See TracChangeset for help on using the changeset viewer.