[ 'noindex' => false, 'in_search' => true ], 'page' => [ 'noindex' => false, 'in_search' => true ], ]; return get_option( 'shadowsync_seo_post_type_settings', $defaults ); } private function get_taxonomy_settings() { $defaults = [ 'category' => [ 'noindex' => false, 'in_search' => true ], 'post_tag' => [ 'noindex' => false, 'in_search' => true ], ]; return get_option( 'shadowsync_seo_taxonomy_settings', $defaults ); } private function get_archive_settings() { $defaults = [ 'author_archive_noindex' => false, 'date_archive_noindex' => true, // date archives are noindexed by default (best practice) ]; return get_option( 'shadowsync_seo_archive_settings', $defaults ); } // ── OUTPUT META ROBOTS TAG ────────────────────────────── public function output_meta_robots() { $directives = []; if ( is_singular() ) { global $post; $post_noindex = get_post_meta( $post->ID, '_shadowsync_seo_noindex', true ); $post_nofollow = get_post_meta( $post->ID, '_shadowsync_seo_nofollow', true ); if ( '1' === $post_noindex ) { $directives[] = 'noindex'; } else { $type_settings = $this->get_post_type_settings(); if ( ! empty( $type_settings[ $post->post_type ]['noindex'] ) ) { $directives[] = 'noindex'; } } if ( '1' === $post_nofollow ) { $directives[] = 'nofollow'; } } elseif ( is_author() ) { $archive_settings = $this->get_archive_settings(); if ( ! empty( $archive_settings['author_archive_noindex'] ) ) { $directives[] = 'noindex'; } } elseif ( is_date() ) { $archive_settings = $this->get_archive_settings(); if ( ! empty( $archive_settings['date_archive_noindex'] ) ) { $directives[] = 'noindex'; } } elseif ( is_category() || is_tag() ) { $term = get_queried_object(); if ( $term ) { $tax_settings = $this->get_taxonomy_settings(); $taxonomy = $term->taxonomy; if ( ! empty( $tax_settings[ $taxonomy ]['noindex'] ) ) { $directives[] = 'noindex'; } } } // Advanced robots controls (max-snippet, max-image-preview etc.) $advanced = get_option( 'shadowsync_seo_advanced_robots', [ 'max_snippet' => '-1', 'max_image_preview' => 'large', 'max_video_preview' => '-1', ] ); $directives[] = 'max-snippet:' . $advanced['max_snippet']; $directives[] = 'max-image-preview:' . $advanced['max_image_preview']; $directives[] = 'max-video-preview:' . $advanced['max_video_preview']; if ( ! empty( $directives ) ) { echo '' . "\n"; } } // ── PER-POST META BOX ─────────────────────────────────── public function add_post_meta_box() { $post_types = get_post_types( [ 'public' => true ], 'names' ); foreach ( $post_types as $type ) { add_meta_box( 'shadowsync_seo_robots_meta', __( '🔍 Search Visibility', 'shadowsync-seo' ), [ $this, 'render_post_meta_box' ], $type, 'side', 'low' ); } } public function render_post_meta_box( $post ) { wp_nonce_field( 'shadowsync_seo_robots_meta_save', 'shadowsync_seo_robots_meta_nonce' ); $noindex = get_post_meta( $post->ID, '_shadowsync_seo_noindex', true ); $nofollow = get_post_meta( $post->ID, '_shadowsync_seo_nofollow', true ); ?>
$settings ) { $type = sanitize_key( $type ); $post_type_settings[ $type ] = [ 'noindex' => ! empty( $settings['noindex'] ), 'in_search' => empty( $settings['noindex'] ), // inverse for clarity in UI ]; } update_option( 'shadowsync_seo_post_type_settings', $post_type_settings ); // Taxonomy settings $tax_settings = []; $raw_tax = isset( $_POST['taxonomies'] ) ? map_deep( (array) wp_unslash( $_POST['taxonomies'] ), 'sanitize_text_field' ) : []; foreach ( $raw_tax as $tax => $settings ) { $tax = sanitize_key( $tax ); $tax_settings[ $tax ] = [ 'noindex' => ! empty( $settings['noindex'] ), ]; } update_option( 'shadowsync_seo_taxonomy_settings', $tax_settings ); // Archive settings update_option( 'shadowsync_seo_archive_settings', [ 'author_archive_noindex' => ! empty( $_POST['author_archive_noindex'] ), 'date_archive_noindex' => ! empty( $_POST['date_archive_noindex'] ), ] ); // Advanced robots directives $max_snippet = isset( $_POST['max_snippet'] ) ? sanitize_text_field( wp_unslash( $_POST['max_snippet'] ) ) : '-1'; $max_image = isset( $_POST['max_image_preview'] ) ? sanitize_text_field( wp_unslash( $_POST['max_image_preview'] ) ) : 'large'; $max_video = isset( $_POST['max_video_preview'] ) ? sanitize_text_field( wp_unslash( $_POST['max_video_preview'] ) ) : '-1'; update_option( 'shadowsync_seo_advanced_robots', [ 'max_snippet' => $max_snippet, 'max_image_preview' => in_array( $max_image, [ 'none', 'standard', 'large' ], true ) ? $max_image : 'large', 'max_video_preview' => $max_video, ] ); wp_send_json_success( [ 'message' => __( '✅ Search appearance settings saved.', 'shadowsync-seo' ), ] ); } // ── RENDER ADMIN PAGE ─────────────────────────────────── public function render_page() { $post_type_settings = $this->get_post_type_settings(); $tax_settings = $this->get_taxonomy_settings(); $archive_settings = $this->get_archive_settings(); $advanced = get_option( 'shadowsync_seo_advanced_robots', [ 'max_snippet' => '-1', 'max_image_preview' => 'large', 'max_video_preview' => '-1', ] ); $public_post_types = get_post_types( [ 'public' => true ], 'objects' ); $public_taxonomies = get_taxonomies( [ 'public' => true ], 'objects' ); ?>
labels->name ); ?> name ); ?> |
labels->name ); ?> name ); ?> |