Skip to:
Content

BuddyPress.org


Ignore:
Timestamp:
02/16/2024 01:33:24 AM (2 years ago)
Author:
imath
Message:

Improve the BP Site Health debug info panel

  • Make sure empty options are displaying their default values
  • Add a an help tab for the BP Site Health debug info panel
  • Make sure this panel is only generated for the root blog
  • Improve the way the global community setting is handled
  • Add a debug info about whether the current theme supports BuddyPress

Fixes #9093

File:
1 edited

Legend:

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

    r13680 r13728  
    757757function bp_core_admin_debug_information( $debug_info = array() ) {
    758758    global $wp_settings_fields;
    759     $active_components = array_intersect_key( bp_core_get_components(), buddypress()->active_components );
     759
     760    if ( ! bp_is_root_blog() ) {
     761        return $debug_info;
     762    }
     763
     764    $active_components = wp_list_pluck( bp_core_get_active_components( array(), 'objects' ), 'name', 'id' );
    760765    $bp_settings       = array();
     766    $skipped_settings  = array( '_bp_theme_package_id', '_bp_community_visibility' );
    761767    $bp_url_parsers    = array(
    762768        'rewrites' => __( 'BP Rewrites API', 'buddypress' ),
     
    772778    }
    773779
    774 
    775780    foreach ( $wp_settings_fields['buddypress'] as $section => $settings ) {
    776781        $prefix       = '';
    777782        $component_id = str_replace( 'bp_', '', $section );
    778783
    779         if ( isset( $active_components[ $component_id ]['title'] ) ) {
    780             $prefix = $active_components[ $component_id ]['title'] .': ';
     784        if ( isset( $active_components[ $component_id ] ) ) {
     785            $prefix = $active_components[ $component_id ] .': ';
    781786        }
    782787
     
    788793            );
    789794
    790             if ( ! isset( $bp_setting['id'] ) || '_bp_theme_package_id' === $bp_setting['id'] ) {
     795            if ( ! isset( $bp_setting['id'] ) || in_array( $bp_setting['id'], $skipped_settings, true ) ) {
    791796                continue;
    792797            }
    793798
    794             $bp_setting_value = bp_get_option( $bp_setting['id'] );
    795             if ( '0' === $bp_setting_value || '1' === $bp_setting_value ) {
    796                 if ( ( $reverse && '0' === $bp_setting_value ) || ( ! $reverse && '1' === $bp_setting_value ) ) {
    797                     $bp_setting_value = __( 'Yes', 'buddypress' );
     799            $bp_setting_value = bp_get_option( $bp_setting['id'], 0 );
     800
     801            if ( is_array( $bp_setting_value ) ) {
     802                if ( is_numeric( key( $bp_setting_value ) ) ) {
     803                    $bp_setting_value = implode( ', ', $bp_setting_value );
    798804                } else {
    799                     $bp_setting_value = __( 'No', 'buddypress' );
     805                    $setting_array    = $bp_setting_value;
     806                    $bp_setting_value = array();
     807                    foreach ( $setting_array as $setting_array_key => $setting_array_value ) {
     808                        $bp_setting_value[ $setting_array_key ] = implode( ', ', $setting_array_value );
     809                    }
     810                }
     811            } else {
     812                $bp_setting_value = (int) $bp_setting_value;
     813                if ( 0 === $bp_setting_value || 1 === $bp_setting_value ) {
     814                    if ( ( $reverse && 0 === $bp_setting_value ) || ( ! $reverse && 1 === $bp_setting_value ) ) {
     815                        $bp_setting_value = __( 'Yes', 'buddypress' );
     816                    } else {
     817                        $bp_setting_value = __( 'No', 'buddypress' );
     818                    }
    800819                }
    801820            }
     
    814833    }
    815834
     835    $theme_settings = array();
     836    if ( current_theme_supports( 'buddypress' ) ) {
     837        $theme_settings['standalone_bptheme'] = array(
     838            'label' => __( 'BuddyPress standalone theme', 'buddypress' ),
     839            'value' => wp_get_theme()->get( 'Name' ),
     840        );
     841    } else {
     842        $theme_settings['template_pack'] = array(
     843            'label' => __( 'Active template pack', 'buddypress' ),
     844            'value' => bp_get_theme_compat_name() . ' ' . bp_get_theme_compat_version(),
     845        );
     846    }
     847
    816848    $debug_info['buddypress'] = array(
    817849        'label'  => __( 'BuddyPress', 'buddypress' ),
    818850        'fields' => array_merge(
    819851            array(
    820                 'version' => array(
     852                'version'                     => array(
    821853                    'label' => __( 'Version', 'buddypress' ),
    822854                    'value' => bp_get_version(),
    823855                ),
    824                 'active_components' => array(
     856                'active_components'           => array(
    825857                    'label' => __( 'Active components', 'buddypress' ),
    826                     'value' => implode( ', ', wp_list_pluck( $active_components, 'title' ) ),
     858                    'value' => implode( ', ', $active_components ),
    827859                ),
    828                 'template_pack' => array(
    829                     'label' => __( 'Active template pack', 'buddypress' ),
    830                     'value' => bp_get_theme_compat_name() . ' ' . bp_get_theme_compat_version(),
    831                 ),
    832                 'url_parser'    => array(
     860                'url_parser'                  => array(
    833861                    'label' => __( 'URL Parser', 'buddypress' ),
    834862                    'value' => $bp_url_parser,
    835863                ),
     864                'global_community_visibility' => array(
     865                    'label' => __( 'Community visibility', 'buddypress' ),
     866                    'value' => bp_get_community_visibility( 'global' ),
     867                ),
    836868            ),
     869            $theme_settings,
    837870            $bp_settings
    838871        )
     
    842875}
    843876add_filter( 'debug_information', 'bp_core_admin_debug_information' );
     877
     878/**
     879 * Adds a BuddyPress section to the Site Health Info Admin Screen help tabs.
     880 *
     881 * @since 14.0.0
     882 */
     883function bp_core_admin_debug_information_add_help_tab() {
     884    if ( ! bp_is_root_blog() ) {
     885        return;
     886    }
     887
     888    if ( isset( $_REQUEST['tab'] ) && 'debug' === sanitize_key( wp_unslash( $_REQUEST['tab'] ) ) ) {
     889        $screen = get_current_screen();
     890
     891        $screen->add_help_tab(
     892            array(
     893                'id'      => 'bp-debug-settings',
     894                'title'   => esc_html__( 'BuddyPress', 'buddypress' ),
     895                'content' => bp_core_add_contextual_help_content( 'bp-debug-settings' ),
     896            )
     897        );
     898
     899        $help_sidebar = $screen->get_help_sidebar();
     900        $bp_links     = sprintf(
     901            '<p><a href="%1$s" class="bp-help-sidebar-links">%2$s</a></p>',
     902            esc_url( 'https://buddypress.org/support/' ),
     903            esc_html__( 'BuddyPress Support Forums', 'buddypress' )
     904        );
     905
     906        $screen->set_help_sidebar( $help_sidebar . $bp_links );
     907        wp_add_inline_script(
     908            'site-health',
     909            '( function() {
     910                let bpHelpSidebarLinks;
     911
     912                document.onreadystatechange = function()  {
     913                    if ( document.readyState === "complete" ) {
     914                        bpHelpSidebarLinks = document.querySelector( \'.bp-help-sidebar-links\' ).closest( \'p\')
     915                        bpHelpSidebarLinks.style.display = \'none\';
     916                    }
     917                }
     918
     919                document.querySelectorAll( \'.contextual-help-tabs ul li a\' ).forEach(
     920                    function( a ) {
     921                        a.addEventListener( \'click\', function( e ) {
     922                            if ( \'tab-link-bp-debug-settings\' === e.target.parentElement.getAttribute( \'id\' ) ) {
     923                                bpHelpSidebarLinks.style.display = \'block\';
     924                            } else {
     925                                bpHelpSidebarLinks.style.display = \'none\';
     926                            }
     927                        } );
     928                    }
     929                );
     930            } )();'
     931        );
     932    }
     933}
     934add_action( 'admin_head-site-health.php', 'bp_core_admin_debug_information_add_help_tab' );
Note: See TracChangeset for help on using the changeset viewer.