Skip to:
Content

BuddyPress.org


Ignore:
Timestamp:
09/21/2020 01:09:16 AM (4 years ago)
Author:
imath
Message:

BP Types: introduce type metadata registration & add a Member type one

  • Introduces the bp_register_type_meta() function to register metadata for the Type taxonomies.
  • Introduces the bp_get_type_metadata_schema() to get common to all types metadata properties.
  • Adds the bp_register_type_metadata hook. Hook to it to register the Member type metadata.
  • Introduces the bp_get_default_taxonomies() to list the BuddyPress default taxonomies (BP Email & Member Type taxonomies).
  • Improves bp_register_default_taxonomies() so that it use the previous point new function.
  • Adds labels and arguments to the Member Type taxonomy.
  • Introduces the bp_get_taxonomy_common_args() to retrieve common BP Taxonomy arguments.
  • Introduces the bp_get_email_tax_type_args() & bp_get_member_type_tax_args() so that the BP Email & the Member type taxonomies use it to retrieve its arguments enjoying the previous point new function.

Props mercime, DJPaul, dcavins, boonebgorges, tw2113, sbrajesh

See #7179
See #7181

File:
1 edited

Legend:

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

    r12727 r12728  
    1616
    1717/**
     18 * Returns default BuddyPress taxonomies.
     19 *
     20 * @since 7.0.0
     21 *
     22 * @return array The BuddyPress default taxonomies.
     23 */
     24function bp_get_default_taxonomies() {
     25    $taxonomies = array(
     26        // Member Type.
     27        bp_get_member_type_tax_name() => array(
     28            'object'    => 'user',
     29            'component' => 'members',
     30            'args'      => bp_get_member_type_tax_args(),
     31        ),
     32        // Email type.
     33        bp_get_email_tax_type()       => array(
     34            'object'    => bp_get_email_post_type(),
     35            'component' => 'core',
     36            'args'      => bp_get_email_tax_type_args(),
     37        ),
     38    );
     39
     40    /**
     41     * This filter should only be used by built-in BuddyPress Components.
     42     *
     43     * @since 7.0.0
     44     *
     45     * @param array $taxonomies The taxonomy arguments used for WordPress registration.
     46     */
     47    return apply_filters( 'bp_get_default_taxonomies', $taxonomies );
     48}
     49
     50/**
    1851 * Register our default taxonomies.
    1952 *
     
    2154 */
    2255function bp_register_default_taxonomies() {
    23     // Member Type.
    24     register_taxonomy( bp_get_member_type_tax_name(), 'user', array(
    25         'public' => false,
    26     ) );
    27 
    28     // Email type.
    29     register_taxonomy(
    30         bp_get_email_tax_type(),
    31         bp_get_email_post_type(),
    32         apply_filters( 'bp_register_email_tax_type', array(
    33             'description'   => _x( 'BuddyPress email types', 'email type taxonomy description', 'buddypress' ),
    34             'labels'        => bp_get_email_tax_type_labels(),
    35             'meta_box_cb'   => 'bp_email_tax_type_metabox',
    36             'public'        => false,
    37             'query_var'     => false,
    38             'rewrite'       => false,
    39             'show_in_menu'  => false,
    40             'show_tagcloud' => false,
    41             'show_ui'       => bp_is_root_blog() && bp_current_user_can( 'bp_moderate' ),
    42         ) )
    43     );
     56    $taxonomies = bp_get_default_taxonomies();
     57
     58    foreach ( $taxonomies as $taxonomy_name => $taxonomy_params ) {
     59        if ( ! isset( $taxonomy_params['object'] ) || ! isset( $taxonomy_params['args'] ) ) {
     60            continue;
     61        }
     62
     63        register_taxonomy(
     64            $taxonomy_name,
     65            $taxonomy_params['object'],
     66            $taxonomy_params['args']
     67        );
     68    }
    4469}
    4570add_action( 'bp_register_taxonomies', 'bp_register_default_taxonomies' );
Note: See TracChangeset for help on using the changeset viewer.