ui = $ui; $this->sitemap = $sitemap; } public function slug(): string { return 'sitemap'; } public function label(): string { return __( 'Sitemap', 'acez-seo' ); } public function icon(): string { return 'sitemap'; } public function enqueue(): void { } public function handles_form_key( string $raw_tab ): bool { return 'sitemap_settings' === sanitize_key( $raw_tab ); } /** @return array */ public function save( string $raw_tab ): array { // Defence in depth: SettingsPage::handle_save() verifies this nonce // before dispatch; re-checking keeps every entry point independently safe. check_admin_referer( FormControls::NONCE_ACTION ); $excluded_post_types = array(); foreach ( PostTypes::supported() as $post_type ) { if ( ! isset( $_POST[ 'sitemap_pt_' . $post_type ] ) ) { $excluded_post_types[] = $post_type; } } $excluded_taxonomies = array(); foreach ( Taxonomies::supported() as $taxonomy ) { if ( ! isset( $_POST[ 'sitemap_tax_' . $taxonomy ] ) ) { $excluded_taxonomies[] = $taxonomy; } } $custom_urls_raw = isset( $_POST['sitemap_custom_urls'] ) ? TemplateSanitizer::sanitize_multiline( wp_strip_all_tags( wp_unslash( $_POST['sitemap_custom_urls'] ) ) ) : ''; $excluded_urls_raw = isset( $_POST['sitemap_excluded_urls'] ) ? TemplateSanitizer::sanitize_multiline( wp_strip_all_tags( wp_unslash( $_POST['sitemap_excluded_urls'] ) ) ) : ''; $this->sitemap->update( array( 'excluded_post_types' => $excluded_post_types, 'excluded_taxonomies' => $excluded_taxonomies, 'include_users' => isset( $_POST['sitemap_users'] ), 'max_urls' => isset( $_POST['sitemap_max_urls'] ) ? absint( $_POST['sitemap_max_urls'] ) : 0, // One URL per line — social_profiles textarea pattern; per-line // validation (scheme, same host, path normalization) happens in // the repository. 'custom_urls' => preg_split( '/\r\n|\r|\n/', $custom_urls_raw ) ?: array(), 'excluded_urls' => preg_split( '/\r\n|\r|\n/', $excluded_urls_raw ) ?: array(), ) ); return array( 'tab' => 'sitemap' ); } public function render(): void { echo '

' . esc_html__( 'Manage the contents of WordPress\'s built-in sitemap (/wp-sitemap.xml). The plugin extends the sitemap WordPress generates — it does not replace it with its own.', 'acez-seo' ) . wp_kses( HelpIcon::render( 'sitemap_tab' ), KsesTags::help_icon() ) . '

'; $this->render_status(); $settings = $this->sitemap->get(); $this->ui->form_open( 'sitemap_settings' ); $this->render_content_card( $settings ); $this->render_excluded_urls_card( $settings ); $this->render_custom_urls_card( $settings ); $this->render_limits_card( $settings ); submit_button( __( 'Save sitemap settings', 'acez-seo' ) ); $this->ui->form_close(); $this->render_excluded_posts_card(); } private function render_status(): void { // The live truth: every party hooking wp_sitemaps_enabled has its say — // our Dashboard toggle, hide-from-search, AND other SEO plugins (e.g. // Rank Math disables core sitemaps in favor of its own). $enabled = (bool) apply_filters( 'wp_sitemaps_enabled', true ); // phpcs:ignore WordPress.NamingConventions.PrefixAllGlobals.NonPrefixedHooknameFound -- this hook name belongs to WP core or another plugin (WPML/core sitemaps) being invoked/filtered, not one of ours — must stay unprefixed to match their API. if ( ! $enabled ) { echo '

' . esc_html__( 'WordPress\'s built-in sitemap is currently disabled — by the “Sitemap XML” switch on the Dashboard, the hide-site mode, or another SEO plugin generating its own sitemap. The settings below will take effect once it is enabled.', 'acez-seo' ) . '

'; return; } printf( '

%2$s

', esc_url( home_url( '/wp-sitemap.xml' ) ), esc_html__( 'View your sitemap ↗', 'acez-seo' ) ); } /** * @param array{excluded_post_types: string[], excluded_taxonomies: string[], include_users: bool, max_urls: int, custom_urls: string[], excluded_urls: string[]} $settings */ private function render_content_card( array $settings ): void { $this->ui->card_open( __( 'Sitemap contents', 'acez-seo' ), 'sitemap', '', 'sitemap-content' ); echo '

' . esc_html__( 'Untick the content types and taxonomies that should disappear from the sitemap. Posts with noindex and posts excluded manually in the editor are always skipped, regardless of these settings.', 'acez-seo' ) . wp_kses( HelpIcon::render( 'sitemap_content' ), KsesTags::help_icon() ) . '

'; echo '

' . esc_html__( 'Content types', 'acez-seo' ) . '

'; foreach ( PostTypes::supported() as $post_type ) { $object = get_post_type_object( $post_type ); $label = null !== $object ? $object->labels->name : $post_type; printf( '

', esc_attr( 'sitemap_pt_' . $post_type ), checked( ! in_array( $post_type, $settings['excluded_post_types'], true ), true, false ), esc_html( $label ), esc_html( $post_type ) ); } echo '

' . esc_html__( 'Taxonomies', 'acez-seo' ) . '

'; foreach ( Taxonomies::supported() as $taxonomy ) { $object = get_taxonomy( $taxonomy ); $label = false !== $object ? $object->labels->name : $taxonomy; printf( '

', esc_attr( 'sitemap_tax_' . $taxonomy ), checked( ! in_array( $taxonomy, $settings['excluded_taxonomies'], true ), true, false ), esc_html( $label ), esc_html( $taxonomy ) ); } echo '

' . esc_html__( 'Authors', 'acez-seo' ) . '

'; $this->ui->checkbox_field( 'sitemap_users', __( 'Include author archives in the sitemap', 'acez-seo' ), $settings['include_users'], 'sitemap_users' ); $this->ui->card_close(); } /** * @param array{excluded_post_types: string[], excluded_taxonomies: string[], include_users: bool, max_urls: int, custom_urls: string[], excluded_urls: string[]} $settings */ private function render_excluded_urls_card( array $settings ): void { $this->ui->card_open( __( 'Add an exclusion — URLs removed from the sitemap', 'acez-seo' ), 'sitemap', '', 'sitemap-excluded-urls' ); echo '

' . esc_html__( 'URLs from this list are removed from the sitemap — one per line, as a path or a full URL. A trailing asterisk excludes a whole branch, e.g. /promo/* removes everything under /promo/. Applies to every sitemap section: posts, taxonomies and author archives.', 'acez-seo' ) . wp_kses( HelpIcon::render( 'sitemap_excluded_urls' ), KsesTags::help_icon() ) . '

'; printf( '', esc_attr( "/stara-strona/\n/promocje/*" ), esc_textarea( implode( "\n", $settings['excluded_urls'] ) ) ); $this->ui->card_close(); } /** * @param array{excluded_post_types: string[], excluded_taxonomies: string[], include_users: bool, max_urls: int, custom_urls: string[], excluded_urls: string[]} $settings */ private function render_custom_urls_card( array $settings ): void { $this->ui->card_open( __( 'Additional URLs', 'acez-seo' ), 'sitemap', '', 'sitemap-custom-urls' ); echo '

' . esc_html__( 'URLs from this list are added to the sitemap as their own section — one URL per line. Useful for non-WordPress pages living on the same domain (e.g. a hand-uploaded landing page). URLs from other domains are rejected on save.', 'acez-seo' ) . wp_kses( HelpIcon::render( 'sitemap_custom_urls' ), KsesTags::help_icon() ) . '

'; printf( '', esc_attr( home_url( '/promocja/' ) ), esc_textarea( implode( "\n", $settings['custom_urls'] ) ) ); $this->ui->card_close(); } /** * @param array{excluded_post_types: string[], excluded_taxonomies: string[], include_users: bool, max_urls: int, custom_urls: string[], excluded_urls: string[]} $settings */ private function render_limits_card( array $settings ): void { $this->ui->card_open( __( 'URL limit per sitemap page', 'acez-seo' ), 'sitemap', '', 'sitemap-limits' ); printf( '

%4$s

%5$s

', esc_html__( 'Maximum number of URLs on a single sitemap page:', 'acez-seo' ), (int) SitemapRepository::MAX_URLS_CEILING, (int) $settings['max_urls'], wp_kses( HelpIcon::render( 'sitemap_max_urls' ), KsesTags::help_icon() ), esc_html__( '0 = WordPress\'s default limit (2000). Large sitemaps are automatically split into pages.', 'acez-seo' ) ); $this->ui->card_close(); } private function render_excluded_posts_card(): void { $query = new \WP_Query( array( 'post_type' => PostTypes::supported(), 'post_status' => 'publish', 'posts_per_page' => self::EXCLUDED_LIST_CAP, 'no_found_rows' => false, 'update_post_term_cache' => false, 'meta_key' => MetaFields::SITEMAP_EXCLUDE, // phpcs:ignore WordPress.DB.SlowDBQuery.slow_db_query_meta_key -- small capped admin-only listing. 'meta_value' => '1', // phpcs:ignore WordPress.DB.SlowDBQuery.slow_db_query_meta_value -- ditto. ) ); $this->ui->card_open( __( 'Manually excluded posts', 'acez-seo' ), 'sitemap', '', 'sitemap-excluded' ); echo '

' . esc_html__( 'Posts with the “Exclude from sitemap” option ticked in the editor. The exclusion is changed in that post\'s SEO meta box, not here.', 'acez-seo' ) . '

'; if ( array() === $query->posts ) { echo '

' . esc_html__( 'No post is manually excluded from the sitemap.', 'acez-seo' ) . '

'; } else { echo ''; if ( (int) $query->found_posts > self::EXCLUDED_LIST_CAP ) { printf( '

%s

', esc_html( sprintf( /* translators: 1: number of listed posts, 2: total number of excluded posts */ __( 'Showing %1$d of %2$d excluded posts.', 'acez-seo' ), self::EXCLUDED_LIST_CAP, (int) $query->found_posts ) ) ); } } $this->ui->card_close(); } }