PluginProbe
Yoast SEO – Advanced SEO with real-time guidance and built-in AI / 18.1
Yoast SEO – Advanced SEO with real-time guidance and built-in AI v18.1
28.5 28.4 28.3 28.2 28.1 28.0 27.9 27.8 27.7 27.6 27.5 trunk 18.0 18.1 18.2 18.3 18.4 18.4.1 18.5 18.5.1 18.6 18.7 18.8 18.9 19.0 All 129 releases
wordpress-seo / admin / import / plugins / class-import-aioseo.php

class-import-aioseo.php in Yoast SEO – Advanced SEO with real-time guidance and built-in AI 18.1, at admin/import/plugins/class-import-aioseo.php

109 lines 2.4 KB
No matching file
Up and down to move Enter to open Esc to close
Raw Download Zip
1 <?php
2 /**
3 * File with the class to handle data from All in One SEO Pack, versions 3 and under.
4 *
5 * @package WPSEO\Admin\Import\Plugins
6 */
7
8 /**
9 * Class with functionality to import & clean All in One SEO Pack post metadata, versions 3 and under.
10 */
11 class WPSEO_Import_AIOSEO extends WPSEO_Plugin_Importer {
12
13 /**
14 * The plugin name.
15 *
16 * @var string
17 */
18 protected $plugin_name = 'All In One SEO Pack';
19
20 /**
21 * Meta key, used in SQL LIKE clause for delete query.
22 *
23 * @var string
24 */
25 protected $meta_key = '_aioseop_%';
26
27 /**
28 * OpenGraph keys to import.
29 *
30 * @var array
31 */
32 protected $import_keys = [
33 'aioseop_opengraph_settings_title' => 'opengraph-title',
34 'aioseop_opengraph_settings_desc' => 'opengraph-description',
35 'aioseop_opengraph_settings_customimg' => 'opengraph-image',
36 'aioseop_opengraph_settings_customimg_twitter' => 'twitter-image',
37 ];
38
39 /**
40 * Array of meta keys to detect and import.
41 *
42 * @var array
43 */
44 protected $clone_keys = [
45 [
46 'old_key' => '_aioseop_title',
47 'new_key' => 'title',
48 ],
49 [
50 'old_key' => '_aioseop_description',
51 'new_key' => 'metadesc',
52 ],
53 [
54 'old_key' => '_aioseop_noindex',
55 'new_key' => 'meta-robots-noindex',
56 'convert' => [ 'on' => 1 ],
57 ],
58 [
59 'old_key' => '_aioseop_nofollow',
60 'new_key' => 'meta-robots-nofollow',
61 'convert' => [ 'on' => 1 ],
62 ],
63 ];
64
65 /**
66 * Import All In One SEO meta values.
67 *
68 * @return bool Import success status.
69 */
70 protected function import() {
71 $status = parent::import();
72 if ( $status ) {
73 $this->import_opengraph();
74 }
75 return $status;
76 }
77
78 /**
79 * Imports the OpenGraph and Twitter settings for all posts.
80 *
81 * @return bool
82 */
83 protected function import_opengraph() {
84 $query_posts = new WP_Query( 'post_type=any&meta_key=_aioseop_opengraph_settings&order=ASC&fields=ids&nopaging=true' );
85
86 if ( ! empty( $query_posts->posts ) ) {
87 foreach ( array_values( $query_posts->posts ) as $post_id ) {
88 $this->import_post_opengraph( $post_id );
89 }
90 }
91
92 return true;
93 }
94
95 /**
96 * Imports the OpenGraph and Twitter settings for a single post.
97 *
98 * @param int $post_id Post ID.
99 */
100 private function import_post_opengraph( $post_id ) {
101 $meta = get_post_meta( $post_id, '_aioseop_opengraph_settings', true );
102 $meta = maybe_unserialize( $meta );
103
104 foreach ( $this->import_keys as $old_key => $new_key ) {
105 $this->maybe_save_post_meta( $new_key, $meta[ $old_key ], $post_id );
106 }
107 }
108 }
109