menu label. * * @return array */ private static function pages() { $pages = array( 'dashboard' => __( 'Dashboard', 'youwall' ), 'connect' => __( 'Connect', 'youwall' ), 'display' => __( 'Display', 'youwall' ), 'style' => __( 'Style', 'youwall' ), ); if ( self::pro_visible() ) { $pages['pro'] = __( 'Pro', 'youwall' ); } return $pages; } /** * What Pro adds: icon, title, description. * * @return array */ private static function pro_features() { return array( array( 'featured', __( 'Featured player', 'youwall' ), __( 'A big player with an "Up next" list beside it.', 'youwall' ) ), array( 'playlist', __( 'Playlists', 'youwall' ), __( 'Show any public playlist, like a course or a series.', 'youwall' ) ), array( 'popular', __( 'Most viewed', 'youwall' ), __( 'A button that sorts a feed by views instead of date.', 'youwall' ) ), ); } /** * Admin page slug for a page key. * * @param string $key Page key. * @return string */ private static function slug( $key ) { return 'dashboard' === $key ? self::PAGE : self::PAGE . '-' . $key; } /** * Page URL. * * @param string $key Page key. * @return string */ public static function url( $key = 'dashboard' ) { return admin_url( 'admin.php?page=' . self::slug( $key ) ); } /** * YouWall menu with submenus. */ public static function menu() { self::$hooks[] = add_menu_page( __( 'YouWall', 'youwall' ), __( 'YouWall', 'youwall' ), 'manage_options', self::PAGE, array( __CLASS__, 'page' ), self::MENU_ICON, 58 ); foreach ( self::pages() as $key => $label ) { self::$hooks[] = add_submenu_page( self::PAGE, $label . ' ‹ ' . __( 'YouWall', 'youwall' ), $label, 'manage_options', self::slug( $key ), array( __CLASS__, 'page' ) ); } } /** * Register the option. */ public static function register() { register_setting( self::GROUP, YouWall_Settings::OPTION, array( 'type' => 'array', 'sanitize_callback' => array( 'YouWall_Settings', 'sanitize' ), 'default' => YouWall_Settings::defaults(), ) ); } /** * "Settings" link on the Plugins screen. * * @param array $links Links. * @return array */ public static function action_links( $links ) { array_unshift( $links, '' . esc_html__( 'Settings', 'youwall' ) . '' ); if ( ! self::pro_active() && '' !== self::pro_url() ) { $links[] = '' . esc_html__( 'Get Pro', 'youwall' ) . ''; } return $links; } /** * Load assets on our pages only. * * @param string $hook Screen hook. */ public static function assets( $hook ) { if ( ! in_array( $hook, self::$hooks, true ) ) { return; } wp_enqueue_style( 'wp-color-picker' ); wp_enqueue_style( 'youwall-admin', YOUWALL_URL . 'assets/admin.css', array(), YOUWALL_VERSION . '.' . filemtime( YOUWALL_DIR . 'assets/admin.css' ) ); wp_enqueue_script( 'youwall-admin', YOUWALL_URL . 'assets/admin.js', array( 'jquery', 'wp-color-picker' ), YOUWALL_VERSION . '.' . filemtime( YOUWALL_DIR . 'assets/admin.js' ), true ); wp_localize_script( 'youwall-admin', 'youwallAdmin', array( 'ajaxUrl' => admin_url( 'admin-ajax.php' ), 'nonce' => wp_create_nonce( 'youwall_admin' ), 'i18n' => array( 'testing' => __( 'Checking…', 'youwall' ), 'clearing' => __( 'Clearing…', 'youwall' ), 'copied' => __( 'Copied', 'youwall' ), 'copy' => __( 'Copy', 'youwall' ), 'show' => __( 'Show', 'youwall' ), 'hide' => __( 'Hide', 'youwall' ), 'failed' => __( 'Something went wrong. Please reload the page and try again.', 'youwall' ), ), ) ); } /* ── Layout ──────────────────────────────────────────────────────── */ /** * Render the current page. */ public static function page() { if ( ! current_user_can( 'manage_options' ) ) { return; } // phpcs:ignore WordPress.Security.NonceVerification.Recommended -- only picks which page to show. $slug = isset( $_GET['page'] ) ? sanitize_key( wp_unslash( $_GET['page'] ) ) : self::PAGE; $current = 'dashboard'; foreach ( array_keys( self::pages() ) as $key ) { if ( self::slug( $key ) === $slug ) { $current = $key; } } $icons = array( 'dashboard' => 'grid', 'connect' => 'plug', 'display' => 'layout', 'style' => 'palette', 'pro' => 'star', ); ?>