Skip to:
Content

BuddyPress.org


Ignore:
Timestamp:
07/27/2024 06:44:41 PM (12 months ago)
Author:
espellcaste
Message:

Require singular and plural names for BuddyPress custom types.

When creating a member or group type, require that both singular and plural names are provided. This ensures that the type can be properly registered and used throughout BuddyPress.

Props 1naveengiri, imath, imranmd.

Fixes #9092
Closes https://github.com/buddypress/buddypress/pull/335/

File:
1 edited

Legend:

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

    r13890 r13983  
    4545 *     @type string $taxonomy   The Type's taxonomy. Required.
    4646 *     @type string $bp_type_id Unique string identifier for the member type. Required.
     47 *     @type string $bp_type_singular_name Singular name for the member type. Required.
     48 *     @type string $bp_type_name Plural name for the member type. Required.
    4749 *     @see keys of the array returned by bp_get_type_metadata_schema() for the other arguments.
    4850 * }
    49  * @return integer|WP_Error The Type's term ID on success. A WP_Error object otherwise.
     51 * @return int|WP_Error The Type's term ID on success. A WP_Error object otherwise.
    5052 */
    5153function bp_core_admin_insert_type( $args = array() ) {
     
    5355        'taxonomy'   => '',
    5456        'bp_type_id' => '',
     57        'bp_type_singular_name' => '',
     58        'bp_type_name' => '',
    5559    );
    5660
     
    6771            __( 'The Type ID value is missing', 'buddypress' ),
    6872            array( 'message' => 1 )
     73        );
     74    }
     75
     76    if ( ! $args['bp_type_singular_name'] ) {
     77        return new WP_Error(
     78            'empty_field_singular',
     79            __( 'The Singular Name value is missing', 'buddypress' ),
     80            array(
     81                'message' => 11,
     82            )
     83        );
     84    }
     85
     86    if ( ! $args['bp_type_name'] ) {
     87        return new WP_Error(
     88            'empty_field_plural',
     89            __( 'The Plural Name value is missing', 'buddypress' ),
     90            array(
     91                'message' => 12,
     92            )
    6993        );
    7094    }
     
    117141    }
    118142
     143    $type_term_id = reset( $type_term_id );
     144
    119145    /**
    120146     * Hook here to add code once the type has been inserted.
Note: See TracChangeset for help on using the changeset viewer.