• 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

35.48
/admin/import/class-import-settings.php
1
<?php
2
/**
3
 * WPSEO plugin file.
4
 *
5
 * @package WPSEO\Admin\Import
6
 */
7

8
/**
9
 * Class WPSEO_Import_Settings.
10
 *
11
 * Class with functionality to import the Yoast SEO settings.
12
 */
13
class WPSEO_Import_Settings {
14

15
        /**
16
         * Nonce action key.
17
         *
18
         * @var string
19
         */
20
        public const NONCE_ACTION = 'wpseo-import-settings';
21

22
        /**
23
         * Holds the import status instance.
24
         *
25
         * @var WPSEO_Import_Status
26
         */
27
        public $status;
28

29
        /**
30
         * Holds the old WPSEO version.
31
         *
32
         * @var string
33
         */
34
        private $old_wpseo_version;
35

36
        /**
37
         * Class constructor.
38
         */
39
        public function __construct() {
×
40
                $this->status = new WPSEO_Import_Status( 'import', false );
×
41
        }
42

43
        /**
44
         * Imports the data submitted by the user.
45
         *
46
         * @return void
47
         */
48
        public function import() {
8✔
49
                check_admin_referer( self::NONCE_ACTION );
8✔
50

51
                if ( ! WPSEO_Capability_Utils::current_user_can( 'wpseo_manage_options' ) ) {
8✔
52
                        return;
2✔
53
                }
54

55
                if ( ! isset( $_POST['settings_import'] ) || ! is_string( $_POST['settings_import'] ) ) {
6✔
56
                        return;
2✔
57
                }
58

59
                // phpcs:ignore WordPress.Security.ValidatedSanitizedInput.InputNotSanitized -- Reason: The raw content will be parsed afterwards.
60
                $content = wp_unslash( $_POST['settings_import'] );
4✔
61

62
                if ( empty( $content ) ) {
4✔
63
                        return;
2✔
64
                }
65

66
                $this->parse_options( $content );
2✔
67
        }
1✔
68

69
        /**
70
         * Parse the options.
71
         *
72
         * @param string $raw_options The content to parse.
73
         *
74
         * @return void
75
         */
UNCOV
76
        protected function parse_options( $raw_options ) {
×
UNCOV
77
                $options = parse_ini_string( $raw_options, true, INI_SCANNER_RAW );
×
78

UNCOV
79
                if ( is_array( $options ) && $options !== [] ) {
×
UNCOV
80
                        $this->import_options( $options );
×
81

UNCOV
82
                        return;
×
83
                }
84

UNCOV
85
                $this->status->set_msg( __( 'Settings could not be imported:', 'wordpress-seo' ) . ' ' . __( 'No settings found.', 'wordpress-seo' ) );
×
86
        }
87

88
        /**
89
         * Parse the option group and import it.
90
         *
91
         * @param string $name         Name string.
92
         * @param array  $option_group Option group data.
93
         * @param array  $options      Options data.
94
         *
95
         * @return void
96
         */
97
        protected function parse_option_group( $name, $option_group, $options ) {
×
98
                // Make sure that the imported options are cleaned/converted on import.
99
                $option_instance = WPSEO_Options::get_option_instance( $name );
×
100
                if ( is_object( $option_instance ) && method_exists( $option_instance, 'import' ) ) {
×
101
                        $option_instance->import( $option_group, $this->old_wpseo_version, $options );
×
102
                }
103
        }
104

105
        /**
106
         * Imports the options if found.
107
         *
108
         * @param array $options The options parsed from the provided settings.
109
         *
110
         * @return void
111
         */
112
        protected function import_options( $options ) {
×
113
                if ( isset( $options['wpseo']['version'] ) && $options['wpseo']['version'] !== '' ) {
×
114
                        $this->old_wpseo_version = $options['wpseo']['version'];
×
115
                }
116

117
                foreach ( $options as $name => $option_group ) {
×
118
                        $this->parse_option_group( $name, $option_group, $options );
×
119
                }
120

121
                $this->status->set_msg( __( 'Settings successfully imported.', 'wordpress-seo' ) );
×
122
                $this->status->set_status( true );
×
123

124
                // Reset the cached option values.
125
                WPSEO_Options::clear_cache();
×
126
        }
127
}
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