• 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-rankmath.php
1
<?php
2
/**
3
 * File with the class to handle data from RankMath.
4
 *
5
 * @package WPSEO\Admin\Import\Plugins
6
 */
7

8
/**
9
 * Class with functionality to import RankMath post metadata.
10
 */
11
class WPSEO_Import_RankMath extends WPSEO_Plugin_Importer {
12

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

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

27
        /**
28
         * Array of meta keys to detect and import.
29
         *
30
         * @var array
31
         */
32
        protected $clone_keys = [
33
                [
34
                        'old_key' => 'rank_math_description',
35
                        'new_key' => 'metadesc',
36
                ],
37
                [
38
                        'old_key' => 'rank_math_title',
39
                        'new_key' => 'title',
40
                ],
41
                [
42
                        'old_key' => 'rank_math_canonical_url',
43
                        'new_key' => 'canonical',
44
                ],
45
                [
46
                        'old_key' => 'rank_math_primary_category',
47
                        'new_key' => 'primary_category',
48
                ],
49
                [
50
                        'old_key' => 'rank_math_facebook_title',
51
                        'new_key' => 'opengraph-title',
52
                ],
53
                [
54
                        'old_key' => 'rank_math_facebook_description',
55
                        'new_key' => 'opengraph-description',
56
                ],
57
                [
58
                        'old_key' => 'rank_math_facebook_image',
59
                        'new_key' => 'opengraph-image',
60
                ],
61
                [
62
                        'old_key' => 'rank_math_facebook_image_id',
63
                        'new_key' => 'opengraph-image-id',
64
                ],
65
                [
66
                        'old_key' => 'rank_math_twitter_title',
67
                        'new_key' => 'twitter-title',
68
                ],
69
                [
70
                        'old_key' => 'rank_math_twitter_description',
71
                        'new_key' => 'twitter-description',
72
                ],
73
                [
74
                        'old_key' => 'rank_math_twitter_image',
75
                        'new_key' => 'twitter-image',
76
                ],
77
                [
78
                        'old_key' => 'rank_math_twitter_image_id',
79
                        'new_key' => 'twitter-image-id',
80
                ],
81
                [
82
                        'old_key' => 'rank_math_focus_keyword',
83
                        'new_key' => 'focuskw',
84
                ],
85
        ];
86

87
        /**
88
         * Handles post meta data to import.
89
         *
90
         * @return bool Import success status.
91
         */
UNCOV
92
        protected function import() {
×
UNCOV
93
                global $wpdb;
×
94
                // Replace % with %% as their variables are the same except for that.
UNCOV
95
                $wpdb->query( "UPDATE $wpdb->postmeta SET meta_value = REPLACE( meta_value, '%', '%%' ) WHERE meta_key IN ( 'rank_math_description', 'rank_math_title' )" );
×
96

UNCOV
97
                $this->import_meta_robots();
×
UNCOV
98
                $return = $this->meta_keys_clone( $this->clone_keys );
×
99

100
                // Return %% to % so our import is non-destructive.
UNCOV
101
                $wpdb->query( "UPDATE $wpdb->postmeta SET meta_value = REPLACE( meta_value, '%%', '%' ) WHERE meta_key IN ( 'rank_math_description', 'rank_math_title' )" );
×
102

UNCOV
103
                if ( $return ) {
×
UNCOV
104
                        $this->import_settings();
×
105
                }
106

UNCOV
107
                return $return;
×
108
        }
109

110
        /**
111
         * RankMath stores robots meta quite differently, so we have to parse it out.
112
         *
113
         * @return void
114
         */
115
        private function import_meta_robots() {
×
116
                global $wpdb;
×
117
                $post_metas = $wpdb->get_results( "SELECT post_id, meta_value FROM $wpdb->postmeta WHERE meta_key = 'rank_math_robots'" );
×
118
                foreach ( $post_metas as $post_meta ) {
×
119
                        // phpcs:ignore WordPress.PHP.DiscouragedPHPFunctions -- Reason: We can't control the form in which Rankmath sends the data.
120
                        $robots_values = unserialize( $post_meta->meta_value );
×
121
                        foreach ( [ 'noindex', 'nofollow' ] as $directive ) {
×
122
                                $directive_key = array_search( $directive, $robots_values, true );
×
123
                                if ( $directive_key !== false ) {
×
124
                                        update_post_meta( $post_meta->post_id, '_yoast_wpseo_meta-robots-' . $directive, 1 );
×
125
                                        unset( $robots_values[ $directive_key ] );
×
126
                                }
127
                        }
128
                        if ( count( $robots_values ) > 0 ) {
×
129
                                $value = implode( ',', $robots_values );
×
130
                                update_post_meta( $post_meta->post_id, '_yoast_wpseo_meta-robots-adv', $value );
×
131
                        }
132
                }
133
        }
134

135
        /**
136
         * Imports some of the RankMath settings.
137
         *
138
         * @return void
139
         */
UNCOV
140
        private function import_settings() {
×
UNCOV
141
                $settings = [
×
UNCOV
142
                        'title_separator'      => 'separator',
×
UNCOV
143
                        'homepage_title'       => 'title-home-wpseo',
×
UNCOV
144
                        'homepage_description' => 'metadesc-home-wpseo',
×
UNCOV
145
                        'author_archive_title' => 'title-author-wpseo',
×
UNCOV
146
                        'date_archive_title'   => 'title-archive-wpseo',
×
UNCOV
147
                        'search_title'         => 'title-search-wpseo',
×
UNCOV
148
                        '404_title'            => 'title-404-wpseo',
×
UNCOV
149
                        'pt_post_title'        => 'title-post',
×
UNCOV
150
                        'pt_page_title'        => 'title-page',
×
UNCOV
151
                ];
×
UNCOV
152
                $options  = get_option( 'rank-math-options-titles' );
×
153

UNCOV
154
                foreach ( $settings as $import_setting_key => $setting_key ) {
×
UNCOV
155
                        if ( ! empty( $options[ $import_setting_key ] ) ) {
×
UNCOV
156
                                $value = $options[ $import_setting_key ];
×
157
                                // Make sure replace vars work.
UNCOV
158
                                $value = str_replace( '%', '%%', $value );
×
UNCOV
159
                                WPSEO_Options::set( $setting_key, $value );
×
160
                        }
161
                }
162
        }
163

164
        /**
165
         * Removes the plugin data from the database.
166
         *
167
         * @return bool Cleanup status.
168
         */
UNCOV
169
        protected function cleanup() {
×
UNCOV
170
                $return = parent::cleanup();
×
UNCOV
171
                if ( $return ) {
×
UNCOV
172
                        global $wpdb;
×
UNCOV
173
                        $wpdb->query( "DELETE FROM $wpdb->options WHERE option_name LIKE 'rank-math-%'" );
×
UNCOV
174
                        $wpdb->query( "DELETE FROM $wpdb->options WHERE option_name LIKE '%rank_math%'" );
×
175
                }
176

UNCOV
177
                return $return;
×
178
        }
179
}
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