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

8
/**
9
 * Class WPSEO_Import_SEOPressor.
10
 *
11
 * Class with functionality to import & clean SEOPressor post metadata.
12
 */
13
class WPSEO_Import_SEOPressor extends WPSEO_Plugin_Importer {
14

15
        /**
16
         * The plugin name.
17
         *
18
         * @var string
19
         */
20
        protected $plugin_name = 'SEOpressor';
21

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

29
        /**
30
         * Array of meta keys to detect and import.
31
         *
32
         * @var array
33
         */
34
        protected $clone_keys = [
35
                [
36
                        'old_key' => '_seop_settings',
37
                ],
38
        ];
39

40
        /**
41
         * Imports the post meta values to Yoast SEO.
42
         *
43
         * @return bool Import success status.
44
         */
UNCOV
45
        protected function import() {
×
46
                // Query for all the posts that have an _seop_settings meta set.
UNCOV
47
                $query_posts = new WP_Query( 'post_type=any&meta_key=_seop_settings&order=ASC&fields=ids&nopaging=true' );
×
UNCOV
48
                foreach ( $query_posts->posts as $post_id ) {
×
UNCOV
49
                        $this->import_post_focus_keywords( $post_id );
×
UNCOV
50
                        $this->import_seopressor_post_settings( $post_id );
×
51
                }
52

UNCOV
53
                return true;
×
54
        }
55

56
        /**
57
         * Removes all the post meta fields SEOpressor creates.
58
         *
59
         * @return bool Cleanup status.
60
         */
UNCOV
61
        protected function cleanup() {
×
UNCOV
62
                global $wpdb;
×
63

64
                // If we get to replace the data, let's do some proper cleanup.
UNCOV
65
                return $wpdb->query( "DELETE FROM {$wpdb->postmeta} WHERE meta_key LIKE '_seop_%'" );
×
66
        }
67

68
        /**
69
         * Imports the data. SEOpressor stores most of the data in one post array, this loops over it.
70
         *
71
         * @param int $post_id Post ID.
72
         *
73
         * @return void
74
         */
UNCOV
75
        private function import_seopressor_post_settings( $post_id ) {
×
UNCOV
76
                $settings = get_post_meta( $post_id, '_seop_settings', true );
×
77

78
                foreach (
UNCOV
79
                        [
×
UNCOV
80
                                'fb_description'   => 'opengraph-description',
×
UNCOV
81
                                'fb_title'         => 'opengraph-title',
×
UNCOV
82
                                'fb_type'          => 'og_type',
×
UNCOV
83
                                'fb_img'           => 'opengraph-image',
×
UNCOV
84
                                'meta_title'       => 'title',
×
UNCOV
85
                                'meta_description' => 'metadesc',
×
UNCOV
86
                                'meta_canonical'   => 'canonical',
×
UNCOV
87
                                'tw_description'   => 'twitter-description',
×
UNCOV
88
                                'tw_title'         => 'twitter-title',
×
UNCOV
89
                                'tw_image'         => 'twitter-image',
×
UNCOV
90
                        ] as $seopressor_key => $yoast_key ) {
×
UNCOV
91
                        $this->import_meta_helper( $seopressor_key, $yoast_key, $settings, $post_id );
×
92
                }
93

UNCOV
94
                if ( isset( $settings['meta_rules'] ) ) {
×
UNCOV
95
                        $this->import_post_robots( $settings['meta_rules'], $post_id );
×
96
                }
97
        }
98

99
        /**
100
         * Imports the focus keywords, and stores them for later use.
101
         *
102
         * @param int $post_id Post ID.
103
         *
104
         * @return void
105
         */
UNCOV
106
        private function import_post_focus_keywords( $post_id ) {
×
107
                // Import the focus keyword.
UNCOV
108
                $focuskw = trim( get_post_meta( $post_id, '_seop_kw_1', true ) );
×
UNCOV
109
                $this->maybe_save_post_meta( 'focuskw', $focuskw, $post_id );
×
110

111
                // Import additional focus keywords for use in premium.
UNCOV
112
                $focuskw2 = trim( get_post_meta( $post_id, '_seop_kw_2', true ) );
×
UNCOV
113
                $focuskw3 = trim( get_post_meta( $post_id, '_seop_kw_3', true ) );
×
114

UNCOV
115
                $focus_keywords = [];
×
UNCOV
116
                if ( ! empty( $focuskw2 ) ) {
×
UNCOV
117
                        $focus_keywords[] = $focuskw2;
×
118
                }
UNCOV
119
                if ( ! empty( $focuskw3 ) ) {
×
UNCOV
120
                        $focus_keywords[] = $focuskw3;
×
121
                }
122

UNCOV
123
                if ( $focus_keywords !== [] ) {
×
UNCOV
124
                        $this->maybe_save_post_meta( 'focuskeywords', WPSEO_Utils::format_json_encode( $focus_keywords ), $post_id );
×
125
                }
126
        }
127

128
        /**
129
         * Retrieves the SEOpressor robot value and map this to Yoast SEO values.
130
         *
131
         * @param string $meta_rules The meta rules taken from the SEOpressor settings array.
132
         * @param int    $post_id    The post id of the current post.
133
         *
134
         * @return void
135
         */
UNCOV
136
        private function import_post_robots( $meta_rules, $post_id ) {
×
UNCOV
137
                $seopressor_robots = explode( '#|#|#', $meta_rules );
×
UNCOV
138
                $robot_value       = $this->get_robot_value( $seopressor_robots );
×
139

140
                // Saving the new meta values for Yoast SEO.
UNCOV
141
                $this->maybe_save_post_meta( 'meta-robots-noindex', $robot_value['index'], $post_id );
×
UNCOV
142
                $this->maybe_save_post_meta( 'meta-robots-nofollow', $robot_value['follow'], $post_id );
×
UNCOV
143
                $this->maybe_save_post_meta( 'meta-robots-adv', $robot_value['advanced'], $post_id );
×
144
        }
145

146
        /**
147
         * Gets the robot config by given SEOpressor robots value.
148
         *
149
         * @param array $seopressor_robots The value in SEOpressor that needs to be converted to the Yoast format.
150
         *
151
         * @return array The robots values in Yoast format.
152
         */
UNCOV
153
        private function get_robot_value( $seopressor_robots ) {
×
UNCOV
154
                $return = [
×
UNCOV
155
                        'index'    => 2,
×
UNCOV
156
                        'follow'   => 0,
×
UNCOV
157
                        'advanced' => '',
×
UNCOV
158
                ];
×
159

UNCOV
160
                if ( in_array( 'noindex', $seopressor_robots, true ) ) {
×
UNCOV
161
                        $return['index'] = 1;
×
162
                }
UNCOV
163
                if ( in_array( 'nofollow', $seopressor_robots, true ) ) {
×
UNCOV
164
                        $return['follow'] = 1;
×
165
                }
UNCOV
166
                foreach ( [ 'noarchive', 'nosnippet', 'noimageindex' ] as $needle ) {
×
UNCOV
167
                        if ( in_array( $needle, $seopressor_robots, true ) ) {
×
168
                                $return['advanced'] .= $needle . ',';
×
169
                        }
170
                }
UNCOV
171
                $return['advanced'] = rtrim( $return['advanced'], ',' );
×
172

UNCOV
173
                return $return;
×
174
        }
175
}
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