Make WordPress Core


Ignore:
Timestamp:
04/17/2021 01:12:25 AM (5 years ago)
Author:
Clorith
Message:

Site Health: Support custom sub-menus and pages.

Allow developers to extend the Site Health screen with their own custom navigation tabs and pages.

This implements a new filter, site_health_navigation_tabs, which takes an associated array of tab identifiers/slugs, and tab labels, allowing developers to add their own subpage to the Site Health interface as new tabs.

To output a custom page, or add to an existing page, the site_health_tab_content action is triggered whenever the tab query argument is present and not empty. This action includes the current tab as its argument, which a developer would match against to only output content when relevant.

Props ramiy for initial patch.
Fixes #47225.

File:
1 edited

Legend:

Unmodified
Added
Removed
  • trunk/src/wp-admin/includes/class-wp-site-health.php

    r50710 r50764  
    5151                add_action( 'admin_enqueue_scripts', array( $this, 'enqueue_scripts' ) );
    5252                add_action( 'wp_site_health_scheduled_check', array( $this, 'wp_cron_scheduled_check' ) );
     53
     54                add_action( 'site_health_tab_content', array( $this, 'show_site_health_tab' ) );
     55        }
     56
     57        /**
     58         * Output the content of a tab in the Site Health screen.
     59         *
     60         * @since 5.8.0
     61         *
     62         * @param string $tab Slug of the current tab being displayed.
     63         */
     64        public function show_site_health_tab( $tab ) {
     65                if ( 'debug' === $tab ) {
     66                        require_once ABSPATH . '/wp-admin/site-health-info.php';
     67                }
    5368        }
    5469
     
    104119                }
    105120
    106                 if ( 'site-health' === $screen->id && ! isset( $_GET['tab'] ) ) {
     121                if ( 'site-health' === $screen->id && ( ! isset( $_GET['tab'] ) || empty( $_GET['tab'] ) ) ) {
    107122                        $tests = WP_Site_Health::get_tests();
    108123
Note: See TracChangeset for help on using the changeset viewer.