• Home
  • Features
  • Pricing
  • Docs
  • Announcements
  • Sign In

Yoast / wordpress-seo / b05d07fc5b184095141e8ead75857d0154e04580

23 Jul 2024 07:52AM UTC coverage: 48.579% (-5.4%) from 53.976%
b05d07fc5b184095141e8ead75857d0154e04580

push

github

YoastBot
Bump version to 23.1

7399 of 13400 branches covered (55.22%)

Branch coverage included in aggregate %.

25129 of 53559 relevant lines covered (46.92%)

41942.49 hits per line

Source File
Press 'n' to go to next uncovered line, 'b' for previous

0.0
/admin/import/plugins/class-import-smartcrawl.php
1
<?php
2
/**
3
 * File with the class to handle data from Smartcrawl SEO.
4
 *
5
 * @package WPSEO\Admin\Import\Plugins
6
 */
7

8
/**
9
 * Class with functionality to import & clean Smartcrawl SEO post metadata.
10
 */
11
class WPSEO_Import_Smartcrawl_SEO extends WPSEO_Plugin_Importer {
12

13
        /**
14
         * The plugin name.
15
         *
16
         * @var string
17
         */
18
        protected $plugin_name = 'Smartcrawl SEO';
19

20
        /**
21
         * Meta key, used in SQL LIKE clause for delete query.
22
         *
23
         * @var string
24
         */
25
        protected $meta_key = '_wds_%';
26

27
        /**
28
         * Array of meta keys to detect and import.
29
         *
30
         * @var array
31
         */
32
        protected $clone_keys = [
33
                [
34
                        'old_key' => '_wds_metadesc',
35
                        'new_key' => 'metadesc',
36
                ],
37
                [
38
                        'old_key' => '_wds_title',
39
                        'new_key' => 'title',
40
                ],
41
                [
42
                        'old_key' => '_wds_canonical',
43
                        'new_key' => 'canonical',
44
                ],
45
                [
46
                        'old_key' => '_wds_focus-keywords',
47
                        'new_key' => 'focuskw',
48
                ],
49
                [
50
                        'old_key' => '_wds_meta-robots-noindex',
51
                        'new_key' => 'meta-robots-noindex',
52
                ],
53
                [
54
                        'old_key' => '_wds_meta-robots-nofollow',
55
                        'new_key' => 'meta-robots-nofollow',
56
                ],
57
        ];
58

59
        /**
60
         * Used for importing Twitter and Facebook meta's.
61
         *
62
         * @var array
63
         */
64
        protected $social_keys = [];
65

66
        /**
67
         * Handles post meta data to import.
68
         *
69
         * @return bool Import success status.
70
         */
71
        protected function import() {
×
72
                $return = parent::import();
×
73
                if ( $return ) {
×
74
                        $this->import_opengraph();
×
75
                        $this->import_twitter();
×
76
                }
77

78
                return $return;
×
79
        }
80

81
        /**
82
         * Imports the OpenGraph meta keys saved by Smartcrawl.
83
         *
84
         * @return bool Import status.
85
         */
86
        protected function import_opengraph() {
×
87
                $this->social_keys = [
×
88
                        'title'       => 'opengraph-title',
×
89
                        'description' => 'opengraph-description',
×
90
                        'images'      => 'opengraph-image',
×
91
                ];
×
92
                return $this->post_find_import( '_wds_opengraph' );
×
93
        }
94

95
        /**
96
         * Imports the Twitter meta keys saved by Smartcrawl.
97
         *
98
         * @return bool Import status.
99
         */
100
        protected function import_twitter() {
×
101
                $this->social_keys = [
×
102
                        'title'       => 'twitter-title',
×
103
                        'description' => 'twitter-description',
×
104
                ];
×
105
                return $this->post_find_import( '_wds_twitter' );
×
106
        }
107

108
        /**
109
         * Imports a post's serialized post meta values.
110
         *
111
         * @param int    $post_id Post ID.
112
         * @param string $key     The meta key to import.
113
         *
114
         * @return void
115
         */
116
        protected function import_serialized_post_meta( $post_id, $key ) {
×
117
                $data = get_post_meta( $post_id, $key, true );
×
118
                $data = maybe_unserialize( $data );
×
119
                foreach ( $this->social_keys as $key => $meta_key ) {
×
120
                        if ( ! isset( $data[ $key ] ) ) {
×
121
                                return;
×
122
                        }
123
                        $value = $data[ $key ];
×
124
                        if ( is_array( $value ) ) {
×
125
                                $value = $value[0];
×
126
                        }
127
                        $this->maybe_save_post_meta( $meta_key, $value, $post_id );
×
128
                }
129
        }
130

131
        /**
132
         * Finds all the posts with a certain meta key and imports its values.
133
         *
134
         * @param string $key The meta key to search for.
135
         *
136
         * @return bool Import status.
137
         */
138
        protected function post_find_import( $key ) {
×
139
                $query_posts = new WP_Query( 'post_type=any&meta_key=' . $key . '&order=ASC&fields=ids&nopaging=true' );
×
140

141
                if ( empty( $query_posts->posts ) ) {
×
142
                        return false;
×
143
                }
144

145
                foreach ( array_values( $query_posts->posts ) as $post_id ) {
×
146
                        $this->import_serialized_post_meta( $post_id, $key );
×
147
                }
148

149
                return true;
×
150
        }
151
}
STATUS · Troubleshooting · Open an Issue · Sales · Support · CAREERS · ENTERPRISE · START FREE · SCHEDULE DEMO
ANNOUNCEMENTS · TWITTER · TOS & SLA · Supported CI Services · What's a CI service? · Automated Testing

© 2026 Coveralls, Inc