hook = (string) add_menu_page( __( 'AdPresso', 'adpresso' ), __( 'AdPresso', 'adpresso' ), adpresso_get_capability( 'edit_ad' ), Constants::ADPRESSO_SLUG, '__return_null', 'data:image/svg+xml;base64,PHN2ZyB4bWxucz0iaHR0cDovL3d3dy53My5vcmcvMjAwMC9zdmciIHdpZHRoPSIyMCIgaGVpZ2h0PSIyMCIgdmlld0JveD0iLTAuMjA1IDAgMjAgMjAiIG92ZXJmbG93PSJ2aXNpYmxlIj48cGF0aCBmaWxsPSJjdXJyZW50Q29sb3IiIGQ9Ik0xOS41OSAyMEwxMi44MTggMEg2Ljc3MUwwIDIwaDQuODY2di0zLjMwN2EuNDcuNDcgMCAwIDEgLjQ3My0uNDczaDIuNjI1Yy4yNjEgMCAuNDcyLS4yMTIuNDcyLS40NzN2LTIuOTNjMC0uMjYtLjIxMS0uNDcyLS40NzItLjQ3MmgtLjU2M2MtLjI2MSAwLS40NzItLjIxMi0uNDcyLS40NzNWOS4wNGMwLTEuNTgzIDEuMjgzLTIuODY2IDIuODY2LTIuODY2czIuODY3IDEuMjgzIDIuODY3IDIuODY2djIuODM0YzAgLjI2MS0uMjEzLjQ3My0uNDczLjQ3M2gtLjU2MmMtLjI2IDAtLjQ3My4yMTItLjQ3My40NzJ2Mi45M2MwIC4yNjEuMjEzLjQ3My40NzMuNDczaDIuNjI1Yy4yNjEgMCAuNDczLjIxMS40NzMuNDczVjIwaDQuODY1eiIvPjwvc3ZnPgo=', 56 ); // Opens the submenu so the other screens can append to it; removed again once they have. add_submenu_page( Constants::ADPRESSO_SLUG, __( 'AdPresso', 'adpresso' ), __( 'AdPresso', 'adpresso' ), adpresso_get_capability( 'edit_ad' ), Constants::ADPRESSO_SLUG, '__return_null' ); } /** * Without its own entry the menu links to the first remaining one, the ads list. * * @return void */ public function remove_main_submenu_entry(): void { remove_submenu_page( Constants::ADPRESSO_SLUG, Constants::ADPRESSO_SLUG ); } /** * The main slug has no page of its own: old settings links go to the settings, everything else to the ads list. * * @return void */ public function redirect_main_page(): void { $url = $this->get_main_page_redirect(); if ( null !== $url ) { wp_safe_redirect( $url ); exit; } } /** * Target for a request to the main slug, null for every other request. * * @return string|null */ public function get_main_page_redirect(): ?string { if ( wp_doing_ajax() || Params::get()->getKey( 'page' ) !== Constants::ADPRESSO_SLUG ) { return null; } return $this->get_legacy_settings_redirect() ?? admin_url( 'admin.php?page=adpresso-list-tables&tab=ads' ); } /** * Settings URL for an old settings link (main slug plus a tab), null for everything else. * * @return string|null */ public function get_legacy_settings_redirect(): ?string { if ( wp_doing_ajax() || Params::get()->getKey( 'page' ) !== Constants::ADPRESSO_SLUG || Params::get()->getKey( 'tab' ) === '' ) { return null; } // phpcs:ignore WordPress.Security.NonceVerification.Recommended -- Read-only redirect, the target page checks its own capability. $args = array_map( 'sanitize_text_field', array_filter( wp_unslash( $_GET ), 'is_scalar' ) ); unset( $args['page'] ); // add_query_arg() expects encoded values; $_GET holds the decoded ones. $args = array_map( 'rawurlencode', $args ); return add_query_arg( $args, Util::get_settings_url() ); } }