PluginProbe
Yoast SEO – Advanced SEO with real-time guidance and built-in AI / 19.0
Yoast SEO – Advanced SEO with real-time guidance and built-in AI v19.0
28.5 28.4 28.3 28.2 28.1 28.0 27.9 27.8 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 All 129 releases
wordpress-seo / admin / import / class-import-settings.php

class-import-settings.php in Yoast SEO – Advanced SEO with real-time guidance and built-in AI 19.0, at admin/import/class-import-settings.php

118 lines 2.7 KB
No matching file
Up and down to move Enter to open Esc to close
Raw Download Zip
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() {
49 check_admin_referer( self::NONCE_ACTION );
50
51 if ( ! WPSEO_Capability_Utils::current_user_can( 'wpseo_manage_options' ) ) {
52 return;
53 }
54
55 $content = filter_input( INPUT_POST, 'settings_import' );
56 if ( empty( $content ) ) {
57 return;
58 }
59
60 $this->parse_options( $content );
61 }
62
63 /**
64 * Parse the options.
65 *
66 * @param string $raw_options The content to parse.
67 *
68 * @return void
69 */
70 protected function parse_options( $raw_options ) {
71 $options = parse_ini_string( $raw_options, true, INI_SCANNER_RAW );
72
73 if ( is_array( $options ) && $options !== [] ) {
74 $this->import_options( $options );
75
76 return;
77 }
78
79 $this->status->set_msg( __( 'Settings could not be imported:', 'wordpress-seo' ) . ' ' . __( 'No settings found.', 'wordpress-seo' ) );
80 }
81
82 /**
83 * Parse the option group and import it.
84 *
85 * @param string $name Name string.
86 * @param array $option_group Option group data.
87 * @param array $options Options data.
88 */
89 protected function parse_option_group( $name, $option_group, $options ) {
90 // Make sure that the imported options are cleaned/converted on import.
91 $option_instance = WPSEO_Options::get_option_instance( $name );
92 if ( is_object( $option_instance ) && method_exists( $option_instance, 'import' ) ) {
93 $option_instance->import( $option_group, $this->old_wpseo_version, $options );
94 }
95 }
96
97 /**
98 * Imports the options if found.
99 *
100 * @param array $options The options parsed from the provided settings.
101 */
102 protected function import_options( $options ) {
103 if ( isset( $options['wpseo']['version'] ) && $options['wpseo']['version'] !== '' ) {
104 $this->old_wpseo_version = $options['wpseo']['version'];
105 }
106
107 foreach ( $options as $name => $option_group ) {
108 $this->parse_option_group( $name, $option_group, $options );
109 }
110
111 $this->status->set_msg( __( 'Settings successfully imported.', 'wordpress-seo' ) );
112 $this->status->set_status( true );
113
114 // Reset the cached option values.
115 WPSEO_Options::clear_cache();
116 }
117 }
118