| Current Path : /home/xbodynamge/namtation/wp-content/ |
| Current File : /home/xbodynamge/namtation/wp-content/YoastSeo.tar |
Helpers.php 0000666 00000011315 15113765011 0006664 0 ustar 00 <?php
namespace AIOSEO\Plugin\Common\ImportExport\YoastSeo;
// Exit if accessed directly.
if ( ! defined( 'ABSPATH' ) ) {
exit;
}
use AIOSEO\Plugin\Common\ImportExport;
// phpcs:disable WordPress.Arrays.ArrayDeclarationSpacing.AssociativeArrayFound
/**
* Contains helper methods for the import from Rank Math.
*
* @since 4.0.0
*/
class Helpers extends ImportExport\Helpers {
/**
* Converts the macros from Yoast SEO to our own smart tags.
*
* @since 4.0.0
*
* @param string $string The string with macros.
* @param string $postType The post type.
* @param string $pageType The page type.
* @return string $string The string with smart tags.
*/
public function macrosToSmartTags( $string, $postType = null, $pageType = null ) {
$macros = $this->getMacros( $postType, $pageType );
if ( preg_match( '#%%BLOGDESCLINK%%#', (string) $string ) ) {
$blogDescriptionLink = '<a href="' .
aioseo()->helpers->decodeHtmlEntities( get_bloginfo( 'url' ) ) . '">' .
aioseo()->helpers->decodeHtmlEntities( get_bloginfo( 'name' ) ) . ' - ' .
aioseo()->helpers->decodeHtmlEntities( get_bloginfo( 'description' ) ) . '</a>';
$string = str_replace( '%%BLOGDESCLINK%%', $blogDescriptionLink, $string );
}
if ( preg_match_all( '#%%cf_([^%]*)%%#', (string) $string, $matches ) && ! empty( $matches[1] ) ) {
foreach ( $matches[1] as $name ) {
if ( ! preg_match( '#\s#', (string) $name ) ) {
$string = aioseo()->helpers->pregReplace( "#%%cf_$name%%#", "#custom_field-$name", $string );
}
}
}
if ( preg_match_all( '#%%tax_([^%]*)%%#', (string) $string, $matches ) && ! empty( $matches[1] ) ) {
foreach ( $matches[1] as $name ) {
if ( ! preg_match( '#\s#', (string) $name ) ) {
$string = aioseo()->helpers->pregReplace( "#%%tax_$name%%#", "#tax_name-$name", $string );
}
}
}
foreach ( $macros as $macro => $tag ) {
$string = aioseo()->helpers->pregReplace( "#$macro(?![a-zA-Z0-9_])#im", $tag, $string );
}
// Strip out all remaining tags.
$string = aioseo()->helpers->pregReplace( '/%[^\%\s]*\([^\%]*\)%/i', '', aioseo()->helpers->pregReplace( '/%[^\%\s]*%/i', '', $string ) );
return trim( $string );
}
/**
* Returns the macro mappings.
*
* @since 4.1.1
*
* @param string $postType The post type.
* @param string $pageType The page type.
* @return array $macros The macros.
*/
protected function getMacros( $postType = null, $pageType = null ) {
$macros = [
'%%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',
'%%pagenumber%%' => '#page_number',
'%%caption%%' => '#attachment_caption',
'%%name%%' => '#author_first_name #author_last_name',
'%%user_description%%' => '#author_bio',
'%%date%%' => '#archive_date',
'%%currentday%%' => '#current_day',
'%%currentmonth%%' => '#current_month',
'%%currentyear%%' => '#current_year',
'%%searchphrase%%' => '#search_term',
'%%AUTHORLINK%%' => '#author_link',
'%%POSTLINK%%' => '#post_link',
'%%BLOGLINK%%' => '#site_link',
'%%category%%' => '#categories',
'%%parent_title%%' => '#parent_title',
'%%wc_sku%%' => '#woocommerce_sku',
'%%wc_price%%' => '#woocommerce_price',
'%%wc_brand%%' => '#woocommerce_brand',
'%%excerpt%%' => '#post_excerpt',
'%%excerpt_only%%' => '#post_excerpt_only'
/* '%%tag%%' => '',
'%%id%%' => '',
'%%page%%' => '',
'%%modified%%' => '',
'%%pagetotal%%' => '',
'%%focuskw%%' => '',
'%%term404%%' => '',
'%%ct_desc_[^%]*%%' => '' */
];
if ( $postType ) {
$postType = get_post_type_object( $postType );
if ( ! empty( $postType ) ) {
$macros += [
'%%pt_single%%' => $postType->labels->singular_name,
'%%pt_plural%%' => $postType->labels->name,
];
}
}
switch ( $pageType ) {
case 'archive':
$macros['%%title%%'] = '#archive_title';
break;
case 'term':
$macros['%%title%%'] = '#taxonomy_title';
break;
default:
$macros['%%title%%'] = '#post_title';
break;
}
// Strip all other tags.
$macros['%%[^%]*%%'] = '';
return $macros;
}
} SearchAppearance.php 0000666 00000034145 15113765011 0010455 0 ustar 00 <?php
namespace AIOSEO\Plugin\Common\ImportExport\YoastSeo;
// Exit if accessed directly.
if ( ! defined( 'ABSPATH' ) ) {
exit;
}
use AIOSEO\Plugin\Common\ImportExport;
// phpcs:disable WordPress.Arrays.ArrayDeclarationSpacing.AssociativeArrayFound
/**
* Migrates the Search Appearance settings.
*
* @since 4.0.0
*/
class SearchAppearance {
/**
* List of options.
*
* @since 4.2.7
*
* @var array
*/
private $options = [];
/**
* Whether the homepage social settings have been imported here.
*
* @since 4.2.4
*
* @var bool
*/
public $hasImportedHomepageSocialSettings = false;
/**
* Class constructor.
*
* @since 4.0.0
*/
public function __construct() {
$this->options = get_option( 'wpseo_titles' );
if ( empty( $this->options ) ) {
return;
}
$this->migrateSeparator();
$this->migrateTitleFormats();
$this->migrateDescriptionFormats();
$this->migrateNoindexSettings();
$this->migratePostTypeSettings();
$this->migratePostTypeArchiveSettings();
$this->migrateRedirectAttachments();
$this->migrateKnowledgeGraphSettings();
$this->migrateRssContentSettings();
$this->migrateStripCategoryBase();
$this->migrateHomepageSocialSettings();
}
/**
* Migrates the title/description separator.
*
* @since 4.0.0
*
* @return void
*/
private function migrateSeparator() {
$separators = [
'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' => '>',
];
if ( ! empty( $this->options['separator'] ) && in_array( $this->options['separator'], array_keys( $separators ), true ) ) {
aioseo()->options->searchAppearance->global->separator = $separators[ $this->options['separator'] ];
}
}
/**
* Migrates the title formats.
*
* @since 4.0.0
*
* @return void
*/
private function migrateTitleFormats() {
aioseo()->options->searchAppearance->global->siteTitle =
aioseo()->helpers->sanitizeOption( aioseo()->importExport->yoastSeo->helpers->macrosToSmartTags( $this->options['title-home-wpseo'] ) );
aioseo()->options->searchAppearance->archives->date->title =
aioseo()->helpers->sanitizeOption( aioseo()->importExport->yoastSeo->helpers->macrosToSmartTags( $this->options['title-archive-wpseo'], null, 'archive' ) );
// Archive Title tag needs to be stripped since we don't support it for these two archives.
$value = aioseo()->helpers->sanitizeOption( aioseo()->importExport->yoastSeo->helpers->macrosToSmartTags( $this->options['title-author-wpseo'], null, 'archive' ) );
aioseo()->options->searchAppearance->archives->author->title = aioseo()->helpers->pregReplace( '/#archive_title/', '', $value );
$value = aioseo()->helpers->sanitizeOption( aioseo()->importExport->yoastSeo->helpers->macrosToSmartTags( $this->options['title-search-wpseo'], null, 'archive' ) );
aioseo()->options->searchAppearance->archives->search->title = aioseo()->helpers->pregReplace( '/#archive_title/', '', $value );
}
/**
* Migrates the description formats.
*
* @since 4.0.0
*
* @return void
*/
private function migrateDescriptionFormats() {
$settings = [
'metadesc-home-wpseo' => [ 'type' => 'string', 'newOption' => [ 'searchAppearance', 'global', 'metaDescription' ] ],
'metadesc-author-wpseo' => [ 'type' => 'string', 'newOption' => [ 'searchAppearance', 'archives', 'author', 'metaDescription' ] ],
'metadesc-archive-wpseo' => [ 'type' => 'string', 'newOption' => [ 'searchAppearance', 'archives', 'date', 'metaDescription' ] ],
];
aioseo()->importExport->yoastSeo->helpers->mapOldToNew( $settings, $this->options, true );
}
/**
* Migrates the noindex settings.
*
* @since 4.0.0
*
* @return void
*/
private function migrateNoindexSettings() {
if ( ! empty( $this->options['noindex-author-wpseo'] ) ) {
aioseo()->options->searchAppearance->archives->author->show = false;
aioseo()->options->searchAppearance->archives->author->advanced->robotsMeta->default = false;
aioseo()->options->searchAppearance->archives->author->advanced->robotsMeta->noindex = true;
} else {
aioseo()->options->searchAppearance->archives->author->show = true;
}
if ( ! empty( $this->options['noindex-archive-wpseo'] ) ) {
aioseo()->options->searchAppearance->archives->date->show = false;
aioseo()->options->searchAppearance->archives->date->advanced->robotsMeta->default = false;
aioseo()->options->searchAppearance->archives->date->advanced->robotsMeta->noindex = true;
} else {
aioseo()->options->searchAppearance->archives->date->show = true;
}
}
/**
* Migrates the post type settings.
*
* @since 4.0.0
*
* @return void
*/
private function migratePostTypeSettings() {
$supportedSettings = [
'title',
'metadesc',
'noindex',
'display-metabox-pt',
'schema-page-type',
'schema-article-type'
];
foreach ( aioseo()->helpers->getPublicPostTypes( true ) as $postType ) {
foreach ( $this->options as $name => $value ) {
if ( ! preg_match( "#(.*)-$postType$#", (string) $name, $match ) || ! in_array( $match[1], $supportedSettings, true ) ) {
continue;
}
switch ( $match[1] ) {
case 'title':
if ( 'page' === $postType ) {
$value = aioseo()->helpers->pregReplace( '#%%primary_category%%#', '', $value );
$value = aioseo()->helpers->pregReplace( '#%%excerpt%%#', '', $value );
}
aioseo()->dynamicOptions->searchAppearance->postTypes->$postType->title =
aioseo()->helpers->sanitizeOption( aioseo()->importExport->yoastSeo->helpers->macrosToSmartTags( $value, $postType ) );
break;
case 'metadesc':
if ( 'page' === $postType ) {
$value = aioseo()->helpers->pregReplace( '#%%primary_category%%#', '', $value );
$value = aioseo()->helpers->pregReplace( '#%%excerpt%%#', '', $value );
}
aioseo()->dynamicOptions->searchAppearance->postTypes->$postType->metaDescription =
aioseo()->helpers->sanitizeOption( aioseo()->importExport->yoastSeo->helpers->macrosToSmartTags( $value, $postType ) );
break;
case 'noindex':
aioseo()->dynamicOptions->searchAppearance->postTypes->$postType->show = empty( $value ) ? true : false;
aioseo()->dynamicOptions->searchAppearance->postTypes->$postType->advanced->robotsMeta->default = empty( $value ) ? true : false;
aioseo()->dynamicOptions->searchAppearance->postTypes->$postType->advanced->robotsMeta->noindex = empty( $value ) ? false : true;
break;
case 'display-metabox-pt':
if ( empty( $value ) ) {
aioseo()->dynamicOptions->searchAppearance->postTypes->$postType->advanced->showMetaBox = false;
}
break;
case 'schema-page-type':
$value = aioseo()->helpers->pregReplace( '#\s#', '', $value );
if ( in_array( $postType, [ 'post', 'page', 'attachment' ], true ) ) {
break;
}
aioseo()->dynamicOptions->searchAppearance->postTypes->$postType->schemaType = 'WebPage';
if ( in_array( $value, ImportExport\SearchAppearance::$supportedWebPageGraphs, true ) ) {
aioseo()->dynamicOptions->searchAppearance->postTypes->$postType->webPageType = $value;
}
break;
case 'schema-article-type':
$value = aioseo()->helpers->pregReplace( '#\s#', '', $value );
if ( 'none' === lcfirst( $value ) ) {
aioseo()->dynamicOptions->searchAppearance->postTypes->$postType->articleType = 'none';
break;
}
aioseo()->dynamicOptions->searchAppearance->postTypes->$postType->articleType = 'Article';
if ( in_array( $value, ImportExport\SearchAppearance::$supportedArticleGraphs, true ) ) {
if ( ! in_array( $postType, [ 'page', 'attachment' ], true ) ) {
aioseo()->dynamicOptions->searchAppearance->postTypes->$postType->articleType = $value;
}
} else {
aioseo()->dynamicOptions->searchAppearance->postTypes->$postType->articleType = 'BlogPosting';
}
break;
default:
break;
}
}
}
}
/**
* Migrates the post type archive settings.
*
* @since 4.0.16
*
* @return void
*/
private function migratePostTypeArchiveSettings() {
$supportedSettings = [
'title',
'metadesc',
'noindex'
];
foreach ( aioseo()->helpers->getPublicPostTypes( true, true ) as $postType ) {
foreach ( $this->options as $name => $value ) {
if ( ! preg_match( "#(.*)-ptarchive-$postType$#", (string) $name, $match ) || ! in_array( $match[1], $supportedSettings, true ) ) {
continue;
}
switch ( $match[1] ) {
case 'title':
aioseo()->dynamicOptions->searchAppearance->archives->$postType->title =
aioseo()->helpers->sanitizeOption( aioseo()->importExport->yoastSeo->helpers->macrosToSmartTags( $value, $postType, 'archive' ) );
break;
case 'metadesc':
aioseo()->dynamicOptions->searchAppearance->archives->$postType->metaDescription =
aioseo()->helpers->sanitizeOption( aioseo()->importExport->yoastSeo->helpers->macrosToSmartTags( $value, $postType, 'archive' ) );
break;
case 'noindex':
aioseo()->dynamicOptions->searchAppearance->archives->$postType->show = empty( $value ) ? true : false;
aioseo()->dynamicOptions->searchAppearance->archives->$postType->advanced->robotsMeta->default = empty( $value ) ? true : false;
aioseo()->dynamicOptions->searchAppearance->archives->$postType->advanced->robotsMeta->noindex = empty( $value ) ? false : true;
break;
default:
break;
}
}
}
}
/**
* Migrates the Knowledge Graph settings.
*
* @since 4.0.0
*
* @return void
*/
private function migrateKnowledgeGraphSettings() {
if ( ! empty( $this->options['company_or_person'] ) ) {
aioseo()->options->searchAppearance->global->schema->siteRepresents =
'company' === $this->options['company_or_person'] ? 'organization' : 'person';
}
$settings = [
'company_or_person_user_id' => [ 'type' => 'string', 'newOption' => [ 'searchAppearance', 'global', 'schema', 'person' ] ],
'person_logo' => [ 'type' => 'string', 'newOption' => [ 'searchAppearance', 'global', 'schema', 'personLogo' ] ],
'person_name' => [ 'type' => 'string', 'newOption' => [ 'searchAppearance', 'global', 'schema', 'personName' ] ],
'company_name' => [ 'type' => 'string', 'newOption' => [ 'searchAppearance', 'global', 'schema', 'organizationName' ] ],
'company_logo' => [ 'type' => 'string', 'newOption' => [ 'searchAppearance', 'global', 'schema', 'organizationLogo' ] ],
'org-email' => [ 'type' => 'string', 'newOption' => [ 'searchAppearance', 'global', 'schema', 'email' ] ],
'org-phone' => [ 'type' => 'string', 'newOption' => [ 'searchAppearance', 'global', 'schema', 'phone' ] ],
'org-description' => [ 'type' => 'string', 'newOption' => [ 'searchAppearance', 'global', 'schema', 'organizationDescription' ] ],
'org-founding-date' => [ 'type' => 'string', 'newOption' => [ 'searchAppearance', 'global', 'schema', 'foundingDate' ] ],
];
aioseo()->importExport->yoastSeo->helpers->mapOldToNew( $settings, $this->options );
// Additional Info
// Reset data
aioseo()->options->noConflict()->searchAppearance->global->schema->numberOfEmployees->reset();
$numberOfEmployees = $this->options['org-number-employees'];
if ( ! empty( $numberOfEmployees ) ) {
list( $num1, $num2 ) = explode( '-', $numberOfEmployees );
if ( $num2 ) {
aioseo()->options->noConflict()->searchAppearance->global->schema->numberOfEmployees->isRange = true;
aioseo()->options->noConflict()->searchAppearance->global->schema->numberOfEmployees->from = (int) $num1;
aioseo()->options->noConflict()->searchAppearance->global->schema->numberOfEmployees->to = (int) $num2;
} else {
aioseo()->options->noConflict()->searchAppearance->global->schema->numberOfEmployees->number = (int) $num1;
}
}
}
/**
* Migrates the RSS content settings.
*
* @since 4.0.0
*
* @return void
*/
private function migrateRssContentSettings() {
if ( isset( $this->options['rssbefore'] ) ) {
aioseo()->options->rssContent->before = esc_html( aioseo()->importExport->yoastSeo->helpers->macrosToSmartTags( $this->options['rssbefore'] ) );
}
if ( isset( $this->options['rssafter'] ) ) {
aioseo()->options->rssContent->after = esc_html( aioseo()->importExport->yoastSeo->helpers->macrosToSmartTags( $this->options['rssafter'] ) );
}
}
/**
* Migrates the Redirect Attachments setting.
*
* @since 4.0.0
*
* @return void
*/
private function migrateRedirectAttachments() {
aioseo()->dynamicOptions->searchAppearance->postTypes->attachment->redirectAttachmentUrls = empty( $this->options['disable-attachment'] ) ? 'disabled' : 'attachment';
}
/**
* Migrates the strip category base option.
*
* @since 4.2.0
*
* @return void
*/
private function migrateStripCategoryBase() {
aioseo()->options->searchAppearance->advanced->removeCategoryBase = empty( $this->options['stripcategorybase'] ) ? false : true;
}
/**
* Migrate the social settings for the homepage.
*
* @since 4.2.4
*
* @return void
*/
private function migrateHomepageSocialSettings() {
if (
empty( $this->options['open_graph_frontpage_title'] ) &&
empty( $this->options['open_graph_frontpage_desc'] ) &&
empty( $this->options['open_graph_frontpage_image'] )
) {
return;
}
$this->hasImportedHomepageSocialSettings = true;
$settings = [
// These settings can also be found in the SocialMeta class, but Yoast recently moved them here.
// We'll still keep them in the other class for backwards compatibility.
'open_graph_frontpage_title' => [ 'type' => 'string', 'newOption' => [ 'social', 'facebook', 'homePage', 'title' ] ],
'open_graph_frontpage_desc' => [ 'type' => 'string', 'newOption' => [ 'social', 'facebook', 'homePage', 'description' ] ],
'open_graph_frontpage_image' => [ 'type' => 'string', 'newOption' => [ 'social', 'facebook', 'homePage', 'image' ] ]
];
aioseo()->importExport->yoastSeo->helpers->mapOldToNew( $settings, $this->options, true );
}
} YoastSeo.php 0000666 00000004174 15113765011 0007035 0 ustar 00 <?php
namespace AIOSEO\Plugin\Common\ImportExport\YoastSeo;
// Exit if accessed directly.
if ( ! defined( 'ABSPATH' ) ) {
exit;
}
use AIOSEO\Plugin\Common\ImportExport;
class YoastSeo extends ImportExport\Importer {
/**
* A list of plugins to look for to import.
*
* @since 4.0.0
*
* @var array
*/
public $plugins = [
[
'name' => 'Yoast SEO',
'version' => '14.0',
'basename' => 'wordpress-seo/wp-seo.php',
'slug' => 'yoast-seo'
],
[
'name' => 'Yoast SEO Premium',
'version' => '14.0',
'basename' => 'wordpress-seo-premium/wp-seo-premium.php',
'slug' => 'yoast-seo-premium'
],
];
/**
* The post action name.
*
* @since 4.0.0
*
* @var string
*/
public $postActionName = 'aioseo_import_post_meta_yoast_seo';
/**
* The user action name.
*
* @since 4.1.4
*
* @var string
*/
public $userActionName = 'aioseo_import_user_meta_yoast_seo';
/**
* UserMeta class instance.
*
* @since 4.2.7
*
* @var UserMeta
*/
private $userMeta = null;
/**
* SearchAppearance class instance.
*
* @since 4.2.7
*
* @var SearchAppearance
*/
public $searchAppearance = null;
/**
* The post action name.
*
* @since 4.0.0
*
* @param ImportExport\ImportExport $importer The main importer class.
*/
public function __construct( $importer ) {
$this->helpers = new Helpers();
$this->postMeta = new PostMeta();
$this->userMeta = new UserMeta();
add_action( $this->postActionName, [ $this->postMeta, 'importPostMeta' ] );
add_action( $this->userActionName, [ $this->userMeta, 'importUserMeta' ] );
$plugins = $this->plugins;
foreach ( $plugins as $key => $plugin ) {
$plugins[ $key ]['class'] = $this;
}
$importer->addPlugins( $plugins );
}
/**
* Imports the settings.
*
* @since 4.0.0
*
* @return void
*/
protected function importSettings() {
new GeneralSettings();
$this->searchAppearance = new SearchAppearance();
// NOTE: The Social Meta settings need to be imported after the Search Appearance ones because some imports depend on what was imported there.
new SocialMeta();
$this->userMeta->scheduleImport();
}
} PostMeta.php 0000666 00000025720 15113765011 0007023 0 ustar 00 <?php
namespace AIOSEO\Plugin\Common\ImportExport\YoastSeo;
// Exit if accessed directly.
if ( ! defined( 'ABSPATH' ) ) {
exit;
}
use AIOSEO\Plugin\Common\ImportExport;
use AIOSEO\Plugin\Common\Models;
// phpcs:disable WordPress.Arrays.ArrayDeclarationSpacing.AssociativeArrayFound
/**
* Imports the post meta from Yoast SEO.
*
* @since 4.0.0
*/
class PostMeta {
/**
* Class constructor.
*
* @since 4.0.0
*/
public function scheduleImport() {
try {
if ( as_next_scheduled_action( aioseo()->importExport->yoastSeo->postActionName ) ) {
return;
}
if ( ! aioseo()->core->cache->get( 'import_post_meta_yoast_seo' ) ) {
aioseo()->core->cache->update( 'import_post_meta_yoast_seo', time(), WEEK_IN_SECONDS );
}
as_schedule_single_action( time(), aioseo()->importExport->yoastSeo->postActionName, [], 'aioseo' );
} catch ( \Exception $e ) {
// Do nothing.
}
}
/**
* Imports the post meta.
*
* @since 4.0.0
*
* @return void
*/
public function importPostMeta() {
$postsPerAction = apply_filters( 'aioseo_import_yoast_seo_posts_per_action', 100 );
$publicPostTypes = implode( "', '", aioseo()->helpers->getPublicPostTypes( true ) );
$timeStarted = gmdate( 'Y-m-d H:i:s', aioseo()->core->cache->get( 'import_post_meta_yoast_seo' ) );
$posts = aioseo()->core->db
->start( 'posts' . ' as p' )
->select( 'p.ID, p.post_type' )
->leftJoin( 'aioseo_posts as ap', '`p`.`ID` = `ap`.`post_id`' )
->whereRaw( "( p.post_type IN ( '$publicPostTypes' ) )" )
->whereRaw( "( ap.post_id IS NULL OR ap.updated < '$timeStarted' )" )
->orderBy( 'p.ID DESC' )
->limit( $postsPerAction )
->run()
->result();
if ( ! $posts || ! count( $posts ) ) {
aioseo()->core->cache->delete( 'import_post_meta_yoast_seo' );
return;
}
$mappedMeta = [
'_yoast_wpseo_title' => 'title',
'_yoast_wpseo_metadesc' => 'description',
'_yoast_wpseo_canonical' => 'canonical_url',
'_yoast_wpseo_meta-robots-noindex' => 'robots_noindex',
'_yoast_wpseo_meta-robots-nofollow' => 'robots_nofollow',
'_yoast_wpseo_meta-robots-adv' => '',
'_yoast_wpseo_focuskw' => '',
'_yoast_wpseo_focuskeywords' => '',
'_yoast_wpseo_opengraph-title' => 'og_title',
'_yoast_wpseo_opengraph-description' => 'og_description',
'_yoast_wpseo_opengraph-image' => 'og_image_custom_url',
'_yoast_wpseo_twitter-title' => 'twitter_title',
'_yoast_wpseo_twitter-description' => 'twitter_description',
'_yoast_wpseo_twitter-image' => 'twitter_image_custom_url',
'_yoast_wpseo_schema_page_type' => '',
'_yoast_wpseo_schema_article_type' => '',
'_yoast_wpseo_is_cornerstone' => 'pillar_content'
];
foreach ( $posts as $post ) {
$postMeta = aioseo()->core->db
->start( 'postmeta' . ' as pm' )
->select( 'pm.meta_key, pm.meta_value' )
->where( 'pm.post_id', $post->ID )
->whereRaw( "`pm`.`meta_key` LIKE '_yoast_wpseo_%'" )
->run()
->result();
$featuredImage = get_the_post_thumbnail_url( $post->ID );
$meta = [
'post_id' => (int) $post->ID,
'twitter_use_og' => true,
'og_image_type' => $featuredImage ? 'featured' : 'content',
'pillar_content' => 0,
'canonical_url' => '',
'robots_default' => true,
'robots_noarchive' => false,
'robots_nofollow' => false,
'robots_noimageindex' => false,
'robots_noindex' => false,
'robots_noodp' => false,
'robots_nosnippet' => false,
'title' => '',
'description' => '',
'og_title' => '',
'og_description' => '',
'og_image_custom_url' => '',
'twitter_title' => '',
'twitter_description' => '',
'twitter_image_custom_url' => '',
'twitter_image_type' => 'default'
];
if ( ! $postMeta || ! count( $postMeta ) ) {
$aioseoPost = Models\Post::getPost( (int) $post->ID );
$aioseoPost->set( $meta );
$aioseoPost->save();
aioseo()->migration->meta->migrateAdditionalPostMeta( $post->ID );
continue;
}
$title = '';
foreach ( $postMeta as $record ) {
$name = $record->meta_key;
$value = $record->meta_value;
// Handles primary taxonomy terms.
// We need to handle it separately because it's stored in a different format.
if ( false !== stripos( $name, '_yoast_wpseo_primary_' ) ) {
sscanf( $name, '_yoast_wpseo_primary_%s', $taxonomy );
if ( null === $taxonomy ) {
continue;
}
$options = new \stdClass();
if ( isset( $meta['primary_term'] ) ) {
$options = json_decode( $meta['primary_term'] );
}
$options->$taxonomy = (int) $value;
$meta['primary_term'] = wp_json_encode( $options );
}
if ( ! in_array( $name, array_keys( $mappedMeta ), true ) ) {
continue;
}
switch ( $name ) {
case '_yoast_wpseo_meta-robots-noindex':
case '_yoast_wpseo_meta-robots-nofollow':
if ( (bool) $value ) {
$meta[ $mappedMeta[ $name ] ] = (bool) $value;
$meta['robots_default'] = false;
}
break;
case '_yoast_wpseo_meta-robots-adv':
$supportedValues = [ 'index', 'noarchive', 'noimageindex', 'nosnippet' ];
foreach ( $supportedValues as $val ) {
$meta[ "robots_$val" ] = false;
}
// This is a separated foreach so we can import any and all values.
$values = explode( ',', $value );
if ( $values ) {
$meta['robots_default'] = false;
foreach ( $values as $value ) {
$meta[ "robots_$value" ] = true;
}
}
break;
case '_yoast_wpseo_canonical':
$meta[ $mappedMeta[ $name ] ] = esc_url( $value );
break;
case '_yoast_wpseo_opengraph-image':
$meta['og_image_type'] = 'custom_image';
$meta[ $mappedMeta[ $name ] ] = esc_url( $value );
break;
case '_yoast_wpseo_twitter-image':
$meta['twitter_use_og'] = false;
$meta['twitter_image_type'] = 'custom_image';
$meta[ $mappedMeta[ $name ] ] = esc_url( $value );
break;
case '_yoast_wpseo_schema_page_type':
$value = aioseo()->helpers->pregReplace( '#\s#', '', $value );
if ( in_array( $post->post_type, [ 'post', 'page', 'attachment' ], true ) ) {
break;
}
if ( ! in_array( $value, ImportExport\SearchAppearance::$supportedWebPageGraphs, true ) ) {
break;
}
$meta[ $mappedMeta[ $name ] ] = 'WebPage';
$meta['schema_type_options'] = wp_json_encode( [
'webPage' => [
'webPageType' => $value
]
] );
break;
case '_yoast_wpseo_schema_article_type':
$value = aioseo()->helpers->pregReplace( '#\s#', '', $value );
if ( 'none' === lcfirst( $value ) ) {
$meta[ $mappedMeta[ $name ] ] = 'None';
break;
}
if ( in_array( $post->post_type, [ 'page', 'attachment' ], true ) ) {
break;
}
$options = new \stdClass();
if ( isset( $meta['schema_type_options'] ) ) {
$options = json_decode( $meta['schema_type_options'] );
}
$options->article = [ 'articleType' => 'Article' ];
if ( in_array( $value, ImportExport\SearchAppearance::$supportedArticleGraphs, true ) ) {
$options->article = [ 'articleType' => $value ];
} else {
$options->article = [ 'articleType' => 'BlogPosting' ];
}
$meta['schema_type'] = 'Article';
$meta['schema_type_options'] = wp_json_encode( $options );
break;
case '_yoast_wpseo_focuskw':
$focusKeyphrase = [
'focus' => [ 'keyphrase' => aioseo()->helpers->sanitizeOption( $value ) ]
];
// Merge with existing keyphrases if the array key already exists.
if ( ! empty( $meta['keyphrases'] ) ) {
$meta['keyphrases'] = array_merge( $meta['keyphrases'], $focusKeyphrase );
} else {
$meta['keyphrases'] = $focusKeyphrase;
}
break;
case '_yoast_wpseo_focuskeywords':
$keyphrases = [];
if ( ! empty( $meta[ $mappedMeta[ $name ] ] ) ) {
$keyphrases = (array) json_decode( $meta[ $mappedMeta[ $name ] ] );
}
$yoastKeyphrases = json_decode( $value, true );
if ( is_array( $yoastKeyphrases ) ) {
foreach ( $yoastKeyphrases as $yoastKeyphrase ) {
if ( ! empty( $yoastKeyphrase['keyword'] ) ) {
$keyphrase = [ 'keyphrase' => aioseo()->helpers->sanitizeOption( $yoastKeyphrase['keyword'] ) ];
if ( ! isset( $keyphrases['additional'] ) ) {
$keyphrases['additional'] = [];
}
$keyphrases['additional'][] = $keyphrase;
}
}
}
if ( ! empty( $keyphrases ) ) {
// Merge with existing keyphrases if the array key already exists.
if ( ! empty( $meta['keyphrases'] ) ) {
$meta['keyphrases'] = array_merge( $meta['keyphrases'], $keyphrases );
} else {
$meta['keyphrases'] = $keyphrases;
}
}
break;
case '_yoast_wpseo_title':
case '_yoast_wpseo_metadesc':
case '_yoast_wpseo_opengraph-title':
case '_yoast_wpseo_opengraph-description':
case '_yoast_wpseo_twitter-title':
case '_yoast_wpseo_twitter-description':
if ( 'page' === $post->post_type ) {
$value = aioseo()->helpers->pregReplace( '#%%primary_category%%#', '', $value );
$value = aioseo()->helpers->pregReplace( '#%%excerpt%%#', '', $value );
}
if ( '_yoast_wpseo_twitter-title' === $name || '_yoast_wpseo_twitter-description' === $name ) {
$meta['twitter_use_og'] = false;
}
$value = aioseo()->importExport->yoastSeo->helpers->macrosToSmartTags( $value, 'post', $post->post_type );
if ( '_yoast_wpseo_title' === $name ) {
$title = $value;
}
$meta[ $mappedMeta[ $name ] ] = esc_html( wp_strip_all_tags( strval( $value ) ) );
break;
case '_yoast_wpseo_is_cornerstone':
$meta['pillar_content'] = (bool) $value ? 1 : 0;
break;
default:
$meta[ $mappedMeta[ $name ] ] = esc_html( wp_strip_all_tags( strval( $value ) ) );
break;
}
}
// Resetting the `twitter_use_og` option if the user has a custom title and no twitter title.
if ( $meta['twitter_use_og'] && $title && empty( $meta['twitter_title'] ) ) {
$meta['twitter_use_og'] = false;
$meta['twitter_title'] = $title;
}
$aioseoPost = Models\Post::getPost( (int) $post->ID );
$aioseoPost->set( $meta );
$aioseoPost->save();
aioseo()->migration->meta->migrateAdditionalPostMeta( $post->ID );
// Clear the Overview cache.
aioseo()->postSettings->clearPostTypeOverviewCache( $post->ID );
}
if ( count( $posts ) === $postsPerAction ) {
try {
as_schedule_single_action( time() + 5, aioseo()->importExport->yoastSeo->postActionName, [], 'aioseo' );
} catch ( \Exception $e ) {
// Do nothing.
}
} else {
aioseo()->core->cache->delete( 'import_post_meta_yoast_seo' );
}
}
} GeneralSettings.php 0000666 00000002233 15113765011 0010357 0 ustar 00 <?php
namespace AIOSEO\Plugin\Common\ImportExport\YoastSeo;
// Exit if accessed directly.
if ( ! defined( 'ABSPATH' ) ) {
exit;
}
// phpcs:disable WordPress.Arrays.ArrayDeclarationSpacing.AssociativeArrayFound
/**
* Migrates the General Settings.
*
* @since 4.0.0
*/
class GeneralSettings {
/**
* List of options.
*
* @since 4.2.7
*
* @var array
*/
private $options = [];
/**
* Class constructor.
*
* @since 4.0.0
*/
public function __construct() {
$this->options = get_option( 'wpseo' );
if ( empty( $this->options ) ) {
return;
}
$settings = [
'googleverify' => [ 'type' => 'string', 'newOption' => [ 'webmasterTools', 'google' ] ],
'msverify' => [ 'type' => 'string', 'newOption' => [ 'webmasterTools', 'bing' ] ],
'yandexverify' => [ 'type' => 'string', 'newOption' => [ 'webmasterTools', 'yandex' ] ],
'baiduverify' => [ 'type' => 'string', 'newOption' => [ 'webmasterTools', 'baidu' ] ],
'enable_xml_sitemap' => [ 'type' => 'boolean', 'newOption' => [ 'sitemap', 'general', 'enable' ] ]
];
aioseo()->importExport->yoastSeo->helpers->mapOldToNew( $settings, $this->options );
}
} SocialMeta.php 0000666 00000014250 15113765011 0007304 0 ustar 00 <?php
namespace AIOSEO\Plugin\Common\ImportExport\YoastSeo;
// Exit if accessed directly.
if ( ! defined( 'ABSPATH' ) ) {
exit;
}
use AIOSEO\Plugin\Common\Models;
// phpcs:disable WordPress.Arrays.ArrayDeclarationSpacing.AssociativeArrayFound
/**
* Migrates the Social Meta.
*
* @since 4.0.0
*/
class SocialMeta {
/**
* List of options.
*
* @since 4.2.7
*
* @var array
*/
private $options = [];
/**
* Class constructor.
*
* @since 4.0.0
*/
public function __construct() {
$this->options = get_option( 'wpseo_social' );
if ( empty( $this->options ) ) {
return;
}
$this->migrateSocialUrls();
$this->migrateFacebookSettings();
$this->migrateTwitterSettings();
$this->migrateFacebookAdminId();
$this->migrateSiteName();
$this->migrateArticleTags();
$this->migrateAdditionalTwitterData();
$settings = [
'pinterestverify' => [ 'type' => 'string', 'newOption' => [ 'webmasterTools', 'pinterest' ] ]
];
aioseo()->importExport->yoastSeo->helpers->mapOldToNew( $settings, $this->options );
}
/**
* Migrates the Social URLs.
*
* @since 4.0.0
*
* @return void
*/
private function migrateSocialUrls() {
$settings = [
'facebook_site' => [ 'type' => 'string', 'newOption' => [ 'social', 'profiles', 'urls', 'facebookPageUrl' ] ],
'instagram_url' => [ 'type' => 'string', 'newOption' => [ 'social', 'profiles', 'urls', 'instagramUrl' ] ],
'linkedin_url' => [ 'type' => 'string', 'newOption' => [ 'social', 'profiles', 'urls', 'linkedinUrl' ] ],
'myspace_url' => [ 'type' => 'string', 'newOption' => [ 'social', 'profiles', 'urls', 'myspaceUrl' ] ],
'pinterest_url' => [ 'type' => 'string', 'newOption' => [ 'social', 'profiles', 'urls', 'pinterestUrl' ] ],
'youtube_url' => [ 'type' => 'string', 'newOption' => [ 'social', 'profiles', 'urls', 'youtubeUrl' ] ],
'wikipedia_url' => [ 'type' => 'string', 'newOption' => [ 'social', 'profiles', 'urls', 'wikipediaUrl' ] ],
'wordpress_url' => [ 'type' => 'string', 'newOption' => [ 'social', 'profiles', 'urls', 'wordPressUrl' ] ],
];
if ( ! empty( $this->options['twitter_site'] ) ) {
aioseo()->options->social->profiles->urls->twitterUrl =
'https://x.com/' . aioseo()->helpers->sanitizeOption( $this->options['twitter_site'] );
}
aioseo()->importExport->yoastSeo->helpers->mapOldToNew( $settings, $this->options );
}
/**
* Migrates the Facebook settings.
*
* @since 4.0.0
*
* @return void
*/
private function migrateFacebookSettings() {
if ( ! empty( $this->options['og_default_image'] ) ) {
$defaultImage = esc_url( $this->options['og_default_image'] );
aioseo()->options->social->facebook->general->defaultImagePosts = $defaultImage;
aioseo()->options->social->facebook->general->defaultImageSourcePosts = 'default';
aioseo()->options->social->twitter->general->defaultImagePosts = $defaultImage;
aioseo()->options->social->twitter->general->defaultImageSourcePosts = 'default';
}
$settings = [
'opengraph' => [ 'type' => 'boolean', 'newOption' => [ 'social', 'facebook', 'general', 'enable' ] ],
];
if ( ! aioseo()->importExport->yoastSeo->searchAppearance->hasImportedHomepageSocialSettings ) {
// These settings were moved to the Search Appearance tab of Yoast, but we'll leave this here to support older versions.
// However, we want to make sure we import them only if the other ones aren't set.
$settings = array_merge( $settings, [
'og_frontpage_title' => [ 'type' => 'string', 'newOption' => [ 'social', 'facebook', 'homePage', 'title' ] ],
'og_frontpage_desc' => [ 'type' => 'string', 'newOption' => [ 'social', 'facebook', 'homePage', 'description' ] ],
'og_frontpage_image' => [ 'type' => 'string', 'newOption' => [ 'social', 'facebook', 'homePage', 'image' ] ]
] );
}
aioseo()->importExport->yoastSeo->helpers->mapOldToNew( $settings, $this->options, true );
// Migrate home page object type.
aioseo()->options->social->facebook->homePage->objectType = 'website';
if ( 'page' === get_option( 'show_on_front' ) ) {
$staticHomePageId = get_option( 'page_on_front' );
// We must check if the ID exists because one might select the static homepage option but not actually set one.
if ( ! $staticHomePageId ) {
return;
}
$aioseoPost = Models\Post::getPost( (int) $staticHomePageId );
$aioseoPost->set( [
'og_object_type' => 'website'
] );
$aioseoPost->save();
}
}
/**
* Migrates the Twitter settings.
*
* @since 4.0.0
*
* @return void
*/
private function migrateTwitterSettings() {
$settings = [
'twitter' => [ 'type' => 'boolean', 'newOption' => [ 'social', 'twitter', 'general', 'enable' ] ],
'twitter_card_type' => [ 'type' => 'string', 'newOption' => [ 'social', 'twitter', 'general', 'defaultCardType' ] ],
];
aioseo()->importExport->yoastSeo->helpers->mapOldToNew( $settings, $this->options );
}
/**
* Migrates the Facebook admin ID.
*
* @since 4.0.0
*
* @return void
*/
private function migrateFacebookAdminId() {
if ( ! empty( $this->options['fbadminapp'] ) ) {
aioseo()->options->social->facebook->advanced->enable = true;
aioseo()->options->social->facebook->advanced->adminId = aioseo()->helpers->sanitizeOption( $this->options['fbadminapp'] );
}
}
/**
* Yoast sets the og:site_name to '#site_title';
*
* @since 4.1.4
*
* @return void
*/
private function migrateSiteName() {
aioseo()->options->social->facebook->general->siteName = '#site_title';
}
/**
* Yoast uses post tags by default, so we need to enable this.
*
* @since 4.1.4
*
* @return void
*/
private function migrateArticleTags() {
aioseo()->options->social->facebook->advanced->enable = true;
aioseo()->options->social->facebook->advanced->generateArticleTags = true;
aioseo()->options->social->facebook->advanced->usePostTagsInTags = true;
aioseo()->options->social->facebook->advanced->useKeywordsInTags = false;
aioseo()->options->social->facebook->advanced->useCategoriesInTags = false;
}
/**
* Enable additional Twitter Data.
*
* @since 4.1.4
*
* @return void
*/
private function migrateAdditionalTwitterData() {
aioseo()->options->social->twitter->general->additionalData = true;
}
} UserMeta.php 0000666 00000005176 15113765011 0007017 0 ustar 00 <?php
namespace AIOSEO\Plugin\Common\ImportExport\YoastSeo;
// Exit if accessed directly.
if ( ! defined( 'ABSPATH' ) ) {
exit;
}
use AIOSEO\Plugin\Common\ImportExport;
use AIOSEO\Plugin\Common\Models;
// phpcs:disable WordPress.Arrays.ArrayDeclarationSpacing.AssociativeArrayFound
/**
* Imports the user meta from Yoast SEO.
*
* @since 4.0.0
*/
class UserMeta {
/**
* Class constructor.
*
* @since 4.0.0
*/
public function scheduleImport() {
aioseo()->actionScheduler->scheduleSingle( aioseo()->importExport->yoastSeo->userActionName, 30 );
if ( ! aioseo()->core->cache->get( 'import_user_meta_yoast_seo' ) ) {
aioseo()->core->cache->update( 'import_user_meta_yoast_seo', 0, WEEK_IN_SECONDS );
}
}
/**
* Imports the post meta.
*
* @since 4.0.0
*
* @return void
*/
public function importUserMeta() {
$usersPerAction = 100;
$offset = aioseo()->core->cache->get( 'import_user_meta_yoast_seo' );
$usersMeta = aioseo()->core->db
->start( aioseo()->core->db->db->usermeta . ' as um', true )
->whereRaw( "um.meta_key IN ('facebook', 'twitter', 'instagram', 'linkedin', 'myspace', 'pinterest', 'soundcloud', 'tumblr', 'wikipedia', 'youtube', 'mastodon', 'bluesky', 'threads')" )
->whereRaw( "um.meta_value != ''" )
->limit( $usersPerAction, $offset )
->run()
->result();
if ( ! $usersMeta || ! count( $usersMeta ) ) {
aioseo()->core->cache->delete( 'import_user_meta_yoast_seo' );
return;
}
$mappedMeta = [
'facebook' => 'aioseo_facebook_page_url',
'twitter' => 'aioseo_twitter_url',
'instagram' => 'aioseo_instagram_url',
'linkedin' => 'aioseo_linkedin_url',
'myspace' => 'aioseo_myspace_url',
'pinterest' => 'aioseo_pinterest_url',
'soundcloud' => 'aioseo_sound_cloud_url',
'tumblr' => 'aioseo_tumblr_url',
'wikipedia' => 'aioseo_wikipedia_url',
'youtube' => 'aioseo_youtube_url',
'bluesky' => 'aioseo_bluesky_url',
'threads' => 'aioseo_threads_url',
'mastodon' => 'aioseo_profiles_additional_urls'
];
foreach ( $usersMeta as $meta ) {
if ( isset( $mappedMeta[ $meta->meta_key ] ) ) {
$value = 'twitter' === $meta->meta_key ? 'https://x.com/' . $meta->meta_value : $meta->meta_value;
update_user_meta( $meta->user_id, $mappedMeta[ $meta->meta_key ], $value );
}
}
if ( count( $usersMeta ) === $usersPerAction ) {
aioseo()->core->cache->update( 'import_user_meta_yoast_seo', 100 + $offset, WEEK_IN_SECONDS );
aioseo()->actionScheduler->scheduleSingle( aioseo()->importExport->yoastSeo->userActionName, 5, [], true );
} else {
aioseo()->core->cache->delete( 'import_user_meta_yoast_seo' );
}
}
}