Edit File by line

Deprecated: str_replace(): Passing null to parameter #2 ($replace) of type array|string is deprecated in /home/sportsfever/public_html/filemanger/function.php on line 93
/home/sportsfe.../public_h.../wp-conte.../plugins/wordpres.../admin/import/plugins
File: class-import-wpseo.php
<?php
[0] Fix | Delete
/**
[1] Fix | Delete
* File with the class to handle data from wpSEO.de.
[2] Fix | Delete
*
[3] Fix | Delete
* @package WPSEO\Admin\Import\Plugins
[4] Fix | Delete
*/
[5] Fix | Delete
[6] Fix | Delete
/**
[7] Fix | Delete
* Class WPSEO_Import_WPSEO.
[8] Fix | Delete
*
[9] Fix | Delete
* Class with functionality to import & clean wpSEO.de post metadata.
[10] Fix | Delete
*/
[11] Fix | Delete
class WPSEO_Import_WPSEO extends WPSEO_Plugin_Importer {
[12] Fix | Delete
[13] Fix | Delete
/**
[14] Fix | Delete
* The plugin name.
[15] Fix | Delete
*
[16] Fix | Delete
* @var string
[17] Fix | Delete
*/
[18] Fix | Delete
protected $plugin_name = 'wpSEO.de';
[19] Fix | Delete
[20] Fix | Delete
/**
[21] Fix | Delete
* Meta key, used in SQL LIKE clause for delete query.
[22] Fix | Delete
*
[23] Fix | Delete
* @var string
[24] Fix | Delete
*/
[25] Fix | Delete
protected $meta_key = '_wpseo_edit_%';
[26] Fix | Delete
[27] Fix | Delete
/**
[28] Fix | Delete
* Array of meta keys to detect and import.
[29] Fix | Delete
*
[30] Fix | Delete
* @var array
[31] Fix | Delete
*/
[32] Fix | Delete
protected $clone_keys = [
[33] Fix | Delete
[
[34] Fix | Delete
'old_key' => '_wpseo_edit_description',
[35] Fix | Delete
'new_key' => 'metadesc',
[36] Fix | Delete
],
[37] Fix | Delete
[
[38] Fix | Delete
'old_key' => '_wpseo_edit_title',
[39] Fix | Delete
'new_key' => 'title',
[40] Fix | Delete
],
[41] Fix | Delete
[
[42] Fix | Delete
'old_key' => '_wpseo_edit_canonical',
[43] Fix | Delete
'new_key' => 'canonical',
[44] Fix | Delete
],
[45] Fix | Delete
[
[46] Fix | Delete
'old_key' => '_wpseo_edit_og_title',
[47] Fix | Delete
'new_key' => 'opengraph-title',
[48] Fix | Delete
],
[49] Fix | Delete
[
[50] Fix | Delete
'old_key' => '_wpseo_edit_og_description',
[51] Fix | Delete
'new_key' => 'opengraph-description',
[52] Fix | Delete
],
[53] Fix | Delete
[
[54] Fix | Delete
'old_key' => '_wpseo_edit_og_image',
[55] Fix | Delete
'new_key' => 'opengraph-image',
[56] Fix | Delete
],
[57] Fix | Delete
[
[58] Fix | Delete
'old_key' => '_wpseo_edit_twittercard_title',
[59] Fix | Delete
'new_key' => 'twitter-title',
[60] Fix | Delete
],
[61] Fix | Delete
[
[62] Fix | Delete
'old_key' => '_wpseo_edit_twittercard_description',
[63] Fix | Delete
'new_key' => 'twitter-description',
[64] Fix | Delete
],
[65] Fix | Delete
[
[66] Fix | Delete
'old_key' => '_wpseo_edit_twittercard_image',
[67] Fix | Delete
'new_key' => 'twitter-image',
[68] Fix | Delete
],
[69] Fix | Delete
];
[70] Fix | Delete
[71] Fix | Delete
/**
[72] Fix | Delete
* The values 1 - 6 are the configured values from wpSEO. This array will map the values of wpSEO to our values.
[73] Fix | Delete
*
[74] Fix | Delete
* There are some double array like 1-6 and 3-4. The reason is they only set the index value. The follow value is
[75] Fix | Delete
* the default we use in the cases there isn't a follow value present.
[76] Fix | Delete
*
[77] Fix | Delete
* @var array
[78] Fix | Delete
*/
[79] Fix | Delete
private $robot_values = [
[80] Fix | Delete
// In wpSEO: index, follow.
[81] Fix | Delete
1 => [
[82] Fix | Delete
'index' => 2,
[83] Fix | Delete
'follow' => 0,
[84] Fix | Delete
],
[85] Fix | Delete
// In wpSEO: index, nofollow.
[86] Fix | Delete
2 => [
[87] Fix | Delete
'index' => 2,
[88] Fix | Delete
'follow' => 1,
[89] Fix | Delete
],
[90] Fix | Delete
// In wpSEO: noindex.
[91] Fix | Delete
3 => [
[92] Fix | Delete
'index' => 1,
[93] Fix | Delete
'follow' => 0,
[94] Fix | Delete
],
[95] Fix | Delete
// In wpSEO: noindex, follow.
[96] Fix | Delete
4 => [
[97] Fix | Delete
'index' => 1,
[98] Fix | Delete
'follow' => 0,
[99] Fix | Delete
],
[100] Fix | Delete
// In wpSEO: noindex, nofollow.
[101] Fix | Delete
5 => [
[102] Fix | Delete
'index' => 1,
[103] Fix | Delete
'follow' => 1,
[104] Fix | Delete
],
[105] Fix | Delete
// In wpSEO: index.
[106] Fix | Delete
6 => [
[107] Fix | Delete
'index' => 2,
[108] Fix | Delete
'follow' => 0,
[109] Fix | Delete
],
[110] Fix | Delete
];
[111] Fix | Delete
[112] Fix | Delete
/**
[113] Fix | Delete
* Imports wpSEO settings.
[114] Fix | Delete
*
[115] Fix | Delete
* @return bool Import success status.
[116] Fix | Delete
*/
[117] Fix | Delete
protected function import() {
[118] Fix | Delete
$status = parent::import();
[119] Fix | Delete
if ( $status ) {
[120] Fix | Delete
$this->import_post_robots();
[121] Fix | Delete
$this->import_taxonomy_metas();
[122] Fix | Delete
}
[123] Fix | Delete
[124] Fix | Delete
return $status;
[125] Fix | Delete
}
[126] Fix | Delete
[127] Fix | Delete
/**
[128] Fix | Delete
* Removes wpseo.de post meta's.
[129] Fix | Delete
*
[130] Fix | Delete
* @return bool Cleanup status.
[131] Fix | Delete
*/
[132] Fix | Delete
protected function cleanup() {
[133] Fix | Delete
$this->cleanup_term_meta();
[134] Fix | Delete
$result = $this->cleanup_post_meta();
[135] Fix | Delete
return $result;
[136] Fix | Delete
}
[137] Fix | Delete
[138] Fix | Delete
/**
[139] Fix | Delete
* Detects whether there is post meta data to import.
[140] Fix | Delete
*
[141] Fix | Delete
* @return bool Boolean indicating whether there is something to import.
[142] Fix | Delete
*/
[143] Fix | Delete
protected function detect() {
[144] Fix | Delete
if ( parent::detect() ) {
[145] Fix | Delete
return true;
[146] Fix | Delete
}
[147] Fix | Delete
[148] Fix | Delete
global $wpdb;
[149] Fix | Delete
$count = $wpdb->get_var( "SELECT COUNT(*) FROM {$wpdb->options} WHERE option_name LIKE 'wpseo_category_%'" );
[150] Fix | Delete
if ( $count !== '0' ) {
[151] Fix | Delete
return true;
[152] Fix | Delete
}
[153] Fix | Delete
[154] Fix | Delete
return false;
[155] Fix | Delete
}
[156] Fix | Delete
[157] Fix | Delete
/**
[158] Fix | Delete
* Imports the robot values from WPSEO plugin. These have to be converted to the Yoast format.
[159] Fix | Delete
*
[160] Fix | Delete
* @return void
[161] Fix | Delete
*/
[162] Fix | Delete
private function import_post_robots() {
[163] Fix | Delete
$query_posts = new WP_Query( 'post_type=any&meta_key=_wpseo_edit_robots&order=ASC&fields=ids&nopaging=true' );
[164] Fix | Delete
[165] Fix | Delete
if ( ! empty( $query_posts->posts ) ) {
[166] Fix | Delete
foreach ( array_values( $query_posts->posts ) as $post_id ) {
[167] Fix | Delete
$this->import_post_robot( $post_id );
[168] Fix | Delete
}
[169] Fix | Delete
}
[170] Fix | Delete
}
[171] Fix | Delete
[172] Fix | Delete
/**
[173] Fix | Delete
* Gets the wpSEO robot value and map this to Yoast SEO values.
[174] Fix | Delete
*
[175] Fix | Delete
* @param int $post_id The post id of the current post.
[176] Fix | Delete
*
[177] Fix | Delete
* @return void
[178] Fix | Delete
*/
[179] Fix | Delete
private function import_post_robot( $post_id ) {
[180] Fix | Delete
$wpseo_robots = get_post_meta( $post_id, '_wpseo_edit_robots', true );
[181] Fix | Delete
$robot_value = $this->get_robot_value( $wpseo_robots );
[182] Fix | Delete
[183] Fix | Delete
// Saving the new meta values for Yoast SEO.
[184] Fix | Delete
$this->maybe_save_post_meta( 'meta-robots-noindex', $robot_value['index'], $post_id );
[185] Fix | Delete
$this->maybe_save_post_meta( 'meta-robots-nofollow', $robot_value['follow'], $post_id );
[186] Fix | Delete
}
[187] Fix | Delete
[188] Fix | Delete
/**
[189] Fix | Delete
* Imports the taxonomy metas from wpSEO.
[190] Fix | Delete
*
[191] Fix | Delete
* @return void
[192] Fix | Delete
*/
[193] Fix | Delete
private function import_taxonomy_metas() {
[194] Fix | Delete
$terms = get_terms(
[195] Fix | Delete
[
[196] Fix | Delete
'taxonomy' => get_taxonomies(),
[197] Fix | Delete
'hide_empty' => false,
[198] Fix | Delete
]
[199] Fix | Delete
);
[200] Fix | Delete
$tax_meta = get_option( 'wpseo_taxonomy_meta' );
[201] Fix | Delete
[202] Fix | Delete
foreach ( $terms as $term ) {
[203] Fix | Delete
$this->import_taxonomy_description( $tax_meta, $term->taxonomy, $term->term_id );
[204] Fix | Delete
$this->import_taxonomy_robots( $tax_meta, $term->taxonomy, $term->term_id );
[205] Fix | Delete
}
[206] Fix | Delete
[207] Fix | Delete
update_option( 'wpseo_taxonomy_meta', $tax_meta );
[208] Fix | Delete
}
[209] Fix | Delete
[210] Fix | Delete
/**
[211] Fix | Delete
* Imports the meta description to Yoast SEO.
[212] Fix | Delete
*
[213] Fix | Delete
* @param array $tax_meta The array with the current metadata.
[214] Fix | Delete
* @param string $taxonomy String with the name of the taxonomy.
[215] Fix | Delete
* @param string $term_id The ID of the current term.
[216] Fix | Delete
*
[217] Fix | Delete
* @return void
[218] Fix | Delete
*/
[219] Fix | Delete
private function import_taxonomy_description( &$tax_meta, $taxonomy, $term_id ) {
[220] Fix | Delete
$description = get_option( 'wpseo_' . $taxonomy . '_' . $term_id, false );
[221] Fix | Delete
if ( $description !== false ) {
[222] Fix | Delete
// Import description.
[223] Fix | Delete
$tax_meta[ $taxonomy ][ $term_id ]['wpseo_desc'] = $description;
[224] Fix | Delete
}
[225] Fix | Delete
}
[226] Fix | Delete
[227] Fix | Delete
/**
[228] Fix | Delete
* Imports the robot value to Yoast SEO.
[229] Fix | Delete
*
[230] Fix | Delete
* @param array $tax_meta The array with the current metadata.
[231] Fix | Delete
* @param string $taxonomy String with the name of the taxonomy.
[232] Fix | Delete
* @param string $term_id The ID of the current term.
[233] Fix | Delete
*
[234] Fix | Delete
* @return void
[235] Fix | Delete
*/
[236] Fix | Delete
private function import_taxonomy_robots( &$tax_meta, $taxonomy, $term_id ) {
[237] Fix | Delete
$wpseo_robots = get_option( 'wpseo_' . $taxonomy . '_' . $term_id . '_robots', false );
[238] Fix | Delete
if ( $wpseo_robots === false ) {
[239] Fix | Delete
return;
[240] Fix | Delete
}
[241] Fix | Delete
// The value 1, 2 and 6 are the index values in wpSEO.
[242] Fix | Delete
$new_robot_value = 'noindex';
[243] Fix | Delete
[244] Fix | Delete
if ( in_array( (int) $wpseo_robots, [ 1, 2, 6 ], true ) ) {
[245] Fix | Delete
$new_robot_value = 'index';
[246] Fix | Delete
}
[247] Fix | Delete
[248] Fix | Delete
$tax_meta[ $taxonomy ][ $term_id ]['wpseo_noindex'] = $new_robot_value;
[249] Fix | Delete
}
[250] Fix | Delete
[251] Fix | Delete
/**
[252] Fix | Delete
* Deletes the wpSEO taxonomy meta data.
[253] Fix | Delete
*
[254] Fix | Delete
* @param string $taxonomy String with the name of the taxonomy.
[255] Fix | Delete
* @param string $term_id The ID of the current term.
[256] Fix | Delete
*
[257] Fix | Delete
* @return void
[258] Fix | Delete
*/
[259] Fix | Delete
private function delete_taxonomy_metas( $taxonomy, $term_id ) {
[260] Fix | Delete
delete_option( 'wpseo_' . $taxonomy . '_' . $term_id );
[261] Fix | Delete
delete_option( 'wpseo_' . $taxonomy . '_' . $term_id . '_robots' );
[262] Fix | Delete
}
[263] Fix | Delete
[264] Fix | Delete
/**
[265] Fix | Delete
* Gets the robot config by given wpSEO robots value.
[266] Fix | Delete
*
[267] Fix | Delete
* @param string $wpseo_robots The value in wpSEO that needs to be converted to the Yoast format.
[268] Fix | Delete
*
[269] Fix | Delete
* @return string The correct robot value.
[270] Fix | Delete
*/
[271] Fix | Delete
private function get_robot_value( $wpseo_robots ) {
[272] Fix | Delete
if ( array_key_exists( $wpseo_robots, $this->robot_values ) ) {
[273] Fix | Delete
return $this->robot_values[ $wpseo_robots ];
[274] Fix | Delete
}
[275] Fix | Delete
[276] Fix | Delete
return $this->robot_values[1];
[277] Fix | Delete
}
[278] Fix | Delete
[279] Fix | Delete
/**
[280] Fix | Delete
* Deletes wpSEO postmeta from the database.
[281] Fix | Delete
*
[282] Fix | Delete
* @return bool Cleanup status.
[283] Fix | Delete
*/
[284] Fix | Delete
private function cleanup_post_meta() {
[285] Fix | Delete
global $wpdb;
[286] Fix | Delete
[287] Fix | Delete
// If we get to replace the data, let's do some proper cleanup.
[288] Fix | Delete
return $wpdb->query( "DELETE FROM {$wpdb->postmeta} WHERE meta_key LIKE '_wpseo_edit_%'" );
[289] Fix | Delete
}
[290] Fix | Delete
[291] Fix | Delete
/**
[292] Fix | Delete
* Cleans up the wpSEO term meta.
[293] Fix | Delete
*
[294] Fix | Delete
* @return void
[295] Fix | Delete
*/
[296] Fix | Delete
private function cleanup_term_meta() {
[297] Fix | Delete
$terms = get_terms(
[298] Fix | Delete
[
[299] Fix | Delete
'taxonomy' => get_taxonomies(),
[300] Fix | Delete
'hide_empty' => false,
[301] Fix | Delete
]
[302] Fix | Delete
);
[303] Fix | Delete
[304] Fix | Delete
foreach ( $terms as $term ) {
[305] Fix | Delete
$this->delete_taxonomy_metas( $term->taxonomy, $term->term_id );
[306] Fix | Delete
}
[307] Fix | Delete
}
[308] Fix | Delete
}
[309] Fix | Delete
[310] Fix | Delete
It is recommended that you Edit text format, this type of Fix handles quite a lot in one request
Function