dashboard.php
15.6 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
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
<?php
/**
*
*
* @package Admin
*/
if ( !defined( 'WPSEO_VERSION' ) ) {
header( 'HTTP/1.0 403 Forbidden' );
die;
}
global $wpseo_admin_pages;
$options = get_option( 'wpseo' );
if ( isset( $_GET['allow_tracking'] ) && check_admin_referer( 'wpseo_activate_tracking', 'nonce' ) ) {
$options['tracking_popup'] = 'done';
if ( $_GET['allow_tracking'] == 'yes' )
$options['yoast_tracking'] = 'on';
else
$options['yoast_tracking'] = 'off';
update_option( 'wpseo', $options );
if ( isset( $_SERVER['HTTP_REFERER'] ) ) {
wp_safe_redirect( $_SERVER['HTTP_REFERER'], 307 );
exit;
}
}
$wpseo_admin_pages->admin_header( true, 'yoast_wpseo_options', 'wpseo' );
// detect and handle robots meta here
robots_meta_handler();
// detect and handle aioseo here
aioseo_handler();
do_action( 'wpseo_all_admin_notices' );
echo $wpseo_admin_pages->hidden( 'ignore_blog_public_warning' );
echo $wpseo_admin_pages->hidden( 'ignore_meta_description_warning' );
echo $wpseo_admin_pages->hidden( 'ignore_tour' );
echo $wpseo_admin_pages->hidden( 'ignore_page_comments' );
echo $wpseo_admin_pages->hidden( 'ignore_permalink' );
echo $wpseo_admin_pages->hidden( 'ms_defaults_set' );
echo $wpseo_admin_pages->hidden( 'version' );
echo $wpseo_admin_pages->hidden( 'tracking_popup' );
// Fix metadescription if so requested
if ( isset( $_GET['fixmetadesc'] ) && check_admin_referer( 'wpseo-fix-metadesc', 'nonce' ) && isset( $options['theme_check'] ) && isset( $options['theme_check']['description_found'] ) && $options['theme_check']['description_found'] ) {
$path = false;
if ( file_exists( get_stylesheet_directory() . '/header.php' ) ) {
// theme or child theme
$path = get_stylesheet_directory();
}
else if ( file_exists( get_template_directory() . '/header.php' ) ) {
// parent theme in case of a child theme
$path = get_template_directory();
}
if ( is_string( $path ) && $path !== '' ) {
$fcontent = file_get_contents( $path . '/header.php' );
$msg = '';
$backup_file = date( 'Ymd-H.i.s-' ) . 'header.php.wpseobak';
if ( !file_exists( $path . '/' . $backup_file ) ) {
$backupfile = fopen( $path . '/' . $backup_file, 'w+' );
if ( $backupfile ) {
fwrite( $backupfile, $fcontent );
fclose( $backupfile );
$msg = __( 'Backed up the original file header.php to <strong><em>' . $backup_file . '</em></strong>, ', 'wordpress-seo' );
$count = 0;
$fcontent = str_replace( $options['theme_check']['description_found'], '', $fcontent, $count );
if ( $count > 0 ) {
$header_file = fopen( $path . '/header.php', 'w+' );
if ( $header_file ) {
fwrite( $header_file, $fcontent );
fclose( $header_file );
$msg .= __( 'Removed hardcoded meta description.', 'wordpress-seo' );
}
}
unset( $options['theme_check']['description_found'] );
update_option( 'wpseo', $options );
echo '<div class="updated"><p>' . $msg . '</p></div>';
}
}
}
}
if ( isset( $options['blocking_files'] ) && is_array( $options['blocking_files'] ) && count( $options['blocking_files'] ) > 0 ) {
$options['blocking_files'] = array_unique( $options['blocking_files'] );
echo '<p id="blocking_files" class="wrong">'
. '<a href="javascript:wpseo_killBlockingFiles(\'' . wp_create_nonce( 'wpseo-blocking-files' ) . '\')" class="button fixit">' . __( 'Fix it.', 'wordpress-seo' ) . '</a>'
. __( 'The following file(s) is/are blocking your XML sitemaps from working properly:', 'wordpress-seo' ) . '<br />';
foreach ( $options['blocking_files'] as $file ) {
echo esc_html( $file ) . '<br/>';
}
echo __( 'Either delete them (this can be done with the "Fix it" button) or disable WP SEO XML sitemaps.', 'wordpress-seo' );
echo '</p>';
}
if ( ( ( !isset( $options['theme_check']['description'] ) && !isset( $options['theme_check']['description_found'] ) ) || ( ( isset( $options['theme_check'] ) && isset( $options['theme_check']['description'] ) ) && $options['theme_check']['description'] !== true ) ) || ( ( isset( $_GET['checkmetadesc'] ) && check_admin_referer( 'wpseo-check-metadesc', 'nonce' ) ) && ( ( isset( $options['theme_check'] ) && isset( $options['theme_check']['description_found'] ) ) && $options['theme_check']['description_found'] ) ) ) {
wpseo_description_test();
// Renew the options after the test
$options = get_option( 'wpseo' );
}
if ( isset( $options['theme_check'] ) && isset( $options['theme_check']['description_found'] ) && $options['theme_check']['description_found'] ) {
echo '<p id="metadesc_found notice" class="wrong settings_error">'
. '<a href="' . admin_url( 'admin.php?page=wpseo_dashboard&fixmetadesc&nonce=' . wp_create_nonce( 'wpseo-fix-metadesc' ) ) . '" class="button fixit">' . __( 'Fix it.', 'wordpress-seo' ) . '</a>'
. ' <a href="' . admin_url( 'admin.php?page=wpseo_dashboard&checkmetadesc&nonce=' . wp_create_nonce( 'wpseo-check-metadesc' ) ) . '" class="button checkit">' . __( 'Re-check theme.', 'wordpress-seo' ) . '</a>'
. __( 'Your theme contains a meta description, which blocks WordPress SEO from working properly, please delete the following line, or press fix it:', 'wordpress-seo' ) . '<br />';
echo '<code>' . htmlentities( $options['theme_check']['description_found'] ) . '</code>';
echo '</p>';
}
if ( strpos( get_option( 'permalink_structure' ), '%postname%' ) === false && !isset( $options['ignore_permalink'] ) )
echo '<p id="wrong_permalink" class="wrong">'
. '<a href="' . admin_url( 'options-permalink.php' ) . '" class="button fixit">' . __( 'Fix it.', 'wordpress-seo' ) . '</a>'
. '<a href="javascript:wpseo_setIgnore(\'permalink\',\'wrong_permalink\',\'' . wp_create_nonce( 'wpseo-ignore' ) . '\');" class="button fixit">' . __( 'Ignore.', 'wordpress-seo' ) . '</a>'
. __( 'You do not have your postname in the URL of your posts and pages, it is highly recommended that you do. Consider setting your permalink structure to <strong>/%postname%/</strong>.', 'wordpress-seo' ) . '</p>';
if ( get_option( 'page_comments' ) && !isset( $options['ignore_page_comments'] ) )
echo '<p id="wrong_page_comments" class="wrong">'
. '<a href="javascript:setWPOption(\'page_comments\',\'0\',\'wrong_page_comments\',\'' . wp_create_nonce( 'wpseo-setoption' ) . '\');" class="button fixit">' . __( 'Fix it.', 'wordpress-seo' ) . '</a>'
. '<a href="javascript:wpseo_setIgnore(\'page_comments\',\'wrong_page_comments\',\'' . wp_create_nonce( 'wpseo-ignore' ) . '\');" class="button fixit">' . __( 'Ignore.', 'wordpress-seo' ) . '</a>'
. __( 'Paging comments is enabled, this is not needed in 999 out of 1000 cases, so the suggestion is to disable it, to do that, simply uncheck the box before "Break comments into pages..."', 'wordpress-seo' ) . '</p>';
echo '<h2>' . __( 'General', 'wordpress-seo' ) . '</h2>';
if ( isset( $options['ignore_tour'] ) && $options['ignore_tour'] ) {
echo '<label class="select">' . __( 'Introduction Tour:', 'wordpress-seo' ) . '</label><a class="button-secondary" href="' . admin_url( 'admin.php?page=wpseo_dashboard&wpseo_restart_tour' ) . '">' . __( 'Start Tour', 'wordpress-seo' ) . '</a>';
echo '<p class="desc label">' . __( 'Take this tour to quickly learn about the use of this plugin.', 'wordpress-seo' ) . '</p>';
}
echo '<label class="select">' . __( 'Default Settings:', 'wordpress-seo' ) . '</label><a class="button-secondary" href="' . admin_url( 'admin.php?page=wpseo_dashboard&wpseo_reset_defaults&nonce='. wp_create_nonce( 'wpseo_reset_defaults' ) ) . '">' . __( 'Reset Default Settings', 'wordpress-seo' ) . '</a>';
echo '<p class="desc label">' . __( 'If you want to restore a site to the default WordPress SEO settings, press this button.', 'wordpress-seo' ) . '</p>';
echo '<h2>' . __( 'Tracking', 'wordpress-seo' ) . '</h2>';
echo $wpseo_admin_pages->checkbox( 'yoast_tracking', __( 'Allow tracking of this WordPress installs anonymous data.', 'wordpress-seo' ) );
echo '<p class="desc">' . __( "To maintain a plugin as big as WordPress SEO, we need to know what we're dealing: what kinds of other plugins our users are using, what themes, etc. Please allow us to track that data from your install. It will not track <em>any</em> user details, so your security and privacy are safe with us.", 'wordpress-seo' ) . '</p>';
echo '<h2>' . __( 'Security', 'wordpress-seo' ) . '</h2>';
echo $wpseo_admin_pages->checkbox( 'disableadvanced_meta', __( 'Disable the Advanced part of the WordPress SEO meta box', 'wordpress-seo' ) );
echo '<p class="desc">' . __( 'Unchecking this box allows authors and editors to redirect posts, noindex them and do other things you might not want if you don\'t trust your authors.', 'wordpress-seo' ) . '</p>';
echo '<h2>' . __( 'Webmaster Tools', 'wordpress-seo' ) . '</h2>';
echo '<p>' . __( 'You can use the boxes below to verify with the different Webmaster Tools, if your site is already verified, you can just forget about these. Enter the verify meta values for:', 'wordpress-seo' ) . '</p>';
echo $wpseo_admin_pages->textinput( 'googleverify', '<a target="_blank" href="https://www.google.com/webmasters/tools/dashboard?hl=en&siteUrl=' . urlencode( get_bloginfo( 'url' ) ) . '%2F">' . __( 'Google Webmaster Tools', 'wordpress-seo' ) . '</a>' );
echo $wpseo_admin_pages->textinput( 'msverify', '<a target="_blank" href="http://www.bing.com/webmaster/?rfp=1#/Dashboard/?url=' . str_replace( 'http://', '', get_bloginfo( 'url' ) ) . '">' . __( 'Bing Webmaster Tools', 'wordpress-seo' ) . '</a>' );
echo $wpseo_admin_pages->textinput( 'alexaverify', '<a target="_blank" href="http://www.alexa.com/pro/subscription">' . __( 'Alexa Verification ID', 'wordpress-seo' ) . '</a>' );
do_action( 'wpseo_dashboard' );
$wpseo_admin_pages->admin_footer();
/**
* Handle deactivation & import of Robots Meta data
*
* @ since 1.4.8
*/
function robots_meta_handler() {
global $wpdb;
// check if robots meta is running
if ( is_plugin_active( 'robots-meta/robots-meta.php' ) ) {
// deactivate robots meta
if ( isset( $_GET['deactivate_robots_meta'] ) && $_GET['deactivate_robots_meta'] == 1 ) {
deactivate_plugins( 'robots-meta/robots-meta.php' );
// show notice that robots meta has been deactivated
add_action( 'wpseo_all_admin_notices', 'wpseo_deactivate_robots_meta_notice' );
// import the settings
} else if ( isset( $_GET['import_robots_meta'] ) && $_GET['import_robots_meta'] == 1 ) {
// import robots meta setting for each post
$posts = $wpdb->get_results( "SELECT ID, robotsmeta FROM $wpdb->posts" );
foreach ( $posts as $post ) {
// sync all possible settings
if ( $post->robotsmeta ) {
$pieces = explode( ',', $post->robotsmeta );
foreach ( $pieces as $meta ) {
switch ( $meta ) {
case 'noindex':
wpseo_set_value( 'meta-robots-noindex', true, $post->ID );
break;
case 'index':
wpseo_set_value( 'meta-robots-noindex', 2, $post->ID );
break;
case 'nofollow':
wpseo_set_value( 'meta-robots-nofollow', true, $post->ID );
break;
case 'follow':
// No need to store it
break;
default:
// do nothing
}
}
}
}
// show notice to deactivate robots meta plugin
add_action( 'wpseo_all_admin_notices', 'wpseo_deactivate_link_robots_meta_notice' );
// show notice to import robots meta settings
} else {
add_action( 'wpseo_all_admin_notices', 'wpseo_import_robots_meta_notice' );
}
}
}
/**
* Handle deactivation & import of AIOSEO data
*
* @ since 1.4.8
*/
function aioseo_handler() {
// check if aioseo is running
if ( is_plugin_active( 'all-in-one-seo-pack/all_in_one_seo_pack.php' ) ) {
// deactivate aioseo plugin
if ( isset( $_GET['deactivate_aioseo'] ) && $_GET['deactivate_aioseo'] == 1 ) {
deactivate_plugins( 'all-in-one-seo-pack/all_in_one_seo_pack.php' );
// show notice that aioseo has been deactivated
add_action( 'wpseo_all_admin_notices', 'wpseo_deactivate_aioseo_notice' );
// import the settings
// TODO: currently not deleting aioseop postmeta or handling old aioseop format
} else if ( isset( $_GET['import_aioseo'] ) && $_GET['import_aioseo'] == 1 ) {
$replace = false;
replace_meta( '_aioseop_description', '_yoast_wpseo_metadesc', $replace );
replace_meta( '_aioseop_keywords', '_yoast_wpseo_metakeywords', $replace );
replace_meta( '_aioseop_title', '_yoast_wpseo_title', $replace );
if ( isset( $_POST['wpseo']['importaioseoold'] ) ) {
replace_meta( 'description', '_yoast_wpseo_metadesc', $replace );
replace_meta( 'keywords', '_yoast_wpseo_metakeywords', $replace );
replace_meta( 'title', '_yoast_wpseo_title', $replace );
}
// show notice to deactivate aioseo plugin
add_action( 'wpseo_all_admin_notices', 'wpseo_deactivate_link_aioseo_notice' );
// show notice to import aioseo settings
} else {
add_action( 'wpseo_all_admin_notices', 'wpseo_import_aioseo_setting_notice' );
}
}
}
/**
* Throw a notice to import Robots Meta.
*
* @since 1.4.8
*/
function wpseo_import_robots_meta_notice() {
echo '<div class="updated"><p>' . sprintf( __( 'The plugin Robots-Meta has been detected. Do you want to %simport its settings%s.' ), '<a href="' . admin_url( 'admin.php?page=wpseo_dashboard&import_robots_meta=1' ) . '">', '</a>' ) . '</p></div>';
}
/**
* Throw a notice to allow the user to deactivate Robots Meta
*
* @since 1.4.8
*/
function wpseo_deactivate_link_robots_meta_notice() {
echo '<div class="updated"><p>' . sprintf( __( 'Robots-Meta settings has been imported. We recommend %sdisabling the Robots-Meta plugin%s to avoid any conflicts' ), '<a href="' . admin_url( 'admin.php?page=wpseo_dashboard&deactivate_robots_meta=1' ) . '">', '</a>' ) . '</p></div>';
}
/**
* Throw a notice to inform the user Robots Meta has been deactivated
*
* @since 1.4.8
*/
function wpseo_deactivate_robots_meta_notice() {
echo '<div class="updated"><p>' . __( 'Robots-Meta has been deactivated' ) . '</p></div>';
}
/**
* Throw a notice to import AIOSEO.
*
* @since 1.4.8
*/
function wpseo_import_aioseo_setting_notice() {
echo '<div class="updated"><p>' . sprintf( __( 'The plugin All-In-One-SEO has been detected. Do you want to %simport its settings%s.' ), '<a href="' . admin_url( 'admin.php?page=wpseo_dashboard&import_aioseo=1' ) . '">', '</a>' ) . '</p></div>';
}
/**
* Throw a notice to allow the user to deactivate AIOSEO
*
* @since 1.4.8
*/
function wpseo_deactivate_link_aioseo_notice( $active ) {
echo '<div class="updated"><p>' . sprintf( __( 'All in One SEO data successfully imported. Would you like to %sdisable the All in One SEO plugin%s.' ), '<a href="' . admin_url( 'admin.php?page=wpseo_dashboard&deactivate_aioseo=1' ) . '">', '</a>' ) . '</p></div>';
}
/**
* Throw a notice to inform the user AIOSEO has been deactivated
*
* @since 1.4.8
*/
function wpseo_deactivate_aioseo_notice() {
echo '<div class="updated"><p>' . __( 'All-In-One-SEO has been deactivated' ) . '</p></div>';
}
// TODO: consider moving this to a utility class. Currently being used in import.php also.
/**
* Used for imports, this functions either copies $old_metakey into $new_metakey or just plain replaces $old_metakey with $new_metakey
*
* @param string $old_metakey The old name of the meta value.
* @param string $new_metakey The new name of the meta value, usually the WP SEO name.
* @param bool $replace Whether to replace or to copy the values.
*/
function replace_meta( $old_metakey, $new_metakey, $replace = false ) {
global $wpdb;
$oldies = $wpdb->get_results( $wpdb->prepare( "SELECT * FROM $wpdb->postmeta WHERE meta_key = %s", $old_metakey ) );
foreach ( $oldies as $old ) {
// Prevent inserting new meta values for posts that already have a value for that new meta key
$check = get_post_meta( $old->post_id, $new_metakey, true );
if ( !$check || empty( $check ) )
update_post_meta( $old->post_id, $new_metakey, $old->meta_value );
if ( $replace )
delete_post_meta( $old->post_id, $old_metakey );
}
}