' . \esc_html( $env_type_name ) . ''; } return $items; } /** * Adds an admin bar item. * * @param \admin_bar $admin_bar The WordPress toolbar. * * @return void * * @since 1.8.4 */ public static function add_toolbar_item( $admin_bar ) { $env_type = \wp_get_environment_type(); $env_type_name = self::get_env_type_name( $env_type ); if ( ! empty( $env_type ) ) { $admin_bar->add_menu( array( 'id' => 'det_env_type', 'parent' => 'top-secondary', 'title' => '' . \esc_html( $env_type_name ) . '', 'meta' => array( 'class' => 'det-' . \sanitize_title( $env_type ), ), ) ); $admin_bar->add_node( array( 'id' => 'det-wp-debug', 'title' => self::show_label_value( 'WP_DEBUG', ( \defined( 'WP_DEBUG' ) && WP_DEBUG ? 'true' : 'false' ) ), 'parent' => 'det_env_type', ) ); $admin_bar->add_node( array( 'id' => 'det-wp-debug-log', 'title' => self::show_label_value( 'WP_DEBUG_LOG', ( \defined( 'WP_DEBUG_LOG' ) && WP_DEBUG_LOG ? 'true' : 'false' ) ), 'parent' => 'det_env_type', 'meta' => array( 'title' => \esc_attr( (string) ( \defined( 'WP_DEBUG_LOG' ) ? ( \is_string( WP_DEBUG_LOG ) ? WP_DEBUG_LOG : ( WP_DEBUG_LOG ? 'true' : 'false' ) ) : '' ) ), ), ) ); $admin_bar->add_node( array( 'id' => 'det-wp-debug-display', 'title' => self::show_label_value( 'WP_DEBUG_DISPLAY', ( \defined( 'WP_DEBUG_DISPLAY' ) && WP_DEBUG_DISPLAY ? 'true' : 'false' ) ), 'parent' => 'det_env_type', ) ); $wp_development_mode = ( function_exists( 'wp_get_development_mode' ) ? \wp_get_development_mode() : null ); if ( null !== $wp_development_mode ) { if ( empty( $wp_development_mode ) ) { $wp_development_mode = 'false'; } $admin_bar->add_node( array( 'id' => 'det-wp-development-mode', 'title' => self::show_label_value( 'WP_DEVELOPMENT_MODE', $wp_development_mode ), 'parent' => 'det_env_type', ) ); } $admin_bar->add_node( array( 'id' => 'det-script-display', 'title' => self::show_label_value( 'SCRIPT_DEBUG', ( \defined( 'SCRIPT_DEBUG' ) && SCRIPT_DEBUG ? 'true' : 'false' ) ), 'parent' => 'det_env_type', ) ); $admin_bar->add_node( array( 'id' => 'det-savequeries', 'title' => self::show_label_value( 'SAVEQUERIES', ( defined( 'SAVEQUERIES' ) && SAVEQUERIES ? 'true' : 'false' ) ), 'parent' => 'det_env_type', ) ); $admin_bar->add_node( array( 'id' => 'det-wp', 'title' => self::show_label_value( 'WP', \get_bloginfo( 'version', 'display' ) ), 'parent' => 'det_env_type', ) ); $admin_bar->add_node( array( 'id' => 'det-php', 'title' => self::show_label_value( 'PHP', phpversion() ), 'parent' => 'det_env_type', ) ); } } /** * Html_label_value * * @param string $label Text to display as label. * @param string $value Text to display as value. * * @return string HTML to display label and value. * * @since 1.8.4 */ private static function show_label_value( $label, $value ): string { $html = ''; $html .= '' . \esc_html( (string) $label ) . ''; $html .= '' . \esc_html( (string) $value ) . ''; return $html; } /** * Determine whether or not to display the environment type. * * @return bool Whether the plugin should display anything. * * @since 1.8.4 */ protected static function should_display() { // By default, we don't display anything. $display = false; // If the function doesn't exist, the plugin absolutely cannot function. if ( ! function_exists( 'wp_get_environment_type' ) ) { return false; } // If the admin bar is not showing there is no place to display the environment type. if ( ! \is_admin_bar_showing() ) { return false; } if ( is_admin() ) { // Display in wp-admin for any role above subscriber. if ( is_user_logged_in() && current_user_can( 'edit_posts' ) ) { $display = true; } } elseif ( \is_user_logged_in() && \current_user_can( 'manage_options' ) ) { // Display on the front-end only if user has the manage_options capability. $display = true; } /** * Filter whether or not the environment type should be displayed. * * Allows you to perform checks like user capabilities or is_admin() * and return true to display the environment type, or false to not. * * @since 1.2 * * @param boolean $display Whether the environment type should be displayed. */ $display = (bool) \apply_filters( 'aadvan_display_environment_type', $display ); return $display; } /** * Enqueues the CSS styles necessary to display the environment type. * * @since 1.8.4 */ public static function enqueue_styles() { \wp_enqueue_style( self::STYLESHEET_HANDLE, ADVAN_PLUGIN_ROOT_URL . 'css/admin.css', array(), ADVAN_VERSION ); } /** * Enqueues assets for the block editor. * * @since 4.4.0 */ public static function enqueue_block_editor_assets() { $env_type = \wp_get_environment_type(); $env_type_name = self::get_env_type_name( $env_type ); // Enqueue the JavaScript file. \wp_enqueue_script( 'advan-det-block-editor', ADVAN_PLUGIN_ROOT_URL . 'js/block-editor.js', array(), ADVAN_VERSION, true ); // Enqueue the CSS file for block editor. \wp_enqueue_style( 'advan-det-block-editor-styles', ADVAN_PLUGIN_ROOT_URL . 'css/block-editor.css', array(), ADVAN_VERSION ); // Pass environment data to JavaScript. \wp_localize_script( 'advan-det-block-editor', 'detEnvData', array( 'envType' => $env_type, 'envTypeName' => $env_type_name, 'wpDebug' => ( \defined( 'WP_DEBUG' ) && WP_DEBUG ? 'true' : 'false' ), 'wpDebugLog' => ( \defined( 'WP_DEBUG_LOG' ) && WP_DEBUG_LOG ? 'true' : 'false' ), 'wpDebugDisplay' => ( \defined( 'WP_DEBUG_DISPLAY' ) && WP_DEBUG_DISPLAY ? 'true' : 'false' ), 'wpDevelopmentMode' => ( function_exists( 'wp_get_development_mode' ) ? \wp_get_development_mode() : '' ), 'scriptDebug' => ( \defined( 'SCRIPT_DEBUG' ) && SCRIPT_DEBUG ? 'true' : 'false' ), 'saveQueries' => ( defined( 'SAVEQUERIES' ) && SAVEQUERIES ? 'true' : 'false' ), 'wpVersion' => \get_bloginfo( 'version', 'display' ), 'phpVersion' => phpversion(), ) ); } } }