$slugs Source slugs to import.
- * @return array{posts: int, terms: int, skipped_posts: int, skipped_terms: int} Totals across sources.
- */
-function noindex_seo_run_import( array $slugs ) {
- $totals = array(
- 'posts' => 0,
- 'terms' => 0,
- 'skipped_posts' => 0,
- 'skipped_terms' => 0,
- );
-
- $sources = noindex_seo_get_import_sources();
-
- foreach ( $slugs as $slug ) {
- if ( ! isset( $sources[ $slug ] ) ) {
- continue;
- }
- $source = $sources[ $slug ];
-
- // Posts.
- $coverage = noindex_seo_import_posts_coverage();
- $post_ids = get_posts(
- array(
- 'post_type' => $coverage['post_types'],
- 'post_status' => $coverage['post_statuses'],
- 'fields' => 'ids',
- 'posts_per_page' => -1,
- 'no_found_rows' => true,
- 'suppress_filters' => true,
- 'meta_query' => array( // phpcs:ignore WordPress.DB.SlowDBQuery.slow_db_query_meta_query
- array_merge( array( 'relation' => 'OR' ), noindex_seo_import_flags_meta_query( $source['posts'] ) ),
- ),
- )
- );
-
- foreach ( (array) $post_ids as $post_id ) {
- $post_id = (int) $post_id;
- // Never overwrite existing data (an explicit "off" row counts as data too).
- if ( metadata_exists( 'post', $post_id, '_noindex_seo_override' ) ) {
- ++$totals['skipped_posts'];
- continue;
- }
-
- $noindex = noindex_seo_source_flag_is_on( get_post_meta( $post_id, $source['posts']['noindex']['key'], true ), $source['posts']['noindex'] );
- $nofollow = noindex_seo_source_flag_is_on( get_post_meta( $post_id, $source['posts']['nofollow']['key'], true ), $source['posts']['nofollow'] );
-
- if ( ! $noindex && ! $nofollow ) {
- continue; // False positive of the LIKE query: nothing to import.
- }
-
- update_post_meta( $post_id, '_noindex_seo_override', 1 );
- update_post_meta( $post_id, '_noindex_seo_noindex', $noindex ? 1 : 0 );
- update_post_meta( $post_id, '_noindex_seo_nofollow', $nofollow ? 1 : 0 );
- ++$totals['posts'];
- }
-
- // Terms (only sources that store term meta).
- if ( isset( $source['terms'] ) ) {
- $term_ids = get_terms(
- array(
- 'taxonomy' => get_taxonomies( array( 'public' => true ), 'names' ),
- 'hide_empty' => false,
- 'fields' => 'ids',
- 'meta_query' => array( // phpcs:ignore WordPress.DB.SlowDBQuery.slow_db_query_meta_query
- array_merge( array( 'relation' => 'OR' ), noindex_seo_import_flags_meta_query( $source['terms'] ) ),
- ),
- )
- );
-
- foreach ( is_array( $term_ids ) ? $term_ids : array() as $term_id ) {
- if ( metadata_exists( 'term', $term_id, '_noindex_seo_override' ) ) {
- ++$totals['skipped_terms'];
- continue;
- }
-
- $noindex = noindex_seo_source_flag_is_on( get_term_meta( $term_id, $source['terms']['noindex']['key'], true ), $source['terms']['noindex'] );
- $nofollow = noindex_seo_source_flag_is_on( get_term_meta( $term_id, $source['terms']['nofollow']['key'], true ), $source['terms']['nofollow'] );
-
- if ( ! $noindex && ! $nofollow ) {
- continue;
- }
-
- update_term_meta( $term_id, '_noindex_seo_override', 1 );
- update_term_meta( $term_id, '_noindex_seo_noindex', $noindex ? 1 : 0 );
- update_term_meta( $term_id, '_noindex_seo_nofollow', $nofollow ? 1 : 0 );
- ++$totals['terms'];
- }
- }
- }
-
- // The counts shown on the Tools tab describe pre-import state: drop them.
- delete_transient( 'noindex_seo_import_counts' );
-
- return $totals;
-}
-
/**
* Collects the active directive map stored in a post's granular meta.
*
@@ -2098,9 +1533,9 @@ function noindex_seo_rest_effective_permission_check( WP_REST_Request $request )
* REST callback: returns the consolidated settings array.
*
* Strips the internal `version` key — that is an implementation detail that
- * callers should not depend on. Everything else (contexts, rules,
- * robots_txt, config) is exposed verbatim so headless consumers can
- * replicate the directive logic on their own front-end.
+ * callers should not depend on. Everything else (contexts, config) is exposed
+ * verbatim so headless consumers can replicate the directive logic on their
+ * own front-end.
*
* @since 3.1.0
*
@@ -2450,7 +1885,7 @@ function noindex_seo_enqueue_admin_assets( $hook ) {
true
);
- // Localize script with translations and the robots.txt preset bot lists..
+ // Localize script with translations..
wp_localize_script(
'noindex-seo-admin',
'noindexSeoAdmin',
@@ -2458,8 +1893,6 @@ function noindex_seo_enqueue_admin_assets( $hook ) {
'successMessage' => __( 'Settings saved successfully!', 'noindex-seo' ),
'expandAll' => __( 'Expand All', 'noindex-seo' ),
'collapseAll' => __( 'Collapse All', 'noindex-seo' ),
- 'aiBots' => array_values( noindex_seo_get_ai_bots() ),
- 'searchBots' => array_values( noindex_seo_get_search_bots() ),
)
);
}
@@ -2980,7 +2413,7 @@ function noindex_seo_process_form() {
$scope = ( isset( $_POST['noindex_seo_form_scope'] ) && is_string( $_POST['noindex_seo_form_scope'] ) )
? sanitize_key( wp_unslash( $_POST['noindex_seo_form_scope'] ) )
: 'settings';
- if ( ! in_array( $scope, array( 'general', 'settings', 'robotstxt' ), true ) ) {
+ if ( ! in_array( $scope, array( 'general', 'settings' ), true ) ) {
$scope = 'settings';
}
@@ -3042,28 +2475,6 @@ function noindex_seo_process_form() {
}
$settings['rules'] = noindex_seo_sanitize_rules( $raw_rules );
// phpcs:enable WordPress.Security.NonceVerification.Missing
- } elseif ( 'robotstxt' === $scope ) {
- // Virtual robots.txt management (3.7.0): feature toggle + bot rules
- // from the parallel agent/policy arrays of the Robots.txt tab.
- // phpcs:disable WordPress.Security.NonceVerification.Missing -- nonce verified above.
- $settings['robots_txt']['enabled'] = isset( $_POST['noindex_seo_robotstxt_enabled'] ) ? 1 : 0;
-
- $raw_rules = array();
- if ( isset( $_POST['noindex_seo_robotstxt_agent'], $_POST['noindex_seo_robotstxt_policy'] )
- && is_array( $_POST['noindex_seo_robotstxt_agent'] ) && is_array( $_POST['noindex_seo_robotstxt_policy'] ) ) {
- // phpcs:ignore WordPress.Security.ValidatedSanitizedInput.InputNotSanitized -- array input; every element is sanitized in the loop below.
- $agents = (array) wp_unslash( $_POST['noindex_seo_robotstxt_agent'] );
- // phpcs:ignore WordPress.Security.ValidatedSanitizedInput.InputNotSanitized -- array input; every element is sanitized in the loop below.
- $policies = (array) wp_unslash( $_POST['noindex_seo_robotstxt_policy'] );
- foreach ( $policies as $index => $policy ) {
- $raw_rules[] = array(
- 'user_agent' => isset( $agents[ $index ] ) && is_scalar( $agents[ $index ] ) ? sanitize_text_field( wp_unslash( (string) $agents[ $index ] ) ) : '',
- 'policy' => is_scalar( $policy ) ? sanitize_key( wp_unslash( (string) $policy ) ) : '',
- );
- }
- }
- $settings['robots_txt']['rules'] = noindex_seo_sanitize_robots_txt_rules( $raw_rules );
- // phpcs:enable WordPress.Security.NonceVerification.Missing
} else {
// phpcs:disable WordPress.Security.NonceVerification.Missing -- nonce verified above.
// Get the implementation method to validate field compatibility.
@@ -3260,14 +2671,6 @@ function noindex_seo_sanitize_imported_settings( $raw ) {
$settings['rules'] = noindex_seo_sanitize_rules( $raw['rules'] );
}
- // Virtual robots.txt rules (3.7.0) ride the JSON backup as well.
- if ( isset( $raw['robots_txt'] ) && is_array( $raw['robots_txt'] ) ) {
- $settings['robots_txt']['enabled'] = empty( $raw['robots_txt']['enabled'] ) ? 0 : 1;
- if ( isset( $raw['robots_txt']['rules'] ) ) {
- $settings['robots_txt']['rules'] = noindex_seo_sanitize_robots_txt_rules( $raw['robots_txt']['rules'] );
- }
- }
-
$raw_config = $raw['config'];
$method = isset( $raw_config['method'] ) && is_string( $raw_config['method'] )
@@ -3345,63 +2748,6 @@ function noindex_seo_handle_import() {
}
add_action( 'admin_post_noindex_seo_import', 'noindex_seo_handle_import' );
-/**
- * Handles the "Import from other plugins" action (3.7.0, spec section 5).
- *
- * On-demand and confirmed by the user: only the sources checked in the form
- * are imported, and noindex SEO never overwrites content that already
- * carries its own override data (skipped and counted instead). Redirects
- * back to the tools tab with the totals for the result notices.
- *
- * Hooked to the {@see 'admin_post_noindex_seo_plugin_import'} action.
- *
- * @since 3.7.0
- *
- * @return void
- */
-function noindex_seo_handle_plugin_import() {
- if ( ! current_user_can( 'manage_options' ) ) {
- wp_die( esc_html__( 'Permission denied.', 'noindex-seo' ) );
- }
- check_admin_referer( 'noindex_seo_plugin_import' );
-
- $known = array_keys( noindex_seo_get_import_sources() );
- $slugs = array();
- $raw_selection = isset( $_POST['noindex_seo_import_sources'] ) && is_array( $_POST['noindex_seo_import_sources'] )
- ? wp_unslash( $_POST['noindex_seo_import_sources'] ) // phpcs:ignore WordPress.Security.ValidatedSanitizedInput.InputNotSanitized -- array of slugs, whitelisted against the known sources below.
- : array();
- foreach ( $raw_selection as $slug ) {
- if ( is_string( $slug ) && in_array( sanitize_key( $slug ), $known, true ) ) {
- $slugs[] = sanitize_key( $slug );
- }
- }
-
- $redirect = admin_url( 'options-general.php?page=noindex_seo&tab=tools' );
-
- if ( array() === $slugs ) {
- wp_safe_redirect( add_query_arg( 'plugin_import_empty', '1', $redirect ) );
- exit;
- }
-
- $totals = noindex_seo_run_import( $slugs );
-
- wp_safe_redirect(
- add_query_arg(
- array(
- 'plugin_import_posts' => $totals['posts'],
- 'plugin_import_terms' => $totals['terms'],
- 'plugin_import_skipped_posts' => $totals['skipped_posts'],
- 'plugin_import_skipped_terms' => $totals['skipped_terms'],
- ),
- ( $totals['posts'] || $totals['terms'] || $totals['skipped_posts'] || $totals['skipped_terms'] )
- ? $redirect
- : add_query_arg( 'plugin_import_done', '1', $redirect )
- )
- );
- exit;
-}
-add_action( 'admin_post_noindex_seo_plugin_import', 'noindex_seo_handle_plugin_import' );
-
/**
* Applies a directive change to a context in the consolidated settings.
*
@@ -3935,10 +3281,6 @@ function noindex_seo_get_suggested_contexts() {
* @since 3.1.3 Skipped on WordPress versions without register_post_meta()
* (pre-4.9.6): granular control still works there through the
* classic meta box, Quick Edit and bulk actions.
- * @since 3.7.1 Adds 'custom-fields' post type support for the registered
- * types: without it the REST API exposes no `meta` field and
- * the block editor sidebar silently drops every save on
- * custom post types registered without that support.
*
* @return void
*/
@@ -3956,17 +3298,6 @@ function noindex_seo_register_post_meta() {
// Get all public post types.
$post_types = get_post_types( array( 'public' => true ), 'names' );
- // The REST API (and with it the block editor sidebar) only exposes the
- // `meta` field for post types that support 'custom-fields'. Custom post
- // types registered without it (a very common registration) would
- // silently drop every sidebar save with an HTTP 200, so the support is
- // added for exactly the post types the plugin registers meta on.
- foreach ( $post_types as $post_type ) {
- if ( ! post_type_supports( $post_type, 'custom-fields' ) ) {
- add_post_type_support( $post_type, 'custom-fields' );
- }
- }
-
// Meta fields to register. Boolean directives (and the override flag) are
// integers; value directives (3.6.0) are strings normalized on write.
$boolean_meta_fields = array(
@@ -5283,15 +4614,14 @@ function noindex_seo_admin() {
// phpcs:ignore WordPress.Security.NonceVerification.Recommended -- read-only navigation state, not form data.
$current_tab = isset( $_GET['tab'] ) && is_string( $_GET['tab'] ) ? sanitize_key( wp_unslash( $_GET['tab'] ) ) : 'general';
- if ( ! in_array( $current_tab, array( 'general', 'settings', 'tools', 'robotstxt' ), true ) ) {
+ if ( ! in_array( $current_tab, array( 'general', 'settings', 'tools' ), true ) ) {
$current_tab = 'general';
}
$tabs = array(
- 'general' => __( 'General', 'noindex-seo' ),
- 'settings' => __( 'SEO Settings', 'noindex-seo' ),
- 'tools' => __( 'Import / Export', 'noindex-seo' ),
- 'robotstxt' => __( 'Robots.txt', 'noindex-seo' ),
+ 'general' => __( 'General', 'noindex-seo' ),
+ 'settings' => __( 'SEO Settings', 'noindex-seo' ),
+ 'tools' => __( 'Import / Export', 'noindex-seo' ),
);
// Define section icons (using Dashicons)..
@@ -6054,112 +5384,6 @@ function noindex_seo_admin() {
- ';
- echo esc_html( $imported_posts_text . ', ' . $imported_terms_text );
-
- if ( $skipped_posts || $skipped_terms ) {
- echo ' — ' . esc_html(
- sprintf(
- /* translators: 1: number of skipped posts, 2: number of skipped terms. */
- __( '%1$d posts and %2$d terms skipped (already configured)', 'noindex-seo' ),
- $skipped_posts,
- $skipped_terms
- )
- );
- }
- echo '
';
- }
- if ( $import_selection_empty ) {
- echo '';
- esc_html_e( 'No plugins were selected to import from.', 'noindex-seo' );
- echo '
';
- }
- if ( isset( $_GET['plugin_import_done'] ) ) { // phpcs:ignore WordPress.Security.NonceVerification.Recommended -- read-only result flag set by our own handler after a nonce check.
- echo '';
- esc_html_e( 'The selected plugins had no importable robots data left.', 'noindex-seo' );
- echo '
';
- }
- ?>
-
-
-
-
-
-
-
-
@@ -6206,86 +5430,6 @@ function noindex_seo_admin() {
-
-
-
-
-
-
-