[ 'name' => 'Yoast SEO', 'path' => 'wordpress-seo/wp-seo.php', ], 'aioseo' => [ 'name' => 'All in One SEO', 'path' => 'all-in-one-seo-pack/all-in-one-seo-pack.php', ], 'rankmath' => [ 'name' => 'Rank Math SEO', 'path' => 'seo-by-rank-math/rank-math.php', ], 'seopress' => [ 'name' => 'SEOPress', 'path' => 'wp-seopress/wp-seopress.php', ], 'slimseo' => [ 'name' => 'Slim SEO', 'path' => 'slim-seo/slim-seo.php', ], 'tsf' => [ 'name' => 'The SEO Framework', 'path' => 'the-seo-framework/index.php', ], 'smartcrawl' => [ 'name' => 'SmartCrawl SEO', 'path' => 'wpmudev-updates/plugin-updates.php', ], ]; /** * Constructor * * @param array $options User options. */ public function __construct( $options ) { $this->options = $options; add_action( 'admin_init', [ $this, 'init' ] ); } /** * Option keys that only the Pro settings UI writes. * * @return string[] */ protected function get_pro_only_option_keys(): array { return [ 'exclude_noindex', 'tracking_seo_plugin', 'enable_static_cache', 'cache_duration' ]; } /** * Start the engine running * * @return void */ public function init() { $this->settings_options = [ [ 'option_group' => XML_Sitemap::MENU_SLUG, 'option_name' => XML_Sitemap::OPTION_NAME, 'args' => [ 'sanitize_callback' => [ $this, 'sanitize_settings' ] ], ], ]; $this->settings_sections = [ 'free' => [ 'id' => 'adminoptimizer-xml-sitemap-section', 'title' => '', 'menu_slug' => XML_Sitemap::MENU_SLUG, 'option_name' => XML_Sitemap::OPTION_NAME, 'fields' => [ [ 'type' => 'callback', 'title' => __( 'Sitemap URL', 'admin-optimizer' ), 'id' => 'custom-sitemap-url', 'name' => 'custom_sitemap_slug', 'callback' => [ $this, 'render_custom_sitemap_url_field' ], ], [ 'type' => 'callback', 'title' => __( 'Post Types', 'admin-optimizer' ), 'id' => 'sitemap-post-types', 'name' => 'post_types', 'desc' => __( 'Include these post types in the sitemap (if no post types are selected, Post will be included by default)', 'admin-optimizer' ), 'callback' => [ $this, 'render_post_types_field' ], 'param' => 'post', ], [ 'type' => 'callback', 'title' => __( 'Taxonomies', 'admin-optimizer' ), 'id' => 'sitemap-taxonomies', 'name' => 'taxonomies', 'desc' => __( 'Include these taxonomies in the sitemap', 'admin-optimizer' ), 'callback' => [ $this, 'render_taxonomies_field' ], ], [ 'type' => 'callback', 'title' => __( 'Exclude Categories', 'admin-optimizer' ), 'id' => 'exclude-categories', 'name' => 'exclude_categories', 'desc' => __( 'Exclude the selected categories from the sitemap', 'admin-optimizer' ), 'callback' => [ $this, 'render_exclude_categories_field' ], ], [ 'type' => 'checkbox', 'title' => __( 'Authors', 'admin-optimizer' ), 'id' => 'sitemap-include-authors', 'name' => 'include_authors', 'label' => __( 'Include Authors in the sitemap?', 'admin-optimizer' ), ], [ 'type' => 'number', 'title' => __( 'Maximum entries per sitemap', 'admin-optimizer' ), 'id' => 'sitemap-max-entries', 'name' => 'max_entries', 'min' => 1, 'max' => 5000, 'default' => 2000, 'desc' => __( 'Minimum is 1. Maximum is 5000. Default is 2000. The higher the value, the slower it takes to generate the sitemap.', 'admin-optimizer' ), ], [ 'type' => 'checkbox', 'title' => __( 'Add sitemap to Robot.txt', 'admin-optimizer' ), 'id' => 'include-sitemap-robotstxt', 'name' => 'include_in_robotstxt', 'label' => __( 'Add sitemap URL to the robots.txt file.', 'admin-optimizer' ), ], [ 'type' => 'callback', 'title' => __( 'Exclude individual post from sitemap', 'admin-optimizer' ), 'id' => 'exclude-individual-post', 'name' => 'exclude_individual_post', 'callback' => [ $this, 'render_exclude_individual_post_field' ], ], ], ], ]; if ( $this->is_pro_active() ) { $this->settings_sections = $this->inject_pro_fields( $this->settings_sections, 'adminoptimizer-xml-sitemap-section', [ [ 'type' => 'callback', 'title' => __( 'Exclude Noindex Posts', 'admin-optimizer' ), 'id' => 'exclude-noindex-posts', 'name' => 'exclude_noindex', 'desc' => __( 'Exclude posts that are marked as "noindex" by your SEO plugin.', 'admin-optimizer' ), 'callback' => [ $this, 'render_seo_plugins_field' ], ], [ 'type' => 'checkbox', 'title' => __( 'Enable Static Sitemap Cache', 'admin-optimizer' ), 'id' => 'enable-static-cache', 'name' => 'enable_static_cache', 'label' => __( 'Cache sitemap to static files for better performance', 'admin-optimizer' ), 'desc' => __( 'When enabled, sitemaps will be cached as static XML files. Cache is automatically cleared when content changes.', 'admin-optimizer' ), ], [ 'type' => 'number', 'title' => __( 'Cache Duration (hours)', 'admin-optimizer' ), 'id' => 'cache-duration', 'name' => 'cache_duration', 'min' => 1, 'max' => 168, 'default' => 24, 'desc' => __( 'How long to keep cached sitemaps before regenerating. Minimum is 1 hour. Maximum is 168 hours (7 days). Default is 24 hours.', 'admin-optimizer' ), ], [ 'type' => 'callback', 'title' => __( 'Clear Sitemap Cache', 'admin-optimizer' ), 'id' => 'clear-sitemap-cache', 'name' => 'clear_cache', 'callback' => [ $this, 'render_clear_cache_field' ], ], ] ); } else { $this->settings_sections['pro'] = [ 'id' => 'adminoptimizer-xml-sitemap-pro', 'title' => __( 'Pro Options', 'admin-optimizer' ), 'menu_slug' => XML_Sitemap::MENU_SLUG . '_pro', 'option_name' => XML_Sitemap::OPTION_NAME, 'args' => [ 'before_section' => '
', ], 'fields' => [ [ 'type' => 'callback', 'title' => __( 'Exclude Noindex Posts', 'admin-optimizer' ), 'id' => 'exclude-noindex-posts', 'name' => 'exclude_noindex', 'desc' => __( 'Exclude posts that are marked as "noindex" by your SEO plugin.', 'admin-optimizer' ), 'callback' => [ $this, 'render_disabled_seo_plugins_field' ], ], [ 'type' => 'checkbox', 'title' => __( 'Enable Static Sitemap Cache', 'admin-optimizer' ), 'id' => 'enable-static-cache', 'name' => 'enable_static_cache', 'disabled' => 'disabled', 'label' => __( 'Cache sitemap to static files for better performance', 'admin-optimizer' ), 'desc' => __( 'When enabled, sitemaps will be cached as static XML files. Cache is automatically cleared when content changes.', 'admin-optimizer' ), ], [ 'type' => 'number', 'title' => __( 'Cache Duration (hours)', 'admin-optimizer' ), 'id' => 'cache-duration', 'name' => 'cache_duration', 'min' => 1, 'max' => 168, 'default' => 24, 'disabled' => 'disabled', 'desc' => __( 'How long to keep cached sitemaps before regenerating. Minimum is 1 hour. Maximum is 168 hours (7 days). Default is 24 hours.', 'admin-optimizer' ), ], [ 'type' => 'callback', 'title' => __( 'Clear Sitemap Cache', 'admin-optimizer' ), 'id' => 'clear-sitemap-cache', 'name' => 'clear_cache', 'callback' => [ $this, 'render_disabled_clear_cache_field' ], ], ], ]; $this->settings_sections['pro-tab'] = [ 'id' => 'adminoptimizer-news-sitemap-section', 'title' => '', 'menu_slug' => XML_Sitemap::MENU_SLUG . '_protab', 'option_name' => XML_Sitemap::OPTION_NAME, /* translators: %1$s is the anchor link to the Pro version. %2$s is the closing anchor tag */ 'description' => sprintf( __( 'Upgrade to the %1$sPro version%2$s to access these features', 'admin-optimizer' ), '', '' ), 'args' => [ 'before_section' => '', ], 'fields' => [ [ 'type' => 'checkbox', 'title' => __( 'Enable Google News Sitemap', 'admin-optimizer' ), 'id' => 'enable-news-sitemap', 'name' => 'enable_news_sitemap', 'disabled' => 'disabled', 'label' => __( 'Add a new Google News sitemap?', 'admin-optimizer' ), ], [ 'type' => 'callback', 'title' => __( 'News Sitemap URL', 'admin-optimizer' ), 'id' => 'custom-news-sitemap-url', 'name' => 'custom_sitemap_slug', 'callback' => [ $this, 'render_custom_sitemap_url_field' ], 'param' => 'news', ], [ 'type' => 'text', 'title' => __( 'Publication Name', 'admin-optimizer' ), 'id' => 'publication-name', 'name' => 'publication_name', 'default' => get_bloginfo( 'name' ), 'disabled' => 'disabled', 'desc' => __( 'The name of your publication. This will be used in the Google News sitemap. If left empty, the Site Title will be used.', 'admin-optimizer' ), ], [ 'type' => 'callback', 'title' => __( 'Post Types', 'admin-optimizer' ), 'id' => 'sitemap-post-types', 'name' => 'post_types', 'disabled' => 'disabled', 'desc' => __( 'Include these post types in the News sitemap (if no post types are selected, Post will be included by default)', 'admin-optimizer' ), 'callback' => [ $this, 'render_post_types_field' ], 'param' => 'news', ], [ 'type' => 'callback', 'title' => __( 'Exclude Noindex Posts', 'admin-optimizer' ), 'id' => 'exclude-noindex-posts', 'name' => 'exclude_noindex', 'desc' => __( 'Posts marked as "noindex" by your SEO plugin will not be included in the News sitemap.', 'admin-optimizer' ), 'callback' => [ $this, 'render_disabled_seo_plugins_field' ], 'param' => 'news', ], [ 'type' => 'checkbox', 'title' => __( 'Enable Static News Sitemap Cache', 'admin-optimizer' ), 'id' => 'enable-news-static-cache', 'name' => 'enable_static_cache', 'disabled' => 'disabled', 'label' => __( 'Cache News sitemap to static file for better performance', 'admin-optimizer' ), 'desc' => __( 'When enabled, the News sitemap will be cached as a static XML file. Cache is automatically cleared when content changes.', 'admin-optimizer' ), ], [ 'type' => 'number', 'title' => __( 'News Cache Duration (hours)', 'admin-optimizer' ), 'id' => 'news-cache-duration', 'name' => 'cache_duration', 'min' => 1, 'max' => 168, 'default' => 24, 'disabled' => 'disabled', 'desc' => __( 'How long to keep cached News sitemap before regenerating. Minimum is 1 hour. Maximum is 168 hours (7 days). Default is 24 hours.', 'admin-optimizer' ), ], [ 'type' => 'callback', 'title' => __( 'Clear News Sitemap Cache', 'admin-optimizer' ), 'id' => 'clear-news-sitemap-cache', 'name' => 'clear_news_cache', 'callback' => [ $this, 'render_disabled_clear_cache_field' ], ], ], ]; } $this->setup(); } /** * Render custom sitemap url field * * @param [] $atts Attributes. * @param string $xml_type Sitemap type. * @return void */ public function render_custom_sitemap_url_field( $atts, $xml_type = '' ) { $disabled = ''; if ( 'news' === $xml_type ) { $value = 'wp-sitemap-news'; $default_slug = 'wp-sitemap-news'; $disabled = 'disabled'; } else { $value = $this->options['custom_sitemap_slug'] ?? 'wp-sitemap'; $default_slug = 'wp-sitemap'; } ?> >
get_sitemap_url( $xml_type ); ?>
' . esc_html( $default_slug . '.xml' ) . '', '' . esc_url( $sitemap_url ) . '' );
?>
' . esc_url( $sitemap_url ) . '', '' . esc_url( home_url( '/wp-sitemap-posts-post-1.xml' ) ) . '' );
?>
Permalinks, and press Save Changes to flush the rewrite rules.', 'admin-optimizer' ); ?>
false, 'public' => true, ], 'objects' ); $post_types = []; foreach ( $custom_post_types as $custom_post_type ) { $post_types[ $custom_post_type->name ] = $custom_post_type->label; } $post_types = array_merge( [ 'post' => 'Post', 'page' => 'Page', ], $post_types ); if ( ! empty( $attr['desc'] ) ) { echo '' . esc_html( $attr['desc'] ) . '
'; } $disabled = ''; if ( 'news' === $sitemap_type ) { $options = [ 'post' ]; $disabled = 'disabled'; } elseif ( ! empty( $this->options['post_types'] ) && is_array( $this->options['post_types'] ) ) { $options = $this->options['post_types']; } else { $options = [ 'post' ]; } foreach ( $post_types as $post_type_name => $post_type_label ) : $checked = ''; if ( in_array( $post_type_name, $options, true ) ) { $checked = ' checked="checked"'; } ?>' . esc_html( $attr['desc'] ) . '
'; } if ( ! empty( $this->options['taxonomies'] ) && is_array( $this->options['taxonomies'] ) ) { $options = $this->options['taxonomies']; } else { $options = []; } foreach ( $tax_fields as $tax_name => $tax_label ) : $checked = ''; if ( in_array( $tax_name, $options, true ) ) { $checked = ' checked="checked"'; } ?>' . esc_html( $attr['desc'] ) . '
'; } foreach ( $categories as $category ) : $checked = ''; if ( in_array( intval( $category->term_id ), $options, true ) ) { $checked = ' checked="checked"'; } ?>seo_plugins[ $tracking_seo ]['name'] ) ); ?>