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

Yoast / wordpress-seo / 6987097851

25 Nov 2023 04:49AM UTC coverage: 49.206% (-0.1%) from 49.302%
6987097851

push

github

web-flow
Merge pull request #20878 from Yoast/JRF/ghactions-minor-tweak

GH Actions: update a few links in inline comments

15305 of 31104 relevant lines covered (49.21%)

4.03 hits per line

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

56.25
/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
        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
         */
76
        protected function parse_options( $raw_options ) {
12✔
77
                $options = parse_ini_string( $raw_options, true, INI_SCANNER_RAW );
12✔
78

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

82
                        return;
4✔
83
                }
84

85
                $this->status->set_msg( __( 'Settings could not be imported:', 'wordpress-seo' ) . ' ' . __( 'No settings found.', 'wordpress-seo' ) );
8✔
86
        }
4✔
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
        protected function parse_option_group( $name, $option_group, $options ) {
×
96
                // Make sure that the imported options are cleaned/converted on import.
97
                $option_instance = WPSEO_Options::get_option_instance( $name );
×
98
                if ( is_object( $option_instance ) && method_exists( $option_instance, 'import' ) ) {
×
99
                        $option_instance->import( $option_group, $this->old_wpseo_version, $options );
×
100
                }
101
        }
102

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

113
                foreach ( $options as $name => $option_group ) {
×
114
                        $this->parse_option_group( $name, $option_group, $options );
×
115
                }
116

117
                $this->status->set_msg( __( 'Settings successfully imported.', 'wordpress-seo' ) );
×
118
                $this->status->set_status( true );
×
119

120
                // Reset the cached option values.
121
                WPSEO_Options::clear_cache();
×
122
        }
123
}
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