editor = $editor; $this->shortcode = $shortcode; } /** * Registers hooks. * * @return void */ public function register(): void { add_action( 'admin_menu', array( $this, 'add_menu' ) ); add_action( 'admin_enqueue_scripts', array( $this, 'enqueue' ) ); } /** * The page's address. * * @return string */ public static function url(): string { return admin_url( 'admin.php?page=' . self::SLUG ); } /** * Adds the page. Registered before Settings, so it's listed above it. * * @return void */ public function add_menu(): void { $parent = current_user_can( DashboardPage::CAPABILITY ) ? DashboardPage::SLUG : ''; $this->hook_suffix = (string) add_submenu_page( $parent, __( 'Shortcode builder', 'yangra-conditional' ), __( 'Shortcode builder', 'yangra-conditional' ), self::CAPABILITY, self::SLUG, array( $this, 'render' ) ); if ( '' === $parent && '' !== $this->hook_suffix ) { add_action( 'load-' . $this->hook_suffix, array( $this, 'set_title' ) ); } } /** * Gives the page its title when it has no menu item. WordPress finds a * page's title through its menu item, so it would otherwise be null, which * admin-header.php passes to strip_tags() (deprecated in PHP 8.1+). * * @return void */ public function set_title(): void { global $title; $title = __( 'Shortcode builder', 'yangra-conditional' ); // phpcs:ignore WordPress.WP.GlobalVariablesOverride.Prohibited -- The admin page title WordPress reads. } /** * Renders the React mount point. * * @return void */ public function render(): void { echo '