asset_manager = $asset_manager; $this->add_ons_collector = $add_ons_collector; $this->current_page_helper = $current_page_helper; $this->short_link_helper = $short_link_helper; $this->admin_conditional = $admin_conditional; $this->promotion_manager = $promotion_manager; $this->duplicate_post_manager = $duplicate_post_manager; } /** * Initializes the integration. * * This is the place to register hooks and filters. * * @return void */ public function register_hooks() { // Add page with priority 7 to add it above the workouts. \add_filter( 'wpseo_submenu_pages', [ $this, 'add_page' ], 7 ); \add_filter( 'wpseo_network_submenu_pages', [ $this, 'add_page' ], 7 ); // Are we on our page? if ( $this->admin_conditional->is_met() && $this->current_page_helper->get_current_yoast_seo_page() === self::PAGE ) { \add_action( 'admin_enqueue_scripts', [ $this, 'enqueue_assets' ] ); \add_action( 'in_admin_header', [ $this, 'remove_notices' ], \PHP_INT_MAX ); } } /** * Adds the page to the (currently) last position in the array. * * @param array>> $pages The pages. * * @return array>> The pages. */ public function add_page( $pages ) { $pages[] = [ General_Page_Integration::PAGE, '', \__( 'Plans', 'wordpress-seo' ), 'wpseo_manage_options', self::PAGE, [ $this, 'display_page' ], ]; return $pages; } /** * Displays the page. * * @return void */ public function display_page() { echo '
'; } /** * Enqueues the assets. * * @return void */ public function enqueue_assets() { // Remove the emoji script as it is incompatible with both React and any contenteditable fields. \remove_action( 'admin_print_scripts', 'print_emoji_detection_script' ); $this->asset_manager->enqueue_script( self::ASSETS_NAME ); $this->asset_manager->enqueue_style( self::ASSETS_NAME ); $this->asset_manager->localize_script( self::ASSETS_NAME, 'wpseoScriptData', $this->get_script_data() ); } /** * Creates the script data. * * @return array>> The script data. */ private function get_script_data(): array { return [ 'addOns' => $this->add_ons_collector->to_array(), 'linkParams' => $this->short_link_helper->get_query_params(), 'preferences' => [ 'isRtl' => \is_rtl(), ], 'currentPromotions' => $this->promotion_manager->get_current_promotions(), 'duplicatePost' => $this->duplicate_post_manager->get_params(), 'userCan' => [ 'installPlugin' => \current_user_can( 'install_plugins' ), 'activatePlugin' => \current_user_can( 'activate_plugins' ), ], ]; } /** * Removes all current WP notices. * * @return void */ public function remove_notices() { \remove_all_actions( 'admin_notices' ); \remove_all_actions( 'user_admin_notices' ); \remove_all_actions( 'network_admin_notices' ); \remove_all_actions( 'all_admin_notices' ); } }