Skip to:
Content

BuddyPress.org

Changeset 13883


Ignore:
Timestamp:
06/01/2024 05:06:17 PM (2 years ago)
Author:
espellcaste
Message:

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

Closes https://github.com/buddypress/buddypress/pull/304
See #9164 and #7228

Location:
trunk/src/bp-core
Files:
3 edited

Legend:

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

    r13877 r13883  
    1717 *
    1818 * @param string $type_taxonomy The type's taxonomy name.
    19  * @return array                Default values for the taxonomy registered metadata.
     19 * @return array Default values for the taxonomy registered metadata.
    2020 */
    2121function bp_core_admin_get_type_default_meta_values( $type_taxonomy ) {
     
    4040 * @since 7.0.0
    4141 *
    42  * @param array  $args {
     42 * @param array $args {
    4343 *     Array of arguments describing the object type.
    4444 *
     
    6363
    6464        if ( ! $args['bp_type_id'] || ! $args['taxonomy'] ) {
    65                  return new WP_Error(
    66                          'invalid_type_taxonomy',
    67                          __( 'The Type ID value is missing', 'buddypress' ),
    68                          array(
    69                                 'message' => 1,
    70                          )
     65                return new WP_Error(
     66                        'invalid_type_taxonomy',
     67                        __( 'The Type ID value is missing', 'buddypress' ),
     68                        array( 'message' => 1 )
    7169                );
    7270        }
     
    8078         * @since 7.0.0
    8179         *
    82          * @param boolean $value  True if the type exists. False otherwise.
    83          * @param string  $type_id The Type's ID.
     80         * @param boolean $existing_type True if the type exists. False otherwise.
     81         * @param string  $type_id       The Type's ID.
    8482         */
    8583        $type_exists = apply_filters( "{$type_taxonomy}_check_existing_type", false, $type_id );
     
    8987                        'type_already_exists',
    9088                        __( 'The Type already exists', 'buddypress' ),
    91                         array(
    92                            'message' => 5,
    93                         )
    94            );
     89                        array( 'message' => 5 )
     90                );
    9591        }
    9692
     
    9894        $metadata = bp_core_admin_get_type_default_meta_values( $type_taxonomy );
    9995
    100         // Validate metadata
     96        // Validate metadata.
    10197        $metas = array_filter( array_intersect_key( $args, $metadata ) );
    10298
     
    141137 * @since 7.0.0
    142138 *
    143  * @param array  $args {
     139 * @param array $args {
    144140 *     Array of arguments describing the object type.
    145141 *
     
    164160
    165161        if ( ! $args['type_term_id'] || ! $args['taxonomy'] ) {
    166                  return new WP_Error(
    167                          'invalid_type_taxonomy',
    168                          __( 'The Term Type ID value is missing', 'buddypress' ),
    169                          array(
    170                                 'message' => 10,
    171                         )
     162                return new WP_Error(
     163                        'invalid_type_taxonomy',
     164                        __( 'The Term Type ID value is missing', 'buddypress' ),
     165                        array( 'message' => 10 )
    172166                );
    173167        }
     
    177171
    178172        // Get default values for metadata.
    179         $metadata  = bp_core_admin_get_type_default_meta_values( $type_taxonomy );
     173        $metadata = bp_core_admin_get_type_default_meta_values( $type_taxonomy );
    180174
    181175        // Merge customs with defaults.
     
    215209 * @since 7.0.0
    216210 *
    217  * @param array  $args {
     211 * @param array $args {
    218212 *     Array of arguments describing the object type.
    219213 *
     
    237231
    238232        if ( ! $args['type_term_id'] || ! $args['taxonomy'] ) {
    239                  return new WP_Error(
    240                          'invalid_type_taxonomy',
    241                          __( 'The Term Type ID value is missing', 'buddypress' ),
    242                          array(
    243                                 'message' => 10,
    244                         )
     233                return new WP_Error(
     234                        'invalid_type_taxonomy',
     235                        __( 'The Term Type ID value is missing', 'buddypress' ),
     236                        array( 'message' => 10 )
    245237                );
    246238        }
     
    254246                        'type_doesnotexist',
    255247                        __( 'The type was not deleted: it does not exist.', 'buddypress' ),
    256                         array(
    257                            'message' => 6,
    258                         )
     248                        array( 'message' => 6 )
    259249                );
    260250        }
     
    267257                        'type_register_by_code',
    268258                        __( 'This type is registered using code, deactivate the plugin or remove the custom code before trying to delete it again.', 'buddypress' ),
    269                         array(
    270                            'message' => 7,
    271                         )
     259                        array( 'message' => 7 )
    272260                );
    273261        }
     
    279267                        'type_not_deleted',
    280268                        __( 'There was an error while trying to delete this type.', 'buddypress' ),
    281                         array(
    282                            'message' => 8,
    283                         )
     269                        array( 'message' => 8 )
    284270                );
    285271        }
  • trunk/src/bp-core/classes/class-bp-admin-types.php

    r13877 r13883  
    1111defined( 'ABSPATH' ) || exit;
    1212
    13 if ( ! class_exists( 'BP_Admin_Types' ) ) :
     13if ( class_exists( 'BP_Admin_Types' ) ) {
     14        return;
     15}
    1416
    1517/**
     
    3133         *
    3234         * @since 7.0.0
    33          * @var array()
     35         * @var array
    3436         */
    3537        public $taxonomies = array();
     
    7274         * @since 7.0.0
    7375         *
    74          * @return BP_Admin_Types
     76         * @return BP_Admin_Types|null The BP Types Admin object or null if not in admin.
    7577         */
    7678        public static function register_types_admin() {
     
    8284
    8385                if ( empty( $bp->core->types_admin ) ) {
    84                         $bp->core->types_admin = new self;
     86                        $bp->core->types_admin = new self();
    8587                }
    8688
     
    128130                add_action( "{$this->taxonomy}_edit_form_fields", array( $this, 'edit_form_fields' ), 10, 2 );
    129131
    130                 // Filters
     132                // Filters.
    131133                add_filter( 'bp_core_admin_register_scripts', array( $this, 'register_scripts' ) );
    132134                add_filter( "manage_{$this->screen_id}_columns", array( $this, 'column_headers' ), 10, 1 );
     
    260262         * Override the Admin parent file to highlight the right menu.
    261263         *
     264         * @global string $parent_file The parent file of the current admin screen.
     265         *
    262266         * @since 7.0.0
    263267         */
     
    276280         *
    277281         * @since 7.0.0
     282         *
     283         * @param array $scripts The registered scripts.
    278284         */
    279285        public function register_scripts( $scripts = array() ) {
     
    327333
    328334                // Default values for the Type ID field.
    329                 $type_id_label   = __( 'Type ID', 'buddypress' );
    330                 $type_id_desc    = __( 'Enter a lower-case string without spaces or special characters (used internally to identify the type).', 'buddypress' );
     335                $type_id_label = __( 'Type ID', 'buddypress' );
     336                $type_id_desc  = __( 'Enter a lower-case string without spaces or special characters (used internally to identify the type).', 'buddypress' );
    331337
    332338                if ( isset( $labels->bp_type_id_label ) && $labels->bp_type_id_label ) {
     
    374380                                        sprintf(
    375381                                                /* translators: %s is the name of the Type meta key */
    376                                                 esc_html__( 'As a result, the form elements for the "%s" meta key cannot be displayed', 'buddypress' ), esc_html( $meta_key ) ),
     382                                                esc_html__( 'As a result, the form elements for the "%s" meta key cannot be displayed', 'buddypress' ),
     383                                                esc_html( $meta_key )
     384                                        ),
    377385                                        '7.0.0'
    378386                                );
     
    389397                                                        $type_prop_value = $type->labels[ $type_key ];
    390398                                                }
    391 
    392399                                        } elseif ( isset( $type->{$type_key} ) ) {
    393400                                                $type_prop_value = $type->{$type_key};
     
    407414                                                esc_html( $meta_schema['description'] )
    408415                                        );
    409 
    410416                                } else {
    411417                                        printf(
     
    420426                                        );
    421427                                }
     428                        } elseif ( isset( $type->name ) ) {
     429                                $checked = '';
     430                                if ( isset( $type->{$type_key} ) && true === (bool) $type->{$type_key} ) {
     431                                        $checked = ' checked="checked"';
     432                                }
     433
     434                                printf(
     435                                        '<tr class="form-field bp-types-form term-%1$s-wrap">
     436                                                <th scope="row"><label for="%1$s">%2$s</label></th>
     437                                                <td>
     438                                                        <input name="%1$s" id="%1$s" type="checkbox" value="1"%3$s> %4$s
     439                                                        <p class="description">%5$s</p>
     440                                                </td>
     441                                        </tr>',
     442                                        esc_attr( $meta_key ),
     443                                        esc_html( $labels->{ $meta_key } ),
     444                                        // phpcs:ignore WordPress.Security.EscapeOutput
     445                                        $checked,
     446                                        esc_html__( 'Yes', 'buddypress' ),
     447                                        esc_html( $meta_schema['description'] )
     448                                );
    422449                        } else {
    423                                 if ( isset( $type->name ) ) {
    424                                         $checked = '';
    425                                         if ( isset( $type->{$type_key} ) && true === (bool) $type->{$type_key} ) {
    426                                                 $checked = ' checked="checked"';
    427                                         }
    428 
    429                                         printf(
    430                                                 '<tr class="form-field bp-types-form term-%1$s-wrap">
    431                                                         <th scope="row"><label for="%1$s">%2$s</label></th>
    432                                                         <td>
    433                                                                 <input name="%1$s" id="%1$s" type="checkbox" value="1"%3$s> %4$s
    434                                                                 <p class="description">%5$s</p>
    435                                                         </td>
    436                                                 </tr>',
    437                                                 esc_attr( $meta_key ),
    438                                                 esc_html( $labels->{ $meta_key } ),
    439                                                 // phpcs:ignore WordPress.Security.EscapeOutput
    440                                                 $checked,
    441                                                 esc_html__( 'Yes', 'buddypress' ),
    442                                                 esc_html( $meta_schema['description'] )
    443                                         );
    444                                 } else {
    445                                         printf(
    446                                                 '<div class="form-field bp-types-form term-%1$s-wrap">
    447                                                         <label for="%1$s">
    448                                                                 <input name="%1$s" id="%1$s" type="checkbox" value="1"> %2$s
    449                                                         </label>
    450                                                         <p>%3$s</p>
    451                                                 </div>',
    452                                                 esc_attr( $meta_key ),
    453                                                 esc_html( $labels->{ $meta_key } ),
    454                                                 esc_html( $meta_schema['description'] )
    455                                         );
    456                                 }
     450                                printf(
     451                                        '<div class="form-field bp-types-form term-%1$s-wrap">
     452                                                <label for="%1$s">
     453                                                        <input name="%1$s" id="%1$s" type="checkbox" value="1"> %2$s
     454                                                </label>
     455                                                <p>%3$s</p>
     456                                        </div>',
     457                                        esc_attr( $meta_key ),
     458                                        esc_html( $labels->{ $meta_key } ),
     459                                        esc_html( $meta_schema['description'] )
     460                                );
    457461                        }
    458462                }
     
    464468         * @since 7.0.0
    465469         *
    466          * @param WP_Term $term     The term object for the BP Type.
    467          * @param string  $taxonomy The type taxonomy name.
    468          * @return string           HTML Output.
     470         * @param WP_Term|null $term     The term object for the BP Type.
     471         * @param string       $taxonomy The type taxonomy name.
    469472         */
    470473        public function edit_form_fields( $term = null, $taxonomy = '' ) {
     
    489492                }
    490493
    491                 return $this->add_form_fields( $taxonomy, $type );
     494                $this->add_form_fields( $taxonomy, $type );
    492495        }
    493496
     
    497500         * @since 7.0.0
    498501         *
    499          * @param array  $column_headers The column header labels keyed by column ID.
    500          * @return array                 The column header labels keyed by column ID.
     502         * @param array $column_headers The column header labels keyed by column ID.
     503         * @return arrayThe column header labels keyed by column ID.
    501504         */
    502505        public function column_headers( $column_headers = array() ) {
     
    518521         * @since 7.0.0
    519522         *
    520          * @param string  $string      Blank string.
    521          * @param string  $column_name Name of the column.
    522          * @param int     $type_id     The type's term ID.
    523          * @return string              The Type Plural name.
     523         * @param string $column_content The column content.
     524         * @param string $column_name    Name of the column.
     525         * @param int    $type_id        The type's term ID.
     526         * @return string|null|int
    524527         */
    525528        public function column_contents( $column_content = '', $column_name = '', $type_id = 0 ) {
     
    543546                                 * @since 7.0.0
    544547                                 *
    545                                  * @param string $value Metadata for the BP Type.
     548                                 * @param string $meta_data Metadata for the BP Type.
     549                                 * @param string $type_name The BP Type name.
    546550                                 */
    547551                                $metadata = apply_filters( "{$this->taxonomy}_set_registered_by_code_metada", array(), $type_name );
     
    557561                } elseif ( 'counts' === $column_name ) {
    558562                        global $parent_file;
    559                         $type  = bp_get_term_by( 'id', $type_id, $this->taxonomy );
     563                        $type = bp_get_term_by( 'id', $type_id, $this->taxonomy );
    560564                        if ( 0 === (int) $type->count ) {
    561565                                return 0;
     
    587591         * @since 7.0.0
    588592         *
    589          * @param array   $actions The table row actions.
    590          * @param WP_Term $type    The current BP Type for the row.
    591          * @return array           The table row actions for the current BP type.
     593         * @param array        $actions The table row actions.
     594         * @param WP_Term|null $type    The current BP Type for the row.
     595         * @return array The table row actions for the current BP type.
    592596         */
    593597        public function row_actions( $actions = array(), $type = null ) {
     
    602606                 *
    603607                 * @since 7.0.0
     608                 *
     609                 * @param array        $registered_by_code_types The types registered by code.
     610                 * @param WP_Term|null $type                     The current BP Type for the row.
    604611                 */
    605                 $registered_by_code_types = apply_filters( "{$type->taxonomy}_registered_by_code", array() );
     612                $registered_by_code_types = apply_filters( "{$type->taxonomy}_registered_by_code", array(), $type );
    606613
    607614                // Types registered by code cannot be deleted as long as the custom registration code exists.
     
    621628        }
    622629}
    623 
    624 endif;
  • trunk/src/bp-core/classes/class-bp-admin.php

    r13878 r13883  
    1111defined( 'ABSPATH' ) || exit;
    1212
    13 if ( !class_exists( 'BP_Admin' ) ) :
     13if ( class_exists( 'BP_Admin' ) ) {
     14        return;
     15}
    1416
    1517/**
     
    2931         *
    3032         * @since 1.6.0
    31          * @var string $admin_dir
     33         * @var string
    3234         */
    3335        public $admin_dir = '';
     
    3739        /**
    3840         * URL to the BuddyPress admin directory.
    39          *
    40          * @since 1.6.0
    41          * @var string $admin_url
    42          */
    43         public $admin_url = '';
    44 
    45         /**
    46          * URL to the BuddyPress images directory.
    47          *
    48          * @since 1.6.0
    49          * @var string $images_url
    50          */
    51         public $images_url = '';
    52 
    53         /**
    54          * URL to the BuddyPress admin CSS directory.
    55          *
    56          * @since 1.6.0
    57          * @var string $css_url
    58          */
    59         public $css_url = '';
    60 
    61         /**
    62          * URL to the BuddyPress admin JS directory.
    6341         *
    6442         * @since 1.6.0
    6543         * @var string
    6644         */
     45        public $admin_url = '';
     46
     47        /**
     48         * URL to the BuddyPress images directory.
     49         *
     50         * @since 1.6.0
     51         * @var string
     52         */
     53        public $images_url = '';
     54
     55        /**
     56         * URL to the BuddyPress admin CSS directory.
     57         *
     58         * @since 1.6.0
     59         * @var string
     60         */
     61        public $css_url = '';
     62
     63        /**
     64         * URL to the BuddyPress admin JS directory.
     65         *
     66         * @since 1.6.0
     67         * @var string
     68         */
    6769        public $js_url = '';
    6870
     
    7375         *
    7476         * @since 1.9.0
    75          * @var array()
     77         * @var array
    7678         */
    7779        public $notices = array();
     
    8183         *
    8284         * @since 10.0.0
    83          * @var array()
     85         * @var array
    8486         */
    8587        public $nav_tabs = array();
     
    8991         *
    9092         * @since 10.0.0
    91          * @var string()
     93         * @var string
    9294         */
    9395        public $active_nav_tab = '';
     
    9799         *
    98100         * @since 10.0.0
    99          * @var array()
     101         * @var array
    100102         */
    101103        public $submenu_pages = array();
     
    107109         *
    108110         * @since 1.6.0
    109          *
    110111         */
    111112        public function __construct() {
     
    123124                $bp = buddypress();
    124125
    125                 // Paths and URLs
    126                 $this->admin_dir  = trailingslashit( $bp->plugin_dir  . 'bp-core/admin' ); // Admin path.
    127                 $this->admin_url  = trailingslashit( $bp->plugin_url  . 'bp-core/admin' ); // Admin url.
    128                 $this->images_url = trailingslashit( $this->admin_url . 'images'        ); // Admin images URL.
    129                 $this->css_url    = trailingslashit( $this->admin_url . 'css'           ); // Admin css URL.
    130                 $this->js_url     = trailingslashit( $this->admin_url . 'js'            ); // Admin css URL.
     126                // Paths and URLs.
     127                $this->admin_dir  = trailingslashit( $bp->plugin_dir . 'bp-core/admin' ); // Admin path.
     128                $this->admin_url  = trailingslashit( $bp->plugin_url . 'bp-core/admin' ); // Admin url.
     129                $this->images_url = trailingslashit( $this->admin_url . 'images' ); // Admin images URL.
     130                $this->css_url    = trailingslashit( $this->admin_url . 'css' ); // Admin css URL.
     131                $this->js_url     = trailingslashit( $this->admin_url . 'js' ); // Admin css URL.
    131132
    132133                // Main settings page.
     
    159160         *
    160161         * @since 1.6.0
    161          *
    162162         */
    163163        private function setup_actions() {
     
    166166
    167167                // Add some page specific output to the <head>.
    168                 add_action( 'bp_admin_head',            array( $this, 'admin_head'  ), 999 );
     168                add_action( 'bp_admin_head',            array( $this, 'admin_head' ), 999 );
    169169
    170170                // Add menu item to settings menu.
     
    225225                add_filter( 'user_row_actions',    'bp_core_admin_user_row_actions', 10, 2 );
    226226
    227                 // Emails
     227                // Emails.
    228228                add_filter( 'bp_admin_menu_order', array( $this, 'emails_admin_menu_order' ), 20 );
    229229                add_action( 'load-edit.php', array( $this, 'post_type_load_admin_screen' ), 20 );
     
    232232                // Official BuddyPress supported Add-ons.
    233233                add_filter( 'install_plugins_tabs', array( $this, 'addons_tab' ) );
    234                 add_filter( 'install_plugins_table_api_args_bp-add-ons', array( $this,'addons_args' ) );
     234                add_filter( 'install_plugins_table_api_args_bp-add-ons', array( $this, 'addons_args' ) );
    235235        }
    236236
     
    320320
    321321                $this->submenu_pages['settings']['bp-admin-notifications'] = $bp_admin_notifications;
    322                 $hooks[]                                                   = $bp_admin_notifications;
     322                $hooks[] = $bp_admin_notifications;
    323323
    324324                // Credits.
     
    477477         *
    478478         * @since 1.6.0
    479          *
    480479         */
    481480        public function register_admin_settings() {
     
    490489                register_setting( 'buddypress', 'hide-loggedout-adminbar', 'intval' );
    491490
    492                 // Community Visibility
     491                // Community Visibility.
    493492                if ( 'rewrites' === bp_core_get_query_parser() ) {
    494493                        add_settings_field( '_bp_community_visibility', __( 'Community Visibility', 'buddypress' ), 'bp_admin_setting_callback_community_visibility', 'buddypress', 'bp_main' );
     
    547546                        // Profile sync setting.
    548547                        add_settings_field( 'bp-disable-profile-sync',   __( 'Profile Syncing',  'buddypress' ), 'bp_admin_setting_callback_profile_sync', 'buddypress', 'bp_xprofile' );
    549                         register_setting  ( 'buddypress', 'bp-disable-profile-sync', 'intval' );
     548                        register_setting( 'buddypress', 'bp-disable-profile-sync', 'intval' );
    550549                }
    551550
     
    612611                }
    613612
    614                 $wp_admin_bar->add_node( array(
    615                         'parent' => 'wp-logo',
    616                         'id'     => 'bp-about',
    617                         'title'  => esc_html_x( 'Hello, BuddyPress!', 'Colloquial alternative to "learn about BuddyPress"', 'buddypress' ),
    618                         'href'   => bp_get_admin_url( '?hello=buddypress' ),
    619                         'meta'   => array(
    620                                 'class' => 'say-hello-buddypress',
    621                         ),
    622                 ) );
     613                $wp_admin_bar->add_node(
     614                        array(
     615                                'parent' => 'wp-logo',
     616                                'id'     => 'bp-about',
     617                                'title'  => esc_html_x( 'Hello, BuddyPress!', 'Colloquial alternative to "learn about BuddyPress"', 'buddypress' ),
     618                                'href'   => bp_get_admin_url( '?hello=buddypress' ),
     619                                'meta'   => array(
     620                                        'class' => 'say-hello-buddypress',
     621                                ),
     622                        )
     623                );
    623624        }
    624625
     
    635636
    636637                // Return normal links if not BuddyPress.
    637                 if ( plugin_basename( buddypress()->basename ) != $file ) {
     638                if ( plugin_basename( buddypress()->basename ) !== $file ) {
    638639                        return $links;
    639640                }
     
    780781
    781782                // Get BuddyPress stable version.
    782                 $version      =  self::display_version();
     783                $version      = self::display_version();
    783784                $version_slug = 'version-' . str_replace( '.', '-', $version );
    784785
     
    824825                                                <h2>
    825826                                                        <?php
    826                                                         printf(
     827                                                                printf(
    827828                                                                        /* Translators: %s is a raising hands emoji. */
    828829                                                                        esc_html__( 'You now have complete control over all BuddyPress-generated URLs %s', 'buddypress' ),
     
    895896                                                <h2>
    896897                                                        <?php
    897                                                         printf(
     898                                                                printf(
    898899                                                                        /* Translators: %s is a woman supervillain emoji. */
    899900                                                                        esc_html__( 'Here\'s another benefit of the BP Rewrites API: the new "members only" community visibility level %s', 'buddypress' ),
     
    966967                                                                'span' => array(
    967968                                                                        'class' => true,
    968                                                                 )
     969                                                                ),
    969970                                                        )
    970971                                                );
     
    12841285                $taxonomy_object = get_taxonomy( bp_get_email_tax_type() );
    12851286
    1286                 if ( is_wp_error( $terms ) || ! $terms  ) {
     1287                if ( is_wp_error( $terms ) || ! $terms ) {
    12871288                        printf( '<span aria-hidden="true">&#8212;</span><span class="screen-reader-text">%s</span>', esc_html( $taxonomy_object->labels->no_terms ) );
    12881289                } else {
     
    13481349
    13491350                        // Check for prerelease hyphen.
    1350                         $pre     = strpos( $version, '-' );
     1351                        $pre = strpos( $version, '-' );
    13511352
    13521353                        // Strip prerelease suffix.
     
    15711572                                        }
    15721573                                        %2$s',
    1573                                         implode( " ", $grid_columns ),
     1574                                        implode( ' ', $grid_columns ),
    15741575                                        $help_tab_css
    15751576                                )
     
    16121613         * @global int $paged The current page of the Plugin results.
    16131614         *
    1614          * @param false|array $args  `false` by default.
    1615          * @return array             The "BuddyPress add-ons" args.
    1616          */
    1617         public function addons_args( $args = false ) {
     1615         * @return array The "BuddyPress add-ons" args.
     1616         */
     1617        public function addons_args() {
    16181618                global $paged;
    16191619
     
    16861686        }
    16871687}
    1688 endif; // End class_exists check.
Note: See TracChangeset for help on using the changeset viewer.