Skip to:
Content

BuddyPress.org

Changeset 13974


Ignore:
Timestamp:
07/24/2024 08:36:35 AM (2 years ago)
Author:
imath
Message:

Administration: add a function to check a BP Admin Screen is displayed

bp_is_admin() accepts an optional parameter: a string containing the BP Admin Screen ID. If provided: it checks this screen is loaded, if not it only checks a BP Admin Screen is displayed. This function will help us put together a specific community dashboard in the future.

For now it's helping us making sure the WP Plugin dependency warning is not displayed into the WP Admin > Add new plugin > BP Add-ons tab as this tab is generated by BuddyPress: so it is available & activated!

Props emaralive.

Fixes #9212
Closes ​https://github.com/buddypress/buddypress/pull/334

Location:
trunk/src
Files:
7 edited

Legend:

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

    r13937 r13974  
    180180function bp_activity_admin_load() {
    181181        global $bp_activity_list_table;
    182 
    183         $bp       = buddypress();
     182        $bp = buddypress();
     183
     184        // Traces the current BP Admin screen.
     185        $bp->admin->trace_current_screen();
     186
    184187        $doaction = bp_admin_list_table_current_bulk_action();
    185188        $min      = bp_core_get_minified_asset_suffix();
  • trunk/src/bp-core/admin/bp-core-admin-functions.php

    r13955 r13974  
    17681768add_filter( 'set_screen_option_tools_page_bp_members_invitations_per_page', 'bp_admin_set_screen_options', 10, 3 );
    17691769add_filter( 'set_screen_option_tools_page_bp_members_invitations_network_per_page', 'bp_admin_set_screen_options', 10, 3 );
     1770
     1771/**
     1772 * Remove the Plugin Dependency warning from BP add-ons listed into the Plugin/Add BP Addons tab.
     1773 *
     1774 * @since 15.0.0
     1775 *
     1776 * @param false|object|array $result The result object or array. Default false.
     1777 * @param string             $action The type of information being requested from the Plugin Installation API.
     1778 * @param object             $args   Plugin API arguments.
     1779 */
     1780function bp_admin_edit_available_addons_properties( $addons, $action, $args ) {
     1781        if ( 'query_plugins' === $action && bp_is_admin( 'plugin-install' ) && isset( $args->author ) && 'buddypress' === $args->author ) {
     1782                foreach ( $addons->plugins as $key => $plugin_data ) {
     1783                        if ( ! isset( $plugin_data['requires_plugins'] ) || ! in_array( 'buddypress', $plugin_data['requires_plugins'], true ) ) {
     1784                                continue;
     1785                        }
     1786
     1787                        // The BP Add-ons tab is generated by BuddyPress, so BuddyPress is installed, no need to add a Plugin Dependency warning about it.
     1788                        $addons->plugins[ $key ]['requires_plugins'] = array_diff( $plugin_data['requires_plugins'], array( 'buddypress' ) );
     1789                }
     1790        }
     1791
     1792        return $addons;
     1793}
     1794add_filter( 'plugins_api_result', 'bp_admin_edit_available_addons_properties', 10, 3 );
  • trunk/src/bp-core/bp-core-functions.php

    r13964 r13974  
    52515251        return $admin_notifications;
    52525252}
     5253
     5254/**
     5255 * Checks whether a BuddyPress admin screen is displayed.
     5256 *
     5257 * @since 15.0.0
     5258 *
     5259 * @param string $screen_id The specific screen ID to check.
     5260 * @return boolean True if a BuddyPress admin screen is displayed. False otherwise.
     5261 */
     5262function bp_is_admin( $screen_id = '' ) {
     5263        $bp = buddypress();
     5264
     5265        if ( ! isset( $bp->admin->current_screen ) ) {
     5266                return false;
     5267        }
     5268
     5269        if ( ! $screen_id ) {
     5270                return ! empty( $bp->admin->current_screen );
     5271        }
     5272
     5273        return $screen_id === $bp->admin->current_screen;
     5274}
  • trunk/src/bp-core/classes/class-bp-admin.php

    r13966 r13974  
    102102         */
    103103        public $submenu_pages = array();
     104
     105        /**
     106         * The current BP Admin screen being displayed.
     107         *
     108         * @since 15.0.0
     109         * @var array
     110         */
     111        public $current_screen = '';
    104112
    105113        /** Methods ***************************************************************/
    … …  
    410418                foreach ( $hooks as $hook ) {
    411419                        add_action( "admin_head-$hook", 'bp_core_modify_admin_menu_highlight' );
     420                        add_action( "load-{$hook}", array( $this, 'trace_current_screen' ), 1 );
    412421
    413422                        if ( 'settings_page_bp-rewrites' === $hook ) {
    … …  
    13201329                }
    13211330
     1331                /*
     1332                 * @todo We should check for any possible post types generated by BuddyPress:
     1333                 * - BP Email,
     1334                 * - BP Directories...
     1335                 */
    13221336                if ( ! isset( $screen->post_type ) || bp_get_email_post_type() !== $screen->post_type ) {
    13231337                        return;
    … …  
    13251339
    13261340                bp_core_add_contextual_help( $screen );
     1341                $this->trace_current_screen();
    13271342        }
    13281343
    … …  
    16291644        public function addons_args() {
    16301645                global $paged;
     1646                $this->current_screen = get_current_screen()->id;
    16311647
    16321648                return array(
    … …  
    16971713                <?php
    16981714        }
     1715
     1716        /**
     1717         * Traces the BP Admin screen being viewed.
     1718         *
     1719         * @since 15.0.0
     1720         */
     1721        public function trace_current_screen() {
     1722                $this->current_screen = get_current_screen()->id;
     1723        }
    16991724}
  • trunk/src/bp-groups/bp-groups-admin.php

    r13937 r13974  
    128128function bp_groups_admin_load() {
    129129        global $bp_groups_list_table;
     130        $bp = buddypress();
     131
     132        // Traces the current BP Admin screen.
     133        $bp->admin->trace_current_screen();
    130134
    131135        // Build redirection URL.
    … …  
    247251                ) );
    248252        }
    249 
    250         $bp = buddypress();
    251253
    252254        // Enqueue CSS and JavaScript.
  • trunk/src/bp-members/classes/class-bp-members-admin.php

    r13973 r13974  
    964964         */
    965965        public function user_admin_load() {
     966                $bp = buddypress();
     967
     968                // Traces the current BP Admin screen.
     969                $bp->admin->trace_current_screen();
    966970
    967971                // Get the user ID.
  • trunk/src/bp-xprofile/bp-xprofile-admin.php

    r13878 r13974  
    2626        }
    2727
    28         add_users_page( _x( 'Profile Fields', 'xProfile admin page title', 'buddypress' ), _x( 'Profile Fields', 'Admin Users menu', 'buddypress' ), 'manage_options', 'bp-profile-setup', 'xprofile_admin' );
     28        $hook = add_users_page(
     29                _x( 'Profile Fields', 'xProfile admin page title', 'buddypress' ),
     30                _x( 'Profile Fields', 'Admin Users menu', 'buddypress' ),
     31                'manage_options',
     32                'bp-profile-setup',
     33                'xprofile_admin'
     34        );
     35
     36        // Hook into early actions to load our init handler.
     37        add_action( "load-$hook", 'bp_xprofile_admin_load' );
    2938}
    3039add_action( bp_core_admin_hook(), 'xprofile_add_admin_menu' );
     40
     41/**
     42 * Performs actions early during the xProfile Admin loading process.
     43 *
     44 * @since 15.0.0
     45 */
     46function bp_xprofile_admin_load() {
     47        $bp = buddypress();
     48
     49        // Traces the current BP Admin screen.
     50        $bp->admin->trace_current_screen();
     51}
    3152
    3253/**
Note: See TracChangeset for help on using the changeset viewer.