hook = (string) add_menu_page( __( 'Layout Now', 'layout-now' ), __( 'Layout Now', 'layout-now' ), Plugin::capability(), self::SLUG, array( $this, 'render' ), 'dashicons-layout', 58 ); } /** * Page markup: a mount point for the app. */ public function render() { echo '
'; echo ''; } /** * Enqueues the app on our page only. * * @param string $hook Current admin page hook. */ public function enqueue( $hook ) { if ( $hook !== $this->hook ) { return; } $asset_file = Plugin::path( 'admin/build/index.asset.php' ); if ( ! is_readable( $asset_file ) ) { add_action( 'admin_notices', static function () { echo '

' . esc_html__( 'Layout Now: the admin app has not been built. Run "npm install && npm run build" in the plugin folder.', 'layout-now' ) . '

'; } ); return; } $asset = include $asset_file; wp_enqueue_script( self::HANDLE, Plugin::url( 'admin/build/index.js' ), $asset['dependencies'], $asset['version'], true ); wp_enqueue_style( self::HANDLE, Plugin::url( 'admin/build/index.css' ), array( 'wp-components' ), $asset['version'] ); wp_style_add_data( self::HANDLE, 'rtl', 'replace' ); wp_set_script_translations( self::HANDLE, 'layout-now' ); wp_add_inline_script( self::HANDLE, 'window.layoutNowAdmin = ' . wp_json_encode( array( 'namespace' => Controller::NAMESPACE_V1, 'pageUrl' => admin_url( 'admin.php?page=' . self::SLUG ), 'baseStyle' => add_query_arg( 'ver', VERSION, Plugin::url( 'assets/css/base.css' ) ), 'version' => VERSION, ) ) . ';', 'before' ); } /** * Body class used to give the app the full content area. * * @param string $classes Classes. * @return string */ public function body_class( $classes ) { $screen = function_exists( 'get_current_screen' ) ? get_current_screen() : null; if ( $screen && $screen->id === $this->hook ) { $classes .= ' lnow-admin-page'; } return $classes; } /** * "Layouts" link on the Plugins screen. * * @param array $links Links. * @return array */ public function action_links( $links ) { array_unshift( $links, sprintf( '%s', esc_url( admin_url( 'admin.php?page=' . self::SLUG ) ), esc_html__( 'Layouts', 'layout-now' ) ) ); return $links; } }