Skip to:
Content

BuddyPress.org


Ignore:
Timestamp:
06/01/2024 05:06:17 PM (11 months 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

File:
1 edited

Legend:

Unmodified
Added
Removed
  • 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;
Note: See TracChangeset for help on using the changeset viewer.