| @@ -6,8 +6,9 @@ | ||
| 6 | 6 | */ |
| 7 | 7 | |
| 8 | 8 | use Yoast\WP\SEO\Actions\Importing\Aioseo\Aioseo_Cleanup_Action; |
| 9 | 9 | use Yoast\WP\SEO\Actions\Importing\Aioseo\Aioseo_Posts_Importing_Action; |
| 10 | + | |
| 10 | 11 | /** |
| 11 | 12 | * Class with functionality to import & clean All in One SEO Pack post metadata, versions 4 and up. |
| 12 | 13 | */ |
| 13 | 14 | class WPSEO_Import_AIOSEO_V4 extends WPSEO_Plugin_Importer { |
| @@ -60,11 +61,11 @@ | ||
| 60 | 61 | |
| 61 | 62 | /** |
| 62 | 63 | * Mapping between the AiOSEO replace vars and the Yoast replace vars. |
| 63 | 64 | * |
| 65 | + * @see https://yoast.com/help/list-available-snippet-variables-yoast-seo/ | |
| 66 | + * | |
| 64 | 67 | * @var array |
| 65 | - * | |
| 66 | - * @see https://yoast.com/help/list-available-snippet-variables-yoast-seo/ | |
| 67 | 68 | */ |
| 68 | 69 | protected $replace_vars = [ |
| 69 | 70 | // They key is the AiOSEO replace var, the value is the Yoast replace var (see class-wpseo-replace-vars). |
| 70 | 71 | '#author_first_name' => '%%author_first_name%%', |
| @@ -105,15 +106,15 @@ | ||
| 105 | 106 | // At this point we're already looping through all the $clone_keys (this happens in meta_keys_clone() in the abstract class). |
| 106 | 107 | // Now, we'll also loop through the replace_vars array, which holds the mappings between the AiOSEO variables and the Yoast variables. |
| 107 | 108 | // We'll replace all the AiOSEO variables in the temporary table with their Yoast equivalents. |
| 108 | 109 | foreach ( $this->replace_vars as $aioseo_variable => $yoast_variable ) { |
| 109 | - // phpcs:ignore WordPress.DB.DirectDatabaseQuery.DirectQuery, WordPress.DB.DirectDatabaseQuery.NoCaching -- Reason: We need this query and this is done at many other places as well, for example class-import-rankmath. | |
| 110 | + // phpcs:ignore WordPress.DB.DirectDatabaseQuery.DirectQuery,WordPress.DB.DirectDatabaseQuery.NoCaching -- Reason: We need this query and this is done at many other places as well, for example class-import-rankmath. | |
| 110 | 111 | $wpdb->query( |
| 111 | 112 | $wpdb->prepare( |
| 112 | 113 | 'UPDATE tmp_meta_table SET meta_value = REPLACE( meta_value, %s, %s )', |
| 113 | 114 | $aioseo_variable, |
| 114 | - $yoast_variable | |
| 115 | - ) | |
| 115 | + $yoast_variable, | |
| 116 | + ), | |
| 116 | 117 | ); |
| 117 | 118 | } |
| 118 | 119 | |
| 119 | 120 | // The AiOSEO custom fields take the form of `#custom_field-myfield`. |
| @@ -144,12 +145,12 @@ | ||
| 144 | 145 | $unique_custom_fields_or_taxonomies = []; |
| 145 | 146 | |
| 146 | 147 | foreach ( $meta_values as $meta_value ) { |
| 147 | 148 | // Find all custom field replace vars, store them in `$matches`. |
| 148 | - \preg_match_all( | |
| 149 | + preg_match_all( | |
| 149 | 150 | "/#$aioseo_prefix-([\w-]+)/", |
| 150 | 151 | $meta_value, |
| 151 | - $matches | |
| 152 | + $matches, | |
| 152 | 153 | ); |
| 153 | 154 | |
| 154 | 155 | /* |
| 155 | 156 | * `$matches[1]` contain the captured matches of the |
| @@ -157,13 +158,13 @@ | ||
| 157 | 158 | */ |
| 158 | 159 | $custom_fields_or_taxonomies = $matches[1]; |
| 159 | 160 | |
| 160 | 161 | foreach ( $custom_fields_or_taxonomies as $custom_field_or_taxonomy ) { |
| 161 | - $unique_custom_fields_or_taxonomies[ \trim( $custom_field_or_taxonomy ) ] = 1; | |
| 162 | + $unique_custom_fields_or_taxonomies[ trim( $custom_field_or_taxonomy ) ] = 1; | |
| 162 | 163 | } |
| 163 | 164 | } |
| 164 | 165 | |
| 165 | - return \array_keys( $unique_custom_fields_or_taxonomies ); | |
| 166 | + return array_keys( $unique_custom_fields_or_taxonomies ); | |
| 166 | 167 | } |
| 167 | 168 | |
| 168 | 169 | /** |
| 169 | 170 | * Replaces every AIOSEO custom field/taxonomy/etc. replace var with the Yoast version. |
| @@ -174,8 +175,10 @@ | ||
| 174 | 175 | * @param wpdb $wpdb The WordPress database object. |
| 175 | 176 | * @param string $aioseo_prefix The AiOSEO prefix to use |
| 176 | 177 | * (e.g. `custom-field` for custom fields or `tax_name` for custom taxonomies). |
| 177 | 178 | * @param string $yoast_prefix The Yoast prefix to use (e.g. `cf` for custom fields). |
| 179 | + * | |
| 180 | + * @return void | |
| 178 | 181 | */ |
| 179 | 182 | protected function replace_custom_field_or_taxonomy_replace_vars( $unique_custom_fields_or_taxonomies, $wpdb, $aioseo_prefix, $yoast_prefix ) { |
| 180 | 183 | foreach ( $unique_custom_fields_or_taxonomies as $unique_custom_field_or_taxonomy ) { |
| 181 | 184 | $aioseo_variable = "#{$aioseo_prefix}-{$unique_custom_field_or_taxonomy}"; |
| @@ -180,20 +183,20 @@ | ||
| 180 | 183 | foreach ( $unique_custom_fields_or_taxonomies as $unique_custom_field_or_taxonomy ) { |
| 181 | 184 | $aioseo_variable = "#{$aioseo_prefix}-{$unique_custom_field_or_taxonomy}"; |
| 182 | 185 | $yoast_variable = "%%{$yoast_prefix}_{$unique_custom_field_or_taxonomy}%%"; |
| 183 | 186 | |
| 184 | - // phpcs:ignore WordPress.DB.DirectDatabaseQuery.DirectQuery, WordPress.DB.DirectDatabaseQuery.NoCaching | |
| 187 | + // phpcs:ignore WordPress.DB.DirectDatabaseQuery.DirectQuery,WordPress.DB.DirectDatabaseQuery.NoCaching | |
| 185 | 188 | $wpdb->query( |
| 186 | 189 | $wpdb->prepare( |
| 187 | 190 | 'UPDATE tmp_meta_table SET meta_value = REPLACE( meta_value, %s, %s )', |
| 188 | 191 | $aioseo_variable, |
| 189 | - $yoast_variable | |
| 190 | - ) | |
| 192 | + $yoast_variable, | |
| 193 | + ), | |
| 191 | 194 | ); |
| 192 | 195 | } |
| 193 | 196 | } |
| 194 | 197 | |
| 195 | - // phpcs:disable WordPress.DB.DirectDatabaseQuery.DirectQuery, WordPress.DB.DirectDatabaseQuery.NoCaching | |
| 198 | + // phpcs:disable WordPress.DB.DirectDatabaseQuery.DirectQuery,WordPress.DB.DirectDatabaseQuery.NoCaching | |
| 196 | 199 | |
| 197 | 200 | /** |
| 198 | 201 | * Retrieve all the meta values from the temporary meta table that contain |
| 199 | 202 | * at least one AiOSEO custom field replace var. |
| @@ -207,14 +210,14 @@ | ||
| 207 | 210 | protected function get_meta_values_with_custom_field_or_taxonomy( $wpdb, $aioseo_prefix ) { |
| 208 | 211 | return $wpdb->get_col( |
| 209 | 212 | $wpdb->prepare( |
| 210 | 213 | 'SELECT meta_value FROM tmp_meta_table WHERE meta_value LIKE %s', |
| 211 | - "%#$aioseo_prefix-%" | |
| 212 | - ) | |
| 214 | + "%#$aioseo_prefix-%", | |
| 215 | + ), | |
| 213 | 216 | ); |
| 214 | 217 | } |
| 215 | 218 | |
| 216 | - // phpcs:enable WordPress.DB.DirectDatabaseQuery.DirectQuery, WordPress.DB.DirectDatabaseQuery.NoCaching | |
| 219 | + // phpcs:enable WordPress.DB.DirectDatabaseQuery.DirectQuery,WordPress.DB.DirectDatabaseQuery.NoCaching | |
| 217 | 220 | |
| 218 | 221 | /** |
| 219 | 222 | * Detects whether there is AIOSEO data to import by looking whether the AIOSEO data have been cleaned up. |
| 220 | 223 | * |