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

Yoast / wordpress-seo / dd6e866a9e6d253114633104d9e3858d807178ba

19 Jun 2024 10:03AM UTC coverage: 48.628% (-4.3%) from 52.936%
dd6e866a9e6d253114633104d9e3858d807178ba

push

github

web-flow
Merge pull request #21431 from Yoast/21429-update-copy-in-the-introduction-and-consent-modals

Updates the copy for the introduction and consent modals

7441 of 13454 branches covered (55.31%)

Branch coverage included in aggregate %.

0 of 3 new or added lines in 2 files covered. (0.0%)

3718 existing lines in 107 files now uncovered.

25100 of 53464 relevant lines covered (46.95%)

62392.47 hits per line

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

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

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

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

20
        /**
21
         * Holds the name of the table Squirrly uses to store data.
22
         *
23
         * @var string
24
         */
25
        protected $table_name;
26

27
        /**
28
         * Meta key, used in SQL LIKE clause for delete query.
29
         *
30
         * @var string
31
         */
32
        protected $meta_key = '_sq_post_keyword';
33

34
        /**
35
         * Data to import from (and the target to field) the serialized array stored in the SEO field in the Squirrly table.
36
         *
37
         * @var array
38
         */
39
        protected $seo_field_keys = [
40
                'noindex'        => 'meta-robots-noindex',
41
                'nofollow'       => 'meta-robots-nofollow',
42
                'title'          => 'title',
43
                'description'    => 'metadesc',
44
                'canonical'      => 'canonical',
45
                'cornerstone'    => '_yst_is_cornerstone',
46
                'tw_media'       => 'twitter-image',
47
                'tw_title'       => 'twitter-title',
48
                'tw_description' => 'twitter-description',
49
                'og_title'       => 'opengraph-title',
50
                'og_description' => 'opengraph-description',
51
                'og_media'       => 'opengraph-image',
52
                'focuskw'        => 'focuskw',
53
        ];
54

55
        /**
56
         * WPSEO_Import_Squirrly constructor.
57
         */
UNCOV
58
        public function __construct() {
×
UNCOV
59
                parent::__construct();
×
60

UNCOV
61
                global $wpdb;
×
UNCOV
62
                $this->table_name = $wpdb->prefix . 'qss';
×
63
        }
64

65
        /**
66
         * Imports the post meta values to Yoast SEO.
67
         *
68
         * @return bool Import success status.
69
         */
UNCOV
70
        protected function import() {
×
UNCOV
71
                $results = $this->retrieve_posts();
×
UNCOV
72
                foreach ( $results as $post ) {
×
UNCOV
73
                        $return = $this->import_post_values( $post->identifier );
×
UNCOV
74
                        if ( ! $return ) {
×
UNCOV
75
                                return false;
×
76
                        }
77
                }
78

UNCOV
79
                return true;
×
80
        }
81

82
        /**
83
         * Retrieve the posts from the Squirrly Database.
84
         *
85
         * @return array Array of post IDs from the DB.
86
         */
UNCOV
87
        protected function retrieve_posts() {
×
UNCOV
88
                global $wpdb;
×
UNCOV
89
                return $wpdb->get_results(
×
UNCOV
90
                        $wpdb->prepare(
×
UNCOV
91
                                $this->retrieve_posts_query(),
×
UNCOV
92
                                get_current_blog_id()
×
UNCOV
93
                        )
×
UNCOV
94
                );
×
95
        }
96

97
        /**
98
         * Returns the query to return an identifier for the posts to import.
99
         *
100
         * @return string Query to get post ID's from the DB.
101
         */
UNCOV
102
        protected function retrieve_posts_query() {
×
UNCOV
103
                return "SELECT post_id AS identifier FROM {$this->table_name} WHERE blog_id = %d";
×
104
        }
105

106
        /**
107
         * Removes the DB table and the post meta field Squirrly creates.
108
         *
109
         * @return bool Cleanup status.
110
         */
UNCOV
111
        protected function cleanup() {
×
UNCOV
112
                global $wpdb;
×
113

114
                // If we can clean, let's clean.
UNCOV
115
                $wpdb->query( "DROP TABLE {$this->table_name}" );
×
116

117
                // This removes the post meta field for the focus keyword from the DB.
UNCOV
118
                parent::cleanup();
×
119

120
                // If we can still see the table, something went wrong.
UNCOV
121
                if ( $this->detect() ) {
×
UNCOV
122
                        $this->cleanup_error_msg();
×
UNCOV
123
                        return false;
×
124
                }
125

UNCOV
126
                return true;
×
127
        }
128

129
        /**
130
         * Detects whether there is post meta data to import.
131
         *
132
         * @return bool Boolean indicating whether there is something to import.
133
         */
UNCOV
134
        protected function detect() {
×
UNCOV
135
                global $wpdb;
×
136

UNCOV
137
                $result = $wpdb->get_var( "SHOW TABLES LIKE '{$this->table_name}'" );
×
UNCOV
138
                if ( is_wp_error( $result ) || is_null( $result ) ) {
×
UNCOV
139
                        return false;
×
140
                }
141

UNCOV
142
                return true;
×
143
        }
144

145
        /**
146
         * Imports the data of a post out of Squirrly's DB table.
147
         *
148
         * @param mixed $post_identifier Post identifier, can be ID or string.
149
         *
150
         * @return bool Import status.
151
         */
UNCOV
152
        private function import_post_values( $post_identifier ) {
×
UNCOV
153
                $data = $this->retrieve_post_data( $post_identifier );
×
UNCOV
154
                if ( ! $data ) {
×
UNCOV
155
                        return false;
×
156
                }
157

UNCOV
158
                if ( ! is_numeric( $post_identifier ) ) {
×
UNCOV
159
                        $post_id = url_to_postid( $post_identifier );
×
160
                }
161

UNCOV
162
                if ( is_numeric( $post_identifier ) ) {
×
UNCOV
163
                        $post_id         = (int) $post_identifier;
×
UNCOV
164
                        $data['focuskw'] = $this->maybe_add_focus_kw( $post_identifier );
×
165
                }
166

UNCOV
167
                foreach ( $this->seo_field_keys as $squirrly_key => $yoast_key ) {
×
UNCOV
168
                        $this->import_meta_helper( $squirrly_key, $yoast_key, $data, $post_id );
×
169
                }
UNCOV
170
                return true;
×
171
        }
172

173
        /**
174
         * Retrieves the Squirrly SEO data for a post from the DB.
175
         *
176
         * @param int $post_identifier Post ID.
177
         *
178
         * @return array|bool Array of data or false.
179
         */
UNCOV
180
        private function retrieve_post_data( $post_identifier ) {
×
UNCOV
181
                global $wpdb;
×
182

UNCOV
183
                if ( is_numeric( $post_identifier ) ) {
×
UNCOV
184
                        $post_identifier = (int) $post_identifier;
×
UNCOV
185
                        $query_where     = 'post_id = %d';
×
186
                }
UNCOV
187
                if ( ! is_numeric( $post_identifier ) ) {
×
UNCOV
188
                        $query_where = 'URL = %s';
×
189
                }
190

UNCOV
191
                $replacements = [
×
UNCOV
192
                        get_current_blog_id(),
×
UNCOV
193
                        $post_identifier,
×
UNCOV
194
                ];
×
195

UNCOV
196
                $data = $wpdb->get_var(
×
UNCOV
197
                        $wpdb->prepare(
×
UNCOV
198
                                "SELECT seo FROM {$this->table_name} WHERE blog_id = %d AND " . $query_where,
×
UNCOV
199
                                $replacements
×
UNCOV
200
                        )
×
UNCOV
201
                );
×
UNCOV
202
                if ( ! $data || is_wp_error( $data ) ) {
×
UNCOV
203
                        return false;
×
204
                }
UNCOV
205
                $data = maybe_unserialize( $data );
×
UNCOV
206
                return $data;
×
207
        }
208

209
        /**
210
         * Squirrly stores the focus keyword in post meta.
211
         *
212
         * @param int $post_id Post ID.
213
         *
214
         * @return string The focus keyword.
215
         */
UNCOV
216
        private function maybe_add_focus_kw( $post_id ) {
×
UNCOV
217
                $focuskw = get_post_meta( $post_id, '_sq_post_keyword', true );
×
UNCOV
218
                if ( $focuskw ) {
×
UNCOV
219
                        $focuskw = json_decode( $focuskw );
×
UNCOV
220
                        return $focuskw->keyword;
×
221
                }
UNCOV
222
                return '';
×
223
        }
224
}
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

© 2025 Coveralls, Inc