Skip to:
Content

BuddyPress.org


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

BP Types: add functions to generate the Group types WP Admin screens

  • Adds labels and arguments to the Group Type taxonomy.
  • Adds the Group type's Administration screens.
  • Introduces the bp_groups_register_group_type_taxonomy() function to register the Group type's taxonomy and stop doing it from the BP_Groups_Component::register_taxonomies() method.
  • Introduces the bp_get_group_type_metadata_schema() to add custom metadata for the Group type's taxonomy.
  • Introduces the bp_get_group_types_registered_by_code() to only get Group types registered by code.
  • Stops using the hardcoded bp_group_type identifier in favor of the filterable bp_get_group_type_tax_name() function.
  • Updates the test_groups_get_type_should_not_return_unregistered_types() unit test to test_groups_registered_by_code_group_type_should_not_return_unregistered_types() to check the previous point new function.

Props mercime, DJPaul, dcavins, boonebgorges

Fixes #7179

File:
1 edited

Legend:

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

    r12725 r12731  
    1515
    1616// Include WP's list table class.
    17 if ( !class_exists( 'WP_List_Table' ) ) require( ABSPATH . 'wp-admin/includes/class-wp-list-table.php' );
     17if ( ! class_exists( 'WP_List_Table' ) ) {
     18    require ABSPATH . 'wp-admin/includes/class-wp-list-table.php';
     19}
    1820
    1921// The per_page screen option. Has to be hooked in extremely early.
    20 if ( is_admin() && ! empty( $_REQUEST['page'] ) && 'bp-groups' == $_REQUEST['page'] )
     22if ( is_admin() && ! empty( $_REQUEST['page'] ) && 'bp-groups' == $_REQUEST['page'] ) {
    2123    add_filter( 'set-screen-option', 'bp_groups_admin_screen_options', 10, 3 );
     24}
    2225
    2326/**
     
    4245}
    4346add_action( bp_core_admin_hook(), 'bp_groups_add_admin_menu' );
     47
     48/**
     49 * Redirects the user on the Goups network admin screen when BuddyPress is network activated.
     50 *
     51 * @since 7.0.0
     52 */
     53function bp_group_site_admin_network_admin_redirect() {
     54    wp_safe_redirect( add_query_arg( 'page', 'bp-groups', network_admin_url( 'admin.php' ) ) );
     55    exit();
     56}
     57
     58/**
     59 * Create Groups submenu to manage BuddyPress types.
     60 *
     61 * @since 7.0.0
     62 */
     63function bp_groups_admin_types_menu() {
     64    if ( ! bp_is_root_blog() ) {
     65        return;
     66    }
     67
     68    if ( bp_is_network_activated() && is_network_admin() ) {
     69        // Adds a 'bp-groups' submenu to go to the root blog Group types screen.
     70        $group_type_admin_url = add_query_arg( 'taxonomy', 'bp_group_type', get_admin_url( bp_get_root_blog_id(), 'edit-tags.php' ) );
     71        add_submenu_page(
     72            'bp-groups',
     73            __( 'Group types', 'buddypress' ),
     74            __( 'Group types', 'buddypress' ),
     75            'bp_moderate',
     76            esc_url( $group_type_admin_url )
     77        );
     78    } elseif ( ! is_network_admin() ) {
     79        if ( is_multisite() ) {
     80            // Adds a 'bp-groups' menu to the root blog menu.
     81            $redirect_hook = add_menu_page(
     82                _x( 'Groups', 'Admin Groups page title', 'buddypress' ),
     83                _x( 'Groups', 'Admin Groups menu', 'buddypress' ),
     84                'bp_moderate',
     85                'bp-groups',
     86                '__return_empty_string',
     87                'div'
     88            );
     89
     90            add_action( "load-{$redirect_hook}", 'bp_group_site_admin_network_admin_redirect' );
     91        }
     92
     93        // Add the submenu to manage Group Types.
     94        add_submenu_page(
     95            'bp-groups',
     96            __( 'Group types', 'buddypress' ),
     97            __( 'Group types', 'buddypress' ),
     98            'bp_moderate',
     99            basename( add_query_arg( 'taxonomy', 'bp_group_type', bp_get_admin_url( 'edit-tags.php' ) ) )
     100        );
     101    }
     102}
     103add_action( 'bp_admin_menu', 'bp_groups_admin_types_menu' );
    44104
    45105/**
     
    13801440}
    13811441add_action( bp_core_admin_hook(), 'bp_groups_admin_groups_type_change_notice' );
     1442
     1443/**
     1444 * Checks whether a group type already exists.
     1445 *
     1446 * @since 7.0.0
     1447 *
     1448 * @param  boolean $exists  True if the group type already exists. False otherwise.
     1449 * @param  string  $type_id The group type identifier.
     1450 * @return boolean          True if the group type already exists. False otherwise.
     1451 */
     1452function bp_groups_type_admin_type_exists( $exists = false, $type_id = '' ) {
     1453    if ( ! $type_id ) {
     1454        return $exists;
     1455    }
     1456
     1457    return ! is_null( bp_groups_get_group_type_object( $type_id ) );
     1458}
     1459add_filter( bp_get_group_type_tax_name() . '_check_existing_type', 'bp_groups_type_admin_type_exists', 1, 2 );
     1460
     1461/**
     1462 * Set the feedback messages for the Group Types Admin actions.
     1463 *
     1464 * @since 7.0.0
     1465 *
     1466 * @param array  $messages The feedback messages.
     1467 * @return array           The feedback messages including the ones for the Group Types Admin actions.
     1468 */
     1469function bp_groups_type_admin_updated_messages( $messages = array() ) {
     1470    $type_taxonomy = bp_get_group_type_tax_name();
     1471
     1472    $messages[ $type_taxonomy ] = array(
     1473        0  => '',
     1474        1  => __( 'Please define the Group Type ID field.', 'buddypress' ),
     1475        2  => __( 'Group type successfully added.', 'buddypress' ),
     1476        3  => __( 'Sorry, there was an error and the Group type wasn’t added.', 'buddypress' ),
     1477        // The following one needs to be != 5.
     1478        4  => __( 'Group type successfully updated.', 'buddypress' ),
     1479        5  => __( 'Sorry, this Group type already exists.', 'buddypress' ),
     1480        6  => __( 'Sorry, the Group type was not deleted: it does not exist.', 'buddypress' ),
     1481        7  => __( 'Sorry, This Group type is registered using code, deactivate the plugin or remove the custom code before trying to delete it again.', 'buddypress' ),
     1482        8  => __( 'Sorry, there was an error while trying to delete this Group type.', 'buddypress' ),
     1483        9  => __( 'Group type successfully deleted.', 'buddypress' ),
     1484        10 => __( 'Group type could not be updated due to missing required information.', 'buddypress' ),
     1485    );
     1486
     1487    return $messages;
     1488}
     1489add_filter( 'term_updated_messages', 'bp_groups_type_admin_updated_messages' );
Note: See TracChangeset for help on using the changeset viewer.