id ) || false === strpos( (string) $screen->id, self::SLUG ) ) { return; } echo '' . "\n"; } /** * Register the top level menu and every module submenu. * * @return void */ public function add_menus() { $capability = Capabilities::manage(); add_menu_page( __( 'PageCore', 'pagecore' ), __( 'PageCore', 'pagecore' ), $capability, self::SLUG, array( pagecore()->modules_screen(), 'render' ), $this->menu_icon(), self::POSITION ); $this->hooks['__modules'] = add_submenu_page( self::SLUG, __( 'Settings', 'pagecore' ), __( 'Settings', 'pagecore' ), $capability, self::SLUG, array( pagecore()->modules_screen(), 'render' ) ); foreach ( pagecore()->modules()->enabled() as $id => $module ) { if ( ! $module->has_screen() || ! Capabilities::current_user_can_manage() ) { continue; } $this->hooks[ $id ] = add_submenu_page( self::SLUG, $module->get_label(), $module->get_menu_title(), $capability, $module->get_screen_slug(), array( $module, 'render_screen' ) ); } } /** * Load the Modules screen application on its own screen only. * * Module screens enqueue their own assets from their own boot(), so a module * never pays for another module's JavaScript. * * @param string $hook_suffix Current admin page hook. * @return void */ public function enqueue( $hook_suffix ) { if ( ! isset( $this->hooks['__modules'] ) || $hook_suffix !== $this->hooks['__modules'] ) { return; } pagecore()->assets()->enqueue_app( 'modules-screen', array( 'modules' => pagecore()->modules()->to_array(), // Sent with the screen so the SVG panel can decide whether to // show itself without a second request. 'svg' => Svg_Rest::state(), 'data' => Settings_Rest::state(), ) ); } /** * Hook suffix for a module's screen, once the menu has been built. * * A module compares this against the current hook to decide whether to * enqueue its assets. * * @param string $module_id Module id. * @return string */ public function get_hook( $module_id ) { return isset( $this->hooks[ $module_id ] ) ? $this->hooks[ $module_id ] : ''; } /** * The white PageCore symbol as the menu icon, for the dark sidebar. * * A PNG rather than an SVG: at 20px it renders smoother than the vector. * * @return string */ private function menu_icon() { return PAGECORE_URL . 'images/pagecore-symbol-dark.png'; } }