MainWP Child - Version 4.2.6

Version Description

  • 8-26-2022 =
  • Fixed: An issue with support for the new extension
Download this release

Release Info

Developer mainwp
Plugin Icon 128x128 MainWP Child
Version 4.2.6
Comparing to
See all releases

Code changes from version 4.2.5 to 4.2.6

class/class-mainwp-child-wp-seopress.php ADDED
@@ -0,0 +1,269 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ <?php
2
+ /**
3
+ * MainWP WP SEOPress
4
+ *
5
+ * MainWP WP SEOPress Extension handler.
6
+ *
7
+ * @link https://mainwp.com/extension/wp-seopress/
8
+ *
9
+ * @package MainWP\Child
10
+ *
11
+ * Credits
12
+ *
13
+ * Plugin-Name: SEOPress
14
+ * Plugin URI: https://seopress.org?utm_source=wpadmin&utm_medium=plugin&utm_campaign=wpseopressplugin
15
+ * Author: SEOPress
16
+ * Author URI: https://seopress.com/
17
+ * Licence: GPL v3
18
+ */
19
+
20
+ namespace MainWP\Child;
21
+
22
+ // phpcs:disable PSR1.Classes.ClassDeclaration, WordPress.WP.AlternativeFunctions -- Required to achieve desired results. Pull requests appreciated.
23
+
24
+ /**
25
+ * Class MainWP_Child_WP_Seopress
26
+ *
27
+ * MainWP WP Seopress Extension handler.
28
+ */
29
+ class MainWP_Child_WP_Seopress {
30
+
31
+ /**
32
+ * Public static variable to hold the single instance of the class.
33
+ *
34
+ * @var mixed Default null
35
+ */
36
+ public static $instance = null;
37
+
38
+ /**
39
+ * Method instance()
40
+ *
41
+ * Create a public static instance.
42
+ *
43
+ * @return mixed Class instance.
44
+ */
45
+ public static function instance() {
46
+ if ( null === self::$instance ) {
47
+ self::$instance = new self();
48
+ }
49
+
50
+ return self::$instance;
51
+ }
52
+
53
+ /**
54
+ * Fire off certain SEOPRESS plugin actions.
55
+ *
56
+ * @uses MainWP_Helper::write() Write response data to be sent to the MainWP Dashboard.
57
+ */
58
+ public function action() {
59
+ if ( ! in_array( 'wp-seopress/seopress.php', apply_filters( 'active_plugins', get_option( 'active_plugins' ) ), true ) ) {
60
+ $information['error'] = 'NO_SEOPRESS';
61
+ MainWP_Helper::write( $information );
62
+ }
63
+
64
+ $mwp_action = ! empty( $_POST['action'] ) ? sanitize_text_field( wp_unslash( $_POST['action'] ) ) : '';
65
+
66
+ if ( ! empty( $mwp_action ) && method_exists( $this, $mwp_action ) ) {
67
+ $information = $this->{$mwp_action}();
68
+ MainWP_Helper::write( $information );
69
+ }
70
+ }
71
+
72
+ /**
73
+ * Check if Pro Version is active
74
+ *
75
+ * @return boolean
76
+ */
77
+ protected function is_seopress_pro_version_active() {
78
+ return in_array( 'wp-seopress-pro/seopress-pro.php', apply_filters( 'active_plugins', get_option( 'active_plugins' ) ), true );
79
+ }
80
+
81
+ /**
82
+ * Import the SEOPRESS plugin settings.
83
+ *
84
+ * @uses MainWP_Helper::write() Write response data to be sent to the MainWP Dashboard.
85
+ *
86
+ * @used-by MainWP_Child_WP_Seopress::action() Fire off certain SEOPRESS plugin actions.
87
+ *
88
+ * @throws \Exception Error message.
89
+ */
90
+ public function export_settings() {
91
+ if ( ! function_exists( 'seopress_return_settings' ) ) {
92
+ $information['error'] = __( 'Settings could not be exported. Missing function `seopress_return_settings`', 'mainwp-child' );
93
+ return $information;
94
+ }
95
+
96
+ $settings = seopress_return_settings();
97
+
98
+ $information['settings'] = $settings;
99
+ $information['message'] = __( 'Export completed', 'mainwp-child' );
100
+
101
+ return $information;
102
+ }
103
+
104
+ /**
105
+ * Import the SEOPRESS plugin settings.
106
+ *
107
+ * @used-by MainWP_Child_WP_Seopress::action() Fire off certain SEOPRESS plugin actions.
108
+ */
109
+ public function import_settings() {
110
+ if ( isset( $_POST['settings'] ) ) {
111
+ if ( ! function_exists( 'seopress_do_import_settings' ) ) {
112
+ $information['error'] = __( 'Settings could not be imported. Missing function `seopress_do_import_settings`', 'mainwp-child' );
113
+ return $information;
114
+ }
115
+
116
+ $settings = json_decode( stripslashes( $_POST['settings'] ), true );
117
+
118
+ seopress_do_import_settings( $settings );
119
+
120
+ $information['message'] = __( 'Import completed', 'mainwp-child' );
121
+
122
+ return $information;
123
+ }
124
+ }
125
+
126
+ /**
127
+ * Sync settings
128
+ *
129
+ * @return array
130
+ */
131
+ public function sync_settings() {
132
+ if ( ! function_exists( 'seopress_mainwp_save_settings' ) ) {
133
+ $information['error'] = __( 'Settings could not be saved. Missing function `seopress_mainwp_save_settings`', 'mainwp-child' );
134
+ return $information;
135
+ }
136
+
137
+ if ( isset( $_POST['settings'] ) ) {
138
+ $settings = $_POST['settings'] ?? array();
139
+ $option = sanitize_text_field( $_POST['option'] ?? '' );
140
+
141
+ if ( empty( $option ) ) {
142
+ $information['error'] = __( 'Settings could not be saved. Missing option name.', 'mainwp-child' );
143
+ return $information;
144
+ }
145
+
146
+ if ( 'seopress_pro_option_name' === $option && ! $this->is_seopress_pro_version_active() ) {
147
+ $information['error'] = __( 'SEOPress Pro plugin is not active on child site.', 'mainwp-child' );
148
+ return $information;
149
+ }
150
+
151
+ if ( ! empty( $settings ) ) {
152
+ $settings = $this->sanitize_options( $settings );
153
+ }
154
+
155
+ seopress_mainwp_save_settings( $settings, $option );
156
+
157
+ $information['message'] = __( 'Save successful', 'mainwp-child' );
158
+
159
+ return $information;
160
+ }
161
+ }
162
+
163
+ /**
164
+ * Save pro licence
165
+ *
166
+ * @used-by MainWP_Child_WP_Seopress::action() Fire off certain SEOPRESS plugin actions.
167
+ *
168
+ * @return array
169
+ */
170
+ public function save_pro_licence() {
171
+ if ( ! $this->is_seopress_pro_version_active() ) {
172
+ $information['error'] = __( 'SEOPress Pro plugin is not active on child site.', 'mainwp-child' );
173
+ return $information;
174
+ }
175
+
176
+ if ( ! function_exists( 'seopress_save_pro_licence' ) ) {
177
+ $information['error'] = __( 'Settings could not be saved. Missing function `seopress_save_pro_licence`', 'mainwp-child' );
178
+ return $information;
179
+ }
180
+
181
+ $licence = $_POST['licence'] ?? array();
182
+
183
+ $licence = $this->sanitize_options( $licence );
184
+
185
+ $response = seopress_save_pro_licence( $licence );
186
+
187
+ if ( ! is_wp_error( $response ) ) {
188
+ $information['message'] = __( 'Save successful', 'mainwp-child' );
189
+ } else {
190
+ $information['error'] = $response->get_error_message();
191
+ }
192
+
193
+ return $information;
194
+ }
195
+
196
+ /**
197
+ * Reset pro licence
198
+ *
199
+ * @used-by MainWP_Child_WP_Seopress::action() Fire off certain SEOPRESS plugin actions.
200
+ *
201
+ * @return array
202
+ */
203
+ public function reset_pro_licence() {
204
+ if ( ! $this->is_seopress_pro_version_active() ) {
205
+ $information['error'] = __( 'SEOPress Pro plugin is not active on child site.', 'mainwp-child' );
206
+ return $information;
207
+ }
208
+
209
+ if ( ! function_exists( 'seopress_reset_pro_licence' ) ) {
210
+ $information['error'] = __( 'Licence could not be reset. Missing function `seopress_reset_pro_licence`', 'mainwp-child' );
211
+ return $information;
212
+ }
213
+
214
+ seopress_reset_pro_licence( $licence );
215
+
216
+ $information['message'] = __( 'Reset successful', 'mainwp-child' );
217
+
218
+ return $information;
219
+ }
220
+
221
+ /**
222
+ * Flush rewrite rules
223
+ *
224
+ * @used-by MainWP_Child_WP_Seopress::action() Fire off certain SEOPRESS plugin actions.
225
+ *
226
+ * @return array
227
+ */
228
+ public function flush_rewrite_rules() {
229
+ if ( ! function_exists( 'seopress_flush_rewrite_rules' ) ) {
230
+ $information['error'] = __( 'Action could not be executed. Missing function `seopress_flush_rewrite_rules`', 'mainwp-child' );
231
+ return $information;
232
+ }
233
+
234
+ seopress_flush_rewrite_rules();
235
+
236
+ $information['message'] = __( 'Save successful', 'mainwp-child' );
237
+
238
+ return $information;
239
+ }
240
+
241
+ /**
242
+ * Sanitize the fields before saving
243
+ *
244
+ * @param mixed<string|array> $option The option to be sanitized.
245
+ *
246
+ * @return array
247
+ */
248
+ private function sanitize_options( $option ) {
249
+ if ( is_array( $option ) ) {
250
+ foreach ( $option as $field => $value ) {
251
+ if ( is_numeric( $value ) ) {
252
+ $option[ $field ] = $value;
253
+ } else {
254
+ if ( is_array( $value ) ) {
255
+ $option[ $field ] = $this->sanitize_options( $value );
256
+ } else {
257
+ if ( 'seopress_robots_file' === $field || 'seopress_instant_indexing_google_api_key' === $field ) {
258
+ $option[ $field ] = wp_kses_post( wp_unslash( $value ) );
259
+ } else {
260
+ $option[ $field ] = wp_unslash( $value );
261
+ }
262
+ }
263
+ }
264
+ }
265
+ }
266
+
267
+ return $option;
268
+ }
269
+ }
class/class-mainwp-child.php CHANGED
@@ -33,7 +33,7 @@ class MainWP_Child {
33
  *
34
  * @var string MainWP Child plugin version.
35
  */
36
- public static $version = '4.2.5';
37
 
38
  /**
39
  * Private variable containing the latest MainWP Child update version.
33
  *
34
  * @var string MainWP Child plugin version.
35
  */
36
+ public static $version = '4.2.6';
37
 
38
  /**
39
  * Private variable containing the latest MainWP Child update version.
mainwp-child.php CHANGED
@@ -12,7 +12,7 @@
12
  * Author: MainWP
13
  * Author URI: https://mainwp.com
14
  * Text Domain: mainwp-child
15
- * Version: 4.2.5
16
  * Requires at least: 5.4
17
  * Requires PHP: 7.0
18
  */
12
  * Author: MainWP
13
  * Author URI: https://mainwp.com
14
  * Text Domain: mainwp-child
15
+ * Version: 4.2.6
16
  * Requires at least: 5.4
17
  * Requires PHP: 7.0
18
  */
readme.txt CHANGED
@@ -5,9 +5,9 @@ Author: mainwp
5
  Author URI: https://mainwp.com
6
  Plugin URI: https://mainwp.com
7
  Requires at least: 5.4
8
- Tested up to: 6.0.1
9
  Requires PHP: 7.0
10
- Stable tag: 4.2.5
11
  License: GPLv3 or later
12
  License URI: https://www.gnu.org/licenses/gpl-3.0.html
13
 
@@ -111,6 +111,9 @@ Sure we have a quick FAQ with a lot more questions and answers [here](https://ma
111
 
112
  == Changelog ==
113
 
 
 
 
114
  = 4.2.5 - 8-25-2022 =
115
  * Added: Support for the new extension
116
  * Fixed: An issue with displaying PHP errors
5
  Author URI: https://mainwp.com
6
  Plugin URI: https://mainwp.com
7
  Requires at least: 5.4
8
+ Tested up to: 6.1
9
  Requires PHP: 7.0
10
+ Stable tag: 4.2.6
11
  License: GPLv3 or later
12
  License URI: https://www.gnu.org/licenses/gpl-3.0.html
13
 
111
 
112
  == Changelog ==
113
 
114
+ = 4.2.6 - 8-26-2022 =
115
+ * Fixed: An issue with support for the new extension
116
+
117
  = 4.2.5 - 8-25-2022 =
118
  * Added: Support for the new extension
119
  * Fixed: An issue with displaying PHP errors