Skip to:
Content

BuddyPress.org

Changeset 12730


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

BP Types: make it possible to manage BP Types from the WP Admin

  • Introduces functions to handle BP Types insertion, modification and deletion.
  • Introduces a new JavaScript file to customize the default WP Terms Administration screens.
  • Introduces the BP_Admin_Types class to make it possible to manage any BP Types.
  • Adds the Member type's Administration screens.

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

See #7179
Fixes #7181

Location:
trunk/src
Files:
3 added
3 edited

Legend:

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

    r12725 r12730  
    175175        // BuddyPress Hello.
    176176        add_action( 'admin_footer', array( $this, 'about_screen' ) );
     177
     178        // BuddyPress Types administration.
     179        add_action( 'load-edit-tags.php', array( 'BP_Admin_Types', 'register_types_admin' ) );
    177180
    178181        /* Filters ***********************************************************/
  • trunk/src/bp-members/bp-members-admin.php

    r11360 r12730  
    1313// Load the BP Members admin.
    1414add_action( 'bp_init', array( 'BP_Members_Admin', 'register_members_admin' ) );
     15
     16/**
     17 * Create Users submenu to manage BuddyPress types.
     18 *
     19 * @since 7.0.0
     20 */
     21function bp_members_type_admin_menu() {
     22    if ( ! bp_is_root_blog() ) {
     23        return;
     24    }
     25
     26    if ( bp_is_network_activated() && is_network_admin() ) {
     27        // Adds a users.php submenu to go to the root blog Member types screen.
     28        $member_type_admin_url = add_query_arg( 'taxonomy', bp_get_member_type_tax_name(), get_admin_url( bp_get_root_blog_id(), 'edit-tags.php' ) );
     29
     30        add_submenu_page(
     31            'users.php',
     32            __( 'Member types', 'buddypress' ),
     33            __( 'Member types', 'buddypress' ),
     34            'bp_moderate',
     35            esc_url( $member_type_admin_url )
     36        );
     37
     38    } elseif ( ! is_network_admin() ) {
     39        add_submenu_page(
     40            'users.php',
     41            __( 'Member types', 'buddypress' ),
     42            __( 'Member types', 'buddypress' ),
     43            'bp_moderate',
     44            basename( add_query_arg( 'taxonomy', bp_get_member_type_tax_name(), bp_get_admin_url( 'edit-tags.php' ) ) )
     45        );
     46    }
     47}
     48add_action( 'bp_admin_menu', 'bp_members_type_admin_menu' );
     49
     50/**
     51 * Checks whether a member type already exists.
     52 *
     53 * @since 7.0.0
     54 *
     55 * @param  boolean $exists  True if the member type already exists. False otherwise.
     56 * @param  string  $type_id The member type identifier.
     57 * @return boolean          True if the member type already exists. False otherwise.
     58 */
     59function bp_members_type_admin_type_exists( $exists = false, $type_id = '' ) {
     60    if ( ! $type_id ) {
     61        return $exists;
     62    }
     63
     64    return ! is_null( bp_get_member_type_object( $type_id ) );
     65}
     66add_filter( bp_get_member_type_tax_name() . '_check_existing_type', 'bp_members_type_admin_type_exists', 1, 2 );
     67
     68/**
     69 * Set the feedback messages for the Member Types Admin actions.
     70 *
     71 * @since 7.0.0
     72 *
     73 * @param array  $messages The feedback messages.
     74 * @return array           The feedback messages including the ones for the Member Types Admin actions.
     75 */
     76function bp_members_type_admin_updated_messages( $messages = array() ) {
     77    $type_taxonomy = bp_get_member_type_tax_name();
     78
     79    $messages[ $type_taxonomy ] = array(
     80        0  => '',
     81        1  => __( 'Please define the Member Type ID field.', 'buddypress' ),
     82        2  => __( 'Member type successfully added.', 'buddypress' ),
     83        3  => __( 'Sorry, there was an error and the Member type wasn’t added.', 'buddypress' ),
     84        // The following one needs to be != 5.
     85        4  => __( 'Member type successfully updated.', 'buddypress' ),
     86        5  => __( 'Sorry, this Member type already exists.', 'buddypress' ),
     87        6  => __( 'Sorry, the Member type was not deleted: it does not exist.', 'buddypress' ),
     88        7  => __( 'Sorry, This Member type is registered using code, deactivate the plugin or remove the custom code before trying to delete it again.', 'buddypress' ),
     89        8  => __( 'Sorry, there was an error while trying to delete this Member type.', 'buddypress' ),
     90        9  => __( 'Member type successfully deleted.', 'buddypress' ),
     91        10 => __( 'Member type could not be updated due to missing required information.', 'buddypress' ),
     92    );
     93
     94    return $messages;
     95}
     96add_filter( 'term_updated_messages', 'bp_members_type_admin_updated_messages' );
  • trunk/src/class-buddypress.php

    r12698 r12730  
    593593            'BP_REST_Components_Endpoint'  => 'core',
    594594            'BP_REST_Attachments'          => 'core',
     595            'BP_Admin_Types'               => 'core',
    595596
    596597            'BP_Core_Friends_Widget'   => 'friends',
Note: See TracChangeset for help on using the changeset viewer.