required_capability() ) ) { return; } if ( ! wp_script_is( 'wp-core-commands', 'registered' ) ) { return; } $asset = require ADMINOPTIMIZER_ADMIN_PATH . 'command-palette/dist/commands.asset.php'; wp_enqueue_script( self::HANDLE, ADMINOPTIMIZER_ADMIN_URI . 'command-palette/dist/commands.js', $asset['dependencies'], $asset['version'], true ); $commands = array_values( array_filter( Module_Registry::get_navigable_modules_for_commands(), static function ( array $module ): bool { return current_user_can( Module_Registry::get_settings_capability( $module['id'] ) ); } ) ); foreach ( Module_Registry::get_modules() as $module ) { if ( Module_Registry::NATIVE !== $module['classification'] || 'overview' !== $module['section'] || ! empty( $module['retired'] ) || ! current_user_can( Module_Registry::get_settings_capability( $module['id'] ) ) ) { continue; } // Pro-only Overview pages need their runtime before they can be opened. if ( 'pro' === $module['tier'] ) { $runtime = Module_Registry::get_runtime_target( $module['id'] ); if ( ! is_string( $runtime ) || ! class_exists( $runtime ) ) { continue; } } $commands[] = [ 'id' => $module['id'], 'slug' => $module['id'], 'label' => $module['name'], 'section' => $module['section'], 'url' => Module_Registry::get_module_url( $module['id'], [ 'page' => ADMINOPTIMIZER_MODULES_MENU_SLUG ] ), ]; } wp_localize_script( self::HANDLE, 'aoCommandsData', $commands ); } /** * Output the hidden mount point the script attaches its command * registrations to via `createRoot()`, only when the script actually * got enqueued. * * @return void */ public function render_mount_point(): void { if ( ! wp_script_is( self::HANDLE, 'enqueued' ) ) { return; } printf( '
', esc_attr( self::MOUNT_ID ) ); } /** * Required WordPress capability to see Admin Optimizer commands in the * palette. * * @return string */ private function required_capability(): string { return 'manage_options'; } }