'og_title', '_yoast_wpseo_opengraph-description' => 'og_description', '_yoast_wpseo_twitter-title' => 'twitter_title', '_yoast_wpseo_twitter-description' => 'twitter_description', ); private static $separators = array( 'sc-dash' => '-', 'sc-ndash' => '–', 'sc-mdash' => '—', 'sc-colon' => ':', 'sc-middot' => '·', 'sc-bull' => '•', 'sc-star' => '*', 'sc-smstar' => '⋆', 'sc-pipe' => '|', 'sc-tilde' => '~', 'sc-laquo' => '«', 'sc-raquo' => '»', 'sc-lt' => '<', 'sc-gt' => '>', ); public function id() { return 'yoast'; } public function label() { return __( 'Yoast SEO', 'ai-eshop-optimizer' ); } public function available() { $c = $this->counts(); if ( $c['posts'] > 0 || $c['terms'] > 0 ) { return true; } $titles = get_option( 'wpseo_titles' ); return is_array( $titles ) && ! empty( $titles ); } public function counts() { global $wpdb; static $memo = null; if ( null !== $memo ) { return $memo; } $out = array( 'posts' => 0, 'terms' => 0 ); $like = $this->like_prefix( self::META_PREFIX ); $out['posts'] = (int) $wpdb->get_var( $wpdb->prepare( "SELECT COUNT(DISTINCT pm.post_id) FROM {$wpdb->postmeta} pm INNER JOIN {$wpdb->posts} p ON p.ID = pm.post_id WHERE pm.meta_key LIKE %s AND p.post_type NOT IN ('revision')", $like ) ); $out['terms'] = count( $this->term_rows() ); $memo = $out; return $out; } public function import_posts_chunk( $after_id, $limit ) { global $wpdb; $out = $this->empty_result( $after_id ); $like = $this->like_prefix( self::META_PREFIX ); $posts = $wpdb->get_results( $wpdb->prepare( "SELECT DISTINCT p.ID, p.post_type FROM {$wpdb->posts} p INNER JOIN {$wpdb->postmeta} pm ON pm.post_id = p.ID AND pm.meta_key LIKE %s WHERE p.ID > %d AND p.post_type NOT IN ('revision') ORDER BY p.ID ASC LIMIT %d", $like, (int) $after_id, (int) $limit ), ARRAY_A ); $count = is_array( $posts ) ? count( $posts ) : 0; if ( ! $count ) { return $out; } $ids = array(); $types = array(); foreach ( $posts as $p ) { $id = (int) $p['ID']; $ids[] = $id; $types[ $id ] = (string) $p['post_type']; } $out['last_id'] = (int) end( $ids ); $placeholders = implode( ',', array_fill( 0, count( $ids ), '%d' ) ); $args = $ids; $args[] = $like; $meta_rows = $wpdb->get_results( $wpdb->prepare( "SELECT post_id, meta_key, meta_value FROM {$wpdb->postmeta} WHERE post_id IN ({$placeholders}) AND meta_key LIKE %s", $args ), ARRAY_A ); $by_post = array(); foreach ( (array) $meta_rows as $r ) { $by_post[ (int) $r['post_id'] ][ (string) $r['meta_key'] ] = $r['meta_value']; } foreach ( $ids as $id ) { $type = $types[ $id ]; if ( '' === $type || empty( $by_post[ $id ] ) ) { $out['skipped']++; continue; } list( $fields, $stripped ) = $this->map_meta( $by_post[ $id ], $type, 'post' ); if ( ! $fields ) { $out['skipped']++; continue; } AIEO_SEO_Store::save( $type, $id, $fields ); if ( $stripped ) { $out['stripped']++; } $out['imported']++; } $out['done'] = ( $count < (int) $limit ); return $out; } private function term_rows() { static $cache = null; if ( null !== $cache ) { return $cache; } $cache = array(); $opt = get_option( self::TERM_OPTION ); if ( ! is_array( $opt ) ) { return $cache; } ksort( $opt ); foreach ( $opt as $taxonomy => $terms ) { $taxonomy = (string) $taxonomy; if ( '' === $taxonomy || ! is_array( $terms ) || ! taxonomy_exists( $taxonomy ) ) { continue; } ksort( $terms ); foreach ( $terms as $term_id => $meta ) { $term_id = (int) $term_id; if ( $term_id <= 0 || ! is_array( $meta ) ) { continue; } $cache[] = array( 'taxonomy' => $taxonomy, 'term_id' => $term_id, 'meta' => $meta ); } } return $cache; } public function import_terms_chunk( $after_id, $limit ) { $out = $this->empty_result( $after_id ); $rows = $this->term_rows(); $offset = max( 0, (int) $after_id ); $limit = max( 1, (int) $limit ); $slice = array_slice( $rows, $offset, $limit ); if ( ! $slice ) { return $out; } foreach ( $slice as $row ) { $offset++; $out['last_id'] = $offset; if ( ! term_exists( $row['term_id'], $row['taxonomy'] ) ) { $out['skipped']++; continue; } list( $fields, $stripped ) = $this->map_term_meta( $row['meta'] ); if ( ! $fields ) { $out['skipped']++; continue; } AIEO_SEO_Store::save( $row['taxonomy'], $row['term_id'], $fields ); if ( $stripped ) { $out['stripped']++; } $out['imported']++; } $out['done'] = ( count( $slice ) < $limit ); return $out; } private function map_meta( $meta, $post_type, $page_type = 'post' ) { $fields = array(); $stripped = false; $title = $this->tags( $this->val( $meta, '_yoast_wpseo_title' ), $post_type, $page_type ); if ( '' !== $title ) { $fields['title'] = $title; } $desc = $this->tags( $this->val( $meta, '_yoast_wpseo_metadesc' ), $post_type, $page_type ); if ( '' !== $desc ) { $fields['description'] = $desc; } $canonical = trim( (string) $this->val( $meta, '_yoast_wpseo_canonical' ) ); if ( '' !== $canonical ) { $fields['canonical_override'] = esc_url_raw( $canonical ); } foreach ( self::$direct_map as $key => $col ) { $v = $this->tags( $this->val( $meta, $key ), $post_type, $page_type ); if ( '' !== $v ) { $fields[ $col ] = $v; } } $og_image = trim( (string) $this->val( $meta, '_yoast_wpseo_opengraph-image' ) ); if ( '' !== $og_image ) { $fields['og_image_custom_url'] = esc_url_raw( $og_image ); $fields['og_image_type'] = 'custom_image'; } $og_image_id = (int) $this->val( $meta, '_yoast_wpseo_opengraph-image-id' ); if ( $og_image_id > 0 ) { $fields['og_image_id'] = $og_image_id; } $tw_image = trim( (string) $this->val( $meta, '_yoast_wpseo_twitter-image' ) ); if ( '' !== $tw_image ) { $fields['twitter_image_custom_url'] = esc_url_raw( $tw_image ); $fields['twitter_image_type'] = 'custom_image'; } $fields['twitter_use_og'] = ( isset( $fields['twitter_title'] ) || isset( $fields['twitter_description'] ) || isset( $fields['twitter_image_custom_url'] ) ) ? 0 : 1; $fields += $this->robots_from_meta( $meta ); $focus = (string) $this->val( $meta, '_yoast_wpseo_focuskw' ); $additional = array(); $extra_json = (string) $this->val( $meta, '_yoast_wpseo_focuskeywords' ); if ( '' !== $extra_json ) { $decoded = json_decode( $extra_json, true ); foreach ( (array) $decoded as $kw ) { if ( is_array( $kw ) && ! empty( $kw['keyword'] ) ) { $additional[] = (string) $kw['keyword']; } } } $fields += $this->keyphrase_fields( $focus, $additional ); $fields['pillar_content'] = ! empty( $meta['_yoast_wpseo_is_cornerstone'] ) ? 1 : 0; $schema = (string) $this->val( $meta, '_yoast_wpseo_schema_article_type' ); if ( '' === $schema || 'none' === strtolower( $schema ) ) { $schema = (string) $this->val( $meta, '_yoast_wpseo_schema_page_type' ); } list( $our_type, $stripped ) = $this->normalise_schema_type( $schema ); if ( '' !== $our_type ) { $fields['schema_type'] = $our_type; } $primary = array(); foreach ( $meta as $key => $value ) { if ( 0 === strpos( (string) $key, '_yoast_wpseo_primary_' ) ) { $tax = substr( (string) $key, strlen( '_yoast_wpseo_primary_' ) ); if ( '' !== $tax ) { $primary[ $tax ] = (int) $value; } } } $fields += $this->primary_term_fields( $primary ); if ( ! $this->has_authored_meta( $meta ) ) { return array( array(), false ); } return array( $fields, $stripped ); } private function map_term_meta( $meta ) { $translated = array(); $map = array( 'wpseo_title' => '_yoast_wpseo_title', 'wpseo_desc' => '_yoast_wpseo_metadesc', 'wpseo_canonical' => '_yoast_wpseo_canonical', 'wpseo_focuskw' => '_yoast_wpseo_focuskw', 'wpseo_focuskeywords' => '_yoast_wpseo_focuskeywords', 'wpseo_opengraph-title' => '_yoast_wpseo_opengraph-title', 'wpseo_opengraph-description' => '_yoast_wpseo_opengraph-description', 'wpseo_opengraph-image' => '_yoast_wpseo_opengraph-image', 'wpseo_opengraph-image-id' => '_yoast_wpseo_opengraph-image-id', 'wpseo_twitter-title' => '_yoast_wpseo_twitter-title', 'wpseo_twitter-description' => '_yoast_wpseo_twitter-description', 'wpseo_twitter-image' => '_yoast_wpseo_twitter-image', 'wpseo_is_cornerstone' => '_yoast_wpseo_is_cornerstone', ); foreach ( $map as $from => $to ) { if ( isset( $meta[ $from ] ) && '' !== (string) $meta[ $from ] && '[]' !== (string) $meta[ $from ] ) { $translated[ $to ] = $meta[ $from ]; } } $ni = isset( $meta['wpseo_noindex'] ) ? (string) $meta['wpseo_noindex'] : 'default'; if ( 'noindex' === $ni ) { $translated['_yoast_wpseo_meta-robots-noindex'] = '1'; } elseif ( 'index' === $ni ) { $translated['_yoast_wpseo_meta-robots-noindex'] = '2'; } if ( ! $translated ) { return array( array(), false ); } return $this->map_meta( $translated, '', 'term' ); } private function has_authored_meta( $meta ) { $authored = array( '_yoast_wpseo_title', '_yoast_wpseo_metadesc', '_yoast_wpseo_canonical', '_yoast_wpseo_focuskw', '_yoast_wpseo_focuskeywords', '_yoast_wpseo_opengraph-title', '_yoast_wpseo_opengraph-description', '_yoast_wpseo_opengraph-image', '_yoast_wpseo_twitter-title', '_yoast_wpseo_twitter-description', '_yoast_wpseo_twitter-image', '_yoast_wpseo_meta-robots-noindex', '_yoast_wpseo_meta-robots-nofollow', '_yoast_wpseo_meta-robots-adv', '_yoast_wpseo_is_cornerstone', '_yoast_wpseo_schema_page_type', '_yoast_wpseo_schema_article_type', ); foreach ( $authored as $k ) { if ( isset( $meta[ $k ] ) && '' !== trim( (string) $meta[ $k ] ) && '[]' !== (string) $meta[ $k ] && '0' !== (string) $meta[ $k ] ) { return true; } } foreach ( array_keys( $meta ) as $k ) { if ( 0 === strpos( (string) $k, '_yoast_wpseo_primary_' ) && (int) $meta[ $k ] > 0 ) { return true; } } return false; } private function robots_from_meta( $meta ) { $flags = array(); $explicit = false; $noindex = (string) $this->val( $meta, '_yoast_wpseo_meta-robots-noindex' ); if ( '1' === $noindex ) { $flags['noindex'] = true; $explicit = true; } elseif ( '2' === $noindex ) { $explicit = true; } if ( '1' === (string) $this->val( $meta, '_yoast_wpseo_meta-robots-nofollow' ) ) { $flags['nofollow'] = true; $explicit = true; } $adv = trim( (string) $this->val( $meta, '_yoast_wpseo_meta-robots-adv' ) ); if ( '' !== $adv && 'none' !== $adv && '-' !== $adv ) { $allowed = array( 'noarchive', 'noimageindex', 'nosnippet' ); foreach ( explode( ',', $adv ) as $token ) { $token = trim( $token ); if ( in_array( $token, $allowed, true ) ) { $flags[ $token ] = true; $explicit = true; } } } return $this->robots_fields( $explicit, $flags ); } private function val( $meta, $key ) { return isset( $meta[ $key ] ) ? (string) $meta[ $key ] : ''; } private function tags( $string, $post_type = '', $page_type = 'post' ) { if ( '' === (string) $string ) { return ''; } $macros = array( '%%sitename%%' => '#site_title', '%%sitedesc%%' => '#tagline', '%%sep%%' => '#separator_sa', '%%term_title%%' => '#taxonomy_title', '%%term_description%%' => '#taxonomy_description', '%%category_description%%' => '#taxonomy_description', '%%tag_description%%' => '#taxonomy_description', '%%primary_category%%' => '#taxonomy_title', '%%archive_title%%' => '#archive_title', '%%excerpt%%' => '#post_excerpt', '%%excerpt_only%%' => '#post_excerpt', '%%currentyear%%' => '#current_year', '%%searchphrase%%' => '#search_term', ); if ( 'archive' === $page_type ) { $macros['%%title%%'] = '#archive_title'; } elseif ( 'term' === $page_type ) { $macros['%%title%%'] = '#taxonomy_title'; } else { $macros['%%title%%'] = '#post_title'; } if ( '' !== $post_type ) { $obj = get_post_type_object( $post_type ); if ( $obj && isset( $obj->labels ) ) { $macros['%%pt_single%%'] = (string) $obj->labels->singular_name; $macros['%%pt_plural%%'] = (string) $obj->labels->name; } } return $this->macros_to_tags( $string, $macros, '%%[a-zA-Z_][a-zA-Z0-9_\-]*%%' ); } public function import_options() { if ( ! class_exists( 'AIEO_DMM_Settings' ) ) { return array( 'imported' => false, 'post_types' => 0, 'taxonomies' => 0 ); } $titles = get_option( 'wpseo_titles' ); $social = get_option( 'wpseo_social' ); $base = get_option( 'wpseo' ); if ( ! is_array( $titles ) && ! is_array( $social ) ) { return array( 'imported' => false, 'post_types' => 0, 'taxonomies' => 0 ); } $titles = is_array( $titles ) ? $titles : array(); $social = is_array( $social ) ? $social : array(); $base = is_array( $base ) ? $base : array(); $seo = (array) AIEO_DMM_Settings::get( 'seo', array() ); $sep_key = isset( $titles['separator'] ) ? (string) $titles['separator'] : ''; if ( isset( self::$separators[ $sep_key ] ) ) { $seo['separator'] = self::$separators[ $sep_key ]; } $sep = isset( $seo['separator'] ) ? (string) $seo['separator'] : '-'; $represents = (string) ( $titles['company_or_person'] ?? ( $base['company_or_person'] ?? '' ) ); $is_person = ( 'person' === $represents ); if ( '' !== $represents ) { $seo['org_represents'] = $is_person ? 'person' : 'organization'; } if ( $is_person ) { $person = (string) ( $titles['person_name'] ?? '' ); if ( '' === $person ) { $uid = (int) ( $titles['company_or_person_user_id'] ?? 0 ); if ( $uid > 0 ) { $u = get_userdata( $uid ); $person = $u ? (string) $u->display_name : ''; } } if ( '' !== $person ) { $seo['org_name'] = $person; } $logo = (string) ( $titles['person_logo'] ?? '' ); if ( '' !== $logo ) { $seo['org_logo'] = esc_url_raw( $logo ); } } else { $company = (string) ( $titles['company_name'] ?? '' ); if ( '' !== $company ) { $seo['org_name'] = $this->tags( $company, '', 'post' ); } $logo = (string) ( $titles['company_logo'] ?? '' ); if ( '' !== $logo ) { $seo['org_logo'] = esc_url_raw( $logo ); } } $same = array(); foreach ( array( 'facebook_site', 'instagram_url', 'linkedin_url', 'myspace_url', 'pinterest_url', 'youtube_url', 'wikipedia_url', 'soundcloud_url', 'tumblr_url' ) as $k ) { $u = trim( (string) ( $social[ $k ] ?? '' ) ); if ( '' !== $u ) { $same[] = esc_url_raw( $u ); } } $handle = trim( (string) ( $social['twitter_site'] ?? '' ) ); if ( '' !== $handle ) { $same[] = ( 0 === strpos( $handle, 'http' ) ) ? esc_url_raw( $handle ) : 'https://x.com/' . ltrim( $handle, '@' ); } foreach ( (array) ( $social['other_social_urls'] ?? array() ) as $u ) { $u = trim( (string) $u ); if ( '' !== $u ) { $same[] = esc_url_raw( $u ); } } if ( $same ) { $seo['social_urls'] = array_values( array_unique( array_filter( $same ) ) ); } $og_img = trim( (string) ( $social['og_default_image'] ?? '' ) ); if ( '' !== $og_img ) { $seo['og_default_image'] = esc_url_raw( $og_img ); } $existing = AIEO_DMM_Settings::get( 'seo.robots_global', array() ); $existing = is_array( $existing ) ? $existing : array(); $seo['robots_global'] = array_merge( $existing, array( 'noindex' => ! empty( $existing['noindex'] ), 'noindex_paginated' => ! empty( $titles['noindex-subpages-wpseo'] ), ) ); $seo['post_types'] = array(); foreach ( get_post_types( array( 'public' => true ), 'names' ) as $type ) { $cfg = $this->type_cfg( $titles, 'title-' . $type, 'metadesc-' . $type, 'noindex-' . $type, $type ); if ( $cfg ) { $seo['post_types'][ $type ] = $cfg; } } $seo['taxonomies'] = array(); foreach ( get_taxonomies( array( 'public' => true ), 'names' ) as $tax ) { $cfg = $this->type_cfg( $titles, 'title-tax-' . $tax, 'metadesc-tax-' . $tax, 'noindex-tax-' . $tax, '', 'term' ); if ( $cfg ) { $seo['taxonomies'][ $tax ] = $cfg; } } $all = AIEO_DMM_Settings::get_all(); $all['seo'] = $seo; AIEO_DMM_Settings::replace( $all ); return array( 'imported' => true, 'post_types' => count( $seo['post_types'] ), 'taxonomies' => count( $seo['taxonomies'] ), ); } private function type_cfg( $titles, $title_key, $desc_key, $noindex_key, $post_type = '', $page_type = 'post' ) { $has = array_key_exists( $title_key, $titles ) || array_key_exists( $desc_key, $titles ) || array_key_exists( $noindex_key, $titles ); if ( ! $has ) { return null; } $schema = ''; if ( '' !== $post_type ) { $article = (string) ( $titles[ 'schema-article-type-' . $post_type ] ?? '' ); $page = (string) ( $titles[ 'schema-page-type-' . $post_type ] ?? '' ); $raw = ( '' !== $article && 'None' !== $article ) ? $article : $page; list( $schema ) = $this->normalise_schema_type( $raw ); } return array( 'title' => $this->tags( (string) ( $titles[ $title_key ] ?? '' ), $post_type, $page_type ), 'description' => $this->tags( (string) ( $titles[ $desc_key ] ?? '' ), $post_type, $page_type ), 'schema_type' => $schema, 'noindex' => ! empty( $titles[ $noindex_key ] ), ); } public function has_redirects() { $plain = get_option( 'wpseo-premium-redirects-base' ); $regex = get_option( 'wpseo-premium-redirects-base-regex' ); return ( is_array( $plain ) && $plain ) || ( is_array( $regex ) && $regex ); } public function import_redirects() { if ( ! class_exists( 'AIEO_SEO_Redirects' ) ) { return parent::import_redirects(); } return AIEO_SEO_Redirects::import_yoast(); } public function mapping_report() { return array( '_yoast_wpseo_title / _metadesc' => array( 'status' => 'transformed', 'detail' => 'Yoast %%macros%% converted to our #smart-tags; macros with no equivalent (%%page%%, %%pagetotal%%, %%focuskw%%, %%cf_*%%) are REMOVED rather than carried, so no title renders vendor syntax' ), '_yoast_wpseo_canonical' => array( 'status' => 'transformed', 'detail' => '→ canonical_override (our canonical_url is the materialised path)' ), '_yoast_wpseo_meta-robots-noindex' => array( 'status' => 'transformed', 'detail' => "1 = noindex; 2 = explicitly INDEX (kept as an override, NOT read as noindex); 0/absent = inherit" ), '_yoast_wpseo_meta-robots-nofollow / -adv' => array( 'status' => 'mapped', 'detail' => 'nofollow + noarchive / noimageindex / nosnippet' ), '_yoast_wpseo_focuskw / _focuskeywords' => array( 'status' => 'mapped', 'detail' => 'focus keyphrase + Premium additional keyphrases → keyphrases JSON + focus_keyphrase' ), '_yoast_wpseo_primary_{taxonomy}' => array( 'status' => 'transformed', 'detail' => '→ primary_term JSON + flat primary_cat_id' ), '_yoast_wpseo_opengraph-* / twitter-*' => array( 'status' => 'transformed', 'detail' => 'custom URL + id copied; Twitter-vs-OG is DERIVED (Yoast has no such switch — any Twitter-specific value means "do not reuse OG")' ), '_yoast_wpseo_schema_article_type / _page_type' => array( 'status' => 'transformed', 'detail' => 'article type wins; mapped to Article / Product / WebPage' ), 'FAQPage / HowTo schema' => array( 'status' => 'dropped', 'detail' => 'STRIPPED to WebPage — no longer rich-result-eligible (FAQ ended 2026-05-07)' ), '_yoast_wpseo_is_cornerstone' => array( 'status' => 'mapped', 'detail' => '→ pillar_content (AIEO also auto-derives pillars from performance)' ), 'wpseo_taxonomy_meta' => array( 'status' => 'mapped', 'detail' => 'term titles/descriptions/canonicals/robots/social; entries whose term no longer exists are skipped' ), 'wp_yoast_indexable' => array( 'status' => 'dropped', 'detail' => 'NOT read — it is a derived cache Yoast rebuilds from postmeta and is routinely stale or unbuilt; postmeta is the authored source' ), '_yoast_wpseo_linkdex / _content_score / _inclusive_language_score' => array( 'status' => 'dropped', 'detail' => 'recomputed by our own demand-aware score' ), '_yoast_wpseo_bctitle' => array( 'status' => 'dropped', 'detail' => 'breadcrumb title — our breadcrumbs use the object title' ), '_yoast_wpseo_estimated-reading-time-minutes' => array( 'status' => 'dropped', 'detail' => 'derived value, not a setting' ), 'wpseo_titles (per type/taxonomy)' => array( 'status' => 'mapped', 'detail' => 'title + description formats, schema type and the noindex switch, per public post type and taxonomy' ), 'wpseo_social' => array( 'status' => 'transformed', 'detail' => 'profile URLs → sameAs (twitter_site is a HANDLE and is expanded to a URL); og_default_image copied' ), 'wpseo_titles separator' => array( 'status' => 'transformed', 'detail' => "Yoast stores a key ('sc-dash'); resolved to the character" ), 'Yoast Premium redirects' => array( 'status' => 'deferred', 'detail' => 'imported by the Redirects tool — validated (target must resolve, no loops) before entering' ), 'Breadcrumb / RSS / archive settings' => array( 'status' => 'dropped', 'detail' => 'not migrated (out of scope)' ), ); } }