キーは hook suffix、値はページスラッグ。 */ private $hooks = array(); /** * フックを登録する。 */ public function __construct() { add_action( 'admin_menu', array( $this, 'register_menu' ) ); add_action( 'admin_enqueue_scripts', array( $this, 'enqueue_assets' ) ); } /* * ----------------------------------------------------------------------- * メニュー * ----------------------------------------------------------------------- */ /** * メニューを登録する。 * * @return void */ public function register_menu() { $top_hook = add_menu_page( __( 'Paid Content', 'acs-content-for-woocommerce' ), __( 'Paid Content', 'acs-content-for-woocommerce' ), self::CAP, self::MENU_SLUG, array( $this, 'render_dashboard' ), 'dashicons-money-alt', 30 ); if ( $top_hook ) { $this->hooks[ $top_hook ] = self::MENU_SLUG; } $submenus = array( array( 'acscw-dashboard', __( 'Dashboard', 'acs-content-for-woocommerce' ), 'render_dashboard' ), array( 'acscw-items', __( 'Paid Content', 'acs-content-for-woocommerce' ), 'render_items' ), array( 'acscw-reports', __( 'Sales Report', 'acs-content-for-woocommerce' ), 'render_reports' ), array( 'acscw-buyers', __( 'Buyers', 'acs-content-for-woocommerce' ), 'render_buyers' ), array( 'acscw-coupons', __( 'Coupons', 'acs-content-for-woocommerce' ), 'render_coupons' ), array( 'acscw-settings', __( 'Settings', 'acs-content-for-woocommerce' ), 'render_settings' ), ); foreach ( $submenus as $submenu ) { list( $slug, $title, $callback ) = $submenu; $hook = add_submenu_page( self::MENU_SLUG, $title, $title, self::CAP, $slug, array( $this, $callback ) ); if ( $hook ) { $this->hooks[ $hook ] = $slug; } } } /** * 登録済み hook suffix を返す。 * * @return array キーは hook suffix、値はページスラッグ。 */ public function get_hooks() { return $this->hooks; } /* * ----------------------------------------------------------------------- * 資産 * ----------------------------------------------------------------------- */ /** * 自分のページにだけ資産を読み込む。 * * v2 は admin_enqueue_scripts を一度も使わず、各レンダリング関数の中に *