class-import-woothemes-seo.php
4.35 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
<?php
/**
* @package WPSEO\Admin\Import\External
*/
/**
* Class WPSEO_Import_WooThemes_SEO
*
* Class with functionality to import Yoast SEO settings from WooThemes SEO
*/
class WPSEO_Import_WooThemes_SEO extends WPSEO_Import_External {
/**
* Class constructor
*/
public function __construct() {
parent::__construct();
$this->import_home();
$this->import_option( 'seo_woo_single_layout', 'post' );
$this->import_option( 'seo_woo_page_layout', 'page' );
$this->import_archive_option();
$this->import_custom_values( 'seo_woo_meta_home_desc', 'metadesc-home-wpseo' );
$this->import_custom_values( 'seo_woo_meta_home_key', 'metakey-home-wpseo' );
$this->import_metas();
update_option( 'wpseo_titles', $this->options );
$this->set_msg( __( 'WooThemes SEO framework settings & data successfully imported.', 'wordpress-seo' ) );
}
/**
* Holds the WPSEO Title Options
*
* @var array
*/
private $options;
/**
* Import options.
*
* @param string $option Option key.
* @param string $post_type Post type name to import for.
*/
private function import_option( $option, $post_type ) {
switch ( get_option( $option ) ) {
case 'a':
$this->options[ 'title-' . $post_type ] = '%%title%% %%sep%% %%sitename%%';
break;
case 'b':
$this->options[ 'title-' . $post_type ] = '%%title%%';
break;
case 'c':
$this->options[ 'title-' . $post_type ] = '%%sitename%% %%sep%% %%title%%';
break;
case 'd':
$this->options[ 'title-' . $post_type ] = '%%title%% %%sep%% %%sitedesc%%';
break;
case 'e':
$this->options[ 'title-' . $post_type ] = '%%sitename%% %%sep%% %%title%% %%sep%% %%sitedesc%%';
break;
}
$this->perhaps_delete( $option );
}
/**
* Import the archive layout for all taxonomies
*/
private function import_archive_option() {
$reinstate_replace = false;
if ( $this->replace ) {
$this->replace = false;
$reinstate_replace = true;
}
$taxonomies = get_taxonomies( array( 'public' => true ), 'names' );
if ( is_array( $taxonomies ) && $taxonomies !== array() ) {
foreach ( $taxonomies as $tax ) {
$this->import_option( 'seo_woo_archive_layout', 'tax-' . $tax );
}
}
if ( $reinstate_replace ) {
$this->replace = true;
$this->perhaps_delete( 'seo_woo_archive_layout' );
}
}
/**
* Import custom descriptions and meta keys
*
* @param string $option Option key.
* @param string $key Internal key to import over.
*/
private function import_custom_values( $option, $key ) {
// Import the custom homepage description.
if ( 'c' == get_option( $option ) ) {
$this->options[ $key ] = get_option( $option . '_custom' );
}
$this->perhaps_delete( $option );
$this->perhaps_delete( $option . '_custom' );
}
/**
* Imports the WooThemes SEO homepage settings
*/
private function import_home() {
switch ( get_option( 'seo_woo_home_layout' ) ) {
case 'a':
$this->options['title-home-wpseo'] = '%%sitename%% %%sep%% %%sitedesc%%';
break;
case 'b':
$this->options['title-home-wpseo'] = '%%sitename%% ' . get_option( 'seo_woo_paged_var' ) . ' %%pagenum%%';
break;
case 'c':
$this->options['title-home-wpseo'] = '%%sitedesc%%';
break;
}
$this->perhaps_delete( 'seo_woo_home_layout' );
}
/**
* Import meta values if they're applicable
*/
private function import_metas() {
WPSEO_Meta::replace_meta( 'seo_follow', WPSEO_Meta::$meta_prefix . 'meta-robots-nofollow', $this->replace );
WPSEO_Meta::replace_meta( 'seo_noindex', WPSEO_Meta::$meta_prefix . 'meta-robots-noindex', $this->replace );
// If WooSEO is set to use the Woo titles, import those.
if ( 'true' == get_option( 'seo_woo_wp_title' ) ) {
WPSEO_Meta::replace_meta( 'seo_title', WPSEO_Meta::$meta_prefix . 'title', $this->replace );
}
// If WooSEO is set to use the Woo meta descriptions, import those.
if ( 'b' == get_option( 'seo_woo_meta_single_desc' ) ) {
WPSEO_Meta::replace_meta( 'seo_description', WPSEO_Meta::$meta_prefix . 'metadesc', $this->replace );
}
// If WooSEO is set to use the Woo meta keywords, import those.
if ( 'b' == get_option( 'seo_woo_meta_single_key' ) ) {
WPSEO_Meta::replace_meta( 'seo_keywords', WPSEO_Meta::$meta_prefix . 'metakeywords', $this->replace );
}
foreach ( array( 'seo_woo_wp_title', 'seo_woo_meta_single_desc', 'seo_woo_meta_single_key' ) as $option ) {
$this->perhaps_delete( $option );
}
}
}