PluginProbe ʕ •ᴥ•ʔ
Yoast SEO – Advanced SEO with real-time guidance and built-in AI / 27.5
Yoast SEO – Advanced SEO with real-time guidance and built-in AI v27.5
27.7 27.6 27.5 trunk 18.0 18.1 18.2 18.3 18.4 18.4.1 18.5 18.5.1 18.6 18.7 18.8 18.9 19.0 19.1 19.10 19.11 19.12 19.13 19.14 19.2 19.3 19.4 19.5 19.5.1 19.6 19.6.1 19.7 19.7.1 19.7.2 19.8 19.9 20.0 20.1 20.10 20.11 20.12 20.13 20.2 20.2.1 20.3 20.4 20.5 20.6 20.7 20.8 20.9 21.0 21.1 21.2 21.3 21.4 21.5 21.6 21.7 21.8 21.8.1 21.9 21.9.1 22.0 22.1 22.2 22.3 22.4 22.5 22.6 22.7 22.8 22.9 23.0 23.1 23.2 23.3 23.4 23.5 23.6 23.7 23.8 23.9 24.0 24.1 24.2 24.3 24.4 24.5 24.6 24.7 24.8 24.8.1 24.9 25.0 25.1 25.2 25.3 25.3.1 25.4 25.5 25.6 25.7 25.8 25.9 26.0 26.1 26.1.1 26.2 26.3 26.4 26.5 26.6 26.7 26.8 26.9 27.0 27.1 27.1.1 27.2 27.3 27.4
wordpress-seo / admin / import / class-import-settings.php
wordpress-seo / admin / import Last commit date
plugins 3 months ago class-import-detector.php 2 years ago class-import-plugin.php 6 years ago class-import-settings.php 2 years ago class-import-status.php 7 years ago
class-import-settings.php
128 lines
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() {
49 check_admin_referer( self::NONCE_ACTION );
50
51 if ( ! WPSEO_Capability_Utils::current_user_can( 'wpseo_manage_options' ) ) {
52 return;
53 }
54
55 if ( ! isset( $_POST['settings_import'] ) || ! is_string( $_POST['settings_import'] ) ) {
56 return;
57 }
58
59 // phpcs:ignore WordPress.Security.ValidatedSanitizedInput.InputNotSanitized -- Reason: The raw content will be parsed afterwards.
60 $content = wp_unslash( $_POST['settings_import'] );
61
62 if ( empty( $content ) ) {
63 return;
64 }
65
66 $this->parse_options( $content );
67 }
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 ) {
77 $options = parse_ini_string( $raw_options, true, INI_SCANNER_RAW );
78
79 if ( is_array( $options ) && $options !== [] ) {
80 $this->import_options( $options );
81
82 return;
83 }
84
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 }
128