Version Description
- 2-16-2022 =
- Fixed: Problem with loading UpdrafPlus data when
$updraftplus_admin
returns empty value - Fixed: Problem with posting images
- Fixed: Problem with loading Wordfence Scan data in reports
- Updated: Multiple error messages
- Updated: Incorrect links
Download this release
Release Info
Developer | mainwp |
Plugin | MainWP Child |
Version | 4.1.10 |
Comparing to | |
See all releases |
Code changes from version 4.1.9 to 4.1.10
- class/class-mainwp-child-branding-render.php +382 -382
- class/class-mainwp-child-branding.php +1 -1
- class/class-mainwp-child-callable.php +1011 -1011
- class/class-mainwp-child-install.php +2 -2
- class/class-mainwp-child-ithemes-security.php +1653 -1653
- class/class-mainwp-child-posts.php +1448 -1347
- class/class-mainwp-child-server-information-base.php +766 -766
- class/class-mainwp-child-server-information.php +1443 -1443
- class/class-mainwp-child-stats.php +1072 -1072
- class/class-mainwp-child-updates.php +997 -997
- class/class-mainwp-child-users.php +1 -1
- class/class-mainwp-child-woocommerce-status.php +493 -493
- class/class-mainwp-child-wordfence.php +4020 -4023
- class/class-mainwp-child.php +456 -456
- class/class-mainwp-client-report-base.php +1026 -1026
- class/class-mainwp-clone.php +0 -777
class/class-mainwp-child-branding-render.php
CHANGED
@@ -1,382 +1,382 @@
|
|
1 |
-
<?php
|
2 |
-
/**
|
3 |
-
* MainWP Render Branding
|
4 |
-
*
|
5 |
-
* This file handles rendering the Child Branding settings.
|
6 |
-
*
|
7 |
-
* @package MainWP\Child
|
8 |
-
*/
|
9 |
-
|
10 |
-
namespace MainWP\Child;
|
11 |
-
|
12 |
-
/**
|
13 |
-
* Class MainWP_Child_Branding_Render
|
14 |
-
*
|
15 |
-
* @package MainWP\Child
|
16 |
-
*/
|
17 |
-
class MainWP_Child_Branding_Render {
|
18 |
-
|
19 |
-
/**
|
20 |
-
* Public static variable to hold the single instance of the class.
|
21 |
-
*
|
22 |
-
* @var mixed Default null
|
23 |
-
*/
|
24 |
-
public static $instance = null;
|
25 |
-
|
26 |
-
/**
|
27 |
-
* Method instance()
|
28 |
-
*
|
29 |
-
* Create a public static instance.
|
30 |
-
*
|
31 |
-
* @return mixed Class instance.
|
32 |
-
*/
|
33 |
-
public static function instance() {
|
34 |
-
if ( null === self::$instance ) {
|
35 |
-
self::$instance = new self();
|
36 |
-
}
|
37 |
-
return self::$instance;
|
38 |
-
}
|
39 |
-
|
40 |
-
/**
|
41 |
-
* Get Class Name.
|
42 |
-
*
|
43 |
-
* @return string
|
44 |
-
*/
|
45 |
-
public static function get_class_name() {
|
46 |
-
return __CLASS__;
|
47 |
-
}
|
48 |
-
|
49 |
-
/**
|
50 |
-
* MainWP_Child_Branding_Render constructor.
|
51 |
-
*
|
52 |
-
* Run any time the class is called.
|
53 |
-
*/
|
54 |
-
public function __construct() {
|
55 |
-
}
|
56 |
-
|
57 |
-
/**
|
58 |
-
* Method admin_head_hide_elements().
|
59 |
-
*/
|
60 |
-
public function admin_head_hide_elements() {
|
61 |
-
?>
|
62 |
-
<script type="text/javascript">
|
63 |
-
document.addEventListener( "DOMContentLoaded", function( event ) {
|
64 |
-
document.getElementById( "wp-admin-bar-updates" ).outerHTML = '';
|
65 |
-
document.getElementById( "menu-plugins" ).outerHTML = '';
|
66 |
-
var els_core = document.querySelectorAll( "a[href='update-core.php']" );
|
67 |
-
for ( var i = 0, l = els_core.length; i < l; i++ ) {
|
68 |
-
var el = els_core[i];
|
69 |
-
el.parentElement.innerHTML = '';
|
70 |
-
}
|
71 |
-
} );
|
72 |
-
</script>
|
73 |
-
<?php
|
74 |
-
}
|
75 |
-
|
76 |
-
/**
|
77 |
-
* Render Contact Support.
|
78 |
-
*
|
79 |
-
* @return string Contact Support form html.
|
80 |
-
*
|
81 |
-
* @uses \MainWP\Child\MainWP_Child_Branding::$child_branding_options
|
82 |
-
*/
|
83 |
-
public function contact_support() {
|
84 |
-
|
85 |
-
/**
|
86 |
-
* Current user global.
|
87 |
-
*
|
88 |
-
* @global string
|
89 |
-
*/
|
90 |
-
global $current_user;
|
91 |
-
|
92 |
-
?>
|
93 |
-
<style>
|
94 |
-
.mainwp_info-box-yellow {
|
95 |
-
margin: 5px 0 15px;
|
96 |
-
padding: .6em;
|
97 |
-
background: #ffffe0;
|
98 |
-
border: 1px solid #e6db55;
|
99 |
-
border-radius: 3px;
|
100 |
-
-moz-border-radius: 3px;
|
101 |
-
-webkit-border-radius: 3px;
|
102 |
-
clear: both;
|
103 |
-
}
|
104 |
-
</style>
|
105 |
-
<?php
|
106 |
-
$opts = MainWP_Child_Branding::instance()->child_branding_options;
|
107 |
-
|
108 |
-
if ( isset( $_POST['submit'] ) ) {
|
109 |
-
if ( ! isset( $_POST['_wpnonce'] ) || ! wp_verify_nonce( sanitize_text_field( wp_unslash( $_POST['_wpnonce'] ) ), '_contactNonce' ) ) {
|
110 |
-
return false;
|
111 |
-
}
|
112 |
-
$this->render_submit_message( $opts );
|
113 |
-
return;
|
114 |
-
}
|
115 |
-
|
116 |
-
$from_page = '';
|
117 |
-
if ( isset( $_GET['from_page'] ) ) {
|
118 |
-
$from_page = isset( $_GET['from_page'] ) ? rawurldecode( wp_unslash( $_GET['from_page'] ) ) : '';
|
119 |
-
} else {
|
120 |
-
$protocol = isset( $_SERVER['HTTPS'] ) && strcasecmp( sanitize_text_field( wp_unslash( $_SERVER['HTTPS'] ) ), 'off' ) ? 'https://' : 'http://';
|
121 |
-
$fullurl = isset( $_SERVER['HTTP_HOST'] ) && isset( $_SERVER['REQUEST_URI'] ) ? $protocol . sanitize_text_field( wp_unslash( $_SERVER['HTTP_HOST'] ) ) . wp_unslash( $_SERVER['REQUEST_URI'] ) : '';
|
122 |
-
$from_page = rawurldecode( $fullurl );
|
123 |
-
}
|
124 |
-
|
125 |
-
$support_message = $opts['support_message'];
|
126 |
-
$support_message = nl2br( stripslashes( $support_message ) );
|
127 |
-
$from_email = $current_user ? $current_user->user_email : '';
|
128 |
-
?>
|
129 |
-
<form action="" method="post">
|
130 |
-
<div style="width: 99%;" class="whlb-support-form">
|
131 |
-
<h2><?php echo esc_html( $opts['contact_label'] ); ?></h2>
|
132 |
-
<div style="height: auto; margin-bottom: 10px; text-align: left">
|
133 |
-
<p class="whlb-support-form"><?php echo wp_kses_post( $support_message ); ?></p>
|
134 |
-
<p class="whlb-support-form">
|
135 |
-
<label for="mainwp_branding_contact_message_subject"><?php esc_html_e( 'Subject:', 'mainwp-child' ); ?></label>
|
136 |
-
<br>
|
137 |
-
<input type="text" id="mainwp_branding_contact_message_subject" name="mainwp_branding_contact_message_subject" style="width: 650px;">
|
138 |
-
</p>
|
139 |
-
<p class="whlb-support-form">
|
140 |
-
<label for="mainwp_branding_contact_send_from"><?php esc_html_e( 'From:', 'mainwp-child' ); ?></label>
|
141 |
-
<br>
|
142 |
-
<input type="text" id="mainwp_branding_contact_send_from" name="mainwp_branding_contact_send_from" style="width: 650px;" value="<?php echo esc_attr( $from_email ); ?>">
|
143 |
-
</p>
|
144 |
-
<div style="max-width: 650px;" class="whlb-support-form">
|
145 |
-
<label for="mainwp_branding_contact_message_content"><?php esc_html_e( 'Your message:', 'mainwp-child' ); ?></label>
|
146 |
-
<br>
|
147 |
-
<?php
|
148 |
-
remove_editor_styles(); // stop custom theme styling interfering with the editor.
|
149 |
-
wp_editor(
|
150 |
-
'',
|
151 |
-
'mainwp_branding_contact_message_content',
|
152 |
-
array(
|
153 |
-
'textarea_name' => 'mainwp_branding_contact_message_content',
|
154 |
-
'textarea_rows' => 10,
|
155 |
-
'teeny' => true,
|
156 |
-
'wpautop' => true,
|
157 |
-
'media_buttons' => false,
|
158 |
-
)
|
159 |
-
);
|
160 |
-
?>
|
161 |
-
</div>
|
162 |
-
</div>
|
163 |
-
<br/>
|
164 |
-
<?php
|
165 |
-
$button_title = $opts['submit_button_title'];
|
166 |
-
$button_title = ! empty( $button_title ) ? $button_title : __( 'Submit', 'mainwp-child' );
|
167 |
-
?>
|
168 |
-
<div class="whlb-support-field">
|
169 |
-
<input id="mainwp-branding-contact-support-submit" type="submit" name="submit" value="<?php echo esc_attr( $button_title ); ?>" class="button-primary button" style="float: left"/>
|
170 |
-
</div>
|
171 |
-
</div>
|
172 |
-
<input type="hidden" name="mainwp_branding_send_from_page" value="<?php echo esc_url( $from_page ); ?>"/>
|
173 |
-
<input type="hidden" name="_wpnonce" value="<?php echo esc_attr( wp_create_nonce( '_contactNonce' ) ); ?>"/>
|
174 |
-
</form>
|
175 |
-
<?php
|
176 |
-
}
|
177 |
-
|
178 |
-
/**
|
179 |
-
* Render contact support submit message.
|
180 |
-
*
|
181 |
-
* @param array $opts An array containg message options.
|
182 |
-
*/
|
183 |
-
private function render_submit_message( $opts ) {
|
184 |
-
$from_page = isset( $_POST['mainwp_branding_send_from_page'] ) ? wp_unslash( $_POST['mainwp_branding_send_from_page'] ) : '';
|
185 |
-
$back_link = $opts['message_return_sender'];
|
186 |
-
$back_link = ! empty( $back_link ) ? $back_link : 'Go Back';
|
187 |
-
$back_link = ! empty( $from_page ) ? '<a href="' . esc_url( $from_page ) . '" title="' . esc_attr( $back_link ) . '">' . esc_html( $back_link ) . '</a>' : '';
|
188 |
-
|
189 |
-
if ( $this->send_support_mail() ) {
|
190 |
-
$send_email_message = isset( $opts['send_email_message'] ) ? $opts['send_email_message'] : '';
|
191 |
-
if ( ! empty( $send_email_message ) ) {
|
192 |
-
$send_email_message = stripslashes( $send_email_message );
|
193 |
-
} else {
|
194 |
-
$send_email_message = __( 'Message has been submitted successfully.', 'mainwp-child' );
|
195 |
-
}
|
196 |
-
} else {
|
197 |
-
$send_email_message = __( 'Sending email failed!', 'mainwp-child' );
|
198 |
-
}
|
199 |
-
?>
|
200 |
-
<div class="mainwp_info-box-yellow"><?php echo esc_html( $send_email_message ) . '  ' . $back_link; ?></div>
|
201 |
-
<?php
|
202 |
-
}
|
203 |
-
|
204 |
-
/**
|
205 |
-
* Send support email.
|
206 |
-
*
|
207 |
-
* @return bool Return TRUE on success FALSE on failure.
|
208 |
-
*
|
209 |
-
* @uses \MainWP\Child\MainWP_Child_Branding::get_branding_options()
|
210 |
-
*/
|
211 |
-
public function send_support_mail() {
|
212 |
-
$opts = MainWP_Child_Branding::instance()->get_branding_options();
|
213 |
-
$email = $opts['support_email'];
|
214 |
-
$sub = isset( $_POST['mainwp_branding_contact_message_subject'] ) ? wp_kses_post( nl2br( stripslashes( wp_unslash( $_POST['mainwp_branding_contact_message_subject'] ) ) ) ) : '';
|
215 |
-
$from = isset( $_POST['mainwp_branding_contact_send_from'] ) ? trim( wp_unslash( $_POST['mainwp_branding_contact_send_from'] ) ) : '';
|
216 |
-
$subject = ! empty( $sub ) ? $sub : 'MainWP - Support Contact';
|
217 |
-
$content = isset( $_POST['mainwp_branding_contact_message_content'] ) ? wp_kses_post( nl2br( stripslashes( wp_unslash( $_POST['mainwp_branding_contact_message_content'] ) ) ) ) : '';
|
218 |
-
$mail = '';
|
219 |
-
$headers = '';
|
220 |
-
|
221 |
-
$from_page = isset( $_POST['mainwp_branding_send_from_page'] ) ? wp_unslash( $_POST['mainwp_branding_send_from_page'] ) : '';
|
222 |
-
|
223 |
-
if ( ! empty( $_POST['mainwp_branding_contact_message_content'] ) && ! empty( $email ) ) {
|
224 |
-
|
225 |
-
/**
|
226 |
-
* Current user global.
|
227 |
-
*
|
228 |
-
* @global string
|
229 |
-
*/
|
230 |
-
global $current_user;
|
231 |
-
|
232 |
-
$headers .= "Content-Type: text/html;charset=utf-8\r\n";
|
233 |
-
if ( ! empty( $from ) ) {
|
234 |
-
$headers .= 'From: "' . $from . '" <' . $from . ">\r\n";
|
235 |
-
}
|
236 |
-
$mail .= "<p>Support Email from: <a href='" . site_url() . "'>" . site_url() . "</a></p>\r\n\r\n";
|
237 |
-
$mail .= '<p>Sent from WordPress page: ' . ( ! empty( $from_page ) ? "<a href='" . esc_url( $from_page ) . "'>" . esc_url( $from_page ) . "</a></p>\r\n\r\n" : '' );
|
238 |
-
$mail .= '<p>Client Email: ' . $current_user->user_email . " </p>\r\n\r\n";
|
239 |
-
$mail .= "<p>Support Text:</p>\r\n\r\n";
|
240 |
-
$mail .= '<p>' . $content . "</p>\r\n\r\n";
|
241 |
-
|
242 |
-
wp_mail( $email, $subject, $mail, $headers );
|
243 |
-
|
244 |
-
return true;
|
245 |
-
}
|
246 |
-
return false;
|
247 |
-
}
|
248 |
-
|
249 |
-
/**
|
250 |
-
* After admin bar render.
|
251 |
-
*/
|
252 |
-
public function after_admin_bar_render() {
|
253 |
-
$hide_slugs = apply_filters( 'mainwp_child_hide_update_notice', array() );
|
254 |
-
|
255 |
-
if ( ! is_array( $hide_slugs ) ) {
|
256 |
-
$hide_slugs = array();
|
257 |
-
}
|
258 |
-
|
259 |
-
if ( 0 == count( $hide_slugs ) ) {
|
260 |
-
return;
|
261 |
-
}
|
262 |
-
|
263 |
-
if ( ! function_exists( '\get_plugin_updates' ) ) {
|
264 |
-
include_once ABSPATH . '/wp-admin/includes/update.php';
|
265 |
-
}
|
266 |
-
|
267 |
-
$count_hide = 0;
|
268 |
-
|
269 |
-
$updates = get_plugin_updates();
|
270 |
-
if ( is_array( $updates ) ) {
|
271 |
-
foreach ( $updates as $slug => $data ) {
|
272 |
-
if ( in_array( $slug, $hide_slugs ) ) {
|
273 |
-
$count_hide++;
|
274 |
-
}
|
275 |
-
}
|
276 |
-
}
|
277 |
-
|
278 |
-
if ( 0 == $count_hide ) {
|
279 |
-
return;
|
280 |
-
}
|
281 |
-
?>
|
282 |
-
<script type="text/javascript">
|
283 |
-
var mainwpCountHide = <?php echo esc_attr( $count_hide ); ?>;
|
284 |
-
document.addEventListener( "DOMContentLoaded", function( event ) {
|
285 |
-
var $adminBarUpdates = document.querySelector( '#wp-admin-bar-updates .ab-label' ),
|
286 |
-
itemCount;
|
287 |
-
|
288 |
-
if ( typeof( $adminBarUpdates ) !== 'undefined' && $adminBarUpdates !== null ) {
|
289 |
-
itemCount = $adminBarUpdates.textContent;
|
290 |
-
itemCount = parseInt( itemCount );
|
291 |
-
|
292 |
-
itemCount -= mainwpCountHide;
|
293 |
-
if ( itemCount < 0 )
|
294 |
-
itemCount = 0;
|
295 |
-
|
296 |
-
$adminBarUpdates.textContent = itemCount;
|
297 |
-
}
|
298 |
-
} );
|
299 |
-
</script>
|
300 |
-
<?php
|
301 |
-
}
|
302 |
-
|
303 |
-
/**
|
304 |
-
* Admin footer text.
|
305 |
-
*/
|
306 |
-
public function in_admin_footer() {
|
307 |
-
$hide_slugs = apply_filters( 'mainwp_child_hide_update_notice', array() );
|
308 |
-
|
309 |
-
if ( ! is_array( $hide_slugs ) ) {
|
310 |
-
$hide_slugs = array();
|
311 |
-
}
|
312 |
-
|
313 |
-
$count_hide = 0;
|
314 |
-
|
315 |
-
$updates = get_plugin_updates();
|
316 |
-
if ( is_array( $updates ) ) {
|
317 |
-
foreach ( $updates as $slug => $data ) {
|
318 |
-
if ( in_array( $slug, $hide_slugs ) ) {
|
319 |
-
$count_hide++;
|
320 |
-
}
|
321 |
-
}
|
322 |
-
}
|
323 |
-
|
324 |
-
if ( 0 == $count_hide ) {
|
325 |
-
return;
|
326 |
-
}
|
327 |
-
|
328 |
-
?>
|
329 |
-
<script type="text/javascript">
|
330 |
-
var mainwpCountHide = <?php echo esc_attr( $count_hide ); ?>;
|
331 |
-
document.addEventListener( "DOMContentLoaded", function( event ) {
|
332 |
-
if ( typeof( pagenow ) !== 'undefined' && pagenow == 'plugins' ) {
|
333 |
-
<?php
|
334 |
-
// hide update notice row.
|
335 |
-
if ( in_array( 'mainwp-child/mainwp-child.php', $hide_slugs ) ) {
|
336 |
-
?>
|
337 |
-
var el = document.querySelector( 'tr#mainwp-child-update' );
|
338 |
-
if ( typeof( el ) !== 'undefined' && el !== null ) {
|
339 |
-
el.style.display = 'none';
|
340 |
-
}
|
341 |
-
<?php
|
342 |
-
}
|
343 |
-
// hide update notice row.
|
344 |
-
if ( in_array( 'mainwp-child-reports/mainwp-child-reports.php', $hide_slugs ) ) {
|
345 |
-
?>
|
346 |
-
var el = document.querySelector( 'tr#mainwp-child-reports-update' );
|
347 |
-
if ( typeof( el ) !== 'undefined' && el !== null ) {
|
348 |
-
el.style.display = 'none';
|
349 |
-
}
|
350 |
-
<?php
|
351 |
-
}
|
352 |
-
?>
|
353 |
-
}
|
354 |
-
|
355 |
-
if ( mainwpCountHide > 0 ) {
|
356 |
-
jQuery( document ).ready( function () {
|
357 |
-
|
358 |
-
var $adminBarUpdates = jQuery( '#wp-admin-bar-updates' ),
|
359 |
-
$pluginsNavMenuUpdateCount = jQuery( 'a[href="plugins.php"] .update-plugins' ),
|
360 |
-
itemCount;
|
361 |
-
itemCount = $adminBarUpdates.find( '.ab-label' ).text();
|
362 |
-
itemCount -= mainwpCountHide;
|
363 |
-
if ( itemCount < 0 )
|
364 |
-
itemCount = 0;
|
365 |
-
|
366 |
-
itemPCount = $pluginsNavMenuUpdateCount.find( '.plugin-count' ).text();
|
367 |
-
itemPCount -= mainwpCountHide;
|
368 |
-
|
369 |
-
if ( itemPCount < 0 )
|
370 |
-
itemPCount = 0;
|
371 |
-
|
372 |
-
$adminBarUpdates.find( '.ab-label' ).text( itemCount );
|
373 |
-
$pluginsNavMenuUpdateCount.find( '.plugin-count' ).text( itemPCount );
|
374 |
-
|
375 |
-
} );
|
376 |
-
}
|
377 |
-
} );
|
378 |
-
</script>
|
379 |
-
<?php
|
380 |
-
}
|
381 |
-
|
382 |
-
}
|
1 |
+
<?php
|
2 |
+
/**
|
3 |
+
* MainWP Render Branding
|
4 |
+
*
|
5 |
+
* This file handles rendering the Child Branding settings.
|
6 |
+
*
|
7 |
+
* @package MainWP\Child
|
8 |
+
*/
|
9 |
+
|
10 |
+
namespace MainWP\Child;
|
11 |
+
|
12 |
+
/**
|
13 |
+
* Class MainWP_Child_Branding_Render
|
14 |
+
*
|
15 |
+
* @package MainWP\Child
|
16 |
+
*/
|
17 |
+
class MainWP_Child_Branding_Render {
|
18 |
+
|
19 |
+
/**
|
20 |
+
* Public static variable to hold the single instance of the class.
|
21 |
+
*
|
22 |
+
* @var mixed Default null
|
23 |
+
*/
|
24 |
+
public static $instance = null;
|
25 |
+
|
26 |
+
/**
|
27 |
+
* Method instance()
|
28 |
+
*
|
29 |
+
* Create a public static instance.
|
30 |
+
*
|
31 |
+
* @return mixed Class instance.
|
32 |
+
*/
|
33 |
+
public static function instance() {
|
34 |
+
if ( null === self::$instance ) {
|
35 |
+
self::$instance = new self();
|
36 |
+
}
|
37 |
+
return self::$instance;
|
38 |
+
}
|
39 |
+
|
40 |
+
/**
|
41 |
+
* Get Class Name.
|
42 |
+
*
|
43 |
+
* @return string
|
44 |
+
*/
|
45 |
+
public static function get_class_name() {
|
46 |
+
return __CLASS__;
|
47 |
+
}
|
48 |
+
|
49 |
+
/**
|
50 |
+
* MainWP_Child_Branding_Render constructor.
|
51 |
+
*
|
52 |
+
* Run any time the class is called.
|
53 |
+
*/
|
54 |
+
public function __construct() {
|
55 |
+
}
|
56 |
+
|
57 |
+
/**
|
58 |
+
* Method admin_head_hide_elements().
|
59 |
+
*/
|
60 |
+
public static function admin_head_hide_elements() {
|
61 |
+
?>
|
62 |
+
<script type="text/javascript">
|
63 |
+
document.addEventListener( "DOMContentLoaded", function( event ) {
|
64 |
+
document.getElementById( "wp-admin-bar-updates" ).outerHTML = '';
|
65 |
+
document.getElementById( "menu-plugins" ).outerHTML = '';
|
66 |
+
var els_core = document.querySelectorAll( "a[href='update-core.php']" );
|
67 |
+
for ( var i = 0, l = els_core.length; i < l; i++ ) {
|
68 |
+
var el = els_core[i];
|
69 |
+
el.parentElement.innerHTML = '';
|
70 |
+
}
|
71 |
+
} );
|
72 |
+
</script>
|
73 |
+
<?php
|
74 |
+
}
|
75 |
+
|
76 |
+
/**
|
77 |
+
* Render Contact Support.
|
78 |
+
*
|
79 |
+
* @return string Contact Support form html.
|
80 |
+
*
|
81 |
+
* @uses \MainWP\Child\MainWP_Child_Branding::$child_branding_options
|
82 |
+
*/
|
83 |
+
public function contact_support() {
|
84 |
+
|
85 |
+
/**
|
86 |
+
* Current user global.
|
87 |
+
*
|
88 |
+
* @global string
|
89 |
+
*/
|
90 |
+
global $current_user;
|
91 |
+
|
92 |
+
?>
|
93 |
+
<style>
|
94 |
+
.mainwp_info-box-yellow {
|
95 |
+
margin: 5px 0 15px;
|
96 |
+
padding: .6em;
|
97 |
+
background: #ffffe0;
|
98 |
+
border: 1px solid #e6db55;
|
99 |
+
border-radius: 3px;
|
100 |
+
-moz-border-radius: 3px;
|
101 |
+
-webkit-border-radius: 3px;
|
102 |
+
clear: both;
|
103 |
+
}
|
104 |
+
</style>
|
105 |
+
<?php
|
106 |
+
$opts = MainWP_Child_Branding::instance()->child_branding_options;
|
107 |
+
|
108 |
+
if ( isset( $_POST['submit'] ) ) {
|
109 |
+
if ( ! isset( $_POST['_wpnonce'] ) || ! wp_verify_nonce( sanitize_text_field( wp_unslash( $_POST['_wpnonce'] ) ), '_contactNonce' ) ) {
|
110 |
+
return false;
|
111 |
+
}
|
112 |
+
$this->render_submit_message( $opts );
|
113 |
+
return;
|
114 |
+
}
|
115 |
+
|
116 |
+
$from_page = '';
|
117 |
+
if ( isset( $_GET['from_page'] ) ) {
|
118 |
+
$from_page = isset( $_GET['from_page'] ) ? rawurldecode( wp_unslash( $_GET['from_page'] ) ) : '';
|
119 |
+
} else {
|
120 |
+
$protocol = isset( $_SERVER['HTTPS'] ) && strcasecmp( sanitize_text_field( wp_unslash( $_SERVER['HTTPS'] ) ), 'off' ) ? 'https://' : 'http://';
|
121 |
+
$fullurl = isset( $_SERVER['HTTP_HOST'] ) && isset( $_SERVER['REQUEST_URI'] ) ? $protocol . sanitize_text_field( wp_unslash( $_SERVER['HTTP_HOST'] ) ) . wp_unslash( $_SERVER['REQUEST_URI'] ) : '';
|
122 |
+
$from_page = rawurldecode( $fullurl );
|
123 |
+
}
|
124 |
+
|
125 |
+
$support_message = $opts['support_message'];
|
126 |
+
$support_message = nl2br( stripslashes( $support_message ) );
|
127 |
+
$from_email = $current_user ? $current_user->user_email : '';
|
128 |
+
?>
|
129 |
+
<form action="" method="post">
|
130 |
+
<div style="width: 99%;" class="whlb-support-form">
|
131 |
+
<h2><?php echo esc_html( $opts['contact_label'] ); ?></h2>
|
132 |
+
<div style="height: auto; margin-bottom: 10px; text-align: left">
|
133 |
+
<p class="whlb-support-form"><?php echo wp_kses_post( $support_message ); ?></p>
|
134 |
+
<p class="whlb-support-form">
|
135 |
+
<label for="mainwp_branding_contact_message_subject"><?php esc_html_e( 'Subject:', 'mainwp-child' ); ?></label>
|
136 |
+
<br>
|
137 |
+
<input type="text" id="mainwp_branding_contact_message_subject" name="mainwp_branding_contact_message_subject" style="width: 650px;">
|
138 |
+
</p>
|
139 |
+
<p class="whlb-support-form">
|
140 |
+
<label for="mainwp_branding_contact_send_from"><?php esc_html_e( 'From:', 'mainwp-child' ); ?></label>
|
141 |
+
<br>
|
142 |
+
<input type="text" id="mainwp_branding_contact_send_from" name="mainwp_branding_contact_send_from" style="width: 650px;" value="<?php echo esc_attr( $from_email ); ?>">
|
143 |
+
</p>
|
144 |
+
<div style="max-width: 650px;" class="whlb-support-form">
|
145 |
+
<label for="mainwp_branding_contact_message_content"><?php esc_html_e( 'Your message:', 'mainwp-child' ); ?></label>
|
146 |
+
<br>
|
147 |
+
<?php
|
148 |
+
remove_editor_styles(); // stop custom theme styling interfering with the editor.
|
149 |
+
wp_editor(
|
150 |
+
'',
|
151 |
+
'mainwp_branding_contact_message_content',
|
152 |
+
array(
|
153 |
+
'textarea_name' => 'mainwp_branding_contact_message_content',
|
154 |
+
'textarea_rows' => 10,
|
155 |
+
'teeny' => true,
|
156 |
+
'wpautop' => true,
|
157 |
+
'media_buttons' => false,
|
158 |
+
)
|
159 |
+
);
|
160 |
+
?>
|
161 |
+
</div>
|
162 |
+
</div>
|
163 |
+
<br/>
|
164 |
+
<?php
|
165 |
+
$button_title = $opts['submit_button_title'];
|
166 |
+
$button_title = ! empty( $button_title ) ? $button_title : __( 'Submit', 'mainwp-child' );
|
167 |
+
?>
|
168 |
+
<div class="whlb-support-field">
|
169 |
+
<input id="mainwp-branding-contact-support-submit" type="submit" name="submit" value="<?php echo esc_attr( $button_title ); ?>" class="button-primary button" style="float: left"/>
|
170 |
+
</div>
|
171 |
+
</div>
|
172 |
+
<input type="hidden" name="mainwp_branding_send_from_page" value="<?php echo esc_url( $from_page ); ?>"/>
|
173 |
+
<input type="hidden" name="_wpnonce" value="<?php echo esc_attr( wp_create_nonce( '_contactNonce' ) ); ?>"/>
|
174 |
+
</form>
|
175 |
+
<?php
|
176 |
+
}
|
177 |
+
|
178 |
+
/**
|
179 |
+
* Render contact support submit message.
|
180 |
+
*
|
181 |
+
* @param array $opts An array containg message options.
|
182 |
+
*/
|
183 |
+
private function render_submit_message( $opts ) {
|
184 |
+
$from_page = isset( $_POST['mainwp_branding_send_from_page'] ) ? wp_unslash( $_POST['mainwp_branding_send_from_page'] ) : '';
|
185 |
+
$back_link = $opts['message_return_sender'];
|
186 |
+
$back_link = ! empty( $back_link ) ? $back_link : 'Go Back';
|
187 |
+
$back_link = ! empty( $from_page ) ? '<a href="' . esc_url( $from_page ) . '" title="' . esc_attr( $back_link ) . '">' . esc_html( $back_link ) . '</a>' : '';
|
188 |
+
|
189 |
+
if ( $this->send_support_mail() ) {
|
190 |
+
$send_email_message = isset( $opts['send_email_message'] ) ? $opts['send_email_message'] : '';
|
191 |
+
if ( ! empty( $send_email_message ) ) {
|
192 |
+
$send_email_message = stripslashes( $send_email_message );
|
193 |
+
} else {
|
194 |
+
$send_email_message = __( 'Message has been submitted successfully.', 'mainwp-child' );
|
195 |
+
}
|
196 |
+
} else {
|
197 |
+
$send_email_message = __( 'Sending email failed!', 'mainwp-child' );
|
198 |
+
}
|
199 |
+
?>
|
200 |
+
<div class="mainwp_info-box-yellow"><?php echo esc_html( $send_email_message ) . '  ' . $back_link; ?></div>
|
201 |
+
<?php
|
202 |
+
}
|
203 |
+
|
204 |
+
/**
|
205 |
+
* Send support email.
|
206 |
+
*
|
207 |
+
* @return bool Return TRUE on success FALSE on failure.
|
208 |
+
*
|
209 |
+
* @uses \MainWP\Child\MainWP_Child_Branding::get_branding_options()
|
210 |
+
*/
|
211 |
+
public function send_support_mail() {
|
212 |
+
$opts = MainWP_Child_Branding::instance()->get_branding_options();
|
213 |
+
$email = $opts['support_email'];
|
214 |
+
$sub = isset( $_POST['mainwp_branding_contact_message_subject'] ) ? wp_kses_post( nl2br( stripslashes( wp_unslash( $_POST['mainwp_branding_contact_message_subject'] ) ) ) ) : '';
|
215 |
+
$from = isset( $_POST['mainwp_branding_contact_send_from'] ) ? trim( wp_unslash( $_POST['mainwp_branding_contact_send_from'] ) ) : '';
|
216 |
+
$subject = ! empty( $sub ) ? $sub : 'MainWP - Support Contact';
|
217 |
+
$content = isset( $_POST['mainwp_branding_contact_message_content'] ) ? wp_kses_post( nl2br( stripslashes( wp_unslash( $_POST['mainwp_branding_contact_message_content'] ) ) ) ) : '';
|
218 |
+
$mail = '';
|
219 |
+
$headers = '';
|
220 |
+
|
221 |
+
$from_page = isset( $_POST['mainwp_branding_send_from_page'] ) ? wp_unslash( $_POST['mainwp_branding_send_from_page'] ) : '';
|
222 |
+
|
223 |
+
if ( ! empty( $_POST['mainwp_branding_contact_message_content'] ) && ! empty( $email ) ) {
|
224 |
+
|
225 |
+
/**
|
226 |
+
* Current user global.
|
227 |
+
*
|
228 |
+
* @global string
|
229 |
+
*/
|
230 |
+
global $current_user;
|
231 |
+
|
232 |
+
$headers .= "Content-Type: text/html;charset=utf-8\r\n";
|
233 |
+
if ( ! empty( $from ) ) {
|
234 |
+
$headers .= 'From: "' . $from . '" <' . $from . ">\r\n";
|
235 |
+
}
|
236 |
+
$mail .= "<p>Support Email from: <a href='" . site_url() . "'>" . site_url() . "</a></p>\r\n\r\n";
|
237 |
+
$mail .= '<p>Sent from WordPress page: ' . ( ! empty( $from_page ) ? "<a href='" . esc_url( $from_page ) . "'>" . esc_url( $from_page ) . "</a></p>\r\n\r\n" : '' );
|
238 |
+
$mail .= '<p>Client Email: ' . $current_user->user_email . " </p>\r\n\r\n";
|
239 |
+
$mail .= "<p>Support Text:</p>\r\n\r\n";
|
240 |
+
$mail .= '<p>' . $content . "</p>\r\n\r\n";
|
241 |
+
|
242 |
+
wp_mail( $email, $subject, $mail, $headers );
|
243 |
+
|
244 |
+
return true;
|
245 |
+
}
|
246 |
+
return false;
|
247 |
+
}
|
248 |
+
|
249 |
+
/**
|
250 |
+
* After admin bar render.
|
251 |
+
*/
|
252 |
+
public function after_admin_bar_render() {
|
253 |
+
$hide_slugs = apply_filters( 'mainwp_child_hide_update_notice', array() );
|
254 |
+
|
255 |
+
if ( ! is_array( $hide_slugs ) ) {
|
256 |
+
$hide_slugs = array();
|
257 |
+
}
|
258 |
+
|
259 |
+
if ( 0 == count( $hide_slugs ) ) {
|
260 |
+
return;
|
261 |
+
}
|
262 |
+
|
263 |
+
if ( ! function_exists( '\get_plugin_updates' ) ) {
|
264 |
+
include_once ABSPATH . '/wp-admin/includes/update.php';
|
265 |
+
}
|
266 |
+
|
267 |
+
$count_hide = 0;
|
268 |
+
|
269 |
+
$updates = get_plugin_updates();
|
270 |
+
if ( is_array( $updates ) ) {
|
271 |
+
foreach ( $updates as $slug => $data ) {
|
272 |
+
if ( in_array( $slug, $hide_slugs ) ) {
|
273 |
+
$count_hide++;
|
274 |
+
}
|
275 |
+
}
|
276 |
+
}
|
277 |
+
|
278 |
+
if ( 0 == $count_hide ) {
|
279 |
+
return;
|
280 |
+
}
|
281 |
+
?>
|
282 |
+
<script type="text/javascript">
|
283 |
+
var mainwpCountHide = <?php echo esc_attr( $count_hide ); ?>;
|
284 |
+
document.addEventListener( "DOMContentLoaded", function( event ) {
|
285 |
+
var $adminBarUpdates = document.querySelector( '#wp-admin-bar-updates .ab-label' ),
|
286 |
+
itemCount;
|
287 |
+
|
288 |
+
if ( typeof( $adminBarUpdates ) !== 'undefined' && $adminBarUpdates !== null ) {
|
289 |
+
itemCount = $adminBarUpdates.textContent;
|
290 |
+
itemCount = parseInt( itemCount );
|
291 |
+
|
292 |
+
itemCount -= mainwpCountHide;
|
293 |
+
if ( itemCount < 0 )
|
294 |
+
itemCount = 0;
|
295 |
+
|
296 |
+
$adminBarUpdates.textContent = itemCount;
|
297 |
+
}
|
298 |
+
} );
|
299 |
+
</script>
|
300 |
+
<?php
|
301 |
+
}
|
302 |
+
|
303 |
+
/**
|
304 |
+
* Admin footer text.
|
305 |
+
*/
|
306 |
+
public function in_admin_footer() {
|
307 |
+
$hide_slugs = apply_filters( 'mainwp_child_hide_update_notice', array() );
|
308 |
+
|
309 |
+
if ( ! is_array( $hide_slugs ) ) {
|
310 |
+
$hide_slugs = array();
|
311 |
+
}
|
312 |
+
|
313 |
+
$count_hide = 0;
|
314 |
+
|
315 |
+
$updates = get_plugin_updates();
|
316 |
+
if ( is_array( $updates ) ) {
|
317 |
+
foreach ( $updates as $slug => $data ) {
|
318 |
+
if ( in_array( $slug, $hide_slugs ) ) {
|
319 |
+
$count_hide++;
|
320 |
+
}
|
321 |
+
}
|
322 |
+
}
|
323 |
+
|
324 |
+
if ( 0 == $count_hide ) {
|
325 |
+
return;
|
326 |
+
}
|
327 |
+
|
328 |
+
?>
|
329 |
+
<script type="text/javascript">
|
330 |
+
var mainwpCountHide = <?php echo esc_attr( $count_hide ); ?>;
|
331 |
+
document.addEventListener( "DOMContentLoaded", function( event ) {
|
332 |
+
if ( typeof( pagenow ) !== 'undefined' && pagenow == 'plugins' ) {
|
333 |
+
<?php
|
334 |
+
// hide update notice row.
|
335 |
+
if ( in_array( 'mainwp-child/mainwp-child.php', $hide_slugs ) ) {
|
336 |
+
?>
|
337 |
+
var el = document.querySelector( 'tr#mainwp-child-update' );
|
338 |
+
if ( typeof( el ) !== 'undefined' && el !== null ) {
|
339 |
+
el.style.display = 'none';
|
340 |
+
}
|
341 |
+
<?php
|
342 |
+
}
|
343 |
+
// hide update notice row.
|
344 |
+
if ( in_array( 'mainwp-child-reports/mainwp-child-reports.php', $hide_slugs ) ) {
|
345 |
+
?>
|
346 |
+
var el = document.querySelector( 'tr#mainwp-child-reports-update' );
|
347 |
+
if ( typeof( el ) !== 'undefined' && el !== null ) {
|
348 |
+
el.style.display = 'none';
|
349 |
+
}
|
350 |
+
<?php
|
351 |
+
}
|
352 |
+
?>
|
353 |
+
}
|
354 |
+
|
355 |
+
if ( mainwpCountHide > 0 ) {
|
356 |
+
jQuery( document ).ready( function () {
|
357 |
+
|
358 |
+
var $adminBarUpdates = jQuery( '#wp-admin-bar-updates' ),
|
359 |
+
$pluginsNavMenuUpdateCount = jQuery( 'a[href="plugins.php"] .update-plugins' ),
|
360 |
+
itemCount;
|
361 |
+
itemCount = $adminBarUpdates.find( '.ab-label' ).text();
|
362 |
+
itemCount -= mainwpCountHide;
|
363 |
+
if ( itemCount < 0 )
|
364 |
+
itemCount = 0;
|
365 |
+
|
366 |
+
itemPCount = $pluginsNavMenuUpdateCount.find( '.plugin-count' ).text();
|
367 |
+
itemPCount -= mainwpCountHide;
|
368 |
+
|
369 |
+
if ( itemPCount < 0 )
|
370 |
+
itemPCount = 0;
|
371 |
+
|
372 |
+
$adminBarUpdates.find( '.ab-label' ).text( itemCount );
|
373 |
+
$pluginsNavMenuUpdateCount.find( '.plugin-count' ).text( itemPCount );
|
374 |
+
|
375 |
+
} );
|
376 |
+
}
|
377 |
+
} );
|
378 |
+
</script>
|
379 |
+
<?php
|
380 |
+
}
|
381 |
+
|
382 |
+
}
|
class/class-mainwp-child-branding.php
CHANGED
@@ -467,7 +467,7 @@ class MainWP_Child_Branding {
|
|
467 |
|
468 |
add_filter( 'map_meta_cap', array( $this, 'branding_map_meta_cap' ), 10, 5 );
|
469 |
|
470 |
-
if ( 'T' === $opts['disable_change'] ) {
|
471 |
|
472 |
// Disable the WordPress plugin update notifications.
|
473 |
remove_action( 'load-update-core.php', 'wp_update_plugins' );
|
467 |
|
468 |
add_filter( 'map_meta_cap', array( $this, 'branding_map_meta_cap' ), 10, 5 );
|
469 |
|
470 |
+
if ( 'T' === $opts['disable_change'] && ! isset( $_POST['mainwpsignature'] ) ) {
|
471 |
|
472 |
// Disable the WordPress plugin update notifications.
|
473 |
remove_action( 'load-update-core.php', 'wp_update_plugins' );
|
class/class-mainwp-child-callable.php
CHANGED
@@ -1,1011 +1,1011 @@
|
|
1 |
-
<?php
|
2 |
-
/**
|
3 |
-
* MainWP Callable Functions
|
4 |
-
*
|
5 |
-
* Manage functions that can be executed on the child site.
|
6 |
-
*
|
7 |
-
* @package MainWP\Child
|
8 |
-
*/
|
9 |
-
|
10 |
-
namespace MainWP\Child;
|
11 |
-
|
12 |
-
// phpcs:disable WordPress.WP.AlternativeFunctions -- to use external code, third party credit.
|
13 |
-
|
14 |
-
/**
|
15 |
-
* Class MainWP_Child_Callable
|
16 |
-
*
|
17 |
-
* Manage functions that can be executed on the child site.
|
18 |
-
*/
|
19 |
-
class MainWP_Child_Callable {
|
20 |
-
|
21 |
-
/**
|
22 |
-
* Public static variable to hold the single instance of the class.
|
23 |
-
*
|
24 |
-
* @var mixed Default null
|
25 |
-
*/
|
26 |
-
protected static $instance = null;
|
27 |
-
|
28 |
-
/**
|
29 |
-
* Private variable to hold the array of all callable functions.
|
30 |
-
*
|
31 |
-
* @var array Callable functions.
|
32 |
-
*/
|
33 |
-
private $callableFunctions = array(
|
34 |
-
'stats' => 'get_site_stats',
|
35 |
-
'upgrade' => 'upgrade_wp',
|
36 |
-
'newpost' => 'new_post',
|
37 |
-
'deactivate' => 'deactivate',
|
38 |
-
'newuser' => 'new_user',
|
39 |
-
'newadminpassword' => 'new_admin_password',
|
40 |
-
'installplugintheme' => 'install_plugin_theme',
|
41 |
-
'upgradeplugintheme' => 'upgrade_plugin_theme',
|
42 |
-
'upgradetranslation' => 'upgrade_translation',
|
43 |
-
'backup' => 'backup',
|
44 |
-
'backup_checkpid' => 'backup_checkpid',
|
45 |
-
'cloneinfo' => 'cloneinfo',
|
46 |
-
'security' => 'get_security_stats',
|
47 |
-
'securityFix' => 'do_security_fix',
|
48 |
-
'securityUnFix' => 'do_security_un_fix',
|
49 |
-
'post_action' => 'post_action',
|
50 |
-
'get_all_posts' => 'get_all_posts',
|
51 |
-
'comment_action' => 'comment_action',
|
52 |
-
'comment_bulk_action' => 'comment_bulk_action',
|
53 |
-
'get_all_comments' => 'get_all_comments',
|
54 |
-
'get_all_themes' => 'get_all_themes',
|
55 |
-
'theme_action' => 'theme_action',
|
56 |
-
'get_all_plugins' => 'get_all_plugins',
|
57 |
-
'plugin_action' => 'plugin_action',
|
58 |
-
'get_all_pages' => 'get_all_pages',
|
59 |
-
'get_all_users' => 'get_all_users',
|
60 |
-
'user_action' => 'user_action',
|
61 |
-
'search_users' => 'search_users',
|
62 |
-
'maintenance_site' => 'maintenance_site',
|
63 |
-
'branding_child_plugin' => 'branding_child_plugin',
|
64 |
-
'code_snippet' => 'code_snippet',
|
65 |
-
'uploader_action' => 'uploader_action',
|
66 |
-
'wordpress_seo' => 'wordpress_seo',
|
67 |
-
'client_report' => 'client_report',
|
68 |
-
'createBackupPoll' => 'backup_poll',
|
69 |
-
'page_speed' => 'page_speed',
|
70 |
-
'woo_com_status' => 'woo_com_status',
|
71 |
-
'links_checker' => 'links_checker',
|
72 |
-
'wordfence' => 'wordfence',
|
73 |
-
'delete_backup' => 'delete_backup',
|
74 |
-
'update_values' => 'update_child_values',
|
75 |
-
'ithemes' => 'ithemes',
|
76 |
-
'updraftplus' => 'updraftplus',
|
77 |
-
'backup_wp' => 'backup_wp',
|
78 |
-
'backwpup' => 'backwpup',
|
79 |
-
'wp_rocket' => 'wp_rocket',
|
80 |
-
'settings_tools' => 'settings_tools',
|
81 |
-
'skeleton_key' => 'bulk_settings_manager', // deprecated.
|
82 |
-
'bulk_settings_manager' => 'bulk_settings_manager',
|
83 |
-
'custom_post_type' => 'custom_post_type',
|
84 |
-
'backup_buddy' => 'backup_buddy',
|
85 |
-
'get_site_icon' => 'get_site_icon',
|
86 |
-
'vulner_checker' => 'vulner_checker',
|
87 |
-
'wp_staging' => 'wp_staging',
|
88 |
-
'disconnect' => 'disconnect',
|
89 |
-
'time_capsule' => 'time_capsule',
|
90 |
-
'extra_excution' => 'extra_execution', // deprecated!
|
91 |
-
'extra_execution' => 'extra_execution',
|
92 |
-
'wpvivid_backuprestore' => 'wpvivid_backuprestore',
|
93 |
-
'check_abandoned' => 'check_abandoned',
|
94 |
-
);
|
95 |
-
|
96 |
-
/**
|
97 |
-
* Private variable to hold the array of all callable functions that don't require regularl authentication.
|
98 |
-
*
|
99 |
-
* @var array Callable functions.
|
100 |
-
*/
|
101 |
-
private $callableFunctionsNoAuth = array(
|
102 |
-
'stats' => 'get_site_stats_no_auth',
|
103 |
-
);
|
104 |
-
|
105 |
-
/**
|
106 |
-
* Method get_class_name()
|
107 |
-
*
|
108 |
-
* Get class name.
|
109 |
-
*
|
110 |
-
* @return string __CLASS__ Class name.
|
111 |
-
*/
|
112 |
-
public static function get_class_name() {
|
113 |
-
return __CLASS__;
|
114 |
-
}
|
115 |
-
|
116 |
-
/**
|
117 |
-
* MainWP_Child_Callable constructor.
|
118 |
-
*
|
119 |
-
* Run any time class is called.
|
120 |
-
*/
|
121 |
-
public function __construct() {
|
122 |
-
}
|
123 |
-
|
124 |
-
/**
|
125 |
-
* Method instance()
|
126 |
-
*
|
127 |
-
* Create a public static instance.
|
128 |
-
*
|
129 |
-
* @return mixed Class instance.
|
130 |
-
*/
|
131 |
-
public static function get_instance() {
|
132 |
-
if ( null === self::$instance ) {
|
133 |
-
self::$instance = new self();
|
134 |
-
}
|
135 |
-
return self::$instance;
|
136 |
-
}
|
137 |
-
|
138 |
-
/**
|
139 |
-
* Method init_call_functions()
|
140 |
-
*
|
141 |
-
* Initiate callable functions.
|
142 |
-
*
|
143 |
-
* @param bool $auth If true, regular authentication is required.
|
144 |
-
*
|
145 |
-
* @uses \MainWP\Child\MainWP_Helper::instance()->error()
|
146 |
-
* @uses \MainWP\Child\MainWP_Utility::handle_fatal_error()
|
147 |
-
* @uses \MainWP\Child\MainWP_Utility::fix_for_custom_themes()
|
148 |
-
*/
|
149 |
-
public function init_call_functions( $auth = false ) {
|
150 |
-
$callable = false;
|
151 |
-
$callable_no_auth = false;
|
152 |
-
$call_func = false;
|
153 |
-
|
154 |
-
// check if function is callable.
|
155 |
-
if ( isset( $_POST['function'] ) ) {
|
156 |
-
$call_func = isset( $_POST['function'] ) ? sanitize_text_field( wp_unslash( $_POST['function'] ) ) : '';
|
157 |
-
$callable = $this->is_callable_function( $call_func ); // check callable func.
|
158 |
-
$callable_no_auth = $this->is_callable_function_no_auth( $call_func ); // check callable no auth func.
|
159 |
-
}
|
160 |
-
|
161 |
-
// Fire off the called function.
|
162 |
-
if ( $auth && isset( $_POST['function'] ) && $callable ) {
|
163 |
-
|
164 |
-
/**
|
165 |
-
* Checks whether cron is in progress.
|
166 |
-
*
|
167 |
-
* @const ( bool ) Default: true
|
168 |
-
* @source https://code-reference.mainwp.com/classes/MainWP.Child.MainWP_Child_Callable.html
|
169 |
-
*/
|
170 |
-
define( 'DOING_CRON', true );
|
171 |
-
|
172 |
-
MainWP_Utility::handle_fatal_error();
|
173 |
-
MainWP_Utility::fix_for_custom_themes();
|
174 |
-
$this->call_function( $call_func );
|
175 |
-
} elseif ( isset( $_POST['function'] ) && $callable_no_auth ) {
|
176 |
-
|
177 |
-
/**
|
178 |
-
* Checks whether cron is in progress.
|
179 |
-
*
|
180 |
-
* @const ( bool ) Default: true
|
181 |
-
* @source https://code-reference.mainwp.com/classes/MainWP.Child.MainWP_Child_Callable.html
|
182 |
-
*/
|
183 |
-
define( 'DOING_CRON', true );
|
184 |
-
|
185 |
-
MainWP_Utility::fix_for_custom_themes();
|
186 |
-
$this->call_function_no_auth( $call_func );
|
187 |
-
} elseif ( isset( $_POST['function'] ) && isset( $_POST['mainwpsignature'] ) && ! $callable && ! $callable_no_auth ) {
|
188 |
-
MainWP_Helper::instance()->error( __( 'Required version has not been detected. Please, make sure that you are using the latest version of the MainWP Child plugin on your site.', 'mainwp-child' ) );
|
189 |
-
}
|
190 |
-
}
|
191 |
-
|
192 |
-
/**
|
193 |
-
* Method is_callable_function()
|
194 |
-
*
|
195 |
-
* Check if the function is the list of callable functions.
|
196 |
-
*
|
197 |
-
* @param string $func Contains the name of the function to check.
|
198 |
-
*
|
199 |
-
* @return bool If callable, return true, if not, return false.
|
200 |
-
*/
|
201 |
-
public function is_callable_function( $func ) {
|
202 |
-
if ( isset( $this->callableFunctions[ $func ] ) ) {
|
203 |
-
return true;
|
204 |
-
}
|
205 |
-
return false;
|
206 |
-
}
|
207 |
-
|
208 |
-
/**
|
209 |
-
* Method is_callable_function_no_auth()
|
210 |
-
*
|
211 |
-
* Check if the function is the list of callable functions that don't require regular authentication.
|
212 |
-
*
|
213 |
-
* @param string $func Contains the name of the function to check.
|
214 |
-
*
|
215 |
-
* @return bool If callable, return true, if not, return false.
|
216 |
-
*/
|
217 |
-
public function is_callable_function_no_auth( $func ) {
|
218 |
-
if ( isset( $this->callableFunctionsNoAuth[ $func ] ) ) {
|
219 |
-
return true;
|
220 |
-
}
|
221 |
-
return false;
|
222 |
-
}
|
223 |
-
|
224 |
-
/**
|
225 |
-
* Method call_function()
|
226 |
-
*
|
227 |
-
* Call ceratin function.
|
228 |
-
*
|
229 |
-
* @param string $func Contains the name of the function to call.
|
230 |
-
*/
|
231 |
-
public function call_function( $func ) {
|
232 |
-
if ( $this->is_callable_function( $func ) ) {
|
233 |
-
call_user_func( array( $this, $this->callableFunctions[ $func ] ) );
|
234 |
-
}
|
235 |
-
}
|
236 |
-
|
237 |
-
/**
|
238 |
-
* Method call_function_no_auth()
|
239 |
-
*
|
240 |
-
* Call ceratin function without regular authentication if the function is in the $callableFunctionsNoAuth list.
|
241 |
-
*
|
242 |
-
* @param string $func Contains the name of the function to call.
|
243 |
-
*/
|
244 |
-
public function call_function_no_auth( $func ) {
|
245 |
-
if ( $this->is_callable_function_no_auth( $func ) ) {
|
246 |
-
call_user_func( array( $this, $this->callableFunctionsNoAuth[ $func ] ) );
|
247 |
-
}
|
248 |
-
}
|
249 |
-
|
250 |
-
/**
|
251 |
-
* Method get_site_stats()
|
252 |
-
*
|
253 |
-
* Fire off the get_site_stats() function.
|
254 |
-
*
|
255 |
-
* @uses \MainWP\Child\MainWP_Child_Stats::get_site_stats()
|
256 |
-
*/
|
257 |
-
public function get_site_stats() {
|
258 |
-
MainWP_Child_Stats::get_instance()->get_site_stats();
|
259 |
-
}
|
260 |
-
|
261 |
-
/**
|
262 |
-
* Method get_site_stats_no_auth()
|
263 |
-
*
|
264 |
-
* Fire off the get_site_stats_no_auth() function.
|
265 |
-
*
|
266 |
-
* @uses \MainWP\Child\MainWP_Child_Stats::get_site_stats_no_auth()
|
267 |
-
*/
|
268 |
-
public function get_site_stats_no_auth() {
|
269 |
-
MainWP_Child_Stats::get_instance()->get_site_stats_no_auth();
|
270 |
-
}
|
271 |
-
|
272 |
-
/**
|
273 |
-
* Method install_plugin_theme()
|
274 |
-
*
|
275 |
-
* Fire off the install_plugin_theme() function.
|
276 |
-
*
|
277 |
-
* @uses \MainWP\Child\MainWP_Child_Install::install_plugin_theme()
|
278 |
-
*/
|
279 |
-
public function install_plugin_theme() {
|
280 |
-
MainWP_Child_Install::get_instance()->install_plugin_theme();
|
281 |
-
}
|
282 |
-
|
283 |
-
/**
|
284 |
-
* Method upgrade_wp()
|
285 |
-
*
|
286 |
-
* Fire off the upgrade_wp() function.
|
287 |
-
*
|
288 |
-
* @uses \MainWP\Child\MainWP_Child_Updates::upgrade_wp()
|
289 |
-
*/
|
290 |
-
public function upgrade_wp() {
|
291 |
-
MainWP_Child_Updates::get_instance()->upgrade_wp();
|
292 |
-
}
|
293 |
-
|
294 |
-
/**
|
295 |
-
* Method upgrade_translation()
|
296 |
-
*
|
297 |
-
* Fire off the upgrade_translation() function.
|
298 |
-
*
|
299 |
-
* @uses \MainWP\Child\MainWP_Child_Updates::upgrade_translation()
|
300 |
-
*/
|
301 |
-
public function upgrade_translation() {
|
302 |
-
MainWP_Child_Updates::get_instance()->upgrade_translation();
|
303 |
-
}
|
304 |
-
|
305 |
-
/**
|
306 |
-
* Method upgrade_plugin_theme()
|
307 |
-
*
|
308 |
-
* Fire off the upgrade_plugin_theme() function.
|
309 |
-
*
|
310 |
-
* @uses \MainWP\Child\MainWP_Child_Updates::upgrade_plugin_theme()
|
311 |
-
*/
|
312 |
-
public function upgrade_plugin_theme() {
|
313 |
-
MainWP_Child_Updates::get_instance()->upgrade_plugin_theme();
|
314 |
-
}
|
315 |
-
|
316 |
-
/**
|
317 |
-
* Method theme_action()
|
318 |
-
*
|
319 |
-
* Fire off the theme_action() function.
|
320 |
-
*
|
321 |
-
* @uses \MainWP\Child\MainWP_Child_Install::theme_action()
|
322 |
-
*/
|
323 |
-
public function theme_action() {
|
324 |
-
MainWP_Child_Install::get_instance()->theme_action();
|
325 |
-
}
|
326 |
-
|
327 |
-
/**
|
328 |
-
* Method plugin_action()
|
329 |
-
*
|
330 |
-
* Fire off the plugin_action() function.
|
331 |
-
*
|
332 |
-
* @uses \MainWP\Child\MainWP_Child_Install::plugin_action()
|
333 |
-
*/
|
334 |
-
public function plugin_action() {
|
335 |
-
MainWP_Child_Install::get_instance()->plugin_action();
|
336 |
-
}
|
337 |
-
|
338 |
-
/**
|
339 |
-
* Method get_all_plugins()
|
340 |
-
*
|
341 |
-
* Fire off the get_all_plugins() function.
|
342 |
-
*
|
343 |
-
* @uses \MainWP\Child\MainWP_Child_Stats::get_all_plugins()
|
344 |
-
*/
|
345 |
-
public function get_all_plugins() {
|
346 |
-
MainWP_Child_Stats::get_instance()->get_all_plugins();
|
347 |
-
}
|
348 |
-
|
349 |
-
/**
|
350 |
-
* Method get_all_themes()
|
351 |
-
*
|
352 |
-
* Fire off the get_all_themes() function.
|
353 |
-
*
|
354 |
-
* @uses \MainWP\Child\MainWP_Child_Stats::get_all_themes()
|
355 |
-
*/
|
356 |
-
public function get_all_themes() {
|
357 |
-
MainWP_Child_Stats::get_instance()->get_all_themes();
|
358 |
-
}
|
359 |
-
|
360 |
-
/**
|
361 |
-
* Method get_all_users()
|
362 |
-
*
|
363 |
-
* Fire off the get_all_users() function.
|
364 |
-
*
|
365 |
-
* @uses \MainWP\Child\MainWP_Child_Users::get_all_users()
|
366 |
-
*/
|
367 |
-
public function get_all_users() {
|
368 |
-
MainWP_Child_Users::get_instance()->get_all_users();
|
369 |
-
}
|
370 |
-
|
371 |
-
/**
|
372 |
-
* Method user_action()
|
373 |
-
*
|
374 |
-
* Fire off the user_action() function.
|
375 |
-
*
|
376 |
-
* @uses \MainWP\Child\MainWP_Child_Users::user_action()
|
377 |
-
*/
|
378 |
-
public function user_action() {
|
379 |
-
MainWP_Child_Users::get_instance()->user_action();
|
380 |
-
}
|
381 |
-
|
382 |
-
/**
|
383 |
-
* Method search_users()
|
384 |
-
*
|
385 |
-
* Fire off the search_users() function.
|
386 |
-
*
|
387 |
-
* @uses \MainWP\Child\MainWP_Child_Users::search_users()
|
388 |
-
*/
|
389 |
-
public function search_users() {
|
390 |
-
MainWP_Child_Users::get_instance()->search_users();
|
391 |
-
}
|
392 |
-
|
393 |
-
/**
|
394 |
-
* Method get_all_posts()
|
395 |
-
*
|
396 |
-
* Fire off the get_all_posts() function.
|
397 |
-
*
|
398 |
-
* @uses \MainWP\Child\MainWP_Child_Posts::get_all_posts()
|
399 |
-
*/
|
400 |
-
public function get_all_posts() {
|
401 |
-
MainWP_Child_Posts::get_instance()->get_all_posts();
|
402 |
-
}
|
403 |
-
|
404 |
-
/**
|
405 |
-
* Method get_all_pages()
|
406 |
-
*
|
407 |
-
* Fire off the get_all_pages() function.
|
408 |
-
*
|
409 |
-
* @uses \MainWP\Child\MainWP_Child_Posts::get_all_pages()
|
410 |
-
*/
|
411 |
-
public function get_all_pages() {
|
412 |
-
MainWP_Child_Posts::get_instance()->get_all_pages();
|
413 |
-
}
|
414 |
-
|
415 |
-
/**
|
416 |
-
* Method comment_action()
|
417 |
-
*
|
418 |
-
* Fire off the comment_action() function.
|
419 |
-
*
|
420 |
-
* @uses \MainWP\Child\MainWP_Child_Comments::comment_action()
|
421 |
-
*/
|
422 |
-
public function comment_action() {
|
423 |
-
MainWP_Child_Comments::get_instance()->comment_action();
|
424 |
-
}
|
425 |
-
|
426 |
-
/**
|
427 |
-
* Method get_all_comments()
|
428 |
-
*
|
429 |
-
* Fire off the get_all_comments() function.
|
430 |
-
*
|
431 |
-
* @uses \MainWP\Child\MainWP_Child_Comments::get_all_comments()
|
432 |
-
*/
|
433 |
-
public function get_all_comments() {
|
434 |
-
MainWP_Child_Comments::get_instance()->get_all_comments();
|
435 |
-
}
|
436 |
-
|
437 |
-
/**
|
438 |
-
* Method comment_bulk_action()
|
439 |
-
*
|
440 |
-
* Fire off the comment_bulk_action() function.
|
441 |
-
*
|
442 |
-
* @uses \MainWP\Child\MainWP_Child_Comments::comment_bulk_action()
|
443 |
-
*/
|
444 |
-
public function comment_bulk_action() {
|
445 |
-
MainWP_Child_Comments::get_instance()->comment_bulk_action();
|
446 |
-
}
|
447 |
-
|
448 |
-
/**
|
449 |
-
* Method maintenance_site()
|
450 |
-
*
|
451 |
-
* Fire off the maintenance_site() function.
|
452 |
-
*
|
453 |
-
* @uses \MainWP\Child\MainWP_Child_Maintenance::maintenance_site()
|
454 |
-
*/
|
455 |
-
public function maintenance_site() {
|
456 |
-
MainWP_Child_Maintenance::get_instance()->maintenance_site();
|
457 |
-
}
|
458 |
-
|
459 |
-
/**
|
460 |
-
* Method new_post()
|
461 |
-
*
|
462 |
-
* Fire off the new_post() function.
|
463 |
-
*
|
464 |
-
* @uses \MainWP\Child\MainWP_Child_Posts::new_post()
|
465 |
-
*/
|
466 |
-
public function new_post() {
|
467 |
-
MainWP_Child_Posts::get_instance()->new_post();
|
468 |
-
}
|
469 |
-
|
470 |
-
/**
|
471 |
-
* Method post_action()
|
472 |
-
*
|
473 |
-
* Fire off the post_action() function.
|
474 |
-
*
|
475 |
-
* @uses \MainWP\Child\MainWP_Child_Posts::post_action()
|
476 |
-
*/
|
477 |
-
public function post_action() {
|
478 |
-
MainWP_Child_Posts::get_instance()->post_action();
|
479 |
-
}
|
480 |
-
|
481 |
-
/**
|
482 |
-
* Method new_admin_password()
|
483 |
-
*
|
484 |
-
* Fire off the new_admin_password() function.
|
485 |
-
*
|
486 |
-
* @uses \MainWP\Child\MainWP_Child_Users::new_admin_password()
|
487 |
-
*/
|
488 |
-
public function new_admin_password() {
|
489 |
-
MainWP_Child_Users::get_instance()->new_admin_password();
|
490 |
-
}
|
491 |
-
|
492 |
-
/**
|
493 |
-
* Method new_user()
|
494 |
-
*
|
495 |
-
* Fire off the new_user() function.
|
496 |
-
*
|
497 |
-
* @uses \MainWP\Child\MainWP_Child_Users::new_user()
|
498 |
-
*/
|
499 |
-
public function new_user() {
|
500 |
-
MainWP_Child_Users::get_instance()->new_user();
|
501 |
-
}
|
502 |
-
|
503 |
-
/**
|
504 |
-
* Method cloneinfo()
|
505 |
-
*
|
506 |
-
* Fire off the cloneinfo() function.
|
507 |
-
*
|
508 |
-
* @uses \MainWP\Child\MainWP_Helper::write()
|
509 |
-
*/
|
510 |
-
public function cloneinfo() {
|
511 |
-
|
512 |
-
/**
|
513 |
-
* WordPress DB Table Prefix.
|
514 |
-
*
|
515 |
-
* @global string
|
516 |
-
*/
|
517 |
-
global $table_prefix;
|
518 |
-
|
519 |
-
$information['dbCharset'] = DB_CHARSET;
|
520 |
-
$information['dbCollate'] = DB_COLLATE;
|
521 |
-
$information['table_prefix'] = $table_prefix;
|
522 |
-
$information['site_url'] = get_option( 'site_url' );
|
523 |
-
$information['home'] = get_option( 'home' );
|
524 |
-
|
525 |
-
MainWP_Helper::write( $information );
|
526 |
-
}
|
527 |
-
|
528 |
-
/**
|
529 |
-
* Method backup_poll()
|
530 |
-
*
|
531 |
-
* Fire off the backup_poll() function.
|
532 |
-
*
|
533 |
-
* @uses \MainWP\Child\MainWP_Backup::backup_poll()
|
534 |
-
*/
|
535 |
-
public function backup_poll() {
|
536 |
-
MainWP_Backup::get()->backup_poll();
|
537 |
-
}
|
538 |
-
|
539 |
-
/**
|
540 |
-
* Method backup_checkpid()
|
541 |
-
*
|
542 |
-
* Fire off the backup_checkpid() function.
|
543 |
-
*
|
544 |
-
* @uses \MainWP\Child\MainWP_Backup::backup_checkpid()
|
545 |
-
*/
|
546 |
-
public function backup_checkpid() {
|
547 |
-
MainWP_Backup::get()->backup_checkpid();
|
548 |
-
}
|
549 |
-
|
550 |
-
/**
|
551 |
-
* Method backup()
|
552 |
-
*
|
553 |
-
* Fire off the backup() function.
|
554 |
-
*
|
555 |
-
* @param bool $write Whether or not to execute MainWP_Helper::write(), Default: true.
|
556 |
-
*
|
557 |
-
* @return array Action result.
|
558 |
-
*
|
559 |
-
* @uses \MainWP\Child\MainWP_Backup::backup()
|
560 |
-
*/
|
561 |
-
public function backup( $write = true ) {
|
562 |
-
return MainWP_Backup::get()->backup( $write );
|
563 |
-
}
|
564 |
-
|
565 |
-
/**
|
566 |
-
* Method backup_full()
|
567 |
-
*
|
568 |
-
* Fire off the backup_full() function.
|
569 |
-
*
|
570 |
-
* @param string $file_name Contains the backup file name.
|
571 |
-
*
|
572 |
-
* @return array Action result.
|
573 |
-
*
|
574 |
-
* @uses \MainWP\Child\MainWP_Backup::backup_full()
|
575 |
-
*/
|
576 |
-
protected function backup_full( $file_name ) {
|
577 |
-
return MainWP_Backup::get()->backup_full( $file_name );
|
578 |
-
}
|
579 |
-
|
580 |
-
/**
|
581 |
-
* Method backup_db()
|
582 |
-
*
|
583 |
-
* Fire off the backup_db() function.
|
584 |
-
*
|
585 |
-
* @param string $file_name Contains the backup file name.
|
586 |
-
* @param string $file_extension Contains the backup file extension.
|
587 |
-
*
|
588 |
-
* @return array Action result.
|
589 |
-
*
|
590 |
-
* @uses \MainWP\Child\MainWP_Backup::backup_db()
|
591 |
-
*/
|
592 |
-
protected function backup_db( $file_name = '', $file_extension = 'zip' ) {
|
593 |
-
return MainWP_Backup::get()->backup_db( $file_name, $file_extension );
|
594 |
-
}
|
595 |
-
|
596 |
-
/**
|
597 |
-
* Method get_site_icon()
|
598 |
-
*
|
599 |
-
* Fire off the get_site_icon() function.
|
600 |
-
*
|
601 |
-
* @uses \MainWP\Child\MainWP_Child_Misc::get_site_icon()
|
602 |
-
*/
|
603 |
-
public function get_site_icon() {
|
604 |
-
MainWP_Child_Misc::get_instance()->get_site_icon();
|
605 |
-
}
|
606 |
-
|
607 |
-
/**
|
608 |
-
* Method check_abandoned()
|
609 |
-
*
|
610 |
-
* Fire off the check_abandoned() function.
|
611 |
-
*/
|
612 |
-
public function check_abandoned() {
|
613 |
-
$which = sanitize_text_field( wp_unslash( $_POST['which'] ) );
|
614 |
-
$infor = array();
|
615 |
-
if ( 'plugin' == $which ) {
|
616 |
-
MainWP_Child_Plugins_Check::instance()->run_check();
|
617 |
-
$infor['success'] = 1;
|
618 |
-
} else {
|
619 |
-
MainWP_Child_Themes_Check::instance()->run_check();
|
620 |
-
$infor['success'] = 1;
|
621 |
-
}
|
622 |
-
$infor['sync'] = MainWP_Child_Stats::get_instance()->get_site_stats( array(), false );
|
623 |
-
MainWP_Helper::write( $infor );
|
624 |
-
}
|
625 |
-
|
626 |
-
/**
|
627 |
-
* Method get_security_stats()
|
628 |
-
*
|
629 |
-
* Fire off the get_security_stats() function.
|
630 |
-
*
|
631 |
-
* @uses \MainWP\Child\MainWP_Child_Misc::get_security_stats()
|
632 |
-
*/
|
633 |
-
public function get_security_stats() {
|
634 |
-
MainWP_Child_Misc::get_instance()->get_security_stats();
|
635 |
-
}
|
636 |
-
|
637 |
-
/**
|
638 |
-
* Method do_security_fix()
|
639 |
-
*
|
640 |
-
* Fire off the do_security_fix() function.
|
641 |
-
*
|
642 |
-
* @uses \MainWP\Child\MainWP_Child_Misc::do_security_fix()
|
643 |
-
*/
|
644 |
-
public function do_security_fix() {
|
645 |
-
MainWP_Child_Misc::get_instance()->do_security_fix();
|
646 |
-
}
|
647 |
-
|
648 |
-
/**
|
649 |
-
* Method do_security_un_fix()
|
650 |
-
*
|
651 |
-
* Fire off the do_security_un_fix() function.
|
652 |
-
*
|
653 |
-
* @uses \MainWP\Child\MainWP_Child_Misc::do_security_un_fix()
|
654 |
-
*/
|
655 |
-
public function do_security_un_fix() {
|
656 |
-
MainWP_Child_Misc::get_instance()->do_security_un_fix();
|
657 |
-
}
|
658 |
-
|
659 |
-
/**
|
660 |
-
* Method settings_tools()
|
661 |
-
*
|
662 |
-
* Fire off the settings_tools() function.
|
663 |
-
*
|
664 |
-
* @uses \MainWP\Child\MainWP_Child_Misc::do_security_un_fix()
|
665 |
-
*/
|
666 |
-
public function settings_tools() {
|
667 |
-
MainWP_Child_Misc::get_instance()->do_security_un_fix();
|
668 |
-
}
|
669 |
-
|
670 |
-
/**
|
671 |
-
* Method bulk_settings_manager()
|
672 |
-
*
|
673 |
-
* Fire off the action() function.
|
674 |
-
*
|
675 |
-
* @uses \MainWP\Child\MainWP_Child_Bulk_Settings_Manager::action()
|
676 |
-
*/
|
677 |
-
public function bulk_settings_manager() {
|
678 |
-
MainWP_Child_Bulk_Settings_Manager::instance()->action();
|
679 |
-
}
|
680 |
-
|
681 |
-
/**
|
682 |
-
* Method custom_post_type()
|
683 |
-
*
|
684 |
-
* Fire off the action() function.
|
685 |
-
*
|
686 |
-
* @uses \MainWP\Child\MainWP_Custom_Post_Type::action()
|
687 |
-
*/
|
688 |
-
public function custom_post_type() {
|
689 |
-
MainWP_Custom_Post_Type::instance()->action();
|
690 |
-
}
|
691 |
-
|
692 |
-
/**
|
693 |
-
* Method backup_buddy()
|
694 |
-
*
|
695 |
-
* Fire off the action() function.
|
696 |
-
*
|
697 |
-
* @uses \MainWP\Child\MainWP_Child_Back_Up_Buddy::action()
|
698 |
-
*/
|
699 |
-
public function backup_buddy() {
|
700 |
-
MainWP_Child_Back_Up_Buddy::instance()->action();
|
701 |
-
}
|
702 |
-
|
703 |
-
/**
|
704 |
-
* Method vulner_checker()
|
705 |
-
*
|
706 |
-
* Fire off the action() function.
|
707 |
-
*
|
708 |
-
* @uses \MainWP\Child\MainWP_Child_Vulnerability_Checker::action()
|
709 |
-
*/
|
710 |
-
public function vulner_checker() {
|
711 |
-
MainWP_Child_Vulnerability_Checker::instance()->action();
|
712 |
-
}
|
713 |
-
|
714 |
-
/**
|
715 |
-
* Method time_capsule()
|
716 |
-
*
|
717 |
-
* Fire off the action() function.
|
718 |
-
*
|
719 |
-
* @uses \MainWP\Child\MainWP_Child_Timecapsule::action()
|
720 |
-
*/
|
721 |
-
public function time_capsule() {
|
722 |
-
MainWP_Child_Timecapsule::instance()->action();
|
723 |
-
}
|
724 |
-
|
725 |
-
/**
|
726 |
-
* Method wp_staging()
|
727 |
-
*
|
728 |
-
* Fire off the action() function.
|
729 |
-
*
|
730 |
-
* @uses \MainWP\Child\MainWP_Child_Staging::action()
|
731 |
-
*/
|
732 |
-
public function wp_staging() {
|
733 |
-
MainWP_Child_Staging::instance()->action();
|
734 |
-
}
|
735 |
-
|
736 |
-
/**
|
737 |
-
* Method extra_execution()
|
738 |
-
*
|
739 |
-
* Additional functions to execute.
|
740 |
-
*
|
741 |
-
* @uses \MainWP\Child\MainWP_Helper::write()
|
742 |
-
*/
|
743 |
-
public function extra_execution() {
|
744 |
-
$post = $_POST;
|
745 |
-
$information = array();
|
746 |
-
/**
|
747 |
-
* Filter 'mainwp_child_extra_execution'
|
748 |
-
*
|
749 |
-
* Additional functions to execute through the filter.
|
750 |
-
*
|
751 |
-
* @param array $information An array containing the synchronization information.
|
752 |
-
* @param mixed $post Contains the POST request.
|
753 |
-
*
|
754 |
-
* @since 4.0
|
755 |
-
*/
|
756 |
-
$information = apply_filters( 'mainwp_child_extra_execution', $information, $post );
|
757 |
-
MainWP_Helper::write( $information );
|
758 |
-
}
|
759 |
-
|
760 |
-
/**
|
761 |
-
* Method uploader_action()
|
762 |
-
*
|
763 |
-
* Fire off the uploader_action() function.
|
764 |
-
*
|
765 |
-
* @uses \MainWP\Child\MainWP_Child_Misc::uploader_action()
|
766 |
-
*/
|
767 |
-
public function uploader_action() {
|
768 |
-
MainWP_Child_Misc::get_instance()->uploader_action();
|
769 |
-
}
|
770 |
-
|
771 |
-
/**
|
772 |
-
* Method wordpress_seo()
|
773 |
-
*
|
774 |
-
* Fire off the action() function.
|
775 |
-
*/
|
776 |
-
public function wordpress_seo() {
|
777 |
-
MainWP_WordPress_SEO::instance()->action();
|
778 |
-
}
|
779 |
-
|
780 |
-
/**
|
781 |
-
* Method client_report()
|
782 |
-
*
|
783 |
-
* Fire off the action() function.
|
784 |
-
*
|
785 |
-
* @uses \MainWP\Child\MainWP_Client_Report::action()
|
786 |
-
*/
|
787 |
-
public function client_report() {
|
788 |
-
MainWP_Client_Report::instance()->action();
|
789 |
-
}
|
790 |
-
|
791 |
-
/**
|
792 |
-
* Method page_speed()
|
793 |
-
*
|
794 |
-
* Fire off the action() function.
|
795 |
-
*
|
796 |
-
* @uses \MainWP\Child\MainWP_Child_Pagespeed::action()
|
797 |
-
*/
|
798 |
-
public function page_speed() {
|
799 |
-
MainWP_Child_Pagespeed::instance()->action();
|
800 |
-
}
|
801 |
-
|
802 |
-
/**
|
803 |
-
* Method woo_com_status()
|
804 |
-
*
|
805 |
-
* Fire off the action() function.
|
806 |
-
*
|
807 |
-
* @uses \MainWP\Child\MainWP_Child_WooCommerce_Status::action()
|
808 |
-
*/
|
809 |
-
public function woo_com_status() {
|
810 |
-
MainWP_Child_WooCommerce_Status::instance()->action();
|
811 |
-
}
|
812 |
-
|
813 |
-
/**
|
814 |
-
* Method links_checker()
|
815 |
-
*
|
816 |
-
* Fire off the action() function.
|
817 |
-
*
|
818 |
-
* @uses \MainWP\Child\MainWP_Child_Links_Checker::action()
|
819 |
-
*/
|
820 |
-
public function links_checker() {
|
821 |
-
MainWP_Child_Links_Checker::instance()->action();
|
822 |
-
}
|
823 |
-
|
824 |
-
/**
|
825 |
-
* Method wordfence()
|
826 |
-
*
|
827 |
-
* Fire off the action() function.
|
828 |
-
*
|
829 |
-
* @uses \MainWP\Child\MainWP_Child_Wordfence::action()
|
830 |
-
*/
|
831 |
-
public function wordfence() {
|
832 |
-
MainWP_Child_Wordfence::instance()->action();
|
833 |
-
}
|
834 |
-
|
835 |
-
/**
|
836 |
-
* Method ithemes()
|
837 |
-
*
|
838 |
-
* Fire off the action() function.
|
839 |
-
*
|
840 |
-
* @uses \MainWP\Child\MainWP_Child_IThemes_Security::action()
|
841 |
-
*/
|
842 |
-
public function ithemes() {
|
843 |
-
MainWP_Child_IThemes_Security::instance()->action();
|
844 |
-
}
|
845 |
-
|
846 |
-
/**
|
847 |
-
* Method updraftplus()
|
848 |
-
*
|
849 |
-
* Fire off the action() function.
|
850 |
-
*
|
851 |
-
* @uses \MainWP\Child\MainWP_Child_Updraft_Plus_Backups::action()
|
852 |
-
*/
|
853 |
-
public function updraftplus() {
|
854 |
-
MainWP_Child_Updraft_Plus_Backups::instance()->action();
|
855 |
-
}
|
856 |
-
|
857 |
-
/**
|
858 |
-
* Method wpvivid_backuprestore()
|
859 |
-
*
|
860 |
-
* Fire off the action() function.
|
861 |
-
*
|
862 |
-
* @uses \MainWP\Child\MainWP_Child_WPvivid_BackupRestore::action()
|
863 |
-
*/
|
864 |
-
public function wpvivid_backuprestore() {
|
865 |
-
MainWP_Child_WPvivid_BackupRestore::instance()->action();
|
866 |
-
}
|
867 |
-
|
868 |
-
/**
|
869 |
-
* Method backup_wp()
|
870 |
-
*
|
871 |
-
* Fire off the action() function.
|
872 |
-
*
|
873 |
-
* @uses \MainWP\Child\MainWP_Child_Back_Up_WordPress::action()
|
874 |
-
* @uses \MainWP\Child\MainWP_Helper::write()
|
875 |
-
*/
|
876 |
-
public function backup_wp() {
|
877 |
-
if ( ! version_compare( phpversion(), '5.3', '>=' ) ) {
|
878 |
-
$error = sprintf( __( 'PHP Version %s is unsupported.', 'mainwp-child' ), phpversion() );
|
879 |
-
MainWP_Helper::write( array( 'error' => $error ) );
|
880 |
-
}
|
881 |
-
MainWP_Child_Back_Up_WordPress::instance()->action();
|
882 |
-
}
|
883 |
-
|
884 |
-
/**
|
885 |
-
* Method wp_rocket()
|
886 |
-
*
|
887 |
-
* Fire off the action() function.
|
888 |
-
*
|
889 |
-
* @uses \MainWP\Child\MainWP_Child_WP_Rocket::action()
|
890 |
-
*/
|
891 |
-
public function wp_rocket() {
|
892 |
-
MainWP_Child_WP_Rocket::instance()->action();
|
893 |
-
}
|
894 |
-
|
895 |
-
/**
|
896 |
-
* Method backwpup()
|
897 |
-
*
|
898 |
-
* Fire off the action() function.
|
899 |
-
*
|
900 |
-
* @uses \MainWP\Child\MainWP_Child_Back_WP_Up::action()
|
901 |
-
*/
|
902 |
-
public function backwpup() {
|
903 |
-
MainWP_Child_Back_WP_Up::instance()->action();
|
904 |
-
}
|
905 |
-
|
906 |
-
/**
|
907 |
-
* Method delete_backup()
|
908 |
-
*
|
909 |
-
* Delete backup.
|
910 |
-
*
|
911 |
-
* @uses \MainWP\Child\MainWP_Helper::get_mainwp_dir()
|
912 |
-
* @uses \MainWP\Child\MainWP_Helper::write()
|
913 |
-
*/
|
914 |
-
public function delete_backup() {
|
915 |
-
$dirs = MainWP_Helper::get_mainwp_dir( 'backup' );
|
916 |
-
$backupdir = $dirs[0];
|
917 |
-
|
918 |
-
$file = isset( $_REQUEST['del'] ) ? wp_unslash( $_REQUEST['del'] ) : '';
|
919 |
-
|
920 |
-
if ( file_exists( $backupdir . $file ) ) {
|
921 |
-
unlink( $backupdir . $file );
|
922 |
-
}
|
923 |
-
|
924 |
-
MainWP_Helper::write( array( 'result' => 'ok' ) );
|
925 |
-
}
|
926 |
-
|
927 |
-
/**
|
928 |
-
* Method update_child_values()
|
929 |
-
*
|
930 |
-
* Update the MainWP Child site options.
|
931 |
-
*
|
932 |
-
* @uses \MainWP\Child\MainWP_Helper::update_option()
|
933 |
-
* @uses \MainWP\Child\MainWP_Helper::write()
|
934 |
-
*/
|
935 |
-
public function update_child_values() {
|
936 |
-
$unique_id = isset( $_POST['uniqueId'] ) ? sanitize_text_field( wp_unslash( $_POST['uniqueId'] ) ) : '';
|
937 |
-
MainWP_Helper::update_option( 'mainwp_child_uniqueId', $unique_id );
|
938 |
-
MainWP_Helper::write( array( 'result' => 'ok' ) );
|
939 |
-
}
|
940 |
-
|
941 |
-
/**
|
942 |
-
* Method branding_child_plugin()
|
943 |
-
*
|
944 |
-
* Fire off the action() function.
|
945 |
-
*
|
946 |
-
* @uses \MainWP\Child\MainWP_Child_Branding::action()
|
947 |
-
*/
|
948 |
-
public function branding_child_plugin() {
|
949 |
-
MainWP_Child_Branding::instance()->action();
|
950 |
-
}
|
951 |
-
|
952 |
-
/**
|
953 |
-
* Method code_snippet()
|
954 |
-
*
|
955 |
-
* Fire off the code_snippet() function.
|
956 |
-
*
|
957 |
-
* @uses MainWP_Child_Misc::code_snippet()
|
958 |
-
*/
|
959 |
-
public function code_snippet() {
|
960 |
-
MainWP_Child_Misc::get_instance()->code_snippet();
|
961 |
-
}
|
962 |
-
|
963 |
-
/**
|
964 |
-
* Method disconnect()
|
965 |
-
*
|
966 |
-
* Disconnect the child site from the current MainWP Dashboard.
|
967 |
-
*
|
968 |
-
* @uses \MainWP\Child\MainWP_Helper::write()
|
969 |
-
*/
|
970 |
-
public function disconnect() {
|
971 |
-
|
972 |
-
/**
|
973 |
-
* MainWP Child instance.
|
974 |
-
*
|
975 |
-
* @global object
|
976 |
-
*/
|
977 |
-
global $mainWPChild;
|
978 |
-
|
979 |
-
$mainWPChild->deactivation( false );
|
980 |
-
MainWP_Helper::write( array( 'result' => 'success' ) );
|
981 |
-
}
|
982 |
-
|
983 |
-
|
984 |
-
/**
|
985 |
-
* Method deactivate()
|
986 |
-
*
|
987 |
-
* Deactivate the MainWP Child plugin in the site.
|
988 |
-
*
|
989 |
-
* @uses \MainWP\Child\MainWP_Helper::errpr()
|
990 |
-
* @uses \MainWP\Child\MainWP_Helper::write()
|
991 |
-
*/
|
992 |
-
public function deactivate() {
|
993 |
-
|
994 |
-
/**
|
995 |
-
* MainWP Child instance.
|
996 |
-
*
|
997 |
-
* @global object
|
998 |
-
*/
|
999 |
-
global $mainWPChild;
|
1000 |
-
|
1001 |
-
include_once ABSPATH . 'wp-admin/includes/plugin.php';
|
1002 |
-
deactivate_plugins( $mainWPChild->plugin_slug, true );
|
1003 |
-
$information = array();
|
1004 |
-
if ( is_plugin_active( $mainWPChild->plugin_slug ) ) {
|
1005 |
-
MainWP_Helper::instance()->error( 'Plugin still active' );
|
1006 |
-
}
|
1007 |
-
$information['deactivated'] = true;
|
1008 |
-
MainWP_Helper::write( $information );
|
1009 |
-
}
|
1010 |
-
|
1011 |
-
}
|
1 |
+
<?php
|
2 |
+
/**
|
3 |
+
* MainWP Callable Functions
|
4 |
+
*
|
5 |
+
* Manage functions that can be executed on the child site.
|
6 |
+
*
|
7 |
+
* @package MainWP\Child
|
8 |
+
*/
|
9 |
+
|
10 |
+
namespace MainWP\Child;
|
11 |
+
|
12 |
+
// phpcs:disable WordPress.WP.AlternativeFunctions -- to use external code, third party credit.
|
13 |
+
|
14 |
+
/**
|
15 |
+
* Class MainWP_Child_Callable
|
16 |
+
*
|
17 |
+
* Manage functions that can be executed on the child site.
|
18 |
+
*/
|
19 |
+
class MainWP_Child_Callable {
|
20 |
+
|
21 |
+
/**
|
22 |
+
* Public static variable to hold the single instance of the class.
|
23 |
+
*
|
24 |
+
* @var mixed Default null
|
25 |
+
*/
|
26 |
+
protected static $instance = null;
|
27 |
+
|
28 |
+
/**
|
29 |
+
* Private variable to hold the array of all callable functions.
|
30 |
+
*
|
31 |
+
* @var array Callable functions.
|
32 |
+
*/
|
33 |
+
private $callableFunctions = array(
|
34 |
+
'stats' => 'get_site_stats',
|
35 |
+
'upgrade' => 'upgrade_wp',
|
36 |
+
'newpost' => 'new_post',
|
37 |
+
'deactivate' => 'deactivate',
|
38 |
+
'newuser' => 'new_user',
|
39 |
+
'newadminpassword' => 'new_admin_password',
|
40 |
+
'installplugintheme' => 'install_plugin_theme',
|
41 |
+
'upgradeplugintheme' => 'upgrade_plugin_theme',
|
42 |
+
'upgradetranslation' => 'upgrade_translation',
|
43 |
+
'backup' => 'backup',
|
44 |
+
'backup_checkpid' => 'backup_checkpid',
|
45 |
+
'cloneinfo' => 'cloneinfo',
|
46 |
+
'security' => 'get_security_stats',
|
47 |
+
'securityFix' => 'do_security_fix',
|
48 |
+
'securityUnFix' => 'do_security_un_fix',
|
49 |
+
'post_action' => 'post_action',
|
50 |
+
'get_all_posts' => 'get_all_posts',
|
51 |
+
'comment_action' => 'comment_action',
|
52 |
+
'comment_bulk_action' => 'comment_bulk_action',
|
53 |
+
'get_all_comments' => 'get_all_comments',
|
54 |
+
'get_all_themes' => 'get_all_themes',
|
55 |
+
'theme_action' => 'theme_action',
|
56 |
+
'get_all_plugins' => 'get_all_plugins',
|
57 |
+
'plugin_action' => 'plugin_action',
|
58 |
+
'get_all_pages' => 'get_all_pages',
|
59 |
+
'get_all_users' => 'get_all_users',
|
60 |
+
'user_action' => 'user_action',
|
61 |
+
'search_users' => 'search_users',
|
62 |
+
'maintenance_site' => 'maintenance_site',
|
63 |
+
'branding_child_plugin' => 'branding_child_plugin',
|
64 |
+
'code_snippet' => 'code_snippet',
|
65 |
+
'uploader_action' => 'uploader_action',
|
66 |
+
'wordpress_seo' => 'wordpress_seo',
|
67 |
+
'client_report' => 'client_report',
|
68 |
+
'createBackupPoll' => 'backup_poll',
|
69 |
+
'page_speed' => 'page_speed',
|
70 |
+
'woo_com_status' => 'woo_com_status',
|
71 |
+
'links_checker' => 'links_checker',
|
72 |
+
'wordfence' => 'wordfence',
|
73 |
+
'delete_backup' => 'delete_backup',
|
74 |
+
'update_values' => 'update_child_values',
|
75 |
+
'ithemes' => 'ithemes',
|
76 |
+
'updraftplus' => 'updraftplus',
|
77 |
+
'backup_wp' => 'backup_wp',
|
78 |
+
'backwpup' => 'backwpup',
|
79 |
+
'wp_rocket' => 'wp_rocket',
|
80 |
+
'settings_tools' => 'settings_tools',
|
81 |
+
'skeleton_key' => 'bulk_settings_manager', // deprecated.
|
82 |
+
'bulk_settings_manager' => 'bulk_settings_manager',
|
83 |
+
'custom_post_type' => 'custom_post_type',
|
84 |
+
'backup_buddy' => 'backup_buddy',
|
85 |
+
'get_site_icon' => 'get_site_icon',
|
86 |
+
'vulner_checker' => 'vulner_checker',
|
87 |
+
'wp_staging' => 'wp_staging',
|
88 |
+
'disconnect' => 'disconnect',
|
89 |
+
'time_capsule' => 'time_capsule',
|
90 |
+
'extra_excution' => 'extra_execution', // deprecated!
|
91 |
+
'extra_execution' => 'extra_execution',
|
92 |
+
'wpvivid_backuprestore' => 'wpvivid_backuprestore',
|
93 |
+
'check_abandoned' => 'check_abandoned',
|
94 |
+
);
|
95 |
+
|
96 |
+
/**
|
97 |
+
* Private variable to hold the array of all callable functions that don't require regularl authentication.
|
98 |
+
*
|
99 |
+
* @var array Callable functions.
|
100 |
+
*/
|
101 |
+
private $callableFunctionsNoAuth = array(
|
102 |
+
'stats' => 'get_site_stats_no_auth',
|
103 |
+
);
|
104 |
+
|
105 |
+
/**
|
106 |
+
* Method get_class_name()
|
107 |
+
*
|
108 |
+
* Get class name.
|
109 |
+
*
|
110 |
+
* @return string __CLASS__ Class name.
|
111 |
+
*/
|
112 |
+
public static function get_class_name() {
|
113 |
+
return __CLASS__;
|
114 |
+
}
|
115 |
+
|
116 |
+
/**
|
117 |
+
* MainWP_Child_Callable constructor.
|
118 |
+
*
|
119 |
+
* Run any time class is called.
|
120 |
+
*/
|
121 |
+
public function __construct() {
|
122 |
+
}
|
123 |
+
|
124 |
+
/**
|
125 |
+
* Method instance()
|
126 |
+
*
|
127 |
+
* Create a public static instance.
|
128 |
+
*
|
129 |
+
* @return mixed Class instance.
|
130 |
+
*/
|
131 |
+
public static function get_instance() {
|
132 |
+
if ( null === self::$instance ) {
|
133 |
+
self::$instance = new self();
|
134 |
+
}
|
135 |
+
return self::$instance;
|
136 |
+
}
|
137 |
+
|
138 |
+
/**
|
139 |
+
* Method init_call_functions()
|
140 |
+
*
|
141 |
+
* Initiate callable functions.
|
142 |
+
*
|
143 |
+
* @param bool $auth If true, regular authentication is required.
|
144 |
+
*
|
145 |
+
* @uses \MainWP\Child\MainWP_Helper::instance()->error()
|
146 |
+
* @uses \MainWP\Child\MainWP_Utility::handle_fatal_error()
|
147 |
+
* @uses \MainWP\Child\MainWP_Utility::fix_for_custom_themes()
|
148 |
+
*/
|
149 |
+
public function init_call_functions( $auth = false ) {
|
150 |
+
$callable = false;
|
151 |
+
$callable_no_auth = false;
|
152 |
+
$call_func = false;
|
153 |
+
|
154 |
+
// check if function is callable.
|
155 |
+
if ( isset( $_POST['function'] ) ) {
|
156 |
+
$call_func = isset( $_POST['function'] ) ? sanitize_text_field( wp_unslash( $_POST['function'] ) ) : '';
|
157 |
+
$callable = $this->is_callable_function( $call_func ); // check callable func.
|
158 |
+
$callable_no_auth = $this->is_callable_function_no_auth( $call_func ); // check callable no auth func.
|
159 |
+
}
|
160 |
+
|
161 |
+
// Fire off the called function.
|
162 |
+
if ( $auth && isset( $_POST['function'] ) && $callable ) {
|
163 |
+
|
164 |
+
/**
|
165 |
+
* Checks whether cron is in progress.
|
166 |
+
*
|
167 |
+
* @const ( bool ) Default: true
|
168 |
+
* @source https://code-reference.mainwp.com/classes/MainWP.Child.MainWP_Child_Callable.html
|
169 |
+
*/
|
170 |
+
define( 'DOING_CRON', true );
|
171 |
+
|
172 |
+
MainWP_Utility::handle_fatal_error();
|
173 |
+
MainWP_Utility::fix_for_custom_themes();
|
174 |
+
$this->call_function( $call_func );
|
175 |
+
} elseif ( isset( $_POST['function'] ) && $callable_no_auth ) {
|
176 |
+
|
177 |
+
/**
|
178 |
+
* Checks whether cron is in progress.
|
179 |
+
*
|
180 |
+
* @const ( bool ) Default: true
|
181 |
+
* @source https://code-reference.mainwp.com/classes/MainWP.Child.MainWP_Child_Callable.html
|
182 |
+
*/
|
183 |
+
define( 'DOING_CRON', true );
|
184 |
+
|
185 |
+
MainWP_Utility::fix_for_custom_themes();
|
186 |
+
$this->call_function_no_auth( $call_func );
|
187 |
+
} elseif ( isset( $_POST['function'] ) && isset( $_POST['mainwpsignature'] ) && ! $callable && ! $callable_no_auth ) {
|
188 |
+
MainWP_Helper::instance()->error( __( 'Required version has not been detected. Please, make sure that you are using the latest version of the MainWP Child plugin on your site.', 'mainwp-child' ) );
|
189 |
+
}
|
190 |
+
}
|
191 |
+
|
192 |
+
/**
|
193 |
+
* Method is_callable_function()
|
194 |
+
*
|
195 |
+
* Check if the function is the list of callable functions.
|
196 |
+
*
|
197 |
+
* @param string $func Contains the name of the function to check.
|
198 |
+
*
|
199 |
+
* @return bool If callable, return true, if not, return false.
|
200 |
+
*/
|
201 |
+
public function is_callable_function( $func ) {
|
202 |
+
if ( isset( $this->callableFunctions[ $func ] ) ) {
|
203 |
+
return true;
|
204 |
+
}
|
205 |
+
return false;
|
206 |
+
}
|
207 |
+
|
208 |
+
/**
|
209 |
+
* Method is_callable_function_no_auth()
|
210 |
+
*
|
211 |
+
* Check if the function is the list of callable functions that don't require regular authentication.
|
212 |
+
*
|
213 |
+
* @param string $func Contains the name of the function to check.
|
214 |
+
*
|
215 |
+
* @return bool If callable, return true, if not, return false.
|
216 |
+
*/
|
217 |
+
public function is_callable_function_no_auth( $func ) {
|
218 |
+
if ( isset( $this->callableFunctionsNoAuth[ $func ] ) ) {
|
219 |
+
return true;
|
220 |
+
}
|
221 |
+
return false;
|
222 |
+
}
|
223 |
+
|
224 |
+
/**
|
225 |
+
* Method call_function()
|
226 |
+
*
|
227 |
+
* Call ceratin function.
|
228 |
+
*
|
229 |
+
* @param string $func Contains the name of the function to call.
|
230 |
+
*/
|
231 |
+
public function call_function( $func ) {
|
232 |
+
if ( $this->is_callable_function( $func ) ) {
|
233 |
+
call_user_func( array( $this, $this->callableFunctions[ $func ] ) );
|
234 |
+
}
|
235 |
+
}
|
236 |
+
|
237 |
+
/**
|
238 |
+
* Method call_function_no_auth()
|
239 |
+
*
|
240 |
+
* Call ceratin function without regular authentication if the function is in the $callableFunctionsNoAuth list.
|
241 |
+
*
|
242 |
+
* @param string $func Contains the name of the function to call.
|
243 |
+
*/
|
244 |
+
public function call_function_no_auth( $func ) {
|
245 |
+
if ( $this->is_callable_function_no_auth( $func ) ) {
|
246 |
+
call_user_func( array( $this, $this->callableFunctionsNoAuth[ $func ] ) );
|
247 |
+
}
|
248 |
+
}
|
249 |
+
|
250 |
+
/**
|
251 |
+
* Method get_site_stats()
|
252 |
+
*
|
253 |
+
* Fire off the get_site_stats() function.
|
254 |
+
*
|
255 |
+
* @uses \MainWP\Child\MainWP_Child_Stats::get_site_stats()
|
256 |
+
*/
|
257 |
+
public function get_site_stats() {
|
258 |
+
MainWP_Child_Stats::get_instance()->get_site_stats();
|
259 |
+
}
|
260 |
+
|
261 |
+
/**
|
262 |
+
* Method get_site_stats_no_auth()
|
263 |
+
*
|
264 |
+
* Fire off the get_site_stats_no_auth() function.
|
265 |
+
*
|
266 |
+
* @uses \MainWP\Child\MainWP_Child_Stats::get_site_stats_no_auth()
|
267 |
+
*/
|
268 |
+
public function get_site_stats_no_auth() {
|
269 |
+
MainWP_Child_Stats::get_instance()->get_site_stats_no_auth();
|
270 |
+
}
|
271 |
+
|
272 |
+
/**
|
273 |
+
* Method install_plugin_theme()
|
274 |
+
*
|
275 |
+
* Fire off the install_plugin_theme() function.
|
276 |
+
*
|
277 |
+
* @uses \MainWP\Child\MainWP_Child_Install::install_plugin_theme()
|
278 |
+
*/
|
279 |
+
public function install_plugin_theme() {
|
280 |
+
MainWP_Child_Install::get_instance()->install_plugin_theme();
|
281 |
+
}
|
282 |
+
|
283 |
+
/**
|
284 |
+
* Method upgrade_wp()
|
285 |
+
*
|
286 |
+
* Fire off the upgrade_wp() function.
|
287 |
+
*
|
288 |
+
* @uses \MainWP\Child\MainWP_Child_Updates::upgrade_wp()
|
289 |
+
*/
|
290 |
+
public function upgrade_wp() {
|
291 |
+
MainWP_Child_Updates::get_instance()->upgrade_wp();
|
292 |
+
}
|
293 |
+
|
294 |
+
/**
|
295 |
+
* Method upgrade_translation()
|
296 |
+
*
|
297 |
+
* Fire off the upgrade_translation() function.
|
298 |
+
*
|
299 |
+
* @uses \MainWP\Child\MainWP_Child_Updates::upgrade_translation()
|
300 |
+
*/
|
301 |
+
public function upgrade_translation() {
|
302 |
+
MainWP_Child_Updates::get_instance()->upgrade_translation();
|
303 |
+
}
|
304 |
+
|
305 |
+
/**
|
306 |
+
* Method upgrade_plugin_theme()
|
307 |
+
*
|
308 |
+
* Fire off the upgrade_plugin_theme() function.
|
309 |
+
*
|
310 |
+
* @uses \MainWP\Child\MainWP_Child_Updates::upgrade_plugin_theme()
|
311 |
+
*/
|
312 |
+
public function upgrade_plugin_theme() {
|
313 |
+
MainWP_Child_Updates::get_instance()->upgrade_plugin_theme();
|
314 |
+
}
|
315 |
+
|
316 |
+
/**
|
317 |
+
* Method theme_action()
|
318 |
+
*
|
319 |
+
* Fire off the theme_action() function.
|
320 |
+
*
|
321 |
+
* @uses \MainWP\Child\MainWP_Child_Install::theme_action()
|
322 |
+
*/
|
323 |
+
public function theme_action() {
|
324 |
+
MainWP_Child_Install::get_instance()->theme_action();
|
325 |
+
}
|
326 |
+
|
327 |
+
/**
|
328 |
+
* Method plugin_action()
|
329 |
+
*
|
330 |
+
* Fire off the plugin_action() function.
|
331 |
+
*
|
332 |
+
* @uses \MainWP\Child\MainWP_Child_Install::plugin_action()
|
333 |
+
*/
|
334 |
+
public function plugin_action() {
|
335 |
+
MainWP_Child_Install::get_instance()->plugin_action();
|
336 |
+
}
|
337 |
+
|
338 |
+
/**
|
339 |
+
* Method get_all_plugins()
|
340 |
+
*
|
341 |
+
* Fire off the get_all_plugins() function.
|
342 |
+
*
|
343 |
+
* @uses \MainWP\Child\MainWP_Child_Stats::get_all_plugins()
|
344 |
+
*/
|
345 |
+
public function get_all_plugins() {
|
346 |
+
MainWP_Child_Stats::get_instance()->get_all_plugins();
|
347 |
+
}
|
348 |
+
|
349 |
+
/**
|
350 |
+
* Method get_all_themes()
|
351 |
+
*
|
352 |
+
* Fire off the get_all_themes() function.
|
353 |
+
*
|
354 |
+
* @uses \MainWP\Child\MainWP_Child_Stats::get_all_themes()
|
355 |
+
*/
|
356 |
+
public function get_all_themes() {
|
357 |
+
MainWP_Child_Stats::get_instance()->get_all_themes();
|
358 |
+
}
|
359 |
+
|
360 |
+
/**
|
361 |
+
* Method get_all_users()
|
362 |
+
*
|
363 |
+
* Fire off the get_all_users() function.
|
364 |
+
*
|
365 |
+
* @uses \MainWP\Child\MainWP_Child_Users::get_all_users()
|
366 |
+
*/
|
367 |
+
public function get_all_users() {
|
368 |
+
MainWP_Child_Users::get_instance()->get_all_users();
|
369 |
+
}
|
370 |
+
|
371 |
+
/**
|
372 |
+
* Method user_action()
|
373 |
+
*
|
374 |
+
* Fire off the user_action() function.
|
375 |
+
*
|
376 |
+
* @uses \MainWP\Child\MainWP_Child_Users::user_action()
|
377 |
+
*/
|
378 |
+
public function user_action() {
|
379 |
+
MainWP_Child_Users::get_instance()->user_action();
|
380 |
+
}
|
381 |
+
|
382 |
+
/**
|
383 |
+
* Method search_users()
|
384 |
+
*
|
385 |
+
* Fire off the search_users() function.
|
386 |
+
*
|
387 |
+
* @uses \MainWP\Child\MainWP_Child_Users::search_users()
|
388 |
+
*/
|
389 |
+
public function search_users() {
|
390 |
+
MainWP_Child_Users::get_instance()->search_users();
|
391 |
+
}
|
392 |
+
|
393 |
+
/**
|
394 |
+
* Method get_all_posts()
|
395 |
+
*
|
396 |
+
* Fire off the get_all_posts() function.
|
397 |
+
*
|
398 |
+
* @uses \MainWP\Child\MainWP_Child_Posts::get_all_posts()
|
399 |
+
*/
|
400 |
+
public function get_all_posts() {
|
401 |
+
MainWP_Child_Posts::get_instance()->get_all_posts();
|
402 |
+
}
|
403 |
+
|
404 |
+
/**
|
405 |
+
* Method get_all_pages()
|
406 |
+
*
|
407 |
+
* Fire off the get_all_pages() function.
|
408 |
+
*
|
409 |
+
* @uses \MainWP\Child\MainWP_Child_Posts::get_all_pages()
|
410 |
+
*/
|
411 |
+
public function get_all_pages() {
|
412 |
+
MainWP_Child_Posts::get_instance()->get_all_pages();
|
413 |
+
}
|
414 |
+
|
415 |
+
/**
|
416 |
+
* Method comment_action()
|
417 |
+
*
|
418 |
+
* Fire off the comment_action() function.
|
419 |
+
*
|
420 |
+
* @uses \MainWP\Child\MainWP_Child_Comments::comment_action()
|
421 |
+
*/
|
422 |
+
public function comment_action() {
|
423 |
+
MainWP_Child_Comments::get_instance()->comment_action();
|
424 |
+
}
|
425 |
+
|
426 |
+
/**
|
427 |
+
* Method get_all_comments()
|
428 |
+
*
|
429 |
+
* Fire off the get_all_comments() function.
|
430 |
+
*
|
431 |
+
* @uses \MainWP\Child\MainWP_Child_Comments::get_all_comments()
|
432 |
+
*/
|
433 |
+
public function get_all_comments() {
|
434 |
+
MainWP_Child_Comments::get_instance()->get_all_comments();
|
435 |
+
}
|
436 |
+
|
437 |
+
/**
|
438 |
+
* Method comment_bulk_action()
|
439 |
+
*
|
440 |
+
* Fire off the comment_bulk_action() function.
|
441 |
+
*
|
442 |
+
* @uses \MainWP\Child\MainWP_Child_Comments::comment_bulk_action()
|
443 |
+
*/
|
444 |
+
public function comment_bulk_action() {
|
445 |
+
MainWP_Child_Comments::get_instance()->comment_bulk_action();
|
446 |
+
}
|
447 |
+
|
448 |
+
/**
|
449 |
+
* Method maintenance_site()
|
450 |
+
*
|
451 |
+
* Fire off the maintenance_site() function.
|
452 |
+
*
|
453 |
+
* @uses \MainWP\Child\MainWP_Child_Maintenance::maintenance_site()
|
454 |
+
*/
|
455 |
+
public function maintenance_site() {
|
456 |
+
MainWP_Child_Maintenance::get_instance()->maintenance_site();
|
457 |
+
}
|
458 |
+
|
459 |
+
/**
|
460 |
+
* Method new_post()
|
461 |
+
*
|
462 |
+
* Fire off the new_post() function.
|
463 |
+
*
|
464 |
+
* @uses \MainWP\Child\MainWP_Child_Posts::new_post()
|
465 |
+
*/
|
466 |
+
public function new_post() {
|
467 |
+
MainWP_Child_Posts::get_instance()->new_post();
|
468 |
+
}
|
469 |
+
|
470 |
+
/**
|
471 |
+
* Method post_action()
|
472 |
+
*
|
473 |
+
* Fire off the post_action() function.
|
474 |
+
*
|
475 |
+
* @uses \MainWP\Child\MainWP_Child_Posts::post_action()
|
476 |
+
*/
|
477 |
+
public function post_action() {
|
478 |
+
MainWP_Child_Posts::get_instance()->post_action();
|
479 |
+
}
|
480 |
+
|
481 |
+
/**
|
482 |
+
* Method new_admin_password()
|
483 |
+
*
|
484 |
+
* Fire off the new_admin_password() function.
|
485 |
+
*
|
486 |
+
* @uses \MainWP\Child\MainWP_Child_Users::new_admin_password()
|
487 |
+
*/
|
488 |
+
public function new_admin_password() {
|
489 |
+
MainWP_Child_Users::get_instance()->new_admin_password();
|
490 |
+
}
|
491 |
+
|
492 |
+
/**
|
493 |
+
* Method new_user()
|
494 |
+
*
|
495 |
+
* Fire off the new_user() function.
|
496 |
+
*
|
497 |
+
* @uses \MainWP\Child\MainWP_Child_Users::new_user()
|
498 |
+
*/
|
499 |
+
public function new_user() {
|
500 |
+
MainWP_Child_Users::get_instance()->new_user();
|
501 |
+
}
|
502 |
+
|
503 |
+
/**
|
504 |
+
* Method cloneinfo()
|
505 |
+
*
|
506 |
+
* Fire off the cloneinfo() function.
|
507 |
+
*
|
508 |
+
* @uses \MainWP\Child\MainWP_Helper::write()
|
509 |
+
*/
|
510 |
+
public function cloneinfo() {
|
511 |
+
|
512 |
+
/**
|
513 |
+
* WordPress DB Table Prefix.
|
514 |
+
*
|
515 |
+
* @global string
|
516 |
+
*/
|
517 |
+
global $table_prefix;
|
518 |
+
|
519 |
+
$information['dbCharset'] = DB_CHARSET;
|
520 |
+
$information['dbCollate'] = DB_COLLATE;
|
521 |
+
$information['table_prefix'] = $table_prefix;
|
522 |
+
$information['site_url'] = get_option( 'site_url' );
|
523 |
+
$information['home'] = get_option( 'home' );
|
524 |
+
|
525 |
+
MainWP_Helper::write( $information );
|
526 |
+
}
|
527 |
+
|
528 |
+
/**
|
529 |
+
* Method backup_poll()
|
530 |
+
*
|
531 |
+
* Fire off the backup_poll() function.
|
532 |
+
*
|
533 |
+
* @uses \MainWP\Child\MainWP_Backup::backup_poll()
|
534 |
+
*/
|
535 |
+
public function backup_poll() {
|
536 |
+
MainWP_Backup::get()->backup_poll();
|
537 |
+
}
|
538 |
+
|
539 |
+
/**
|
540 |
+
* Method backup_checkpid()
|
541 |
+
*
|
542 |
+
* Fire off the backup_checkpid() function.
|
543 |
+
*
|
544 |
+
* @uses \MainWP\Child\MainWP_Backup::backup_checkpid()
|
545 |
+
*/
|
546 |
+
public function backup_checkpid() {
|
547 |
+
MainWP_Backup::get()->backup_checkpid();
|
548 |
+
}
|
549 |
+
|
550 |
+
/**
|
551 |
+
* Method backup()
|
552 |
+
*
|
553 |
+
* Fire off the backup() function.
|
554 |
+
*
|
555 |
+
* @param bool $write Whether or not to execute MainWP_Helper::write(), Default: true.
|
556 |
+
*
|
557 |
+
* @return array Action result.
|
558 |
+
*
|
559 |
+
* @uses \MainWP\Child\MainWP_Backup::backup()
|
560 |
+
*/
|
561 |
+
public function backup( $write = true ) {
|
562 |
+
return MainWP_Backup::get()->backup( $write );
|
563 |
+
}
|
564 |
+
|
565 |
+
/**
|
566 |
+
* Method backup_full()
|
567 |
+
*
|
568 |
+
* Fire off the backup_full() function.
|
569 |
+
*
|
570 |
+
* @param string $file_name Contains the backup file name.
|
571 |
+
*
|
572 |
+
* @return array Action result.
|
573 |
+
*
|
574 |
+
* @uses \MainWP\Child\MainWP_Backup::backup_full()
|
575 |
+
*/
|
576 |
+
protected function backup_full( $file_name ) {
|
577 |
+
return MainWP_Backup::get()->backup_full( $file_name );
|
578 |
+
}
|
579 |
+
|
580 |
+
/**
|
581 |
+
* Method backup_db()
|
582 |
+
*
|
583 |
+
* Fire off the backup_db() function.
|
584 |
+
*
|
585 |
+
* @param string $file_name Contains the backup file name.
|
586 |
+
* @param string $file_extension Contains the backup file extension.
|
587 |
+
*
|
588 |
+
* @return array Action result.
|
589 |
+
*
|
590 |
+
* @uses \MainWP\Child\MainWP_Backup::backup_db()
|
591 |
+
*/
|
592 |
+
protected function backup_db( $file_name = '', $file_extension = 'zip' ) {
|
593 |
+
return MainWP_Backup::get()->backup_db( $file_name, $file_extension );
|
594 |
+
}
|
595 |
+
|
596 |
+
/**
|
597 |
+
* Method get_site_icon()
|
598 |
+
*
|
599 |
+
* Fire off the get_site_icon() function.
|
600 |
+
*
|
601 |
+
* @uses \MainWP\Child\MainWP_Child_Misc::get_site_icon()
|
602 |
+
*/
|
603 |
+
public function get_site_icon() {
|
604 |
+
MainWP_Child_Misc::get_instance()->get_site_icon();
|
605 |
+
}
|
606 |
+
|
607 |
+
/**
|
608 |
+
* Method check_abandoned()
|
609 |
+
*
|
610 |
+
* Fire off the check_abandoned() function.
|
611 |
+
*/
|
612 |
+
public function check_abandoned() {
|
613 |
+
$which = sanitize_text_field( wp_unslash( $_POST['which'] ) );
|
614 |
+
$infor = array();
|
615 |
+
if ( 'plugin' == $which ) {
|
616 |
+
MainWP_Child_Plugins_Check::instance()->run_check();
|
617 |
+
$infor['success'] = 1;
|
618 |
+
} else {
|
619 |
+
MainWP_Child_Themes_Check::instance()->run_check();
|
620 |
+
$infor['success'] = 1;
|
621 |
+
}
|
622 |
+
$infor['sync'] = MainWP_Child_Stats::get_instance()->get_site_stats( array(), false );
|
623 |
+
MainWP_Helper::write( $infor );
|
624 |
+
}
|
625 |
+
|
626 |
+
/**
|
627 |
+
* Method get_security_stats()
|
628 |
+
*
|
629 |
+
* Fire off the get_security_stats() function.
|
630 |
+
*
|
631 |
+
* @uses \MainWP\Child\MainWP_Child_Misc::get_security_stats()
|
632 |
+
*/
|
633 |
+
public function get_security_stats() {
|
634 |
+
MainWP_Child_Misc::get_instance()->get_security_stats();
|
635 |
+
}
|
636 |
+
|
637 |
+
/**
|
638 |
+
* Method do_security_fix()
|
639 |
+
*
|
640 |
+
* Fire off the do_security_fix() function.
|
641 |
+
*
|
642 |
+
* @uses \MainWP\Child\MainWP_Child_Misc::do_security_fix()
|
643 |
+
*/
|
644 |
+
public function do_security_fix() {
|
645 |
+
MainWP_Child_Misc::get_instance()->do_security_fix();
|
646 |
+
}
|
647 |
+
|
648 |
+
/**
|
649 |
+
* Method do_security_un_fix()
|
650 |
+
*
|
651 |
+
* Fire off the do_security_un_fix() function.
|
652 |
+
*
|
653 |
+
* @uses \MainWP\Child\MainWP_Child_Misc::do_security_un_fix()
|
654 |
+
*/
|
655 |
+
public function do_security_un_fix() {
|
656 |
+
MainWP_Child_Misc::get_instance()->do_security_un_fix();
|
657 |
+
}
|
658 |
+
|
659 |
+
/**
|
660 |
+
* Method settings_tools()
|
661 |
+
*
|
662 |
+
* Fire off the settings_tools() function.
|
663 |
+
*
|
664 |
+
* @uses \MainWP\Child\MainWP_Child_Misc::do_security_un_fix()
|
665 |
+
*/
|
666 |
+
public function settings_tools() {
|
667 |
+
MainWP_Child_Misc::get_instance()->do_security_un_fix();
|
668 |
+
}
|
669 |
+
|
670 |
+
/**
|
671 |
+
* Method bulk_settings_manager()
|
672 |
+
*
|
673 |
+
* Fire off the action() function.
|
674 |
+
*
|
675 |
+
* @uses \MainWP\Child\MainWP_Child_Bulk_Settings_Manager::action()
|
676 |
+
*/
|
677 |
+
public function bulk_settings_manager() {
|
678 |
+
MainWP_Child_Bulk_Settings_Manager::instance()->action();
|
679 |
+
}
|
680 |
+
|
681 |
+
/**
|
682 |
+
* Method custom_post_type()
|
683 |
+
*
|
684 |
+
* Fire off the action() function.
|
685 |
+
*
|
686 |
+
* @uses \MainWP\Child\MainWP_Custom_Post_Type::action()
|
687 |
+
*/
|
688 |
+
public function custom_post_type() {
|
689 |
+
MainWP_Custom_Post_Type::instance()->action();
|
690 |
+
}
|
691 |
+
|
692 |
+
/**
|
693 |
+
* Method backup_buddy()
|
694 |
+
*
|
695 |
+
* Fire off the action() function.
|
696 |
+
*
|
697 |
+
* @uses \MainWP\Child\MainWP_Child_Back_Up_Buddy::action()
|
698 |
+
*/
|
699 |
+
public function backup_buddy() {
|
700 |
+
MainWP_Child_Back_Up_Buddy::instance()->action();
|
701 |
+
}
|
702 |
+
|
703 |
+
/**
|
704 |
+
* Method vulner_checker()
|
705 |
+
*
|
706 |
+
* Fire off the action() function.
|
707 |
+
*
|
708 |
+
* @uses \MainWP\Child\MainWP_Child_Vulnerability_Checker::action()
|
709 |
+
*/
|
710 |
+
public function vulner_checker() {
|
711 |
+
MainWP_Child_Vulnerability_Checker::instance()->action();
|
712 |
+
}
|
713 |
+
|
714 |
+
/**
|
715 |
+
* Method time_capsule()
|
716 |
+
*
|
717 |
+
* Fire off the action() function.
|
718 |
+
*
|
719 |
+
* @uses \MainWP\Child\MainWP_Child_Timecapsule::action()
|
720 |
+
*/
|
721 |
+
public function time_capsule() {
|
722 |
+
MainWP_Child_Timecapsule::instance()->action();
|
723 |
+
}
|
724 |
+
|
725 |
+
/**
|
726 |
+
* Method wp_staging()
|
727 |
+
*
|
728 |
+
* Fire off the action() function.
|
729 |
+
*
|
730 |
+
* @uses \MainWP\Child\MainWP_Child_Staging::action()
|
731 |
+
*/
|
732 |
+
public function wp_staging() {
|
733 |
+
MainWP_Child_Staging::instance()->action();
|
734 |
+
}
|
735 |
+
|
736 |
+
/**
|
737 |
+
* Method extra_execution()
|
738 |
+
*
|
739 |
+
* Additional functions to execute.
|
740 |
+
*
|
741 |
+
* @uses \MainWP\Child\MainWP_Helper::write()
|
742 |
+
*/
|
743 |
+
public function extra_execution() {
|
744 |
+
$post = $_POST;
|
745 |
+
$information = array();
|
746 |
+
/**
|
747 |
+
* Filter 'mainwp_child_extra_execution'
|
748 |
+
*
|
749 |
+
* Additional functions to execute through the filter.
|
750 |
+
*
|
751 |
+
* @param array $information An array containing the synchronization information.
|
752 |
+
* @param mixed $post Contains the POST request.
|
753 |
+
*
|
754 |
+
* @since 4.0
|
755 |
+
*/
|
756 |
+
$information = apply_filters( 'mainwp_child_extra_execution', $information, $post );
|
757 |
+
MainWP_Helper::write( $information );
|
758 |
+
}
|
759 |
+
|
760 |
+
/**
|
761 |
+
* Method uploader_action()
|
762 |
+
*
|
763 |
+
* Fire off the uploader_action() function.
|
764 |
+
*
|
765 |
+
* @uses \MainWP\Child\MainWP_Child_Misc::uploader_action()
|
766 |
+
*/
|
767 |
+
public function uploader_action() {
|
768 |
+
MainWP_Child_Misc::get_instance()->uploader_action();
|
769 |
+
}
|
770 |
+
|
771 |
+
/**
|
772 |
+
* Method wordpress_seo()
|
773 |
+
*
|
774 |
+
* Fire off the action() function.
|
775 |
+
*/
|
776 |
+
public function wordpress_seo() {
|
777 |
+
MainWP_WordPress_SEO::instance()->action();
|
778 |
+
}
|
779 |
+
|
780 |
+
/**
|
781 |
+
* Method client_report()
|
782 |
+
*
|
783 |
+
* Fire off the action() function.
|
784 |
+
*
|
785 |
+
* @uses \MainWP\Child\MainWP_Client_Report::action()
|
786 |
+
*/
|
787 |
+
public function client_report() {
|
788 |
+
MainWP_Client_Report::instance()->action();
|
789 |
+
}
|
790 |
+
|
791 |
+
/**
|
792 |
+
* Method page_speed()
|
793 |
+
*
|
794 |
+
* Fire off the action() function.
|
795 |
+
*
|
796 |
+
* @uses \MainWP\Child\MainWP_Child_Pagespeed::action()
|
797 |
+
*/
|
798 |
+
public function page_speed() {
|
799 |
+
MainWP_Child_Pagespeed::instance()->action();
|
800 |
+
}
|
801 |
+
|
802 |
+
/**
|
803 |
+
* Method woo_com_status()
|
804 |
+
*
|
805 |
+
* Fire off the action() function.
|
806 |
+
*
|
807 |
+
* @uses \MainWP\Child\MainWP_Child_WooCommerce_Status::action()
|
808 |
+
*/
|
809 |
+
public function woo_com_status() {
|
810 |
+
MainWP_Child_WooCommerce_Status::instance()->action();
|
811 |
+
}
|
812 |
+
|
813 |
+
/**
|
814 |
+
* Method links_checker()
|
815 |
+
*
|
816 |
+
* Fire off the action() function.
|
817 |
+
*
|
818 |
+
* @uses \MainWP\Child\MainWP_Child_Links_Checker::action()
|
819 |
+
*/
|
820 |
+
public function links_checker() {
|
821 |
+
MainWP_Child_Links_Checker::instance()->action();
|
822 |
+
}
|
823 |
+
|
824 |
+
/**
|
825 |
+
* Method wordfence()
|
826 |
+
*
|
827 |
+
* Fire off the action() function.
|
828 |
+
*
|
829 |
+
* @uses \MainWP\Child\MainWP_Child_Wordfence::action()
|
830 |
+
*/
|
831 |
+
public function wordfence() {
|
832 |
+
MainWP_Child_Wordfence::instance()->action();
|
833 |
+
}
|
834 |
+
|
835 |
+
/**
|
836 |
+
* Method ithemes()
|
837 |
+
*
|
838 |
+
* Fire off the action() function.
|
839 |
+
*
|
840 |
+
* @uses \MainWP\Child\MainWP_Child_IThemes_Security::action()
|
841 |
+
*/
|
842 |
+
public function ithemes() {
|
843 |
+
MainWP_Child_IThemes_Security::instance()->action();
|
844 |
+
}
|
845 |
+
|
846 |
+
/**
|
847 |
+
* Method updraftplus()
|
848 |
+
*
|
849 |
+
* Fire off the action() function.
|
850 |
+
*
|
851 |
+
* @uses \MainWP\Child\MainWP_Child_Updraft_Plus_Backups::action()
|
852 |
+
*/
|
853 |
+
public function updraftplus() {
|
854 |
+
MainWP_Child_Updraft_Plus_Backups::instance()->action();
|
855 |
+
}
|
856 |
+
|
857 |
+
/**
|
858 |
+
* Method wpvivid_backuprestore()
|
859 |
+
*
|
860 |
+
* Fire off the action() function.
|
861 |
+
*
|
862 |
+
* @uses \MainWP\Child\MainWP_Child_WPvivid_BackupRestore::action()
|
863 |
+
*/
|
864 |
+
public function wpvivid_backuprestore() {
|
865 |
+
MainWP_Child_WPvivid_BackupRestore::instance()->action();
|
866 |
+
}
|
867 |
+
|
868 |
+
/**
|
869 |
+
* Method backup_wp()
|
870 |
+
*
|
871 |
+
* Fire off the action() function.
|
872 |
+
*
|
873 |
+
* @uses \MainWP\Child\MainWP_Child_Back_Up_WordPress::action()
|
874 |
+
* @uses \MainWP\Child\MainWP_Helper::write()
|
875 |
+
*/
|
876 |
+
public function backup_wp() {
|
877 |
+
if ( ! version_compare( phpversion(), '5.3', '>=' ) ) {
|
878 |
+
$error = sprintf( __( 'PHP Version %s is unsupported.', 'mainwp-child' ), phpversion() );
|
879 |
+
MainWP_Helper::write( array( 'error' => $error ) );
|
880 |
+
}
|
881 |
+
MainWP_Child_Back_Up_WordPress::instance()->action();
|
882 |
+
}
|
883 |
+
|
884 |
+
/**
|
885 |
+
* Method wp_rocket()
|
886 |
+
*
|
887 |
+
* Fire off the action() function.
|
888 |
+
*
|
889 |
+
* @uses \MainWP\Child\MainWP_Child_WP_Rocket::action()
|
890 |
+
*/
|
891 |
+
public function wp_rocket() {
|
892 |
+
MainWP_Child_WP_Rocket::instance()->action();
|
893 |
+
}
|
894 |
+
|
895 |
+
/**
|
896 |
+
* Method backwpup()
|
897 |
+
*
|
898 |
+
* Fire off the action() function.
|
899 |
+
*
|
900 |
+
* @uses \MainWP\Child\MainWP_Child_Back_WP_Up::action()
|
901 |
+
*/
|
902 |
+
public function backwpup() {
|
903 |
+
MainWP_Child_Back_WP_Up::instance()->action();
|
904 |
+
}
|
905 |
+
|
906 |
+
/**
|
907 |
+
* Method delete_backup()
|
908 |
+
*
|
909 |
+
* Delete backup.
|
910 |
+
*
|
911 |
+
* @uses \MainWP\Child\MainWP_Helper::get_mainwp_dir()
|
912 |
+
* @uses \MainWP\Child\MainWP_Helper::write()
|
913 |
+
*/
|
914 |
+
public function delete_backup() {
|
915 |
+
$dirs = MainWP_Helper::get_mainwp_dir( 'backup' );
|
916 |
+
$backupdir = $dirs[0];
|
917 |
+
|
918 |
+
$file = isset( $_REQUEST['del'] ) ? wp_unslash( $_REQUEST['del'] ) : '';
|
919 |
+
|
920 |
+
if ( file_exists( $backupdir . $file ) ) {
|
921 |
+
unlink( $backupdir . $file );
|
922 |
+
}
|
923 |
+
|
924 |
+
MainWP_Helper::write( array( 'result' => 'ok' ) );
|
925 |
+
}
|
926 |
+
|
927 |
+
/**
|
928 |
+
* Method update_child_values()
|
929 |
+
*
|
930 |
+
* Update the MainWP Child site options.
|
931 |
+
*
|
932 |
+
* @uses \MainWP\Child\MainWP_Helper::update_option()
|
933 |
+
* @uses \MainWP\Child\MainWP_Helper::write()
|
934 |
+
*/
|
935 |
+
public function update_child_values() {
|
936 |
+
$unique_id = isset( $_POST['uniqueId'] ) ? sanitize_text_field( wp_unslash( $_POST['uniqueId'] ) ) : '';
|
937 |
+
MainWP_Helper::update_option( 'mainwp_child_uniqueId', $unique_id );
|
938 |
+
MainWP_Helper::write( array( 'result' => 'ok' ) );
|
939 |
+
}
|
940 |
+
|
941 |
+
/**
|
942 |
+
* Method branding_child_plugin()
|
943 |
+
*
|
944 |
+
* Fire off the action() function.
|
945 |
+
*
|
946 |
+
* @uses \MainWP\Child\MainWP_Child_Branding::action()
|
947 |
+
*/
|
948 |
+
public function branding_child_plugin() {
|
949 |
+
MainWP_Child_Branding::instance()->action();
|
950 |
+
}
|
951 |
+
|
952 |
+
/**
|
953 |
+
* Method code_snippet()
|
954 |
+
*
|
955 |
+
* Fire off the code_snippet() function.
|
956 |
+
*
|
957 |
+
* @uses MainWP_Child_Misc::code_snippet()
|
958 |
+
*/
|
959 |
+
public function code_snippet() {
|
960 |
+
MainWP_Child_Misc::get_instance()->code_snippet();
|
961 |
+
}
|
962 |
+
|
963 |
+
/**
|
964 |
+
* Method disconnect()
|
965 |
+
*
|
966 |
+
* Disconnect the child site from the current MainWP Dashboard.
|
967 |
+
*
|
968 |
+
* @uses \MainWP\Child\MainWP_Helper::write()
|
969 |
+
*/
|
970 |
+
public function disconnect() {
|
971 |
+
|
972 |
+
/**
|
973 |
+
* MainWP Child instance.
|
974 |
+
*
|
975 |
+
* @global object
|
976 |
+
*/
|
977 |
+
global $mainWPChild;
|
978 |
+
|
979 |
+
$mainWPChild->deactivation( false );
|
980 |
+
MainWP_Helper::write( array( 'result' => 'success' ) );
|
981 |
+
}
|
982 |
+
|
983 |
+
|
984 |
+
/**
|
985 |
+
* Method deactivate()
|
986 |
+
*
|
987 |
+
* Deactivate the MainWP Child plugin in the site.
|
988 |
+
*
|
989 |
+
* @uses \MainWP\Child\MainWP_Helper::errpr()
|
990 |
+
* @uses \MainWP\Child\MainWP_Helper::write()
|
991 |
+
*/
|
992 |
+
public function deactivate() {
|
993 |
+
|
994 |
+
/**
|
995 |
+
* MainWP Child instance.
|
996 |
+
*
|
997 |
+
* @global object
|
998 |
+
*/
|
999 |
+
global $mainWPChild;
|
1000 |
+
|
1001 |
+
include_once ABSPATH . 'wp-admin/includes/plugin.php';
|
1002 |
+
deactivate_plugins( $mainWPChild->plugin_slug, true );
|
1003 |
+
$information = array();
|
1004 |
+
if ( is_plugin_active( $mainWPChild->plugin_slug ) ) {
|
1005 |
+
MainWP_Helper::instance()->error( 'Plugin still active' );
|
1006 |
+
}
|
1007 |
+
$information['deactivated'] = true;
|
1008 |
+
MainWP_Helper::write( $information );
|
1009 |
+
}
|
1010 |
+
|
1011 |
+
}
|
class/class-mainwp-child-install.php
CHANGED
@@ -204,7 +204,7 @@ class MainWP_Child_Install {
|
|
204 |
* @uses \MainWP\Child\MainWP_Helper::check_wp_filesystem()
|
205 |
* @uses \MainWP\Child\MainWP_Helper::write()
|
206 |
*/
|
207 |
-
public function theme_action() {
|
208 |
|
209 |
$action = ! empty( $_POST['action'] ) ? sanitize_text_field( wp_unslash( $_POST['action'] ) ) : '';
|
210 |
$theme = isset( $_POST['theme'] ) ? wp_unslash( $_POST['theme'] ) : '';
|
@@ -261,7 +261,7 @@ class MainWP_Child_Install {
|
|
261 |
if ( $themeToDelete !== $theme_name && $themeToDelete !== $parent_name ) {
|
262 |
$theTheme = wp_get_theme( $themeToDelete );
|
263 |
if ( null !== $theTheme && '' !== $theTheme ) {
|
264 |
-
$tmp['theme'] = $theTheme
|
265 |
if ( true === $themeUpgrader->delete_old_theme( null, null, null, $tmp ) ) {
|
266 |
$args = array(
|
267 |
'action' => 'delete',
|
204 |
* @uses \MainWP\Child\MainWP_Helper::check_wp_filesystem()
|
205 |
* @uses \MainWP\Child\MainWP_Helper::write()
|
206 |
*/
|
207 |
+
public function theme_action() { // phpcs:ignore -- Current complexity is the only way to achieve desired results, pull request solutions appreciated.
|
208 |
|
209 |
$action = ! empty( $_POST['action'] ) ? sanitize_text_field( wp_unslash( $_POST['action'] ) ) : '';
|
210 |
$theme = isset( $_POST['theme'] ) ? wp_unslash( $_POST['theme'] ) : '';
|
261 |
if ( $themeToDelete !== $theme_name && $themeToDelete !== $parent_name ) {
|
262 |
$theTheme = wp_get_theme( $themeToDelete );
|
263 |
if ( null !== $theTheme && '' !== $theTheme ) {
|
264 |
+
$tmp['theme'] = $theTheme->stylesheet; // to fix delete parent theme issue.
|
265 |
if ( true === $themeUpgrader->delete_old_theme( null, null, null, $tmp ) ) {
|
266 |
$args = array(
|
267 |
'action' => 'delete',
|
class/class-mainwp-child-ithemes-security.php
CHANGED
@@ -1,1653 +1,1653 @@
|
|
1 |
-
<?php
|
2 |
-
/**
|
3 |
-
* MainWP Ithemes Security
|
4 |
-
*
|
5 |
-
* MainWP iThemes Security Extension handler.
|
6 |
-
* Extension URL: https://mainwp.com/extension/ithemes-security/
|
7 |
-
*
|
8 |
-
* @package MainWP\Child
|
9 |
-
*
|
10 |
-
* Credits
|
11 |
-
*
|
12 |
-
* Plugin-Name: iThemes Security
|
13 |
-
* Plugin URI: https://ithemes.com/security
|
14 |
-
* Author: iThemes
|
15 |
-
* Author URI: https://ithemes.com
|
16 |
-
* License: GPLv2
|
17 |
-
*
|
18 |
-
* The code is used for the MainWP iThemes Security Extension
|
19 |
-
* Extension URL: https://mainwp.com/extension/ithemes-security/
|
20 |
-
*/
|
21 |
-
|
22 |
-
namespace MainWP\Child;
|
23 |
-
|
24 |
-
// phpcs:disable -- third party credit code.
|
25 |
-
|
26 |
-
|
27 |
-
/**
|
28 |
-
* Class MainWP_Child_IThemes_Security
|
29 |
-
*/
|
30 |
-
class MainWP_Child_IThemes_Security {
|
31 |
-
|
32 |
-
/**
|
33 |
-
* Public static variable to hold the single instance of MainWP_Child_IThemes_Security.
|
34 |
-
* @var null
|
35 |
-
*/
|
36 |
-
public static $instance = null;
|
37 |
-
|
38 |
-
/**
|
39 |
-
* @var bool Whether or not iThemes Plugin is installed or not. Default: false.
|
40 |
-
*/
|
41 |
-
public $is_plugin_installed = false;
|
42 |
-
|
43 |
-
/**
|
44 |
-
* Create a public static instance of MainWP_Child_IThemes_Security.
|
45 |
-
*
|
46 |
-
* @return MainWP_Child_IThemes_Security|null
|
47 |
-
*/
|
48 |
-
public static function instance() {
|
49 |
-
if ( null === self::$instance ) {
|
50 |
-
self::$instance = new self();
|
51 |
-
}
|
52 |
-
return self::$instance;
|
53 |
-
}
|
54 |
-
|
55 |
-
/**
|
56 |
-
* MainWP_Child_IThemes_Security constructor.
|
57 |
-
*
|
58 |
-
* Run any time class is called.
|
59 |
-
*
|
60 |
-
* @uses MainWP_Child_IThemes_Security::is_plugin_installed()
|
61 |
-
*/
|
62 |
-
public function __construct() {
|
63 |
-
require_once ABSPATH . 'wp-admin/includes/plugin.php';
|
64 |
-
if ( is_plugin_active( 'better-wp-security/better-wp-security.php' ) || is_plugin_active( 'ithemes-security-pro/ithemes-security-pro.php' ) ) {
|
65 |
-
$this->is_plugin_installed = true;
|
66 |
-
}
|
67 |
-
|
68 |
-
if ( ! $this->is_plugin_installed ) {
|
69 |
-
return;
|
70 |
-
}
|
71 |
-
|
72 |
-
add_filter( 'mainwp_site_sync_others_data', array( $this, 'sync_others_data' ), 10, 2 );
|
73 |
-
}
|
74 |
-
|
75 |
-
/**
|
76 |
-
* Sync other data from $data[] and merge with $information[]
|
77 |
-
*
|
78 |
-
* @param array $information Returned response array for MainWP BackWPup Extension actions.
|
79 |
-
* @param array $data Other data to sync to $information array.
|
80 |
-
* @return array $information Returned information array with both sets of data.
|
81 |
-
*/
|
82 |
-
public function sync_others_data( $information, $data = array() ) {
|
83 |
-
if ( is_array( $data ) && isset( $data['ithemeExtActivated'] ) && ( 'yes' === $data['ithemeExtActivated'] ) ) {
|
84 |
-
try {
|
85 |
-
$information['syncIThemeData'] = array(
|
86 |
-
'users_and_roles' => $this->get_available_admin_users_and_roles(),
|
87 |
-
);
|
88 |
-
|
89 |
-
global $itsec_lockout;
|
90 |
-
|
91 |
-
if ( $itsec_lockout ) {
|
92 |
-
$lockout_query = array(
|
93 |
-
'limit' => 100,
|
94 |
-
'current' => true,
|
95 |
-
'order' => 'DESC',
|
96 |
-
'orderby' => 'lockout_start',
|
97 |
-
);
|
98 |
-
$lockouts = $itsec_lockout->get_lockouts( 'all', $lockout_query );
|
99 |
-
if ( $lockouts ) {
|
100 |
-
$information['syncIThemeData']['lockout_count'] = count( $lockouts );
|
101 |
-
}
|
102 |
-
}
|
103 |
-
|
104 |
-
|
105 |
-
$request = new \WP_REST_Request( 'GET', '/ithemes-security/v1/site-scanner/scans' );
|
106 |
-
|
107 |
-
$range1 = \ITSEC_Core::get_current_time_gmt();
|
108 |
-
$range0 = strtotime( '-30 days', $range1 );
|
109 |
-
|
110 |
-
|
111 |
-
$request->set_query_params( [
|
112 |
-
'after' => \ITSEC_Lib::to_rest_date( $range0 ),
|
113 |
-
'before' => \ITSEC_Lib::to_rest_date( $range1 ),
|
114 |
-
] );
|
115 |
-
|
116 |
-
$response = rest_do_request( $request );
|
117 |
-
$scans = rest_get_server()->response_to_data( $response, true );
|
118 |
-
|
119 |
-
if ( is_array( $scans ) && count( $scans ) > 0 ) {
|
120 |
-
$scan = current( $scans );
|
121 |
-
$information['syncIThemeData']['scan_info'] = array(
|
122 |
-
'time' => $scan['time'],
|
123 |
-
'description' => $scan['description'],
|
124 |
-
'status' => $scan['status'],
|
125 |
-
);
|
126 |
-
}
|
127 |
-
|
128 |
-
if ( class_exists( '\iThemesSecurity\Ban_Users\Database_Repository' ) ) {
|
129 |
-
$repository = \ITSEC_Modules::get_container()->get( \iThemesSecurity\Ban_Users\Database_Repository::class );
|
130 |
-
$information['syncIThemeData']['count_bans'] = $repository->count_bans( new \iThemesSecurity\Ban_Hosts\Filters() );
|
131 |
-
}
|
132 |
-
|
133 |
-
$information['syncIThemeData']['lockouts_host'] = $this->get_lockouts( 'host', true );
|
134 |
-
$information['syncIThemeData']['lockouts_user'] = $this->get_lockouts( 'user', true );
|
135 |
-
$information['syncIThemeData']['lockouts_username'] = $this->get_lockouts( 'username', true );
|
136 |
-
|
137 |
-
|
138 |
-
} catch ( \Exception $e ) {
|
139 |
-
error_log( $e->getMessage() ); // phpcs:ignore -- debug mode only.
|
140 |
-
}
|
141 |
-
}
|
142 |
-
return $information;
|
143 |
-
}
|
144 |
-
|
145 |
-
/**
|
146 |
-
* MainWP iThemes Security Extension actions.
|
147 |
-
*
|
148 |
-
* @uses \MainWP\Child\MainWP_Child_IThemes_Security::set_showhide()
|
149 |
-
* @uses \MainWP\Child\MainWP_Child_IThemes_Security::save_settings()
|
150 |
-
* @uses \MainWP\Child\MainWP_Child_IThemes_Security::whitelist_release()
|
151 |
-
* @uses \MainWP\Child\MainWP_Child_IThemes_Security::backup_db()
|
152 |
-
* @uses \MainWP\Child\MainWP_Child_IThemes_Security::admin_user()
|
153 |
-
* @uses \MainWP\Child\MainWP_Child_IThemes_Security::change_database_prefix()
|
154 |
-
* @uses \MainWP\Child\MainWP_Child_IThemes_Security::reset_api_key()
|
155 |
-
* @uses \MainWP\Child\MainWP_Child_IThemes_Security::malware_scan()
|
156 |
-
* @uses \MainWP\Child\MainWP_Child_IThemes_Security::>purge_logs()
|
157 |
-
* @uses \MainWP\Child\MainWP_Child_IThemes_Security::file_change()
|
158 |
-
* @uses \MainWP\Child\MainWP_Child_IThemes_Security::release_lockout()
|
159 |
-
* @uses \MainWP\Child\MainWP_Child_IThemes_Security::update_module_status()
|
160 |
-
* @uses \MainWP\Child\MainWP_Child_IThemes_Security::wordpress_salts()
|
161 |
-
* @uses \MainWP\Child\MainWP_Child_IThemes_Security::file_permissions()
|
162 |
-
* @uses \MainWP\Child\MainWP_Child_IThemes_Security::reload_backup_exclude()
|
163 |
-
* @uses \MainWP\Child\MainWP_Child_IThemes_Security::security_site()
|
164 |
-
* @uses \MainWP\Child\MainWP_Child_IThemes_Security::activate_network_brute_force()
|
165 |
-
* @uses \MainWP\Child\MainWP_Helper::write()
|
166 |
-
*/
|
167 |
-
public function action() {
|
168 |
-
$information = array();
|
169 |
-
if ( ! class_exists( '\ITSEC_Core' ) || ! class_exists( '\ITSEC_Modules' ) ) {
|
170 |
-
$information['error'] = 'NO_ITHEME';
|
171 |
-
MainWP_Helper::write( $information );
|
172 |
-
}
|
173 |
-
|
174 |
-
/** @global string $mainwp_itsec_modules_path MainWP itsec modules path. */
|
175 |
-
global $mainwp_itsec_modules_path;
|
176 |
-
|
177 |
-
$mainwp_itsec_modules_path = \ITSEC_Core::get_core_dir() . '/modules/';
|
178 |
-
|
179 |
-
if ( isset( $_POST['mwp_action'] ) ) {
|
180 |
-
$mwp_action = ! empty( $_POST['mwp_action'] ) ? sanitize_text_field( wp_unslash( $_POST['mwp_action'] ) ) : '';
|
181 |
-
switch ( $mwp_action ) {
|
182 |
-
case 'set_showhide':
|
183 |
-
$information = $this->set_showhide();
|
184 |
-
break;
|
185 |
-
case 'save_settings':
|
186 |
-
$information = $this->save_settings();
|
187 |
-
break;
|
188 |
-
case 'whitelist_release':
|
189 |
-
$information = $this->whitelist_release();
|
190 |
-
break;
|
191 |
-
case 'backup_db':
|
192 |
-
$information = $this->backup_db();
|
193 |
-
break;
|
194 |
-
case 'admin_user':
|
195 |
-
$information = $this->admin_user();
|
196 |
-
break;
|
197 |
-
case 'database_prefix':
|
198 |
-
$information = $this->change_database_prefix();
|
199 |
-
break;
|
200 |
-
case 'reset_api_key':
|
201 |
-
$information = $this->reset_api_key();
|
202 |
-
break;
|
203 |
-
case 'malware_scan':
|
204 |
-
$information = $this->malware_scan();
|
205 |
-
break;
|
206 |
-
case 'clear_all_logs':
|
207 |
-
$information = $this->purge_logs();
|
208 |
-
break;
|
209 |
-
case 'file_change':
|
210 |
-
$information = $this->file_change();
|
211 |
-
break;
|
212 |
-
case 'release_lockout':
|
213 |
-
$information = $this->release_lockout();
|
214 |
-
break;
|
215 |
-
case 'module_status':
|
216 |
-
$information = $this->update_module_status();
|
217 |
-
break;
|
218 |
-
case 'wordpress_salts':
|
219 |
-
$information = $this->wordpress_salts();
|
220 |
-
break;
|
221 |
-
case 'file_permissions':
|
222 |
-
$information = $this->file_permissions();
|
223 |
-
break;
|
224 |
-
case 'reload_backup_exclude':
|
225 |
-
$information = $this->reload_backup_exclude();
|
226 |
-
break;
|
227 |
-
case 'security_site':
|
228 |
-
$information = $this->security_site();
|
229 |
-
break;
|
230 |
-
case 'activate_network_brute_force':
|
231 |
-
$information = $this->activate_network_brute_force();
|
232 |
-
break;
|
233 |
-
}
|
234 |
-
}
|
235 |
-
MainWP_Helper::write( $information );
|
236 |
-
}
|
237 |
-
|
238 |
-
/**
|
239 |
-
* Set show or hide UpdraftPlus Plugin from Admin & plugins list.
|
240 |
-
*
|
241 |
-
* @return array $information Return results.
|
242 |
-
*
|
243 |
-
* @uses \MainWP\Child\MainWP_Helper::update_option()
|
244 |
-
*/
|
245 |
-
public function set_showhide() {
|
246 |
-
$hide = isset( $_POST['showhide'] ) && ( 'hide' === $_POST['showhide'] ) ? 'hide' : '';
|
247 |
-
MainWP_Helper::update_option( 'mainwp_ithemes_hide_plugin', $hide );
|
248 |
-
$information['result'] = 'success';
|
249 |
-
|
250 |
-
return $information;
|
251 |
-
}
|
252 |
-
|
253 |
-
/**
|
254 |
-
* Initiate iThemes settings.
|
255 |
-
*
|
256 |
-
* @uses MainWP_Child_IThemes_Security::is_plugin_installed()
|
257 |
-
*/
|
258 |
-
public function ithemes_init() {
|
259 |
-
if ( ! $this->is_plugin_installed ) {
|
260 |
-
return;
|
261 |
-
}
|
262 |
-
|
263 |
-
if ( 'hide' === get_option( 'mainwp_ithemes_hide_plugin' ) ) {
|
264 |
-
add_filter( 'all_plugins', array( $this, 'all_plugins' ) );
|
265 |
-
add_action( 'admin_menu', array( $this, 'remove_menu' ) );
|
266 |
-
add_action( 'admin_init', array( $this, 'admin_init' ) );
|
267 |
-
add_action( 'admin_head', array( &$this, 'custom_admin_css' ) );
|
268 |
-
if ( isset( $_GET['page'] ) && ( 'itsec' == $_GET['page'] || 'itsec-security-check' == $_GET['page'] ) ) {
|
269 |
-
wp_safe_redirect( get_option( 'siteurl' ) . '/wp-admin/index.php' );
|
270 |
-
exit();
|
271 |
-
}
|
272 |
-
}
|
273 |
-
}
|
274 |
-
|
275 |
-
/**
|
276 |
-
* iThemes Security Admin initiation.
|
277 |
-
*/
|
278 |
-
public function admin_init() {
|
279 |
-
remove_meta_box( 'itsec-dashboard-widget', 'dashboard', 'normal' );
|
280 |
-
}
|
281 |
-
|
282 |
-
/**
|
283 |
-
* Remove iThemes Security from plugins page.
|
284 |
-
*
|
285 |
-
* @param array $plugins All plugins array.
|
286 |
-
*
|
287 |
-
* @return array $plugins All plugins array with iThemes Security removed.
|
288 |
-
*/
|
289 |
-
public function all_plugins( $plugins ) {
|
290 |
-
foreach ( $plugins as $key => $value ) {
|
291 |
-
$plugin_slug = basename( $key, '.php' );
|
292 |
-
if ( 'better-wp-security' === $plugin_slug || 'ithemes-security-pro' === $plugin_slug ) {
|
293 |
-
unset( $plugins[ $key ] );
|
294 |
-
}
|
295 |
-
}
|
296 |
-
|
297 |
-
return $plugins;
|
298 |
-
}
|
299 |
-
|
300 |
-
/**
|
301 |
-
* Remove iThemes Security plugin from WP Admin menu.
|
302 |
-
*/
|
303 |
-
public function remove_menu() {
|
304 |
-
remove_menu_page( 'itsec' );
|
305 |
-
}
|
306 |
-
|
307 |
-
/**
|
308 |
-
* Custom admin CSS.
|
309 |
-
*/
|
310 |
-
public function custom_admin_css() {
|
311 |
-
?>
|
312 |
-
<style type="text/css">
|
313 |
-
#wp-admin-bar-itsec_admin_bar_menu{
|
314 |
-
display: none !important;
|
315 |
-
}
|
316 |
-
</style>
|
317 |
-
<?php
|
318 |
-
}
|
319 |
-
|
320 |
-
/**
|
321 |
-
* Save UpdraftPlus settings.
|
322 |
-
*
|
323 |
-
* @return array[] $return Return Error message or Success Message.
|
324 |
-
*
|
325 |
-
* @uses \ITSEC_Lib::get_server()
|
326 |
-
* @uses \ITSEC_Lib::get_ssl_support_probability()
|
327 |
-
* @uses \ITSEC_Lib_Config_File::get_server_config()
|
328 |
-
* @uses \ITSEC_Lib_Config_File::get_wp_config()
|
329 |
-
* @uses \ITSEC_Modules::get_default()
|
330 |
-
* @uses \ITSEC_Modules::get_setting()
|
331 |
-
* @uses MainWP_Child_IThemes_Security::get_lockouts()
|
332 |
-
* @uses MainWP_Child_IThemes_Security::validate_directory()
|
333 |
-
* @uses MainWP_Child_IThemes_Security::activate_api_key()
|
334 |
-
* @uses MainWP_Child_IThemes_Security::get_excludable_tables()
|
335 |
-
* @uses MainWP_Child_IThemes_Security::get_available_admin_users_and_roles()
|
336 |
-
*/
|
337 |
-
public function save_settings() {
|
338 |
-
|
339 |
-
if ( ! class_exists( '\ITSEC_Lib' ) ) {
|
340 |
-
require \ITSEC_Core::get_core_dir() . '/core/class-itsec-lib.php';
|
341 |
-
}
|
342 |
-
|
343 |
-
$_itsec_modules = array(
|
344 |
-
'global',
|
345 |
-
'away-mode',
|
346 |
-
'backup',
|
347 |
-
'hide-backend',
|
348 |
-
'ipcheck',
|
349 |
-
'ban-users',
|
350 |
-
'brute-force',
|
351 |
-
'file-change',
|
352 |
-
'404-detection',
|
353 |
-
'network-brute-force',
|
354 |
-
'ssl',
|
355 |
-
'password-requirements',
|
356 |
-
'system-tweaks',
|
357 |
-
'wordpress-tweaks',
|
358 |
-
'multisite-tweaks',
|
359 |
-
'notification-center',
|
360 |
-
'two-factor',
|
361 |
-
);
|
362 |
-
|
363 |
-
$require_permalinks = false;
|
364 |
-
$updated = false;
|
365 |
-
$errors = array();
|
366 |
-
$nbf_settings = array();
|
367 |
-
|
368 |
-
$update_settings = isset( $_POST['settings'] ) ? maybe_unserialize( base64_decode( wp_unslash( $_POST['settings'] ) ) ) : ''; // phpcs:ignore WordPress.PHP.DiscouragedPHPFunctions -- base64_encode function is used for http encode compatible..
|
369 |
-
|
370 |
-
foreach ( $update_settings as $module => $settings ) {
|
371 |
-
$do_not_save = false;
|
372 |
-
$current_settings = \ITSEC_Modules::get_settings( $module );
|
373 |
-
if ( in_array( $module, $_itsec_modules ) ) {
|
374 |
-
if ( 'wordpress-salts' == $module ) {
|
375 |
-
$settings['last_generated'] = \ITSEC_Modules::get_setting( $module, 'last_generated' );
|
376 |
-
} elseif ( 'global' == $module ) {
|
377 |
-
$keep_olds = array( 'did_upgrade', 'log_info', 'show_new_dashboard_notice', 'show_security_check', 'nginx_file', 'manage_group' );
|
378 |
-
foreach ( $keep_olds as $key ) {
|
379 |
-
$settings[ $key ] = \ITSEC_Modules::get_setting( $module, $key );
|
380 |
-
}
|
381 |
-
|
382 |
-
if ( ! isset( $settings['log_location'] ) || empty( $settings['log_location'] ) ) {
|
383 |
-
$settings['log_location'] = \ITSEC_Modules::get_setting( $module, 'log_location' );
|
384 |
-
} else {
|
385 |
-
$result = $this->validate_directory( 'log_location', $settings['log_location'] );
|
386 |
-
if ( true !== $result ) {
|
387 |
-
$errors[] = $result;
|
388 |
-
$settings['log_location'] = \ITSEC_Modules::get_setting( $module, 'log_location' );
|
389 |
-
}
|
390 |
-
}
|
391 |
-
} elseif ( 'backup' == $module ) {
|
392 |
-
if ( ! isset( $settings['location'] ) || empty( $settings['location'] ) ) {
|
393 |
-
$settings['location'] = \ITSEC_Modules::get_setting( $module, 'location' );
|
394 |
-
} else {
|
395 |
-
$result = $this->validate_directory( 'location', $settings['location'] );
|
396 |
-
if ( true !== $result ) {
|
397 |
-
$errors[] = $result;
|
398 |
-
$settings['location'] = \ITSEC_Modules::get_setting( $module, 'location' );
|
399 |
-
}
|
400 |
-
}
|
401 |
-
if ( ! isset( $settings['exclude'] ) ) {
|
402 |
-
$settings['exclude'] = \ITSEC_Modules::get_setting( $module, 'exclude' );
|
403 |
-
|
404 |
-
}
|
405 |
-
} elseif ( 'hide-backend' == $module ) {
|
406 |
-
if ( isset( $settings['enabled'] ) && ! empty( $settings['enabled'] ) ) {
|
407 |
-
$permalink_structure = get_option( 'permalink_structure', false );
|
408 |
-
if ( empty( $permalink_structure ) && ! is_multisite() ) {
|
409 |
-
$errors[] = __( 'You must change <strong>WordPress permalinks</strong> to a setting other than "Plain" in order to use "Hide Backend" feature.', 'mainwp-child' );
|
410 |
-
$require_permalinks = true;
|
411 |
-
$do_not_save = true;
|
412 |
-
}
|
413 |
-
}
|
414 |
-
} elseif ( 'network-brute-force' == $module ) {
|
415 |
-
|
416 |
-
if ( isset( $settings['email'] ) ) {
|
417 |
-
$result = $this->activate_api_key( $settings );
|
418 |
-
if ( false === $result ) {
|
419 |
-
$nbf_settings = $settings;
|
420 |
-
$errors[] = 'Error: Active iThemes Network Brute Force Protection Api Key';
|
421 |
-
} else {
|
422 |
-
$nbf_settings = $result;
|
423 |
-
}
|
424 |
-
} else {
|
425 |
-
$previous_settings = \ITSEC_Modules::get_settings( $module );
|
426 |
-
if ( isset( $settings['enable_ban'] ) ) {
|
427 |
-
$previous_settings['enable_ban'] = $settings['enable_ban'];
|
428 |
-
$nbf_settings = $previous_settings;
|
429 |
-
} else {
|
430 |
-
$do_not_save = true;
|
431 |
-
$nbf_settings = $previous_settings;
|
432 |
-
}
|
433 |
-
}
|
434 |
-
$settings = $nbf_settings;
|
435 |
-
} elseif ( 'notification-center' == $module ) {
|
436 |
-
$current_settings = \ITSEC_Modules::get_settings( $module );
|
437 |
-
if ( isset( $settings['notifications'] ) ) {
|
438 |
-
$update_fields = array( 'schedule', 'enabled', 'subject' );
|
439 |
-
if ( isset( $_POST['is_individual'] ) && $_POST['is_individual'] ) {
|
440 |
-
$update_fields = array_merge( $update_fields, array( 'user_list', 'email_list' ) );
|
441 |
-
}
|
442 |
-
foreach ( $settings['notifications'] as $key => $val ) {
|
443 |
-
foreach ( $update_fields as $field ) {
|
444 |
-
if ( isset( $val[ $field ] ) ) {
|
445 |
-
$current_settings['notifications'][ $key ][ $field ] = $val[ $field ];
|
446 |
-
}
|
447 |
-
}
|
448 |
-
}
|
449 |
-
$updated = true;
|
450 |
-
\ITSEC_Modules::set_settings( $module, $current_settings );
|
451 |
-
}
|
452 |
-
continue;
|
453 |
-
}
|
454 |
-
|
455 |
-
if ( ! $do_not_save ) {
|
456 |
-
foreach ( $settings as $key => $val ) {
|
457 |
-
$current_settings[$key] = $val;
|
458 |
-
}
|
459 |
-
\ITSEC_Modules::set_settings( $module, $current_settings );
|
460 |
-
$updated = true;
|
461 |
-
}
|
462 |
-
}
|
463 |
-
}
|
464 |
-
|
465 |
-
if ( isset( $update_settings['itsec_active_modules'] ) ) {
|
466 |
-
$current_val = get_site_option( 'itsec_active_modules', array() );
|
467 |
-
foreach ( $update_settings['itsec_active_modules'] as $mod => $val ) {
|
468 |
-
$current_val[ $mod ] = $val;
|
469 |
-
}
|
470 |
-
update_site_option( 'itsec_active_modules', $current_val );
|
471 |
-
}
|
472 |
-
|
473 |
-
require_once \ITSEC_Core::get_core_dir() . '/lib/class-itsec-lib-config-file.php';
|
474 |
-
|
475 |
-
$values = array(
|
476 |
-
'permalink_structure' => get_option( 'permalink_structure' ),
|
477 |
-
'is_multisite' => is_multisite() ? 1 : 0,
|
478 |
-
'users_can_register' => get_site_option( 'users_can_register' ) ? 1 : 0,
|
479 |
-
'server_nginx' => ( \ITSEC_Lib::get_server() === 'nginx' ) ? 1 : 0,
|
480 |
-
'has_ssl' => \ITSEC_Lib::get_ssl_support_probability(),
|
481 |
-
'jquery_version' => \ITSEC_Modules::get_setting( 'wordpress-tweaks', 'jquery_version' ),
|
482 |
-
'server_rules' => \ITSEC_Lib_Config_File::get_server_config(),
|
483 |
-
'config_rules' => \ITSEC_Lib_Config_File::get_wp_config(),
|
484 |
-
'default_log_location' => \ITSEC_Modules::get_default( 'global', 'log_location' ),
|
485 |
-
'default_location' => \ITSEC_Modules::get_default( 'backup', 'location' ),
|
486 |
-
'excludable_tables' => $this->get_excludable_tables(),
|
487 |
-
'users_and_roles' => $this->get_available_admin_users_and_roles(),
|
488 |
-
);
|
489 |
-
|
490 |
-
$return = array(
|
491 |
-
'site_status' => $values,
|
492 |
-
);
|
493 |
-
|
494 |
-
if ( $require_permalinks ) {
|
495 |
-
$return['require_permalinks'] = 1;
|
496 |
-
}
|
497 |
-
|
498 |
-
$return['nbf_settings'] = $nbf_settings;
|
499 |
-
|
500 |
-
if ( ! empty( $errors ) ) {
|
501 |
-
$return['extra_message'] = $errors;
|
502 |
-
}
|
503 |
-
|
504 |
-
if ( $updated ) {
|
505 |
-
$return['result'] = 'success';
|
506 |
-
} else {
|
507 |
-
$return['error'] = __( 'Not Updated', 'mainwp-child' );
|
508 |
-
}
|
509 |
-
|
510 |
-
return $return;
|
511 |
-
}
|
512 |
-
|
513 |
-
/**
|
514 |
-
* Activate network brute force.
|
515 |
-
*
|
516 |
-
* @return array $information Results array.
|
517 |
-
*
|
518 |
-
* @uses \ITSEC_Modules::get_settings()
|
519 |
-
* @uses \ITSEC_Modules::activate()
|
520 |
-
*/
|
521 |
-
public static function activate_network_brute_force() {
|
522 |
-
$data = isset( $_POST['data'] ) ? maybe_unserialize( base64_decode( wp_unslash( $_POST['data'] ) ) ) : array(); // phpcs:ignore WordPress.PHP.DiscouragedPHPFunctions -- base64_encode function is used for http encode compatible..
|
523 |
-
$information = array();
|
524 |
-
if ( is_array( $data ) ) {
|
525 |
-
$settings = \ITSEC_Modules::get_settings( 'network-brute-force' );
|
526 |
-
$settings['email'] = $data['email'];
|
527 |
-
$settings['updates_optin'] = $data['updates_optin'];
|
528 |
-
$settings['api_nag'] = false;
|
529 |
-
$results = \ITSEC_Modules::set_settings( 'network-brute-force', $settings );
|
530 |
-
if ( is_wp_error( $results ) ) {
|
531 |
-
$information['error'] = 'Error: Active iThemes Network Brute Force Protection Api Key';
|
532 |
-
} elseif ( $results['saved'] ) {
|
533 |
-
\ITSEC_Modules::activate( 'network-brute-force' );
|
534 |
-
$nbf_settings = \ITSEC_Modules::get_settings( 'network-brute-force' );
|
535 |
-
}
|
536 |
-
}
|
537 |
-
if ( null !== $nbf_settings ) {
|
538 |
-
$information['nbf_settings'] = $nbf_settings;
|
539 |
-
$information['result'] = 'success';
|
540 |
-
}
|
541 |
-
return $information;
|
542 |
-
}
|
543 |
-
|
544 |
-
/**
|
545 |
-
* Validate directory.
|
546 |
-
*
|
547 |
-
* @param string $name Input name.
|
548 |
-
* @param string $folder Folder.
|
549 |
-
*
|
550 |
-
* @return bool|string Return TRUE on success or Error message on failure.
|
551 |
-
*
|
552 |
-
* @uses \ITSEC_Lib_Directory::is_dir()
|
553 |
-
* @uses \ITSEC_Lib_Directory::create()
|
554 |
-
* @uses \ITSEC_Lib_Directory::is_writable()
|
555 |
-
* @uses \ITSEC_Lib_Directory::add_file_listing_protection()
|
556 |
-
*/
|
557 |
-
private function validate_directory( $name, $folder ) {
|
558 |
-
require_once \ITSEC_Core::get_core_dir() . 'lib/class-itsec-lib-directory.php';
|
559 |
-
$error = null;
|
560 |
-
if ( ! \ITSEC_Lib_Directory::is_dir( $folder ) ) {
|
561 |
-
$result = \ITSEC_Lib_Directory::create( $folder );
|
562 |
-
|
563 |
-
if ( is_wp_error( $result ) ) {
|
564 |
-
$error = sprintf( _x( 'The directory supplied in %1$s cannot be used as a valid directory. %2$s', '%1$s is the input name. %2$s is the error message.', 'mainwp-child' ), $name, $result->get_error_message() );
|
565 |
-
}
|
566 |
-
}
|
567 |
-
|
568 |
-
if ( empty( $error ) && ! \ITSEC_Lib_Directory::is_writable( $folder ) ) {
|
569 |
-
$error = sprintf( __( 'The directory supplied in %1$s is not writable. Please select a directory that can be written to.', 'mainwp-child' ), $name );
|
570 |
-
}
|
571 |
-
|
572 |
-
if ( empty( $error ) ) {
|
573 |
-
\ITSEC_Lib_Directory::add_file_listing_protection( $folder );
|
574 |
-
return true;
|
575 |
-
} else {
|
576 |
-
return $error;
|
577 |
-
}
|
578 |
-
}
|
579 |
-
|
580 |
-
/**
|
581 |
-
* Activate api key.
|
582 |
-
*
|
583 |
-
* @param array $settings Setting array.
|
584 |
-
*
|
585 |
-
* @return array|bool Return $settings array or FALSE on failure.
|
586 |
-
*
|
587 |
-
* @uses \ITSEC_Network_Brute_Force_Utilities::get_api_key()
|
588 |
-
* @uses \ITSEC_Network_Brute_Force_Utilities::activate_api_key()
|
589 |
-
* @uses \ITSEC_Response::reload_module()
|
590 |
-
*/
|
591 |
-
private function activate_api_key( $settings ) {
|
592 |
-
|
593 |
-
/** @global string $mainwp_itsec_modules_path MainWP itsec modules path. */
|
594 |
-
global $mainwp_itsec_modules_path;
|
595 |
-
|
596 |
-
if ( file_exists( $mainwp_itsec_modules_path . 'network-brute-force/utilities.php' ) ) {
|
597 |
-
require_once $mainwp_itsec_modules_path . 'network-brute-force/utilities.php';
|
598 |
-
} else if ( file_exists( $mainwp_itsec_modules_path . 'ipcheck/utilities.php' ) ) {
|
599 |
-
require_once $mainwp_itsec_modules_path . 'ipcheck/utilities.php';
|
600 |
-
}
|
601 |
-
|
602 |
-
$key = \ITSEC_Network_Brute_Force_Utilities::get_api_key( $settings['email'], $settings['updates_optin'] );
|
603 |
-
if ( is_wp_error( $key ) ) {
|
604 |
-
return false;
|
605 |
-
} else {
|
606 |
-
$secret = \ITSEC_Network_Brute_Force_Utilities::activate_api_key( $key );
|
607 |
-
|
608 |
-
if ( is_wp_error( $secret ) ) {
|
609 |
-
return false;
|
610 |
-
} else {
|
611 |
-
$settings['api_key'] = $key;
|
612 |
-
$settings['api_secret'] = $secret;
|
613 |
-
|
614 |
-
$settings['api_nag'] = false;
|
615 |
-
|
616 |
-
\ITSEC_Response::reload_module( 'network-brute-force' );
|
617 |
-
}
|
618 |
-
}
|
619 |
-
unset( $settings['email'] );
|
620 |
-
return $settings;
|
621 |
-
}
|
622 |
-
|
623 |
-
/**
|
624 |
-
* Backup status.
|
625 |
-
*
|
626 |
-
* @return int $status 1, 2, 3 or 4
|
627 |
-
* (1) Is not a multisite installation, backupbuddy_api exists & Scheduled backups are >=1
|
628 |
-
* (2) Is not multisite and backupbuddy_api exists
|
629 |
-
* (3) Has backup = true & schedualed backup = true
|
630 |
-
* (4) Has backup = true.
|
631 |
-
*
|
632 |
-
* @uses \backupbuddy_api::getSchedules()
|
633 |
-
* @uses MainWP_Child_IThemes_Security::has_backup()
|
634 |
-
* @uses MainWP_Child_IThemes_Security::scheduled_backup()
|
635 |
-
* @uses MainWP_Child_IThemes_Security::has_backup()
|
636 |
-
*
|
637 |
-
*/
|
638 |
-
public function backup_status() {
|
639 |
-
$status = 0;
|
640 |
-
if ( ! is_multisite() && class_exists( '\backupbuddy_api' ) && count( \backupbuddy_api::getSchedules() ) >= 1 ) {
|
641 |
-
$status = 1;
|
642 |
-
} elseif ( ! is_multisite() && class_exists( '\backupbuddy_api' ) ) {
|
643 |
-
$status = 2;
|
644 |
-
} elseif ( $this->has_backup() === true && $this->scheduled_backup() === true ) {
|
645 |
-
$status = 3;
|
646 |
-
} elseif ( $this->has_backup() === true ) {
|
647 |
-
$status = 4;
|
648 |
-
}
|
649 |
-
|
650 |
-
return $status;
|
651 |
-
}
|
652 |
-
|
653 |
-
/**
|
654 |
-
* Check if backup exists.
|
655 |
-
*
|
656 |
-
* @return bool TRUE|FALSE
|
657 |
-
*/
|
658 |
-
public function has_backup() {
|
659 |
-
$has_backup = false;
|
660 |
-
|
661 |
-
return apply_filters( 'itsec_has_external_backup', $has_backup );
|
662 |
-
}
|
663 |
-
|
664 |
-
/**
|
665 |
-
* Check if there is a shedualed backup.
|
666 |
-
*
|
667 |
-
* @return bool TRUE|FALSE.
|
668 |
-
*/
|
669 |
-
public function scheduled_backup() {
|
670 |
-
$sceduled_backup = false;
|
671 |
-
|
672 |
-
return apply_filters( 'itsec_scheduled_external_backup', $sceduled_backup );
|
673 |
-
}
|
674 |
-
|
675 |
-
/**
|
676 |
-
* Whitelist Dashboard IP address.
|
677 |
-
*
|
678 |
-
* @return array|string[] Response array.
|
679 |
-
*/
|
680 |
-
public function whitelist() {
|
681 |
-
|
682 |
-
/** @global array $itsec_globals itsec globals. */
|
683 |
-
global $itsec_globals;
|
684 |
-
|
685 |
-
$ip = isset( $_POST['ip'] ) ? sanitize_text_field( wp_unslash( $_POST['ip'] ) ) : '';
|
686 |
-
$add_temp = false;
|
687 |
-
$temp_ip = get_site_option( 'itsec_temp_whitelist_ip' );
|
688 |
-
if ( false !== $temp_ip ) {
|
689 |
-
if ( ( $temp_ip['exp'] < $itsec_globals['current_time'] ) || ( $temp_ip['exp'] !== $ip ) ) {
|
690 |
-
delete_site_option( 'itsec_temp_whitelist_ip' );
|
691 |
-
$add_temp = true;
|
692 |
-
}
|
693 |
-
} else {
|
694 |
-
$add_temp = true;
|
695 |
-
}
|
696 |
-
|
697 |
-
if ( false === $add_temp ) {
|
698 |
-
return array( 'error' => 'Not Updated' );
|
699 |
-
} else {
|
700 |
-
$response = array(
|
701 |
-
'ip' => $ip,
|
702 |
-
'exp' => $itsec_globals['current_time'] + 86400,
|
703 |
-
);
|
704 |
-
add_site_option( 'itsec_temp_whitelist_ip', $response );
|
705 |
-
$response['exp_diff'] = human_time_diff( $itsec_globals['current_time'], $response['exp'] );
|
706 |
-
$response['message1'] = __( 'Your IP Address', 'mainwp-child' );
|
707 |
-
$response['message2'] = __( 'is whitelisted for', 'mainwp-child' );
|
708 |
-
|
709 |
-
return $response;
|
710 |
-
}
|
711 |
-
}
|
712 |
-
|
713 |
-
/**
|
714 |
-
* Whitelist release.
|
715 |
-
*
|
716 |
-
* @return string Return 'Success'.
|
717 |
-
*/
|
718 |
-
public function whitelist_release() {
|
719 |
-
delete_site_option( 'itsec_temp_whitelist_ip' );
|
720 |
-
|
721 |
-
return 'success';
|
722 |
-
}
|
723 |
-
|
724 |
-
/**
|
725 |
-
* Backup Database.
|
726 |
-
*
|
727 |
-
* @return array $return Return results array.
|
728 |
-
*
|
729 |
-
* @uses \ITSEC_Backup()
|
730 |
-
* @uses \ITSEC_Backup::run()
|
731 |
-
* @uses \ITSEC_Backup::do_backup()
|
732 |
-
* @uses \ITSEC_Response::get_error_strings()
|
733 |
-
*/
|
734 |
-
public function backup_db() {
|
735 |
-
|
736 |
-
/**
|
737 |
-
* @global string $mainwp_itsec_modules_path MainWP itsec modules path.
|
738 |
-
* @global object $itsec_backup ITsec backup class.
|
739 |
-
*/
|
740 |
-
global $itsec_backup, $mainwp_itsec_modules_path;
|
741 |
-
|
742 |
-
if ( ! isset( $itsec_backup ) ) {
|
743 |
-
require_once $mainwp_itsec_modules_path . 'backup/class-itsec-backup.php';
|
744 |
-
$itsec_backup = new \ITSEC_Backup();
|
745 |
-
$itsec_backup->run();
|
746 |
-
}
|
747 |
-
|
748 |
-
$return = array();
|
749 |
-
|
750 |
-
$str_error = '';
|
751 |
-
$result = $itsec_backup->do_backup( true );
|
752 |
-
|
753 |
-
if ( is_wp_error( $result ) ) {
|
754 |
-
$errors = \ITSEC_Response::get_error_strings( $result );
|
755 |
-
|
756 |
-
foreach ( $errors as $error ) {
|
757 |
-
$str_error .= $error . '<br />';
|
758 |
-
}
|
759 |
-
} elseif ( is_string( $result ) ) {
|
760 |
-
$return['result'] = 'success';
|
761 |
-
$return['message'] = $result;
|
762 |
-
} else {
|
763 |
-
$str_error = sprintf( __( 'The backup request returned an unexpected response. It returned a response of type <code>%1$s</code>.', 'mainwp-child' ), gettype( $result ) );
|
764 |
-
}
|
765 |
-
|
766 |
-
if ( ! empty( $str_error ) ) {
|
767 |
-
$return['error'] = $str_error;
|
768 |
-
}
|
769 |
-
|
770 |
-
return $return;
|
771 |
-
}
|
772 |
-
|
773 |
-
|
774 |
-
/**
|
775 |
-
* Update WordPress Salts.
|
776 |
-
*
|
777 |
-
* @return array $return Return results array.
|
778 |
-
*
|
779 |
-
* @uses \ITSEC_WordPress_Salts_Utilities::generate_new_salts()
|
780 |
-
* @uses \ITSEC_Response::get_error_strings()
|
781 |
-
* @uses \ITSEC_Core::get_current_time_gmt()
|
782 |
-
* @uses \ITSEC_Modules::set_setting()
|
783 |
-
*/
|
784 |
-
private function wordpress_salts() {
|
785 |
-
|
786 |
-
/** @global string $mainwp_itsec_modules_path MainWP itsec modules path. */
|
787 |
-
global $mainwp_itsec_modules_path;
|
788 |
-
|
789 |
-
if ( ! class_exists( '\ITSEC_WordPress_Salts_Utilities' ) ) {
|
790 |
-
require $mainwp_itsec_modules_path . 'salts/utilities.php';
|
791 |
-
}
|
792 |
-
$result = \ITSEC_WordPress_Salts_Utilities::generate_new_salts();
|
793 |
-
$str_error = '';
|
794 |
-
if ( is_wp_error( $result ) ) {
|
795 |
-
$errors = \ITSEC_Response::get_error_strings( $result );
|
796 |
-
|
797 |
-
foreach ( $errors as $error ) {
|
798 |
-
$str_error .= $error . '<br />';
|
799 |
-
}
|
800 |
-
} else {
|
801 |
-
$return['result'] = 'success';
|
802 |
-
$return['message'] = __( 'The WordPress salts were successfully regenerated.', 'mainwp-child' );
|
803 |
-
$last_generated = \ITSEC_Core::get_current_time_gmt();
|
804 |
-
\ITSEC_Modules::set_setting( 'wordpress-salts', 'last_generated', $last_generated );
|
805 |
-
}
|
806 |
-
if ( ! empty( $str_error ) ) {
|
807 |
-
$return['error'] = $str_error;
|
808 |
-
}
|
809 |
-
return $return;
|
810 |
-
}
|
811 |
-
|
812 |
-
/**
|
813 |
-
* Update file permissions.
|
814 |
-
*
|
815 |
-
* @return array Return results table html.
|
816 |
-
*
|
817 |
-
* @uses \ITSEC_Core::get_wp_upload_dir()
|
818 |
-
* @uses \ITSEC_Lib_Config_File::get_wp_config_file_path()
|
819 |
-
* @uses \ITSEC_Lib_Config_File::get_server_config_file_path()
|
820 |
-
*/
|
821 |
-
private function file_permissions() {
|
822 |
-
|
823 |
-
require_once \ITSEC_Core::get_core_dir() . '/lib/class-itsec-lib-config-file.php';
|
824 |
-
|
825 |
-
$wp_upload_dir = \ITSEC_Core::get_wp_upload_dir();
|
826 |
-
|
827 |
-
$path_data = array(
|
828 |
-
array(
|
829 |
-
ABSPATH,
|
830 |
-
0755,
|
831 |
-
),
|
832 |
-
array(
|
833 |
-
ABSPATH . WPINC,
|
834 |
-
0755,
|
835 |
-
),
|
836 |
-
array(
|
837 |
-
ABSPATH . 'wp-admin',
|
838 |
-
0755,
|
839 |
-
),
|
840 |
-
array(
|
841 |
-
ABSPATH . 'wp-admin/js',
|
842 |
-
0755,
|
843 |
-
),
|
844 |
-
array(
|
845 |
-
WP_CONTENT_DIR,
|
846 |
-
0755,
|
847 |
-
),
|
848 |
-
array(
|
849 |
-
get_theme_root(),
|
850 |
-
0755,
|
851 |
-
),
|
852 |
-
array(
|
853 |
-
WP_PLUGIN_DIR,
|
854 |
-
0755,
|
855 |
-
),
|
856 |
-
array(
|
857 |
-
$wp_upload_dir['basedir'],
|
858 |
-
0755,
|
859 |
-
),
|
860 |
-
array(
|
861 |
-
\ITSEC_Lib_Config_File::get_wp_config_file_path(),
|
862 |
-
0444,
|
863 |
-
),
|
864 |
-
array(
|
865 |
-
\ITSEC_Lib_Config_File::get_server_config_file_path(),
|
866 |
-
0444,
|
867 |
-
),
|
868 |
-
);
|
869 |
-
|
870 |
-
$rows = array();
|
871 |
-
|
872 |
-
foreach ( $path_data as $path ) {
|
873 |
-
$row = array();
|
874 |
-
|
875 |
-
list( $path, $suggested_permissions ) = $path;
|
876 |
-
|
877 |
-
$display_path = preg_replace( '/^' . preg_quote( ABSPATH, '/' ) . '/', '', $path );
|
878 |
-
$display_path = ltrim( $display_path, '/' );
|
879 |
-
|
880 |
-
if ( empty( $display_path ) ) {
|
881 |
-
$display_path = '/';
|
882 |
-
}
|
883 |
-
|
884 |
-
$row[] = $display_path;
|
885 |
-
$row[] = sprintf( '%o', $suggested_permissions );
|
886 |
-
|
887 |
-
$permissions = fileperms( $path ) & 0777;
|
888 |
-
$row[] = sprintf( '%o', $permissions );
|
889 |
-
|
890 |
-
if ( ! $permissions || $permissions != $suggested_permissions ) {
|
891 |
-
$row[] = __( 'WARNING', 'mainwp-child' );
|
892 |
-
$row[] = '<div style="background-color: #FEFF7F; border: 1px solid #E2E2E2;"> </div>';
|
893 |
-
} else {
|
894 |
-
$row[] = __( 'OK', 'mainwp-child' );
|
895 |
-
$row[] = '<div style="background-color: #22EE5B; border: 1px solid #E2E2E2;"> </div>';
|
896 |
-
}
|
897 |
-
|
898 |
-
$rows[] = $row;
|
899 |
-
}
|
900 |
-
|
901 |
-
$class = 'entry-row';
|
902 |
-
ob_start();
|
903 |
-
?>
|
904 |
-
<p><input type="button" id="itsec-file-permissions-reload_file_permissions" name="file-permissions[reload_file_permissions]" class="button-primary itsec-reload-module" value="<?php esc_attr_e( 'Reload File Permissions Details', 'mainwp-child' ); ?>"></p>
|
905 |
-
<table class="widefat">
|
906 |
-
<thead>
|
907 |
-
<tr>
|
908 |
-
<th><?php esc_html_e( 'Relative Path', 'mainwp-child' ); ?></th>
|
909 |
-
<th><?php esc_html_e( 'Suggestion', 'mainwp-child' ); ?></th>
|
910 |
-
<th><?php esc_html_e( 'Value', 'mainwp-child' ); ?></th>
|
911 |
-
<th><?php esc_html_e( 'Result', 'mainwp-child' ); ?></th>
|
912 |
-
<th><?php esc_html_e( 'Status', 'mainwp-child' ); ?></th>
|
913 |
-
</tr>
|
914 |
-
</thead>
|
915 |
-
<tfoot>
|
916 |
-
<tr>
|
917 |
-
<th><?php esc_html_e( 'Relative Path', 'mainwp-child' ); ?></th>
|
918 |
-
<th><?php esc_html_e( 'Suggestion', 'mainwp-child' ); ?></th>
|
919 |
-
<th><?php esc_html_e( 'Value', 'mainwp-child' ); ?></th>
|
920 |
-
<th><?php esc_html_e( 'Result', 'mainwp-child' ); ?></th>
|
921 |
-
<th><?php esc_html_e( 'Status', 'mainwp-child' ); ?></th>
|
922 |
-
</tr>
|
923 |
-
</tfoot>
|
924 |
-
<tbody>
|
925 |
-
<?php foreach ( $rows as $row ) : ?>
|
926 |
-
<tr class="<?php echo $class; ?>">
|
927 |
-
<?php foreach ( $row as $column ) : ?>
|
928 |
-
<td><?php echo $column; ?></td>
|
929 |
-
<?php endforeach; ?>
|
930 |
-
</tr>
|
931 |
-
<?php $class = ( 'entry-row' === $class ) ? 'entry-row alternate' : 'entry-row'; ?>
|
932 |
-
<?php endforeach; ?>
|
933 |
-
</tbody>
|
934 |
-
</table>
|
935 |
-
<br />
|
936 |
-
<?php
|
937 |
-
$html = ob_get_clean();
|
938 |
-
return array( 'html' => $html );
|
939 |
-
}
|
940 |
-
|
941 |
-
/**
|
942 |
-
* Run File Change scanner.
|
943 |
-
*
|
944 |
-
* @return array $return results array.
|
945 |
-
*
|
946 |
-
* @uses \ITSEC_File_Change_Scanner::run_scan()
|
947 |
-
*/
|
948 |
-
public function file_change() {
|
949 |
-
|
950 |
-
/** @global string $mainwp_itsec_modules_path MainWP itsec modules path. */
|
951 |
-
global $mainwp_itsec_modules_path;
|
952 |
-
|
953 |
-
if ( ! class_exists( '\ITSEC_File_Change_Scanner' ) ) {
|
954 |
-
require_once $mainwp_itsec_modules_path . 'file-change/scanner.php';
|
955 |
-
}
|
956 |
-
|
957 |
-
$results = \ITSEC_File_Change_Scanner::schedule_start();
|
958 |
-
|
959 |
-
if ( is_wp_error( $results ) ) {
|
960 |
-
$error = $results->get_error_message();
|
961 |
-
$return['result'] = 'failed';
|
962 |
-
$return['scan_error'] = $error;
|
963 |
-
} else {
|
964 |
-
$return['result'] = 'success';
|
965 |
-
$return['scan_result'] = $results;
|
966 |
-
}
|
967 |
-
return $return;
|
968 |
-
}
|
969 |
-
|
970 |
-
/**
|
971 |
-
* Update admin user.
|
972 |
-
*
|
973 |
-
* @return array Return Success or Fail.
|
974 |
-
*
|
975 |
-
* @uses \ITSEC_Lib::user_id_exists()
|
976 |
-
* @uses MainWP_Child_IThemes_Security::change_admin_user()
|
977 |
-
*/
|
978 |
-
public function admin_user() {
|
979 |
-
|
980 |
-
$settings = isset( $_POST['settings'] ) ? wp_unslash( $_POST['settings'] ) : array();
|
981 |
-
|
982 |
-
if ( ! is_array( $settings ) ) {
|
983 |
-
$settings = array();
|
984 |
-
}
|
985 |
-
|
986 |
-
$new_username = isset( $settings['new_username'] ) ? $settings['new_username'] : '';
|
987 |
-
$change_id = isset( $settings['change_id'] ) && $settings['change_id'] ? true : false;
|
988 |
-
|
989 |
-
if ( ! class_exists( '\ITSEC_Lib' ) ) {
|
990 |
-
|
991 |
-
/** @global object $itsec_globals ITsec globals. */
|
992 |
-
global $itsec_globals;
|
993 |
-
|
994 |
-
require \ITSEC_Core::get_core_dir() . '/core/class-itsec-lib.php';
|
995 |
-
}
|
996 |
-
|
997 |
-
$username_exists = username_exists( 'admin' );
|
998 |
-
$user_id_exists = \ITSEC_Lib::user_id_exists( 1 );
|
999 |
-
$msg = '';
|
1000 |
-
if ( strlen( $new_username ) >= 1 ) {
|
1001 |
-
|
1002 |
-
/** @global string $current_user Current user global variable. */
|
1003 |
-
global $current_user;
|
1004 |
-
|
1005 |
-
if ( ! $username_exists ) {
|
1006 |
-
$msg = __( 'Admin user already changes.', 'mainwp-child' );
|
1007 |
-
} elseif ( 'admin' == $current_user->user_login ) {
|
1008 |
-
$return['result'] = 'CHILD_ADMIN';
|
1009 |
-
return $return;
|
1010 |
-
}
|
1011 |
-
}
|
1012 |
-
|
1013 |
-
if ( true === $change_id && ! $user_id_exists ) {
|
1014 |
-
if ( ! empty( $msg ) ) {
|
1015 |
-
$msg .= '<br/>';
|
1016 |
-
}
|
1017 |
-
$msg .= __( 'Admin user ID already changes.', 'mainwp-child' );
|
1018 |
-
}
|
1019 |
-
|
1020 |
-
$admin_success = true;
|
1021 |
-
$return = array();
|
1022 |
-
|
1023 |
-
if ( strlen( $new_username ) >= 1 && $username_exists ) {
|
1024 |
-
$admin_success = $this->change_admin_user( $new_username, $change_id );
|
1025 |
-
} elseif ( true === $change_id && $user_id_exists ) {
|
1026 |
-
$admin_success = $this->change_admin_user( null, $change_id );
|
1027 |
-
}
|
1028 |
-
|
1029 |
-
$return['message'] = $msg;
|
1030 |
-
if ( false === $admin_success ) {
|
1031 |
-
$return['result'] = 'fail';
|
1032 |
-
} else {
|
1033 |
-
$return['result'] = 'success';
|
1034 |
-
}
|
1035 |
-
return $return;
|
1036 |
-
}
|
1037 |
-
|
1038 |
-
/**
|
1039 |
-
* Change admin user.
|
1040 |
-
*
|
1041 |
-
* @param string $username Username to update to. Default: null.
|
1042 |
-
* @param bool $id User Id found. Default: false.
|
1043 |
-
* @return bool Return TRUE on success and FALSE on failure.
|
1044 |
-
*
|
1045 |
-
* @uses \ITSEC_Core::get_itsec_files()
|
1046 |
-
* @uses \ITSEC_Core::get_itsec_files::release_file_lock()
|
1047 |
-
*/
|
1048 |
-
private function change_admin_user($username = null, $id = false ) {
|
1049 |
-
|
1050 |
-
/** @global object $wpdb WordPress Database */
|
1051 |
-
global $wpdb;
|
1052 |
-
|
1053 |
-
$itsec_files = \ITSEC_Core::get_itsec_files();
|
1054 |
-
|
1055 |
-
$new_user = sanitize_text_field( $username );
|
1056 |
-
|
1057 |
-
$user_object = get_user_by( 'id', '1' );
|
1058 |
-
|
1059 |
-
if ( null !== $username && validate_username( $new_user ) && false === username_exists( $new_user ) ) {
|
1060 |
-
|
1061 |
-
if ( true === $id ) {
|
1062 |
-
|
1063 |
-
$user_login = $new_user;
|
1064 |
-
|
1065 |
-
} else {
|
1066 |
-
|
1067 |
-
$wpdb->query( 'UPDATE `' . $wpdb->users . "` SET user_login = '" . esc_sql( $new_user ) . "' WHERE user_login='admin';" );
|
1068 |
-
|
1069 |
-
if ( is_multisite() ) {
|
1070 |
-
$oldAdmins = $wpdb->get_var( 'SELECT meta_value FROM `' . $wpdb->sitemeta . "` WHERE meta_key = 'site_admins'" );
|
1071 |
-
$newAdmins = str_replace( '5:"admin"', strlen( $new_user ) . ':"' . esc_sql( $new_user ) . '"', $oldAdmins );
|
1072 |
-
$wpdb->query( $wpdb->prepare( 'UPDATE `' . $wpdb->sitemeta . "` SET meta_value = %s WHERE meta_key = 'site_admins'", $newAdmins ) );
|
1073 |
-
}
|
1074 |
-
|
1075 |
-
wp_clear_auth_cookie();
|
1076 |
-
$itsec_files->release_file_lock( 'admin_user' );
|
1077 |
-
|
1078 |
-
return true;
|
1079 |
-
|
1080 |
-
}
|
1081 |
-
} elseif ( null !== $username ) {
|
1082 |
-
|
1083 |
-
$itsec_files->release_file_lock( 'admin_user' );
|
1084 |
-
|
1085 |
-
return false;
|
1086 |
-
|
1087 |
-
} else {
|
1088 |
-
|
1089 |
-
$user_login = $user_object->user_login;
|
1090 |
-
|
1091 |
-
}
|
1092 |
-
|
1093 |
-
if ( true === $id ) {
|
1094 |
-
|
1095 |
-
$wpdb->query( 'DELETE FROM `' . $wpdb->users . '` WHERE ID = 1;' );
|
1096 |
-
|
1097 |
-
$wpdb->insert(
|
1098 |
-
$wpdb->users,
|
1099 |
-
array(
|
1100 |
-
'user_login' => $user_login,
|
1101 |
-
'user_pass' => $user_object->user_pass,
|
1102 |
-
'user_nicename' => $user_object->user_nicename,
|
1103 |
-
'user_email' => $user_object->user_email,
|
1104 |
-
'user_url' => $user_object->user_url,
|
1105 |
-
'user_registered' => $user_object->user_registered,
|
1106 |
-
'user_activation_key' => $user_object->user_activation_key,
|
1107 |
-
'user_status' => $user_object->user_status,
|
1108 |
-
'display_name' => $user_object->display_name,
|
1109 |
-
)
|
1110 |
-
);
|
1111 |
-
|
1112 |
-
if ( is_multisite() && null !== $username && validate_username( $new_user ) ) {
|
1113 |
-
|
1114 |
-
$oldAdmins = $wpdb->get_var( 'SELECT meta_value FROM `' . $wpdb->sitemeta . "` WHERE meta_key = 'site_admins'" );
|
1115 |
-
$newAdmins = str_replace( '5:"admin"', strlen( $new_user ) . ':"' . esc_sql( $new_user ) . '"', $oldAdmins );
|
1116 |
-
$wpdb->query( 'UPDATE `' . $wpdb->sitemeta . "` SET meta_value = '" . esc_sql( $newAdmins ) . "' WHERE meta_key = 'site_admins'" );
|
1117 |
-
|
1118 |
-
}
|
1119 |
-
|
1120 |
-
$new_user = $wpdb->insert_id;
|
1121 |
-
|
1122 |
-
$wpdb->query( $wpdb->prepare( 'UPDATE `' . $wpdb->posts . '` SET post_author = %s WHERE post_author = 1;', $new_user ) );
|
1123 |
-
$wpdb->query( $wpdb->prepare( 'UPDATE `' . $wpdb->usermeta . '` SET user_id = %s WHERE user_id = 1;', $new_user ) );
|
1124 |
-
$wpdb->query( $wpdb->prepare( 'UPDATE `' . $wpdb->comments . '` SET user_id = %s WHERE user_id = 1;', $new_user ) );
|
1125 |
-
$wpdb->query( $wpdb->prepare( 'UPDATE `' . $wpdb->links . '` SET link_owner = %s WHERE link_owner = 1;', $new_user ) );
|
1126 |
-
|
1127 |
-
wp_clear_auth_cookie();
|
1128 |
-
$itsec_files->release_file_lock( 'admin_user' );
|
1129 |
-
|
1130 |
-
return true;
|
1131 |
-
|
1132 |
-
}
|
1133 |
-
|
1134 |
-
return false;
|
1135 |
-
}
|
1136 |
-
|
1137 |
-
/**
|
1138 |
-
* Build WP_config rules.
|
1139 |
-
*
|
1140 |
-
* @param array $rules_array Config rules array.
|
1141 |
-
* @param null $input New directory input.
|
1142 |
-
*
|
1143 |
-
* @return array Return $rules_array.
|
1144 |
-
*/
|
1145 |
-
public function build_wpconfig_rules( $rules_array, $input = null ) {
|
1146 |
-
if ( null === $input ) {
|
1147 |
-
return $rules_array;
|
1148 |
-
}
|
1149 |
-
|
1150 |
-
$new_dir = trailingslashit( ABSPATH ) . $input;
|
1151 |
-
|
1152 |
-
$rules[] = array(
|
1153 |
-
'type' => 'add',
|
1154 |
-
'search_text' => '//Do not delete these. Doing so WILL break your site.',
|
1155 |
-
'rule' => '//Do not delete these. Doing so WILL break your site.',
|
1156 |
-
);
|
1157 |
-
|
1158 |
-
$rules[] = array(
|
1159 |
-
'type' => 'add',
|
1160 |
-
'search_text' => 'WP_CONTENT_URL',
|
1161 |
-
'rule' => "define( 'WP_CONTENT_URL', '" . trailingslashit( get_option( 'siteurl' ) ) . $input . "' );",
|
1162 |
-
);
|
1163 |
-
|
1164 |
-
$rules[] = array(
|
1165 |
-
'type' => 'add',
|
1166 |
-
'search_text' => 'WP_CONTENT_DIR',
|
1167 |
-
'rule' => "define( 'WP_CONTENT_DIR', '" . $new_dir . "' );",
|
1168 |
-
);
|
1169 |
-
|
1170 |
-
$rules_array[] = array(
|
1171 |
-
'type' => 'wpconfig',
|
1172 |
-
'name' => 'Content Directory',
|
1173 |
-
'rules' => $rules,
|
1174 |
-
);
|
1175 |
-
|
1176 |
-
return $rules_array;
|
1177 |
-
}
|
1178 |
-
|
1179 |
-
|
1180 |
-
/**
|
1181 |
-
* Change database prefix.
|
1182 |
-
*
|
1183 |
-
* @return array $return Return response array.
|
1184 |
-
*
|
1185 |
-
* @uses \ITSEC_Database_Prefix_Utility::change_database_prefix()
|
1186 |
-
* @uses \ITSEC_Response::get_error_strings()
|
1187 |
-
* @uses \ITSEC_Response::reload_module()
|
1188 |
-
*/
|
1189 |
-
public function change_database_prefix() {
|
1190 |
-
|
1191 |
-
/** @global string $mainwp_itsec_modules_path MainWP itsec modules path. */
|
1192 |
-
global $mainwp_itsec_modules_path;
|
1193 |
-
|
1194 |
-
require_once $mainwp_itsec_modules_path . 'database-prefix/utility.php';
|
1195 |
-
$str_error = '';
|
1196 |
-
$return = array();
|
1197 |
-
|
1198 |
-
if ( isset( $_POST['change_prefix'] ) && 'yes' === $_POST['change_prefix'] ) {
|
1199 |
-
$result = \ITSEC_Database_Prefix_Utility::change_database_prefix();
|
1200 |
-
$return = $result['errors'];
|
1201 |
-
if ( is_array( $result['errors'] ) ) {
|
1202 |
-
foreach ( $result['errors'] as $error ) {
|
1203 |
-
$arr_errors = \ITSEC_Response::get_error_strings( $error );
|
1204 |
-
foreach ( $arr_errors as $er ) {
|
1205 |
-
$str_error .= $er . '<br />';
|
1206 |
-
}
|
1207 |
-
}
|
1208 |
-
}
|
1209 |
-
|
1210 |
-
\ITSEC_Response::reload_module( 'database-prefix' );
|
1211 |
-
|
1212 |
-
if ( false === $result['new_prefix'] ) {
|
1213 |
-
$return['error'] = $str_error;
|
1214 |
-
} else {
|
1215 |
-
$return['result'] = 'success';
|
1216 |
-
$return['message'] = sprintf( __( 'The database table prefix was successfully changed to <code>%1$s</code>.', 'mainwp-child' ), $result['new_prefix'] );
|
1217 |
-
|
1218 |
-
}
|
1219 |
-
}
|
1220 |
-
return $return;
|
1221 |
-
}
|
1222 |
-
|
1223 |
-
/**
|
1224 |
-
* Update API key.
|
1225 |
-
*
|
1226 |
-
* @return array $return Return response array. Success or nochange.
|
1227 |
-
*/
|
1228 |
-
public function api_key() {
|
1229 |
-
$settings = get_site_option( 'itsec_ipcheck' );
|
1230 |
-
if ( ! is_array( $settings ) ) {
|
1231 |
-
$settings = array();
|
1232 |
-
}
|
1233 |
-
$settings['reset'] = true;
|
1234 |
-
$return = array();
|
1235 |
-
if ( update_site_option( 'itsec_ipcheck', $settings ) ) {
|
1236 |
-
$return['result'] = 'success';
|
1237 |
-
} else {
|
1238 |
-
$return['result'] = 'nochange';
|
1239 |
-
}
|
1240 |
-
|
1241 |
-
return $return;
|
1242 |
-
}
|
1243 |
-
|
1244 |
-
/**
|
1245 |
-
* Reset api key.
|
1246 |
-
*
|
1247 |
-
* @return array $information Return response array.
|
1248 |
-
*
|
1249 |
-
* @uses \ITSEC_Modules::get_defaults()
|
1250 |
-
* @uses \ITSEC_Modules::set_defaults()
|
1251 |
-
* @uses \ITSEC_Response::set_response()
|
1252 |
-
* @uses \ITSEC_Response::add_errors()
|
1253 |
-
* @uses \ITSEC_Response::add_messages()
|
1254 |
-
*/
|
1255 |
-
public function reset_api_key() {
|
1256 |
-
|
1257 |
-
$defaults = \ITSEC_Modules::get_defaults( 'network-brute-force' );
|
1258 |
-
$results = \ITSEC_Modules::set_settings( 'network-brute-force', $defaults );
|
1259 |
-
|
1260 |
-
\ITSEC_Response::set_response( $results['saved'] );
|
1261 |
-
\ITSEC_Response::add_errors( $results['errors'] );
|
1262 |
-
\ITSEC_Response::add_messages( $results['messages'] );
|
1263 |
-
|
1264 |
-
$information = array();
|
1265 |
-
if ( $results['saved'] ) {
|
1266 |
-
$information['result'] = 'success';
|
1267 |
-
$information['nbf_settings'] = \ITSEC_Modules::get_settings( 'network-brute-force' );
|
1268 |
-
} elseif ( empty( $results['errors'] ) ) {
|
1269 |
-
$information['error_reset_api'] = 1;
|
1270 |
-
}
|
1271 |
-
return $information;
|
1272 |
-
}
|
1273 |
-
|
1274 |
-
/**
|
1275 |
-
* Malware scan.
|
1276 |
-
*
|
1277 |
-
* @return array $response Return response array.
|
1278 |
-
*
|
1279 |
-
* @uses \ITSEC_Core::current_user_can_manage()
|
1280 |
-
* @uses \ITSEC_Malware_Scanner::scan()
|
1281 |
-
* @uses \ITSEC_Malware_Scan_Results_Template::get_html()
|
1282 |
-
*/
|
1283 |
-
public function malware_scan() {
|
1284 |
-
|
1285 |
-
/** @global string $mainwp_itsec_modules_path MainWP itsec modules path. */
|
1286 |
-
global $mainwp_itsec_modules_path;
|
1287 |
-
|
1288 |
-
if ( ! class_exists( '\ITSEC_Malware_Scanner' ) ) {
|
1289 |
-
require_once $mainwp_itsec_modules_path . 'malware/class-itsec-malware-scanner.php';
|
1290 |
-
require_once $mainwp_itsec_modules_path . 'malware/class-itsec-malware-scan-results-template.php';
|
1291 |
-
}
|
1292 |
-
|
1293 |
-
$response = array();
|
1294 |
-
if ( ! \ITSEC_Core::current_user_can_manage() ) {
|
1295 |
-
$response['error'] = 'The currently logged in user does not have sufficient permissions to run this scan.';
|
1296 |
-
} else {
|
1297 |
-
$results = \ITSEC_Malware_Scanner::scan();
|
1298 |
-
$response['html'] = \ITSEC_Malware_Scan_Results_Template::get_html( $results, true );
|
1299 |
-
}
|
1300 |
-
|
1301 |
-
return $response;
|
1302 |
-
}
|
1303 |
-
|
1304 |
-
/**
|
1305 |
-
* Get malware scan results.
|
1306 |
-
*
|
1307 |
-
* @return array $response Return response array.
|
1308 |
-
*
|
1309 |
-
* @uses \ITSEC_Malware_Scanner::scan()
|
1310 |
-
* @uses \ITSEC_Malware_Scan_Results_Template::get_html()
|
1311 |
-
*/
|
1312 |
-
public function malware_get_scan_results() {
|
1313 |
-
|
1314 |
-
/** @global string $mainwp_itsec_modules_path MainWP itsec modules path. */
|
1315 |
-
global $mainwp_itsec_modules_path;
|
1316 |
-
|
1317 |
-
if ( ! class_exists( '\ITSEC_Malware_Scanner' ) ) {
|
1318 |
-
require_once $mainwp_itsec_modules_path . 'malware/class-itsec-malware-scanner.php';
|
1319 |
-
require_once $mainwp_itsec_modules_path . 'malware/class-itsec-malware-scan-results-template.php';
|
1320 |
-
}
|
1321 |
-
$response = array();
|
1322 |
-
$results = \ITSEC_Malware_Scanner::scan();
|
1323 |
-
$response['html'] = \ITSEC_Malware_Scan_Results_Template::get_html( $results, true );
|
1324 |
-
return $response;
|
1325 |
-
}
|
1326 |
-
|
1327 |
-
/**
|
1328 |
-
* Purge logs.
|
1329 |
-
*
|
1330 |
-
* @return string[] Return response array.
|
1331 |
-
*/
|
1332 |
-
public function purge_logs() {
|
1333 |
-
|
1334 |
-
/** @global object $wpdb WordPress Database object. */
|
1335 |
-
global $wpdb;
|
1336 |
-
|
1337 |
-
$wpdb->query( 'DELETE FROM `' . $wpdb->base_prefix . 'itsec_log`;' );
|
1338 |
-
|
1339 |
-
return array( 'result' => 'success' );
|
1340 |
-
}
|
1341 |
-
|
1342 |
-
|
1343 |
-
/**
|
1344 |
-
* Get lockouts.
|
1345 |
-
*
|
1346 |
-
* @param string $type Type of lockout: Host, user, username, Default: all.
|
1347 |
-
* @param bool $current TRUE if current. Default: FALSE.
|
1348 |
-
*
|
1349 |
-
* @return array $output Return response array.
|
1350 |
-
*
|
1351 |
-
* @uses MainWP_Child_IThemes_Security::get_lockouts_int()
|
1352 |
-
*/
|
1353 |
-
public function get_lockouts( $type = 'all', $current = false ) {
|
1354 |
-
|
1355 |
-
/**
|
1356 |
-
* @global object $wpdb WordPress Database object.
|
1357 |
-
* @global object $itsec_globals itsec globals.
|
1358 |
-
*/
|
1359 |
-
global $wpdb, $itsec_globals;
|
1360 |
-
|
1361 |
-
if ( 'all' !== $type || true === $current ) {
|
1362 |
-
$where = ' WHERE ';
|
1363 |
-
} else {
|
1364 |
-
$where = '';
|
1365 |
-
}
|
1366 |
-
|
1367 |
-
switch ( $type ) {
|
1368 |
-
|
1369 |
-
case 'host':
|
1370 |
-
$type_statement = "`lockout_host` IS NOT NULL && `lockout_host` != ''";
|
1371 |
-
break;
|
1372 |
-
case 'user':
|
1373 |
-
$type_statement = '`lockout_user` != 0';
|
1374 |
-
break;
|
1375 |
-
case 'username':
|
1376 |
-
$type_statement = "`lockout_username` IS NOT NULL && `lockout_username` != ''";
|
1377 |
-
break;
|
1378 |
-
default:
|
1379 |
-
$type_statement = '';
|
1380 |
-
break;
|
1381 |
-
|
1382 |
-
}
|
1383 |
-
|
1384 |
-
if ( true === $current ) {
|
1385 |
-
|
1386 |
-
if ( '' !== $type_statement ) {
|
1387 |
-
$and = ' AND ';
|
1388 |
-
} else {
|
1389 |
-
$and = '';
|
1390 |
-
}
|
1391 |
-
|
1392 |
-
$active = $and . " `lockout_active`=1 AND `lockout_expire_gmt` > '" . gmdate( 'Y-m-d H:i:s', $itsec_globals['current_time_gmt'] ) . "'";
|
1393 |
-
|
1394 |
-
} else {
|
1395 |
-
|
1396 |
-
$active = '';
|
1397 |
-
|
1398 |
-
}
|
1399 |
-
$results = $wpdb->get_results( 'SELECT * FROM `' . $wpdb->base_prefix . 'itsec_lockouts`' . $where . $type_statement . $active . ';', ARRAY_A ); // phpcs:ignore -- safe query. $output = array();
|
1400 |
-
|
1401 |
-
return $this->get_lockouts_int( $results, $type );
|
1402 |
-
}
|
1403 |
-
|
1404 |
-
/**
|
1405 |
-
* Initiate get lockouts.
|
1406 |
-
*
|
1407 |
-
* @param array $results Results from MainWP_Child_IThemes_Security::get_lockouts()
|
1408 |
-
* @param string $type Type of lockout: Host, user, username, Default: all.
|
1409 |
-
*
|
1410 |
-
* @return array $output Return response array.
|
1411 |
-
*/
|
1412 |
-
private function get_lockouts_int($results, $type ){
|
1413 |
-
|
1414 |
-
if ( is_array( $results ) && count( $results ) > 0 ) {
|
1415 |
-
switch ( $type ) {
|
1416 |
-
case 'host':
|
1417 |
-
foreach ( $results as $val ) {
|
1418 |
-
$output[] = array(
|
1419 |
-
'lockout_id' => $val['lockout_id'],
|
1420 |
-
'lockout_host' => $val['lockout_host'],
|
1421 |
-
'lockout_expire_gmt' => $val['lockout_expire_gmt'],
|
1422 |
-
);
|
1423 |
-
}
|
1424 |
-
break;
|
1425 |
-
case 'user':
|
1426 |
-
foreach ( $results as $val ) {
|
1427 |
-
$output[] = array(
|
1428 |
-
'lockout_id' => $val['lockout_id'],
|
1429 |
-
'lockout_user' => $val['lockout_user'],
|
1430 |
-
'lockout_expire_gmt' => $val['lockout_expire_gmt'],
|
1431 |
-
);
|
1432 |
-
}
|
1433 |
-
break;
|
1434 |
-
case 'username':
|
1435 |
-
foreach ( $results as $val ) {
|
1436 |
-
$output[] = array(
|
1437 |
-
'lockout_id' => $val['lockout_id'],
|
1438 |
-
'lockout_username' => $val['lockout_username'],
|
1439 |
-
'lockout_expire_gmt' => $val['lockout_expire_gmt'],
|
1440 |
-
);
|
1441 |
-
}
|
1442 |
-
break;
|
1443 |
-
default:
|
1444 |
-
break;
|
1445 |
-
}
|
1446 |
-
}
|
1447 |
-
|
1448 |
-
return $output;
|
1449 |
-
|
1450 |
-
}
|
1451 |
-
|
1452 |
-
/**
|
1453 |
-
* Release lockout.
|
1454 |
-
*
|
1455 |
-
* @return string[] Return results array.
|
1456 |
-
*
|
1457 |
-
* @uses \ITSEC_Lib::clear_caches()
|
1458 |
-
*/
|
1459 |
-
public function release_lockout() {
|
1460 |
-
|
1461 |
-
/** @global object $wpdb WordPress Database. */
|
1462 |
-
global $wpdb;
|
1463 |
-
|
1464 |
-
if ( ! class_exists( '\ITSEC_Lib' ) ) {
|
1465 |
-
require \ITSEC_Core::get_core_dir() . '/core/class-itsec-lib.php';
|
1466 |
-
}
|
1467 |
-
|
1468 |
-
$lockout_ids = array_map( 'sanitize_text_field', wp_unslash( $_POST['lockout_ids'] ) );
|
1469 |
-
if ( ! is_array( $lockout_ids ) ) {
|
1470 |
-
$lockout_ids = array();
|
1471 |
-
}
|
1472 |
-
|
1473 |
-
$type = 'updated';
|
1474 |
-
$message = __( 'The selected lockouts have been cleared.', 'mainwp-child' );
|
1475 |
-
|
1476 |
-
foreach ( $lockout_ids as $value ) {
|
1477 |
-
$wpdb->update(
|
1478 |
-
$wpdb->base_prefix . 'itsec_lockouts',
|
1479 |
-
array(
|
1480 |
-
'lockout_active' => 0,
|
1481 |
-
),
|
1482 |
-
array(
|
1483 |
-
'lockout_id' => intval( $value ),
|
1484 |
-
)
|
1485 |
-
);
|
1486 |
-
}
|
1487 |
-
|
1488 |
-
\ITSEC_Lib::clear_caches();
|
1489 |
-
|
1490 |
-
if ( ! is_multisite() ) {
|
1491 |
-
if ( ! function_exists( 'add_settings_error' ) ) {
|
1492 |
-
require_once ABSPATH . '/wp-admin/includes/template.php';
|
1493 |
-
}
|
1494 |
-
|
1495 |
-
add_settings_error( 'itsec', esc_attr( 'settings_updated' ), $message, $type );
|
1496 |
-
}
|
1497 |
-
|
1498 |
-
return array(
|
1499 |
-
'result' => 'success',
|
1500 |
-
);
|
1501 |
-
}
|
1502 |
-
|
1503 |
-
/**
|
1504 |
-
* Update module status.
|
1505 |
-
*
|
1506 |
-
* @return string[] Return response array.
|
1507 |
-
*/
|
1508 |
-
public function update_module_status() {
|
1509 |
-
|
1510 |
-
$active_modules = isset( $_POST['active_modules'] ) ? array_map( 'sanitize_text_field', wp_unslash( $_POST['active_modules'] ) ) : array();
|
1511 |
-
|
1512 |
-
if ( ! is_array( $active_modules ) ) {
|
1513 |
-
$active_modules = array();
|
1514 |
-
}
|
1515 |
-
|
1516 |
-
$current_val = get_site_option( 'itsec_active_modules', array() );
|
1517 |
-
foreach ( $active_modules as $mod => $val ) {
|
1518 |
-
$current_val[ $mod ] = $val;
|
1519 |
-
}
|
1520 |
-
|
1521 |
-
update_site_option( 'itsec_active_modules', $current_val );
|
1522 |
-
return array( 'result' => 'success' );
|
1523 |
-
}
|
1524 |
-
|
1525 |
-
/**
|
1526 |
-
* Reload excluded backups table.
|
1527 |
-
*
|
1528 |
-
* @return array Return response array.
|
1529 |
-
*
|
1530 |
-
* @uses \ITSEC_Modules::get_setting()
|
1531 |
-
* @uses MainWP_Child_IThemes_Security::get_excludable_tables()
|
1532 |
-
*/
|
1533 |
-
private function reload_backup_exclude() {
|
1534 |
-
return array(
|
1535 |
-
'exclude' => \ITSEC_Modules::get_setting( 'backup', 'exclude' ),
|
1536 |
-
'excludable_tables' => $this->get_excludable_tables(),
|
1537 |
-
'result' => 'success',
|
1538 |
-
);
|
1539 |
-
}
|
1540 |
-
|
1541 |
-
/**
|
1542 |
-
* Get excludable backups table.
|
1543 |
-
*
|
1544 |
-
* @return array $excludes Return response array.
|
1545 |
-
*
|
1546 |
-
* @uses \ITSEC_Modules::get_setting()
|
1547 |
-
*/
|
1548 |
-
private function get_excludable_tables() {
|
1549 |
-
|
1550 |
-
/** @global object $wpdb WordPress Database. */
|
1551 |
-
global $wpdb;
|
1552 |
-
|
1553 |
-
$all_sites = \ITSEC_Modules::get_setting( 'backup', 'all_sites' );
|
1554 |
-
$ignored_tables = array(
|
1555 |
-
'commentmeta',
|
1556 |
-
'comments',
|
1557 |
-
'links',
|
1558 |
-
'options',
|
1559 |
-
'postmeta',
|
1560 |
-
'posts',
|
1561 |
-
'term_relationships',
|
1562 |
-
'term_taxonomy',
|
1563 |
-
'terms',
|
1564 |
-
'usermeta',
|
1565 |
-
'users',
|
1566 |
-
);
|
1567 |
-
|
1568 |
-
if ( $all_sites ) {
|
1569 |
-
$query = 'SHOW TABLES';
|
1570 |
-
} else {
|
1571 |
-
$query = $wpdb->prepare( 'SHOW TABLES LIKE %s', "{$wpdb->base_prefix}%" );
|
1572 |
-
}
|
1573 |
-
|
1574 |
-
$tables = $wpdb->get_results( $query, ARRAY_N ); // phpcs:ignore -- safe query.
|
1575 |
-
$excludes = array();
|
1576 |
-
|
1577 |
-
foreach ( $tables as $table ) {
|
1578 |
-
$short_table = substr( $table[0], strlen( $wpdb->prefix ) );
|
1579 |
-
|
1580 |
-
if ( in_array( $short_table, $ignored_tables ) ) {
|
1581 |
-
continue;
|
1582 |
-
}
|
1583 |
-
|
1584 |
-
$excludes[ $short_table ] = $table[0];
|
1585 |
-
}
|
1586 |
-
|
1587 |
-
return $excludes;
|
1588 |
-
}
|
1589 |
-
|
1590 |
-
/**
|
1591 |
-
* Get security check results.
|
1592 |
-
*
|
1593 |
-
* @return array Return response array.
|
1594 |
-
*
|
1595 |
-
* @uses \ITSEC_Security_Check_Scanner::get_results()
|
1596 |
-
* @uses \ITSEC_Security_Check_Feedback_Renderer::render(
|
1597 |
-
*/
|
1598 |
-
private function security_site() {
|
1599 |
-
|
1600 |
-
/** @global string $mainwp_itsec_modules_path MainWP itsec modules path. */
|
1601 |
-
global $mainwp_itsec_modules_path;
|
1602 |
-
|
1603 |
-
require_once $mainwp_itsec_modules_path . 'security-check/scanner.php';
|
1604 |
-
require_once $mainwp_itsec_modules_path . 'security-check/feedback-renderer.php';
|
1605 |
-
$results = \ITSEC_Security_Check_Scanner::get_results();
|
1606 |
-
ob_start();
|
1607 |
-
\ITSEC_Security_Check_Feedback_Renderer::render( $results );
|
1608 |
-
$response = ob_get_clean();
|
1609 |
-
return array(
|
1610 |
-
'result' => 'success',
|
1611 |
-
'response' => $response,
|
1612 |
-
);
|
1613 |
-
}
|
1614 |
-
|
1615 |
-
/**
|
1616 |
-
* Get available admin users and roles.
|
1617 |
-
*
|
1618 |
-
* @return array[] Return response array.phpdoc
|
1619 |
-
*
|
1620 |
-
* @uses \WP_Roles()
|
1621 |
-
*/
|
1622 |
-
public function get_available_admin_users_and_roles() {
|
1623 |
-
if ( is_callable( 'wp_roles' ) ) {
|
1624 |
-
$roles = wp_roles();
|
1625 |
-
} else {
|
1626 |
-
$roles = new \WP_Roles();
|
1627 |
-
}
|
1628 |
-
|
1629 |
-
$available_roles = array();
|
1630 |
-
$available_users = array();
|
1631 |
-
|
1632 |
-
foreach ( $roles->roles as $role => $details ) {
|
1633 |
-
if ( isset( $details['capabilities']['manage_options'] ) && ( true === $details['capabilities']['manage_options'] ) ) {
|
1634 |
-
$available_roles[ "role:$role" ] = translate_user_role( $details['name'] );
|
1635 |
-
|
1636 |
-
$users = get_users( array( 'role' => $role ) );
|
1637 |
-
|
1638 |
-
foreach ( $users as $user ) {
|
1639 |
-
/* translators: 1: user display name, 2: user login */
|
1640 |
-
$available_users[ $user->ID ] = sprintf( __( '%1$s (%2$s)', 'mainwp-child' ), $user->display_name, $user->user_login );
|
1641 |
-
}
|
1642 |
-
}
|
1643 |
-
}
|
1644 |
-
|
1645 |
-
natcasesort( $available_users );
|
1646 |
-
|
1647 |
-
return array(
|
1648 |
-
'users' => $available_users,
|
1649 |
-
'roles' => $available_roles,
|
1650 |
-
);
|
1651 |
-
}
|
1652 |
-
|
1653 |
-
}
|
1 |
+
<?php
|
2 |
+
/**
|
3 |
+
* MainWP Ithemes Security
|
4 |
+
*
|
5 |
+
* MainWP iThemes Security Extension handler.
|
6 |
+
* Extension URL: https://mainwp.com/extension/ithemes-security/
|
7 |
+
*
|
8 |
+
* @package MainWP\Child
|
9 |
+
*
|
10 |
+
* Credits
|
11 |
+
*
|
12 |
+
* Plugin-Name: iThemes Security
|
13 |
+
* Plugin URI: https://ithemes.com/security
|
14 |
+
* Author: iThemes
|
15 |
+
* Author URI: https://ithemes.com
|
16 |
+
* License: GPLv2
|
17 |
+
*
|
18 |
+
* The code is used for the MainWP iThemes Security Extension
|
19 |
+
* Extension URL: https://mainwp.com/extension/ithemes-security/
|
20 |
+
*/
|
21 |
+
|
22 |
+
namespace MainWP\Child;
|
23 |
+
|
24 |
+
// phpcs:disable -- third party credit code.
|
25 |
+
|
26 |
+
|
27 |
+
/**
|
28 |
+
* Class MainWP_Child_IThemes_Security
|
29 |
+
*/
|
30 |
+
class MainWP_Child_IThemes_Security {
|
31 |
+
|
32 |
+
/**
|
33 |
+
* Public static variable to hold the single instance of MainWP_Child_IThemes_Security.
|
34 |
+
* @var null
|
35 |
+
*/
|
36 |
+
public static $instance = null;
|
37 |
+
|
38 |
+
/**
|
39 |
+
* @var bool Whether or not iThemes Plugin is installed or not. Default: false.
|
40 |
+
*/
|
41 |
+
public $is_plugin_installed = false;
|
42 |
+
|
43 |
+
/**
|
44 |
+
* Create a public static instance of MainWP_Child_IThemes_Security.
|
45 |
+
*
|
46 |
+
* @return MainWP_Child_IThemes_Security|null
|
47 |
+
*/
|
48 |
+
public static function instance() {
|
49 |
+
if ( null === self::$instance ) {
|
50 |
+
self::$instance = new self();
|
51 |
+
}
|
52 |
+
return self::$instance;
|
53 |
+
}
|
54 |
+
|
55 |
+
/**
|
56 |
+
* MainWP_Child_IThemes_Security constructor.
|
57 |
+
*
|
58 |
+
* Run any time class is called.
|
59 |
+
*
|
60 |
+
* @uses MainWP_Child_IThemes_Security::is_plugin_installed()
|
61 |
+
*/
|
62 |
+
public function __construct() {
|
63 |
+
require_once ABSPATH . 'wp-admin/includes/plugin.php';
|
64 |
+
if ( is_plugin_active( 'better-wp-security/better-wp-security.php' ) || is_plugin_active( 'ithemes-security-pro/ithemes-security-pro.php' ) ) {
|
65 |
+
$this->is_plugin_installed = true;
|
66 |
+
}
|
67 |
+
|
68 |
+
if ( ! $this->is_plugin_installed ) {
|
69 |
+
return;
|
70 |
+
}
|
71 |
+
|
72 |
+
add_filter( 'mainwp_site_sync_others_data', array( $this, 'sync_others_data' ), 10, 2 );
|
73 |
+
}
|
74 |
+
|
75 |
+
/**
|
76 |
+
* Sync other data from $data[] and merge with $information[]
|
77 |
+
*
|
78 |
+
* @param array $information Returned response array for MainWP BackWPup Extension actions.
|
79 |
+
* @param array $data Other data to sync to $information array.
|
80 |
+
* @return array $information Returned information array with both sets of data.
|
81 |
+
*/
|
82 |
+
public function sync_others_data( $information, $data = array() ) {
|
83 |
+
if ( is_array( $data ) && isset( $data['ithemeExtActivated'] ) && ( 'yes' === $data['ithemeExtActivated'] ) ) {
|
84 |
+
try {
|
85 |
+
$information['syncIThemeData'] = array(
|
86 |
+
'users_and_roles' => $this->get_available_admin_users_and_roles(),
|
87 |
+
);
|
88 |
+
|
89 |
+
global $itsec_lockout;
|
90 |
+
|
91 |
+
if ( $itsec_lockout ) {
|
92 |
+
$lockout_query = array(
|
93 |
+
'limit' => 100,
|
94 |
+
'current' => true,
|
95 |
+
'order' => 'DESC',
|
96 |
+
'orderby' => 'lockout_start',
|
97 |
+
);
|
98 |
+
$lockouts = $itsec_lockout->get_lockouts( 'all', $lockout_query );
|
99 |
+
if ( $lockouts ) {
|
100 |
+
$information['syncIThemeData']['lockout_count'] = count( $lockouts );
|
101 |
+
}
|
102 |
+
}
|
103 |
+
|
104 |
+
|
105 |
+
$request = new \WP_REST_Request( 'GET', '/ithemes-security/v1/site-scanner/scans' );
|
106 |
+
|
107 |
+
$range1 = \ITSEC_Core::get_current_time_gmt();
|
108 |
+
$range0 = strtotime( '-30 days', $range1 );
|
109 |
+
|
110 |
+
|
111 |
+
$request->set_query_params( [
|
112 |
+
'after' => \ITSEC_Lib::to_rest_date( $range0 ),
|
113 |
+
'before' => \ITSEC_Lib::to_rest_date( $range1 ),
|
114 |
+
] );
|
115 |
+
|
116 |
+
$response = rest_do_request( $request );
|
117 |
+
$scans = rest_get_server()->response_to_data( $response, true );
|
118 |
+
|
119 |
+
if ( is_array( $scans ) && count( $scans ) > 0 ) {
|
120 |
+
$scan = current( $scans );
|
121 |
+
$information['syncIThemeData']['scan_info'] = array(
|
122 |
+
'time' => $scan['time'],
|
123 |
+
'description' => $scan['description'],
|
124 |
+
'status' => $scan['status'],
|
125 |
+
);
|
126 |
+
}
|
127 |
+
|
128 |
+
if ( class_exists( '\iThemesSecurity\Ban_Users\Database_Repository' ) ) {
|
129 |
+
$repository = \ITSEC_Modules::get_container()->get( \iThemesSecurity\Ban_Users\Database_Repository::class );
|
130 |
+
$information['syncIThemeData']['count_bans'] = $repository->count_bans( new \iThemesSecurity\Ban_Hosts\Filters() );
|
131 |
+
}
|
132 |
+
|
133 |
+
$information['syncIThemeData']['lockouts_host'] = $this->get_lockouts( 'host', true );
|
134 |
+
$information['syncIThemeData']['lockouts_user'] = $this->get_lockouts( 'user', true );
|
135 |
+
$information['syncIThemeData']['lockouts_username'] = $this->get_lockouts( 'username', true );
|
136 |
+
|
137 |
+
|
138 |
+
} catch ( \Exception $e ) {
|
139 |
+
error_log( $e->getMessage() ); // phpcs:ignore -- debug mode only.
|
140 |
+
}
|
141 |
+
}
|
142 |
+
return $information;
|
143 |
+
}
|
144 |
+
|
145 |
+
/**
|
146 |
+
* MainWP iThemes Security Extension actions.
|
147 |
+
*
|
148 |
+
* @uses \MainWP\Child\MainWP_Child_IThemes_Security::set_showhide()
|
149 |
+
* @uses \MainWP\Child\MainWP_Child_IThemes_Security::save_settings()
|
150 |
+
* @uses \MainWP\Child\MainWP_Child_IThemes_Security::whitelist_release()
|
151 |
+
* @uses \MainWP\Child\MainWP_Child_IThemes_Security::backup_db()
|
152 |
+
* @uses \MainWP\Child\MainWP_Child_IThemes_Security::admin_user()
|
153 |
+
* @uses \MainWP\Child\MainWP_Child_IThemes_Security::change_database_prefix()
|
154 |
+
* @uses \MainWP\Child\MainWP_Child_IThemes_Security::reset_api_key()
|
155 |
+
* @uses \MainWP\Child\MainWP_Child_IThemes_Security::malware_scan()
|
156 |
+
* @uses \MainWP\Child\MainWP_Child_IThemes_Security::>purge_logs()
|
157 |
+
* @uses \MainWP\Child\MainWP_Child_IThemes_Security::file_change()
|
158 |
+
* @uses \MainWP\Child\MainWP_Child_IThemes_Security::release_lockout()
|
159 |
+
* @uses \MainWP\Child\MainWP_Child_IThemes_Security::update_module_status()
|
160 |
+
* @uses \MainWP\Child\MainWP_Child_IThemes_Security::wordpress_salts()
|
161 |
+
* @uses \MainWP\Child\MainWP_Child_IThemes_Security::file_permissions()
|
162 |
+
* @uses \MainWP\Child\MainWP_Child_IThemes_Security::reload_backup_exclude()
|
163 |
+
* @uses \MainWP\Child\MainWP_Child_IThemes_Security::security_site()
|
164 |
+
* @uses \MainWP\Child\MainWP_Child_IThemes_Security::activate_network_brute_force()
|
165 |
+
* @uses \MainWP\Child\MainWP_Helper::write()
|
166 |
+
*/
|
167 |
+
public function action() {
|
168 |
+
$information = array();
|
169 |
+
if ( ! class_exists( '\ITSEC_Core' ) || ! class_exists( '\ITSEC_Modules' ) ) {
|
170 |
+
$information['error'] = 'NO_ITHEME';
|
171 |
+
MainWP_Helper::write( $information );
|
172 |
+
}
|
173 |
+
|
174 |
+
/** @global string $mainwp_itsec_modules_path MainWP itsec modules path. */
|
175 |
+
global $mainwp_itsec_modules_path;
|
176 |
+
|
177 |
+
$mainwp_itsec_modules_path = \ITSEC_Core::get_core_dir() . '/modules/';
|
178 |
+
|
179 |
+
if ( isset( $_POST['mwp_action'] ) ) {
|
180 |
+
$mwp_action = ! empty( $_POST['mwp_action'] ) ? sanitize_text_field( wp_unslash( $_POST['mwp_action'] ) ) : '';
|
181 |
+
switch ( $mwp_action ) {
|
182 |
+
case 'set_showhide':
|
183 |
+
$information = $this->set_showhide();
|
184 |
+
break;
|
185 |
+
case 'save_settings':
|
186 |
+
$information = $this->save_settings();
|
187 |
+
break;
|
188 |
+
case 'whitelist_release':
|
189 |
+
$information = $this->whitelist_release();
|
190 |
+
break;
|
191 |
+
case 'backup_db':
|
192 |
+
$information = $this->backup_db();
|
193 |
+
break;
|
194 |
+
case 'admin_user':
|
195 |
+
$information = $this->admin_user();
|
196 |
+
break;
|
197 |
+
case 'database_prefix':
|
198 |
+
$information = $this->change_database_prefix();
|
199 |
+
break;
|
200 |
+
case 'reset_api_key':
|
201 |
+
$information = $this->reset_api_key();
|
202 |
+
break;
|
203 |
+
case 'malware_scan':
|
204 |
+
$information = $this->malware_scan();
|
205 |
+
break;
|
206 |
+
case 'clear_all_logs':
|
207 |
+
$information = $this->purge_logs();
|
208 |
+
break;
|
209 |
+
case 'file_change':
|
210 |
+
$information = $this->file_change();
|
211 |
+
break;
|
212 |
+
case 'release_lockout':
|
213 |
+
$information = $this->release_lockout();
|
214 |
+
break;
|
215 |
+
case 'module_status':
|
216 |
+
$information = $this->update_module_status();
|
217 |
+
break;
|
218 |
+
case 'wordpress_salts':
|
219 |
+
$information = $this->wordpress_salts();
|
220 |
+
break;
|
221 |
+
case 'file_permissions':
|
222 |
+
$information = $this->file_permissions();
|
223 |
+
break;
|
224 |
+
case 'reload_backup_exclude':
|
225 |
+
$information = $this->reload_backup_exclude();
|
226 |
+
break;
|
227 |
+
case 'security_site':
|
228 |
+
$information = $this->security_site();
|
229 |
+
break;
|
230 |
+
case 'activate_network_brute_force':
|
231 |
+
$information = $this->activate_network_brute_force();
|
232 |
+
break;
|
233 |
+
}
|
234 |
+
}
|
235 |
+
MainWP_Helper::write( $information );
|
236 |
+
}
|
237 |
+
|
238 |
+
/**
|
239 |
+
* Set show or hide UpdraftPlus Plugin from Admin & plugins list.
|
240 |
+
*
|
241 |
+
* @return array $information Return results.
|
242 |
+
*
|
243 |
+
* @uses \MainWP\Child\MainWP_Helper::update_option()
|
244 |
+
*/
|
245 |
+
public function set_showhide() {
|
246 |
+
$hide = isset( $_POST['showhide'] ) && ( 'hide' === $_POST['showhide'] ) ? 'hide' : '';
|
247 |
+
MainWP_Helper::update_option( 'mainwp_ithemes_hide_plugin', $hide );
|
248 |
+
$information['result'] = 'success';
|
249 |
+
|
250 |
+
return $information;
|
251 |
+
}
|
252 |
+
|
253 |
+
/**
|
254 |
+
* Initiate iThemes settings.
|
255 |
+
*
|
256 |
+
* @uses MainWP_Child_IThemes_Security::is_plugin_installed()
|
257 |
+
*/
|
258 |
+
public function ithemes_init() {
|
259 |
+
if ( ! $this->is_plugin_installed ) {
|
260 |
+
return;
|
261 |
+
}
|
262 |
+
|
263 |
+
if ( 'hide' === get_option( 'mainwp_ithemes_hide_plugin' ) ) {
|
264 |
+
add_filter( 'all_plugins', array( $this, 'all_plugins' ) );
|
265 |
+
add_action( 'admin_menu', array( $this, 'remove_menu' ) );
|
266 |
+
add_action( 'admin_init', array( $this, 'admin_init' ) );
|
267 |
+
add_action( 'admin_head', array( &$this, 'custom_admin_css' ) );
|
268 |
+
if ( isset( $_GET['page'] ) && ( 'itsec' == $_GET['page'] || 'itsec-security-check' == $_GET['page'] ) ) {
|
269 |
+
wp_safe_redirect( get_option( 'siteurl' ) . '/wp-admin/index.php' );
|
270 |
+
exit();
|
271 |
+
}
|
272 |
+
}
|
273 |
+
}
|
274 |
+
|
275 |
+
/**
|
276 |
+
* iThemes Security Admin initiation.
|
277 |
+
*/
|
278 |
+
public function admin_init() {
|
279 |
+
remove_meta_box( 'itsec-dashboard-widget', 'dashboard', 'normal' );
|
280 |
+
}
|
281 |
+
|
282 |
+
/**
|
283 |
+
* Remove iThemes Security from plugins page.
|
284 |
+
*
|
285 |
+
* @param array $plugins All plugins array.
|
286 |
+
*
|
287 |
+
* @return array $plugins All plugins array with iThemes Security removed.
|
288 |
+
*/
|
289 |
+
public function all_plugins( $plugins ) {
|
290 |
+
foreach ( $plugins as $key => $value ) {
|
291 |
+
$plugin_slug = basename( $key, '.php' );
|
292 |
+
if ( 'better-wp-security' === $plugin_slug || 'ithemes-security-pro' === $plugin_slug ) {
|
293 |
+
unset( $plugins[ $key ] );
|
294 |
+
}
|
295 |
+
}
|
296 |
+
|
297 |
+
return $plugins;
|
298 |
+
}
|
299 |
+
|
300 |
+
/**
|
301 |
+
* Remove iThemes Security plugin from WP Admin menu.
|
302 |
+
*/
|
303 |
+
public function remove_menu() {
|
304 |
+
remove_menu_page( 'itsec' );
|
305 |
+
}
|
306 |
+
|
307 |
+
/**
|
308 |
+
* Custom admin CSS.
|
309 |
+
*/
|
310 |
+
public function custom_admin_css() {
|
311 |
+
?>
|
312 |
+
<style type="text/css">
|
313 |
+
#wp-admin-bar-itsec_admin_bar_menu{
|
314 |
+
display: none !important;
|
315 |
+
}
|
316 |
+
</style>
|
317 |
+
<?php
|
318 |
+
}
|
319 |
+
|
320 |
+
/**
|
321 |
+
* Save UpdraftPlus settings.
|
322 |
+
*
|
323 |
+
* @return array[] $return Return Error message or Success Message.
|
324 |
+
*
|
325 |
+
* @uses \ITSEC_Lib::get_server()
|
326 |
+
* @uses \ITSEC_Lib::get_ssl_support_probability()
|
327 |
+
* @uses \ITSEC_Lib_Config_File::get_server_config()
|
328 |
+
* @uses \ITSEC_Lib_Config_File::get_wp_config()
|
329 |
+
* @uses \ITSEC_Modules::get_default()
|
330 |
+
* @uses \ITSEC_Modules::get_setting()
|
331 |
+
* @uses MainWP_Child_IThemes_Security::get_lockouts()
|
332 |
+
* @uses MainWP_Child_IThemes_Security::validate_directory()
|
333 |
+
* @uses MainWP_Child_IThemes_Security::activate_api_key()
|
334 |
+
* @uses MainWP_Child_IThemes_Security::get_excludable_tables()
|
335 |
+
* @uses MainWP_Child_IThemes_Security::get_available_admin_users_and_roles()
|
336 |
+
*/
|
337 |
+
public function save_settings() {
|
338 |
+
|
339 |
+
if ( ! class_exists( '\ITSEC_Lib' ) ) {
|
340 |
+
require \ITSEC_Core::get_core_dir() . '/core/class-itsec-lib.php';
|
341 |
+
}
|
342 |
+
|
343 |
+
$_itsec_modules = array(
|
344 |
+
'global',
|
345 |
+
'away-mode',
|
346 |
+
'backup',
|
347 |
+
'hide-backend',
|
348 |
+
'ipcheck',
|
349 |
+
'ban-users',
|
350 |
+
'brute-force',
|
351 |
+
'file-change',
|
352 |
+
'404-detection',
|
353 |
+
'network-brute-force',
|
354 |
+
'ssl',
|
355 |
+
'password-requirements',
|
356 |
+
'system-tweaks',
|
357 |
+
'wordpress-tweaks',
|
358 |
+
'multisite-tweaks',
|
359 |
+
'notification-center',
|
360 |
+
'two-factor',
|
361 |
+
);
|
362 |
+
|
363 |
+
$require_permalinks = false;
|
364 |
+
$updated = false;
|
365 |
+
$errors = array();
|
366 |
+
$nbf_settings = array();
|
367 |
+
|
368 |
+
$update_settings = isset( $_POST['settings'] ) ? maybe_unserialize( base64_decode( wp_unslash( $_POST['settings'] ) ) ) : ''; // phpcs:ignore WordPress.PHP.DiscouragedPHPFunctions -- base64_encode function is used for http encode compatible..
|
369 |
+
|
370 |
+
foreach ( $update_settings as $module => $settings ) {
|
371 |
+
$do_not_save = false;
|
372 |
+
$current_settings = \ITSEC_Modules::get_settings( $module );
|
373 |
+
if ( in_array( $module, $_itsec_modules ) ) {
|
374 |
+
if ( 'wordpress-salts' == $module ) {
|
375 |
+
$settings['last_generated'] = \ITSEC_Modules::get_setting( $module, 'last_generated' );
|
376 |
+
} elseif ( 'global' == $module ) {
|
377 |
+
$keep_olds = array( 'did_upgrade', 'log_info', 'show_new_dashboard_notice', 'show_security_check', 'nginx_file', 'manage_group' );
|
378 |
+
foreach ( $keep_olds as $key ) {
|
379 |
+
$settings[ $key ] = \ITSEC_Modules::get_setting( $module, $key );
|
380 |
+
}
|
381 |
+
|
382 |
+
if ( ! isset( $settings['log_location'] ) || empty( $settings['log_location'] ) ) {
|
383 |
+
$settings['log_location'] = \ITSEC_Modules::get_setting( $module, 'log_location' );
|
384 |
+
} else {
|
385 |
+
$result = $this->validate_directory( 'log_location', $settings['log_location'] );
|
386 |
+
if ( true !== $result ) {
|
387 |
+
$errors[] = $result;
|
388 |
+
$settings['log_location'] = \ITSEC_Modules::get_setting( $module, 'log_location' );
|
389 |
+
}
|
390 |
+
}
|
391 |
+
} elseif ( 'backup' == $module ) {
|
392 |
+
if ( ! isset( $settings['location'] ) || empty( $settings['location'] ) ) {
|
393 |
+
$settings['location'] = \ITSEC_Modules::get_setting( $module, 'location' );
|
394 |
+
} else {
|
395 |
+
$result = $this->validate_directory( 'location', $settings['location'] );
|
396 |
+
if ( true !== $result ) {
|
397 |
+
$errors[] = $result;
|
398 |
+
$settings['location'] = \ITSEC_Modules::get_setting( $module, 'location' );
|
399 |
+
}
|
400 |
+
}
|
401 |
+
if ( ! isset( $settings['exclude'] ) ) {
|
402 |
+
$settings['exclude'] = \ITSEC_Modules::get_setting( $module, 'exclude' );
|
403 |
+
|
404 |
+
}
|
405 |
+
} elseif ( 'hide-backend' == $module ) {
|
406 |
+
if ( isset( $settings['enabled'] ) && ! empty( $settings['enabled'] ) ) {
|
407 |
+
$permalink_structure = get_option( 'permalink_structure', false );
|
408 |
+
if ( empty( $permalink_structure ) && ! is_multisite() ) {
|
409 |
+
$errors[] = __( 'You must change <strong>WordPress permalinks</strong> to a setting other than "Plain" in order to use "Hide Backend" feature.', 'mainwp-child' );
|
410 |
+
$require_permalinks = true;
|
411 |
+
$do_not_save = true;
|
412 |
+
}
|
413 |
+
}
|
414 |
+
} elseif ( 'network-brute-force' == $module ) {
|
415 |
+
|
416 |
+
if ( isset( $settings['email'] ) ) {
|
417 |
+
$result = $this->activate_api_key( $settings );
|
418 |
+
if ( false === $result ) {
|
419 |
+
$nbf_settings = $settings;
|
420 |
+
$errors[] = 'Error: Active iThemes Network Brute Force Protection Api Key';
|
421 |
+
} else {
|
422 |
+
$nbf_settings = $result;
|
423 |
+
}
|
424 |
+
} else {
|
425 |
+
$previous_settings = \ITSEC_Modules::get_settings( $module );
|
426 |
+
if ( isset( $settings['enable_ban'] ) ) {
|
427 |
+
$previous_settings['enable_ban'] = $settings['enable_ban'];
|
428 |
+
$nbf_settings = $previous_settings;
|
429 |
+
} else {
|
430 |
+
$do_not_save = true;
|
431 |
+
$nbf_settings = $previous_settings;
|
432 |
+
}
|
433 |
+
}
|
434 |
+
$settings = $nbf_settings;
|
435 |
+
} elseif ( 'notification-center' == $module ) {
|
436 |
+
$current_settings = \ITSEC_Modules::get_settings( $module );
|
437 |
+
if ( isset( $settings['notifications'] ) ) {
|
438 |
+
$update_fields = array( 'schedule', 'enabled', 'subject' );
|
439 |
+
if ( isset( $_POST['is_individual'] ) && $_POST['is_individual'] ) {
|
440 |
+
$update_fields = array_merge( $update_fields, array( 'user_list', 'email_list' ) );
|
441 |
+
}
|
442 |
+
foreach ( $settings['notifications'] as $key => $val ) {
|
443 |
+
foreach ( $update_fields as $field ) {
|
444 |
+
if ( isset( $val[ $field ] ) ) {
|
445 |
+
$current_settings['notifications'][ $key ][ $field ] = $val[ $field ];
|
446 |
+
}
|
447 |
+
}
|
448 |
+
}
|
449 |
+
$updated = true;
|
450 |
+
\ITSEC_Modules::set_settings( $module, $current_settings );
|
451 |
+
}
|
452 |
+
continue;
|
453 |
+
}
|
454 |
+
|
455 |
+
if ( ! $do_not_save ) {
|
456 |
+
foreach ( $settings as $key => $val ) {
|
457 |
+
$current_settings[$key] = $val;
|
458 |
+
}
|
459 |
+
\ITSEC_Modules::set_settings( $module, $current_settings );
|
460 |
+
$updated = true;
|
461 |
+
}
|
462 |
+
}
|
463 |
+
}
|
464 |
+
|
465 |
+
if ( isset( $update_settings['itsec_active_modules'] ) ) {
|
466 |
+
$current_val = get_site_option( 'itsec_active_modules', array() );
|
467 |
+
foreach ( $update_settings['itsec_active_modules'] as $mod => $val ) {
|
468 |
+
$current_val[ $mod ] = $val;
|
469 |
+
}
|
470 |
+
update_site_option( 'itsec_active_modules', $current_val );
|
471 |
+
}
|
472 |
+
|
473 |
+
require_once \ITSEC_Core::get_core_dir() . '/lib/class-itsec-lib-config-file.php';
|
474 |
+
|
475 |
+
$values = array(
|
476 |
+
'permalink_structure' => get_option( 'permalink_structure' ),
|
477 |
+
'is_multisite' => is_multisite() ? 1 : 0,
|
478 |
+
'users_can_register' => get_site_option( 'users_can_register' ) ? 1 : 0,
|
479 |
+
'server_nginx' => ( \ITSEC_Lib::get_server() === 'nginx' ) ? 1 : 0,
|
480 |
+
'has_ssl' => \ITSEC_Lib::get_ssl_support_probability(),
|
481 |
+
'jquery_version' => \ITSEC_Modules::get_setting( 'wordpress-tweaks', 'jquery_version' ),
|
482 |
+
'server_rules' => \ITSEC_Lib_Config_File::get_server_config(),
|
483 |
+
'config_rules' => \ITSEC_Lib_Config_File::get_wp_config(),
|
484 |
+
'default_log_location' => \ITSEC_Modules::get_default( 'global', 'log_location' ),
|
485 |
+
'default_location' => \ITSEC_Modules::get_default( 'backup', 'location' ),
|
486 |
+
'excludable_tables' => $this->get_excludable_tables(),
|
487 |
+
'users_and_roles' => $this->get_available_admin_users_and_roles(),
|
488 |
+
);
|
489 |
+
|
490 |
+
$return = array(
|
491 |
+
'site_status' => $values,
|
492 |
+
);
|
493 |
+
|
494 |
+
if ( $require_permalinks ) {
|
495 |
+
$return['require_permalinks'] = 1;
|
496 |
+
}
|
497 |
+
|
498 |
+
$return['nbf_settings'] = $nbf_settings;
|
499 |
+
|
500 |
+
if ( ! empty( $errors ) ) {
|
501 |
+
$return['extra_message'] = $errors;
|
502 |
+
}
|
503 |
+
|
504 |
+
if ( $updated ) {
|
505 |
+
$return['result'] = 'success';
|
506 |
+
} else {
|
507 |
+
$return['error'] = __( 'Not Updated', 'mainwp-child' );
|
508 |
+
}
|
509 |
+
|
510 |
+
return $return;
|
511 |
+
}
|
512 |
+
|
513 |
+
/**
|
514 |
+
* Activate network brute force.
|
515 |
+
*
|
516 |
+
* @return array $information Results array.
|
517 |
+
*
|
518 |
+
* @uses \ITSEC_Modules::get_settings()
|
519 |
+
* @uses \ITSEC_Modules::activate()
|
520 |
+
*/
|
521 |
+
public static function activate_network_brute_force() {
|
522 |
+
$data = isset( $_POST['data'] ) ? maybe_unserialize( base64_decode( wp_unslash( $_POST['data'] ) ) ) : array(); // phpcs:ignore WordPress.PHP.DiscouragedPHPFunctions -- base64_encode function is used for http encode compatible..
|
523 |
+
$information = array();
|
524 |
+
if ( is_array( $data ) ) {
|
525 |
+
$settings = \ITSEC_Modules::get_settings( 'network-brute-force' );
|
526 |
+
$settings['email'] = $data['email'];
|
527 |
+
$settings['updates_optin'] = $data['updates_optin'];
|
528 |
+
$settings['api_nag'] = false;
|
529 |
+
$results = \ITSEC_Modules::set_settings( 'network-brute-force', $settings );
|
530 |
+
if ( is_wp_error( $results ) ) {
|
531 |
+
$information['error'] = 'Error: Active iThemes Network Brute Force Protection Api Key';
|
532 |
+
} elseif ( $results['saved'] ) {
|
533 |
+
\ITSEC_Modules::activate( 'network-brute-force' );
|
534 |
+
$nbf_settings = \ITSEC_Modules::get_settings( 'network-brute-force' );
|
535 |
+
}
|
536 |
+
}
|
537 |
+
if ( null !== $nbf_settings ) {
|
538 |
+
$information['nbf_settings'] = $nbf_settings;
|
539 |
+
$information['result'] = 'success';
|
540 |
+
}
|
541 |
+
return $information;
|
542 |
+
}
|
543 |
+
|
544 |
+
/**
|
545 |
+
* Validate directory.
|
546 |
+
*
|
547 |
+
* @param string $name Input name.
|
548 |
+
* @param string $folder Folder.
|
549 |
+
*
|
550 |
+
* @return bool|string Return TRUE on success or Error message on failure.
|
551 |
+
*
|
552 |
+
* @uses \ITSEC_Lib_Directory::is_dir()
|
553 |
+
* @uses \ITSEC_Lib_Directory::create()
|
554 |
+
* @uses \ITSEC_Lib_Directory::is_writable()
|
555 |
+
* @uses \ITSEC_Lib_Directory::add_file_listing_protection()
|
556 |
+
*/
|
557 |
+
private function validate_directory( $name, $folder ) {
|
558 |
+
require_once \ITSEC_Core::get_core_dir() . 'lib/class-itsec-lib-directory.php';
|
559 |
+
$error = null;
|
560 |
+
if ( ! \ITSEC_Lib_Directory::is_dir( $folder ) ) {
|
561 |
+
$result = \ITSEC_Lib_Directory::create( $folder );
|
562 |
+
|
563 |
+
if ( is_wp_error( $result ) ) {
|
564 |
+
$error = sprintf( _x( 'The directory supplied in %1$s cannot be used as a valid directory. %2$s', '%1$s is the input name. %2$s is the error message.', 'mainwp-child' ), $name, $result->get_error_message() );
|
565 |
+
}
|
566 |
+
}
|
567 |
+
|
568 |
+
if ( empty( $error ) && ! \ITSEC_Lib_Directory::is_writable( $folder ) ) {
|
569 |
+
$error = sprintf( __( 'The directory supplied in %1$s is not writable. Please select a directory that can be written to.', 'mainwp-child' ), $name );
|
570 |
+
}
|
571 |
+
|
572 |
+
if ( empty( $error ) ) {
|
573 |
+
\ITSEC_Lib_Directory::add_file_listing_protection( $folder );
|
574 |
+
return true;
|
575 |
+
} else {
|
576 |
+
return $error;
|
577 |
+
}
|
578 |
+
}
|
579 |
+
|
580 |
+
/**
|
581 |
+
* Activate api key.
|
582 |
+
*
|
583 |
+
* @param array $settings Setting array.
|
584 |
+
*
|
585 |
+
* @return array|bool Return $settings array or FALSE on failure.
|
586 |
+
*
|
587 |
+
* @uses \ITSEC_Network_Brute_Force_Utilities::get_api_key()
|
588 |
+
* @uses \ITSEC_Network_Brute_Force_Utilities::activate_api_key()
|
589 |
+
* @uses \ITSEC_Response::reload_module()
|
590 |
+
*/
|
591 |
+
private function activate_api_key( $settings ) {
|
592 |
+
|
593 |
+
/** @global string $mainwp_itsec_modules_path MainWP itsec modules path. */
|
594 |
+
global $mainwp_itsec_modules_path;
|
595 |
+
|
596 |
+
if ( file_exists( $mainwp_itsec_modules_path . 'network-brute-force/utilities.php' ) ) {
|
597 |
+
require_once $mainwp_itsec_modules_path . 'network-brute-force/utilities.php';
|
598 |
+
} else if ( file_exists( $mainwp_itsec_modules_path . 'ipcheck/utilities.php' ) ) {
|
599 |
+
require_once $mainwp_itsec_modules_path . 'ipcheck/utilities.php';
|
600 |
+
}
|
601 |
+
|
602 |
+
$key = \ITSEC_Network_Brute_Force_Utilities::get_api_key( $settings['email'], $settings['updates_optin'] );
|
603 |
+
if ( is_wp_error( $key ) ) {
|
604 |
+
return false;
|
605 |
+
} else {
|
606 |
+
$secret = \ITSEC_Network_Brute_Force_Utilities::activate_api_key( $key );
|
607 |
+
|
608 |
+
if ( is_wp_error( $secret ) ) {
|
609 |
+
return false;
|
610 |
+
} else {
|
611 |
+
$settings['api_key'] = $key;
|
612 |
+
$settings['api_secret'] = $secret;
|
613 |
+
|
614 |
+
$settings['api_nag'] = false;
|
615 |
+
|
616 |
+
\ITSEC_Response::reload_module( 'network-brute-force' );
|
617 |
+
}
|
618 |
+
}
|
619 |
+
unset( $settings['email'] );
|
620 |
+
return $settings;
|
621 |
+
}
|
622 |
+
|
623 |
+
/**
|
624 |
+
* Backup status.
|
625 |
+
*
|
626 |
+
* @return int $status 1, 2, 3 or 4
|
627 |
+
* (1) Is not a multisite installation, backupbuddy_api exists & Scheduled backups are >=1
|
628 |
+
* (2) Is not multisite and backupbuddy_api exists
|
629 |
+
* (3) Has backup = true & schedualed backup = true
|
630 |
+
* (4) Has backup = true.
|
631 |
+
*
|
632 |
+
* @uses \backupbuddy_api::getSchedules()
|
633 |
+
* @uses MainWP_Child_IThemes_Security::has_backup()
|
634 |
+
* @uses MainWP_Child_IThemes_Security::scheduled_backup()
|
635 |
+
* @uses MainWP_Child_IThemes_Security::has_backup()
|
636 |
+
*
|
637 |
+
*/
|
638 |
+
public function backup_status() {
|
639 |
+
$status = 0;
|
640 |
+
if ( ! is_multisite() && class_exists( '\backupbuddy_api' ) && count( \backupbuddy_api::getSchedules() ) >= 1 ) {
|
641 |
+
$status = 1;
|
642 |
+
} elseif ( ! is_multisite() && class_exists( '\backupbuddy_api' ) ) {
|
643 |
+
$status = 2;
|
644 |
+
} elseif ( $this->has_backup() === true && $this->scheduled_backup() === true ) {
|
645 |
+
$status = 3;
|
646 |
+
} elseif ( $this->has_backup() === true ) {
|
647 |
+
$status = 4;
|
648 |
+
}
|
649 |
+
|
650 |
+
return $status;
|
651 |
+
}
|
652 |
+
|
653 |
+
/**
|
654 |
+
* Check if backup exists.
|
655 |
+
*
|
656 |
+
* @return bool TRUE|FALSE
|
657 |
+
*/
|
658 |
+
public function has_backup() {
|
659 |
+
$has_backup = false;
|
660 |
+
|
661 |
+
return apply_filters( 'itsec_has_external_backup', $has_backup );
|
662 |
+
}
|
663 |
+
|
664 |
+
/**
|
665 |
+
* Check if there is a shedualed backup.
|
666 |
+
*
|
667 |
+
* @return bool TRUE|FALSE.
|
668 |
+
*/
|
669 |
+
public function scheduled_backup() {
|
670 |
+
$sceduled_backup = false;
|
671 |
+
|
672 |
+
return apply_filters( 'itsec_scheduled_external_backup', $sceduled_backup );
|
673 |
+
}
|
674 |
+
|
675 |
+
/**
|
676 |
+
* Whitelist Dashboard IP address.
|
677 |
+
*
|
678 |
+
* @return array|string[] Response array.
|
679 |
+
*/
|
680 |
+
public function whitelist() {
|
681 |
+
|
682 |
+
/** @global array $itsec_globals itsec globals. */
|
683 |
+
global $itsec_globals;
|
684 |
+
|
685 |
+
$ip = isset( $_POST['ip'] ) ? sanitize_text_field( wp_unslash( $_POST['ip'] ) ) : '';
|
686 |
+
$add_temp = false;
|
687 |
+
$temp_ip = get_site_option( 'itsec_temp_whitelist_ip' );
|
688 |
+
if ( false !== $temp_ip ) {
|
689 |
+
if ( ( $temp_ip['exp'] < $itsec_globals['current_time'] ) || ( $temp_ip['exp'] !== $ip ) ) {
|
690 |
+
delete_site_option( 'itsec_temp_whitelist_ip' );
|
691 |
+
$add_temp = true;
|
692 |
+
}
|
693 |
+
} else {
|
694 |
+
$add_temp = true;
|
695 |
+
}
|
696 |
+
|
697 |
+
if ( false === $add_temp ) {
|
698 |
+
return array( 'error' => 'Not Updated' );
|
699 |
+
} else {
|
700 |
+
$response = array(
|
701 |
+
'ip' => $ip,
|
702 |
+
'exp' => $itsec_globals['current_time'] + 86400,
|
703 |
+
);
|
704 |
+
add_site_option( 'itsec_temp_whitelist_ip', $response );
|
705 |
+
$response['exp_diff'] = human_time_diff( $itsec_globals['current_time'], $response['exp'] );
|
706 |
+
$response['message1'] = __( 'Your IP Address', 'mainwp-child' );
|
707 |
+
$response['message2'] = __( 'is whitelisted for', 'mainwp-child' );
|
708 |
+
|
709 |
+
return $response;
|
710 |
+
}
|
711 |
+
}
|
712 |
+
|
713 |
+
/**
|
714 |
+
* Whitelist release.
|
715 |
+
*
|
716 |
+
* @return string Return 'Success'.
|
717 |
+
*/
|
718 |
+
public function whitelist_release() {
|
719 |
+
delete_site_option( 'itsec_temp_whitelist_ip' );
|
720 |
+
|
721 |
+
return 'success';
|
722 |
+
}
|
723 |
+
|
724 |
+
/**
|
725 |
+
* Backup Database.
|
726 |
+
*
|
727 |
+
* @return array $return Return results array.
|
728 |
+
*
|
729 |
+
* @uses \ITSEC_Backup()
|
730 |
+
* @uses \ITSEC_Backup::run()
|
731 |
+
* @uses \ITSEC_Backup::do_backup()
|
732 |
+
* @uses \ITSEC_Response::get_error_strings()
|
733 |
+
*/
|
734 |
+
public function backup_db() {
|
735 |
+
|
736 |
+
/**
|
737 |
+
* @global string $mainwp_itsec_modules_path MainWP itsec modules path.
|
738 |
+
* @global object $itsec_backup ITsec backup class.
|
739 |
+
*/
|
740 |
+
global $itsec_backup, $mainwp_itsec_modules_path;
|
741 |
+
|
742 |
+
if ( ! isset( $itsec_backup ) ) {
|
743 |
+
require_once $mainwp_itsec_modules_path . 'backup/class-itsec-backup.php';
|
744 |
+
$itsec_backup = new \ITSEC_Backup();
|
745 |
+
$itsec_backup->run();
|
746 |
+
}
|
747 |
+
|
748 |
+
$return = array();
|
749 |
+
|
750 |
+
$str_error = '';
|
751 |
+
$result = $itsec_backup->do_backup( true );
|
752 |
+
|
753 |
+
if ( is_wp_error( $result ) ) {
|
754 |
+
$errors = \ITSEC_Response::get_error_strings( $result );
|
755 |
+
|
756 |
+
foreach ( $errors as $error ) {
|
757 |
+
$str_error .= $error . '<br />';
|
758 |
+
}
|
759 |
+
} elseif ( is_string( $result ) ) {
|
760 |
+
$return['result'] = 'success';
|
761 |
+
$return['message'] = $result;
|
762 |
+
} else {
|
763 |
+
$str_error = sprintf( __( 'The backup request returned an unexpected response. It returned a response of type <code>%1$s</code>.', 'mainwp-child' ), gettype( $result ) );
|
764 |
+
}
|
765 |
+
|
766 |
+
if ( ! empty( $str_error ) ) {
|
767 |
+
$return['error'] = $str_error;
|
768 |
+
}
|
769 |
+
|
770 |
+
return $return;
|
771 |
+
}
|
772 |
+
|
773 |
+
|
774 |
+
/**
|
775 |
+
* Update WordPress Salts.
|
776 |
+
*
|
777 |
+
* @return array $return Return results array.
|
778 |
+
*
|
779 |
+
* @uses \ITSEC_WordPress_Salts_Utilities::generate_new_salts()
|
780 |
+
* @uses \ITSEC_Response::get_error_strings()
|
781 |
+
* @uses \ITSEC_Core::get_current_time_gmt()
|
782 |
+
* @uses \ITSEC_Modules::set_setting()
|
783 |
+
*/
|
784 |
+
private function wordpress_salts() {
|
785 |
+
|
786 |
+
/** @global string $mainwp_itsec_modules_path MainWP itsec modules path. */
|
787 |
+
global $mainwp_itsec_modules_path;
|
788 |
+
|
789 |
+
if ( ! class_exists( '\ITSEC_WordPress_Salts_Utilities' ) ) {
|
790 |
+
require $mainwp_itsec_modules_path . 'salts/utilities.php';
|
791 |
+
}
|
792 |
+
$result = \ITSEC_WordPress_Salts_Utilities::generate_new_salts();
|
793 |
+
$str_error = '';
|
794 |
+
if ( is_wp_error( $result ) ) {
|
795 |
+
$errors = \ITSEC_Response::get_error_strings( $result );
|
796 |
+
|
797 |
+
foreach ( $errors as $error ) {
|
798 |
+
$str_error .= $error . '<br />';
|
799 |
+
}
|
800 |
+
} else {
|
801 |
+
$return['result'] = 'success';
|
802 |
+
$return['message'] = __( 'The WordPress salts were successfully regenerated.', 'mainwp-child' );
|
803 |
+
$last_generated = \ITSEC_Core::get_current_time_gmt();
|
804 |
+
\ITSEC_Modules::set_setting( 'wordpress-salts', 'last_generated', $last_generated );
|
805 |
+
}
|
806 |
+
if ( ! empty( $str_error ) ) {
|
807 |
+
$return['error'] = $str_error;
|
808 |
+
}
|
809 |
+
return $return;
|
810 |
+
}
|
811 |
+
|
812 |
+
/**
|
813 |
+
* Update file permissions.
|
814 |
+
*
|
815 |
+
* @return array Return results table html.
|
816 |
+
*
|
817 |
+
* @uses \ITSEC_Core::get_wp_upload_dir()
|
818 |
+
* @uses \ITSEC_Lib_Config_File::get_wp_config_file_path()
|
819 |
+
* @uses \ITSEC_Lib_Config_File::get_server_config_file_path()
|
820 |
+
*/
|
821 |
+
private function file_permissions() {
|
822 |
+
|
823 |
+
require_once \ITSEC_Core::get_core_dir() . '/lib/class-itsec-lib-config-file.php';
|
824 |
+
|
825 |
+
$wp_upload_dir = \ITSEC_Core::get_wp_upload_dir();
|
826 |
+
|
827 |
+
$path_data = array(
|
828 |
+
array(
|
829 |
+
ABSPATH,
|
830 |
+
0755,
|
831 |
+
),
|
832 |
+
array(
|
833 |
+
ABSPATH . WPINC,
|
834 |
+
0755,
|
835 |
+
),
|
836 |
+
array(
|
837 |
+
ABSPATH . 'wp-admin',
|
838 |
+
0755,
|
839 |
+
),
|
840 |
+
array(
|
841 |
+
ABSPATH . 'wp-admin/js',
|
842 |
+
0755,
|
843 |
+
),
|
844 |
+
array(
|
845 |
+
WP_CONTENT_DIR,
|
846 |
+
0755,
|
847 |
+
),
|
848 |
+
array(
|
849 |
+
get_theme_root(),
|
850 |
+
0755,
|
851 |
+
),
|
852 |
+
array(
|
853 |
+
WP_PLUGIN_DIR,
|
854 |
+
0755,
|
855 |
+
),
|
856 |
+
array(
|
857 |
+
$wp_upload_dir['basedir'],
|
858 |
+
0755,
|
859 |
+
),
|
860 |
+
array(
|
861 |
+
\ITSEC_Lib_Config_File::get_wp_config_file_path(),
|
862 |
+
0444,
|
863 |
+
),
|
864 |
+
array(
|
865 |
+
\ITSEC_Lib_Config_File::get_server_config_file_path(),
|
866 |
+
0444,
|
867 |
+
),
|
868 |
+
);
|
869 |
+
|
870 |
+
$rows = array();
|
871 |
+
|
872 |
+
foreach ( $path_data as $path ) {
|
873 |
+
$row = array();
|
874 |
+
|
875 |
+
list( $path, $suggested_permissions ) = $path;
|
876 |
+
|
877 |
+
$display_path = preg_replace( '/^' . preg_quote( ABSPATH, '/' ) . '/', '', $path );
|
878 |
+
$display_path = ltrim( $display_path, '/' );
|
879 |
+
|
880 |
+
if ( empty( $display_path ) ) {
|
881 |
+
$display_path = '/';
|
882 |
+
}
|
883 |
+
|
884 |
+
$row[] = $display_path;
|
885 |
+
$row[] = sprintf( '%o', $suggested_permissions );
|
886 |
+
|
887 |
+
$permissions = fileperms( $path ) & 0777;
|
888 |
+
$row[] = sprintf( '%o', $permissions );
|
889 |
+
|
890 |
+
if ( ! $permissions || $permissions != $suggested_permissions ) {
|
891 |
+
$row[] = __( 'WARNING', 'mainwp-child' );
|
892 |
+
$row[] = '<div style="background-color: #FEFF7F; border: 1px solid #E2E2E2;"> </div>';
|
893 |
+
} else {
|
894 |
+
$row[] = __( 'OK', 'mainwp-child' );
|
895 |
+
$row[] = '<div style="background-color: #22EE5B; border: 1px solid #E2E2E2;"> </div>';
|
896 |
+
}
|
897 |
+
|
898 |
+
$rows[] = $row;
|
899 |
+
}
|
900 |
+
|
901 |
+
$class = 'entry-row';
|
902 |
+
ob_start();
|
903 |
+
?>
|
904 |
+
<p><input type="button" id="itsec-file-permissions-reload_file_permissions" name="file-permissions[reload_file_permissions]" class="button-primary itsec-reload-module" value="<?php esc_attr_e( 'Reload File Permissions Details', 'mainwp-child' ); ?>"></p>
|
905 |
+
<table class="widefat">
|
906 |
+
<thead>
|
907 |
+
<tr>
|
908 |
+
<th><?php esc_html_e( 'Relative Path', 'mainwp-child' ); ?></th>
|
909 |
+
<th><?php esc_html_e( 'Suggestion', 'mainwp-child' ); ?></th>
|
910 |
+
<th><?php esc_html_e( 'Value', 'mainwp-child' ); ?></th>
|
911 |
+
<th><?php esc_html_e( 'Result', 'mainwp-child' ); ?></th>
|
912 |
+
<th><?php esc_html_e( 'Status', 'mainwp-child' ); ?></th>
|
913 |
+
</tr>
|
914 |
+
</thead>
|
915 |
+
<tfoot>
|
916 |
+
<tr>
|
917 |
+
<th><?php esc_html_e( 'Relative Path', 'mainwp-child' ); ?></th>
|
918 |
+
<th><?php esc_html_e( 'Suggestion', 'mainwp-child' ); ?></th>
|
919 |
+
<th><?php esc_html_e( 'Value', 'mainwp-child' ); ?></th>
|
920 |
+
<th><?php esc_html_e( 'Result', 'mainwp-child' ); ?></th>
|
921 |
+
<th><?php esc_html_e( 'Status', 'mainwp-child' ); ?></th>
|
922 |
+
</tr>
|
923 |
+
</tfoot>
|
924 |
+
<tbody>
|
925 |
+
<?php foreach ( $rows as $row ) : ?>
|
926 |
+
<tr class="<?php echo $class; ?>">
|
927 |
+
<?php foreach ( $row as $column ) : ?>
|
928 |
+
<td><?php echo $column; ?></td>
|
929 |
+
<?php endforeach; ?>
|
930 |
+
</tr>
|
931 |
+
<?php $class = ( 'entry-row' === $class ) ? 'entry-row alternate' : 'entry-row'; ?>
|
932 |
+
<?php endforeach; ?>
|
933 |
+
</tbody>
|
934 |
+
</table>
|
935 |
+
<br />
|
936 |
+
<?php
|
937 |
+
$html = ob_get_clean();
|
938 |
+
return array( 'html' => $html );
|
939 |
+
}
|
940 |
+
|
941 |
+
/**
|
942 |
+
* Run File Change scanner.
|
943 |
+
*
|
944 |
+
* @return array $return results array.
|
945 |
+
*
|
946 |
+
* @uses \ITSEC_File_Change_Scanner::run_scan()
|
947 |
+
*/
|
948 |
+
public function file_change() {
|
949 |
+
|
950 |
+
/** @global string $mainwp_itsec_modules_path MainWP itsec modules path. */
|
951 |
+
global $mainwp_itsec_modules_path;
|
952 |
+
|
953 |
+
if ( ! class_exists( '\ITSEC_File_Change_Scanner' ) ) {
|
954 |
+
require_once $mainwp_itsec_modules_path . 'file-change/scanner.php';
|
955 |
+
}
|
956 |
+
|
957 |
+
$results = \ITSEC_File_Change_Scanner::schedule_start();
|
958 |
+
|
959 |
+
if ( is_wp_error( $results ) ) {
|
960 |
+
$error = $results->get_error_message();
|
961 |
+
$return['result'] = 'failed';
|
962 |
+
$return['scan_error'] = $error;
|
963 |
+
} else {
|
964 |
+
$return['result'] = 'success';
|
965 |
+
$return['scan_result'] = $results;
|
966 |
+
}
|
967 |
+
return $return;
|
968 |
+
}
|
969 |
+
|
970 |
+
/**
|
971 |
+
* Update admin user.
|
972 |
+
*
|
973 |
+
* @return array Return Success or Fail.
|
974 |
+
*
|
975 |
+
* @uses \ITSEC_Lib::user_id_exists()
|
976 |
+
* @uses MainWP_Child_IThemes_Security::change_admin_user()
|
977 |
+
*/
|
978 |
+
public function admin_user() {
|
979 |
+
|
980 |
+
$settings = isset( $_POST['settings'] ) ? wp_unslash( $_POST['settings'] ) : array();
|
981 |
+
|
982 |
+
if ( ! is_array( $settings ) ) {
|
983 |
+
$settings = array();
|
984 |
+
}
|
985 |
+
|
986 |
+
$new_username = isset( $settings['new_username'] ) ? $settings['new_username'] : '';
|
987 |
+
$change_id = isset( $settings['change_id'] ) && $settings['change_id'] ? true : false;
|
988 |
+
|
989 |
+
if ( ! class_exists( '\ITSEC_Lib' ) ) {
|
990 |
+
|
991 |
+
/** @global object $itsec_globals ITsec globals. */
|
992 |
+
global $itsec_globals;
|
993 |
+
|
994 |
+
require \ITSEC_Core::get_core_dir() . '/core/class-itsec-lib.php';
|
995 |
+
}
|
996 |
+
|
997 |
+
$username_exists = username_exists( 'admin' );
|
998 |
+
$user_id_exists = \ITSEC_Lib::user_id_exists( 1 );
|
999 |
+
$msg = '';
|
1000 |
+
if ( strlen( $new_username ) >= 1 ) {
|
1001 |
+
|
1002 |
+
/** @global string $current_user Current user global variable. */
|
1003 |
+
global $current_user;
|
1004 |
+
|
1005 |
+
if ( ! $username_exists ) {
|
1006 |
+
$msg = __( 'Admin user already changes.', 'mainwp-child' );
|
1007 |
+
} elseif ( 'admin' == $current_user->user_login ) {
|
1008 |
+
$return['result'] = 'CHILD_ADMIN';
|
1009 |
+
return $return;
|
1010 |
+
}
|
1011 |
+
}
|
1012 |
+
|
1013 |
+
if ( true === $change_id && ! $user_id_exists ) {
|
1014 |
+
if ( ! empty( $msg ) ) {
|
1015 |
+
$msg .= '<br/>';
|
1016 |
+
}
|
1017 |
+
$msg .= __( 'Admin user ID already changes.', 'mainwp-child' );
|
1018 |
+
}
|
1019 |
+
|
1020 |
+
$admin_success = true;
|
1021 |
+
$return = array();
|
1022 |
+
|
1023 |
+
if ( strlen( $new_username ) >= 1 && $username_exists ) {
|
1024 |
+
$admin_success = $this->change_admin_user( $new_username, $change_id );
|
1025 |
+
} elseif ( true === $change_id && $user_id_exists ) {
|
1026 |
+
$admin_success = $this->change_admin_user( null, $change_id );
|
1027 |
+
}
|
1028 |
+
|
1029 |
+
$return['message'] = $msg;
|
1030 |
+
if ( false === $admin_success ) {
|
1031 |
+
$return['result'] = 'fail';
|
1032 |
+
} else {
|
1033 |
+
$return['result'] = 'success';
|
1034 |
+
}
|
1035 |
+
return $return;
|
1036 |
+
}
|
1037 |
+
|
1038 |
+
/**
|
1039 |
+
* Change admin user.
|
1040 |
+
*
|
1041 |
+
* @param string $username Username to update to. Default: null.
|
1042 |
+
* @param bool $id User Id found. Default: false.
|
1043 |
+
* @return bool Return TRUE on success and FALSE on failure.
|
1044 |
+
*
|
1045 |
+
* @uses \ITSEC_Core::get_itsec_files()
|
1046 |
+
* @uses \ITSEC_Core::get_itsec_files::release_file_lock()
|
1047 |
+
*/
|
1048 |
+
private function change_admin_user($username = null, $id = false ) {
|
1049 |
+
|
1050 |
+
/** @global object $wpdb WordPress Database */
|
1051 |
+
global $wpdb;
|
1052 |
+
|
1053 |
+
$itsec_files = \ITSEC_Core::get_itsec_files();
|
1054 |
+
|
1055 |
+
$new_user = sanitize_text_field( $username );
|
1056 |
+
|
1057 |
+
$user_object = get_user_by( 'id', '1' );
|
1058 |
+
|
1059 |
+
if ( null !== $username && validate_username( $new_user ) && false === username_exists( $new_user ) ) {
|
1060 |
+
|
1061 |
+
if ( true === $id ) {
|
1062 |
+
|
1063 |
+
$user_login = $new_user;
|
1064 |
+
|
1065 |
+
} else {
|
1066 |
+
|
1067 |
+
$wpdb->query( 'UPDATE `' . $wpdb->users . "` SET user_login = '" . esc_sql( $new_user ) . "' WHERE user_login='admin';" );
|
1068 |
+
|
1069 |
+
if ( is_multisite() ) {
|
1070 |
+
$oldAdmins = $wpdb->get_var( 'SELECT meta_value FROM `' . $wpdb->sitemeta . "` WHERE meta_key = 'site_admins'" );
|
1071 |
+
$newAdmins = str_replace( '5:"admin"', strlen( $new_user ) . ':"' . esc_sql( $new_user ) . '"', $oldAdmins );
|
1072 |
+
$wpdb->query( $wpdb->prepare( 'UPDATE `' . $wpdb->sitemeta . "` SET meta_value = %s WHERE meta_key = 'site_admins'", $newAdmins ) );
|
1073 |
+
}
|
1074 |
+
|
1075 |
+
wp_clear_auth_cookie();
|
1076 |
+
$itsec_files->release_file_lock( 'admin_user' );
|
1077 |
+
|
1078 |
+
return true;
|
1079 |
+
|
1080 |
+
}
|
1081 |
+
} elseif ( null !== $username ) {
|
1082 |
+
|
1083 |
+
$itsec_files->release_file_lock( 'admin_user' );
|
1084 |
+
|
1085 |
+
return false;
|
1086 |
+
|
1087 |
+
} else {
|
1088 |
+
|
1089 |
+
$user_login = $user_object->user_login;
|
1090 |
+
|
1091 |
+
}
|
1092 |
+
|
1093 |
+
if ( true === $id ) {
|
1094 |
+
|
1095 |
+
$wpdb->query( 'DELETE FROM `' . $wpdb->users . '` WHERE ID = 1;' );
|
1096 |
+
|
1097 |
+
$wpdb->insert(
|
1098 |
+
$wpdb->users,
|
1099 |
+
array(
|
1100 |
+
'user_login' => $user_login,
|
1101 |
+
'user_pass' => $user_object->user_pass,
|
1102 |
+
'user_nicename' => $user_object->user_nicename,
|
1103 |
+
'user_email' => $user_object->user_email,
|
1104 |
+
'user_url' => $user_object->user_url,
|
1105 |
+
'user_registered' => $user_object->user_registered,
|
1106 |
+
'user_activation_key' => $user_object->user_activation_key,
|
1107 |
+
'user_status' => $user_object->user_status,
|
1108 |
+
'display_name' => $user_object->display_name,
|
1109 |
+
)
|
1110 |
+
);
|
1111 |
+
|
1112 |
+
if ( is_multisite() && null !== $username && validate_username( $new_user ) ) {
|
1113 |
+
|
1114 |
+
$oldAdmins = $wpdb->get_var( 'SELECT meta_value FROM `' . $wpdb->sitemeta . "` WHERE meta_key = 'site_admins'" );
|
1115 |
+
$newAdmins = str_replace( '5:"admin"', strlen( $new_user ) . ':"' . esc_sql( $new_user ) . '"', $oldAdmins );
|
1116 |
+
$wpdb->query( 'UPDATE `' . $wpdb->sitemeta . "` SET meta_value = '" . esc_sql( $newAdmins ) . "' WHERE meta_key = 'site_admins'" );
|
1117 |
+
|
1118 |
+
}
|
1119 |
+
|
1120 |
+
$new_user = $wpdb->insert_id;
|
1121 |
+
|
1122 |
+
$wpdb->query( $wpdb->prepare( 'UPDATE `' . $wpdb->posts . '` SET post_author = %s WHERE post_author = 1;', $new_user ) );
|
1123 |
+
$wpdb->query( $wpdb->prepare( 'UPDATE `' . $wpdb->usermeta . '` SET user_id = %s WHERE user_id = 1;', $new_user ) );
|
1124 |
+
$wpdb->query( $wpdb->prepare( 'UPDATE `' . $wpdb->comments . '` SET user_id = %s WHERE user_id = 1;', $new_user ) );
|
1125 |
+
$wpdb->query( $wpdb->prepare( 'UPDATE `' . $wpdb->links . '` SET link_owner = %s WHERE link_owner = 1;', $new_user ) );
|
1126 |
+
|
1127 |
+
wp_clear_auth_cookie();
|
1128 |
+
$itsec_files->release_file_lock( 'admin_user' );
|
1129 |
+
|
1130 |
+
return true;
|
1131 |
+
|
1132 |
+
}
|
1133 |
+
|
1134 |
+
return false;
|
1135 |
+
}
|
1136 |
+
|
1137 |
+
/**
|
1138 |
+
* Build WP_config rules.
|
1139 |
+
*
|
1140 |
+
* @param array $rules_array Config rules array.
|
1141 |
+
* @param null $input New directory input.
|
1142 |
+
*
|
1143 |
+
* @return array Return $rules_array.
|
1144 |
+
*/
|
1145 |
+
public function build_wpconfig_rules( $rules_array, $input = null ) {
|
1146 |
+
if ( null === $input ) {
|
1147 |
+
return $rules_array;
|
1148 |
+
}
|
1149 |
+
|
1150 |
+
$new_dir = trailingslashit( ABSPATH ) . $input;
|
1151 |
+
|
1152 |
+
$rules[] = array(
|
1153 |
+
'type' => 'add',
|
1154 |
+
'search_text' => '//Do not delete these. Doing so WILL break your site.',
|
1155 |
+
'rule' => '//Do not delete these. Doing so WILL break your site.',
|
1156 |
+
);
|
1157 |
+
|
1158 |
+
$rules[] = array(
|
1159 |
+
'type' => 'add',
|
1160 |
+
'search_text' => 'WP_CONTENT_URL',
|
1161 |
+
'rule' => "define( 'WP_CONTENT_URL', '" . trailingslashit( get_option( 'siteurl' ) ) . $input . "' );",
|
1162 |
+
);
|
1163 |
+
|
1164 |
+
$rules[] = array(
|
1165 |
+
'type' => 'add',
|
1166 |
+
'search_text' => 'WP_CONTENT_DIR',
|
1167 |
+
'rule' => "define( 'WP_CONTENT_DIR', '" . $new_dir . "' );",
|
1168 |
+
);
|
1169 |
+
|
1170 |
+
$rules_array[] = array(
|
1171 |
+
'type' => 'wpconfig',
|
1172 |
+
'name' => 'Content Directory',
|
1173 |
+
'rules' => $rules,
|
1174 |
+
);
|
1175 |
+
|
1176 |
+
return $rules_array;
|
1177 |
+
}
|
1178 |
+
|
1179 |
+
|
1180 |
+
/**
|
1181 |
+
* Change database prefix.
|
1182 |
+
*
|
1183 |
+
* @return array $return Return response array.
|
1184 |
+
*
|
1185 |
+
* @uses \ITSEC_Database_Prefix_Utility::change_database_prefix()
|
1186 |
+
* @uses \ITSEC_Response::get_error_strings()
|
1187 |
+
* @uses \ITSEC_Response::reload_module()
|
1188 |
+
*/
|
1189 |
+
public function change_database_prefix() {
|
1190 |
+
|
1191 |
+
/** @global string $mainwp_itsec_modules_path MainWP itsec modules path. */
|
1192 |
+
global $mainwp_itsec_modules_path;
|
1193 |
+
|
1194 |
+
require_once $mainwp_itsec_modules_path . 'database-prefix/utility.php';
|
1195 |
+
$str_error = '';
|
1196 |
+
$return = array();
|
1197 |
+
|
1198 |
+
if ( isset( $_POST['change_prefix'] ) && 'yes' === $_POST['change_prefix'] ) {
|
1199 |
+
$result = \ITSEC_Database_Prefix_Utility::change_database_prefix();
|
1200 |
+
$return = $result['errors'];
|
1201 |
+
if ( is_array( $result['errors'] ) ) {
|
1202 |
+
foreach ( $result['errors'] as $error ) {
|
1203 |
+
$arr_errors = \ITSEC_Response::get_error_strings( $error );
|
1204 |
+
foreach ( $arr_errors as $er ) {
|
1205 |
+
$str_error .= $er . '<br />';
|
1206 |
+
}
|
1207 |
+
}
|
1208 |
+
}
|
1209 |
+
|
1210 |
+
\ITSEC_Response::reload_module( 'database-prefix' );
|
1211 |
+
|
1212 |
+
if ( false === $result['new_prefix'] ) {
|
1213 |
+
$return['error'] = $str_error;
|
1214 |
+
} else {
|
1215 |
+
$return['result'] = 'success';
|
1216 |
+
$return['message'] = sprintf( __( 'The database table prefix was successfully changed to <code>%1$s</code>.', 'mainwp-child' ), $result['new_prefix'] );
|
1217 |
+
|
1218 |
+
}
|
1219 |
+
}
|
1220 |
+
return $return;
|
1221 |
+
}
|
1222 |
+
|
1223 |
+
/**
|
1224 |
+
* Update API key.
|
1225 |
+
*
|
1226 |
+
* @return array $return Return response array. Success or nochange.
|
1227 |
+
*/
|
1228 |
+
public function api_key() {
|
1229 |
+
$settings = get_site_option( 'itsec_ipcheck' );
|
1230 |
+
if ( ! is_array( $settings ) ) {
|
1231 |
+
$settings = array();
|
1232 |
+
}
|
1233 |
+
$settings['reset'] = true;
|
1234 |
+
$return = array();
|
1235 |
+
if ( update_site_option( 'itsec_ipcheck', $settings ) ) {
|
1236 |
+
$return['result'] = 'success';
|
1237 |
+
} else {
|
1238 |
+
$return['result'] = 'nochange';
|
1239 |
+
}
|
1240 |
+
|
1241 |
+
return $return;
|
1242 |
+
}
|
1243 |
+
|
1244 |
+
/**
|
1245 |
+
* Reset api key.
|
1246 |
+
*
|
1247 |
+
* @return array $information Return response array.
|
1248 |
+
*
|
1249 |
+
* @uses \ITSEC_Modules::get_defaults()
|
1250 |
+
* @uses \ITSEC_Modules::set_defaults()
|
1251 |
+
* @uses \ITSEC_Response::set_response()
|
1252 |
+
* @uses \ITSEC_Response::add_errors()
|
1253 |
+
* @uses \ITSEC_Response::add_messages()
|
1254 |
+
*/
|
1255 |
+
public function reset_api_key() {
|
1256 |
+
|
1257 |
+
$defaults = \ITSEC_Modules::get_defaults( 'network-brute-force' );
|
1258 |
+
$results = \ITSEC_Modules::set_settings( 'network-brute-force', $defaults );
|
1259 |
+
|
1260 |
+
\ITSEC_Response::set_response( $results['saved'] );
|
1261 |
+
\ITSEC_Response::add_errors( $results['errors'] );
|
1262 |
+
\ITSEC_Response::add_messages( $results['messages'] );
|
1263 |
+
|
1264 |
+
$information = array();
|
1265 |
+
if ( $results['saved'] ) {
|
1266 |
+
$information['result'] = 'success';
|
1267 |
+
$information['nbf_settings'] = \ITSEC_Modules::get_settings( 'network-brute-force' );
|
1268 |
+
} elseif ( empty( $results['errors'] ) ) {
|
1269 |
+
$information['error_reset_api'] = 1;
|
1270 |
+
}
|
1271 |
+
return $information;
|
1272 |
+
}
|
1273 |
+
|
1274 |
+
/**
|
1275 |
+
* Malware scan.
|
1276 |
+
*
|
1277 |
+
* @return array $response Return response array.
|
1278 |
+
*
|
1279 |
+
* @uses \ITSEC_Core::current_user_can_manage()
|
1280 |
+
* @uses \ITSEC_Malware_Scanner::scan()
|
1281 |
+
* @uses \ITSEC_Malware_Scan_Results_Template::get_html()
|
1282 |
+
*/
|
1283 |
+
public function malware_scan() {
|
1284 |
+
|
1285 |
+
/** @global string $mainwp_itsec_modules_path MainWP itsec modules path. */
|
1286 |
+
global $mainwp_itsec_modules_path;
|
1287 |
+
|
1288 |
+
if ( ! class_exists( '\ITSEC_Malware_Scanner' ) ) {
|
1289 |
+
require_once $mainwp_itsec_modules_path . 'malware/class-itsec-malware-scanner.php';
|
1290 |
+
require_once $mainwp_itsec_modules_path . 'malware/class-itsec-malware-scan-results-template.php';
|
1291 |
+
}
|
1292 |
+
|
1293 |
+
$response = array();
|
1294 |
+
if ( ! \ITSEC_Core::current_user_can_manage() ) {
|
1295 |
+
$response['error'] = 'The currently logged in user does not have sufficient permissions to run this scan.';
|
1296 |
+
} else {
|
1297 |
+
$results = \ITSEC_Malware_Scanner::scan();
|
1298 |
+
$response['html'] = \ITSEC_Malware_Scan_Results_Template::get_html( $results, true );
|
1299 |
+
}
|
1300 |
+
|
1301 |
+
return $response;
|
1302 |
+
}
|
1303 |
+
|
1304 |
+
/**
|
1305 |
+
* Get malware scan results.
|
1306 |
+
*
|
1307 |
+
* @return array $response Return response array.
|
1308 |
+
*
|
1309 |
+
* @uses \ITSEC_Malware_Scanner::scan()
|
1310 |
+
* @uses \ITSEC_Malware_Scan_Results_Template::get_html()
|
1311 |
+
*/
|
1312 |
+
public function malware_get_scan_results() {
|
1313 |
+
|
1314 |
+
/** @global string $mainwp_itsec_modules_path MainWP itsec modules path. */
|
1315 |
+
global $mainwp_itsec_modules_path;
|
1316 |
+
|
1317 |
+
if ( ! class_exists( '\ITSEC_Malware_Scanner' ) ) {
|
1318 |
+
require_once $mainwp_itsec_modules_path . 'malware/class-itsec-malware-scanner.php';
|
1319 |
+
require_once $mainwp_itsec_modules_path . 'malware/class-itsec-malware-scan-results-template.php';
|
1320 |
+
}
|
1321 |
+
$response = array();
|
1322 |
+
$results = \ITSEC_Malware_Scanner::scan();
|
1323 |
+
$response['html'] = \ITSEC_Malware_Scan_Results_Template::get_html( $results, true );
|
1324 |
+
return $response;
|
1325 |
+
}
|
1326 |
+
|
1327 |
+
/**
|
1328 |
+
* Purge logs.
|
1329 |
+
*
|
1330 |
+
* @return string[] Return response array.
|
1331 |
+
*/
|
1332 |
+
public function purge_logs() {
|
1333 |
+
|
1334 |
+
/** @global object $wpdb WordPress Database object. */
|
1335 |
+
global $wpdb;
|
1336 |
+
|
1337 |
+
$wpdb->query( 'DELETE FROM `' . $wpdb->base_prefix . 'itsec_log`;' );
|
1338 |
+
|
1339 |
+
return array( 'result' => 'success' );
|
1340 |
+
}
|
1341 |
+
|
1342 |
+
|
1343 |
+
/**
|
1344 |
+
* Get lockouts.
|
1345 |
+
*
|
1346 |
+
* @param string $type Type of lockout: Host, user, username, Default: all.
|
1347 |
+
* @param bool $current TRUE if current. Default: FALSE.
|
1348 |
+
*
|
1349 |
+
* @return array $output Return response array.
|
1350 |
+
*
|
1351 |
+
* @uses MainWP_Child_IThemes_Security::get_lockouts_int()
|
1352 |
+
*/
|
1353 |
+
public function get_lockouts( $type = 'all', $current = false ) {
|
1354 |
+
|
1355 |
+
/**
|
1356 |
+
* @global object $wpdb WordPress Database object.
|
1357 |
+
* @global object $itsec_globals itsec globals.
|
1358 |
+
*/
|
1359 |
+
global $wpdb, $itsec_globals;
|
1360 |
+
|
1361 |
+
if ( 'all' !== $type || true === $current ) {
|
1362 |
+
$where = ' WHERE ';
|
1363 |
+
} else {
|
1364 |
+
$where = '';
|
1365 |
+
}
|
1366 |
+
|
1367 |
+
switch ( $type ) {
|
1368 |
+
|
1369 |
+
case 'host':
|
1370 |
+
$type_statement = "`lockout_host` IS NOT NULL && `lockout_host` != ''";
|
1371 |
+
break;
|
1372 |
+
case 'user':
|
1373 |
+
$type_statement = '`lockout_user` != 0';
|
1374 |
+
break;
|
1375 |
+
case 'username':
|
1376 |
+
$type_statement = "`lockout_username` IS NOT NULL && `lockout_username` != ''";
|
1377 |
+
break;
|
1378 |
+
default:
|
1379 |
+
$type_statement = '';
|
1380 |
+
break;
|
1381 |
+
|
1382 |
+
}
|
1383 |
+
|
1384 |
+
if ( true === $current ) {
|
1385 |
+
|
1386 |
+
if ( '' !== $type_statement ) {
|
1387 |
+
$and = ' AND ';
|
1388 |
+
} else {
|
1389 |
+
$and = '';
|
1390 |
+
}
|
1391 |
+
|
1392 |
+
$active = $and . " `lockout_active`=1 AND `lockout_expire_gmt` > '" . gmdate( 'Y-m-d H:i:s', $itsec_globals['current_time_gmt'] ) . "'";
|
1393 |
+
|
1394 |
+
} else {
|
1395 |
+
|
1396 |
+
$active = '';
|
1397 |
+
|
1398 |
+
}
|
1399 |
+
$results = $wpdb->get_results( 'SELECT * FROM `' . $wpdb->base_prefix . 'itsec_lockouts`' . $where . $type_statement . $active . ';', ARRAY_A ); // phpcs:ignore -- safe query. $output = array();
|
1400 |
+
|
1401 |
+
return $this->get_lockouts_int( $results, $type );
|
1402 |
+
}
|
1403 |
+
|
1404 |
+
/**
|
1405 |
+
* Initiate get lockouts.
|
1406 |
+
*
|
1407 |
+
* @param array $results Results from MainWP_Child_IThemes_Security::get_lockouts()
|
1408 |
+
* @param string $type Type of lockout: Host, user, username, Default: all.
|
1409 |
+
*
|
1410 |
+
* @return array $output Return response array.
|
1411 |
+
*/
|
1412 |
+
private function get_lockouts_int($results, $type ){
|
1413 |
+
|
1414 |
+
if ( is_array( $results ) && count( $results ) > 0 ) {
|
1415 |
+
switch ( $type ) {
|
1416 |
+
case 'host':
|
1417 |
+
foreach ( $results as $val ) {
|
1418 |
+
$output[] = array(
|
1419 |
+
'lockout_id' => $val['lockout_id'],
|
1420 |
+
'lockout_host' => $val['lockout_host'],
|
1421 |
+
'lockout_expire_gmt' => $val['lockout_expire_gmt'],
|
1422 |
+
);
|
1423 |
+
}
|
1424 |
+
break;
|
1425 |
+
case 'user':
|
1426 |
+
foreach ( $results as $val ) {
|
1427 |
+
$output[] = array(
|
1428 |
+
'lockout_id' => $val['lockout_id'],
|
1429 |
+
'lockout_user' => $val['lockout_user'],
|
1430 |
+
'lockout_expire_gmt' => $val['lockout_expire_gmt'],
|
1431 |
+
);
|
1432 |
+
}
|
1433 |
+
break;
|
1434 |
+
case 'username':
|
1435 |
+
foreach ( $results as $val ) {
|
1436 |
+
$output[] = array(
|
1437 |
+
'lockout_id' => $val['lockout_id'],
|
1438 |
+
'lockout_username' => $val['lockout_username'],
|
1439 |
+
'lockout_expire_gmt' => $val['lockout_expire_gmt'],
|
1440 |
+
);
|
1441 |
+
}
|
1442 |
+
break;
|
1443 |
+
default:
|
1444 |
+
break;
|
1445 |
+
}
|
1446 |
+
}
|
1447 |
+
|
1448 |
+
return $output;
|
1449 |
+
|
1450 |
+
}
|
1451 |
+
|
1452 |
+
/**
|
1453 |
+
* Release lockout.
|
1454 |
+
*
|
1455 |
+
* @return string[] Return results array.
|
1456 |
+
*
|
1457 |
+
* @uses \ITSEC_Lib::clear_caches()
|
1458 |
+
*/
|
1459 |
+
public function release_lockout() {
|
1460 |
+
|
1461 |
+
/** @global object $wpdb WordPress Database. */
|
1462 |
+
global $wpdb;
|
1463 |
+
|
1464 |
+
if ( ! class_exists( '\ITSEC_Lib' ) ) {
|
1465 |
+
require \ITSEC_Core::get_core_dir() . '/core/class-itsec-lib.php';
|
1466 |
+
}
|
1467 |
+
|
1468 |
+
$lockout_ids = array_map( 'sanitize_text_field', wp_unslash( $_POST['lockout_ids'] ) );
|
1469 |
+
if ( ! is_array( $lockout_ids ) ) {
|
1470 |
+
$lockout_ids = array();
|
1471 |
+
}
|
1472 |
+
|
1473 |
+
$type = 'updated';
|
1474 |
+
$message = __( 'The selected lockouts have been cleared.', 'mainwp-child' );
|
1475 |
+
|
1476 |
+
foreach ( $lockout_ids as $value ) {
|
1477 |
+
$wpdb->update(
|
1478 |
+
$wpdb->base_prefix . 'itsec_lockouts',
|
1479 |
+
array(
|
1480 |
+
'lockout_active' => 0,
|
1481 |
+
),
|
1482 |
+
array(
|
1483 |
+
'lockout_id' => intval( $value ),
|
1484 |
+
)
|
1485 |
+
);
|
1486 |
+
}
|
1487 |
+
|
1488 |
+
\ITSEC_Lib::clear_caches();
|
1489 |
+
|
1490 |
+
if ( ! is_multisite() ) {
|
1491 |
+
if ( ! function_exists( 'add_settings_error' ) ) {
|
1492 |
+
require_once ABSPATH . '/wp-admin/includes/template.php';
|
1493 |
+
}
|
1494 |
+
|
1495 |
+
add_settings_error( 'itsec', esc_attr( 'settings_updated' ), $message, $type );
|
1496 |
+
}
|
1497 |
+
|
1498 |
+
return array(
|
1499 |
+
'result' => 'success',
|
1500 |
+
);
|
1501 |
+
}
|
1502 |
+
|
1503 |
+
/**
|
1504 |
+
* Update module status.
|
1505 |
+
*
|
1506 |
+
* @return string[] Return response array.
|
1507 |
+
*/
|
1508 |
+
public function update_module_status() {
|
1509 |
+
|
1510 |
+
$active_modules = isset( $_POST['active_modules'] ) ? array_map( 'sanitize_text_field', wp_unslash( $_POST['active_modules'] ) ) : array();
|
1511 |
+
|
1512 |
+
if ( ! is_array( $active_modules ) ) {
|
1513 |
+
$active_modules = array();
|
1514 |
+
}
|
1515 |
+
|
1516 |
+
$current_val = get_site_option( 'itsec_active_modules', array() );
|
1517 |
+
foreach ( $active_modules as $mod => $val ) {
|
1518 |
+
$current_val[ $mod ] = $val;
|
1519 |
+
}
|
1520 |
+
|
1521 |
+
update_site_option( 'itsec_active_modules', $current_val );
|
1522 |
+
return array( 'result' => 'success' );
|
1523 |
+
}
|
1524 |
+
|
1525 |
+
/**
|
1526 |
+
* Reload excluded backups table.
|
1527 |
+
*
|
1528 |
+
* @return array Return response array.
|
1529 |
+
*
|
1530 |
+
* @uses \ITSEC_Modules::get_setting()
|
1531 |
+
* @uses MainWP_Child_IThemes_Security::get_excludable_tables()
|
1532 |
+
*/
|
1533 |
+
private function reload_backup_exclude() {
|
1534 |
+
return array(
|
1535 |
+
'exclude' => \ITSEC_Modules::get_setting( 'backup', 'exclude' ),
|
1536 |
+
'excludable_tables' => $this->get_excludable_tables(),
|
1537 |
+
'result' => 'success',
|
1538 |
+
);
|
1539 |
+
}
|
1540 |
+
|
1541 |
+
/**
|
1542 |
+
* Get excludable backups table.
|
1543 |
+
*
|
1544 |
+
* @return array $excludes Return response array.
|
1545 |
+
*
|
1546 |
+
* @uses \ITSEC_Modules::get_setting()
|
1547 |
+
*/
|
1548 |
+
private function get_excludable_tables() {
|
1549 |
+
|
1550 |
+
/** @global object $wpdb WordPress Database. */
|
1551 |
+
global $wpdb;
|
1552 |
+
|
1553 |
+
$all_sites = \ITSEC_Modules::get_setting( 'backup', 'all_sites' );
|
1554 |
+
$ignored_tables = array(
|
1555 |
+
'commentmeta',
|
1556 |
+
'comments',
|
1557 |
+
'links',
|
1558 |
+
'options',
|
1559 |
+
'postmeta',
|
1560 |
+
'posts',
|
1561 |
+
'term_relationships',
|
1562 |
+
'term_taxonomy',
|
1563 |
+
'terms',
|
1564 |
+
'usermeta',
|
1565 |
+
'users',
|
1566 |
+
);
|
1567 |
+
|
1568 |
+
if ( $all_sites ) {
|
1569 |
+
$query = 'SHOW TABLES';
|
1570 |
+
} else {
|
1571 |
+
$query = $wpdb->prepare( 'SHOW TABLES LIKE %s', "{$wpdb->base_prefix}%" );
|
1572 |
+
}
|
1573 |
+
|
1574 |
+
$tables = $wpdb->get_results( $query, ARRAY_N ); // phpcs:ignore -- safe query.
|
1575 |
+
$excludes = array();
|
1576 |
+
|
1577 |
+
foreach ( $tables as $table ) {
|
1578 |
+
$short_table = substr( $table[0], strlen( $wpdb->prefix ) );
|
1579 |
+
|
1580 |
+
if ( in_array( $short_table, $ignored_tables ) ) {
|
1581 |
+
continue;
|
1582 |
+
}
|
1583 |
+
|
1584 |
+
$excludes[ $short_table ] = $table[0];
|
1585 |
+
}
|
1586 |
+
|
1587 |
+
return $excludes;
|
1588 |
+
}
|
1589 |
+
|
1590 |
+
/**
|
1591 |
+
* Get security check results.
|
1592 |
+
*
|
1593 |
+
* @return array Return response array.
|
1594 |
+
*
|
1595 |
+
* @uses \ITSEC_Security_Check_Scanner::get_results()
|
1596 |
+
* @uses \ITSEC_Security_Check_Feedback_Renderer::render(
|
1597 |
+
*/
|
1598 |
+
private function security_site() {
|
1599 |
+
|
1600 |
+
/** @global string $mainwp_itsec_modules_path MainWP itsec modules path. */
|
1601 |
+
global $mainwp_itsec_modules_path;
|
1602 |
+
|
1603 |
+
require_once $mainwp_itsec_modules_path . 'security-check/scanner.php';
|
1604 |
+
require_once $mainwp_itsec_modules_path . 'security-check/feedback-renderer.php';
|
1605 |
+
$results = \ITSEC_Security_Check_Scanner::get_results();
|
1606 |
+
ob_start();
|
1607 |
+
\ITSEC_Security_Check_Feedback_Renderer::render( $results );
|
1608 |
+
$response = ob_get_clean();
|
1609 |
+
return array(
|
1610 |
+
'result' => 'success',
|
1611 |
+
'response' => $response,
|
1612 |
+
);
|
1613 |
+
}
|
1614 |
+
|
1615 |
+
/**
|
1616 |
+
* Get available admin users and roles.
|
1617 |
+
*
|
1618 |
+
* @return array[] Return response array.phpdoc
|
1619 |
+
*
|
1620 |
+
* @uses \WP_Roles()
|
1621 |
+
*/
|
1622 |
+
public function get_available_admin_users_and_roles() {
|
1623 |
+
if ( is_callable( 'wp_roles' ) ) {
|
1624 |
+
$roles = wp_roles();
|
1625 |
+
} else {
|
1626 |
+
$roles = new \WP_Roles();
|
1627 |
+
}
|
1628 |
+
|
1629 |
+
$available_roles = array();
|
1630 |
+
$available_users = array();
|
1631 |
+
|
1632 |
+
foreach ( $roles->roles as $role => $details ) {
|
1633 |
+
if ( isset( $details['capabilities']['manage_options'] ) && ( true === $details['capabilities']['manage_options'] ) ) {
|
1634 |
+
$available_roles[ "role:$role" ] = translate_user_role( $details['name'] );
|
1635 |
+
|
1636 |
+
$users = get_users( array( 'role' => $role ) );
|
1637 |
+
|
1638 |
+
foreach ( $users as $user ) {
|
1639 |
+
/* translators: 1: user display name, 2: user login */
|
1640 |
+
$available_users[ $user->ID ] = sprintf( __( '%1$s (%2$s)', 'mainwp-child' ), $user->display_name, $user->user_login );
|
1641 |
+
}
|
1642 |
+
}
|
1643 |
+
}
|
1644 |
+
|
1645 |
+
natcasesort( $available_users );
|
1646 |
+
|
1647 |
+
return array(
|
1648 |
+
'users' => $available_users,
|
1649 |
+
'roles' => $available_roles,
|
1650 |
+
);
|
1651 |
+
}
|
1652 |
+
|
1653 |
+
}
|
class/class-mainwp-child-posts.php
CHANGED
@@ -1,1347 +1,1448 @@
|
|
1 |
-
<?php
|
2 |
-
/**
|
3 |
-
* MainWP Child posts handler
|
4 |
-
*
|
5 |
-
* This file handles all post & post plus actions.
|
6 |
-
*
|
7 |
-
* @package MainWP\Child
|
8 |
-
*/
|
9 |
-
|
10 |
-
namespace MainWP\Child;
|
11 |
-
|
12 |
-
//phpcs:disable Generic.Metrics.CyclomaticComplexity -- Required to achieve desired results, pull request solutions appreciated.
|
13 |
-
|
14 |
-
/**
|
15 |
-
* Class MainWP_Child_Posts
|
16 |
-
*
|
17 |
-
* Handle all post & post plus actions.
|
18 |
-
*/
|
19 |
-
class MainWP_Child_Posts {
|
20 |
-
|
21 |
-
/**
|
22 |
-
* Public static variable to hold the single instance of MainWP_Child_Posts.
|
23 |
-
*
|
24 |
-
* @var mixed Default null
|
25 |
-
*/
|
26 |
-
protected static $instance = null;
|
27 |
-
|
28 |
-
/**
|
29 |
-
* Comments and clauses.
|
30 |
-
*
|
31 |
-
* @var string Comments and clauses.
|
32 |
-
*/
|
33 |
-
private $comments_and_clauses;
|
34 |
-
|
35 |
-
/**
|
36 |
-
* Posts with given suffix.
|
37 |
-
*
|
38 |
-
* @var string Posts with given suffix.
|
39 |
-
*/
|
40 |
-
private $posts_where_suffix;
|
41 |
-
|
42 |
-
/**
|
43 |
-
* Get class name.
|
44 |
-
*
|
45 |
-
* @return string __CLASS__ Class name.
|
46 |
-
*/
|
47 |
-
public static function get_class_name() {
|
48 |
-
return __CLASS__;
|
49 |
-
}
|
50 |
-
|
51 |
-
/**
|
52 |
-
* MainWP_Child_Posts constructor
|
53 |
-
*
|
54 |
-
* Run any time class is called.
|
55 |
-
*
|
56 |
-
* @uses \MainWP\Child\MainWP_Child_Posts::comments_and_clauses()
|
57 |
-
* @uses \MainWP\Child\MainWP_Child_Posts::posts_where_suffix()
|
58 |
-
*/
|
59 |
-
public function __construct() {
|
60 |
-
$this->comments_and_clauses = '';
|
61 |
-
$this->posts_where_suffix = '';
|
62 |
-
}
|
63 |
-
|
64 |
-
/**
|
65 |
-
* Create a public static instance of MainWP_Child_Posts.
|
66 |
-
*
|
67 |
-
* @return MainWP_Child_Posts|null
|
68 |
-
*/
|
69 |
-
public static function get_instance() {
|
70 |
-
if ( null === self::$instance ) {
|
71 |
-
self::$instance = new self();
|
72 |
-
}
|
73 |
-
|
74 |
-
return self::$instance;
|
75 |
-
}
|
76 |
-
|
77 |
-
|
78 |
-
/**
|
79 |
-
* Get recent posts.
|
80 |
-
*
|
81 |
-
* @param array $pAllowedStatuses Array of allowed post statuses.
|
82 |
-
* @param int $pCount Number of posts.
|
83 |
-
* @param string $type Post type.
|
84 |
-
* @param null $extra Extra tokens.
|
85 |
-
*
|
86 |
-
* @uses \MainWP\Child\MainWP_Child_Posts::get_recent_posts_int()
|
87 |
-
*
|
88 |
-
* @return array $allPost Return array of recent posts.
|
89 |
-
*/
|
90 |
-
public function get_recent_posts( $pAllowedStatuses, $pCount, $type = 'post', $extra = null ) {
|
91 |
-
$allPosts = array();
|
92 |
-
if ( null !== $pAllowedStatuses ) {
|
93 |
-
foreach ( $pAllowedStatuses as $status ) {
|
94 |
-
$this->get_recent_posts_int( $status, $pCount, $type, $allPosts, $extra );
|
95 |
-
}
|
96 |
-
} else {
|
97 |
-
$this->get_recent_posts_int( 'any', $pCount, $type, $allPosts, $extra );
|
98 |
-
}
|
99 |
-
|
100 |
-
return $allPosts;
|
101 |
-
}
|
102 |
-
|
103 |
-
/**
|
104 |
-
* Initiate get recent posts.
|
105 |
-
*
|
106 |
-
* @param string $status Post status.
|
107 |
-
* @param int $pCount Number of posts.
|
108 |
-
* @param string $type Post type.
|
109 |
-
* @param array $allPosts All posts array.
|
110 |
-
* @param null $extra Extra tokens.
|
111 |
-
*
|
112 |
-
* @uses \WPSEO_Link_Column_Count()
|
113 |
-
* @uses \WPSEO_Meta()
|
114 |
-
* @uses MainWP_WordPress_SEO::instance()::parse_column_score()
|
115 |
-
* @uses MainWP_WordPress_SEO::instance()->parse_column_score_readability()
|
116 |
-
* @uses \MainWP\Child\MainWP_Child_Posts::get_out_post()
|
117 |
-
*/
|
118 |
-
public function get_recent_posts_int( $status, $pCount, $type, &$allPosts, $extra = null ) {
|
119 |
-
|
120 |
-
$args = array(
|
121 |
-
'post_status' => $status,
|
122 |
-
'suppress_filters' => false,
|
123 |
-
'post_type' => $type,
|
124 |
-
);
|
125 |
-
|
126 |
-
$tokens = array();
|
127 |
-
if ( is_array( $extra ) && isset( $extra['tokens'] ) ) {
|
128 |
-
$tokens = $extra['tokens'];
|
129 |
-
if ( 1 == $extra['extract_post_type'] ) {
|
130 |
-
$args['post_type'] = 'post';
|
131 |
-
} elseif ( 2 == $extra['extract_post_type'] ) {
|
132 |
-
$args['post_type'] = 'page';
|
133 |
-
} elseif ( 3 == $extra['extract_post_type'] ) {
|
134 |
-
$args['post_type'] = array( 'post', 'page' );
|
135 |
-
}
|
136 |
-
}
|
137 |
-
$tokens = array_flip( $tokens );
|
138 |
-
|
139 |
-
if ( 0 !== $pCount ) {
|
140 |
-
$args['numberposts'] = $pCount;
|
141 |
-
}
|
142 |
-
|
143 |
-
$wp_seo_enabled = false;
|
144 |
-
if ( ! empty( $_POST['WPSEOEnabled'] ) ) {
|
145 |
-
if ( is_plugin_active( 'wordpress-seo/wp-seo.php' ) && class_exists( '\WPSEO_Link_Column_Count' ) && class_exists( '\WPSEO_Meta' ) ) {
|
146 |
-
$wp_seo_enabled = true;
|
147 |
-
}
|
148 |
-
}
|
149 |
-
|
150 |
-
$posts = get_posts( $args );
|
151 |
-
|
152 |
-
if ( is_array( $posts ) ) {
|
153 |
-
if ( $wp_seo_enabled ) {
|
154 |
-
$post_ids = array();
|
155 |
-
foreach ( $posts as $post ) {
|
156 |
-
$post_ids[] = $post->ID;
|
157 |
-
}
|
158 |
-
|
159 |
-
/**
|
160 |
-
* Credits
|
161 |
-
*
|
162 |
-
* Plugin-Name: Yoast SEO
|
163 |
-
* Plugin URI: https://yoast.com/wordpress/plugins/seo/#utm_source=wpadmin&utm_medium=plugin&utm_campaign=wpseoplugin
|
164 |
-
* Author: Team Yoast
|
165 |
-
* Author URI: https://yoast.com/
|
166 |
-
* Licence: GPL v3
|
167 |
-
*
|
168 |
-
* The code is used for the MainWP WordPress SEO Extension
|
169 |
-
* Extension URL: https://mainwp.com/extension/wordpress-seo/
|
170 |
-
*/
|
171 |
-
$link_count = new \WPSEO_Link_Column_Count();
|
172 |
-
$link_count->set( $post_ids );
|
173 |
-
}
|
174 |
-
foreach ( $posts as $post ) {
|
175 |
-
$outPost = $this->get_out_post( $post, $extra, $tokens );
|
176 |
-
if ( $wp_seo_enabled ) {
|
177 |
-
$outPost['seo_data'] = array(
|
178 |
-
'count_seo_links' => $link_count->get( $post->ID, 'internal_link_count' ),
|
179 |
-
'count_seo_linked' => $link_count->get( $post->ID, 'incoming_link_count' ),
|
180 |
-
'seo_score' => MainWP_WordPress_SEO::instance()->parse_column_score( $post->ID ),
|
181 |
-
'readability_score' => MainWP_WordPress_SEO::instance()->parse_column_score_readability( $post->ID ),
|
182 |
-
);
|
183 |
-
}
|
184 |
-
$allPosts[] = $outPost;
|
185 |
-
}
|
186 |
-
}
|
187 |
-
}
|
188 |
-
|
189 |
-
/**
|
190 |
-
* Build Post.
|
191 |
-
*
|
192 |
-
* @param array $post Post array.
|
193 |
-
* @param string $extra Post date & time.
|
194 |
-
* @param array $tokens Post tokens.
|
195 |
-
* @return array $outPost Return completed post.
|
196 |
-
*/
|
197 |
-
private function get_out_post( $post, $extra, $tokens ) {
|
198 |
-
$outPost = array();
|
199 |
-
$outPost['id'] = $post->ID;
|
200 |
-
$outPost['post_type'] = $post->post_type;
|
201 |
-
$outPost['status'] = $post->post_status;
|
202 |
-
$outPost['title'] = $post->post_title;
|
203 |
-
$outPost['comment_count'] = $post->comment_count;
|
204 |
-
if ( isset( $extra['where_post_date'] ) && ! empty( $extra['where_post_date'] ) ) {
|
205 |
-
$outPost['dts'] = strtotime( $post->post_date_gmt );
|
206 |
-
} else {
|
207 |
-
$outPost['dts'] = strtotime( $post->post_modified_gmt );
|
208 |
-
}
|
209 |
-
|
210 |
-
if ( 'page' == $post->post_type ) {
|
211 |
-
$outPost['dts'] = strtotime( $post->post_modified_gmt ); // to order by modified date.
|
212 |
-
}
|
213 |
-
|
214 |
-
if ( 'future' == $post->post_status ) {
|
215 |
-
$outPost['dts'] = strtotime( $post->post_date_gmt );
|
216 |
-
}
|
217 |
-
|
218 |
-
$usr = get_user_by( 'id', $post->post_author );
|
219 |
-
$outPost['author'] = ! empty( $usr ) ? $usr->user_nicename : 'removed';
|
220 |
-
$outPost['authorEmail'] = ! empty( $usr ) ? $usr->user_email : 'removed';
|
221 |
-
$categoryObjects = get_the_category( $post->ID );
|
222 |
-
$categories = '';
|
223 |
-
foreach ( $categoryObjects as $cat ) {
|
224 |
-
if ( '' !== $categories ) {
|
225 |
-
$categories .= ', ';
|
226 |
-
}
|
227 |
-
$categories .= $cat->name;
|
228 |
-
}
|
229 |
-
$outPost['categories'] = $categories;
|
230 |
-
|
231 |
-
$tagObjects = get_the_tags( $post->ID );
|
232 |
-
$tags = '';
|
233 |
-
if ( is_array( $tagObjects ) ) {
|
234 |
-
foreach ( $tagObjects as $tag ) {
|
235 |
-
if ( '' !== $tags ) {
|
236 |
-
$tags .= ', ';
|
237 |
-
}
|
238 |
-
$tags .= $tag->name;
|
239 |
-
}
|
240 |
-
}
|
241 |
-
$outPost['tags'] = $tags;
|
242 |
-
if ( is_array( $tokens ) ) {
|
243 |
-
if ( isset( $tokens['[post.url]'] ) ) {
|
244 |
-
$outPost['[post.url]'] = get_permalink( $post->ID );
|
245 |
-
}
|
246 |
-
if ( isset( $tokens['[post.website.url]'] ) ) {
|
247 |
-
$outPost['[post.website.url]'] = get_site_url();
|
248 |
-
}
|
249 |
-
if ( isset( $tokens['[post.website.name]'] ) ) {
|
250 |
-
$outPost['[post.website.name]'] = get_bloginfo( 'name' );
|
251 |
-
}
|
252 |
-
}
|
253 |
-
return $outPost;
|
254 |
-
}
|
255 |
-
|
256 |
-
/**
|
257 |
-
* Get all posts.
|
258 |
-
*
|
259 |
-
* @uses \MainWP\Child\MainWP_Child_Posts::get_all_posts_by_type()
|
260 |
-
*/
|
261 |
-
public function get_all_posts() {
|
262 |
-
$post_type = ( isset( $_POST['post_type'] ) ? sanitize_text_field( wp_unslash( $_POST['post_type'] ) ) : 'post' );
|
263 |
-
$this->get_all_posts_by_type( $post_type );
|
264 |
-
}
|
265 |
-
|
266 |
-
/**
|
267 |
-
* Get all pages.
|
268 |
-
*
|
269 |
-
* @uses \MainWP\Child\MainWP_Child_Posts::get_all_posts_by_type()
|
270 |
-
*/
|
271 |
-
public function get_all_pages() {
|
272 |
-
$this->get_all_posts_by_type( 'page' );
|
273 |
-
}
|
274 |
-
|
275 |
-
/**
|
276 |
-
* Append the Post's SQL WHERE clause suffix.
|
277 |
-
*
|
278 |
-
* @param string $where Post's SQL WHERE clause.
|
279 |
-
*
|
280 |
-
* @uses \MainWP\Child\MainWP_Child_Posts::posts_where_suffix()
|
281 |
-
*
|
282 |
-
* @return string $where The full SQL WHERE clause with the appended suffix.
|
283 |
-
*/
|
284 |
-
public function posts_where( $where ) {
|
285 |
-
if ( $this->posts_where_suffix ) {
|
286 |
-
$where .= ' ' . $this->posts_where_suffix;
|
287 |
-
}
|
288 |
-
|
289 |
-
return $where;
|
290 |
-
}
|
291 |
-
|
292 |
-
/**
|
293 |
-
* Get all posts by type.
|
294 |
-
*
|
295 |
-
* @param string $type Post type.
|
296 |
-
*
|
297 |
-
* @uses \MainWP\Child\MainWP_Child_Posts::posts_where_suffix()
|
298 |
-
* @uses \MainWP\Child\MainWP_Helper::write()
|
299 |
-
*/
|
300 |
-
public function get_all_posts_by_type( $type ) {
|
301 |
-
|
302 |
-
/**
|
303 |
-
* Object, providing access to the WordPress database.
|
304 |
-
*
|
305 |
-
* @global object $wpdb WordPress Database instance.
|
306 |
-
*/
|
307 |
-
global $wpdb;
|
308 |
-
|
309 |
-
add_filter( 'posts_where', array( &$this, 'posts_where' ) );
|
310 |
-
$where_post_date = isset( $_POST['where_post_date'] ) && ! empty( $_POST['where_post_date'] ) ? true : false;
|
311 |
-
if ( isset( $_POST['postId'] ) ) {
|
312 |
-
$this->posts_where_suffix .= $wpdb->prepare( " AND $wpdb->posts.ID = %d ", sanitize_text_field( wp_unslash( $_POST['postId'] ) ) );
|
313 |
-
} elseif ( isset( $_POST['userId'] ) ) {
|
314 |
-
$this->posts_where_suffix .= $wpdb->prepare( " AND $wpdb->posts.post_author = %d ", sanitize_text_field( wp_unslash( $_POST['userId'] ) ) );
|
315 |
-
} else {
|
316 |
-
if ( isset( $_POST['keyword'] ) && '' !== $_POST['keyword'] ) {
|
317 |
-
$search_on = isset( $_POST['search_on'] ) ? sanitize_text_field( wp_unslash( $_POST['search_on'] ) ) : '';
|
318 |
-
if ( 'title' == $search_on ) {
|
319 |
-
$this->posts_where_suffix .= $wpdb->prepare( " AND ( $wpdb->posts.post_title LIKE %s ) ", '%' . $wpdb->esc_like( sanitize_text_field( wp_unslash( $_POST['keyword'] ) ) ) . '%' );
|
320 |
-
} elseif ( 'content' == $search_on ) {
|
321 |
-
$this->posts_where_suffix .= $wpdb->prepare( " AND ( $wpdb->posts.post_content LIKE %s )", '%' . $wpdb->esc_like( sanitize_text_field( wp_unslash( $_POST['keyword'] ) ) ) . '%' );
|
322 |
-
} else {
|
323 |
-
$this->posts_where_suffix .= $wpdb->prepare( " AND ( $wpdb->posts.post_content LIKE %s OR $wpdb->posts.post_title LIKE %s )", '%' . $wpdb->esc_like( sanitize_text_field( wp_unslash( $_POST['keyword'] ) ) ) . '%', '%' . $wpdb->esc_like( sanitize_text_field( wp_unslash( $_POST['keyword'] ) ) ) . '%' );
|
324 |
-
}
|
325 |
-
}
|
326 |
-
if ( isset( $_POST['dtsstart'] ) && '' !== $_POST['dtsstart'] ) {
|
327 |
-
if ( $where_post_date ) {
|
328 |
-
$this->posts_where_suffix .= $wpdb->prepare( " AND $wpdb->posts.post_date > %s", $wpdb->esc_like( sanitize_text_field( wp_unslash( $_POST['dtsstart'] ) ) ) );
|
329 |
-
} else {
|
330 |
-
$this->posts_where_suffix .= $wpdb->prepare( " AND $wpdb->posts.post_modified > %s", $wpdb->esc_like( sanitize_text_field( wp_unslash( $_POST['dtsstart'] ) ) ) );
|
331 |
-
}
|
332 |
-
}
|
333 |
-
if ( isset( $_POST['dtsstop'] ) && '' !== $_POST['dtsstop'] ) {
|
334 |
-
if ( $where_post_date ) {
|
335 |
-
$this->posts_where_suffix .= $wpdb->prepare( " AND $wpdb->posts.post_date < %s ", $wpdb->esc_like( sanitize_text_field( wp_unslash( $_POST['dtsstop'] ) ) ) );
|
336 |
-
} else {
|
337 |
-
$this->posts_where_suffix .= $wpdb->prepare( " AND $wpdb->posts.post_modified < %s", $wpdb->esc_like( sanitize_text_field( wp_unslash( $_POST['dtsstop'] ) ) ) );
|
338 |
-
}
|
339 |
-
}
|
340 |
-
|
341 |
-
if ( isset( $_POST['exclude_page_type'] ) && wp_unslash( $_POST['exclude_page_type'] ) ) {
|
342 |
-
$this->posts_where_suffix .= " AND $wpdb->posts.post_type NOT IN ('page')";
|
343 |
-
}
|
344 |
-
}
|
345 |
-
|
346 |
-
$maxPages = 50;
|
347 |
-
if ( defined( 'MAINWP_CHILD_NR_OF_PAGES' ) ) {
|
348 |
-
$maxPages = MAINWP_CHILD_NR_OF_PAGES;
|
349 |
-
}
|
350 |
-
|
351 |
-
if ( isset( $_POST['maxRecords'] ) ) {
|
352 |
-
$maxPages = ! empty( $_POST['maxRecords'] ) ? intval( wp_unslash( $_POST['maxRecords'] ) ) : 0;
|
353 |
-
}
|
354 |
-
if ( 0 === $maxPages ) {
|
355 |
-
$maxPages = 99999;
|
356 |
-
}
|
357 |
-
|
358 |
-
$extra = array();
|
359 |
-
if ( isset( $_POST['extract_tokens'] ) ) {
|
360 |
-
$extra['tokens'] = isset( $_POST['extract_tokens'] ) ? maybe_unserialize( base64_decode( wp_unslash( $_POST['extract_tokens'] ) ) ) : ''; // phpcs:ignore WordPress.PHP.DiscouragedPHPFunctions -- base64_encode function is used for http encode compatible..
|
361 |
-
$extra['extract_post_type'] = isset( $_POST['extract_post_type'] ) ? sanitize_text_field( wp_unslash( $_POST['extract_post_type'] ) ) : '';
|
362 |
-
}
|
363 |
-
|
364 |
-
$extra['where_post_date'] = $where_post_date;
|
365 |
-
$rslt = isset( $_POST['status'] ) ? $this->get_recent_posts( explode( ',', wp_unslash( $_POST['status'] ) ), $maxPages, $type, $extra ) : '';
|
366 |
-
$this->posts_where_suffix = '';
|
367 |
-
|
368 |
-
MainWP_Helper::write( $rslt );
|
369 |
-
}
|
370 |
-
|
371 |
-
/**
|
372 |
-
* Build New Post.
|
373 |
-
*
|
374 |
-
* @uses \MainWP\Child\MainWP_Child_Posts::create_post()
|
375 |
-
* @uses \MainWP\Child\MainWP_Helper::instance()->error()
|
376 |
-
* @uses \MainWP\Child\MainWP_Helper::write()
|
377 |
-
*/
|
378 |
-
public function new_post() {
|
379 |
-
$new_post = isset( $_POST['new_post'] ) ? maybe_unserialize( base64_decode( wp_unslash( $_POST['new_post'] ) ) ) : ''; // phpcs:ignore WordPress.PHP.DiscouragedPHPFunctions -- base64_encode function is used for http encode compatible..
|
380 |
-
$post_custom = isset( $_POST['post_custom'] ) ? maybe_unserialize( base64_decode( wp_unslash( $_POST['post_custom'] ) ) ) : ''; // phpcs:ignore WordPress.PHP.DiscouragedPHPFunctions -- base64_encode function is used for http encode compatible..
|
381 |
-
$post_category = isset( $_POST['post_category'] ) ? rawurldecode( base64_decode( wp_unslash( $_POST['post_category'] ) ) ) : null; // phpcs:ignore WordPress.PHP.DiscouragedPHPFunctions -- base64_encode function is used for http encode compatible..
|
382 |
-
$post_tags = isset( $new_post['post_tags'] ) ? rawurldecode( $new_post['post_tags'] ) : null;
|
383 |
-
$post_featured_image = isset( $_POST['post_featured_image'] ) ? base64_decode( wp_unslash( $_POST['post_featured_image'] ) ) : ''; // phpcs:ignore WordPress.PHP.DiscouragedPHPFunctions -- base64_encode function is used for http encode compatible..
|
384 |
-
$upload_dir = isset( $_POST['mainwp_upload_dir'] ) ? maybe_unserialize( base64_decode( wp_unslash( $_POST['mainwp_upload_dir'] ) ) ) : ''; // phpcs:ignore WordPress.PHP.DiscouragedPHPFunctions -- base64_encode function is used for http encode compatible..
|
385 |
-
|
386 |
-
$others = array();
|
387 |
-
if ( isset( $_POST['featured_image_data'] ) && ! empty( $_POST['featured_image_data'] ) ) {
|
388 |
-
$others['featured_image_data'] = ! empty( $_POST['featured_image_data'] ) ? unserialize( base64_decode( wp_unslash( $_POST['featured_image_data'] ) ) ) : ''; // phpcs:ignore WordPress.PHP.DiscouragedPHPFunctions -- base64_encode function is used for http encode compatible..
|
389 |
-
}
|
390 |
-
|
391 |
-
$res = $this->create_post( $new_post, $post_custom, $post_category, $post_featured_image, $upload_dir, $post_tags, $others );
|
392 |
-
|
393 |
-
if ( is_array( $res ) && isset( $res['error'] ) ) {
|
394 |
-
MainWP_Helper::instance()->error( $res['error'] );
|
395 |
-
}
|
396 |
-
|
397 |
-
$created = $res['success'];
|
398 |
-
if ( true !== $created ) {
|
399 |
-
MainWP_Helper::instance()->error( 'Undefined error' );
|
400 |
-
}
|
401 |
-
|
402 |
-
$information['added'] = true;
|
403 |
-
$information['added_id'] = $res['added_id'];
|
404 |
-
$information['link'] = $res['link'];
|
405 |
-
|
406 |
-
do_action( 'mainwp_child_after_newpost', $res );
|
407 |
-
|
408 |
-
MainWP_Helper::write( $information );
|
409 |
-
}
|
410 |
-
|
411 |
-
/**
|
412 |
-
* Post Action.
|
413 |
-
*
|
414 |
-
* @uses \MainWP\Child\MainWP_Child_Links_Checker()
|
415 |
-
* @uses \MainWP\Child\MainWP_Child_Posts::get_post_edit()
|
416 |
-
* @uses \MainWP\Child\MainWP_Child_Posts::get_page_edit()
|
417 |
-
* @uses \MainWP\Child\MainWP_Helper::write()
|
418 |
-
* @uses \MainWP\Child\MainWP_Child_Links_Checker::get_class_name()
|
419 |
-
*/
|
420 |
-
public function post_action() {
|
421 |
-
$action = ! empty( $_POST['action'] ) ? sanitize_text_field( wp_unslash( $_POST['action'] ) ) : '';
|
422 |
-
$postId = isset( $_POST['id'] ) ? sanitize_text_field( wp_unslash( $_POST['id'] ) ) : '';
|
423 |
-
$my_post = array();
|
424 |
-
|
425 |
-
if ( 'publish' === $action ) {
|
426 |
-
$post_current = get_post( $postId );
|
427 |
-
if ( empty( $post_current ) ) {
|
428 |
-
$information['status'] = 'FAIL';
|
429 |
-
} else {
|
430 |
-
if ( 'future' == $post_current->post_status ) {
|
431 |
-
wp_publish_post( $postId );
|
432 |
-
wp_update_post(
|
433 |
-
array(
|
434 |
-
'ID' => $postId,
|
435 |
-
'post_date' => current_time( 'mysql', false ),
|
436 |
-
'post_date_gmt' => current_time( 'mysql', true ),
|
437 |
-
)
|
438 |
-
);
|
439 |
-
} else {
|
440 |
-
wp_update_post(
|
441 |
-
array(
|
442 |
-
'ID' => $postId,
|
443 |
-
'post_status' => 'publish',
|
444 |
-
)
|
445 |
-
);
|
446 |
-
}
|
447 |
-
}
|
448 |
-
} elseif ( 'update' === $action ) {
|
449 |
-
$postData = isset( $_POST['post_data'] ) ? wp_unslash( $_POST['post_data'] ) : array();
|
450 |
-
$my_post = is_array( $postData ) ? $postData : array();
|
451 |
-
wp_update_post( $my_post );
|
452 |
-
} elseif ( 'unpublish' === $action ) {
|
453 |
-
$my_post['ID'] = $postId;
|
454 |
-
$my_post['post_status'] = 'draft';
|
455 |
-
wp_update_post( $my_post );
|
456 |
-
} elseif ( 'trash' === $action ) {
|
457 |
-
add_action( 'trash_post', array( MainWP_Child_Links_Checker::get_class_name(), 'hook_post_deleted' ) );
|
458 |
-
wp_trash_post( $postId );
|
459 |
-
} elseif ( 'delete' === $action ) {
|
460 |
-
add_action( 'delete_post', array( MainWP_Child_Links_Checker::get_class_name(), 'hook_post_deleted' ) );
|
461 |
-
wp_delete_post( $postId, true );
|
462 |
-
} elseif ( 'restore' === $action ) {
|
463 |
-
wp_untrash_post( $postId );
|
464 |
-
} elseif ( 'update_meta' === $action ) {
|
465 |
-
$values = isset( $_POST['values'] ) ? maybe_unserialize( base64_decode( wp_unslash( $_POST['values'] ) ) ) : array(); // phpcs:ignore WordPress.PHP.DiscouragedPHPFunctions -- base64_encode function is used for http encode compatible..
|
466 |
-
$meta_key = $values['meta_key'];
|
467 |
-
$meta_value = $values['meta_value'];
|
468 |
-
$check_prev = $values['check_prev'];
|
469 |
-
|
470 |
-
foreach ( $meta_key as $i => $key ) {
|
471 |
-
if ( 1 === intval( $check_prev[ $i ] ) ) {
|
472 |
-
update_post_meta( $postId, $key, get_post_meta( $postId, $key, true ) ? get_post_meta( $postId, $key, true ) : $meta_value[ $i ] );
|
473 |
-
} else {
|
474 |
-
update_post_meta( $postId, $key, $meta_value[ $i ] );
|
475 |
-
}
|
476 |
-
}
|
477 |
-
} elseif ( 'get_edit' === $action ) {
|
478 |
-
$postId = isset( $_POST['id'] ) ? sanitize_text_field( wp_unslash( $_POST['id'] ) ) : '';
|
479 |
-
$post_type = isset( $_POST['post_type'] ) ? sanitize_text_field( wp_unslash( $_POST['post_type'] ) ) : '';
|
480 |
-
if ( 'post' == $post_type ) {
|
481 |
-
$my_post = $this->get_post_edit( $postId );
|
482 |
-
} else {
|
483 |
-
$my_post = $this->get_page_edit( $postId );
|
484 |
-
}
|
485 |
-
} else {
|
486 |
-
$information['status'] = 'FAIL';
|
487 |
-
}
|
488 |
-
|
489 |
-
if ( ! isset( $information['status'] ) ) {
|
490 |
-
$information['status'] = 'SUCCESS';
|
491 |
-
}
|
492 |
-
$information['my_post'] = $my_post;
|
493 |
-
MainWP_Helper::write( $information );
|
494 |
-
}
|
495 |
-
|
496 |
-
/**
|
497 |
-
* Get post edit data.
|
498 |
-
*
|
499 |
-
* @param string $id Post ID.
|
500 |
-
*
|
501 |
-
* @return array|bool Return $post_data or FALSE on failure.
|
502 |
-
*/
|
503 |
-
public function get_post_edit( $id ) {
|
504 |
-
$post = get_post( $id );
|
505 |
-
if ( $post ) {
|
506 |
-
$categoryObjects = get_the_category( $post->ID );
|
507 |
-
$categories = '';
|
508 |
-
foreach ( $categoryObjects as $cat ) {
|
509 |
-
if ( '' !== $categories ) {
|
510 |
-
$categories .= ', ';
|
511 |
-
}
|
512 |
-
$categories .= $cat->name;
|
513 |
-
}
|
514 |
-
$post_category = $categories;
|
515 |
-
|
516 |
-
$tagObjects = get_the_tags( $post->ID );
|
517 |
-
$tags = '';
|
518 |
-
if ( is_array( $tagObjects ) ) {
|
519 |
-
foreach ( $tagObjects as $tag ) {
|
520 |
-
if ( '' !== $tags ) {
|
521 |
-
$tags .= ', ';
|
522 |
-
}
|
523 |
-
$tags .= $tag->name;
|
524 |
-
}
|
525 |
-
}
|
526 |
-
$post_tags = $tags;
|
527 |
-
|
528 |
-
$post_custom = get_post_custom( $id );
|
529 |
-
|
530 |
-
$galleries = get_post_gallery( $id, false );
|
531 |
-
$post_gallery_images = array();
|
532 |
-
|
533 |
-
if ( is_array( $galleries ) && isset( $galleries['ids'] ) ) {
|
534 |
-
$attached_images = explode( ',', $galleries['ids'] );
|
535 |
-
foreach ( $attached_images as $attachment_id ) {
|
536 |
-
$attachment = get_post( $attachment_id );
|
537 |
-
if ( $attachment ) {
|
538 |
-
$post_gallery_images[] = array(
|
539 |
-
'id' => $attachment_id,
|
540 |
-
'alt' => get_post_meta( $attachment->ID, '_wp_attachment_image_alt', true ),
|
541 |
-
'caption' => $attachment->post_excerpt,
|
542 |
-
'description' => $attachment->post_content,
|
543 |
-
'src' => $attachment->guid,
|
544 |
-
'title' => $attachment->post_title,
|
545 |
-
);
|
546 |
-
}
|
547 |
-
}
|
548 |
-
}
|
549 |
-
|
550 |
-
include_once ABSPATH . 'wp-includes' . DIRECTORY_SEPARATOR . 'post-thumbnail-template.php';
|
551 |
-
$post_featured_image = get_post_thumbnail_id( $id );
|
552 |
-
$child_upload_dir = wp_upload_dir();
|
553 |
-
$new_post = array(
|
554 |
-
'edit_id' => $id,
|
555 |
-
'is_sticky' => is_sticky( $id ) ? 1 : 0,
|
556 |
-
'post_title' => $post->post_title,
|
557 |
-
'post_content' => $post->post_content,
|
558 |
-
'post_status' => $post->post_status,
|
559 |
-
'post_date' => $post->post_date,
|
560 |
-
'post_date_gmt' => $post->post_date_gmt,
|
561 |
-
'post_tags' => $post_tags,
|
562 |
-
'post_name' => $post->post_name,
|
563 |
-
'post_excerpt' => $post->post_excerpt,
|
564 |
-
'comment_status' => $post->comment_status,
|
565 |
-
'ping_status' => $post->ping_status,
|
566 |
-
'post_type' => $post->post_type,
|
567 |
-
);
|
568 |
-
|
569 |
-
if ( null != $post_featured_image ) { // Featured image is set, retrieve URL.
|
570 |
-
$img = wp_get_attachment_image_src( $post_featured_image, 'full' );
|
571 |
-
$post_featured_image = $img[0];
|
572 |
-
}
|
573 |
-
|
574 |
-
require_once ABSPATH . 'wp-admin/includes/post.php';
|
575 |
-
wp_set_post_lock( $id );
|
576 |
-
|
577 |
-
$post_data = array(
|
578 |
-
'new_post' => base64_encode( serialize( $new_post ) ), // phpcs:ignore WordPress.PHP.DiscouragedPHPFunctions -- base64_encode function is used for http encode compatible..
|
579 |
-
'post_custom' => base64_encode( serialize( $post_custom ) ), // phpcs:ignore WordPress.PHP.DiscouragedPHPFunctions -- base64_encode function is used for http encode compatible..
|
580 |
-
'post_category' => base64_encode( $post_category ), // phpcs:ignore WordPress.PHP.DiscouragedPHPFunctions -- base64_encode function is used for http encode compatible..
|
581 |
-
'post_featured_image' => base64_encode( $post_featured_image ), // phpcs:ignore WordPress.PHP.DiscouragedPHPFunctions -- base64_encode function is used for http encode compatible..
|
582 |
-
'post_gallery_images' => base64_encode( serialize( $post_gallery_images ) ), // phpcs:ignore WordPress.PHP.DiscouragedPHPFunctions -- base64_encode function is used for http encode compatible..
|
583 |
-
'child_upload_dir' => base64_encode( serialize( $child_upload_dir ) ), // phpcs:ignore WordPress.PHP.DiscouragedPHPFunctions -- base64_encode function is used for http encode compatible..
|
584 |
-
);
|
585 |
-
return $post_data;
|
586 |
-
|
587 |
-
}
|
588 |
-
return false;
|
589 |
-
}
|
590 |
-
|
591 |
-
/**
|
592 |
-
* Get page edit data.
|
593 |
-
*
|
594 |
-
* @param string $id Page ID.
|
595 |
-
*
|
596 |
-
* @return array|bool Return $post_data or FALSE on failure.
|
597 |
-
*/
|
598 |
-
public function get_page_edit( $id ) {
|
599 |
-
$post = get_post( $id );
|
600 |
-
if ( $post ) {
|
601 |
-
$post_custom = get_post_custom( $id );
|
602 |
-
include_once ABSPATH . 'wp-includes' . DIRECTORY_SEPARATOR . 'post-thumbnail-template.php';
|
603 |
-
$post_featured_image = get_post_thumbnail_id( $id );
|
604 |
-
$child_upload_dir = wp_upload_dir();
|
605 |
-
|
606 |
-
$new_post = array(
|
607 |
-
'edit_id' => $id,
|
608 |
-
'post_title' => $post->post_title,
|
609 |
-
'post_content' => $post->post_content,
|
610 |
-
'post_status' => $post->post_status,
|
611 |
-
'post_date' => $post->post_date,
|
612 |
-
'post_date_gmt' => $post->post_date_gmt,
|
613 |
-
'post_type' => 'page',
|
614 |
-
'post_name' => $post->post_name,
|
615 |
-
'post_excerpt' => $post->post_excerpt,
|
616 |
-
'comment_status' => $post->comment_status,
|
617 |
-
'ping_status' => $post->ping_status,
|
618 |
-
);
|
619 |
-
|
620 |
-
if ( null != $post_featured_image ) {
|
621 |
-
$img = wp_get_attachment_image_src( $post_featured_image, 'full' );
|
622 |
-
$post_featured_image = $img[0];
|
623 |
-
}
|
624 |
-
|
625 |
-
$galleries = get_post_gallery( $id, false );
|
626 |
-
$post_gallery_images = array();
|
627 |
-
|
628 |
-
if ( is_array( $galleries ) && isset( $galleries['ids'] ) ) {
|
629 |
-
$attached_images = explode( ',', $galleries['ids'] );
|
630 |
-
foreach ( $attached_images as $attachment_id ) {
|
631 |
-
$attachment = get_post( $attachment_id );
|
632 |
-
if ( $attachment ) {
|
633 |
-
$post_gallery_images[] = array(
|
634 |
-
'id' => $attachment_id,
|
635 |
-
'alt' => get_post_meta( $attachment->ID, '_wp_attachment_image_alt', true ),
|
636 |
-
'caption' => $attachment->post_excerpt,
|
637 |
-
'description' => $attachment->post_content,
|
638 |
-
'src' => $attachment->guid,
|
639 |
-
'title' => $attachment->post_title,
|
640 |
-
);
|
641 |
-
}
|
642 |
-
}
|
643 |
-
}
|
644 |
-
|
645 |
-
require_once ABSPATH . 'wp-admin/includes/post.php';
|
646 |
-
wp_set_post_lock( $id );
|
647 |
-
|
648 |
-
$post_data = array(
|
649 |
-
'new_post' => base64_encode( serialize( $new_post ) ), // phpcs:ignore WordPress.PHP.DiscouragedPHPFunctions -- base64_encode function is used for http encode compatible..
|
650 |
-
'post_custom' => base64_encode( serialize( $post_custom ) ), // phpcs:ignore WordPress.PHP.DiscouragedPHPFunctions -- base64_encode function is used for http encode compatible..
|
651 |
-
'post_featured_image' => base64_encode( $post_featured_image ), // phpcs:ignore WordPress.PHP.DiscouragedPHPFunctions -- base64_encode function is used for http encode compatible..
|
652 |
-
'post_gallery_images' => base64_encode( serialize( $post_gallery_images ) ), // phpcs:ignore WordPress.PHP.DiscouragedPHPFunctions -- base64_encode function is used for http encode compatible..
|
653 |
-
'child_upload_dir' => base64_encode( serialize( $child_upload_dir ) ), // phpcs:ignore WordPress.PHP.DiscouragedPHPFunctions -- base64_encode function is used for http encode compatible..
|
654 |
-
);
|
655 |
-
return $post_data;
|
656 |
-
}
|
657 |
-
return false;
|
658 |
-
}
|
659 |
-
|
660 |
-
/**
|
661 |
-
* Create new post.
|
662 |
-
*
|
663 |
-
* @param array $new_post Post data array.
|
664 |
-
* @param array $post_custom Post custom meta data.
|
665 |
-
* @param string $post_category Post categories.
|
666 |
-
* @param string $post_featured_image Post featured image.
|
667 |
-
* @param string $upload_dir Upload directory.
|
668 |
-
* @param string $post_tags Post tags.
|
669 |
-
* @param array $others Other data.
|
670 |
-
*
|
671 |
-
* @return array|string[] $ret Return success array, permalink & Post ID.
|
672 |
-
*
|
673 |
-
* @uses \MainWP\Child\MainWP_Child_Posts::set_post_custom_data()
|
674 |
-
* @uses \MainWP\Child\MainWP_Child_Posts::update_found_images()
|
675 |
-
* @uses \MainWP\Child\MainWP_Child_Posts::create_has_shortcode_gallery()
|
676 |
-
* @uses \MainWP\Child\MainWP_Child_Posts::create_post_plus()
|
677 |
-
* @uses \MainWP\Child\MainWP_Child_Posts::update_post_data()
|
678 |
-
*/
|
679 |
-
private function create_post(
|
680 |
-
$new_post,
|
681 |
-
$post_custom,
|
682 |
-
$post_category,
|
683 |
-
$post_featured_image,
|
684 |
-
$upload_dir,
|
685 |
-
$post_tags,
|
686 |
-
$others = array()
|
687 |
-
) {
|
688 |
-
|
689 |
-
/**
|
690 |
-
* Hook: `mainwp_before_post_update`
|
691 |
-
*
|
692 |
-
* Runs before creating or updating a post via MainWP dashboard.
|
693 |
-
*
|
694 |
-
* @param array $new_post � Post data array.
|
695 |
-
* @param array $post_custom � Post custom meta data.
|
696 |
-
* @param string $post_category � Post categories.
|
697 |
-
* @param string $post_tags � Post tags.
|
698 |
-
*/
|
699 |
-
do_action( 'mainwp_before_post_update', $new_post, $post_custom, $post_category, $post_tags, $others );
|
700 |
-
|
701 |
-
$edit_post_id = 0;
|
702 |
-
$is_post_plus = false;
|
703 |
-
|
704 |
-
$this->set_post_custom_data( $new_post, $post_custom, $post_tags, $edit_post_id, $is_post_plus, $others );
|
705 |
-
|
706 |
-
require_once ABSPATH . 'wp-admin/includes/post.php';
|
707 |
-
|
708 |
-
if ( $edit_post_id ) {
|
709 |
-
$user_id = wp_check_post_lock( $edit_post_id );
|
710 |
-
if ( $user_id ) {
|
711 |
-
$user = get_userdata( $user_id );
|
712 |
-
$error = sprintf( __( 'This content is currently locked. %s is currently editing.', 'mainwp-child' ), $user->display_name );
|
713 |
-
return array( 'error' => $error );
|
714 |
-
}
|
715 |
-
}
|
716 |
-
|
717 |
-
// if editing post then will check if image existed.
|
718 |
-
$check_image_existed = $edit_post_id ? true : false;
|
719 |
-
|
720 |
-
$this->update_found_images( $new_post, $upload_dir, $check_image_existed );
|
721 |
-
$this->create_has_shortcode_gallery( $new_post );
|
722 |
-
|
723 |
-
if ( $is_post_plus ) {
|
724 |
-
$this->create_post_plus( $new_post, $post_custom );
|
725 |
-
}
|
726 |
-
|
727 |
-
|
728 |
-
|
729 |
-
|
730 |
-
|
731 |
-
|
732 |
-
|
733 |
-
|
734 |
-
|
735 |
-
|
736 |
-
|
737 |
-
|
738 |
-
|
739 |
-
|
740 |
-
|
741 |
-
|
742 |
-
|
743 |
-
|
744 |
-
|
745 |
-
|
746 |
-
}
|
747 |
-
|
748 |
-
|
749 |
-
|
750 |
-
|
751 |
-
|
752 |
-
|
753 |
-
|
754 |
-
|
755 |
-
|
756 |
-
|
757 |
-
|
758 |
-
|
759 |
-
|
760 |
-
|
761 |
-
|
762 |
-
|
763 |
-
|
764 |
-
|
765 |
-
|
766 |
-
|
767 |
-
|
768 |
-
|
769 |
-
|
770 |
-
|
771 |
-
|
772 |
-
|
773 |
-
|
774 |
-
|
775 |
-
|
776 |
-
|
777 |
-
|
778 |
-
}
|
779 |
-
|
780 |
-
$
|
781 |
-
|
782 |
-
|
783 |
-
|
784 |
-
|
785 |
-
|
786 |
-
|
787 |
-
|
788 |
-
|
789 |
-
|
790 |
-
|
791 |
-
|
792 |
-
|
793 |
-
|
794 |
-
*
|
795 |
-
*
|
796 |
-
* @
|
797 |
-
|
798 |
-
|
799 |
-
|
800 |
-
|
801 |
-
|
802 |
-
|
803 |
-
|
804 |
-
|
805 |
-
|
806 |
-
|
807 |
-
|
808 |
-
|
809 |
-
|
810 |
-
|
811 |
-
|
812 |
-
|
813 |
-
|
814 |
-
|
815 |
-
|
816 |
-
|
817 |
-
|
818 |
-
|
819 |
-
|
820 |
-
|
821 |
-
|
822 |
-
|
823 |
-
|
824 |
-
|
825 |
-
|
826 |
-
|
827 |
-
|
828 |
-
|
829 |
-
|
830 |
-
|
831 |
-
|
832 |
-
|
833 |
-
if (
|
834 |
-
$new_post['
|
835 |
-
|
836 |
-
|
837 |
-
|
838 |
-
|
839 |
-
|
840 |
-
|
841 |
-
|
842 |
-
|
843 |
-
|
844 |
-
|
845 |
-
|
846 |
-
|
847 |
-
|
848 |
-
|
849 |
-
|
850 |
-
|
851 |
-
|
852 |
-
*
|
853 |
-
*
|
854 |
-
*
|
855 |
-
* @
|
856 |
-
* @
|
857 |
-
* @
|
858 |
-
* @
|
859 |
-
* @
|
860 |
-
* @
|
861 |
-
|
862 |
-
|
863 |
-
|
864 |
-
|
865 |
-
|
866 |
-
|
867 |
-
|
868 |
-
|
869 |
-
|
870 |
-
|
871 |
-
$
|
872 |
-
|
873 |
-
|
874 |
-
|
875 |
-
|
876 |
-
|
877 |
-
|
878 |
-
$this->
|
879 |
-
|
880 |
-
|
881 |
-
|
882 |
-
|
883 |
-
|
884 |
-
|
885 |
-
|
886 |
-
|
887 |
-
|
888 |
-
|
889 |
-
if (
|
890 |
-
|
891 |
-
|
892 |
-
|
893 |
-
|
894 |
-
|
895 |
-
|
896 |
-
|
897 |
-
|
898 |
-
|
899 |
-
|
900 |
-
|
901 |
-
|
902 |
-
|
903 |
-
|
904 |
-
|
905 |
-
|
906 |
-
|
907 |
-
*
|
908 |
-
*
|
909 |
-
|
910 |
-
|
911 |
-
|
912 |
-
|
913 |
-
|
914 |
-
|
915 |
-
|
916 |
-
|
917 |
-
|
918 |
-
|
919 |
-
|
920 |
-
'
|
921 |
-
|
922 |
-
|
923 |
-
|
924 |
-
|
925 |
-
|
926 |
-
|
927 |
-
|
928 |
-
|
929 |
-
|
930 |
-
|
931 |
-
|
932 |
-
|
933 |
-
|
934 |
-
|
935 |
-
|
936 |
-
|
937 |
-
|
938 |
-
|
939 |
-
|
940 |
-
}
|
941 |
-
}
|
942 |
-
}
|
943 |
-
|
944 |
-
|
945 |
-
|
946 |
-
|
947 |
-
|
948 |
-
|
949 |
-
|
950 |
-
|
951 |
-
|
952 |
-
|
953 |
-
*
|
954 |
-
|
955 |
-
|
956 |
-
|
957 |
-
|
958 |
-
|
959 |
-
|
960 |
-
|
961 |
-
|
962 |
-
|
963 |
-
|
964 |
-
|
965 |
-
|
966 |
-
|
967 |
-
|
968 |
-
|
969 |
-
|
970 |
-
|
971 |
-
|
972 |
-
|
973 |
-
|
974 |
-
|
975 |
-
|
976 |
-
|
977 |
-
|
978 |
-
$
|
979 |
-
$
|
980 |
-
|
981 |
-
|
982 |
-
|
983 |
-
|
984 |
-
|
985 |
-
|
986 |
-
|
987 |
-
|
988 |
-
|
989 |
-
|
990 |
-
|
991 |
-
|
992 |
-
|
993 |
-
|
994 |
-
|
995 |
-
|
996 |
-
|
997 |
-
|
998 |
-
|
999 |
-
|
1000 |
-
|
1001 |
-
|
1002 |
-
|
1003 |
-
|
1004 |
-
|
1005 |
-
|
1006 |
-
|
1007 |
-
|
1008 |
-
|
1009 |
-
|
1010 |
-
|
1011 |
-
|
1012 |
-
|
1013 |
-
|
1014 |
-
|
1015 |
-
|
1016 |
-
|
1017 |
-
|
1018 |
-
|
1019 |
-
|
1020 |
-
|
1021 |
-
|
1022 |
-
|
1023 |
-
|
1024 |
-
|
1025 |
-
|
1026 |
-
|
1027 |
-
|
1028 |
-
|
1029 |
-
|
1030 |
-
|
1031 |
-
|
1032 |
-
|
1033 |
-
|
1034 |
-
|
1035 |
-
|
1036 |
-
|
1037 |
-
|
1038 |
-
|
1039 |
-
|
1040 |
-
|
1041 |
-
|
1042 |
-
|
1043 |
-
|
1044 |
-
|
1045 |
-
|
1046 |
-
}
|
1047 |
-
}
|
1048 |
-
|
1049 |
-
|
1050 |
-
|
1051 |
-
|
1052 |
-
|
1053 |
-
|
1054 |
-
|
1055 |
-
|
1056 |
-
|
1057 |
-
|
1058 |
-
|
1059 |
-
|
1060 |
-
|
1061 |
-
|
1062 |
-
|
1063 |
-
|
1064 |
-
|
1065 |
-
|
1066 |
-
|
1067 |
-
|
1068 |
-
|
1069 |
-
|
1070 |
-
|
1071 |
-
|
1072 |
-
|
1073 |
-
|
1074 |
-
|
1075 |
-
|
1076 |
-
|
1077 |
-
|
1078 |
-
|
1079 |
-
|
1080 |
-
|
1081 |
-
|
1082 |
-
|
1083 |
-
|
1084 |
-
|
1085 |
-
|
1086 |
-
|
1087 |
-
|
1088 |
-
|
1089 |
-
|
1090 |
-
|
1091 |
-
|
1092 |
-
|
1093 |
-
|
1094 |
-
|
1095 |
-
|
1096 |
-
|
1097 |
-
|
1098 |
-
|
1099 |
-
|
1100 |
-
|
1101 |
-
|
1102 |
-
|
1103 |
-
|
1104 |
-
|
1105 |
-
|
1106 |
-
|
1107 |
-
|
1108 |
-
|
1109 |
-
|
1110 |
-
|
1111 |
-
|
1112 |
-
|
1113 |
-
|
1114 |
-
|
1115 |
-
|
1116 |
-
|
1117 |
-
|
1118 |
-
'
|
1119 |
-
|
1120 |
-
|
1121 |
-
|
1122 |
-
|
1123 |
-
|
1124 |
-
|
1125 |
-
|
1126 |
-
|
1127 |
-
|
1128 |
-
|
1129 |
-
|
1130 |
-
|
1131 |
-
|
1132 |
-
|
1133 |
-
|
1134 |
-
|
1135 |
-
|
1136 |
-
|
1137 |
-
|
1138 |
-
|
1139 |
-
|
1140 |
-
|
1141 |
-
|
1142 |
-
|
1143 |
-
|
1144 |
-
|
1145 |
-
|
1146 |
-
|
1147 |
-
|
1148 |
-
|
1149 |
-
|
1150 |
-
|
1151 |
-
|
1152 |
-
|
1153 |
-
|
1154 |
-
|
1155 |
-
|
1156 |
-
|
1157 |
-
|
1158 |
-
|
1159 |
-
|
1160 |
-
|
1161 |
-
|
1162 |
-
|
1163 |
-
|
1164 |
-
|
1165 |
-
|
1166 |
-
|
1167 |
-
|
1168 |
-
|
1169 |
-
|
1170 |
-
|
1171 |
-
|
1172 |
-
|
1173 |
-
|
1174 |
-
|
1175 |
-
|
1176 |
-
|
1177 |
-
|
1178 |
-
|
1179 |
-
|
1180 |
-
|
1181 |
-
|
1182 |
-
|
1183 |
-
|
1184 |
-
|
1185 |
-
|
1186 |
-
|
1187 |
-
|
1188 |
-
|
1189 |
-
|
1190 |
-
|
1191 |
-
|
1192 |
-
|
1193 |
-
|
1194 |
-
|
1195 |
-
|
1196 |
-
|
1197 |
-
|
1198 |
-
|
1199 |
-
|
1200 |
-
|
1201 |
-
|
1202 |
-
|
1203 |
-
|
1204 |
-
|
1205 |
-
|
1206 |
-
|
1207 |
-
|
1208 |
-
|
1209 |
-
|
1210 |
-
|
1211 |
-
|
1212 |
-
|
1213 |
-
|
1214 |
-
|
1215 |
-
|
1216 |
-
|
1217 |
-
|
1218 |
-
|
1219 |
-
|
1220 |
-
|
1221 |
-
|
1222 |
-
|
1223 |
-
|
1224 |
-
|
1225 |
-
|
1226 |
-
|
1227 |
-
|
1228 |
-
|
1229 |
-
|
1230 |
-
|
1231 |
-
|
1232 |
-
|
1233 |
-
|
1234 |
-
|
1235 |
-
|
1236 |
-
|
1237 |
-
|
1238 |
-
|
1239 |
-
|
1240 |
-
|
1241 |
-
|
1242 |
-
|
1243 |
-
|
1244 |
-
|
1245 |
-
|
1246 |
-
|
1247 |
-
|
1248 |
-
|
1249 |
-
|
1250 |
-
|
1251 |
-
|
1252 |
-
|
1253 |
-
|
1254 |
-
|
1255 |
-
|
1256 |
-
|
1257 |
-
|
1258 |
-
|
1259 |
-
|
1260 |
-
|
1261 |
-
}
|
1262 |
-
|
1263 |
-
|
1264 |
-
|
1265 |
-
|
1266 |
-
|
1267 |
-
|
1268 |
-
|
1269 |
-
|
1270 |
-
|
1271 |
-
|
1272 |
-
|
1273 |
-
|
1274 |
-
|
1275 |
-
|
1276 |
-
|
1277 |
-
|
1278 |
-
*
|
1279 |
-
|
1280 |
-
|
1281 |
-
|
1282 |
-
|
1283 |
-
|
1284 |
-
|
1285 |
-
|
1286 |
-
|
1287 |
-
|
1288 |
-
|
1289 |
-
|
1290 |
-
|
1291 |
-
|
1292 |
-
|
1293 |
-
|
1294 |
-
|
1295 |
-
|
1296 |
-
|
1297 |
-
|
1298 |
-
|
1299 |
-
|
1300 |
-
|
1301 |
-
|
1302 |
-
|
1303 |
-
|
1304 |
-
|
1305 |
-
|
1306 |
-
|
1307 |
-
|
1308 |
-
|
1309 |
-
|
1310 |
-
|
1311 |
-
|
1312 |
-
|
1313 |
-
|
1314 |
-
|
1315 |
-
|
1316 |
-
|
1317 |
-
|
1318 |
-
|
1319 |
-
|
1320 |
-
|
1321 |
-
|
1322 |
-
|
1323 |
-
|
1324 |
-
|
1325 |
-
|
1326 |
-
|
1327 |
-
|
1328 |
-
|
1329 |
-
|
1330 |
-
|
1331 |
-
|
1332 |
-
|
1333 |
-
|
1334 |
-
|
1335 |
-
|
1336 |
-
|
1337 |
-
|
1338 |
-
|
1339 |
-
|
1340 |
-
|
1341 |
-
|
1342 |
-
|
1343 |
-
|
1344 |
-
|
1345 |
-
|
1346 |
-
|
1347 |
-
}
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
1 |
+
<?php
|
2 |
+
/**
|
3 |
+
* MainWP Child posts handler
|
4 |
+
*
|
5 |
+
* This file handles all post & post plus actions.
|
6 |
+
*
|
7 |
+
* @package MainWP\Child
|
8 |
+
*/
|
9 |
+
|
10 |
+
namespace MainWP\Child;
|
11 |
+
|
12 |
+
//phpcs:disable Generic.Metrics.CyclomaticComplexity -- Required to achieve desired results, pull request solutions appreciated.
|
13 |
+
|
14 |
+
/**
|
15 |
+
* Class MainWP_Child_Posts
|
16 |
+
*
|
17 |
+
* Handle all post & post plus actions.
|
18 |
+
*/
|
19 |
+
class MainWP_Child_Posts {
|
20 |
+
|
21 |
+
/**
|
22 |
+
* Public static variable to hold the single instance of MainWP_Child_Posts.
|
23 |
+
*
|
24 |
+
* @var mixed Default null
|
25 |
+
*/
|
26 |
+
protected static $instance = null;
|
27 |
+
|
28 |
+
/**
|
29 |
+
* Comments and clauses.
|
30 |
+
*
|
31 |
+
* @var string Comments and clauses.
|
32 |
+
*/
|
33 |
+
private $comments_and_clauses;
|
34 |
+
|
35 |
+
/**
|
36 |
+
* Posts with given suffix.
|
37 |
+
*
|
38 |
+
* @var string Posts with given suffix.
|
39 |
+
*/
|
40 |
+
private $posts_where_suffix;
|
41 |
+
|
42 |
+
/**
|
43 |
+
* Get class name.
|
44 |
+
*
|
45 |
+
* @return string __CLASS__ Class name.
|
46 |
+
*/
|
47 |
+
public static function get_class_name() {
|
48 |
+
return __CLASS__;
|
49 |
+
}
|
50 |
+
|
51 |
+
/**
|
52 |
+
* MainWP_Child_Posts constructor
|
53 |
+
*
|
54 |
+
* Run any time class is called.
|
55 |
+
*
|
56 |
+
* @uses \MainWP\Child\MainWP_Child_Posts::comments_and_clauses()
|
57 |
+
* @uses \MainWP\Child\MainWP_Child_Posts::posts_where_suffix()
|
58 |
+
*/
|
59 |
+
public function __construct() {
|
60 |
+
$this->comments_and_clauses = '';
|
61 |
+
$this->posts_where_suffix = '';
|
62 |
+
}
|
63 |
+
|
64 |
+
/**
|
65 |
+
* Create a public static instance of MainWP_Child_Posts.
|
66 |
+
*
|
67 |
+
* @return MainWP_Child_Posts|null
|
68 |
+
*/
|
69 |
+
public static function get_instance() {
|
70 |
+
if ( null === self::$instance ) {
|
71 |
+
self::$instance = new self();
|
72 |
+
}
|
73 |
+
|
74 |
+
return self::$instance;
|
75 |
+
}
|
76 |
+
|
77 |
+
|
78 |
+
/**
|
79 |
+
* Get recent posts.
|
80 |
+
*
|
81 |
+
* @param array $pAllowedStatuses Array of allowed post statuses.
|
82 |
+
* @param int $pCount Number of posts.
|
83 |
+
* @param string $type Post type.
|
84 |
+
* @param null $extra Extra tokens.
|
85 |
+
*
|
86 |
+
* @uses \MainWP\Child\MainWP_Child_Posts::get_recent_posts_int()
|
87 |
+
*
|
88 |
+
* @return array $allPost Return array of recent posts.
|
89 |
+
*/
|
90 |
+
public function get_recent_posts( $pAllowedStatuses, $pCount, $type = 'post', $extra = null ) {
|
91 |
+
$allPosts = array();
|
92 |
+
if ( null !== $pAllowedStatuses ) {
|
93 |
+
foreach ( $pAllowedStatuses as $status ) {
|
94 |
+
$this->get_recent_posts_int( $status, $pCount, $type, $allPosts, $extra );
|
95 |
+
}
|
96 |
+
} else {
|
97 |
+
$this->get_recent_posts_int( 'any', $pCount, $type, $allPosts, $extra );
|
98 |
+
}
|
99 |
+
|
100 |
+
return $allPosts;
|
101 |
+
}
|
102 |
+
|
103 |
+
/**
|
104 |
+
* Initiate get recent posts.
|
105 |
+
*
|
106 |
+
* @param string $status Post status.
|
107 |
+
* @param int $pCount Number of posts.
|
108 |
+
* @param string $type Post type.
|
109 |
+
* @param array $allPosts All posts array.
|
110 |
+
* @param null $extra Extra tokens.
|
111 |
+
*
|
112 |
+
* @uses \WPSEO_Link_Column_Count()
|
113 |
+
* @uses \WPSEO_Meta()
|
114 |
+
* @uses MainWP_WordPress_SEO::instance()::parse_column_score()
|
115 |
+
* @uses MainWP_WordPress_SEO::instance()->parse_column_score_readability()
|
116 |
+
* @uses \MainWP\Child\MainWP_Child_Posts::get_out_post()
|
117 |
+
*/
|
118 |
+
public function get_recent_posts_int( $status, $pCount, $type, &$allPosts, $extra = null ) {
|
119 |
+
|
120 |
+
$args = array(
|
121 |
+
'post_status' => $status,
|
122 |
+
'suppress_filters' => false,
|
123 |
+
'post_type' => $type,
|
124 |
+
);
|
125 |
+
|
126 |
+
$tokens = array();
|
127 |
+
if ( is_array( $extra ) && isset( $extra['tokens'] ) ) {
|
128 |
+
$tokens = $extra['tokens'];
|
129 |
+
if ( 1 == $extra['extract_post_type'] ) {
|
130 |
+
$args['post_type'] = 'post';
|
131 |
+
} elseif ( 2 == $extra['extract_post_type'] ) {
|
132 |
+
$args['post_type'] = 'page';
|
133 |
+
} elseif ( 3 == $extra['extract_post_type'] ) {
|
134 |
+
$args['post_type'] = array( 'post', 'page' );
|
135 |
+
}
|
136 |
+
}
|
137 |
+
$tokens = array_flip( $tokens );
|
138 |
+
|
139 |
+
if ( 0 !== $pCount ) {
|
140 |
+
$args['numberposts'] = $pCount;
|
141 |
+
}
|
142 |
+
|
143 |
+
$wp_seo_enabled = false;
|
144 |
+
if ( ! empty( $_POST['WPSEOEnabled'] ) ) {
|
145 |
+
if ( is_plugin_active( 'wordpress-seo/wp-seo.php' ) && class_exists( '\WPSEO_Link_Column_Count' ) && class_exists( '\WPSEO_Meta' ) ) {
|
146 |
+
$wp_seo_enabled = true;
|
147 |
+
}
|
148 |
+
}
|
149 |
+
|
150 |
+
$posts = get_posts( $args );
|
151 |
+
|
152 |
+
if ( is_array( $posts ) ) {
|
153 |
+
if ( $wp_seo_enabled ) {
|
154 |
+
$post_ids = array();
|
155 |
+
foreach ( $posts as $post ) {
|
156 |
+
$post_ids[] = $post->ID;
|
157 |
+
}
|
158 |
+
|
159 |
+
/**
|
160 |
+
* Credits
|
161 |
+
*
|
162 |
+
* Plugin-Name: Yoast SEO
|
163 |
+
* Plugin URI: https://yoast.com/wordpress/plugins/seo/#utm_source=wpadmin&utm_medium=plugin&utm_campaign=wpseoplugin
|
164 |
+
* Author: Team Yoast
|
165 |
+
* Author URI: https://yoast.com/
|
166 |
+
* Licence: GPL v3
|
167 |
+
*
|
168 |
+
* The code is used for the MainWP WordPress SEO Extension
|
169 |
+
* Extension URL: https://mainwp.com/extension/wordpress-seo/
|
170 |
+
*/
|
171 |
+
$link_count = new \WPSEO_Link_Column_Count();
|
172 |
+
$link_count->set( $post_ids );
|
173 |
+
}
|
174 |
+
foreach ( $posts as $post ) {
|
175 |
+
$outPost = $this->get_out_post( $post, $extra, $tokens );
|
176 |
+
if ( $wp_seo_enabled ) {
|
177 |
+
$outPost['seo_data'] = array(
|
178 |
+
'count_seo_links' => $link_count->get( $post->ID, 'internal_link_count' ),
|
179 |
+
'count_seo_linked' => $link_count->get( $post->ID, 'incoming_link_count' ),
|
180 |
+
'seo_score' => MainWP_WordPress_SEO::instance()->parse_column_score( $post->ID ),
|
181 |
+
'readability_score' => MainWP_WordPress_SEO::instance()->parse_column_score_readability( $post->ID ),
|
182 |
+
);
|
183 |
+
}
|
184 |
+
$allPosts[] = $outPost;
|
185 |
+
}
|
186 |
+
}
|
187 |
+
}
|
188 |
+
|
189 |
+
/**
|
190 |
+
* Build Post.
|
191 |
+
*
|
192 |
+
* @param array $post Post array.
|
193 |
+
* @param string $extra Post date & time.
|
194 |
+
* @param array $tokens Post tokens.
|
195 |
+
* @return array $outPost Return completed post.
|
196 |
+
*/
|
197 |
+
private function get_out_post( $post, $extra, $tokens ) {
|
198 |
+
$outPost = array();
|
199 |
+
$outPost['id'] = $post->ID;
|
200 |
+
$outPost['post_type'] = $post->post_type;
|
201 |
+
$outPost['status'] = $post->post_status;
|
202 |
+
$outPost['title'] = $post->post_title;
|
203 |
+
$outPost['comment_count'] = $post->comment_count;
|
204 |
+
if ( isset( $extra['where_post_date'] ) && ! empty( $extra['where_post_date'] ) ) {
|
205 |
+
$outPost['dts'] = strtotime( $post->post_date_gmt );
|
206 |
+
} else {
|
207 |
+
$outPost['dts'] = strtotime( $post->post_modified_gmt );
|
208 |
+
}
|
209 |
+
|
210 |
+
if ( 'page' == $post->post_type ) {
|
211 |
+
$outPost['dts'] = strtotime( $post->post_modified_gmt ); // to order by modified date.
|
212 |
+
}
|
213 |
+
|
214 |
+
if ( 'future' == $post->post_status ) {
|
215 |
+
$outPost['dts'] = strtotime( $post->post_date_gmt );
|
216 |
+
}
|
217 |
+
|
218 |
+
$usr = get_user_by( 'id', $post->post_author );
|
219 |
+
$outPost['author'] = ! empty( $usr ) ? $usr->user_nicename : 'removed';
|
220 |
+
$outPost['authorEmail'] = ! empty( $usr ) ? $usr->user_email : 'removed';
|
221 |
+
$categoryObjects = get_the_category( $post->ID );
|
222 |
+
$categories = '';
|
223 |
+
foreach ( $categoryObjects as $cat ) {
|
224 |
+
if ( '' !== $categories ) {
|
225 |
+
$categories .= ', ';
|
226 |
+
}
|
227 |
+
$categories .= $cat->name;
|
228 |
+
}
|
229 |
+
$outPost['categories'] = $categories;
|
230 |
+
|
231 |
+
$tagObjects = get_the_tags( $post->ID );
|
232 |
+
$tags = '';
|
233 |
+
if ( is_array( $tagObjects ) ) {
|
234 |
+
foreach ( $tagObjects as $tag ) {
|
235 |
+
if ( '' !== $tags ) {
|
236 |
+
$tags .= ', ';
|
237 |
+
}
|
238 |
+
$tags .= $tag->name;
|
239 |
+
}
|
240 |
+
}
|
241 |
+
$outPost['tags'] = $tags;
|
242 |
+
if ( is_array( $tokens ) ) {
|
243 |
+
if ( isset( $tokens['[post.url]'] ) ) {
|
244 |
+
$outPost['[post.url]'] = get_permalink( $post->ID );
|
245 |
+
}
|
246 |
+
if ( isset( $tokens['[post.website.url]'] ) ) {
|
247 |
+
$outPost['[post.website.url]'] = get_site_url();
|
248 |
+
}
|
249 |
+
if ( isset( $tokens['[post.website.name]'] ) ) {
|
250 |
+
$outPost['[post.website.name]'] = get_bloginfo( 'name' );
|
251 |
+
}
|
252 |
+
}
|
253 |
+
return $outPost;
|
254 |
+
}
|
255 |
+
|
256 |
+
/**
|
257 |
+
* Get all posts.
|
258 |
+
*
|
259 |
+
* @uses \MainWP\Child\MainWP_Child_Posts::get_all_posts_by_type()
|
260 |
+
*/
|
261 |
+
public function get_all_posts() {
|
262 |
+
$post_type = ( isset( $_POST['post_type'] ) ? sanitize_text_field( wp_unslash( $_POST['post_type'] ) ) : 'post' );
|
263 |
+
$this->get_all_posts_by_type( $post_type );
|
264 |
+
}
|
265 |
+
|
266 |
+
/**
|
267 |
+
* Get all pages.
|
268 |
+
*
|
269 |
+
* @uses \MainWP\Child\MainWP_Child_Posts::get_all_posts_by_type()
|
270 |
+
*/
|
271 |
+
public function get_all_pages() {
|
272 |
+
$this->get_all_posts_by_type( 'page' );
|
273 |
+
}
|
274 |
+
|
275 |
+
/**
|
276 |
+
* Append the Post's SQL WHERE clause suffix.
|
277 |
+
*
|
278 |
+
* @param string $where Post's SQL WHERE clause.
|
279 |
+
*
|
280 |
+
* @uses \MainWP\Child\MainWP_Child_Posts::posts_where_suffix()
|
281 |
+
*
|
282 |
+
* @return string $where The full SQL WHERE clause with the appended suffix.
|
283 |
+
*/
|
284 |
+
public function posts_where( $where ) {
|
285 |
+
if ( $this->posts_where_suffix ) {
|
286 |
+
$where .= ' ' . $this->posts_where_suffix;
|
287 |
+
}
|
288 |
+
|
289 |
+
return $where;
|
290 |
+
}
|
291 |
+
|
292 |
+
/**
|
293 |
+
* Get all posts by type.
|
294 |
+
*
|
295 |
+
* @param string $type Post type.
|
296 |
+
*
|
297 |
+
* @uses \MainWP\Child\MainWP_Child_Posts::posts_where_suffix()
|
298 |
+
* @uses \MainWP\Child\MainWP_Helper::write()
|
299 |
+
*/
|
300 |
+
public function get_all_posts_by_type( $type ) {
|
301 |
+
|
302 |
+
/**
|
303 |
+
* Object, providing access to the WordPress database.
|
304 |
+
*
|
305 |
+
* @global object $wpdb WordPress Database instance.
|
306 |
+
*/
|
307 |
+
global $wpdb;
|
308 |
+
|
309 |
+
add_filter( 'posts_where', array( &$this, 'posts_where' ) );
|
310 |
+
$where_post_date = isset( $_POST['where_post_date'] ) && ! empty( $_POST['where_post_date'] ) ? true : false;
|
311 |
+
if ( isset( $_POST['postId'] ) ) {
|
312 |
+
$this->posts_where_suffix .= $wpdb->prepare( " AND $wpdb->posts.ID = %d ", sanitize_text_field( wp_unslash( $_POST['postId'] ) ) );
|
313 |
+
} elseif ( isset( $_POST['userId'] ) ) {
|
314 |
+
$this->posts_where_suffix .= $wpdb->prepare( " AND $wpdb->posts.post_author = %d ", sanitize_text_field( wp_unslash( $_POST['userId'] ) ) );
|
315 |
+
} else {
|
316 |
+
if ( isset( $_POST['keyword'] ) && '' !== $_POST['keyword'] ) {
|
317 |
+
$search_on = isset( $_POST['search_on'] ) ? sanitize_text_field( wp_unslash( $_POST['search_on'] ) ) : '';
|
318 |
+
if ( 'title' == $search_on ) {
|
319 |
+
$this->posts_where_suffix .= $wpdb->prepare( " AND ( $wpdb->posts.post_title LIKE %s ) ", '%' . $wpdb->esc_like( sanitize_text_field( wp_unslash( $_POST['keyword'] ) ) ) . '%' );
|
320 |
+
} elseif ( 'content' == $search_on ) {
|
321 |
+
$this->posts_where_suffix .= $wpdb->prepare( " AND ( $wpdb->posts.post_content LIKE %s )", '%' . $wpdb->esc_like( sanitize_text_field( wp_unslash( $_POST['keyword'] ) ) ) . '%' );
|
322 |
+
} else {
|
323 |
+
$this->posts_where_suffix .= $wpdb->prepare( " AND ( $wpdb->posts.post_content LIKE %s OR $wpdb->posts.post_title LIKE %s )", '%' . $wpdb->esc_like( sanitize_text_field( wp_unslash( $_POST['keyword'] ) ) ) . '%', '%' . $wpdb->esc_like( sanitize_text_field( wp_unslash( $_POST['keyword'] ) ) ) . '%' );
|
324 |
+
}
|
325 |
+
}
|
326 |
+
if ( isset( $_POST['dtsstart'] ) && '' !== $_POST['dtsstart'] ) {
|
327 |
+
if ( $where_post_date ) {
|
328 |
+
$this->posts_where_suffix .= $wpdb->prepare( " AND $wpdb->posts.post_date > %s", $wpdb->esc_like( sanitize_text_field( wp_unslash( $_POST['dtsstart'] ) ) ) );
|
329 |
+
} else {
|
330 |
+
$this->posts_where_suffix .= $wpdb->prepare( " AND $wpdb->posts.post_modified > %s", $wpdb->esc_like( sanitize_text_field( wp_unslash( $_POST['dtsstart'] ) ) ) );
|
331 |
+
}
|
332 |
+
}
|
333 |
+
if ( isset( $_POST['dtsstop'] ) && '' !== $_POST['dtsstop'] ) {
|
334 |
+
if ( $where_post_date ) {
|
335 |
+
$this->posts_where_suffix .= $wpdb->prepare( " AND $wpdb->posts.post_date < %s ", $wpdb->esc_like( sanitize_text_field( wp_unslash( $_POST['dtsstop'] ) ) ) );
|
336 |
+
} else {
|
337 |
+
$this->posts_where_suffix .= $wpdb->prepare( " AND $wpdb->posts.post_modified < %s", $wpdb->esc_like( sanitize_text_field( wp_unslash( $_POST['dtsstop'] ) ) ) );
|
338 |
+
}
|
339 |
+
}
|
340 |
+
|
341 |
+
if ( isset( $_POST['exclude_page_type'] ) && wp_unslash( $_POST['exclude_page_type'] ) ) {
|
342 |
+
$this->posts_where_suffix .= " AND $wpdb->posts.post_type NOT IN ('page')";
|
343 |
+
}
|
344 |
+
}
|
345 |
+
|
346 |
+
$maxPages = 50;
|
347 |
+
if ( defined( 'MAINWP_CHILD_NR_OF_PAGES' ) ) {
|
348 |
+
$maxPages = MAINWP_CHILD_NR_OF_PAGES;
|
349 |
+
}
|
350 |
+
|
351 |
+
if ( isset( $_POST['maxRecords'] ) ) {
|
352 |
+
$maxPages = ! empty( $_POST['maxRecords'] ) ? intval( wp_unslash( $_POST['maxRecords'] ) ) : 0;
|
353 |
+
}
|
354 |
+
if ( 0 === $maxPages ) {
|
355 |
+
$maxPages = 99999;
|
356 |
+
}
|
357 |
+
|
358 |
+
$extra = array();
|
359 |
+
if ( isset( $_POST['extract_tokens'] ) ) {
|
360 |
+
$extra['tokens'] = isset( $_POST['extract_tokens'] ) ? maybe_unserialize( base64_decode( wp_unslash( $_POST['extract_tokens'] ) ) ) : ''; // phpcs:ignore WordPress.PHP.DiscouragedPHPFunctions -- base64_encode function is used for http encode compatible..
|
361 |
+
$extra['extract_post_type'] = isset( $_POST['extract_post_type'] ) ? sanitize_text_field( wp_unslash( $_POST['extract_post_type'] ) ) : '';
|
362 |
+
}
|
363 |
+
|
364 |
+
$extra['where_post_date'] = $where_post_date;
|
365 |
+
$rslt = isset( $_POST['status'] ) ? $this->get_recent_posts( explode( ',', wp_unslash( $_POST['status'] ) ), $maxPages, $type, $extra ) : '';
|
366 |
+
$this->posts_where_suffix = '';
|
367 |
+
|
368 |
+
MainWP_Helper::write( $rslt );
|
369 |
+
}
|
370 |
+
|
371 |
+
/**
|
372 |
+
* Build New Post.
|
373 |
+
*
|
374 |
+
* @uses \MainWP\Child\MainWP_Child_Posts::create_post()
|
375 |
+
* @uses \MainWP\Child\MainWP_Helper::instance()->error()
|
376 |
+
* @uses \MainWP\Child\MainWP_Helper::write()
|
377 |
+
*/
|
378 |
+
public function new_post() {
|
379 |
+
$new_post = isset( $_POST['new_post'] ) ? maybe_unserialize( base64_decode( wp_unslash( $_POST['new_post'] ) ) ) : ''; // phpcs:ignore WordPress.PHP.DiscouragedPHPFunctions -- base64_encode function is used for http encode compatible..
|
380 |
+
$post_custom = isset( $_POST['post_custom'] ) ? maybe_unserialize( base64_decode( wp_unslash( $_POST['post_custom'] ) ) ) : ''; // phpcs:ignore WordPress.PHP.DiscouragedPHPFunctions -- base64_encode function is used for http encode compatible..
|
381 |
+
$post_category = isset( $_POST['post_category'] ) ? rawurldecode( base64_decode( wp_unslash( $_POST['post_category'] ) ) ) : null; // phpcs:ignore WordPress.PHP.DiscouragedPHPFunctions -- base64_encode function is used for http encode compatible..
|
382 |
+
$post_tags = isset( $new_post['post_tags'] ) ? rawurldecode( $new_post['post_tags'] ) : null;
|
383 |
+
$post_featured_image = isset( $_POST['post_featured_image'] ) ? base64_decode( wp_unslash( $_POST['post_featured_image'] ) ) : ''; // phpcs:ignore WordPress.PHP.DiscouragedPHPFunctions -- base64_encode function is used for http encode compatible..
|
384 |
+
$upload_dir = isset( $_POST['mainwp_upload_dir'] ) ? maybe_unserialize( base64_decode( wp_unslash( $_POST['mainwp_upload_dir'] ) ) ) : ''; // phpcs:ignore WordPress.PHP.DiscouragedPHPFunctions -- base64_encode function is used for http encode compatible..
|
385 |
+
|
386 |
+
$others = array();
|
387 |
+
if ( isset( $_POST['featured_image_data'] ) && ! empty( $_POST['featured_image_data'] ) ) {
|
388 |
+
$others['featured_image_data'] = ! empty( $_POST['featured_image_data'] ) ? unserialize( base64_decode( wp_unslash( $_POST['featured_image_data'] ) ) ) : ''; // phpcs:ignore WordPress.PHP.DiscouragedPHPFunctions -- base64_encode function is used for http encode compatible..
|
389 |
+
}
|
390 |
+
|
391 |
+
$res = $this->create_post( $new_post, $post_custom, $post_category, $post_featured_image, $upload_dir, $post_tags, $others );
|
392 |
+
|
393 |
+
if ( is_array( $res ) && isset( $res['error'] ) ) {
|
394 |
+
MainWP_Helper::instance()->error( $res['error'] );
|
395 |
+
}
|
396 |
+
|
397 |
+
$created = $res['success'];
|
398 |
+
if ( true !== $created ) {
|
399 |
+
MainWP_Helper::instance()->error( 'Undefined error' );
|
400 |
+
}
|
401 |
+
|
402 |
+
$information['added'] = true;
|
403 |
+
$information['added_id'] = $res['added_id'];
|
404 |
+
$information['link'] = $res['link'];
|
405 |
+
|
406 |
+
do_action( 'mainwp_child_after_newpost', $res );
|
407 |
+
|
408 |
+
MainWP_Helper::write( $information );
|
409 |
+
}
|
410 |
+
|
411 |
+
/**
|
412 |
+
* Post Action.
|
413 |
+
*
|
414 |
+
* @uses \MainWP\Child\MainWP_Child_Links_Checker()
|
415 |
+
* @uses \MainWP\Child\MainWP_Child_Posts::get_post_edit()
|
416 |
+
* @uses \MainWP\Child\MainWP_Child_Posts::get_page_edit()
|
417 |
+
* @uses \MainWP\Child\MainWP_Helper::write()
|
418 |
+
* @uses \MainWP\Child\MainWP_Child_Links_Checker::get_class_name()
|
419 |
+
*/
|
420 |
+
public function post_action() {
|
421 |
+
$action = ! empty( $_POST['action'] ) ? sanitize_text_field( wp_unslash( $_POST['action'] ) ) : '';
|
422 |
+
$postId = isset( $_POST['id'] ) ? sanitize_text_field( wp_unslash( $_POST['id'] ) ) : '';
|
423 |
+
$my_post = array();
|
424 |
+
|
425 |
+
if ( 'publish' === $action ) {
|
426 |
+
$post_current = get_post( $postId );
|
427 |
+
if ( empty( $post_current ) ) {
|
428 |
+
$information['status'] = 'FAIL';
|
429 |
+
} else {
|
430 |
+
if ( 'future' == $post_current->post_status ) {
|
431 |
+
wp_publish_post( $postId );
|
432 |
+
wp_update_post(
|
433 |
+
array(
|
434 |
+
'ID' => $postId,
|
435 |
+
'post_date' => current_time( 'mysql', false ),
|
436 |
+
'post_date_gmt' => current_time( 'mysql', true ),
|
437 |
+
)
|
438 |
+
);
|
439 |
+
} else {
|
440 |
+
wp_update_post(
|
441 |
+
array(
|
442 |
+
'ID' => $postId,
|
443 |
+
'post_status' => 'publish',
|
444 |
+
)
|
445 |
+
);
|
446 |
+
}
|
447 |
+
}
|
448 |
+
} elseif ( 'update' === $action ) {
|
449 |
+
$postData = isset( $_POST['post_data'] ) ? wp_unslash( $_POST['post_data'] ) : array();
|
450 |
+
$my_post = is_array( $postData ) ? $postData : array();
|
451 |
+
wp_update_post( $my_post );
|
452 |
+
} elseif ( 'unpublish' === $action ) {
|
453 |
+
$my_post['ID'] = $postId;
|
454 |
+
$my_post['post_status'] = 'draft';
|
455 |
+
wp_update_post( $my_post );
|
456 |
+
} elseif ( 'trash' === $action ) {
|
457 |
+
add_action( 'trash_post', array( MainWP_Child_Links_Checker::get_class_name(), 'hook_post_deleted' ) );
|
458 |
+
wp_trash_post( $postId );
|
459 |
+
} elseif ( 'delete' === $action ) {
|
460 |
+
add_action( 'delete_post', array( MainWP_Child_Links_Checker::get_class_name(), 'hook_post_deleted' ) );
|
461 |
+
wp_delete_post( $postId, true );
|
462 |
+
} elseif ( 'restore' === $action ) {
|
463 |
+
wp_untrash_post( $postId );
|
464 |
+
} elseif ( 'update_meta' === $action ) {
|
465 |
+
$values = isset( $_POST['values'] ) ? maybe_unserialize( base64_decode( wp_unslash( $_POST['values'] ) ) ) : array(); // phpcs:ignore WordPress.PHP.DiscouragedPHPFunctions -- base64_encode function is used for http encode compatible..
|
466 |
+
$meta_key = $values['meta_key'];
|
467 |
+
$meta_value = $values['meta_value'];
|
468 |
+
$check_prev = $values['check_prev'];
|
469 |
+
|
470 |
+
foreach ( $meta_key as $i => $key ) {
|
471 |
+
if ( 1 === intval( $check_prev[ $i ] ) ) {
|
472 |
+
update_post_meta( $postId, $key, get_post_meta( $postId, $key, true ) ? get_post_meta( $postId, $key, true ) : $meta_value[ $i ] );
|
473 |
+
} else {
|
474 |
+
update_post_meta( $postId, $key, $meta_value[ $i ] );
|
475 |
+
}
|
476 |
+
}
|
477 |
+
} elseif ( 'get_edit' === $action ) {
|
478 |
+
$postId = isset( $_POST['id'] ) ? sanitize_text_field( wp_unslash( $_POST['id'] ) ) : '';
|
479 |
+
$post_type = isset( $_POST['post_type'] ) ? sanitize_text_field( wp_unslash( $_POST['post_type'] ) ) : '';
|
480 |
+
if ( 'post' == $post_type ) {
|
481 |
+
$my_post = $this->get_post_edit( $postId );
|
482 |
+
} else {
|
483 |
+
$my_post = $this->get_page_edit( $postId );
|
484 |
+
}
|
485 |
+
} else {
|
486 |
+
$information['status'] = 'FAIL';
|
487 |
+
}
|
488 |
+
|
489 |
+
if ( ! isset( $information['status'] ) ) {
|
490 |
+
$information['status'] = 'SUCCESS';
|
491 |
+
}
|
492 |
+
$information['my_post'] = $my_post;
|
493 |
+
MainWP_Helper::write( $information );
|
494 |
+
}
|
495 |
+
|
496 |
+
/**
|
497 |
+
* Get post edit data.
|
498 |
+
*
|
499 |
+
* @param string $id Post ID.
|
500 |
+
*
|
501 |
+
* @return array|bool Return $post_data or FALSE on failure.
|
502 |
+
*/
|
503 |
+
public function get_post_edit( $id ) {
|
504 |
+
$post = get_post( $id );
|
505 |
+
if ( $post ) {
|
506 |
+
$categoryObjects = get_the_category( $post->ID );
|
507 |
+
$categories = '';
|
508 |
+
foreach ( $categoryObjects as $cat ) {
|
509 |
+
if ( '' !== $categories ) {
|
510 |
+
$categories .= ', ';
|
511 |
+
}
|
512 |
+
$categories .= $cat->name;
|
513 |
+
}
|
514 |
+
$post_category = $categories;
|
515 |
+
|
516 |
+
$tagObjects = get_the_tags( $post->ID );
|
517 |
+
$tags = '';
|
518 |
+
if ( is_array( $tagObjects ) ) {
|
519 |
+
foreach ( $tagObjects as $tag ) {
|
520 |
+
if ( '' !== $tags ) {
|
521 |
+
$tags .= ', ';
|
522 |
+
}
|
523 |
+
$tags .= $tag->name;
|
524 |
+
}
|
525 |
+
}
|
526 |
+
$post_tags = $tags;
|
527 |
+
|
528 |
+
$post_custom = get_post_custom( $id );
|
529 |
+
|
530 |
+
$galleries = get_post_gallery( $id, false );
|
531 |
+
$post_gallery_images = array();
|
532 |
+
|
533 |
+
if ( is_array( $galleries ) && isset( $galleries['ids'] ) ) {
|
534 |
+
$attached_images = explode( ',', $galleries['ids'] );
|
535 |
+
foreach ( $attached_images as $attachment_id ) {
|
536 |
+
$attachment = get_post( $attachment_id );
|
537 |
+
if ( $attachment ) {
|
538 |
+
$post_gallery_images[] = array(
|
539 |
+
'id' => $attachment_id,
|
540 |
+
'alt' => get_post_meta( $attachment->ID, '_wp_attachment_image_alt', true ),
|
541 |
+
'caption' => $attachment->post_excerpt,
|
542 |
+
'description' => $attachment->post_content,
|
543 |
+
'src' => $attachment->guid,
|
544 |
+
'title' => $attachment->post_title,
|
545 |
+
);
|
546 |
+
}
|
547 |
+
}
|
548 |
+
}
|
549 |
+
|
550 |
+
include_once ABSPATH . 'wp-includes' . DIRECTORY_SEPARATOR . 'post-thumbnail-template.php';
|
551 |
+
$post_featured_image = get_post_thumbnail_id( $id );
|
552 |
+
$child_upload_dir = wp_upload_dir();
|
553 |
+
$new_post = array(
|
554 |
+
'edit_id' => $id,
|
555 |
+
'is_sticky' => is_sticky( $id ) ? 1 : 0,
|
556 |
+
'post_title' => $post->post_title,
|
557 |
+
'post_content' => $post->post_content,
|
558 |
+
'post_status' => $post->post_status,
|
559 |
+
'post_date' => $post->post_date,
|
560 |
+
'post_date_gmt' => $post->post_date_gmt,
|
561 |
+
'post_tags' => $post_tags,
|
562 |
+
'post_name' => $post->post_name,
|
563 |
+
'post_excerpt' => $post->post_excerpt,
|
564 |
+
'comment_status' => $post->comment_status,
|
565 |
+
'ping_status' => $post->ping_status,
|
566 |
+
'post_type' => $post->post_type,
|
567 |
+
);
|
568 |
+
|
569 |
+
if ( null != $post_featured_image ) { // Featured image is set, retrieve URL.
|
570 |
+
$img = wp_get_attachment_image_src( $post_featured_image, 'full' );
|
571 |
+
$post_featured_image = $img[0];
|
572 |
+
}
|
573 |
+
|
574 |
+
require_once ABSPATH . 'wp-admin/includes/post.php';
|
575 |
+
wp_set_post_lock( $id );
|
576 |
+
|
577 |
+
$post_data = array(
|
578 |
+
'new_post' => base64_encode( serialize( $new_post ) ), // phpcs:ignore WordPress.PHP.DiscouragedPHPFunctions -- base64_encode function is used for http encode compatible..
|
579 |
+
'post_custom' => base64_encode( serialize( $post_custom ) ), // phpcs:ignore WordPress.PHP.DiscouragedPHPFunctions -- base64_encode function is used for http encode compatible..
|
580 |
+
'post_category' => base64_encode( $post_category ), // phpcs:ignore WordPress.PHP.DiscouragedPHPFunctions -- base64_encode function is used for http encode compatible..
|
581 |
+
'post_featured_image' => base64_encode( $post_featured_image ), // phpcs:ignore WordPress.PHP.DiscouragedPHPFunctions -- base64_encode function is used for http encode compatible..
|
582 |
+
'post_gallery_images' => base64_encode( serialize( $post_gallery_images ) ), // phpcs:ignore WordPress.PHP.DiscouragedPHPFunctions -- base64_encode function is used for http encode compatible..
|
583 |
+
'child_upload_dir' => base64_encode( serialize( $child_upload_dir ) ), // phpcs:ignore WordPress.PHP.DiscouragedPHPFunctions -- base64_encode function is used for http encode compatible..
|
584 |
+
);
|
585 |
+
return $post_data;
|
586 |
+
|
587 |
+
}
|
588 |
+
return false;
|
589 |
+
}
|
590 |
+
|
591 |
+
/**
|
592 |
+
* Get page edit data.
|
593 |
+
*
|
594 |
+
* @param string $id Page ID.
|
595 |
+
*
|
596 |
+
* @return array|bool Return $post_data or FALSE on failure.
|
597 |
+
*/
|
598 |
+
public function get_page_edit( $id ) {
|
599 |
+
$post = get_post( $id );
|
600 |
+
if ( $post ) {
|
601 |
+
$post_custom = get_post_custom( $id );
|
602 |
+
include_once ABSPATH . 'wp-includes' . DIRECTORY_SEPARATOR . 'post-thumbnail-template.php';
|
603 |
+
$post_featured_image = get_post_thumbnail_id( $id );
|
604 |
+
$child_upload_dir = wp_upload_dir();
|
605 |
+
|
606 |
+
$new_post = array(
|
607 |
+
'edit_id' => $id,
|
608 |
+
'post_title' => $post->post_title,
|
609 |
+
'post_content' => $post->post_content,
|
610 |
+
'post_status' => $post->post_status,
|
611 |
+
'post_date' => $post->post_date,
|
612 |
+
'post_date_gmt' => $post->post_date_gmt,
|
613 |
+
'post_type' => 'page',
|
614 |
+
'post_name' => $post->post_name,
|
615 |
+
'post_excerpt' => $post->post_excerpt,
|
616 |
+
'comment_status' => $post->comment_status,
|
617 |
+
'ping_status' => $post->ping_status,
|
618 |
+
);
|
619 |
+
|
620 |
+
if ( null != $post_featured_image ) {
|
621 |
+
$img = wp_get_attachment_image_src( $post_featured_image, 'full' );
|
622 |
+
$post_featured_image = $img[0];
|
623 |
+
}
|
624 |
+
|
625 |
+
$galleries = get_post_gallery( $id, false );
|
626 |
+
$post_gallery_images = array();
|
627 |
+
|
628 |
+
if ( is_array( $galleries ) && isset( $galleries['ids'] ) ) {
|
629 |
+
$attached_images = explode( ',', $galleries['ids'] );
|
630 |
+
foreach ( $attached_images as $attachment_id ) {
|
631 |
+
$attachment = get_post( $attachment_id );
|
632 |
+
if ( $attachment ) {
|
633 |
+
$post_gallery_images[] = array(
|
634 |
+
'id' => $attachment_id,
|
635 |
+
'alt' => get_post_meta( $attachment->ID, '_wp_attachment_image_alt', true ),
|
636 |
+
'caption' => $attachment->post_excerpt,
|
637 |
+
'description' => $attachment->post_content,
|
638 |
+
'src' => $attachment->guid,
|
639 |
+
'title' => $attachment->post_title,
|
640 |
+
);
|
641 |
+
}
|
642 |
+
}
|
643 |
+
}
|
644 |
+
|
645 |
+
require_once ABSPATH . 'wp-admin/includes/post.php';
|
646 |
+
wp_set_post_lock( $id );
|
647 |
+
|
648 |
+
$post_data = array(
|
649 |
+
'new_post' => base64_encode( serialize( $new_post ) ), // phpcs:ignore WordPress.PHP.DiscouragedPHPFunctions -- base64_encode function is used for http encode compatible..
|
650 |
+
'post_custom' => base64_encode( serialize( $post_custom ) ), // phpcs:ignore WordPress.PHP.DiscouragedPHPFunctions -- base64_encode function is used for http encode compatible..
|
651 |
+
'post_featured_image' => base64_encode( $post_featured_image ), // phpcs:ignore WordPress.PHP.DiscouragedPHPFunctions -- base64_encode function is used for http encode compatible..
|
652 |
+
'post_gallery_images' => base64_encode( serialize( $post_gallery_images ) ), // phpcs:ignore WordPress.PHP.DiscouragedPHPFunctions -- base64_encode function is used for http encode compatible..
|
653 |
+
'child_upload_dir' => base64_encode( serialize( $child_upload_dir ) ), // phpcs:ignore WordPress.PHP.DiscouragedPHPFunctions -- base64_encode function is used for http encode compatible..
|
654 |
+
);
|
655 |
+
return $post_data;
|
656 |
+
}
|
657 |
+
return false;
|
658 |
+
}
|
659 |
+
|
660 |
+
/**
|
661 |
+
* Create new post.
|
662 |
+
*
|
663 |
+
* @param array $new_post Post data array.
|
664 |
+
* @param array $post_custom Post custom meta data.
|
665 |
+
* @param string $post_category Post categories.
|
666 |
+
* @param string $post_featured_image Post featured image.
|
667 |
+
* @param string $upload_dir Upload directory.
|
668 |
+
* @param string $post_tags Post tags.
|
669 |
+
* @param array $others Other data.
|
670 |
+
*
|
671 |
+
* @return array|string[] $ret Return success array, permalink & Post ID.
|
672 |
+
*
|
673 |
+
* @uses \MainWP\Child\MainWP_Child_Posts::set_post_custom_data()
|
674 |
+
* @uses \MainWP\Child\MainWP_Child_Posts::update_found_images()
|
675 |
+
* @uses \MainWP\Child\MainWP_Child_Posts::create_has_shortcode_gallery()
|
676 |
+
* @uses \MainWP\Child\MainWP_Child_Posts::create_post_plus()
|
677 |
+
* @uses \MainWP\Child\MainWP_Child_Posts::update_post_data()
|
678 |
+
*/
|
679 |
+
private function create_post(
|
680 |
+
$new_post,
|
681 |
+
$post_custom,
|
682 |
+
$post_category,
|
683 |
+
$post_featured_image,
|
684 |
+
$upload_dir,
|
685 |
+
$post_tags,
|
686 |
+
$others = array()
|
687 |
+
) {
|
688 |
+
|
689 |
+
/**
|
690 |
+
* Hook: `mainwp_before_post_update`
|
691 |
+
*
|
692 |
+
* Runs before creating or updating a post via MainWP dashboard.
|
693 |
+
*
|
694 |
+
* @param array $new_post � Post data array.
|
695 |
+
* @param array $post_custom � Post custom meta data.
|
696 |
+
* @param string $post_category � Post categories.
|
697 |
+
* @param string $post_tags � Post tags.
|
698 |
+
*/
|
699 |
+
do_action( 'mainwp_before_post_update', $new_post, $post_custom, $post_category, $post_tags, $others );
|
700 |
+
|
701 |
+
$edit_post_id = 0;
|
702 |
+
$is_post_plus = false;
|
703 |
+
|
704 |
+
$this->set_post_custom_data( $new_post, $post_custom, $post_tags, $edit_post_id, $is_post_plus, $others );
|
705 |
+
|
706 |
+
require_once ABSPATH . 'wp-admin/includes/post.php';
|
707 |
+
|
708 |
+
if ( $edit_post_id ) {
|
709 |
+
$user_id = wp_check_post_lock( $edit_post_id );
|
710 |
+
if ( $user_id ) {
|
711 |
+
$user = get_userdata( $user_id );
|
712 |
+
$error = sprintf( __( 'This content is currently locked. %s is currently editing.', 'mainwp-child' ), $user->display_name );
|
713 |
+
return array( 'error' => $error );
|
714 |
+
}
|
715 |
+
}
|
716 |
+
|
717 |
+
// if editing post then will check if image existed.
|
718 |
+
$check_image_existed = $edit_post_id ? true : false;
|
719 |
+
|
720 |
+
$this->update_found_images( $new_post, $upload_dir, $check_image_existed );
|
721 |
+
$this->create_has_shortcode_gallery( $new_post );
|
722 |
+
|
723 |
+
if ( $is_post_plus ) {
|
724 |
+
$this->create_post_plus( $new_post, $post_custom );
|
725 |
+
}
|
726 |
+
|
727 |
+
if ( isset( $post_custom['_mainwp_replace_advance_img'] ) && true == $post_custom['_mainwp_replace_advance_img'][0] ) {
|
728 |
+
$new_post['post_content'] = self::replace_advanced_image( $new_post['post_content'], $upload_dir );
|
729 |
+
$new_post['post_content'] = self::replace_advanced_image( $new_post['post_content'], $upload_dir, true ); // to fix images url with slashes.
|
730 |
+
unset( $post_custom['_mainwp_replace_advance_img'] );
|
731 |
+
}
|
732 |
+
|
733 |
+
// Save the post to the WP.
|
734 |
+
remove_filter( 'content_save_pre', 'wp_filter_post_kses' ); // to fix brake scripts or html.
|
735 |
+
$post_status = $new_post['post_status']; // save post_status.
|
736 |
+
$new_post['post_status'] = 'auto-draft'; // to fix reports, to log as created post.
|
737 |
+
|
738 |
+
// Update post.
|
739 |
+
if ( $edit_post_id ) {
|
740 |
+
// check if post existed.
|
741 |
+
$current_post = get_post( $edit_post_id );
|
742 |
+
if ( $current_post && ( ( ! isset( $new_post['post_type'] ) && 'post' == $current_post->post_type ) || ( isset( $new_post['post_type'] ) && $new_post['post_type'] == $current_post->post_type ) ) ) {
|
743 |
+
$new_post['ID'] = $edit_post_id;
|
744 |
+
}
|
745 |
+
$new_post['post_status'] = $post_status; // child reports: to logging as update post.
|
746 |
+
}
|
747 |
+
$wp_error = null;
|
748 |
+
$new_post_id = wp_insert_post( $new_post, $wp_error ); // insert post.
|
749 |
+
// Show errors if something went wrong.
|
750 |
+
if ( is_wp_error( $wp_error ) ) {
|
751 |
+
return $wp_error->get_error_message();
|
752 |
+
}
|
753 |
+
if ( empty( $new_post_id ) ) {
|
754 |
+
return array( 'error' => 'Empty post id' );
|
755 |
+
}
|
756 |
+
|
757 |
+
if ( ! $edit_post_id ) {
|
758 |
+
wp_update_post(
|
759 |
+
array(
|
760 |
+
'ID' => $new_post_id,
|
761 |
+
'post_status' => $post_status,
|
762 |
+
)
|
763 |
+
);
|
764 |
+
}
|
765 |
+
|
766 |
+
if ( is_array( $post_custom ) && isset( $post_custom['_mainwp_edit_post_save_to_post_type'] ) ) {
|
767 |
+
$saved_post_type = $post_custom['_mainwp_edit_post_save_to_post_type'];
|
768 |
+
$saved_post_type = is_array( $saved_post_type ) ? current( $saved_post_type ) : $saved_post_type;
|
769 |
+
if ( ! empty( $saved_post_type ) ) {
|
770 |
+
wp_update_post(
|
771 |
+
array(
|
772 |
+
'ID' => $new_post_id,
|
773 |
+
'post_type' => $saved_post_type,
|
774 |
+
)
|
775 |
+
);
|
776 |
+
}
|
777 |
+
unset( $post_custom['_mainwp_edit_post_save_to_post_type'] );
|
778 |
+
}
|
779 |
+
|
780 |
+
$this->update_post_data( $new_post_id, $post_custom, $post_category, $post_featured_image, $check_image_existed, $is_post_plus, $others );
|
781 |
+
|
782 |
+
// unlock if edit post.
|
783 |
+
if ( $edit_post_id ) {
|
784 |
+
update_post_meta( $edit_post_id, '_edit_lock', '' );
|
785 |
+
}
|
786 |
+
$permalink = get_permalink( $new_post_id );
|
787 |
+
$ret['success'] = true;
|
788 |
+
$ret['link'] = $permalink;
|
789 |
+
$ret['added_id'] = $new_post_id;
|
790 |
+
return $ret;
|
791 |
+
}
|
792 |
+
|
793 |
+
/**
|
794 |
+
* Set custom post data.
|
795 |
+
*
|
796 |
+
* @param array $new_post Post data array.
|
797 |
+
* @param array $post_custom Post custom meta data.
|
798 |
+
* @param string $post_tags Post tags.
|
799 |
+
* @param string $edit_post_id Edit Post ID.
|
800 |
+
* @param bool $is_post_plus TRUE|FALSE, Whether or not this came from MainWP Post Plus Extension.
|
801 |
+
* @param array $others Post custom others meta data.
|
802 |
+
*
|
803 |
+
* @uses \MainWP\Child\MainWP_Child_Posts::update_wp_rocket_custom_post()
|
804 |
+
*/
|
805 |
+
private function set_post_custom_data( &$new_post, $post_custom, $post_tags, &$edit_post_id, &$is_post_plus, $others ) {
|
806 |
+
|
807 |
+
/**
|
808 |
+
* Current user global.
|
809 |
+
*
|
810 |
+
* @global string
|
811 |
+
*/
|
812 |
+
global $current_user;
|
813 |
+
|
814 |
+
$this->update_wp_rocket_custom_post( $post_custom );
|
815 |
+
|
816 |
+
// current user may be connected admin or alternative admin.
|
817 |
+
$current_uid = $current_user->ID;
|
818 |
+
|
819 |
+
// Set up a new post (adding additional information).
|
820 |
+
$new_post['post_author'] = isset( $new_post['post_author'] ) && ! empty( $new_post['post_author'] ) ? $new_post['post_author'] : $current_uid;
|
821 |
+
|
822 |
+
if ( isset( $new_post['custom_post_author'] ) && ! empty( $new_post['custom_post_author'] ) ) {
|
823 |
+
$_author = get_user_by( 'login', $new_post['custom_post_author'] );
|
824 |
+
if ( ! empty( $_author ) ) {
|
825 |
+
$new_post['post_author'] = $_author->ID;
|
826 |
+
}
|
827 |
+
unset( $new_post['custom_post_author'] );
|
828 |
+
}
|
829 |
+
|
830 |
+
// post plus extension process.
|
831 |
+
$is_post_plus = isset( $post_custom['_mainwp_post_plus'] ) ? true : false;
|
832 |
+
|
833 |
+
if ( $is_post_plus ) {
|
834 |
+
if ( isset( $new_post['post_date_gmt'] ) && ! empty( $new_post['post_date_gmt'] ) && '0000-00-00 00:00:00' != $new_post['post_date_gmt'] ) {
|
835 |
+
$post_date_timestamp = strtotime( $new_post['post_date_gmt'] ) + get_option( 'gmt_offset' ) * 60 * 60;
|
836 |
+
$new_post['post_date'] = date( 'Y-m-d H:i:s', $post_date_timestamp ); // phpcs:ignore -- local time.
|
837 |
+
}
|
838 |
+
}
|
839 |
+
|
840 |
+
if ( isset( $post_tags ) && '' != $post_tags ) {
|
841 |
+
$new_post['tags_input'] = $post_tags;
|
842 |
+
}
|
843 |
+
|
844 |
+
if ( isset( $post_custom['_mainwp_edit_post_id'] ) && $post_custom['_mainwp_edit_post_id'] ) {
|
845 |
+
$edit_post_id = current( $post_custom['_mainwp_edit_post_id'] );
|
846 |
+
} elseif ( isset( $new_post['ID'] ) && $new_post['ID'] ) {
|
847 |
+
$edit_post_id = $new_post['ID'];
|
848 |
+
}
|
849 |
+
}
|
850 |
+
|
851 |
+
/**
|
852 |
+
* Update post data.
|
853 |
+
*
|
854 |
+
* @param string $new_post_id New post ID.
|
855 |
+
* @param array $post_custom Post custom meta data.
|
856 |
+
* @param string $post_category Post categories.
|
857 |
+
* @param string $post_featured_image Post featured image.
|
858 |
+
* @param bool $check_image_existed TRUE|FALSE, Whether or not featured image already exists.
|
859 |
+
* @param bool $is_post_plus TRUE|FALSE, Whether or not this came from MainWP Post Plus Extension.
|
860 |
+
* @param array $others Others data.
|
861 |
+
*
|
862 |
+
* @uses \MainWP\Child\MainWP_Child_Posts::set_custom_post_fields()
|
863 |
+
* @uses \MainWP\Child\MainWP_Child_Posts::update_seo_meta()
|
864 |
+
* @uses \MainWP\Child\MainWP_Child_Posts::create_set_categories()
|
865 |
+
* @uses \MainWP\Child\MainWP_Child_Posts::create_featured_image()
|
866 |
+
* @uses \MainWP\Child\MainWP_Child_Posts::post_plus_update_author()
|
867 |
+
* @uses \MainWP\Child\MainWP_Child_Posts::post_plus_update_categories()
|
868 |
+
*/
|
869 |
+
private function update_post_data( $new_post_id, $post_custom, $post_category, $post_featured_image, $check_image_existed, $is_post_plus, $others ) {
|
870 |
+
|
871 |
+
$seo_ext_activated = false;
|
872 |
+
if ( class_exists( '\WPSEO_Meta' ) && class_exists( '\WPSEO_Admin' ) ) {
|
873 |
+
$seo_ext_activated = true;
|
874 |
+
}
|
875 |
+
|
876 |
+
$post_to_only_existing_categories = false;
|
877 |
+
|
878 |
+
$this->set_custom_post_fields( $new_post_id, $post_custom, $seo_ext_activated, $post_to_only_existing_categories );
|
879 |
+
|
880 |
+
// yoast seo plugin activated.
|
881 |
+
if ( $seo_ext_activated ) {
|
882 |
+
$this->update_seo_meta( $new_post_id, $post_custom );
|
883 |
+
}
|
884 |
+
|
885 |
+
$this->create_set_categories( $new_post_id, $post_category, $post_to_only_existing_categories );
|
886 |
+
$this->create_featured_image( $new_post_id, $post_featured_image, true, $others ); // always checks featured img.
|
887 |
+
|
888 |
+
// post plus extension process.
|
889 |
+
if ( $is_post_plus ) {
|
890 |
+
$this->post_plus_update_author( $new_post_id, $post_custom );
|
891 |
+
$this->post_plus_update_categories( $new_post_id, $post_custom );
|
892 |
+
}
|
893 |
+
|
894 |
+
// to support custom post author.
|
895 |
+
$custom_post_author = apply_filters( 'mainwp_create_post_custom_author', false, $new_post_id );
|
896 |
+
if ( ! empty( $custom_post_author ) ) {
|
897 |
+
wp_update_post(
|
898 |
+
array(
|
899 |
+
'ID' => $new_post_id,
|
900 |
+
'post_author' => $custom_post_author,
|
901 |
+
)
|
902 |
+
);
|
903 |
+
}
|
904 |
+
}
|
905 |
+
|
906 |
+
/**
|
907 |
+
* Update WPRocket custom post.
|
908 |
+
*
|
909 |
+
* @param array $post_custom Post custom meta data.
|
910 |
+
*
|
911 |
+
* @uses \get_rocket_option()
|
912 |
+
* @see https://github.com/wp-media/wp-rocket/blob/master/inc/functions/options.php
|
913 |
+
*
|
914 |
+
* @uses \MainWP\Child\MainWP_Child_WP_Rocket::instance()::is_activated()
|
915 |
+
* @uses \MainWP\Child\MainWP_Child_WP_Rocket::is_activated()
|
916 |
+
*/
|
917 |
+
private function update_wp_rocket_custom_post( &$post_custom ) {
|
918 |
+
// Options fields.
|
919 |
+
$wprocket_fields = array(
|
920 |
+
'lazyload',
|
921 |
+
'lazyload_iframes',
|
922 |
+
'minify_html',
|
923 |
+
'minify_css',
|
924 |
+
'minify_js',
|
925 |
+
'cdn',
|
926 |
+
'async_css',
|
927 |
+
'defer_all_js',
|
928 |
+
);
|
929 |
+
|
930 |
+
$wprocket_activated = false;
|
931 |
+
if ( MainWP_Child_WP_Rocket::instance()->is_activated() ) {
|
932 |
+
if ( function_exists( '\get_rocket_option' ) ) {
|
933 |
+
$wprocket_activated = true;
|
934 |
+
foreach ( $wprocket_fields as $field ) {
|
935 |
+
if ( ! isset( $post_custom[ '_rocket_exclude_' . $field ] ) ) {
|
936 |
+
if ( ! \get_rocket_option( $field ) ) {
|
937 |
+
$post_custom[ '_rocket_exclude_' . $field ] = array( true );
|
938 |
+
}
|
939 |
+
}
|
940 |
+
}
|
941 |
+
}
|
942 |
+
}
|
943 |
+
if ( ! $wprocket_activated ) {
|
944 |
+
foreach ( $wprocket_fields as $field ) {
|
945 |
+
if ( isset( $post_custom[ '_rocket_exclude_' . $field ] ) ) {
|
946 |
+
unset( $post_custom[ '_rocket_exclude_' . $field ] );
|
947 |
+
}
|
948 |
+
}
|
949 |
+
}
|
950 |
+
}
|
951 |
+
|
952 |
+
/**
|
953 |
+
* Search for all the images added to the new post.
|
954 |
+
*
|
955 |
+
* @param array $new_post Post data array.
|
956 |
+
* @param string $upload_dir Upload directory.
|
957 |
+
* @param bool $check_image_existed TRUE|FALSE, Whether or not featured image already exists.
|
958 |
+
*
|
959 |
+
* @uses \MainWP\Child\MainWP_Utility::upload_image()
|
960 |
+
* @uses \MainWP\Child\MainWP_Helper::log_debug()
|
961 |
+
*/
|
962 |
+
private function update_found_images( &$new_post, $upload_dir, $check_image_existed ) {
|
963 |
+
|
964 |
+
// Some images have a href tag to click to navigate to the image.. we need to replace this too.
|
965 |
+
$foundMatches = preg_match_all( '/(<a[^>]+href=\"(.*?)\"[^>]*>)?(<img[^>\/]*src=\"((.*?)(png|gif|jpg|jpeg))\")/ix', $new_post['post_content'], $matches, PREG_SET_ORDER );
|
966 |
+
if ( $foundMatches > 0 ) {
|
967 |
+
// We found images, now to download them so we can start balbal.
|
968 |
+
foreach ( $matches as $match ) {
|
969 |
+
$hrefLink = $match[2];
|
970 |
+
$imgUrl = $match[4];
|
971 |
+
|
972 |
+
if ( ! isset( $upload_dir['baseurl'] ) || ( false === strripos( $imgUrl, $upload_dir['baseurl'] ) ) ) { // url of image is not in dashboard site.
|
973 |
+
continue;
|
974 |
+
}
|
975 |
+
|
976 |
+
if ( preg_match( '/-\d{3}x\d{3}\.[a-zA-Z0-9]{3,4}$/', $imgUrl, $imgMatches ) ) {
|
977 |
+
$search = $imgMatches[0];
|
978 |
+
$replace = '.' . $match[6];
|
979 |
+
$originalImgUrl = str_replace( $search, $replace, $imgUrl );
|
980 |
+
} else {
|
981 |
+
$originalImgUrl = $imgUrl;
|
982 |
+
}
|
983 |
+
|
984 |
+
try {
|
985 |
+
$downloadfile = MainWP_Utility::upload_image( $originalImgUrl, array(), $check_image_existed );
|
986 |
+
$localUrl = $downloadfile['url'];
|
987 |
+
$linkToReplaceWith = dirname( $localUrl );
|
988 |
+
if ( '' !== $hrefLink ) {
|
989 |
+
$server = get_option( 'mainwp_child_server' );
|
990 |
+
$serverHost = wp_parse_url( $server, PHP_URL_HOST );
|
991 |
+
if ( ! empty( $serverHost ) && strpos( $hrefLink, $serverHost ) !== false ) {
|
992 |
+
$serverHref = 'href="' . $serverHost;
|
993 |
+
$replaceServerHref = 'href="' . wp_parse_url( $localUrl, PHP_URL_SCHEME ) . '://' . wp_parse_url( $localUrl, PHP_URL_HOST );
|
994 |
+
$new_post['post_content'] = str_replace( $serverHref, $replaceServerHref, $new_post['post_content'] );
|
995 |
+
}
|
996 |
+
}
|
997 |
+
$lnkToReplace = dirname( $imgUrl );
|
998 |
+
if ( 'http:' !== $lnkToReplace && 'https:' !== $lnkToReplace ) {
|
999 |
+
$new_post['post_content'] = str_replace( $imgUrl, $localUrl, $new_post['post_content'] ); // replace src image.
|
1000 |
+
$new_post['post_content'] = str_replace( $lnkToReplace, $linkToReplaceWith, $new_post['post_content'] );
|
1001 |
+
}
|
1002 |
+
} catch ( \Exception $e ) {
|
1003 |
+
MainWP_Helper::log_debug( $e->getMessage() );
|
1004 |
+
}
|
1005 |
+
}
|
1006 |
+
}
|
1007 |
+
}
|
1008 |
+
|
1009 |
+
/**
|
1010 |
+
* Method replace_advanced_image()
|
1011 |
+
*
|
1012 |
+
* Handle upload advanced image.
|
1013 |
+
*
|
1014 |
+
* @param array $content post content data.
|
1015 |
+
* @param array $upload_dir upload directory info.
|
1016 |
+
* @param bool $withslashes to use preg pattern with slashes.
|
1017 |
+
*
|
1018 |
+
* @return mixed array of result.
|
1019 |
+
*/
|
1020 |
+
public static function replace_advanced_image( $content, $upload_dir, $withslashes = false ) {
|
1021 |
+
|
1022 |
+
if ( empty( $upload_dir ) || ! isset( $upload_dir['baseurl'] ) ) {
|
1023 |
+
return $content;
|
1024 |
+
}
|
1025 |
+
|
1026 |
+
$dashboard_url = get_option( 'mainwp_child_server' );
|
1027 |
+
$site_url_destination = get_site_url();
|
1028 |
+
|
1029 |
+
// to fix url with slashes.
|
1030 |
+
if ( $withslashes ) {
|
1031 |
+
$site_url_destination = str_replace( '/', '\/', $site_url_destination );
|
1032 |
+
$dashboard_url = str_replace( '/', '\/', $dashboard_url );
|
1033 |
+
}
|
1034 |
+
|
1035 |
+
$foundMatches = preg_match_all( '#(' . preg_quote( $site_url_destination, null ) . ')[^\.]*(\.(png|gif|jpg|jpeg))#ix', $content, $matches, PREG_SET_ORDER );
|
1036 |
+
|
1037 |
+
if ( 0 < $foundMatches ) {
|
1038 |
+
|
1039 |
+
$matches_checked = array();
|
1040 |
+
$check_double = array();
|
1041 |
+
foreach ( $matches as $match ) {
|
1042 |
+
// to avoid double images.
|
1043 |
+
if ( ! in_array( $match[0], $check_double ) ) {
|
1044 |
+
$check_double[] = $match[0];
|
1045 |
+
$matches_checked[] = $match;
|
1046 |
+
}
|
1047 |
+
}
|
1048 |
+
foreach ( $matches_checked as $match ) {
|
1049 |
+
|
1050 |
+
$imgUrl = $match[0];
|
1051 |
+
if ( false === strripos( wp_unslash( $imgUrl ), $upload_dir['baseurl'] ) ) {
|
1052 |
+
continue;
|
1053 |
+
}
|
1054 |
+
|
1055 |
+
if ( preg_match( '/-\d{3}x\d{3}\.[a-zA-Z0-9]{3,4}$/', $imgUrl, $imgMatches ) ) {
|
1056 |
+
$search = $imgMatches[0];
|
1057 |
+
$replace = '.' . $match[3];
|
1058 |
+
$originalImgUrl = str_replace( $search, $replace, $imgUrl );
|
1059 |
+
} else {
|
1060 |
+
$originalImgUrl = $imgUrl;
|
1061 |
+
}
|
1062 |
+
|
1063 |
+
try {
|
1064 |
+
$downloadfile = MainWP_Utility::upload_image( wp_unslash( $originalImgUrl ), array(), true );
|
1065 |
+
$localUrl = $downloadfile['url'];
|
1066 |
+
$linkToReplaceWith = dirname( $localUrl );
|
1067 |
+
$lnkToReplace = dirname( $imgUrl );
|
1068 |
+
if ( 'http:' !== $lnkToReplace && 'https:' !== $lnkToReplace ) {
|
1069 |
+
$content = str_replace( $imgUrl, $localUrl, $content ); // replace src image.
|
1070 |
+
$content = str_replace( $lnkToReplace, $linkToReplaceWith, $content );
|
1071 |
+
}
|
1072 |
+
} catch ( \Exception $e ) {
|
1073 |
+
// ok.
|
1074 |
+
}
|
1075 |
+
}
|
1076 |
+
if ( false === strripos( $dashboard_url, $site_url_destination ) ) {
|
1077 |
+
// replace other images src outside dashboard upload folder.
|
1078 |
+
$content = str_replace( $dashboard_url, $site_url_destination, $content );
|
1079 |
+
}
|
1080 |
+
}
|
1081 |
+
return $content;
|
1082 |
+
}
|
1083 |
+
|
1084 |
+
/**
|
1085 |
+
* Create shortcode image gallery.
|
1086 |
+
*
|
1087 |
+
* @param array $new_post Post data array.
|
1088 |
+
*
|
1089 |
+
* @uses \MainWP\Child\MainWP_Utility::upload_image()
|
1090 |
+
* @uses \Exception()
|
1091 |
+
*/
|
1092 |
+
private function create_has_shortcode_gallery( &$new_post ) {
|
1093 |
+
|
1094 |
+
if ( has_shortcode( $new_post['post_content'], 'gallery' ) ) {
|
1095 |
+
if ( preg_match_all( '/\[gallery[^\]]+ids=\"(.*?)\"[^\]]*\]/ix', $new_post['post_content'], $matches, PREG_SET_ORDER ) ) {
|
1096 |
+
$replaceAttachedIds = array();
|
1097 |
+
if ( isset( $_POST['post_gallery_images'] ) ) {
|
1098 |
+
$post_gallery_images = isset( $_POST['post_gallery_images'] ) ? unserialize( base64_decode( wp_unslash( $_POST['post_gallery_images'] ) ) ) : ''; // phpcs:ignore WordPress.PHP.DiscouragedPHPFunctions -- base64_encode function is used for http encode compatible..
|
1099 |
+
if ( is_array( $post_gallery_images ) ) {
|
1100 |
+
foreach ( $post_gallery_images as $gallery ) {
|
1101 |
+
if ( isset( $gallery['src'] ) ) {
|
1102 |
+
try {
|
1103 |
+
$upload = MainWP_Utility::upload_image( $gallery['src'], $gallery ); // Upload image to WP.
|
1104 |
+
if ( null !== $upload ) {
|
1105 |
+
$replaceAttachedIds[ $gallery['id'] ] = $upload['id'];
|
1106 |
+
}
|
1107 |
+
} catch ( \Exception $e ) {
|
1108 |
+
// ok!
|
1109 |
+
}
|
1110 |
+
}
|
1111 |
+
}
|
1112 |
+
}
|
1113 |
+
}
|
1114 |
+
if ( count( $replaceAttachedIds ) > 0 ) {
|
1115 |
+
foreach ( $matches as $match ) {
|
1116 |
+
$idsToReplace = $match[1];
|
1117 |
+
$idsToReplaceWith = '';
|
1118 |
+
$originalIds = explode( ',', $idsToReplace );
|
1119 |
+
foreach ( $originalIds as $attached_id ) {
|
1120 |
+
if ( ! empty( $originalIds ) && isset( $replaceAttachedIds[ $attached_id ] ) ) {
|
1121 |
+
$idsToReplaceWith .= $replaceAttachedIds[ $attached_id ] . ',';
|
1122 |
+
}
|
1123 |
+
}
|
1124 |
+
$idsToReplaceWith = rtrim( $idsToReplaceWith, ',' );
|
1125 |
+
if ( ! empty( $idsToReplaceWith ) ) {
|
1126 |
+
$new_post['post_content'] = str_replace( '"' . $idsToReplace . '"', '"' . $idsToReplaceWith . '"', $new_post['post_content'] );
|
1127 |
+
}
|
1128 |
+
}
|
1129 |
+
}
|
1130 |
+
}
|
1131 |
+
}
|
1132 |
+
}
|
1133 |
+
|
1134 |
+
/**
|
1135 |
+
* Create post plus post.
|
1136 |
+
*
|
1137 |
+
* @param array $new_post Post data array.
|
1138 |
+
* @param array $post_custom Post custom meta data.
|
1139 |
+
*/
|
1140 |
+
private function create_post_plus( &$new_post, $post_custom ) {
|
1141 |
+
$random_publish_date = isset( $post_custom['_saved_draft_random_publish_date'] ) ? $post_custom['_saved_draft_random_publish_date'] : false;
|
1142 |
+
$random_publish_date = is_array( $random_publish_date ) ? current( $random_publish_date ) : null;
|
1143 |
+
|
1144 |
+
if ( ! empty( $random_publish_date ) ) {
|
1145 |
+
$random_date_from = isset( $post_custom['_saved_draft_publish_date_from'] ) ? $post_custom['_saved_draft_publish_date_from'] : 0;
|
1146 |
+
$random_date_from = is_array( $random_date_from ) ? current( $random_date_from ) : 0;
|
1147 |
+
|
1148 |
+
$random_date_to = isset( $post_custom['_saved_draft_publish_date_to'] ) ? $post_custom['_saved_draft_publish_date_to'] : 0;
|
1149 |
+
$random_date_to = is_array( $random_date_to ) ? current( $random_date_to ) : 0;
|
1150 |
+
|
1151 |
+
$now = time();
|
1152 |
+
|
1153 |
+
if ( empty( $random_date_from ) ) {
|
1154 |
+
$random_date_from = $now;
|
1155 |
+
}
|
1156 |
+
|
1157 |
+
if ( empty( $random_date_to ) ) {
|
1158 |
+
$random_date_to = $now;
|
1159 |
+
}
|
1160 |
+
|
1161 |
+
if ( $random_date_from === $now && $random_date_from === $random_date_to ) {
|
1162 |
+
$random_date_to = $now + 7 * 24 * 3600;
|
1163 |
+
}
|
1164 |
+
|
1165 |
+
if ( $random_date_from > $random_date_to ) {
|
1166 |
+
$tmp = $random_date_from;
|
1167 |
+
$random_date_from = $random_date_to;
|
1168 |
+
$random_date_to = $tmp;
|
1169 |
+
}
|
1170 |
+
|
1171 |
+
$random_timestamp = wp_rand( $random_date_from, $random_date_to );
|
1172 |
+
$new_post['post_date'] = date( 'Y-m-d H:i:s', $random_timestamp ); // phpcs:ignore -- local time.
|
1173 |
+
}
|
1174 |
+
}
|
1175 |
+
|
1176 |
+
/**
|
1177 |
+
* Update post plus author.
|
1178 |
+
*
|
1179 |
+
* @param string $new_post_id New post ID.
|
1180 |
+
* @param array $post_custom Post custom meta data.
|
1181 |
+
*/
|
1182 |
+
private function post_plus_update_author( $new_post_id, $post_custom ) {
|
1183 |
+
$random_privelege = isset( $post_custom['_saved_draft_random_privelege'] ) ? $post_custom['_saved_draft_random_privelege'] : null;
|
1184 |
+
$random_privelege = is_array( $random_privelege ) ? current( $random_privelege ) : null;
|
1185 |
+
$random_privelege_base = base64_decode( $random_privelege ); // phpcs:ignore WordPress.PHP.DiscouragedPHPFunctions -- base64_encode function is used for http encode compatible..
|
1186 |
+
$random_privelege = maybe_unserialize( $random_privelege_base );
|
1187 |
+
|
1188 |
+
if ( is_array( $random_privelege ) && count( $random_privelege ) > 0 ) {
|
1189 |
+
$random_post_authors = array();
|
1190 |
+
foreach ( $random_privelege as $role ) {
|
1191 |
+
$users = get_users( array( 'role' => $role ) );
|
1192 |
+
foreach ( $users as $user ) {
|
1193 |
+
$random_post_authors[] = $user->ID;
|
1194 |
+
}
|
1195 |
+
}
|
1196 |
+
if ( count( $random_post_authors ) > 0 ) {
|
1197 |
+
shuffle( $random_post_authors );
|
1198 |
+
$key = array_rand( $random_post_authors );
|
1199 |
+
wp_update_post(
|
1200 |
+
array(
|
1201 |
+
'ID' => $new_post_id,
|
1202 |
+
'post_author' => $random_post_authors[ $key ],
|
1203 |
+
)
|
1204 |
+
);
|
1205 |
+
}
|
1206 |
+
}
|
1207 |
+
}
|
1208 |
+
|
1209 |
+
/**
|
1210 |
+
* Update post plus categories.
|
1211 |
+
*
|
1212 |
+
* @param string $new_post_id New post ID.
|
1213 |
+
* @param array $post_custom Post custom meta data.
|
1214 |
+
*/
|
1215 |
+
private function post_plus_update_categories( $new_post_id, $post_custom ) {
|
1216 |
+
$random_category = isset( $post_custom['_saved_draft_random_category'] ) ? $post_custom['_saved_draft_random_category'] : false;
|
1217 |
+
$random_category = is_array( $random_category ) ? current( $random_category ) : null;
|
1218 |
+
if ( ! empty( $random_category ) ) {
|
1219 |
+
$cats = get_categories(
|
1220 |
+
array(
|
1221 |
+
'type' => 'post',
|
1222 |
+
'hide_empty' => 0,
|
1223 |
+
)
|
1224 |
+
);
|
1225 |
+
$random_cats = array();
|
1226 |
+
if ( is_array( $cats ) ) {
|
1227 |
+
foreach ( $cats as $cat ) {
|
1228 |
+
$random_cats[] = $cat->term_id;
|
1229 |
+
}
|
1230 |
+
}
|
1231 |
+
if ( count( $random_cats ) > 0 ) {
|
1232 |
+
shuffle( $random_cats );
|
1233 |
+
$key = array_rand( $random_cats );
|
1234 |
+
wp_set_post_categories( $new_post_id, array( $random_cats[ $key ] ), false );
|
1235 |
+
}
|
1236 |
+
}
|
1237 |
+
}
|
1238 |
+
|
1239 |
+
/**
|
1240 |
+
* Create new and set categories.
|
1241 |
+
*
|
1242 |
+
* @param string $new_post_id New post ID.
|
1243 |
+
* @param string $post_category Post category.
|
1244 |
+
* @param bool $post_to_only TRUE|FALSE, Whether or not to post only to this category.
|
1245 |
+
*
|
1246 |
+
* @uses wp_create_categories() Create categories for the given post.
|
1247 |
+
* @see https://developer.wordpress.org/reference/functions/wp_create_categories/
|
1248 |
+
*
|
1249 |
+
* @uses wp_set_post_categories() Set categories for a post.
|
1250 |
+
* @see https://developer.wordpress.org/reference/functions/wp_set_post_categories/
|
1251 |
+
*/
|
1252 |
+
private function create_set_categories( $new_post_id, $post_category, $post_to_only ) {
|
1253 |
+
|
1254 |
+
// If categories exist, create them (second parameter of wp_create_categories adds the categories to the post).
|
1255 |
+
include_once ABSPATH . 'wp-admin/includes/taxonomy.php'; // Contains wp_create_categories.
|
1256 |
+
if ( isset( $post_category ) && '' !== $post_category ) {
|
1257 |
+
$categories = explode( ',', $post_category );
|
1258 |
+
if ( count( $categories ) > 0 ) {
|
1259 |
+
if ( ! $post_to_only ) {
|
1260 |
+
$post_category = wp_create_categories( $categories, $new_post_id );
|
1261 |
+
} else {
|
1262 |
+
$cat_ids = array();
|
1263 |
+
foreach ( $categories as $cat ) {
|
1264 |
+
$id = category_exists( $cat );
|
1265 |
+
if ( $id ) {
|
1266 |
+
$cat_ids[] = $id;
|
1267 |
+
}
|
1268 |
+
}
|
1269 |
+
if ( count( $cat_ids ) > 0 ) {
|
1270 |
+
wp_set_post_categories( $new_post_id, $cat_ids );
|
1271 |
+
}
|
1272 |
+
}
|
1273 |
+
}
|
1274 |
+
}
|
1275 |
+
}
|
1276 |
+
|
1277 |
+
/**
|
1278 |
+
* Set custom post fields.
|
1279 |
+
*
|
1280 |
+
* @param string $new_post_id New post ID.
|
1281 |
+
* @param array $post_custom Post custom meta data.
|
1282 |
+
* @param bool $seo_ext_activated TRUE|FALSE, Whether or not Yoast SEO is activateed or not.
|
1283 |
+
* @param bool $post_to_only TRUE|FALSE, Whether or not to post only to this category.
|
1284 |
+
*/
|
1285 |
+
private function set_custom_post_fields( $new_post_id, $post_custom, $seo_ext_activated, &$post_to_only ) {
|
1286 |
+
|
1287 |
+
// Set custom fields.
|
1288 |
+
$not_allowed = array(
|
1289 |
+
'_slug',
|
1290 |
+
'_tags',
|
1291 |
+
'_edit_lock',
|
1292 |
+
'_selected_sites',
|
1293 |
+
'_selected_groups',
|
1294 |
+
'_selected_by',
|
1295 |
+
'_categories',
|
1296 |
+
'_edit_last',
|
1297 |
+
'_sticky',
|
1298 |
+
'_mainwp_post_dripper',
|
1299 |
+
'_bulkpost_do_not_del',
|
1300 |
+
'_mainwp_spin_me',
|
1301 |
+
'_mainwp_boilerplate_sites_posts',
|
1302 |
+
'_mainwp_boilerplate',
|
1303 |
+
'_mainwp_post_plus',
|
1304 |
+
'_saved_as_draft',
|
1305 |
+
'_saved_draft_categories',
|
1306 |
+
'_saved_draft_tags',
|
1307 |
+
'_saved_draft_random_privelege',
|
1308 |
+
'_saved_draft_random_category',
|
1309 |
+
'_saved_draft_random_publish_date',
|
1310 |
+
'_saved_draft_publish_date_from',
|
1311 |
+
'_saved_draft_publish_date_to',
|
1312 |
+
'_post_to_only_existing_categories',
|
1313 |
+
'_mainwp_edit_post_site_id',
|
1314 |
+
'_mainwp_edit_post_id',
|
1315 |
+
'_edit_post_status',
|
1316 |
+
'_mainwp_edit_post_type',
|
1317 |
+
'_mainwp_edit_post_status',
|
1318 |
+
'_mainwp_edit_post_save_to_post_type',
|
1319 |
+
'_mainwp_post_dripper_sites_number',
|
1320 |
+
'_mainwp_post_dripper_time_number',
|
1321 |
+
'_mainwp_post_dripper_select_time',
|
1322 |
+
'_mainwp_post_dripper_use_post_dripper',
|
1323 |
+
'mainwp_post_id',
|
1324 |
+
'_mainwp_post_dripper_selected_drip_sites',
|
1325 |
+
'_mainwp_post_dripper_total_drip_sites',
|
1326 |
+
'_mainwp_replace_advance_img',
|
1327 |
+
);
|
1328 |
+
|
1329 |
+
if ( is_array( $post_custom ) ) {
|
1330 |
+
foreach ( $post_custom as $meta_key => $meta_values ) {
|
1331 |
+
if ( ! in_array( $meta_key, $not_allowed ) ) {
|
1332 |
+
foreach ( $meta_values as $meta_value ) {
|
1333 |
+
if ( 0 === strpos( $meta_key, '_mainwp_spinner_' ) ) {
|
1334 |
+
continue;
|
1335 |
+
}
|
1336 |
+
|
1337 |
+
if ( ! $seo_ext_activated ) {
|
1338 |
+
// if WordPress SEO plugin is not activated do not save yoast post meta.
|
1339 |
+
if ( false === strpos( $meta_key, '_yoast_wpseo_' ) ) {
|
1340 |
+
if ( is_serialized( $meta_value ) ) {
|
1341 |
+
$meta_value = unserialize( $meta_value ); // phpcs:ignore -- compatible.
|
1342 |
+
update_post_meta( $new_post_id, $meta_key, $meta_value );
|
1343 |
+
} else {
|
1344 |
+
update_post_meta( $new_post_id, $meta_key, $meta_value );
|
1345 |
+
}
|
1346 |
+
}
|
1347 |
+
} else {
|
1348 |
+
if ( is_serialized( $meta_value ) ) {
|
1349 |
+
$meta_value = unserialize( $meta_value ); // phpcs:ignore -- compatible.
|
1350 |
+
update_post_meta( $new_post_id, $meta_key, $meta_value );
|
1351 |
+
} else {
|
1352 |
+
update_post_meta( $new_post_id, $meta_key, $meta_value );
|
1353 |
+
}
|
1354 |
+
}
|
1355 |
+
}
|
1356 |
+
} elseif ( '_sticky' === $meta_key ) {
|
1357 |
+
foreach ( $meta_values as $meta_value ) {
|
1358 |
+
if ( 'sticky' === base64_decode( $meta_value ) ) { // phpcs:ignore WordPress.PHP.DiscouragedPHPFunctions -- base64_encode function is used for http encode compatible..
|
1359 |
+
stick_post( $new_post_id );
|
1360 |
+
}
|
1361 |
+
}
|
1362 |
+
} elseif ( '_post_to_only_existing_categories' === $meta_key ) {
|
1363 |
+
if ( isset( $meta_values[0] ) && $meta_values[0] ) {
|
1364 |
+
$post_to_only = true;
|
1365 |
+
}
|
1366 |
+
}
|
1367 |
+
}
|
1368 |
+
}
|
1369 |
+
}
|
1370 |
+
|
1371 |
+
/**
|
1372 |
+
* Update Yoast SEO Extension meta.
|
1373 |
+
*
|
1374 |
+
* @param string $new_post_id New post ID.
|
1375 |
+
* @param array $post_custom Post custom meta data.
|
1376 |
+
*
|
1377 |
+
* @uses \MainWP\Child\MainWP_Utility::upload_image()
|
1378 |
+
* @uses \WPSEO_Meta::$meta_prefix()
|
1379 |
+
* @uses \Exception()
|
1380 |
+
*/
|
1381 |
+
private function update_seo_meta( $new_post_id, $post_custom ) {
|
1382 |
+
|
1383 |
+
$_seo_opengraph_image = isset( $post_custom[ \WPSEO_Meta::$meta_prefix . 'opengraph-image' ] ) ? $post_custom[ \WPSEO_Meta::$meta_prefix . 'opengraph-image' ] : array();
|
1384 |
+
$_seo_opengraph_image = current( $_seo_opengraph_image );
|
1385 |
+
$_server_domain = '';
|
1386 |
+
$_server = get_option( 'mainwp_child_server' );
|
1387 |
+
if ( preg_match( '/(https?:\/\/[^\/]+\/).+/', $_server, $matchs ) ) {
|
1388 |
+
$_server_domain = isset( $matchs[1] ) ? $matchs[1] : '';
|
1389 |
+
}
|
1390 |
+
|
1391 |
+
// upload image if it on the server.
|
1392 |
+
if ( ! empty( $_seo_opengraph_image ) && false !== strpos( $_seo_opengraph_image, $_server_domain ) ) {
|
1393 |
+
try {
|
1394 |
+
$upload = MainWP_Utility::upload_image( $_seo_opengraph_image ); // Upload image to WP.
|
1395 |
+
if ( null !== $upload ) {
|
1396 |
+
update_post_meta( $new_post_id, \WPSEO_Meta::$meta_prefix . 'opengraph-image', $upload['url'] ); // Add the image to the post!
|
1397 |
+
}
|
1398 |
+
} catch ( \Exception $e ) {
|
1399 |
+
// ok!
|
1400 |
+
}
|
1401 |
+
}
|
1402 |
+
}
|
1403 |
+
|
1404 |
+
/**
|
1405 |
+
* Create featured image.
|
1406 |
+
*
|
1407 |
+
* @param string $new_post_id New post ID.
|
1408 |
+
* @param string $post_featured_image Post featured image.
|
1409 |
+
* @param bool $check_image_existed TRUE|FALSE, Whether or not featured image already exists.
|
1410 |
+
* @param array $others Post custom others meta data.
|
1411 |
+
*
|
1412 |
+
* @uses \MainWP\Child\MainWP_Utility::upload_image()
|
1413 |
+
* @uses \Excepsion()
|
1414 |
+
*/
|
1415 |
+
private function create_featured_image( $new_post_id, $post_featured_image, $check_image_existed, $others ) {
|
1416 |
+
|
1417 |
+
$featured_image_exist = false;
|
1418 |
+
// If featured image exists - set it.
|
1419 |
+
if ( null !== $post_featured_image ) {
|
1420 |
+
try {
|
1421 |
+
$upload = MainWP_Utility::upload_image( $post_featured_image, array(), $check_image_existed, $new_post_id ); // Upload image to WP.
|
1422 |
+
if ( null !== $upload ) {
|
1423 |
+
update_post_meta( $new_post_id, '_thumbnail_id', $upload['id'] ); // Add the thumbnail to the post!
|
1424 |
+
$featured_image_exist = true;
|
1425 |
+
if ( isset( $others['featured_image_data'] ) ) {
|
1426 |
+
$_image_data = $others['featured_image_data'];
|
1427 |
+
update_post_meta( $upload['id'], '_wp_attachment_image_alt', $_image_data['alt'] );
|
1428 |
+
wp_update_post(
|
1429 |
+
array(
|
1430 |
+
'ID' => $upload['id'],
|
1431 |
+
'post_excerpt' => $_image_data['caption'],
|
1432 |
+
'post_content' => $_image_data['description'],
|
1433 |
+
'post_title' => $_image_data['title'],
|
1434 |
+
)
|
1435 |
+
);
|
1436 |
+
}
|
1437 |
+
}
|
1438 |
+
} catch ( \Exception $e ) {
|
1439 |
+
// ok!
|
1440 |
+
}
|
1441 |
+
}
|
1442 |
+
|
1443 |
+
if ( ! $featured_image_exist ) {
|
1444 |
+
delete_post_meta( $new_post_id, '_thumbnail_id' );
|
1445 |
+
}
|
1446 |
+
}
|
1447 |
+
|
1448 |
+
}
|
class/class-mainwp-child-server-information-base.php
CHANGED
@@ -1,766 +1,766 @@
|
|
1 |
-
<?php
|
2 |
-
/**
|
3 |
-
* MainWP Child Server Information Base
|
4 |
-
*
|
5 |
-
* This is the base set of methods to collect a Child Site's Server Information.
|
6 |
-
*
|
7 |
-
* @package MainWP\Child
|
8 |
-
*/
|
9 |
-
|
10 |
-
namespace MainWP\Child;
|
11 |
-
|
12 |
-
/**
|
13 |
-
* Class MainWP_Child_Server_Information_Base
|
14 |
-
*
|
15 |
-
* Base set of methods to collect a Child Site's server information.
|
16 |
-
*/
|
17 |
-
class MainWP_Child_Server_Information_Base {
|
18 |
-
|
19 |
-
/**
|
20 |
-
* Method get_class_name()
|
21 |
-
*
|
22 |
-
* Get class name.
|
23 |
-
*
|
24 |
-
* @return string __CLASS__ Class name.
|
25 |
-
*/
|
26 |
-
public static function get_class_name() {
|
27 |
-
return __CLASS__;
|
28 |
-
}
|
29 |
-
|
30 |
-
/**
|
31 |
-
* Initiate check on important System Variables and compare them to required defaults.
|
32 |
-
*
|
33 |
-
* @uses \MainWP\Child\MainWP_Child_Server_Information_Base::check()
|
34 |
-
* @uses \MainWP\Child\MainWP_Child_Server_Information_Base::check_mainwp_directory()
|
35 |
-
*
|
36 |
-
* @return int $i Number of detected issues.
|
37 |
-
*/
|
38 |
-
protected static function get_warnings() {
|
39 |
-
$i = 0;
|
40 |
-
if ( ! self::check( '>=', '3.4', 'get_wordpress_version' ) ) {
|
41 |
-
$i ++;
|
42 |
-
}
|
43 |
-
if ( ! self::check( '>=', '5.2.4', 'get_php_version' ) ) {
|
44 |
-
$i ++;
|
45 |
-
}
|
46 |
-
if ( ! self::check( '>=', '5.0', 'get_my_sql_version' ) ) {
|
47 |
-
$i ++;
|
48 |
-
}
|
49 |
-
if ( ! self::check( '>=', '30', 'get_max_execution_time', '=', '0' ) ) {
|
50 |
-
$i ++;
|
51 |
-
}
|
52 |
-
if ( ! self::check( '>=', '2M', 'get_upload_max_filesize', null, null, true ) ) {
|
53 |
-
$i ++;
|
54 |
-
}
|
55 |
-
if ( ! self::check( '>=', '2M', 'get_post_max_size', null, null, true ) ) {
|
56 |
-
$i ++;
|
57 |
-
}
|
58 |
-
if ( ! self::check( '>=', '10000', 'get_output_buffer_size' ) ) {
|
59 |
-
$i ++;
|
60 |
-
}
|
61 |
-
if ( ! self::check_mainwp_directory() ) {
|
62 |
-
$i ++;
|
63 |
-
}
|
64 |
-
|
65 |
-
return $i;
|
66 |
-
}
|
67 |
-
|
68 |
-
/**
|
69 |
-
* Check if MainWP Directory is writeable.
|
70 |
-
*
|
71 |
-
* @param string $message Return message - Directory not found, Directory not writable, writeable.
|
72 |
-
* @param string $path MainWP directory path.
|
73 |
-
*
|
74 |
-
* @return bool TRUE if exists & writeable, FALSE if not.
|
75 |
-
*
|
76 |
-
* @uses \MainWP\Child\MainWP_Helper::get_mainwp_dir()
|
77 |
-
* @uses \MainWP\Child\MainWP_Helper::get_wp_filesystem()
|
78 |
-
* @uses Exception::getMessage()
|
79 |
-
*/
|
80 |
-
protected static function check_mainwp_directory( &$message = '', &$path = '' ) {
|
81 |
-
$path = '';
|
82 |
-
try {
|
83 |
-
$dirs = MainWP_Helper::get_mainwp_dir( null, false );
|
84 |
-
$path = $dirs[0];
|
85 |
-
} catch ( \Exception $e ) {
|
86 |
-
$message = $e->getMessage();
|
87 |
-
return false;
|
88 |
-
}
|
89 |
-
|
90 |
-
if ( ! is_dir( dirname( $path ) ) ) {
|
91 |
-
$message = 'Directory not found';
|
92 |
-
return false;
|
93 |
-
}
|
94 |
-
|
95 |
-
$hasWPFileSystem = MainWP_Helper::get_wp_filesystem();
|
96 |
-
|
97 |
-
/**
|
98 |
-
* WordPress files system object.
|
99 |
-
*
|
100 |
-
* @global object
|
101 |
-
*/
|
102 |
-
global $wp_filesystem;
|
103 |
-
|
104 |
-
if ( $hasWPFileSystem && ! empty( $wp_filesystem ) ) {
|
105 |
-
if ( ! $wp_filesystem->is_writable( $path ) ) {
|
106 |
-
$message = 'Directory not writable';
|
107 |
-
return false;
|
108 |
-
}
|
109 |
-
} else {
|
110 |
-
if ( ! is_writable( $path ) ) {
|
111 |
-
$message = 'Directory not writable';
|
112 |
-
return false;
|
113 |
-
}
|
114 |
-
}
|
115 |
-
$message = 'Writable';
|
116 |
-
return true;
|
117 |
-
}
|
118 |
-
|
119 |
-
/**
|
120 |
-
* Check Child Site system variables for any issues.
|
121 |
-
*
|
122 |
-
* @param string $pCompare Comparison operator.
|
123 |
-
* @param string $pVersion Version to compare to.
|
124 |
-
* @param string $pGetter The method to grab the data with.
|
125 |
-
* @param string $pExtraCompare Extra comparison operator.
|
126 |
-
* @param string $pExtraVersion Extra version to compare to.
|
127 |
-
* @param bool $sizeCompare Size to compare to.
|
128 |
-
*
|
129 |
-
* @uses \MainWP\Child\MainWP_Child_Server_Information_Base::get_class_name()
|
130 |
-
* @uses \MainWP\Child\MainWP_Child_Server_Information_Base::filesize_compare()
|
131 |
-
*
|
132 |
-
* @return bool|int When using the optional operator argument, the function will return TRUE if the
|
133 |
-
* relationship is the one specified by the operator, FALSE otherwise. Returns -1 if the first version
|
134 |
-
* is lower than the second, 0 if they are equal, and 1 if the second is lower.
|
135 |
-
*/
|
136 |
-
protected static function check( $pCompare, $pVersion, $pGetter, $pExtraCompare = null, $pExtraVersion = null, $sizeCompare = false ) {
|
137 |
-
$currentVersion = call_user_func( array( self::get_class_name(), $pGetter ) );
|
138 |
-
|
139 |
-
if ( $sizeCompare ) {
|
140 |
-
return self::filesize_compare( $currentVersion, $pVersion, $pCompare );
|
141 |
-
} else {
|
142 |
-
return ( version_compare( $currentVersion, $pVersion, $pCompare ) || ( ( null !== $pExtraCompare ) && version_compare( $currentVersion, $pExtraVersion, $pExtraCompare ) ) );
|
143 |
-
}
|
144 |
-
}
|
145 |
-
|
146 |
-
/**
|
147 |
-
* Compare filesizes.
|
148 |
-
*
|
149 |
-
* @param string $value1 First value to compare.
|
150 |
-
* @param string $value2 Second value to compare.
|
151 |
-
* @param string $operator Comparison operator.
|
152 |
-
*
|
153 |
-
* @return bool|int When using the optional operator argument, the function will return TRUE if the
|
154 |
-
* relationship is the one specified by the operator, FALSE otherwise. Returns -1 if the first version
|
155 |
-
* is lower than the second, 0 if they are equal, and 1 if the second is lower.
|
156 |
-
*/
|
157 |
-
protected static function filesize_compare( $value1, $value2, $operator = null ) {
|
158 |
-
if ( false !== strpos( $value1, 'G' ) ) {
|
159 |
-
$value1 = preg_replace( '/[A-Za-z]/', '', $value1 );
|
160 |
-
$value1 = intval( $value1 ) * 1024;
|
161 |
-
} else {
|
162 |
-
$value1 = preg_replace( '/[A-Za-z]/', '', $value1 );
|
163 |
-
}
|
164 |
-
|
165 |
-
if ( false !== strpos( $value2, 'G' ) ) {
|
166 |
-
$value2 = preg_replace( '/[A-Za-z]/', '', $value2 );
|
167 |
-
$value2 = intval( $value2 ) * 1024;
|
168 |
-
} else {
|
169 |
-
$value2 = preg_replace( '/[A-Za-z]/', '', $value2 );
|
170 |
-
}
|
171 |
-
|
172 |
-
return version_compare( $value1, $value2, $operator );
|
173 |
-
}
|
174 |
-
|
175 |
-
/**
|
176 |
-
* Check if PHP class curl_version() is enabled.
|
177 |
-
*
|
178 |
-
* @return bool If 'curl_version' function exists, return true, if not, return false.
|
179 |
-
*/
|
180 |
-
protected static function get_curl_support() {
|
181 |
-
return function_exists( 'curl_version' );
|
182 |
-
}
|
183 |
-
|
184 |
-
/**
|
185 |
-
* Get current cURL Timeout.
|
186 |
-
*
|
187 |
-
* @return int Current cURL timeout value.
|
188 |
-
*/
|
189 |
-
protected static function get_curl_timeout() {
|
190 |
-
return ini_get( 'default_socket_timeout' );
|
191 |
-
}
|
192 |
-
|
193 |
-
/**
|
194 |
-
* Get current cURL Version.
|
195 |
-
*
|
196 |
-
* @return string Current cURL Version.
|
197 |
-
*/
|
198 |
-
protected static function get_curl_version() {
|
199 |
-
$curlversion = curl_version();
|
200 |
-
|
201 |
-
return $curlversion['version'];
|
202 |
-
}
|
203 |
-
|
204 |
-
/**
|
205 |
-
* Compare current cURL & SSL versions to required values.
|
206 |
-
*
|
207 |
-
* @param string $version Required values to compare to.
|
208 |
-
* @param string $operator Comparison operator.
|
209 |
-
*
|
210 |
-
* @return bool|int When using the optional operator argument, the function will return TRUE if the
|
211 |
-
* relationship is the one specified by the operator, FALSE otherwise. Returns -1 if the first version
|
212 |
-
* is lower than the second, 0 if they are equal, and 1 if the second is lower.
|
213 |
-
*/
|
214 |
-
public static function curlssl_compare( $version, $operator ) {
|
215 |
-
if ( function_exists( 'curl_version' ) ) {
|
216 |
-
$ver = self::get_curl_ssl_version();
|
217 |
-
return version_compare( $ver, $version, $operator );
|
218 |
-
}
|
219 |
-
return false;
|
220 |
-
}
|
221 |
-
|
222 |
-
/**
|
223 |
-
* Get curl ssl version.
|
224 |
-
*
|
225 |
-
* @return string SSL version.
|
226 |
-
*/
|
227 |
-
protected static function get_curl_ssl_version() {
|
228 |
-
$curlversion = curl_version();
|
229 |
-
|
230 |
-
return $curlversion['ssl_version'];
|
231 |
-
}
|
232 |
-
|
233 |
-
/**
|
234 |
-
* Check for disabled PHP functions.
|
235 |
-
*/
|
236 |
-
protected static function mainwp_required_functions() {
|
237 |
-
$disabled_functions = ini_get( 'disable_functions' );
|
238 |
-
if ( '' !== $disabled_functions ) {
|
239 |
-
$arr = explode( ',', $disabled_functions );
|
240 |
-
sort( $arr );
|
241 |
-
$arr_length = count( $arr );
|
242 |
-
for ( $i = 0; $i < $arr_length; $i ++ ) {
|
243 |
-
echo esc_html( $arr[ $i ] . ', ' );
|
244 |
-
}
|
245 |
-
} else {
|
246 |
-
echo esc_html__( 'No functions disabled', 'mainwp-child' );
|
247 |
-
}
|
248 |
-
}
|
249 |
-
|
250 |
-
/**
|
251 |
-
* Get loaded PHP extensions.
|
252 |
-
*/
|
253 |
-
protected static function get_loaded_php_extensions() {
|
254 |
-
$extensions = get_loaded_extensions();
|
255 |
-
sort( $extensions );
|
256 |
-
echo esc_html( implode( ', ', $extensions ) );
|
257 |
-
}
|
258 |
-
|
259 |
-
/**
|
260 |
-
* Get file system method.
|
261 |
-
*
|
262 |
-
* @return string $fs The returned file system method.
|
263 |
-
*/
|
264 |
-
protected static function get_file_system_method() {
|
265 |
-
if ( defined( 'MAINWP_SAVE_FS_METHOD' ) ) {
|
266 |
-
return MAINWP_SAVE_FS_METHOD;
|
267 |
-
}
|
268 |
-
$fs = get_filesystem_method();
|
269 |
-
|
270 |
-
return $fs;
|
271 |
-
}
|
272 |
-
|
273 |
-
/**
|
274 |
-
* Get the current MainWP Child plugin version.
|
275 |
-
*
|
276 |
-
* @return string $currentVersion The MainWP Child plugin current version.
|
277 |
-
*/
|
278 |
-
protected static function get_current_version() {
|
279 |
-
$currentVersion = get_option( 'mainwp_child_plugin_version' );
|
280 |
-
|
281 |
-
return $currentVersion;
|
282 |
-
}
|
283 |
-
|
284 |
-
/**
|
285 |
-
* Get the current MainWP Child plugin version.
|
286 |
-
*
|
287 |
-
* @return string|bool Most recent MainWP Child version or FALSE.
|
288 |
-
*/
|
289 |
-
protected static function get_mainwp_version() {
|
290 |
-
include_once ABSPATH . '/wp-admin/includes/plugin-install.php';
|
291 |
-
$api = plugins_api(
|
292 |
-
'plugin_information',
|
293 |
-
array(
|
294 |
-
'slug' => 'mainwp-child',
|
295 |
-
'fields' => array( 'sections' => false ),
|
296 |
-
'timeout' => 60,
|
297 |
-
)
|
298 |
-
);
|
299 |
-
if ( is_object( $api ) && isset( $api->version ) ) {
|
300 |
-
return $api->version;
|
301 |
-
}
|
302 |
-
|
303 |
-
return false;
|
304 |
-
}
|
305 |
-
|
306 |
-
/**
|
307 |
-
* Check if PHP class \ZipArchive is enabled.
|
308 |
-
*
|
309 |
-
* @return bool If '\ZipArchive' class exists, return true, if not, return false.
|
310 |
-
*/
|
311 |
-
protected static function get_zip_archive_enabled() {
|
312 |
-
return class_exists( '\ZipArchive' );
|
313 |
-
}
|
314 |
-
|
315 |
-
/**
|
316 |
-
* Check if PHP function gzopen is enabled.
|
317 |
-
*
|
318 |
-
* @return bool If 'gzopen' function exists, return true, if not, return false.
|
319 |
-
*/
|
320 |
-
protected static function get_gzip_enabled() {
|
321 |
-
return function_exists( 'gzopen' );
|
322 |
-
}
|
323 |
-
|
324 |
-
/**
|
325 |
-
* Check if PHP function bzopen is enabled.
|
326 |
-
*
|
327 |
-
* @return bool If 'bzopen' function exists, return true, if not, return false.
|
328 |
-
*/
|
329 |
-
protected static function get_bzip_enabled() {
|
330 |
-
return function_exists( 'bzopen' );
|
331 |
-
}
|
332 |
-
|
333 |
-
/**
|
334 |
-
* Get current WordPress version.
|
335 |
-
*
|
336 |
-
* @return string $wp_version Current WordPress version.
|
337 |
-
*/
|
338 |
-
protected static function get_wordpress_version() {
|
339 |
-
|
340 |
-
/**
|
341 |
-
* The installed version of WordPress.
|
342 |
-
*
|
343 |
-
* @global string $wp_version The installed version of WordPress.
|
344 |
-
*/
|
345 |
-
global $wp_version;
|
346 |
-
|
347 |
-
return $wp_version;
|
348 |
-
}
|
349 |
-
|
350 |
-
/**
|
351 |
-
* Get current WordPress memory limit.
|
352 |
-
*
|
353 |
-
* @return string Current WordPress memory limit.
|
354 |
-
*/
|
355 |
-
protected static function get_wordpress_memory_limit() {
|
356 |
-
return WP_MEMORY_LIMIT;
|
357 |
-
}
|
358 |
-
|
359 |
-
/**
|
360 |
-
* Check if in multisite WordPress environment.
|
361 |
-
*
|
362 |
-
* @return bool If multisite detected, return false, if not, return true.
|
363 |
-
*/
|
364 |
-
protected static function check_if_multisite() {
|
365 |
-
$isMultisite = ! is_multisite() ? true : false;
|
366 |
-
|
367 |
-
return $isMultisite;
|
368 |
-
}
|
369 |
-
|
370 |
-
/**
|
371 |
-
* Check if PHP extension OpenSSL is enabled.
|
372 |
-
*
|
373 |
-
* @return bool If 'openssl' extension is loaded, return true, if not, return false.
|
374 |
-
*/
|
375 |
-
protected static function get_ssl_support() {
|
376 |
-
return extension_loaded( 'openssl' );
|
377 |
-
}
|
378 |
-
|
379 |
-
/**
|
380 |
-
* Get any SSL warnings.
|
381 |
-
*
|
382 |
-
* @return false|string Return error message if there are warnings, FALSE otherwise.
|
383 |
-
*/
|
384 |
-
protected static function get_ssl_warning() {
|
385 |
-
$conf = array( 'private_key_bits' => 2048 );
|
386 |
-
$str = '';
|
387 |
-
if ( function_exists( 'openssl_pkey_new' ) ) {
|
388 |
-
$res = openssl_pkey_new( $conf );
|
389 |
-
openssl_pkey_export( $res, $privkey );
|
390 |
-
|
391 |
-
$str = openssl_error_string();
|
392 |
-
}
|
393 |
-
return ( stristr( $str, 'NCONF_get_string:no value' ) ? '' : $str );
|
394 |
-
}
|
395 |
-
|
396 |
-
/**
|
397 |
-
* Get current PHP version.
|
398 |
-
*
|
399 |
-
* @return string Current PHP version.
|
400 |
-
*/
|
401 |
-
protected static function get_php_version() {
|
402 |
-
return phpversion();
|
403 |
-
}
|
404 |
-
|
405 |
-
/**
|
406 |
-
* Get max execution time.
|
407 |
-
*
|
408 |
-
* @return string Return the PHP max execution time.
|
409 |
-
*/
|
410 |
-
protected static function get_max_execution_time() {
|
411 |
-
return ini_get( 'max_execution_time' );
|
412 |
-
}
|
413 |
-
|
414 |
-
/**
|
415 |
-
* Get the max uplaod filesize.
|
416 |
-
*
|
417 |
-
* @return string Return the maximum upload filesize.
|
418 |
-
*/
|
419 |
-
protected static function get_upload_max_filesize() {
|
420 |
-
return ini_get( 'upload_max_filesize' );
|
421 |
-
}
|
422 |
-
|
423 |
-
/**
|
424 |
-
* Get the max post size.
|
425 |
-
*
|
426 |
-
* @return string Return the post maximum filesize.
|
427 |
-
*/
|
428 |
-
protected static function get_post_max_size() {
|
429 |
-
return ini_get( 'post_max_size' );
|
430 |
-
}
|
431 |
-
|
432 |
-
/**
|
433 |
-
* Get current MySQL version.
|
434 |
-
*
|
435 |
-
* @return string Return the current MySQL version.
|
436 |
-
*/
|
437 |
-
public static function get_my_sql_version() {
|
438 |
-
|
439 |
-
/**
|
440 |
-
* Object, providing access to the WordPress database.
|
441 |
-
*
|
442 |
-
* @global $wpdb WordPress Database instance.
|
443 |
-
*/
|
444 |
-
global $wpdb;
|
445 |
-
|
446 |
-
return $wpdb->get_var( "SHOW VARIABLES LIKE 'version'", 1 );
|
447 |
-
}
|
448 |
-
|
449 |
-
/**
|
450 |
-
* Get max input time.
|
451 |
-
*
|
452 |
-
* @return string Return current maximum input time.
|
453 |
-
*/
|
454 |
-
protected static function get_max_input_time() {
|
455 |
-
return ini_get( 'max_input_time' );
|
456 |
-
}
|
457 |
-
|
458 |
-
/**
|
459 |
-
* Get current PHP memory limit.
|
460 |
-
*
|
461 |
-
* @return string Return current PHP memory limit.
|
462 |
-
*/
|
463 |
-
public static function get_php_memory_limit() {
|
464 |
-
return ini_get( 'memory_limit' );
|
465 |
-
}
|
466 |
-
|
467 |
-
/**
|
468 |
-
* Get operating system.
|
469 |
-
*/
|
470 |
-
protected static function get_os() {
|
471 |
-
echo esc_html( PHP_OS );
|
472 |
-
}
|
473 |
-
|
474 |
-
/**
|
475 |
-
* Get System architecture.
|
476 |
-
*/
|
477 |
-
protected static function get_architecture() {
|
478 |
-
echo esc_html( PHP_INT_SIZE * 8 ) . ' bit';
|
479 |
-
}
|
480 |
-
|
481 |
-
/**
|
482 |
-
* Get the current Memory usage.
|
483 |
-
*/
|
484 |
-
protected static function memory_usage() {
|
485 |
-
if ( function_exists( 'memory_get_usage' ) ) {
|
486 |
-
$memory_usage = round( memory_get_usage() / 1024 / 1024, 2 ) . ' MB';
|
487 |
-
} else {
|
488 |
-
$memory_usage = __( 'N/A', 'mainwp-child' );
|
489 |
-
}
|
490 |
-
echo esc_html( $memory_usage );
|
491 |
-
}
|
492 |
-
|
493 |
-
/**
|
494 |
-
* Get the current output buffer size.
|
495 |
-
*
|
496 |
-
* @return string Return the current back track limit.
|
497 |
-
*/
|
498 |
-
protected static function get_output_buffer_size() {
|
499 |
-
return ini_get( 'pcre.backtrack_limit' );
|
500 |
-
}
|
501 |
-
|
502 |
-
/**
|
503 |
-
* Check if PHP is in Safe Mode.
|
504 |
-
*/
|
505 |
-
protected static function get_php_safe_mode() {
|
506 |
-
if ( version_compare( phpversion(), '5.3.0' ) < 0 && ini_get( 'safe_mode' ) ) {
|
507 |
-
$safe_mode = __( 'ON', 'mainwp-child' );
|
508 |
-
} else {
|
509 |
-
$safe_mode = __( 'OFF', 'mainwp-child' );
|
510 |
-
}
|
511 |
-
echo esc_html( $safe_mode );
|
512 |
-
}
|
513 |
-
|
514 |
-
/**
|
515 |
-
* Get current SQL mode.
|
516 |
-
*/
|
517 |
-
protected static function get_sql_mode() {
|
518 |
-
|
519 |
-
/**
|
520 |
-
* Object, providing access to the WordPress database.
|
521 |
-
*
|
522 |
-
* @global $wpdb WordPress Database instance.
|
523 |
-
*/
|
524 |
-
global $wpdb;
|
525 |
-
|
526 |
-
$mysqlinfo = $wpdb->get_results( "SHOW VARIABLES LIKE 'sql_mode'" );
|
527 |
-
if ( is_array( $mysqlinfo ) ) {
|
528 |
-
$sql_mode = $mysqlinfo[0]->Value;
|
529 |
-
}
|
530 |
-
if ( empty( $sql_mode ) ) {
|
531 |
-
$sql_mode = __( 'NOT SET', 'mainwp-child' );
|
532 |
-
}
|
533 |
-
echo esc_html( $sql_mode );
|
534 |
-
}
|
535 |
-
|
536 |
-
/**
|
537 |
-
* Check if PHP Allow URL fopen is enabled.
|
538 |
-
*/
|
539 |
-
protected static function get_php_allow_url_fopen() {
|
540 |
-
if ( ini_get( 'allow_url_fopen' ) ) {
|
541 |
-
$allow_url_fopen = __( 'ON', 'mainwp-child' );
|
542 |
-
} else {
|
543 |
-
$allow_url_fopen = __( 'OFF', 'mainwp-child' );
|
544 |
-
}
|
545 |
-
echo esc_html( $allow_url_fopen );
|
546 |
-
}
|
547 |
-
|
548 |
-
/**
|
549 |
-
* Check if PHP exif is enabled.
|
550 |
-
*/
|
551 |
-
protected static function get_php_exif() {
|
552 |
-
if ( is_callable( 'exif_read_data' ) ) {
|
553 |
-
$exif = __( 'YES', 'mainwp-child' ) . ' ( V' . substr( phpversion( 'exif' ), 0, 4 ) . ')';
|
554 |
-
} else {
|
555 |
-
$exif = __( 'NO', 'mainwp-child' );
|
556 |
-
}
|
557 |
-
echo esc_html( $exif );
|
558 |
-
}
|
559 |
-
|
560 |
-
/**
|
561 |
-
* Check if PHP IP TC is enabled.
|
562 |
-
*/
|
563 |
-
protected static function get_php_ip_tc() {
|
564 |
-
if ( is_callable( 'iptcparse' ) ) {
|
565 |
-
$iptc = __( 'YES', 'mainwp-child' );
|
566 |
-
} else {
|
567 |
-
$iptc = __( 'NO', 'mainwp-child' );
|
568 |
-
}
|
569 |
-
echo esc_html( $iptc );
|
570 |
-
}
|
571 |
-
|
572 |
-
/**
|
573 |
-
* Check if PHP XML is enabled.
|
574 |
-
*/
|
575 |
-
protected static function get_php_xml() {
|
576 |
-
if ( is_callable( 'xml_parser_create' ) ) {
|
577 |
-
$xml = __( 'YES', 'mainwp-child' );
|
578 |
-
} else {
|
579 |
-
$xml = __( 'NO', 'mainwp-child' );
|
580 |
-
}
|
581 |
-
echo esc_html( $xml );
|
582 |
-
}
|
583 |
-
|
584 |
-
/**
|
585 |
-
* Get current server gateway interface.
|
586 |
-
*/
|
587 |
-
protected static function get_server_getaway_interface() {
|
588 |
-
echo isset( $_SERVER['GATEWAY_INTERFACE'] ) ? esc_html( sanitize_text_field( wp_unslash( $_SERVER['GATEWAY_INTERFACE'] ) ) ) : '';
|
589 |
-
}
|
590 |
-
|
591 |
-
/**
|
592 |
-
* Get server IP.
|
593 |
-
*/
|
594 |
-
protected static function get_server_ip() {
|
595 |
-
echo isset( $_SERVER['SERVER_ADDR'] ) ? esc_html( sanitize_text_field( wp_unslash( $_SERVER['SERVER_ADDR'] ) ) ) : '';
|
596 |
-
}
|
597 |
-
|
598 |
-
/**
|
599 |
-
* Get server name.
|
600 |
-
*/
|
601 |
-
protected static function get_server_name() {
|
602 |
-
echo isset( $_SERVER['SERVER_NAME'] ) ? esc_html( sanitize_text_field( wp_unslash( $_SERVER['SERVER_NAME'] ) ) ) : '';
|
603 |
-
}
|
604 |
-
|
605 |
-
/**
|
606 |
-
* Get server software.
|
607 |
-
*/
|
608 |
-
protected static function get_server_software() {
|
609 |
-
echo isset( $_SERVER['SERVER_SOFTWARE'] ) ? esc_html( sanitize_text_field( wp_unslash( $_SERVER['SERVER_SOFTWARE'] ) ) ) : '';
|
610 |
-
}
|
611 |
-
|
612 |
-
/**
|
613 |
-
* Get server protocol.
|
614 |
-
*/
|
615 |
-
protected static function get_server_protocol() {
|
616 |
-
echo isset( $_SERVER['SERVER_PROTOCOL'] ) ? esc_html( sanitize_text_field( wp_unslash( $_SERVER['SERVER_PROTOCOL'] ) ) ) : '';
|
617 |
-
}
|
618 |
-
|
619 |
-
/**
|
620 |
-
* Get server request time.
|
621 |
-
*/
|
622 |
-
protected static function get_server_request_time() {
|
623 |
-
echo isset( $_SERVER['REQUEST_TIME'] ) ? esc_html( sanitize_text_field( wp_unslash( $_SERVER['REQUEST_TIME'] ) ) ) : '';
|
624 |
-
}
|
625 |
-
|
626 |
-
/**
|
627 |
-
* Get server HTTP accept.
|
628 |
-
*/
|
629 |
-
protected static function get_server_http_accept() {
|
630 |
-
echo isset( $_SERVER['HTTP_ACCEPT'] ) ? esc_html( sanitize_text_field( wp_unslash( $_SERVER['HTTP_ACCEPT'] ) ) ) : '';
|
631 |
-
}
|
632 |
-
|
633 |
-
/**
|
634 |
-
* Get server accepted charset.
|
635 |
-
*/
|
636 |
-
protected static function get_server_accept_charset() {
|
637 |
-
echo ! empty( $_SERVER['HTTP_ACCEPT_CHARSET'] ) ? esc_html( sanitize_text_field( wp_unslash( $_SERVER['HTTP_ACCEPT_CHARSET'] ) ) ) : esc_html_e( 'N/A', 'mainwp-child' );
|
638 |
-
}
|
639 |
-
|
640 |
-
/**
|
641 |
-
* Get server HTTP host.
|
642 |
-
*/
|
643 |
-
protected static function get_http_host() {
|
644 |
-
echo ! empty( $_SERVER['HTTP_HOST'] ) ? esc_html( sanitize_text_field( wp_unslash( $_SERVER['HTTP_HOST'] ) ) ) : '';
|
645 |
-
}
|
646 |
-
|
647 |
-
/**
|
648 |
-
* Get server complete URL.
|
649 |
-
*/
|
650 |
-
protected static function get_complete_url() {
|
651 |
-
echo ! empty( $_SERVER['HTTP_REFERER'] ) ? esc_html( wp_unslash( $_SERVER['HTTP_REFERER'] ) ) : '';
|
652 |
-
}
|
653 |
-
|
654 |
-
/**
|
655 |
-
* Get server user agent.
|
656 |
-
*/
|
657 |
-
protected static function get_user_agent() {
|
658 |
-
echo ! empty( $_SERVER['HTTP_USER_AGENT'] ) ? esc_html( sanitize_text_field( wp_unslash( $_SERVER['HTTP_USER_AGENT'] ) ) ) : '';
|
659 |
-
}
|
660 |
-
|
661 |
-
/**
|
662 |
-
* Check if HTTPS is on.
|
663 |
-
*/
|
664 |
-
protected static function get_https() {
|
665 |
-
echo ! empty( $_SERVER['HTTPS'] ) ? esc_html( __( 'ON', 'mainwp-child' ) . ' - ' . sanitize_text_field( wp_unslash( $_SERVER['HTTPS'] ) ) ) : esc_html__( 'OFF', 'mainwp-child' );
|
666 |
-
}
|
667 |
-
|
668 |
-
/**
|
669 |
-
* Server self-connection test.
|
670 |
-
*/
|
671 |
-
protected static function server_self_connect() {
|
672 |
-
$url = site_url( 'wp-cron.php' );
|
673 |
-
$query_args = array( 'mainwp_child_run' => 'test' );
|
674 |
-
$url = add_query_arg( $query_args, $url );
|
675 |
-
$args = array(
|
676 |
-
'blocking' => true,
|
677 |
-
'sslverify' => apply_filters( 'https_local_ssl_verify', true ),
|
678 |
-
'timeout' => 15,
|
679 |
-
);
|
680 |
-
$response = wp_remote_post( $url, $args );
|
681 |
-
$test_result = '';
|
682 |
-
if ( is_wp_error( $response ) ) {
|
683 |
-
$test_result .= sprintf( __( 'The HTTP response test get an error "%s"', 'mainwp-child' ), $response->get_error_message() );
|
684 |
-
}
|
685 |
-
$response_code = wp_remote_retrieve_response_code( $response );
|
686 |
-
if ( $response_code < 200 && $response_code > 204 ) {
|
687 |
-
$test_result .= sprintf( __( 'The HTTP response test get a false http status (%s)', 'mainwp-child' ), wp_remote_retrieve_response_code( $response ) );
|
688 |
-
} else {
|
689 |
-
$response_body = wp_remote_retrieve_body( $response );
|
690 |
-
if ( false === strstr( $response_body, 'MainWP Test' ) ) {
|
691 |
-
$test_result .= sprintf( __( 'Not expected HTTP response body: %s', 'mainwp-child' ), esc_attr( wp_strip_all_tags( $response_body ) ) );
|
692 |
-
}
|
693 |
-
}
|
694 |
-
if ( empty( $test_result ) ) {
|
695 |
-
_e( 'Response Test O.K.', 'mainwp-child' );
|
696 |
-
} else {
|
697 |
-
echo $test_result;
|
698 |
-
}
|
699 |
-
}
|
700 |
-
|
701 |
-
|
702 |
-
/**
|
703 |
-
* Get server remote address.
|
704 |
-
*/
|
705 |
-
protected static function get_remote_address() {
|
706 |
-
echo isset( $_SERVER['REMOTE_ADDR'] ) ? esc_html( sanitize_text_field( wp_unslash( $_SERVER['REMOTE_ADDR'] ) ) ) : '';
|
707 |
-
}
|
708 |
-
|
709 |
-
/**
|
710 |
-
* Get server remote host.
|
711 |
-
*/
|
712 |
-
protected static function get_remote_host() {
|
713 |
-
echo ! empty( $_SERVER['REMOTE_HOST'] ) ? sanitize_text_field( wp_unslash( $_SERVER['REMOTE_HOST'] ) ) : esc_html( 'N/A' );
|
714 |
-
}
|
715 |
-
|
716 |
-
/**
|
717 |
-
* Get server remote port.
|
718 |
-
*/
|
719 |
-
protected static function get_remote_port() {
|
720 |
-
echo ! empty( $_SERVER['REMOTE_PORT'] ) ? esc_html( sanitize_text_field( wp_unslash( $_SERVER['REMOTE_PORT'] ) ) ) : '';
|
721 |
-
}
|
722 |
-
|
723 |
-
/**
|
724 |
-
* Get server script filename.
|
725 |
-
*/
|
726 |
-
protected static function get_script_file_name() {
|
727 |
-
echo ! empty( $_SERVER['SCRIPT_FILENAME'] ) ? esc_html( sanitize_text_field( wp_unslash( $_SERVER['SCRIPT_FILENAME'] ) ) ) : '';
|
728 |
-
}
|
729 |
-
|
730 |
-
/**
|
731 |
-
* Get server port.
|
732 |
-
*/
|
733 |
-
protected static function get_server_port() {
|
734 |
-
echo ! empty( $_SERVER['SERVER_PORT'] ) ? esc_html( sanitize_text_field( wp_unslash( $_SERVER['SERVER_PORT'] ) ) ) : '';
|
735 |
-
}
|
736 |
-
|
737 |
-
/**
|
738 |
-
* Get current page URL.
|
739 |
-
*/
|
740 |
-
protected static function get_current_page_uri() {
|
741 |
-
echo ! empty( $_SERVER['REQUEST_URI'] ) ? esc_html( wp_unslash( $_SERVER['REQUEST_URI'] ) ) : '';
|
742 |
-
}
|
743 |
-
|
744 |
-
/**
|
745 |
-
* Get WordPress root directory.
|
746 |
-
*/
|
747 |
-
protected static function get_wp_root() {
|
748 |
-
echo esc_html( ABSPATH );
|
749 |
-
}
|
750 |
-
|
751 |
-
/**
|
752 |
-
* Time comparison.
|
753 |
-
*
|
754 |
-
* @param string $a Time 1.
|
755 |
-
* @param string $b Time 2.
|
756 |
-
*
|
757 |
-
* @return int Return 0 if $a is equal to $b, -1 if $a > $b or 1 if $a < $b.
|
758 |
-
*/
|
759 |
-
protected static function time_compare( $a, $b ) {
|
760 |
-
if ( $a === $b ) {
|
761 |
-
return 0;
|
762 |
-
}
|
763 |
-
|
764 |
-
return ( strtotime( $a['time'] ) > strtotime( $b['time'] ) ) ? - 1 : 1;
|
765 |
-
}
|
766 |
-
}
|
1 |
+
<?php
|
2 |
+
/**
|
3 |
+
* MainWP Child Server Information Base
|
4 |
+
*
|
5 |
+
* This is the base set of methods to collect a Child Site's Server Information.
|
6 |
+
*
|
7 |
+
* @package MainWP\Child
|
8 |
+
*/
|
9 |
+
|
10 |
+
namespace MainWP\Child;
|
11 |
+
|
12 |
+
/**
|
13 |
+
* Class MainWP_Child_Server_Information_Base
|
14 |
+
*
|
15 |
+
* Base set of methods to collect a Child Site's server information.
|
16 |
+
*/
|
17 |
+
class MainWP_Child_Server_Information_Base {
|
18 |
+
|
19 |
+
/**
|
20 |
+
* Method get_class_name()
|
21 |
+
*
|
22 |
+
* Get class name.
|
23 |
+
*
|
24 |
+
* @return string __CLASS__ Class name.
|
25 |
+
*/
|
26 |
+
public static function get_class_name() {
|
27 |
+
return __CLASS__;
|
28 |
+
}
|
29 |
+
|
30 |
+
/**
|
31 |
+
* Initiate check on important System Variables and compare them to required defaults.
|
32 |
+
*
|
33 |
+
* @uses \MainWP\Child\MainWP_Child_Server_Information_Base::check()
|
34 |
+
* @uses \MainWP\Child\MainWP_Child_Server_Information_Base::check_mainwp_directory()
|
35 |
+
*
|
36 |
+
* @return int $i Number of detected issues.
|
37 |
+
*/
|
38 |
+
protected static function get_warnings() {
|
39 |
+
$i = 0;
|
40 |
+
if ( ! self::check( '>=', '3.4', 'get_wordpress_version' ) ) {
|
41 |
+
$i ++;
|
42 |
+
}
|
43 |
+
if ( ! self::check( '>=', '5.2.4', 'get_php_version' ) ) {
|
44 |
+
$i ++;
|
45 |
+
}
|
46 |
+
if ( ! self::check( '>=', '5.0', 'get_my_sql_version' ) ) {
|
47 |
+
$i ++;
|
48 |
+
}
|
49 |
+
if ( ! self::check( '>=', '30', 'get_max_execution_time', '=', '0' ) ) {
|
50 |
+
$i ++;
|
51 |
+
}
|
52 |
+
if ( ! self::check( '>=', '2M', 'get_upload_max_filesize', null, null, true ) ) {
|
53 |
+
$i ++;
|
54 |
+
}
|
55 |
+
if ( ! self::check( '>=', '2M', 'get_post_max_size', null, null, true ) ) {
|
56 |
+
$i ++;
|
57 |
+
}
|
58 |
+
if ( ! self::check( '>=', '10000', 'get_output_buffer_size' ) ) {
|
59 |
+
$i ++;
|
60 |
+
}
|
61 |
+
if ( ! self::check_mainwp_directory() ) {
|
62 |
+
$i ++;
|
63 |
+
}
|
64 |
+
|
65 |
+
return $i;
|
66 |
+
}
|
67 |
+
|
68 |
+
/**
|
69 |
+
* Check if MainWP Directory is writeable.
|
70 |
+
*
|
71 |
+
* @param string $message Return message - Directory not found, Directory not writable, writeable.
|
72 |
+
* @param string $path MainWP directory path.
|
73 |
+
*
|
74 |
+
* @return bool TRUE if exists & writeable, FALSE if not.
|
75 |
+
*
|
76 |
+
* @uses \MainWP\Child\MainWP_Helper::get_mainwp_dir()
|
77 |
+
* @uses \MainWP\Child\MainWP_Helper::get_wp_filesystem()
|
78 |
+
* @uses Exception::getMessage()
|
79 |
+
*/
|
80 |
+
protected static function check_mainwp_directory( &$message = '', &$path = '' ) {
|
81 |
+
$path = '';
|
82 |
+
try {
|
83 |
+
$dirs = MainWP_Helper::get_mainwp_dir( null, false );
|
84 |
+
$path = $dirs[0];
|
85 |
+
} catch ( \Exception $e ) {
|
86 |
+
$message = $e->getMessage();
|
87 |
+
return false;
|
88 |
+
}
|
89 |
+
|
90 |
+
if ( ! is_dir( dirname( $path ) ) ) {
|
91 |
+
$message = 'Directory not found';
|
92 |
+
return false;
|
93 |
+
}
|
94 |
+
|
95 |
+
$hasWPFileSystem = MainWP_Helper::get_wp_filesystem();
|
96 |
+
|
97 |
+
/**
|
98 |
+
* WordPress files system object.
|
99 |
+
*
|
100 |
+
* @global object
|
101 |
+
*/
|
102 |
+
global $wp_filesystem;
|
103 |
+
|
104 |
+
if ( $hasWPFileSystem && ! empty( $wp_filesystem ) ) {
|
105 |
+
if ( ! $wp_filesystem->is_writable( $path ) ) {
|
106 |
+
$message = 'Directory not writable';
|
107 |
+
return false;
|
108 |
+
}
|
109 |
+
} else {
|
110 |
+
if ( ! is_writable( $path ) ) {
|
111 |
+
$message = 'Directory not writable';
|
112 |
+
return false;
|
113 |
+
}
|
114 |
+
}
|
115 |
+
$message = 'Writable';
|
116 |
+
return true;
|
117 |
+
}
|
118 |
+
|
119 |
+
/**
|
120 |
+
* Check Child Site system variables for any issues.
|
121 |
+
*
|
122 |
+
* @param string $pCompare Comparison operator.
|
123 |
+
* @param string $pVersion Version to compare to.
|
124 |
+
* @param string $pGetter The method to grab the data with.
|
125 |
+
* @param string $pExtraCompare Extra comparison operator.
|
126 |
+
* @param string $pExtraVersion Extra version to compare to.
|
127 |
+
* @param bool $sizeCompare Size to compare to.
|
128 |
+
*
|
129 |
+
* @uses \MainWP\Child\MainWP_Child_Server_Information_Base::get_class_name()
|
130 |
+
* @uses \MainWP\Child\MainWP_Child_Server_Information_Base::filesize_compare()
|
131 |
+
*
|
132 |
+
* @return bool|int When using the optional operator argument, the function will return TRUE if the
|
133 |
+
* relationship is the one specified by the operator, FALSE otherwise. Returns -1 if the first version
|
134 |
+
* is lower than the second, 0 if they are equal, and 1 if the second is lower.
|
135 |
+
*/
|
136 |
+
protected static function check( $pCompare, $pVersion, $pGetter, $pExtraCompare = null, $pExtraVersion = null, $sizeCompare = false ) {
|
137 |
+
$currentVersion = call_user_func( array( self::get_class_name(), $pGetter ) );
|
138 |
+
|
139 |
+
if ( $sizeCompare ) {
|
140 |
+
return self::filesize_compare( $currentVersion, $pVersion, $pCompare );
|
141 |
+
} else {
|
142 |
+
return ( version_compare( $currentVersion, $pVersion, $pCompare ) || ( ( null !== $pExtraCompare ) && version_compare( $currentVersion, $pExtraVersion, $pExtraCompare ) ) );
|
143 |
+
}
|
144 |
+
}
|
145 |
+
|
146 |
+
/**
|
147 |
+
* Compare filesizes.
|
148 |
+
*
|
149 |
+
* @param string $value1 First value to compare.
|
150 |
+
* @param string $value2 Second value to compare.
|
151 |
+
* @param string $operator Comparison operator.
|
152 |
+
*
|
153 |
+
* @return bool|int When using the optional operator argument, the function will return TRUE if the
|
154 |
+
* relationship is the one specified by the operator, FALSE otherwise. Returns -1 if the first version
|
155 |
+
* is lower than the second, 0 if they are equal, and 1 if the second is lower.
|
156 |
+
*/
|
157 |
+
protected static function filesize_compare( $value1, $value2, $operator = null ) {
|
158 |
+
if ( false !== strpos( $value1, 'G' ) ) {
|
159 |
+
$value1 = preg_replace( '/[A-Za-z]/', '', $value1 );
|
160 |
+
$value1 = intval( $value1 ) * 1024;
|
161 |
+
} else {
|
162 |
+
$value1 = preg_replace( '/[A-Za-z]/', '', $value1 );
|
163 |
+
}
|
164 |
+
|
165 |
+
if ( false !== strpos( $value2, 'G' ) ) {
|
166 |
+
$value2 = preg_replace( '/[A-Za-z]/', '', $value2 );
|
167 |
+
$value2 = intval( $value2 ) * 1024;
|
168 |
+
} else {
|
169 |
+
$value2 = preg_replace( '/[A-Za-z]/', '', $value2 );
|
170 |
+
}
|
171 |
+
|
172 |
+
return version_compare( $value1, $value2, $operator );
|
173 |
+
}
|
174 |
+
|
175 |
+
/**
|
176 |
+
* Check if PHP class curl_version() is enabled.
|
177 |
+
*
|
178 |
+
* @return bool If 'curl_version' function exists, return true, if not, return false.
|
179 |
+
*/
|
180 |
+
protected static function get_curl_support() {
|
181 |
+
return function_exists( 'curl_version' );
|
182 |
+
}
|
183 |
+
|
184 |
+
/**
|
185 |
+
* Get current cURL Timeout.
|
186 |
+
*
|
187 |
+
* @return int Current cURL timeout value.
|
188 |
+
*/
|
189 |
+
protected static function get_curl_timeout() {
|
190 |
+
return ini_get( 'default_socket_timeout' );
|
191 |
+
}
|
192 |
+
|
193 |
+
/**
|
194 |
+
* Get current cURL Version.
|
195 |
+
*
|
196 |
+
* @return string Current cURL Version.
|
197 |
+
*/
|
198 |
+
protected static function get_curl_version() {
|
199 |
+
$curlversion = curl_version();
|
200 |
+
|
201 |
+
return $curlversion['version'];
|
202 |
+
}
|
203 |
+
|
204 |
+
/**
|
205 |
+
* Compare current cURL & SSL versions to required values.
|
206 |
+
*
|
207 |
+
* @param string $version Required values to compare to.
|
208 |
+
* @param string $operator Comparison operator.
|
209 |
+
*
|
210 |
+
* @return bool|int When using the optional operator argument, the function will return TRUE if the
|
211 |
+
* relationship is the one specified by the operator, FALSE otherwise. Returns -1 if the first version
|
212 |
+
* is lower than the second, 0 if they are equal, and 1 if the second is lower.
|
213 |
+
*/
|
214 |
+
public static function curlssl_compare( $version, $operator ) {
|
215 |
+
if ( function_exists( 'curl_version' ) ) {
|
216 |
+
$ver = self::get_curl_ssl_version();
|
217 |
+
return version_compare( $ver, $version, $operator );
|
218 |
+
}
|
219 |
+
return false;
|
220 |
+
}
|
221 |
+
|
222 |
+
/**
|
223 |
+
* Get curl ssl version.
|
224 |
+
*
|
225 |
+
* @return string SSL version.
|
226 |
+
*/
|
227 |
+
protected static function get_curl_ssl_version() {
|
228 |
+
$curlversion = curl_version();
|
229 |
+
|
230 |
+
return $curlversion['ssl_version'];
|
231 |
+
}
|
232 |
+
|
233 |
+
/**
|
234 |
+
* Check for disabled PHP functions.
|
235 |
+
*/
|
236 |
+
protected static function mainwp_required_functions() {
|
237 |
+
$disabled_functions = ini_get( 'disable_functions' );
|
238 |
+
if ( '' !== $disabled_functions ) {
|
239 |
+
$arr = explode( ',', $disabled_functions );
|
240 |
+
sort( $arr );
|
241 |
+
$arr_length = count( $arr );
|
242 |
+
for ( $i = 0; $i < $arr_length; $i ++ ) {
|
243 |
+
echo esc_html( $arr[ $i ] . ', ' );
|
244 |
+
}
|
245 |
+
} else {
|
246 |
+
echo esc_html__( 'No functions disabled', 'mainwp-child' );
|
247 |
+
}
|
248 |
+
}
|
249 |
+
|
250 |
+
/**
|
251 |
+
* Get loaded PHP extensions.
|
252 |
+
*/
|
253 |
+
protected static function get_loaded_php_extensions() {
|
254 |
+
$extensions = get_loaded_extensions();
|
255 |
+
sort( $extensions );
|
256 |
+
echo esc_html( implode( ', ', $extensions ) );
|
257 |
+
}
|
258 |
+
|
259 |
+
/**
|
260 |
+
* Get file system method.
|
261 |
+
*
|
262 |
+
* @return string $fs The returned file system method.
|
263 |
+
*/
|
264 |
+
protected static function get_file_system_method() {
|
265 |
+
if ( defined( 'MAINWP_SAVE_FS_METHOD' ) ) {
|
266 |
+
return MAINWP_SAVE_FS_METHOD;
|
267 |
+
}
|
268 |
+
$fs = get_filesystem_method();
|
269 |
+
|
270 |
+
return $fs;
|
271 |
+
}
|
272 |
+
|
273 |
+
/**
|
274 |
+
* Get the current MainWP Child plugin version.
|
275 |
+
*
|
276 |
+
* @return string $currentVersion The MainWP Child plugin current version.
|
277 |
+
*/
|
278 |
+
protected static function get_current_version() {
|
279 |
+
$currentVersion = get_option( 'mainwp_child_plugin_version' );
|
280 |
+
|
281 |
+
return $currentVersion;
|
282 |
+
}
|
283 |
+
|
284 |
+
/**
|
285 |
+
* Get the current MainWP Child plugin version.
|
286 |
+
*
|
287 |
+
* @return string|bool Most recent MainWP Child version or FALSE.
|
288 |
+
*/
|
289 |
+
protected static function get_mainwp_version() {
|
290 |
+
include_once ABSPATH . '/wp-admin/includes/plugin-install.php';
|
291 |
+
$api = plugins_api(
|
292 |
+
'plugin_information',
|
293 |
+
array(
|
294 |
+
'slug' => 'mainwp-child',
|
295 |
+
'fields' => array( 'sections' => false ),
|
296 |
+
'timeout' => 60,
|
297 |
+
)
|
298 |
+
);
|
299 |
+
if ( is_object( $api ) && isset( $api->version ) ) {
|
300 |
+
return $api->version;
|
301 |
+
}
|
302 |
+
|
303 |
+
return false;
|
304 |
+
}
|
305 |
+
|
306 |
+
/**
|
307 |
+
* Check if PHP class \ZipArchive is enabled.
|
308 |
+
*
|
309 |
+
* @return bool If '\ZipArchive' class exists, return true, if not, return false.
|
310 |
+
*/
|
311 |
+
protected static function get_zip_archive_enabled() {
|
312 |
+
return class_exists( '\ZipArchive' );
|
313 |
+
}
|
314 |
+
|
315 |
+
/**
|
316 |
+
* Check if PHP function gzopen is enabled.
|
317 |
+
*
|
318 |
+
* @return bool If 'gzopen' function exists, return true, if not, return false.
|
319 |
+
*/
|
320 |
+
protected static function get_gzip_enabled() {
|
321 |
+
return function_exists( 'gzopen' );
|
322 |
+
}
|
323 |
+
|
324 |
+
/**
|
325 |
+
* Check if PHP function bzopen is enabled.
|
326 |
+
*
|
327 |
+
* @return bool If 'bzopen' function exists, return true, if not, return false.
|
328 |
+
*/
|
329 |
+
protected static function get_bzip_enabled() {
|
330 |
+
return function_exists( 'bzopen' );
|
331 |
+
}
|
332 |
+
|
333 |
+
/**
|
334 |
+
* Get current WordPress version.
|
335 |
+
*
|
336 |
+
* @return string $wp_version Current WordPress version.
|
337 |
+
*/
|
338 |
+
protected static function get_wordpress_version() {
|
339 |
+
|
340 |
+
/**
|
341 |
+
* The installed version of WordPress.
|
342 |
+
*
|
343 |
+
* @global string $wp_version The installed version of WordPress.
|
344 |
+
*/
|
345 |
+
global $wp_version;
|
346 |
+
|
347 |
+
return $wp_version;
|
348 |
+
}
|
349 |
+
|
350 |
+
/**
|
351 |
+
* Get current WordPress memory limit.
|
352 |
+
*
|
353 |
+
* @return string Current WordPress memory limit.
|
354 |
+
*/
|
355 |
+
protected static function get_wordpress_memory_limit() {
|
356 |
+
return WP_MEMORY_LIMIT;
|
357 |
+
}
|
358 |
+
|
359 |
+
/**
|
360 |
+
* Check if in multisite WordPress environment.
|
361 |
+
*
|
362 |
+
* @return bool If multisite detected, return false, if not, return true.
|
363 |
+
*/
|
364 |
+
protected static function check_if_multisite() {
|
365 |
+
$isMultisite = ! is_multisite() ? true : false;
|
366 |
+
|
367 |
+
return $isMultisite;
|
368 |
+
}
|
369 |
+
|
370 |
+
/**
|
371 |
+
* Check if PHP extension OpenSSL is enabled.
|
372 |
+
*
|
373 |
+
* @return bool If 'openssl' extension is loaded, return true, if not, return false.
|
374 |
+
*/
|
375 |
+
protected static function get_ssl_support() {
|
376 |
+
return extension_loaded( 'openssl' );
|
377 |
+
}
|
378 |
+
|
379 |
+
/**
|
380 |
+
* Get any SSL warnings.
|
381 |
+
*
|
382 |
+
* @return false|string Return error message if there are warnings, FALSE otherwise.
|
383 |
+
*/
|
384 |
+
protected static function get_ssl_warning() {
|
385 |
+
$conf = array( 'private_key_bits' => 2048 );
|
386 |
+
$str = '';
|
387 |
+
if ( function_exists( 'openssl_pkey_new' ) ) {
|
388 |
+
$res = openssl_pkey_new( $conf );
|
389 |
+
openssl_pkey_export( $res, $privkey );
|
390 |
+
|
391 |
+
$str = openssl_error_string();
|
392 |
+
}
|
393 |
+
return ( stristr( $str, 'NCONF_get_string:no value' ) ? '' : $str );
|
394 |
+
}
|
395 |
+
|
396 |
+
/**
|
397 |
+
* Get current PHP version.
|
398 |
+
*
|
399 |
+
* @return string Current PHP version.
|
400 |
+
*/
|
401 |
+
protected static function get_php_version() {
|
402 |
+
return phpversion();
|
403 |
+
}
|
404 |
+
|
405 |
+
/**
|
406 |
+
* Get max execution time.
|
407 |
+
*
|
408 |
+
* @return string Return the PHP max execution time.
|
409 |
+
*/
|
410 |
+
protected static function get_max_execution_time() {
|
411 |
+
return ini_get( 'max_execution_time' );
|
412 |
+
}
|
413 |
+
|
414 |
+
/**
|
415 |
+
* Get the max uplaod filesize.
|
416 |
+
*
|
417 |
+
* @return string Return the maximum upload filesize.
|
418 |
+
*/
|
419 |
+
protected static function get_upload_max_filesize() {
|
420 |
+
return ini_get( 'upload_max_filesize' );
|
421 |
+
}
|
422 |
+
|
423 |
+
/**
|
424 |
+
* Get the max post size.
|
425 |
+
*
|
426 |
+
* @return string Return the post maximum filesize.
|
427 |
+
*/
|
428 |
+
protected static function get_post_max_size() {
|
429 |
+
return ini_get( 'post_max_size' );
|
430 |
+
}
|
431 |
+
|
432 |
+
/**
|
433 |
+
* Get current MySQL version.
|
434 |
+
*
|
435 |
+
* @return string Return the current MySQL version.
|
436 |
+
*/
|
437 |
+
public static function get_my_sql_version() {
|
438 |
+
|
439 |
+
/**
|
440 |
+
* Object, providing access to the WordPress database.
|
441 |
+
*
|
442 |
+
* @global $wpdb WordPress Database instance.
|
443 |
+
*/
|
444 |
+
global $wpdb;
|
445 |
+
|
446 |
+
return $wpdb->get_var( "SHOW VARIABLES LIKE 'version'", 1 );
|
447 |
+
}
|
448 |
+
|
449 |
+
/**
|
450 |
+
* Get max input time.
|
451 |
+
*
|
452 |
+
* @return string Return current maximum input time.
|
453 |
+
*/
|
454 |
+
protected static function get_max_input_time() {
|
455 |
+
return ini_get( 'max_input_time' );
|
456 |
+
}
|
457 |
+
|
458 |
+
/**
|
459 |
+
* Get current PHP memory limit.
|
460 |
+
*
|
461 |
+
* @return string Return current PHP memory limit.
|
462 |
+
*/
|
463 |
+
public static function get_php_memory_limit() {
|
464 |
+
return ini_get( 'memory_limit' );
|
465 |
+
}
|
466 |
+
|
467 |
+
/**
|
468 |
+
* Get operating system.
|
469 |
+
*/
|
470 |
+
protected static function get_os() {
|
471 |
+
echo esc_html( PHP_OS );
|
472 |
+
}
|
473 |
+
|
474 |
+
/**
|
475 |
+
* Get System architecture.
|
476 |
+
*/
|
477 |
+
protected static function get_architecture() {
|
478 |
+
echo esc_html( PHP_INT_SIZE * 8 ) . ' bit';
|
479 |
+
}
|
480 |
+
|
481 |
+
/**
|
482 |
+
* Get the current Memory usage.
|
483 |
+
*/
|
484 |
+
protected static function memory_usage() {
|
485 |
+
if ( function_exists( 'memory_get_usage' ) ) {
|
486 |
+
$memory_usage = round( memory_get_usage() / 1024 / 1024, 2 ) . ' MB';
|
487 |
+
} else {
|
488 |
+
$memory_usage = __( 'N/A', 'mainwp-child' );
|
489 |
+
}
|
490 |
+
echo esc_html( $memory_usage );
|
491 |
+
}
|
492 |
+
|
493 |
+
/**
|
494 |
+
* Get the current output buffer size.
|
495 |
+
*
|
496 |
+
* @return string Return the current back track limit.
|
497 |
+
*/
|
498 |
+
protected static function get_output_buffer_size() {
|
499 |
+
return ini_get( 'pcre.backtrack_limit' );
|
500 |
+
}
|
501 |
+
|
502 |
+
/**
|
503 |
+
* Check if PHP is in Safe Mode.
|
504 |
+
*/
|
505 |
+
protected static function get_php_safe_mode() {
|
506 |
+
if ( version_compare( phpversion(), '5.3.0' ) < 0 && ini_get( 'safe_mode' ) ) {
|
507 |
+
$safe_mode = __( 'ON', 'mainwp-child' );
|
508 |
+
} else {
|
509 |
+
$safe_mode = __( 'OFF', 'mainwp-child' );
|
510 |
+
}
|
511 |
+
echo esc_html( $safe_mode );
|
512 |
+
}
|
513 |
+
|
514 |
+
/**
|
515 |
+
* Get current SQL mode.
|
516 |
+
*/
|
517 |
+
protected static function get_sql_mode() {
|
518 |
+
|
519 |
+
/**
|
520 |
+
* Object, providing access to the WordPress database.
|
521 |
+
*
|
522 |
+
* @global $wpdb WordPress Database instance.
|
523 |
+
*/
|
524 |
+
global $wpdb;
|
525 |
+
|
526 |
+
$mysqlinfo = $wpdb->get_results( "SHOW VARIABLES LIKE 'sql_mode'" );
|
527 |
+
if ( is_array( $mysqlinfo ) ) {
|
528 |
+
$sql_mode = $mysqlinfo[0]->Value;
|
529 |
+
}
|
530 |
+
if ( empty( $sql_mode ) ) {
|
531 |
+
$sql_mode = __( 'NOT SET', 'mainwp-child' );
|
532 |
+
}
|
533 |
+
echo esc_html( $sql_mode );
|
534 |
+
}
|
535 |
+
|
536 |
+
/**
|
537 |
+
* Check if PHP Allow URL fopen is enabled.
|
538 |
+
*/
|
539 |
+
protected static function get_php_allow_url_fopen() {
|
540 |
+
if ( ini_get( 'allow_url_fopen' ) ) {
|
541 |
+
$allow_url_fopen = __( 'ON', 'mainwp-child' );
|
542 |
+
} else {
|
543 |
+
$allow_url_fopen = __( 'OFF', 'mainwp-child' );
|
544 |
+
}
|
545 |
+
echo esc_html( $allow_url_fopen );
|
546 |
+
}
|
547 |
+
|
548 |
+
/**
|
549 |
+
* Check if PHP exif is enabled.
|
550 |
+
*/
|
551 |
+
protected static function get_php_exif() {
|
552 |
+
if ( is_callable( 'exif_read_data' ) ) {
|
553 |
+
$exif = __( 'YES', 'mainwp-child' ) . ' ( V' . substr( phpversion( 'exif' ), 0, 4 ) . ')';
|
554 |
+
} else {
|
555 |
+
$exif = __( 'NO', 'mainwp-child' );
|
556 |
+
}
|
557 |
+
echo esc_html( $exif );
|
558 |
+
}
|
559 |
+
|
560 |
+
/**
|
561 |
+
* Check if PHP IP TC is enabled.
|
562 |
+
*/
|
563 |
+
protected static function get_php_ip_tc() {
|
564 |
+
if ( is_callable( 'iptcparse' ) ) {
|
565 |
+
$iptc = __( 'YES', 'mainwp-child' );
|
566 |
+
} else {
|
567 |
+
$iptc = __( 'NO', 'mainwp-child' );
|
568 |
+
}
|
569 |
+
echo esc_html( $iptc );
|
570 |
+
}
|
571 |
+
|
572 |
+
/**
|
573 |
+
* Check if PHP XML is enabled.
|
574 |
+
*/
|
575 |
+
protected static function get_php_xml() {
|
576 |
+
if ( is_callable( 'xml_parser_create' ) ) {
|
577 |
+
$xml = __( 'YES', 'mainwp-child' );
|
578 |
+
} else {
|
579 |
+
$xml = __( 'NO', 'mainwp-child' );
|
580 |
+
}
|
581 |
+
echo esc_html( $xml );
|
582 |
+
}
|
583 |
+
|
584 |
+
/**
|
585 |
+
* Get current server gateway interface.
|
586 |
+
*/
|
587 |
+
protected static function get_server_getaway_interface() {
|
588 |
+
echo isset( $_SERVER['GATEWAY_INTERFACE'] ) ? esc_html( sanitize_text_field( wp_unslash( $_SERVER['GATEWAY_INTERFACE'] ) ) ) : '';
|
589 |
+
}
|
590 |
+
|
591 |
+
/**
|
592 |
+
* Get server IP.
|
593 |
+
*/
|
594 |
+
protected static function get_server_ip() {
|
595 |
+
echo isset( $_SERVER['SERVER_ADDR'] ) ? esc_html( sanitize_text_field( wp_unslash( $_SERVER['SERVER_ADDR'] ) ) ) : '';
|
596 |
+
}
|
597 |
+
|
598 |
+
/**
|
599 |
+
* Get server name.
|
600 |
+
*/
|
601 |
+
protected static function get_server_name() {
|
602 |
+
echo isset( $_SERVER['SERVER_NAME'] ) ? esc_html( sanitize_text_field( wp_unslash( $_SERVER['SERVER_NAME'] ) ) ) : '';
|
603 |
+
}
|
604 |
+
|
605 |
+
/**
|
606 |
+
* Get server software.
|
607 |
+
*/
|
608 |
+
protected static function get_server_software() {
|
609 |
+
echo isset( $_SERVER['SERVER_SOFTWARE'] ) ? esc_html( sanitize_text_field( wp_unslash( $_SERVER['SERVER_SOFTWARE'] ) ) ) : '';
|
610 |
+
}
|
611 |
+
|
612 |
+
/**
|
613 |
+
* Get server protocol.
|
614 |
+
*/
|
615 |
+
protected static function get_server_protocol() {
|
616 |
+
echo isset( $_SERVER['SERVER_PROTOCOL'] ) ? esc_html( sanitize_text_field( wp_unslash( $_SERVER['SERVER_PROTOCOL'] ) ) ) : '';
|
617 |
+
}
|
618 |
+
|
619 |
+
/**
|
620 |
+
* Get server request time.
|
621 |
+
*/
|
622 |
+
protected static function get_server_request_time() {
|
623 |
+
echo isset( $_SERVER['REQUEST_TIME'] ) ? esc_html( sanitize_text_field( wp_unslash( $_SERVER['REQUEST_TIME'] ) ) ) : '';
|
624 |
+
}
|
625 |
+
|
626 |
+
/**
|
627 |
+
* Get server HTTP accept.
|
628 |
+
*/
|
629 |
+
protected static function get_server_http_accept() {
|
630 |
+
echo isset( $_SERVER['HTTP_ACCEPT'] ) ? esc_html( sanitize_text_field( wp_unslash( $_SERVER['HTTP_ACCEPT'] ) ) ) : '';
|
631 |
+
}
|
632 |
+
|
633 |
+
/**
|
634 |
+
* Get server accepted charset.
|
635 |
+
*/
|
636 |
+
protected static function get_server_accept_charset() {
|
637 |
+
echo ! empty( $_SERVER['HTTP_ACCEPT_CHARSET'] ) ? esc_html( sanitize_text_field( wp_unslash( $_SERVER['HTTP_ACCEPT_CHARSET'] ) ) ) : esc_html_e( 'N/A', 'mainwp-child' );
|
638 |
+
}
|
639 |
+
|
640 |
+
/**
|
641 |
+
* Get server HTTP host.
|
642 |
+
*/
|
643 |
+
protected static function get_http_host() {
|
644 |
+
echo ! empty( $_SERVER['HTTP_HOST'] ) ? esc_html( sanitize_text_field( wp_unslash( $_SERVER['HTTP_HOST'] ) ) ) : '';
|
645 |
+
}
|
646 |
+
|
647 |
+
/**
|
648 |
+
* Get server complete URL.
|
649 |
+
*/
|
650 |
+
protected static function get_complete_url() {
|
651 |
+
echo ! empty( $_SERVER['HTTP_REFERER'] ) ? esc_html( wp_unslash( $_SERVER['HTTP_REFERER'] ) ) : '';
|
652 |
+
}
|
653 |
+
|
654 |
+
/**
|
655 |
+
* Get server user agent.
|
656 |
+
*/
|
657 |
+
protected static function get_user_agent() {
|
658 |
+
echo ! empty( $_SERVER['HTTP_USER_AGENT'] ) ? esc_html( sanitize_text_field( wp_unslash( $_SERVER['HTTP_USER_AGENT'] ) ) ) : '';
|
659 |
+
}
|
660 |
+
|
661 |
+
/**
|
662 |
+
* Check if HTTPS is on.
|
663 |
+
*/
|
664 |
+
protected static function get_https() {
|
665 |
+
echo ! empty( $_SERVER['HTTPS'] ) ? esc_html( __( 'ON', 'mainwp-child' ) . ' - ' . sanitize_text_field( wp_unslash( $_SERVER['HTTPS'] ) ) ) : esc_html__( 'OFF', 'mainwp-child' );
|
666 |
+
}
|
667 |
+
|
668 |
+
/**
|
669 |
+
* Server self-connection test.
|
670 |
+
*/
|
671 |
+
protected static function server_self_connect() {
|
672 |
+
$url = site_url( 'wp-cron.php' );
|
673 |
+
$query_args = array( 'mainwp_child_run' => 'test' );
|
674 |
+
$url = add_query_arg( $query_args, $url );
|
675 |
+
$args = array(
|
676 |
+
'blocking' => true,
|
677 |
+
'sslverify' => apply_filters( 'https_local_ssl_verify', true ),
|
678 |
+
'timeout' => 15,
|
679 |
+
);
|
680 |
+
$response = wp_remote_post( $url, $args );
|
681 |
+
$test_result = '';
|
682 |
+
if ( is_wp_error( $response ) ) {
|
683 |
+
$test_result .= sprintf( __( 'The HTTP response test get an error "%s"', 'mainwp-child' ), $response->get_error_message() );
|
684 |
+
}
|
685 |
+
$response_code = wp_remote_retrieve_response_code( $response );
|
686 |
+
if ( $response_code < 200 && $response_code > 204 ) {
|
687 |
+
$test_result .= sprintf( __( 'The HTTP response test get a false http status (%s)', 'mainwp-child' ), wp_remote_retrieve_response_code( $response ) );
|
688 |
+
} else {
|
689 |
+
$response_body = wp_remote_retrieve_body( $response );
|
690 |
+
if ( false === strstr( $response_body, 'MainWP Test' ) ) {
|
691 |
+
$test_result .= sprintf( __( 'Not expected HTTP response body: %s', 'mainwp-child' ), esc_attr( wp_strip_all_tags( $response_body ) ) );
|
692 |
+
}
|
693 |
+
}
|
694 |
+
if ( empty( $test_result ) ) {
|
695 |
+
_e( 'Response Test O.K.', 'mainwp-child' );
|
696 |
+
} else {
|
697 |
+
echo $test_result;
|
698 |
+
}
|
699 |
+
}
|
700 |
+
|
701 |
+
|
702 |
+
/**
|
703 |
+
* Get server remote address.
|
704 |
+
*/
|
705 |
+
protected static function get_remote_address() {
|
706 |
+
echo isset( $_SERVER['REMOTE_ADDR'] ) ? esc_html( sanitize_text_field( wp_unslash( $_SERVER['REMOTE_ADDR'] ) ) ) : '';
|
707 |
+
}
|
708 |
+
|
709 |
+
/**
|
710 |
+
* Get server remote host.
|
711 |
+
*/
|
712 |
+
protected static function get_remote_host() {
|
713 |
+
echo ! empty( $_SERVER['REMOTE_HOST'] ) ? sanitize_text_field( wp_unslash( $_SERVER['REMOTE_HOST'] ) ) : esc_html( 'N/A' );
|
714 |
+
}
|
715 |
+
|
716 |
+
/**
|
717 |
+
* Get server remote port.
|
718 |
+
*/
|
719 |
+
protected static function get_remote_port() {
|
720 |
+
echo ! empty( $_SERVER['REMOTE_PORT'] ) ? esc_html( sanitize_text_field( wp_unslash( $_SERVER['REMOTE_PORT'] ) ) ) : '';
|
721 |
+
}
|
722 |
+
|
723 |
+
/**
|
724 |
+
* Get server script filename.
|
725 |
+
*/
|
726 |
+
protected static function get_script_file_name() {
|
727 |
+
echo ! empty( $_SERVER['SCRIPT_FILENAME'] ) ? esc_html( sanitize_text_field( wp_unslash( $_SERVER['SCRIPT_FILENAME'] ) ) ) : '';
|
728 |
+
}
|
729 |
+
|
730 |
+
/**
|
731 |
+
* Get server port.
|
732 |
+
*/
|
733 |
+
protected static function get_server_port() {
|
734 |
+
echo ! empty( $_SERVER['SERVER_PORT'] ) ? esc_html( sanitize_text_field( wp_unslash( $_SERVER['SERVER_PORT'] ) ) ) : '';
|
735 |
+
}
|
736 |
+
|
737 |
+
/**
|
738 |
+
* Get current page URL.
|
739 |
+
*/
|
740 |
+
protected static function get_current_page_uri() {
|
741 |
+
echo ! empty( $_SERVER['REQUEST_URI'] ) ? esc_html( wp_unslash( $_SERVER['REQUEST_URI'] ) ) : '';
|
742 |
+
}
|
743 |
+
|
744 |
+
/**
|
745 |
+
* Get WordPress root directory.
|
746 |
+
*/
|
747 |
+
protected static function get_wp_root() {
|
748 |
+
echo esc_html( ABSPATH );
|
749 |
+
}
|
750 |
+
|
751 |
+
/**
|
752 |
+
* Time comparison.
|
753 |
+
*
|
754 |
+
* @param string $a Time 1.
|
755 |
+
* @param string $b Time 2.
|
756 |
+
*
|
757 |
+
* @return int Return 0 if $a is equal to $b, -1 if $a > $b or 1 if $a < $b.
|
758 |
+
*/
|
759 |
+
protected static function time_compare( $a, $b ) {
|
760 |
+
if ( $a === $b ) {
|
761 |
+
return 0;
|
762 |
+
}
|
763 |
+
|
764 |
+
return ( strtotime( $a['time'] ) > strtotime( $b['time'] ) ) ? - 1 : 1;
|
765 |
+
}
|
766 |
+
}
|
class/class-mainwp-child-server-information.php
CHANGED
@@ -1,1443 +1,1443 @@
|
|
1 |
-
<?php
|
2 |
-
/**
|
3 |
-
* MainWP Child Server Information
|
4 |
-
*
|
5 |
-
* MainWP Child server information handler.
|
6 |
-
*
|
7 |
-
* @package MainWP\Child
|
8 |
-
*/
|
9 |
-
|
10 |
-
namespace MainWP\Child;
|
11 |
-
|
12 |
-
/**
|
13 |
-
* Class MainWP_Child_Server_Information
|
14 |
-
*
|
15 |
-
* MainWP Child server information handler.
|
16 |
-
*
|
17 |
-
* @uses \MainWP\Child\MainWP_Child_Server_Information_Base
|
18 |
-
*/
|
19 |
-
class MainWP_Child_Server_Information extends MainWP_Child_Server_Information_Base {
|
20 |
-
const WARNING = 1;
|
21 |
-
const ERROR = 2;
|
22 |
-
|
23 |
-
/**
|
24 |
-
* Method get_class_name()
|
25 |
-
*
|
26 |
-
* Get class name.
|
27 |
-
*
|
28 |
-
* @return string __CLASS__ Class name.
|
29 |
-
*/
|
30 |
-
public static function get_class_name() {
|
31 |
-
return __CLASS__;
|
32 |
-
}
|
33 |
-
|
34 |
-
/**
|
35 |
-
* Add hooks after WordPress has finished loading but before any headers are sent.
|
36 |
-
*
|
37 |
-
* @uses MainWP_Child_Server_Information::dismiss_warnings() Dismiss warnings.
|
38 |
-
*/
|
39 |
-
public static function init() {
|
40 |
-
add_action(
|
41 |
-
'wp_ajax_mainwp-child_dismiss_warnings',
|
42 |
-
array(
|
43 |
-
self::get_class_name(),
|
44 |
-
'dismiss_warnings',
|
45 |
-
)
|
46 |
-
);
|
47 |
-
}
|
48 |
-
|
49 |
-
/**
|
50 |
-
* Dismiss warnings.
|
51 |
-
*
|
52 |
-
* @uses \MainWP\Child\MainWP_Helper::update_option() Update option by option name.
|
53 |
-
* @uses \MainWP\Child\MainWP_Child_Server_Information_Base::get_warnings() Initiate check on important System Variables and compare them to required defaults.
|
54 |
-
* @uses get_option() Retrieves an option value based on an option name.
|
55 |
-
* @see https://developer.wordpress.org/reference/functions/get_option/
|
56 |
-
*
|
57 |
-
* @used-by MainWP_Child_Server_Information::init() Add hooks after WordPress has finished loading but before any headers are sent.
|
58 |
-
*/
|
59 |
-
public static function dismiss_warnings() {
|
60 |
-
if ( isset( $_POST['what'] ) ) {
|
61 |
-
$dismissWarnings = get_option( 'mainwp_child_dismiss_warnings' );
|
62 |
-
if ( ! is_array( $dismissWarnings ) ) {
|
63 |
-
$dismissWarnings = array();
|
64 |
-
}
|
65 |
-
if ( 'warning' == $_POST['what'] ) {
|
66 |
-
if ( isset( $_POST['warnings'] ) ) {
|
67 |
-
$warnings = intval( $_POST['warnings'] );
|
68 |
-
} else {
|
69 |
-
$warnings = self::get_warnings();
|
70 |
-
}
|
71 |
-
$dismissWarnings['warnings'] = $warnings;
|
72 |
-
}
|
73 |
-
MainWP_Helper::update_option( 'mainwp_child_dismiss_warnings', $dismissWarnings );
|
74 |
-
}
|
75 |
-
}
|
76 |
-
|
77 |
-
/**
|
78 |
-
* Render warnings.
|
79 |
-
*
|
80 |
-
* @uses \MainWP\Child\MainWP_Helper::update_option() Update option by option name.
|
81 |
-
* @uses \MainWP\Child\MainWP_Child_Server_Information_Base::get_warnings() Initiate check on important System Variables and compare them to required defaults.
|
82 |
-
* @uses get_option() Retrieves an option value based on an option name.
|
83 |
-
* @see https://developer.wordpress.org/reference/functions/get_option/
|
84 |
-
*
|
85 |
-
* @used-by MainWP_Child_Server_Information::init() Add hooks after WordPress has finished loading but before any headers are sent.
|
86 |
-
*/
|
87 |
-
public static function render_warnings() {
|
88 |
-
$request_uri = isset( $_SERVER['REQUEST_URI'] ) ? wp_unslash( $_SERVER['REQUEST_URI'] ) : '';
|
89 |
-
if ( isset( $_SERVER['REQUEST_URI'] ) && ( stristr( $request_uri, 'mainwp_child_tab' ) || stristr( $request_uri, 'mainwp-reports-page' ) || stristr( $request_uri, 'mainwp-reports-settings' ) ) ) {
|
90 |
-
return;
|
91 |
-
}
|
92 |
-
|
93 |
-
// improved query.
|
94 |
-
if ( self::is_mainwp_pages() ) {
|
95 |
-
return;
|
96 |
-
}
|
97 |
-
|
98 |
-
$warnings = self::get_warnings();
|
99 |
-
|
100 |
-
$dismissWarnings = get_option( 'mainwp_child_dismiss_warnings' );
|
101 |
-
if ( ! is_array( $dismissWarnings ) ) {
|
102 |
-
$dismissWarnings = array();
|
103 |
-
}
|
104 |
-
|
105 |
-
if ( isset( $dismissWarnings['warnings'] ) && $dismissWarnings['warnings'] >= $warnings ) {
|
106 |
-
$warnings = 0;
|
107 |
-
}
|
108 |
-
|
109 |
-
if ( 0 === $warnings ) {
|
110 |
-
return;
|
111 |
-
}
|
112 |
-
|
113 |
-
if ( $warnings > 0 ) {
|
114 |
-
$dismissWarnings['warnings'] = 0;
|
115 |
-
}
|
116 |
-
|
117 |
-
MainWP_Helper::update_option( 'mainwp_child_dismiss_warnings', $dismissWarnings );
|
118 |
-
?>
|
119 |
-
<script language="javascript">
|
120 |
-
dismiss_warnings = function ( pElement, pAction ) {
|
121 |
-
var table = jQuery( pElement.parents( 'table' )[0] );
|
122 |
-
pElement.parents( 'tr' )[0].remove();
|
123 |
-
if ( table.find( 'tr' ).length == 0 ) {
|
124 |
-
jQuery( '#mainwp-child_server_warnings' ).hide();
|
125 |
-
}
|
126 |
-
|
127 |
-
var data = {
|
128 |
-
action: 'mainwp-child_dismiss_warnings',
|
129 |
-
what: pAction,
|
130 |
-
warnings: <?php echo intval( $warnings ); ?>
|
131 |
-
};
|
132 |
-
|
133 |
-
jQuery.ajax( {
|
134 |
-
type: "POST",
|
135 |
-
url: ajaxurl,
|
136 |
-
data: data,
|
137 |
-
success: function ( resp ) {},
|
138 |
-
error: function () {},
|
139 |
-
dataType: 'json'
|
140 |
-
} );
|
141 |
-
|
142 |
-
return false;
|
143 |
-
};
|
144 |
-
jQuery( document ).on( 'click', '#mainwp-child-connect-warning-dismiss', function () {
|
145 |
-
return dismiss_warnings( jQuery( this ), 'warning' );
|
146 |
-
} );
|
147 |
-
jQuery( document ).on( 'click', '#mainwp-child-all-pages-warning-dismiss', function () {
|
148 |
-
return dismiss_warnings( jQuery( this ), 'conflict' );
|
149 |
-
} );
|
150 |
-
</script>
|
151 |
-
<style type="text/css">
|
152 |
-
.mainwp-child_info-box-red-warning {
|
153 |
-
background-color: rgba(187, 114, 57, 0.2) !important;
|
154 |
-
border-bottom: 4px solid #bb7239 !important;
|
155 |
-
border-top: 1px solid #bb7239 !important;
|
156 |
-
border-left: 1px solid #bb7239 !important;
|
157 |
-
border-right: 1px solid #bb7239 !important;
|
158 |
-
-webkit-border-radius: 3px;
|
159 |
-
-moz-border-radius: 3px;
|
160 |
-
border-radius: 3px;
|
161 |
-
margin: 1em 0 !important;
|
162 |
-
|
163 |
-
background-image: url( '<?php echo esc_url( plugins_url( 'images/mainwp-icon-orange.png', dirname( __FILE__ ) ) ); ?>' ) !important;
|
164 |
-
background-position: 1.5em 50% !important;
|
165 |
-
background-repeat: no-repeat !important;
|
166 |
-
background-size: 30px !important;
|
167 |
-
}
|
168 |
-
|
169 |
-
.mainwp-child_info-box-red-warning table {
|
170 |
-
background-color: rgba(187, 114, 57, 0) !important;
|
171 |
-
border: 0px;
|
172 |
-
padding-left: 4.5em;
|
173 |
-
background-position: 1.5em 50% !important;
|
174 |
-
background-repeat: no-repeat !important;
|
175 |
-
background-size: 30px !important;
|
176 |
-
}
|
177 |
-
</style>
|
178 |
-
|
179 |
-
<div class="updated mainwp-child_info-box-red-warning" id="mainwp-child_server_warnings">
|
180 |
-
<table id="mainwp-table" class="wp-list-table widefat" cellspacing="0">
|
181 |
-
<tbody id="the-sites-list" class="list:sites">
|
182 |
-
<?php
|
183 |
-
$warning = '';
|
184 |
-
if ( $warnings > 0 ) {
|
185 |
-
$warning .= '<tr><td colspan="2">This site may not connect to your dashboard or may have other issues. Check your <a href="options-general.php?page=mainwp_child_tab">MainWP server information page</a>.</td><td style="text-align: right;"><a href="#" id="mainwp-child-connect-warning-dismiss">Dismiss</a></td></tr>';
|
186 |
-
}
|
187 |
-
echo $warning;
|
188 |
-
?>
|
189 |
-
</tbody>
|
190 |
-
</table>
|
191 |
-
</div>
|
192 |
-
<?php
|
193 |
-
}
|
194 |
-
|
195 |
-
/**
|
196 |
-
* Method is_mainwp_pages()
|
197 |
-
*
|
198 |
-
* Get the current page and check it for "mainwp_".
|
199 |
-
*
|
200 |
-
* @return boolean ture|false.
|
201 |
-
*/
|
202 |
-
public static function is_mainwp_pages() {
|
203 |
-
$screen = get_current_screen();
|
204 |
-
if ( $screen && strpos( $screen->base, 'mainwp_' ) !== false && strpos( $screen->base, 'mainwp_child_tab' ) === false ) {
|
205 |
-
return true;
|
206 |
-
}
|
207 |
-
|
208 |
-
return false;
|
209 |
-
}
|
210 |
-
|
211 |
-
/**
|
212 |
-
* Render JavaScrip code for the Server Information page.
|
213 |
-
*
|
214 |
-
* @used-by MainWP_Child_Server_Information::render_page() Render the Server Information page.
|
215 |
-
*/
|
216 |
-
private static function render_page_js() {
|
217 |
-
?>
|
218 |
-
<script language="javascript">
|
219 |
-
|
220 |
-
/* FileSaver.js
|
221 |
-
* A saveAs() FileSaver implementation.
|
222 |
-
* 2013-01-23
|
223 |
-
*
|
224 |
-
* By Eli Grey, http://eligrey.com
|
225 |
-
* License: X11/MIT
|
226 |
-
* See LICENSE.md
|
227 |
-
*/
|
228 |
-
|
229 |
-
/*global self */
|
230 |
-
/*jslint bitwise: true, regexp: true, confusion: true, es5: true, vars: true, white: true, plusplus: true */
|
231 |
-
|
232 |
-
/*! @source http://purl.eligrey.com/github/FileSaver.js/blob/master/FileSaver.js */
|
233 |
-
|
234 |
-
var childSaveAs = childSaveAs
|
235 |
-
|| ( navigator.msSaveBlob && navigator.msSaveBlob.bind( navigator ) )
|
236 |
-
|| ( function( view ) {
|
237 |
-
"use strict";
|
238 |
-
var doc = view.document
|
239 |
-
, get_URL = function() {
|
240 |
-
return view.URL || view.webkitURL || view;
|
241 |
-
}
|
242 |
-
, URL = view.URL || view.webkitURL || view
|
243 |
-
, save_link = doc.createElementNS("http://www.w3.org/1999/xhtml", "a")
|
244 |
-
, can_use_save_link = "download" in save_link
|
245 |
-
, click = function(node) {
|
246 |
-
var event = doc.createEvent("MouseEvents");
|
247 |
-
event.initMouseEvent(
|
248 |
-
"click", true, false, view, 0, 0, 0, 0, 0
|
249 |
-
, false, false, false, false, 0, null
|
250 |
-
);
|
251 |
-
return node.dispatchEvent(event); // false if event was cancelled
|
252 |
-
}
|
253 |
-
, webkit_req_fs = view.webkitRequestFileSystem
|
254 |
-
, req_fs = view.requestFileSystem || webkit_req_fs || view.mozRequestFileSystem
|
255 |
-
, throw_outside = function (ex) {
|
256 |
-
(view.setImmediate || view.setTimeout)(function() {
|
257 |
-
throw ex;
|
258 |
-
}, 0);
|
259 |
-
}
|
260 |
-
, force_saveable_type = "application/octet-stream"
|
261 |
-
, fs_min_size = 0
|
262 |
-
, deletion_queue = []
|
263 |
-
, process_deletion_queue = function() {
|
264 |
-
var i = deletion_queue.length;
|
265 |
-
while (i--) {
|
266 |
-
var file = deletion_queue[i];
|
267 |
-
if (typeof file === "string") {
|
268 |
-
URL.revokeObjectURL(file);
|
269 |
-
} else {
|
270 |
-
file.remove();
|
271 |
-
}
|
272 |
-
}
|
273 |
-
deletion_queue.length = 0;
|
274 |
-
}
|
275 |
-
, dispatch = function(filesaver, event_types, event) {
|
276 |
-
event_types = [].concat(event_types);
|
277 |
-
var i = event_types.length;
|
278 |
-
while (i--) {
|
279 |
-
var listener = filesaver["on" + event_types[i]];
|
280 |
-
if (typeof listener === "function") {
|
281 |
-
try {
|
282 |
-
listener.call(filesaver, event || filesaver);
|
283 |
-
} catch (ex) {
|
284 |
-
throw_outside(ex);
|
285 |
-
}
|
286 |
-
}
|
287 |
-
}
|
288 |
-
}
|
289 |
-
, FileSaver = function( blob, name ) {
|
290 |
-
var
|
291 |
-
filesaver = this
|
292 |
-
, type = blob.type
|
293 |
-
, blob_changed = false
|
294 |
-
, object_url
|
295 |
-
, target_view
|
296 |
-
, get_object_url = function() {
|
297 |
-
var object_url = get_URL().createObjectURL(blob);
|
298 |
-
deletion_queue.push(object_url);
|
299 |
-
return object_url;
|
300 |
-
}
|
301 |
-
, dispatch_all = function() {
|
302 |
-
dispatch( filesaver, "writestart progress write writeend".split( " " ) );
|
303 |
-
}
|
304 |
-
, fs_error = function() {
|
305 |
-
if ( blob_changed || !object_url ) {
|
306 |
-
object_url = get_object_url( blob );
|
307 |
-
}
|
308 |
-
if (target_view) {
|
309 |
-
target_view.location.href = object_url;
|
310 |
-
}
|
311 |
-
filesaver.readyState = filesaver.DONE;
|
312 |
-
dispatch_all();
|
313 |
-
}
|
314 |
-
, abortable = function(func) {
|
315 |
-
return function() {
|
316 |
-
if (filesaver.readyState !== filesaver.DONE) {
|
317 |
-
return func.apply(this, arguments);
|
318 |
-
}
|
319 |
-
};
|
320 |
-
}
|
321 |
-
, create_if_not_found = {create: true, exclusive: false}
|
322 |
-
, slice
|
323 |
-
;
|
324 |
-
filesaver.readyState = filesaver.INIT;
|
325 |
-
if ( !name ) {
|
326 |
-
name = "download";
|
327 |
-
}
|
328 |
-
if ( can_use_save_link ) {
|
329 |
-
object_url = get_object_url( blob );
|
330 |
-
save_link.href = object_url;
|
331 |
-
save_link.download = name;
|
332 |
-
if ( click( save_link ) ) {
|
333 |
-
filesaver.readyState = filesaver.DONE;
|
334 |
-
dispatch_all();
|
335 |
-
return;
|
336 |
-
}
|
337 |
-
}
|
338 |
-
if ( view.chrome && type && type !== force_saveable_type ) {
|
339 |
-
slice = blob.slice || blob.webkitSlice;
|
340 |
-
blob = slice.call( blob, 0, blob.size, force_saveable_type );
|
341 |
-
blob_changed = true;
|
342 |
-
}
|
343 |
-
if (webkit_req_fs && name !== "download") {
|
344 |
-
name += ".download";
|
345 |
-
}
|
346 |
-
if ( type === force_saveable_type || webkit_req_fs ) {
|
347 |
-
target_view = view;
|
348 |
-
} else {
|
349 |
-
target_view = view.open();
|
350 |
-
}
|
351 |
-
if (!req_fs) {
|
352 |
-
fs_error();
|
353 |
-
return;
|
354 |
-
}
|
355 |
-
fs_min_size += blob.size;
|
356 |
-
req_fs(view.TEMPORARY, fs_min_size, abortable(function(fs) {
|
357 |
-
fs.root.getDirectory("saved", create_if_not_found, abortable(function(dir) {
|
358 |
-
var save = function() {
|
359 |
-
dir.getFile(name, create_if_not_found, abortable(function(file) {
|
360 |
-
file.createWriter(abortable(function(writer) {
|
361 |
-
writer.onwriteend = function(event) {
|
362 |
-
target_view.location.href = file.toURL();
|
363 |
-
deletion_queue.push(file);
|
364 |
-
filesaver.readyState = filesaver.DONE;
|
365 |
-
dispatch(filesaver, "writeend", event);
|
366 |
-
};
|
367 |
-
writer.onerror = function() {
|
368 |
-
var error = writer.error;
|
369 |
-
if (error.code !== error.ABORT_ERR) {
|
370 |
-
fs_error();
|
371 |
-
}
|
372 |
-
};
|
373 |
-
"writestart progress write abort".split(" ").forEach(function(event) {
|
374 |
-
writer["on" + event] = filesaver["on" + event];
|
375 |
-
});
|
376 |
-
writer.write(blob);
|
377 |
-
filesaver.abort = function() {
|
378 |
-
writer.abort();
|
379 |
-
filesaver.readyState = filesaver.DONE;
|
380 |
-
};
|
381 |
-
filesaver.readyState = filesaver.WRITING;
|
382 |
-
}), fs_error);
|
383 |
-
}), fs_error);
|
384 |
-
};
|
385 |
-
dir.getFile(name, {create: false}, abortable(function(file) {
|
386 |
-
file.remove();
|
387 |
-
save();
|
388 |
-
}), abortable(function(ex) {
|
389 |
-
if (ex.code === ex.NOT_FOUND_ERR) {
|
390 |
-
save();
|
391 |
-
} else {
|
392 |
-
fs_error();
|
393 |
-
}
|
394 |
-
}));
|
395 |
-
}), fs_error);
|
396 |
-
}), fs_error);
|
397 |
-
}
|
398 |
-
, FS_proto = FileSaver.prototype
|
399 |
-
, childSaveAs = function(blob, name) {
|
400 |
-
return new FileSaver(blob, name);
|
401 |
-
}
|
402 |
-
;
|
403 |
-
FS_proto.abort = function() {
|
404 |
-
var filesaver = this;
|
405 |
-
filesaver.readyState = filesaver.DONE;
|
406 |
-
dispatch(filesaver, "abort");
|
407 |
-
};
|
408 |
-
FS_proto.readyState = FS_proto.INIT = 0;
|
409 |
-
FS_proto.WRITING = 1;
|
410 |
-
FS_proto.DONE = 2;
|
411 |
-
|
412 |
-
FS_proto.error =
|
413 |
-
FS_proto.onwritestart =
|
414 |
-
FS_proto.onprogress =
|
415 |
-
FS_proto.onwrite =
|
416 |
-
FS_proto.onabort =
|
417 |
-
FS_proto.onerror =
|
418 |
-
FS_proto.onwriteend =
|
419 |
-
null;
|
420 |
-
|
421 |
-
view.addEventListener("unload", process_deletion_queue, false);
|
422 |
-
return childSaveAs;
|
423 |
-
}(self));
|
424 |
-
|
425 |
-
|
426 |
-
mwp_child_strCut = function(i,l,s,w) {
|
427 |
-
var o = i.toString();
|
428 |
-
if (!s) { s = '0'; }
|
429 |
-
while (o.length < parseInt(l)) {
|
430 |
-
if( w == 'undefined' ){
|
431 |
-
o = s + o;
|
432 |
-
}else{
|
433 |
-
o = o + s;
|
434 |
-
}
|
435 |
-
}
|
436 |
-
return o;
|
437 |
-
};
|
438 |
-
jQuery( document ).on( 'click', 'a.mwp-child-get-system-report-btn', function() {
|
439 |
-
var report = "";
|
440 |
-
jQuery( '.mwp_server_info_box thead, .mwp_server_info_box tbody' ).each( function() {
|
441 |
-
var td_len = [35, 55, 45, 12, 12];
|
442 |
-
var th_count = 0;
|
443 |
-
var i;
|
444 |
-
if ( jQuery( this ).is( 'thead' ) ) {
|
445 |
-
i = 0;
|
446 |
-
report = report + "\n### ";
|
447 |
-
th_count = jQuery( this ).find( 'th:not(".mwp-not-generate-row")' ).length;
|
448 |
-
jQuery( this ).find( 'th:not(".mwp-not-generate-row")' ).each( function() {
|
449 |
-
var len = td_len[i];
|
450 |
-
if ( i == 0 || i == th_count -1 )
|
451 |
-
len = len - 4;
|
452 |
-
report = report + mwp_child_strCut( jQuery.trim( jQuery( this ).text() ), len, ' ' );
|
453 |
-
i++;
|
454 |
-
} );
|
455 |
-
report = report + " ###\n\n";
|
456 |
-
} else {
|
457 |
-
jQuery( 'tr', jQuery( this ) ).each( function() {
|
458 |
-
if ( jQuery( this ).hasClass( 'mwp-not-generate-row' ) )
|
459 |
-
return;
|
460 |
-
i = 0;
|
461 |
-
jQuery( this ).find( 'td:not(".mwp-not-generate-row")' ).each( function() {
|
462 |
-
if (jQuery( this ).hasClass( 'mwp-hide-generate-row' ) ) {
|
463 |
-
report = report + mwp_child_strCut( ' ', td_len[i], ' ' );
|
464 |
-
i++;
|
465 |
-
return;
|
466 |
-
}
|
467 |
-
report = report + mwp_child_strCut( jQuery.trim( jQuery( this ).text() ), td_len[i], ' ' );
|
468 |
-
i++;
|
469 |
-
} );
|
470 |
-
report = report + "\n";
|
471 |
-
} );
|
472 |
-
}
|
473 |
-
} );
|
474 |
-
try {
|
475 |
-
jQuery( "#mwp-server-information" ).slideDown();
|
476 |
-
jQuery( "#mwp-server-information textarea" ).val( report ).focus().select();
|
477 |
-
jQuery( this ).fadeOut();
|
478 |
-
jQuery( '.mwp_child_close_srv_info' ).show();
|
479 |
-
return false;
|
480 |
-
} catch(e){ }
|
481 |
-
} );
|
482 |
-
|
483 |
-
jQuery( document ).on( 'click', 'a#mwp_child_close_srv_info', function() {
|
484 |
-
jQuery( '#mwp-server-information' ).hide();
|
485 |
-
jQuery( '.mwp_child_close_srv_info' ).hide();
|
486 |
-
jQuery( 'a.mwp-child-get-system-report-btn' ).show();
|
487 |
-
return false;
|
488 |
-
} );
|
489 |
-
jQuery( document ).on( 'click', '#mwp_child_download_srv_info', function() {
|
490 |
-
var server_info = jQuery( '#mwp-server-information textarea' ).val();
|
491 |
-
var blob = new Blob( [server_info], {type: "text/plain;charset=utf-8"} );
|
492 |
-
childSaveAs( blob, "server_child_information.txt" );
|
493 |
-
} );
|
494 |
-
</script>
|
495 |
-
<?php
|
496 |
-
}
|
497 |
-
|
498 |
-
/**
|
499 |
-
* Render the Server Information page.
|
500 |
-
*
|
501 |
-
* @uses MainWP_Child_Server_Information::render_page_js() Render JavaScrip code for the Server Information page.
|
502 |
-
* @uses MainWP_Child_Server_Information::render_server_infor() Render server information.
|
503 |
-
* @uses MainWP_Child_Server_Information::render_cron() Render cron schedules.
|
504 |
-
* @uses MainWP_Child_Server_Information::render_error_page() Render error log.
|
505 |
-
*/
|
506 |
-
public static function render_page() {
|
507 |
-
self::render_page_js();
|
508 |
-
?>
|
509 |
-
<style type="text/css">
|
510 |
-
#mwp-server-information {
|
511 |
-
display: none;
|
512 |
-
margin: 10px 0;
|
513 |
-
padding: 0;
|
514 |
-
position: relative;
|
515 |
-
}
|
516 |
-
|
517 |
-
#mwp-server-information textarea {
|
518 |
-
border-radius: 0;
|
519 |
-
font-family: monospace;
|
520 |
-
font-size: 12px;
|
521 |
-
height: 300px;
|
522 |
-
line-height: 20px;
|
523 |
-
margin: 0;
|
524 |
-
outline: 0 none;
|
525 |
-
padding: 20px;
|
526 |
-
resize: none;
|
527 |
-
width: 100%;
|
528 |
-
-moz-border-radius:0;
|
529 |
-
-webkit-border-radius:0;
|
530 |
-
}
|
531 |
-
|
532 |
-
.mwp_child_close_srv_info {
|
533 |
-
display: none;
|
534 |
-
float: right;
|
535 |
-
margin: 5px 0 5px;
|
536 |
-
}
|
537 |
-
</style>
|
538 |
-
<div class="wrap">
|
539 |
-
<div class="updated below-h2">
|
540 |
-
<p><?php esc_html_e( 'Please include this information when requesting support:', 'mainwp-child' ); ?></p>
|
541 |
-
<span class="mwp_child_close_srv_info">
|
542 |
-
<a href="#" id="mwp_child_download_srv_info"><?php esc_html_e( 'Download', 'mainwp-child' ); ?></a> | <a href="#" id="mwp_child_close_srv_info"><i class="fa fa-eye-slash"></i> <?php _e( 'Hide', 'mainwp-child' ); ?></a>
|
543 |
-
</span>
|
544 |
-
<p class="submit">
|
545 |
-
<a class="button-primary mwp-child-get-system-report-btn" href="#"><?php esc_html_e( 'Get system report', 'mainwp-child' ); ?></a>
|
546 |
-
</p>
|
547 |
-
<div id="mwp-server-information"><textarea readonly="readonly" wrap="off"></textarea></div>
|
548 |
-
</div>
|
549 |
-
<br/>
|
550 |
-
<div class="mwp_server_info_box">
|
551 |
-
<h2><?php esc_html_e( 'Server Information', 'mainwp-child' ); ?></h2>
|
552 |
-
<?php self::render_server_infor(); ?>
|
553 |
-
<h2><?php esc_html_e( 'Cron Schedules', 'mainwp-child' ); ?></h2>
|
554 |
-
<?php self::render_cron(); ?>
|
555 |
-
<h2><?php esc_html_e( 'Error Log', 'mainwp-child' ); ?></h2>
|
556 |
-
<?php self::render_error_page(); ?>
|
557 |
-
</div>
|
558 |
-
</div>
|
559 |
-
<?php
|
560 |
-
}
|
561 |
-
|
562 |
-
/**
|
563 |
-
* Render server information content.
|
564 |
-
*
|
565 |
-
* @uses MainWP_Child_Server_Information::render_system_infor_rows() Render system information rows.
|
566 |
-
* @uses MainWP_Child_Server_Information::render_php_settings_rows() Render PHP settings information rows.
|
567 |
-
* @uses MainWP_Child_Server_Information::render_mysql_infor_rows() Render MySQL settings information rows.
|
568 |
-
* @uses MainWP_Child_Server_Information::render_server_infor_rows() Render server settings information rows.
|
569 |
-
* @uses MainWP_Child_Server_Information::render_php_infor_rows() Render PHP information rows.
|
570 |
-
* @uses MainWP_Child_Server_Information::render_plugins_infor_rows() Render plugins information rows.
|
571 |
-
*
|
572 |
-
* @used-by MainWP_Child_Server_Information::render_page() Render the Server Information page.
|
573 |
-
*
|
574 |
-
* @uses \MainWP\Child\MainWP_Child_Branding::get_branding_title()
|
575 |
-
*/
|
576 |
-
private static function render_server_infor() {
|
577 |
-
$branding_title = MainWP_Child_Branding::instance()->get_branding_title();
|
578 |
-
if ( '' == $branding_title ) {
|
579 |
-
$branding_title = 'MainWP Child';
|
580 |
-
}
|
581 |
-
?>
|
582 |
-
<table id="mainwp-table" class="wp-list-table widefat" cellspacing="0">
|
583 |
-
<thead>
|
584 |
-
<tr>
|
585 |
-
<th scope="col" class="manage-column column-posts mwp-not-generate-row" style="width: 1px;"></th>
|
586 |
-
<th scope="col" class="manage-column column-posts"><span><?php esc_html_e( 'Server configuration', 'mainwp-child' ); ?></span></th>
|
587 |
-
<th scope="col" class="manage-column column-posts"><?php esc_html_e( 'Required value', 'mainwp-child' ); ?></th>
|
588 |
-
<th scope="col" class="manage-column column-posts"><?php esc_html_e( 'Value', 'mainwp-child' ); ?></th>
|
589 |
-
<th scope="col" class="manage-column column-posts"><?php esc_html_e( 'Status', 'mainwp-child' ); ?></th>
|
590 |
-
</tr>
|
591 |
-
</thead>
|
592 |
-
<tbody id="the-sites-list" class="list:sites">
|
593 |
-
<?php self::render_system_infor_rows( $branding_title ); ?>
|
594 |
-
<?php self::render_php_settings_rows(); ?>
|
595 |
-
<?php self::render_mysql_infor_rows(); ?>
|
596 |
-
<?php self::render_server_infor_rows(); ?>
|
597 |
-
<?php self::render_php_infor_rows(); ?>
|
598 |
-
<?php self::render_plugins_infor_rows( $branding_title ); ?>
|
599 |
-
</tbody>
|
600 |
-
</table>
|
601 |
-
<br/>
|
602 |
-
<?php
|
603 |
-
}
|
604 |
-
|
605 |
-
/**
|
606 |
-
* Render system information rows.
|
607 |
-
*
|
608 |
-
* @param string $branding_title Custom branding plgin title.
|
609 |
-
*
|
610 |
-
* @uses MainWP_Child_Server_Information_Base::get_mainwp_version() Get the MainWP Child plugin version number.
|
611 |
-
* @uses MainWP_Child_Server_Information_Base::get_current_version() Get the current MainWP Child plugin version.
|
612 |
-
* @uses MainWP_Child_Server_Information_Base::get_file_system_method() Get file system method.
|
613 |
-
* @uses MainWP_Child_Server_Information::render_file_system_method_check() Render the file system method check.
|
614 |
-
* @uses MainWP_Child_Server_Information::render_mainwp_version_check() Render the MainWP version check row.
|
615 |
-
* @uses MainWP_Child_Server_Information::render_row() Render the server information row.
|
616 |
-
* @uses get_option() Retrieves an option value based on an option name.
|
617 |
-
* @see https://developer.wordpress.org/reference/functions/get_option/
|
618 |
-
*
|
619 |
-
* @used-by MainWP_Child_Server_Information::render_server_infor() Render server information content.
|
620 |
-
*/
|
621 |
-
private static function render_system_infor_rows( $branding_title ) {
|
622 |
-
?>
|
623 |
-
<tr>
|
624 |
-
<td style="background: #333; color: #fff;" colspan="5"><?php echo esc_html( strtoupper( stripslashes( $branding_title ) ) ); ?></td>
|
625 |
-
</tr>
|
626 |
-
<tr>
|
627 |
-
<td></td>
|
628 |
-
<td><?php echo esc_html( stripslashes( $branding_title ) ) . ' ' . __( 'Version', 'mainwp-chil' ); ?></td>
|
629 |
-
<td><?php echo esc_html( self::get_mainwp_version() ); ?></td>
|
630 |
-
<td><?php echo esc_html( self::get_current_version() ); ?></td>
|
631 |
-
<td><?php echo esc_html( self::render_mainwp_version_check() ); ?></td>
|
632 |
-
</tr>
|
633 |
-
<?php self::render_mainwp_directory(); ?>
|
634 |
-
<tr>
|
635 |
-
<td style="background: #333; color: #fff;" colspan="5"><?php esc_html_e( 'WordPress', 'mainwp-child' ); ?></td>
|
636 |
-
</tr>
|
637 |
-
<?php self::render_row( 'WordPress Version', '>=', '3.4', 'get_wordpress_version' ); ?>
|
638 |
-
<?php self::render_row( 'WordPress Memory Limit', '>=', '64M', 'get_wordpress_memory_limit' ); ?>
|
639 |
-
<?php self::render_row( 'MultiSite Disabled', '=', true, 'check_if_multisite' ); ?>
|
640 |
-
<tr>
|
641 |
-
<td></td>
|
642 |
-
<td><?php esc_html_e( 'FileSystem Method', 'mainwp-child' ); ?></td>
|
643 |
-
<td><?php echo esc_html( '= direct' ); ?></td>
|
644 |
-
<td><?php echo esc_html( self::get_file_system_method() ); ?></td>
|
645 |
-
<td><?php echo esc_html( self::render_file_system_method_check() ); ?></td>
|
646 |
-
</tr>
|
647 |
-
<?php
|
648 |
-
}
|
649 |
-
|
650 |
-
/**
|
651 |
-
* Render the file system method check.
|
652 |
-
*
|
653 |
-
* @uses MainWP_Child_Server_Information_Base::get_file_system_method() Get file system method.
|
654 |
-
*
|
655 |
-
* @used-by MainWP_Child_Server_Information::render_system_infor_rows() Render system information rows.
|
656 |
-
*/
|
657 |
-
protected static function render_file_system_method_check() {
|
658 |
-
$fsmethod = self::get_file_system_method();
|
659 |
-
if ( 'direct' === $fsmethod ) {
|
660 |
-
echo '<span class="mainwp-pass"><i class="fa fa-check-circle"></i> Pass</span>';
|
661 |
-
} else {
|
662 |
-
echo '<span class="mainwp-warning"><i class="fa fa-exclamation-circle"></i> Warning</span>';
|
663 |
-
}
|
664 |
-
}
|
665 |
-
|
666 |
-
/**
|
667 |
-
* Render PHP settings information rows.
|
668 |
-
*
|
669 |
-
* @uses MainWP_Child_Server_Information::render_row() Render the server information row.
|
670 |
-
* @uses MainWP_Child_Server_Information::render_row_sec() Render the server information secondary row.
|
671 |
-
* @uses MainWP_Child_Server_Information_Base::get_php_safe_mode() Check if PHP is in Safe Mode.
|
672 |
-
*
|
673 |
-
* @used-by MainWP_Child_Server_Information::render_system_infor_rows() Render system information rows.
|
674 |
-
*/
|
675 |
-
private static function render_php_settings_rows() {
|
676 |
-
?>
|
677 |
-
<tr>
|
678 |
-
<td style="background: #333; color: #fff;"
|
679 |
-
colspan="5"><?php esc_html_e( 'PHP SETTINGS', 'mainwp-child' ); ?></td>
|
680 |
-
</tr>
|
681 |
-
<?php self::render_row( 'PHP Version', '>=', '5.6', 'get_php_version' ); ?>
|
682 |
-
<tr>
|
683 |
-
<td></td>
|
684 |
-
<td><?php esc_html_e( 'PHP Safe Mode Disabled', 'mainwp-child' ); ?></td>
|
685 |
-
<td colspan="3"><?php self::get_php_safe_mode(); ?></td>
|
686 |
-
</tr>
|
687 |
-
<?php
|
688 |
-
self::render_row_sec( 'PHP Max Execution Time', '>=', '30', 'get_max_execution_time', 'seconds', '=', '0' );
|
689 |
-
self::render_row_sec( 'PHP Max Input Time', '>=', '30', 'get_max_input_time', 'seconds', '=', '0' );
|
690 |
-
self::render_row( 'PHP Memory Limit', '>=', '128M', 'get_php_memory_limit', '(256M+ best for big backups)', null, null, true );
|
691 |
-
self::render_row( 'PCRE Backtracking Limit', '>=', '10000', 'get_output_buffer_size' );
|
692 |
-
self::render_row( 'PHP Upload Max Filesize', '>=', '2M', 'get_upload_max_filesize', '(2MB+ best for upload of big plugins)', null, null, true );
|
693 |
-
self::render_row( 'PHP Post Max Size', '>=', '2M', 'get_post_max_size', '(2MB+ best for upload of big plugins)', null, null, true );
|
694 |
-
self::render_row( 'SSL Extension Enabled', '=', true, 'get_ssl_support' );
|
695 |
-
self::render_row_sec( 'SSL Warnings', '=', '', 'get_ssl_warning', 'empty', '' );
|
696 |
-
self::render_row_sec( 'cURL Extension Enabled', '=', true, 'get_curl_support', '', '', null, '', null, self::ERROR );
|
697 |
-
self::render_row_sec( 'cURL Timeout', '>=', '300', 'get_curl_timeout', 'seconds', '=', '0' );
|
698 |
-
if ( function_exists( 'curl_version' ) ) {
|
699 |
-
self::render_row_sec( 'cURL Version', '>=', '7.18.1', 'get_curl_version', '', '', null );
|
700 |
-
$openssl_version = 'OpenSSL/1.1.0';
|
701 |
-
self::render_row_sec(
|
702 |
-
'cURL SSL Version',
|
703 |
-
'>=',
|
704 |
-
$openssl_version,
|
705 |
-
'get_curl_ssl_version',
|
706 |
-
'',
|
707 |
-
'',
|
708 |
-
null,
|
709 |
-
'',
|
710 |
-
'curlssl'
|
711 |
-
);
|
712 |
-
if ( ! self::curlssl_compare( $openssl_version, '>=' ) ) {
|
713 |
-
echo "<tr style=\"background:#fffaf3\"><td colspan='5'><span class=\"mainwp-warning\"><i class='fa fa-exclamation-circle'>" . sprintf( __( 'Your host needs to update OpenSSL to at least version 1.1.0 which is already over 4 years old and contains patches for over 60 vulnerabilities.%1$sThese range from Denial of Service to Remote Code Execution. %2$sClick here for more information.%3$s', 'mainwp' ), '<br/>', '<a href="https://community.letsencrypt.org/t/openssl-client-compatibility-changes-for-let-s-encrypt-certificates/143816" target="_blank">', '</a>' ) . '</span></td></tr>';
|
714 |
-
}
|
715 |
-
}
|
716 |
-
}
|
717 |
-
|
718 |
-
/**
|
719 |
-
* Render MySQL settings information rows.
|
720 |
-
*
|
721 |
-
* @uses MainWP_Child_Server_Information::render_row() Render the server information row.
|
722 |
-
*
|
723 |
-
* @used-by MainWP_Child_Server_Information::render_server_infor() Render server information content.
|
724 |
-
*/
|
725 |
-
private static function render_mysql_infor_rows() {
|
726 |
-
?>
|
727 |
-
<tr>
|
728 |
-
<td style="background: #333; color: #fff;" colspan="5"><?php esc_html_e( 'MySQL SETTINGS', 'mainwp-child' ); ?></td>
|
729 |
-
</tr>
|
730 |
-
<?php self::render_row( 'MySQL Version', '>=', '5.0', 'get_my_sql_version' ); ?>
|
731 |
-
<tr>
|
732 |
-
<td style="background: #333; color: #fff;" colspan="5"><?php esc_html_e( 'BACKUP ARCHIVE INFORMATION', 'mainwp-child' ); ?></td>
|
733 |
-
</tr>
|
734 |
-
<?php self::render_row( 'ZipArchive enabled in PHP', '=', true, 'get_zip_archive_enabled' ); ?>
|
735 |
-
<?php self::render_row( 'Tar GZip supported', '=', true, 'get_gzip_enabled' ); ?>
|
736 |
-
<?php self::render_row( 'Tar BZip2 supported', '=', true, 'get_bzip_enabled' ); ?>
|
737 |
-
<?php
|
738 |
-
}
|
739 |
-
|
740 |
-
/**
|
741 |
-
* Render plugins information rows.
|
742 |
-
*
|
743 |
-
* @param string $branding_title Custom branding plugin title.
|
744 |
-
*
|
745 |
-
* @uses get_plugins() Check the plugins directory and retrieve all plugin files with plugin data.
|
746 |
-
* @see https://developer.wordpress.org/reference/functions/get_plugins/
|
747 |
-
*
|
748 |
-
* @uses is_plugin_active() Determines whether a plugin is active.
|
749 |
-
* @see https://developer.wordpress.org/reference/functions/get_plugins/
|
750 |
-
*
|
751 |
-
* @used-by MainWP_Child_Server_Information::render_server_infor() Render server information content.
|
752 |
-
*/
|
753 |
-
private static function render_plugins_infor_rows( $branding_title ) {
|
754 |
-
?>
|
755 |
-
<tr>
|
756 |
-
<td style="background: #333; color: #fff;" colspan="5"><?php _e( 'WordPress PLUGINS', 'mainwp-child' ); ?></td>
|
757 |
-
</tr>
|
758 |
-
<?php
|
759 |
-
$all_plugins = get_plugins();
|
760 |
-
foreach ( $all_plugins as $slug => $plugin ) {
|
761 |
-
if ( ! empty( $branding_title ) && ( 'mainwp-child/mainwp-child.php' == $slug || 'mainwp-child-reports/mainwp-child-reports.php' == $slug ) ) {
|
762 |
-
if ( 'mainwp-child/mainwp-child.php' == $slug ) {
|
763 |
-
$plugin['Name'] = esc_html( stripslashes( $branding_title ) );
|
764 |
-
} elseif ( 'mainwp-child-reports/mainwp-child-reports.php' == $slug ) {
|
765 |
-
$plugin['Name'] = esc_html( stripslashes( $branding_title ) ) . ' reports';
|
766 |
-
}
|
767 |
-
}
|
768 |
-
?>
|
769 |
-
<tr>
|
770 |
-
<td></td>
|
771 |
-
<td><?php echo esc_html( $plugin['Name'] ); ?></td>
|
772 |
-
<td><?php echo esc_html( $plugin['Version'] ); ?></td>
|
773 |
-
<td><?php echo is_plugin_active( $slug ) ? __( 'Active', 'mainwp-child' ) : __( 'Inactive', 'mainwp-child' ); ?></td>
|
774 |
-
<td></td>
|
775 |
-
</tr>
|
776 |
-
<?php
|
777 |
-
}
|
778 |
-
}
|
779 |
-
|
780 |
-
/**
|
781 |
-
* Render PHP information rows.
|
782 |
-
*
|
783 |
-
* @uses MainWP_Child_Server_Information_Base::get_php_allow_url_fopen() Check if PHP Allow URL fopen is enabled.
|
784 |
-
* @uses MainWP_Child_Server_Information_Base::get_php_exif() Check if PHP exif is enabled.
|
785 |
-
* @uses MainWP_Child_Server_Information_Base::get_php_ip_tc() Check if PHP IP TC is enabled.
|
786 |
-
* @uses MainWP_Child_Server_Information_Base::get_php_xml() Check if PHP XML is enabled.
|
787 |
-
* @uses MainWP_Child_Server_Information_Base::mainwp_required_functions() Check for disabled PHP functions.
|
788 |
-
* @uses MainWP_Child_Server_Information_Base::get_loaded_php_extensions() Get loaded PHP extensions.
|
789 |
-
* @uses MainWP_Child_Server_Information_Base::get_sql_mode() Get current SQL mode.
|
790 |
-
*
|
791 |
-
* @used-by MainWP_Child_Server_Information::render_server_infor() Render server information content.
|
792 |
-
*/
|
793 |
-
private static function render_php_infor_rows() {
|
794 |
-
?>
|
795 |
-
<tr>
|
796 |
-
<td style="background: #333; color: #fff;" colspan="5"><?php esc_html_e( 'PHP INFORMATION', 'mainwp-child' ); ?></td>
|
797 |
-
</tr>
|
798 |
-
<tr>
|
799 |
-
<td></td>
|
800 |
-
<td><?php esc_html_e( 'PHP Allow URL fopen', 'mainwp-child' ); ?></td>
|
801 |
-
<td colspan="3"><?php self::get_php_allow_url_fopen(); ?></td>
|
802 |
-
</tr>
|
803 |
-
<tr>
|
804 |
-
<td></td>
|
805 |
-
<td><?php esc_html_e( 'PHP Exif Support', 'mainwp-child' ); ?></td>
|
806 |
-
<td colspan="3"><?php self::get_php_exif(); ?></td>
|
807 |
-
</tr>
|
808 |
-
<tr>
|
809 |
-
<td></td>
|
810 |
-
<td><?php esc_html_e( 'PHP IPTC Support', 'mainwp-child' ); ?></td>
|
811 |
-
<td colspan="3"><?php self::get_php_ip_tc(); ?></td>
|
812 |
-
</tr>
|
813 |
-
<tr>
|
814 |
-
<td></td>
|
815 |
-
<td><?php esc_html_e( 'PHP XML Support', 'mainwp-child' ); ?></td>
|
816 |
-
<td colspan="3"><?php self::get_php_xml(); ?></td>
|
817 |
-
</tr>
|
818 |
-
<tr>
|
819 |
-
<td></td>
|
820 |
-
<td><?php esc_html_e( 'PHP Disabled Functions', 'mainwp-child' ); ?></td>
|
821 |
-
<td colspan="3"><?php self::mainwp_required_functions(); ?></td>
|
822 |
-
</tr>
|
823 |
-
<tr>
|
824 |
-
<td></td>
|
825 |
-
<td><?php esc_html_e( 'PHP Loaded Extensions', 'mainwp-child' ); ?></td>
|
826 |
-
<td colspan="3" style="width: 73% !important;"><?php self::get_loaded_php_extensions(); ?></td>
|
827 |
-
</tr>
|
828 |
-
<tr>
|
829 |
-
<td style="background: #333; color: #fff;"
|
830 |
-
colspan="5"><?php esc_html_e( 'MySQL INFORMATION', 'mainwp-child' ); ?></td>
|
831 |
-
</tr>
|
832 |
-
<tr>
|
833 |
-
<td></td>
|
834 |
-
<td><?php esc_html_e( 'MySQL Mode', 'mainwp-child' ); ?></td>
|
835 |
-
<td colspan="3"><?php self::get_sql_mode(); ?></td>
|
836 |
-
</tr>
|
837 |
-
<tr>
|
838 |
-
<td></td>
|
839 |
-
<td><?php esc_html_e( 'MySQL Client Encoding', 'mainwp-child' ); ?></td>
|
840 |
-
<td colspan="3"><?php echo esc_html( defined( 'DB_CHARSET' ) ? DB_CHARSET : '' ); ?></td>
|
841 |
-
</tr>
|
842 |
-
<?php
|
843 |
-
}
|
844 |
-
|
845 |
-
/**
|
846 |
-
* Render server settings information rows.
|
847 |
-
*
|
848 |
-
* @uses MainWP_Child_Server_Information_Base::get_wp_root() Get WordPress root directory.
|
849 |
-
* @uses MainWP_Child_Server_Information_Base::get_server_name()Get server name.
|
850 |
-
* @uses MainWP_Child_Server_Information_Base::get_server_software() Get server software.
|
851 |
-
* @uses MainWP_Child_Server_Information_Base::get_os() Get operating system.
|
852 |
-
* @uses MainWP_Child_Server_Information_Base::get_architecture() Get System architecture.
|
853 |
-
* @uses MainWP_Child_Server_Information_Base::get_server_ip() Get server IP.
|
854 |
-
* @uses MainWP_Child_Server_Information_Base::get_server_protocol() Get server protocol.
|
855 |
-
* @uses MainWP_Child_Server_Information_Base::get_http_host() Get server HTTP host.
|
856 |
-
* @uses MainWP_Child_Server_Information_Base::get_https() Check if HTTPS is on.
|
857 |
-
* @uses MainWP_Child_Server_Information_Base::server_self_connect() Server self-connection test.
|
858 |
-
* @uses MainWP_Child_Server_Information_Base::get_user_agent() Get server user agent.
|
859 |
-
* @uses MainWP_Child_Server_Information_Base::get_server_port() Get server port.
|
860 |
-
* @uses MainWP_Child_Server_Information_Base::get_server_getaway_interface() Get current server gateway interface.
|
861 |
-
* @uses MainWP_Child_Server_Information_Base::memory_usage() Get the current Memory usage.
|
862 |
-
* @uses MainWP_Child_Server_Information_Base::get_complete_url() Get server complete URL.
|
863 |
-
* @uses MainWP_Child_Server_Information_Base::get_server_request_time() Get server request time.
|
864 |
-
* @uses MainWP_Child_Server_Information_Base::get_server_http_accept() Get server HTTP accept.
|
865 |
-
* @uses MainWP_Child_Server_Information_Base::get_server_accept_charset() Get server accepted charset.
|
866 |
-
* @uses MainWP_Child_Server_Information_Base::get_script_file_name() Get server script filename.
|
867 |
-
* @uses MainWP_Child_Server_Information_Base::get_current_page_uri() Get current page URL.
|
868 |
-
* @uses MainWP_Child_Server_Information_Base::get_remote_address() Get server remote address.
|
869 |
-
* @uses MainWP_Child_Server_Information_Base::get_remote_host() Get server remote host.
|
870 |
-
* @uses MainWP_Child_Server_Information_Base::get_remote_port() Get server remote port.
|
871 |
-
*
|
872 |
-
* @used-by MainWP_Child_Server_Information::render_server_infor() Render server information content.
|
873 |
-
*/
|
874 |
-
private static function render_server_infor_rows() {
|
875 |
-
?>
|
876 |
-
<tr>
|
877 |
-
<td style="background: #333; color: #fff;" colspan="5"><?php esc_html_e( 'SERVER INFORMATION', 'mainwp-child' ); ?></td>
|
878 |
-
</tr>
|
879 |
-
<tr>
|
880 |
-
<td></td>
|
881 |
-
<td><?php esc_html_e( 'WordPress Root Directory', 'mainwp-child' ); ?></td>
|
882 |
-
<td colspan="3"><?php self::get_wp_root(); ?></td>
|
883 |
-
</tr>
|
884 |
-
<tr>
|
885 |
-
<td></td>
|
886 |
-
<td><?php esc_html_e( 'Server Name', 'mainwp-child' ); ?></td>
|
887 |
-
<td colspan="3"><?php self::get_server_name(); ?></td>
|
888 |
-
</tr>
|
889 |
-
<tr>
|
890 |
-
<td></td>
|
891 |
-
<td><?php esc_html_e( 'Server Software', 'mainwp-child' ); ?></td>
|
892 |
-
<td colspan="3"><?php self::get_server_software(); ?></td>
|
893 |
-
</tr>
|
894 |
-
<tr>
|
895 |
-
<td></td>
|
896 |
-
<td><?php esc_html_e( 'Operating System', 'mainwp-child' ); ?></td>
|
897 |
-
<td colspan="3"><?php self::get_os(); ?></td>
|
898 |
-
</tr>
|
899 |
-
<tr>
|
900 |
-
<td></td>
|
901 |
-
<td><?php esc_html_e( 'Architecture', 'mainwp-child' ); ?></td>
|
902 |
-
<td colspan="3"><?php self::get_architecture(); ?></td>
|
903 |
-
</tr>
|
904 |
-
<tr>
|
905 |
-
<td></td>
|
906 |
-
<td><?php esc_html_e( 'Server IP', 'mainwp-child' ); ?></td>
|
907 |
-
<td colspan="3"><?php self::get_server_ip(); ?></td>
|
908 |
-
</tr>
|
909 |
-
<tr>
|
910 |
-
<td></td>
|
911 |
-
<td><?php esc_html_e( 'Server Protocol', 'mainwp-child' ); ?></td>
|
912 |
-
<td colspan="3"><?php self::get_server_protocol(); ?></td>
|
913 |
-
</tr>
|
914 |
-
<tr>
|
915 |
-
<td></td>
|
916 |
-
<td><?php esc_html_e( 'HTTP Host', 'mainwp-child' ); ?></td>
|
917 |
-
<td colspan="3"><?php self::get_http_host(); ?></td>
|
918 |
-
</tr>
|
919 |
-
<tr>
|
920 |
-
<td></td>
|
921 |
-
<td><?php esc_html_e( 'HTTPS', 'mainwp-child' ); ?></td>
|
922 |
-
<td colspan="3"><?php self::get_https(); ?></td>
|
923 |
-
</tr>
|
924 |
-
<tr>
|
925 |
-
<td></td>
|
926 |
-
<td><?php esc_html_e( 'Server self connect', 'mainwp-child' ); ?></td>
|
927 |
-
<td colspan="3"><?php self::server_self_connect(); ?></td>
|
928 |
-
</tr>
|
929 |
-
<tr>
|
930 |
-
<td></td>
|
931 |
-
<td><?php esc_html_e( 'User Agent', 'mainwp-child' ); ?></td>
|
932 |
-
<td colspan="3"><?php self::get_user_agent(); ?></td>
|
933 |
-
</tr>
|
934 |
-
<tr>
|
935 |
-
<td></td>
|
936 |
-
<td><?php esc_html_e( 'Server Port', 'mainwp-child' ); ?></td>
|
937 |
-
<td colspan="3"><?php self::get_server_port(); ?></td>
|
938 |
-
</tr>
|
939 |
-
<tr>
|
940 |
-
<td></td>
|
941 |
-
<td><?php esc_html_e( 'Gateway Interface', 'mainwp-child' ); ?></td>
|
942 |
-
<td colspan="3"><?php self::get_server_getaway_interface(); ?></td>
|
943 |
-
</tr>
|
944 |
-
<tr>
|
945 |
-
<td></td>
|
946 |
-
<td><?php esc_html_e( 'Memory Usage', 'mainwp-child' ); ?></td>
|
947 |
-
<td colspan="3"><?php self::memory_usage(); ?></td>
|
948 |
-
</tr>
|
949 |
-
<tr>
|
950 |
-
<td></td>
|
951 |
-
<td><?php esc_html_e( 'Complete URL', 'mainwp-child' ); ?></td>
|
952 |
-
<td colspan="3"><?php self::get_complete_url(); ?></td>
|
953 |
-
</tr>
|
954 |
-
<tr>
|
955 |
-
<td></td>
|
956 |
-
<td><?php esc_html_e( 'Request Time', 'mainwp-child' ); ?></td>
|
957 |
-
<td colspan="3"><?php self::get_server_request_time(); ?></td>
|
958 |
-
</tr>
|
959 |
-
<tr>
|
960 |
-
<td></td>
|
961 |
-
<td><?php esc_html_e( 'Accept Content', 'mainwp-child' ); ?></td>
|
962 |
-
<td colspan="3"><?php self::get_server_http_accept(); ?></td>
|
963 |
-
</tr>
|
964 |
-
<tr>
|
965 |
-
<td></td>
|
966 |
-
<td><?php esc_html_e( 'Accept-Charset Content', 'mainwp-child' ); ?></td>
|
967 |
-
<td colspan="3"><?php self::get_server_accept_charset(); ?></td>
|
968 |
-
</tr>
|
969 |
-
<tr>
|
970 |
-
<td></td>
|
971 |
-
<td><?php esc_html_e( 'Currently Executing Script Pathname', 'mainwp-child' ); ?></td>
|
972 |
-
<td colspan="3"><?php self::get_script_file_name(); ?></td>
|
973 |
-
</tr>
|
974 |
-
<tr>
|
975 |
-
<td></td>
|
976 |
-
<td><?php esc_html_e( 'Current Page URI', 'mainwp-child' ); ?></td>
|
977 |
-
<td colspan="3"><?php self::get_current_page_uri(); ?></td>
|
978 |
-
</tr>
|
979 |
-
<tr>
|
980 |
-
<td></td>
|
981 |
-
<td><?php esc_html_e( 'Remote Address', 'mainwp-child' ); ?></td>
|
982 |
-
<td colspan="3"><?php self::get_remote_address(); ?></td>
|
983 |
-
</tr>
|
984 |
-
<tr>
|
985 |
-
<td></td>
|
986 |
-
<td><?php esc_html_e( 'Remote Host', 'mainwp-child' ); ?></td>
|
987 |
-
<td colspan="3"><?php self::get_remote_host(); ?></td>
|
988 |
-
</tr>
|
989 |
-
<tr>
|
990 |
-
<td></td>
|
991 |
-
<td><?php esc_html_e( 'Remote Port', 'mainwp-child' ); ?></td>
|
992 |
-
<td colspan="3"><?php self::get_remote_port(); ?></td>
|
993 |
-
</tr>
|
994 |
-
<?php
|
995 |
-
}
|
996 |
-
|
997 |
-
/**
|
998 |
-
* Render the MainWP version check.
|
999 |
-
*
|
1000 |
-
* @uses MainWP_Child_Server_Information_Base::get_mainwp_version() Get the current MainWP Child plugin version.
|
1001 |
-
*
|
1002 |
-
* @uses get_option() Retrieves an option value based on an option name.
|
1003 |
-
* @see https://developer.wordpress.org/reference/functions/get_option/
|
1004 |
-
*
|
1005 |
-
* @used-by MainWP_Child_Server_Information::render_system_infor_rows() Render system information rows.
|
1006 |
-
*/
|
1007 |
-
protected static function render_mainwp_version_check() {
|
1008 |
-
$current = get_option( 'mainwp_child_plugin_version' );
|
1009 |
-
$latest = self::get_mainwp_version();
|
1010 |
-
if ( $current === $latest ) {
|
1011 |
-
echo '<span class="mainwp-pass"><i class="fa fa-check-circle"></i> Pass</span>';
|
1012 |
-
} else {
|
1013 |
-
echo '<span class="mainwp-warning"><i class="fa fa-exclamation-circle"></i> Warning</span>';
|
1014 |
-
}
|
1015 |
-
}
|
1016 |
-
|
1017 |
-
/**
|
1018 |
-
* Render cron schedules.
|
1019 |
-
*
|
1020 |
-
* @uses _get_cron_array() Retrieve cron info array option.
|
1021 |
-
* @see https://developer.wordpress.org/reference/functions/_get_cron_array/
|
1022 |
-
*
|
1023 |
-
* @uses wp_get_schedules() Retrieve supported event recurrence schedules.
|
1024 |
-
* @see https://developer.wordpress.org/reference/functions/wp_get_schedules/
|
1025 |
-
*
|
1026 |
-
* @uses \MainWP\Child\MainWP_Helper::format_timestamp() Format timestamp as per the WordPress general settings.
|
1027 |
-
*
|
1028 |
-
* @used-by \MainWP\Child\MainWP_Child_Server_Information::render_page() Render the Server Information page.
|
1029 |
-
*/
|
1030 |
-
private static function render_cron() {
|
1031 |
-
$cron_array = _get_cron_array();
|
1032 |
-
$schedules = wp_get_schedules();
|
1033 |
-
?>
|
1034 |
-
<table id="mainwp-table" class="wp-list-table widefat" cellspacing="0">
|
1035 |
-
<thead>
|
1036 |
-
<tr>
|
1037 |
-
<th scope="col" class="manage-column column-posts"><span><?php esc_html_e( 'Next due', 'mainwp-child' ); ?></span></th>
|
1038 |
-
<th scope="col" class="manage-column column-posts"><span><?php esc_html_e( 'Schedule', 'mainwp-child' ); ?></span></th>
|
1039 |
-
<th scope="col" class="manage-column column-posts"><span><?php esc_html_e( 'Hook', 'mainwp-child' ); ?></span></th>
|
1040 |
-
</tr>
|
1041 |
-
</thead>
|
1042 |
-
<tbody id="the-sites-list" class="list:sites">
|
1043 |
-
<?php
|
1044 |
-
foreach ( $cron_array as $time => $cron ) {
|
1045 |
-
foreach ( $cron as $hook => $cron_info ) {
|
1046 |
-
foreach ( $cron_info as $key => $schedule ) {
|
1047 |
-
?>
|
1048 |
-
<tr>
|
1049 |
-
<td><?php echo esc_html( MainWP_Helper::format_timestamp( MainWP_Helper::get_timestamp( $time ) ) ); ?></td>
|
1050 |
-
<td><?php echo esc_html( ( isset( $schedule['schedule'] ) && isset( $schedules[ $schedule['schedule'] ] ) && isset( $schedules[ $schedule['schedule'] ]['display'] ) ) ? $schedules[ $schedule['schedule'] ]['display'] : '' ); ?> </td>
|
1051 |
-
<td><?php echo esc_html( $hook ); ?></td>
|
1052 |
-
</tr>
|
1053 |
-
<?php
|
1054 |
-
}
|
1055 |
-
}
|
1056 |
-
}
|
1057 |
-
?>
|
1058 |
-
</tbody>
|
1059 |
-
</table>
|
1060 |
-
<?php
|
1061 |
-
}
|
1062 |
-
|
1063 |
-
/**
|
1064 |
-
* Render the MainWP directory check.
|
1065 |
-
*
|
1066 |
-
* @uses MainWP_Child_Server_Information_Base::check_mainwp_directory() Check if MainWP Directory is writeable.
|
1067 |
-
* @uses MainWP_Child_Server_Information::render_directory_row() Render the directroy check row.
|
1068 |
-
*
|
1069 |
-
* @used-by MainWP_Child_Server_Information::render_system_infor_rows() Render system information rows.
|
1070 |
-
*
|
1071 |
-
* @uses \MainWP\Child\MainWP_Child_Branding::get_branding_title()
|
1072 |
-
*/
|
1073 |
-
protected static function render_mainwp_directory() {
|
1074 |
-
$branding_title = MainWP_Child_Branding::instance()->get_branding_title();
|
1075 |
-
if ( '' == $branding_title ) {
|
1076 |
-
$branding_title = 'MainWP';
|
1077 |
-
}
|
1078 |
-
$branding_title .= ' Upload Directory';
|
1079 |
-
|
1080 |
-
$path = '';
|
1081 |
-
$message = 'Writable';
|
1082 |
-
|
1083 |
-
self::check_mainwp_directory( $message, $path );
|
1084 |
-
|
1085 |
-
self::render_directory_row( $branding_title, $path, 'Writable', $message, true );
|
1086 |
-
}
|
1087 |
-
|
1088 |
-
/**
|
1089 |
-
* Render the directroy check row.
|
1090 |
-
*
|
1091 |
-
* @param string $name Check name.
|
1092 |
-
* @param string $directory Directory to check.
|
1093 |
-
* @param string $check Check condition.
|
1094 |
-
* @param string $result Check result.
|
1095 |
-
* @param string $passed Show correct label depending on passed status.
|
1096 |
-
*
|
1097 |
-
* @used-by \MainWP\Child\MainWP_Child_Server_Information::render_mainwp_directory() Render the MainWP directory check.
|
1098 |
-
*
|
1099 |
-
* @uses \MainWP\Child\MainWP_Child_Branding::is_branding()
|
1100 |
-
*/
|
1101 |
-
protected static function render_directory_row( $name, $directory, $check, $result, $passed ) {
|
1102 |
-
?>
|
1103 |
-
<tr class="mwp-not-generate-row">
|
1104 |
-
<td></td>
|
1105 |
-
<td><?php echo esc_html( stripslashes( $name ) ); ?><br/><?php echo esc_html( ( MainWP_Child_Branding::instance()->is_branding() ) ? '' : $directory ); ?></td>
|
1106 |
-
<td><?php echo esc_html( $check ); ?></td>
|
1107 |
-
<td><?php echo esc_html( $result ); ?></td>
|
1108 |
-
<td><?php echo ( $passed ? '<span class="mainwp-pass"><i class="fa fa-check-circle"></i> Pass</span>' : '<span class="mainwp-warning"><i class="fa fa-exclamation-circle"></i> Warning</span>' ); ?></td>
|
1109 |
-
</tr>
|
1110 |
-
<?php
|
1111 |
-
}
|
1112 |
-
|
1113 |
-
/**
|
1114 |
-
* Render the server information check row.
|
1115 |
-
*
|
1116 |
-
* @param string $config Check name.
|
1117 |
-
* @param string $compare Comparison operator.
|
1118 |
-
* @param string $version Version for comparison.
|
1119 |
-
* @param string $getter Function to call to handle comparison.
|
1120 |
-
* @param string $extra_text Extra text to display in the row.
|
1121 |
-
* @param string $extra_compare Additional comparison operator.
|
1122 |
-
* @param string $extra_version Additional version to compare.
|
1123 |
-
* @param bool $size_compare Determies if size should be compared.
|
1124 |
-
*
|
1125 |
-
* @uses MainWP_Child_Server_Information_Base::check() Check Child Site system variables for any issues.
|
1126 |
-
*
|
1127 |
-
* @used-by MainWP_Child_Server_Information::render_system_infor_rows() Render system information rows.
|
1128 |
-
* @used-by MainWP_Child_Server_Information::render_php_settings_rows() Render PHP settings information rows.
|
1129 |
-
* @used-by MainWP_Child_Server_Information::render_mysql_infor_rows() Render MySQL settings information rows.
|
1130 |
-
*/
|
1131 |
-
protected static function render_row( $config, $compare, $version, $getter, $extra_text = '', $extra_compare = null, $extra_version = null, $size_compare = false ) {
|
1132 |
-
$currentVersion = call_user_func( array( self::get_class_name(), $getter ) );
|
1133 |
-
?>
|
1134 |
-
<tr>
|
1135 |
-
<td></td>
|
1136 |
-
<td><?php echo esc_html( esc_html( $config ) ); ?></td>
|
1137 |
-
<td><?php echo esc_html( esc_html( $compare ) ); ?><?php echo esc_html( ( true === $version ? 'true' : $version ) . ' ' . $extra_text ); ?></td>
|
1138 |
-
<td><?php echo esc_html( true === $currentVersion ? 'true' : $currentVersion ); ?></td>
|
1139 |
-
<td><?php echo ( self::check( $compare, $version, $getter, $extra_compare, $extra_version, $size_compare ) ? '<span class="mainwp-pass"><i class="fa fa-check-circle"></i> Pass</span>' : '<span class="mainwp-warning"><i class="fa fa-exclamation-circle"></i> Warning</span>' ); ?></td>
|
1140 |
-
</tr>
|
1141 |
-
<?php
|
1142 |
-
}
|
1143 |
-
|
1144 |
-
/**
|
1145 |
-
* Render the server information check secondary row.
|
1146 |
-
*
|
1147 |
-
* @param string $config Check name.
|
1148 |
-
* @param string $compare Comparison operator.
|
1149 |
-
* @param string $version Version for comparison.
|
1150 |
-
* @param string $getter Function to call to handle comparison.
|
1151 |
-
* @param string $extra_text Extra text to display in the row.
|
1152 |
-
* @param string $extra_compare Additional comparison operator.
|
1153 |
-
* @param string $extra_version Additional version to compare.
|
1154 |
-
* @param string $toolTip Tooltip to show.
|
1155 |
-
* @param string $whatType What type.
|
1156 |
-
* @param string $errorType Error type.
|
1157 |
-
*
|
1158 |
-
* @used-by MainWP_Child_Server_Information::render_php_settings_rows() Render PHP settings information rows.
|
1159 |
-
*/
|
1160 |
-
protected static function render_row_sec( $config, $compare, $version, $getter, $extra_text = '', $extra_compare = null, $extra_version = null, $toolTip = null, $whatType = null, $errorType = self::WARNING ) {
|
1161 |
-
$currentVersion = call_user_func( array( self::get_class_name(), $getter ) );
|
1162 |
-
?>
|
1163 |
-
<tr>
|
1164 |
-
<td></td>
|
1165 |
-
<td><?php echo $config; ?></td>
|
1166 |
-
<td><?php echo $compare; ?><?php echo ( true === $version ? 'true' : ( is_array( $version ) && isset( $version['version'] ) ? $version['version'] : $version ) ) . ' ' . $extra_text; ?></td>
|
1167 |
-
<td><?php echo( true === $currentVersion ? 'true' : $currentVersion ); ?></td>
|
1168 |
-
<?php if ( 'filesize' === $whatType ) { ?>
|
1169 |
-
<td><?php echo( self::filesize_compare( $currentVersion, $version, $compare ) ? '<span class="mainwp-pass"><i class="fa fa-check-circle"></i> Pass</span>' : self::render_warning_text( $errorType ) ); ?></td>
|
1170 |
-
<?php } elseif ( 'get_curl_ssl_version' === $getter ) { ?>
|
1171 |
-
<td><?php echo( self::curlssl_compare( $version, $compare ) ? '<span class="mainwp-pass"><i class="fa fa-check-circle"></i> Pass</span>' : self::render_warning_text( $errorType ) ); ?></td>
|
1172 |
-
<?php } elseif ( ( 'get_max_input_time' === $getter || 'get_max_execution_time' === $getter ) && -1 == $currentVersion ) { ?>
|
1173 |
-
<td><?php echo '<span class="mainwp-pass"><i class="fa fa-check-circle"></i> Pass</span>'; ?></td>
|
1174 |
-
<?php } else { ?>
|
1175 |
-
<td><?php echo ( version_compare( $currentVersion, $version, $compare ) || ( ( null != $extra_compare ) && version_compare( $currentVersion, $extra_version, $extra_compare ) ) ? '<span class="mainwp-pass"><i class="fa fa-check-circle"></i> Pass</span>' : self::render_warning_text( $errorType ) ); ?></td>
|
1176 |
-
<?php } ?>
|
1177 |
-
</tr>
|
1178 |
-
<?php
|
1179 |
-
}
|
1180 |
-
|
1181 |
-
/**
|
1182 |
-
* Render warning text.
|
1183 |
-
*
|
1184 |
-
* @param string $errorType Error type.
|
1185 |
-
*
|
1186 |
-
* @used-by MainWP_Child_Server_Information::render_row_sec() Render the server information check secondary row.
|
1187 |
-
*
|
1188 |
-
* @return string Warning message HTML.
|
1189 |
-
*/
|
1190 |
-
public static function render_warning_text( $errorType = self::WARNING ) {
|
1191 |
-
if ( self::WARNING == $errorType ) {
|
1192 |
-
return '<span class="mainwp-warning"><i class="fa fa-exclamation-circle"></i> Warning</span>';
|
1193 |
-
}
|
1194 |
-
return '<span class="mainwp-fail"><i class="fa fa-exclamation-circle"></i> Fail</span>';
|
1195 |
-
}
|
1196 |
-
|
1197 |
-
/**
|
1198 |
-
* Render the Error log page.
|
1199 |
-
*
|
1200 |
-
* @uses MainWP_Child_Server_Information::render_error_log() Render the error log content.
|
1201 |
-
*
|
1202 |
-
* @used-by MainWP_Child_Server_Information::render_page() Rener the Server Information page.
|
1203 |
-
*
|
1204 |
-
* Credits
|
1205 |
-
*
|
1206 |
-
* Plugin-Name: Error Log Dashboard Widget
|
1207 |
-
* Plugin URI: http://wordpress.org/extend/plugins/error-log-dashboard-widget/
|
1208 |
-
* Description: Robust zero-configuration and low-memory way to keep an eye on error log.
|
1209 |
-
* Author: Andrey "Rarst" Savchenko
|
1210 |
-
* Author URI: http://www.rarst.net/
|
1211 |
-
* Version: 1.0.2
|
1212 |
-
* License: GPLv2 or later
|
1213 |
-
* Includes last_lines() function by phant0m, licensed under cc-wiki and GPLv2+
|
1214 |
-
*/
|
1215 |
-
private static function render_error_page() {
|
1216 |
-
?>
|
1217 |
-
<table id="mainwp-table" class="wp-list-table widefat" cellspacing="0">
|
1218 |
-
<thead title="Click to Toggle" style="cursor: pointer;">
|
1219 |
-
<tr>
|
1220 |
-
<th scope="col" class="manage-column column-posts" style="width: 10%"><?php esc_html_e( 'Time', 'mainwp-child' ); ?></th>
|
1221 |
-
<th scope="col" class="manage-column column-posts"><?php esc_html_e( 'Error', 'mainwp-child' ); ?></th>
|
1222 |
-
</tr>
|
1223 |
-
</thead>
|
1224 |
-
<tbody class="list:sites" id="mainwp-error-log-table">
|
1225 |
-
<?php self::render_error_log(); ?>
|
1226 |
-
</tbody>
|
1227 |
-
</table>
|
1228 |
-
<?php
|
1229 |
-
}
|
1230 |
-
|
1231 |
-
/**
|
1232 |
-
* Render the error log content.
|
1233 |
-
*
|
1234 |
-
* @uses MainWP_Child_Server_Information::render_last_lines() Render the error log last lines.
|
1235 |
-
* @uses wp_kses_post() Sanitizes content for allowed HTML tags for post content.
|
1236 |
-
* @see https://developer.wordpress.org/reference/functions/wp_kses_post/
|
1237 |
-
*
|
1238 |
-
* @used-by MainWP_Child_Server_Information::render_error_page() Render the Error log page.
|
1239 |
-
*
|
1240 |
-
* @uses \MainWP\Child\MainWP_Child_Branding::get_branding_title()
|
1241 |
-
*/
|
1242 |
-
public static function render_error_log() {
|
1243 |
-
$log_errors = ini_get( 'log_errors' );
|
1244 |
-
if ( ! $log_errors ) {
|
1245 |
-
echo '<tr><td colspan="2">' . esc_html__( 'Error logging disabled.', 'mainwp-child' ) . '</td></tr>';
|
1246 |
-
}
|
1247 |
-
|
1248 |
-
$error_log = ini_get( 'error_log' );
|
1249 |
-
$logs = apply_filters( 'error_log_mainwp_logs', array( $error_log ) );
|
1250 |
-
$count = apply_filters( 'error_log_mainwp_lines', 10 );
|
1251 |
-
$lines = array();
|
1252 |
-
|
1253 |
-
foreach ( $logs as $log ) {
|
1254 |
-
if ( is_readable( $log ) ) {
|
1255 |
-
$lines = array_merge( $lines, self::render_last_lines( $log, $count ) );
|
1256 |
-
}
|
1257 |
-
}
|
1258 |
-
|
1259 |
-
$lines = array_map( 'trim', $lines );
|
1260 |
-
$lines = array_filter( $lines );
|
1261 |
-
|
1262 |
-
if ( empty( $lines ) ) {
|
1263 |
-
$branding_title = MainWP_Child_Branding::instance()->get_branding_title();
|
1264 |
-
if ( '' == $branding_title ) {
|
1265 |
-
$branding_title = 'MainWP';
|
1266 |
-
}
|
1267 |
-
$msg = esc_html( stripslashes( $branding_title ) ) . ' is unable to find your error logs, please contact your host for server error logs.';
|
1268 |
-
echo '<tr><td colspan="2">' . $msg . '</td></tr>';
|
1269 |
-
return;
|
1270 |
-
}
|
1271 |
-
|
1272 |
-
foreach ( $lines as $key => $line ) {
|
1273 |
-
|
1274 |
-
if ( false !== strpos( $line, ']' ) ) {
|
1275 |
-
list( $time, $error ) = explode( ']', $line, 2 );
|
1276 |
-
} else {
|
1277 |
-
list( $time, $error ) = array( '', $line );
|
1278 |
-
}
|
1279 |
-
|
1280 |
-
$time = trim( $time, '[]' );
|
1281 |
-
$error = trim( $error );
|
1282 |
-
$lines[ $key ] = compact( 'time', 'error' );
|
1283 |
-
}
|
1284 |
-
|
1285 |
-
if ( is_array( $error_log ) && count( $error_log ) > 1 ) {
|
1286 |
-
|
1287 |
-
uasort( $lines, array( __CLASS__, 'time_compare' ) );
|
1288 |
-
$lines = array_slice( $lines, 0, $count );
|
1289 |
-
}
|
1290 |
-
|
1291 |
-
foreach ( $lines as $line ) {
|
1292 |
-
|
1293 |
-
$error = esc_html( $line['error'] );
|
1294 |
-
$time = esc_html( $line['time'] );
|
1295 |
-
|
1296 |
-
if ( ! empty( $error ) ) {
|
1297 |
-
echo wp_kses_post( "<tr><td>{$time}</td><td>{$error}</td></tr>" );
|
1298 |
-
}
|
1299 |
-
}
|
1300 |
-
}
|
1301 |
-
|
1302 |
-
/**
|
1303 |
-
* Render the error log last lines.
|
1304 |
-
*
|
1305 |
-
* @param string $path Error log path.
|
1306 |
-
* @param int $line_count Line count.
|
1307 |
-
* @param int $block_size Block size.
|
1308 |
-
*
|
1309 |
-
* @return array Selected number of error log records to show.
|
1310 |
-
*/
|
1311 |
-
protected static function render_last_lines( $path, $line_count, $block_size = 512 ) {
|
1312 |
-
$lines = array();
|
1313 |
-
|
1314 |
-
// we will always have a fragment of a non-complete line.
|
1315 |
-
// keep this in here till we have our next entire line.
|
1316 |
-
$leftover = '';
|
1317 |
-
|
1318 |
-
// phpcs:disable WordPress.WP.AlternativeFunctions -- to custom read file.
|
1319 |
-
$fh = fopen( $path, 'r' );
|
1320 |
-
// go to the end of the file.
|
1321 |
-
fseek( $fh, 0, SEEK_END );
|
1322 |
-
|
1323 |
-
$count_lines = 0;
|
1324 |
-
do {
|
1325 |
-
// need to know whether we can actually go back.
|
1326 |
-
$can_read = $block_size;
|
1327 |
-
|
1328 |
-
if ( ftell( $fh ) <= $block_size ) {
|
1329 |
-
$can_read = ftell( $fh );
|
1330 |
-
}
|
1331 |
-
|
1332 |
-
if ( empty( $can_read ) ) {
|
1333 |
-
break;
|
1334 |
-
}
|
1335 |
-
|
1336 |
-
// go back as many bytes as we can.
|
1337 |
-
// read them to $data and then move the file pointer.
|
1338 |
-
// back to where we were.
|
1339 |
-
fseek( $fh, - $can_read, SEEK_CUR );
|
1340 |
-
$data = fread( $fh, $can_read );
|
1341 |
-
$data .= $leftover;
|
1342 |
-
fseek( $fh, - $can_read, SEEK_CUR );
|
1343 |
-
|
1344 |
-
// split lines by \n. Then reverse them, now the last line is most likely not a complete line which is why we do not directly add it, but append it to the data read the next time.
|
1345 |
-
$split_data = array_reverse( explode( "\n", $data ) );
|
1346 |
-
$new_lines = array_slice( $split_data, 0, - 1 );
|
1347 |
-
$lines = array_merge( $lines, $new_lines );
|
1348 |
-
$leftover = $split_data[ count( $split_data ) - 1 ];
|
1349 |
-
$count_lines = count( $lines );
|
1350 |
-
} while ( $count_lines < $line_count && 0 !== ftell( $fh ) );
|
1351 |
-
|
1352 |
-
if ( 0 === ftell( $fh ) ) {
|
1353 |
-
$lines[] = $leftover;
|
1354 |
-
}
|
1355 |
-
|
1356 |
-
fclose( $fh );
|
1357 |
-
|
1358 |
-
// phpcs:enable
|
1359 |
-
|
1360 |
-
// Usually, we will read too many lines, correct that here.
|
1361 |
-
return array_slice( $lines, 0, $line_count );
|
1362 |
-
}
|
1363 |
-
|
1364 |
-
/**
|
1365 |
-
* Render the connection details page content.
|
1366 |
-
*
|
1367 |
-
* @uses \MainWP\Child\MainWP_Child_Branding::get_branding_title()
|
1368 |
-
*/
|
1369 |
-
public static function render_connection_details() {
|
1370 |
-
$branding_title = MainWP_Child_Branding::instance()->get_branding_title();
|
1371 |
-
if ( '' == $branding_title ) {
|
1372 |
-
$branding_title = 'MainWP';
|
1373 |
-
}
|
1374 |
-
|
1375 |
-
/**
|
1376 |
-
* Current user global.
|
1377 |
-
*
|
1378 |
-
* @global string
|
1379 |
-
*/
|
1380 |
-
global $current_user;
|
1381 |
-
|
1382 |
-
$uniqueId = MainWP_Helper::get_site_unique_id();
|
1383 |
-
$details = array(
|
1384 |
-
'siteurl' => array(
|
1385 |
-
'title' => __( 'Site URL', 'mainwp-child' ),
|
1386 |
-
'value' => get_bloginfo( 'url' ),
|
1387 |
-
'desc' => get_bloginfo( 'url' ),
|
1388 |
-
),
|
1389 |
-
'adminuser' => array(
|
1390 |
-
'title' => __( 'Administrator name', 'mainwp-child' ),
|
1391 |
-
'value' => $current_user->user_login,
|
1392 |
-
'desc' => __( 'This is your Administrator username, however, you can use any existing Administrator username.', 'mainwp-child' ),
|
1393 |
-
),
|
1394 |
-
'friendly_name' => array(
|
1395 |
-
'title' => __( 'Friendly site name', 'mainwp-child' ),
|
1396 |
-
'value' => get_bloginfo( 'name' ),
|
1397 |
-
'desc' => __( 'For the friendly site name, you can use any name, this is just a suggestion.', 'mainwp-child' ),
|
1398 |
-
),
|
1399 |
-
'uniqueid' => array(
|
1400 |
-
'title' => __( 'Child unique security id', 'mainwp-child' ),
|
1401 |
-
'value' => ! empty( $uniqueId ) ? $uniqueId : __( 'Leave the field blank', 'mainwp-child' ),
|
1402 |
-
'desc' => sprintf( __( 'Child unique security id is not required, however, since you have enabled it, you need to add it to your %s dashboard.', 'mainwp-child' ), stripslashes( $branding_title ) ),
|
1403 |
-
),
|
1404 |
-
'verify_ssl' => array(
|
1405 |
-
'title' => __( 'Verify certificate', 'mainwp-child' ),
|
1406 |
-
'value' => __( 'Yes', 'mainwp-child' ),
|
1407 |
-
'desc' => __( 'If there is an issue with SSL certificate on this site, try to set this option to No.', 'mainwp-child' ),
|
1408 |
-
),
|
1409 |
-
'ssl_version' => array(
|
1410 |
-
'title' => __( 'SSL version', 'mainwp-child' ),
|
1411 |
-
'value' => __( 'Auto Detect', 'mainwp-child' ),
|
1412 |
-
'desc' => __( 'Auto Detect', 'mainwp-child' ),
|
1413 |
-
),
|
1414 |
-
|
1415 |
-
);
|
1416 |
-
?>
|
1417 |
-
<div class="postbox" id="connection_detail">
|
1418 |
-
<h3 class="mainwp_box_title"><span><?php _e( 'Connection details', 'mainwp-child' ); ?></span></h3>
|
1419 |
-
<div class="inside">
|
1420 |
-
<div class="mainwp-postbox-actions-top mainwp-padding-5">
|
1421 |
-
<?php echo sprintf( __( 'If you are trying to connect this child site to your %s Dashboard, you can use following details to do that. Please note that these are only suggested values.', 'mainwp-child' ), stripslashes( $branding_title ) ); ?>
|
1422 |
-
</div>
|
1423 |
-
<table id="mainwp-table" class="wp-list-table widefat" cellspacing="0" style="border: 0">
|
1424 |
-
<tbody>
|
1425 |
-
<?php
|
1426 |
-
foreach ( $details as $row ) {
|
1427 |
-
?>
|
1428 |
-
<tr>
|
1429 |
-
<th style="width: 20%"><strong><?php echo esc_html( $row['title'] ); ?></strong></th>
|
1430 |
-
<td style="width: 20%"><strong><?php echo esc_html( $row['value'] ); ?></strong></td>
|
1431 |
-
<td><?php echo esc_html( $row['desc'] ); ?></td>
|
1432 |
-
</tr>
|
1433 |
-
<?php
|
1434 |
-
}
|
1435 |
-
?>
|
1436 |
-
</tbody>
|
1437 |
-
</table>
|
1438 |
-
</div>
|
1439 |
-
</div>
|
1440 |
-
<?php
|
1441 |
-
}
|
1442 |
-
|
1443 |
-
}
|
1 |
+
<?php
|
2 |
+
/**
|
3 |
+
* MainWP Child Server Information
|
4 |
+
*
|
5 |
+
* MainWP Child server information handler.
|
6 |
+
*
|
7 |
+
* @package MainWP\Child
|
8 |
+
*/
|
9 |
+
|
10 |
+
namespace MainWP\Child;
|
11 |
+
|
12 |
+
/**
|
13 |
+
* Class MainWP_Child_Server_Information
|
14 |
+
*
|
15 |
+
* MainWP Child server information handler.
|
16 |
+
*
|
17 |
+
* @uses \MainWP\Child\MainWP_Child_Server_Information_Base
|
18 |
+
*/
|
19 |
+
class MainWP_Child_Server_Information extends MainWP_Child_Server_Information_Base {
|
20 |
+
const WARNING = 1;
|
21 |
+
const ERROR = 2;
|
22 |
+
|
23 |
+
/**
|
24 |
+
* Method get_class_name()
|
25 |
+
*
|
26 |
+
* Get class name.
|
27 |
+
*
|
28 |
+
* @return string __CLASS__ Class name.
|
29 |
+
*/
|
30 |
+
public static function get_class_name() {
|
31 |
+
return __CLASS__;
|
32 |
+
}
|
33 |
+
|
34 |
+
/**
|
35 |
+
* Add hooks after WordPress has finished loading but before any headers are sent.
|
36 |
+
*
|
37 |
+
* @uses MainWP_Child_Server_Information::dismiss_warnings() Dismiss warnings.
|
38 |
+
*/
|
39 |
+
public static function init() {
|
40 |
+
add_action(
|
41 |
+
'wp_ajax_mainwp-child_dismiss_warnings',
|
42 |
+
array(
|
43 |
+
self::get_class_name(),
|
44 |
+
'dismiss_warnings',
|
45 |
+
)
|
46 |
+
);
|
47 |
+
}
|
48 |
+
|
49 |
+
/**
|
50 |
+
* Dismiss warnings.
|
51 |
+
*
|
52 |
+
* @uses \MainWP\Child\MainWP_Helper::update_option() Update option by option name.
|
53 |
+
* @uses \MainWP\Child\MainWP_Child_Server_Information_Base::get_warnings() Initiate check on important System Variables and compare them to required defaults.
|
54 |
+
* @uses get_option() Retrieves an option value based on an option name.
|
55 |
+
* @see https://developer.wordpress.org/reference/functions/get_option/
|
56 |
+
*
|
57 |
+
* @used-by MainWP_Child_Server_Information::init() Add hooks after WordPress has finished loading but before any headers are sent.
|
58 |
+
*/
|
59 |
+
public static function dismiss_warnings() {
|
60 |
+
if ( isset( $_POST['what'] ) ) {
|
61 |
+
$dismissWarnings = get_option( 'mainwp_child_dismiss_warnings' );
|
62 |
+
if ( ! is_array( $dismissWarnings ) ) {
|
63 |
+
$dismissWarnings = array();
|
64 |
+
}
|
65 |
+
if ( 'warning' == $_POST['what'] ) {
|
66 |
+
if ( isset( $_POST['warnings'] ) ) {
|
67 |
+
$warnings = intval( $_POST['warnings'] );
|
68 |
+
} else {
|
69 |
+
$warnings = self::get_warnings();
|
70 |
+
}
|
71 |
+
$dismissWarnings['warnings'] = $warnings;
|
72 |
+
}
|
73 |
+
MainWP_Helper::update_option( 'mainwp_child_dismiss_warnings', $dismissWarnings );
|
74 |
+
}
|
75 |
+
}
|
76 |
+
|
77 |
+
/**
|
78 |
+
* Render warnings.
|
79 |
+
*
|
80 |
+
* @uses \MainWP\Child\MainWP_Helper::update_option() Update option by option name.
|
81 |
+
* @uses \MainWP\Child\MainWP_Child_Server_Information_Base::get_warnings() Initiate check on important System Variables and compare them to required defaults.
|
82 |
+
* @uses get_option() Retrieves an option value based on an option name.
|
83 |
+
* @see https://developer.wordpress.org/reference/functions/get_option/
|
84 |
+
*
|
85 |
+
* @used-by MainWP_Child_Server_Information::init() Add hooks after WordPress has finished loading but before any headers are sent.
|
86 |
+
*/
|
87 |
+
public static function render_warnings() {
|
88 |
+
$request_uri = isset( $_SERVER['REQUEST_URI'] ) ? wp_unslash( $_SERVER['REQUEST_URI'] ) : '';
|
89 |
+
if ( isset( $_SERVER['REQUEST_URI'] ) && ( stristr( $request_uri, 'mainwp_child_tab' ) || stristr( $request_uri, 'mainwp-reports-page' ) || stristr( $request_uri, 'mainwp-reports-settings' ) ) ) {
|
90 |
+
return;
|
91 |
+
}
|
92 |
+
|
93 |
+
// improved query.
|
94 |
+
if ( self::is_mainwp_pages() ) {
|
95 |
+
return;
|
96 |
+
}
|
97 |
+
|
98 |
+
$warnings = self::get_warnings();
|
99 |
+
|
100 |
+
$dismissWarnings = get_option( 'mainwp_child_dismiss_warnings' );
|
101 |
+
if ( ! is_array( $dismissWarnings ) ) {
|
102 |
+
$dismissWarnings = array();
|
103 |
+
}
|
104 |
+
|
105 |
+
if ( isset( $dismissWarnings['warnings'] ) && $dismissWarnings['warnings'] >= $warnings ) {
|
106 |
+
$warnings = 0;
|
107 |
+
}
|
108 |
+
|
109 |
+
if ( 0 === $warnings ) {
|
110 |
+
return;
|
111 |
+
}
|
112 |
+
|
113 |
+
if ( $warnings > 0 ) {
|
114 |
+
$dismissWarnings['warnings'] = 0;
|
115 |
+
}
|
116 |
+
|
117 |
+
MainWP_Helper::update_option( 'mainwp_child_dismiss_warnings', $dismissWarnings );
|
118 |
+
?>
|
119 |
+
<script language="javascript">
|
120 |
+
dismiss_warnings = function ( pElement, pAction ) {
|
121 |
+
var table = jQuery( pElement.parents( 'table' )[0] );
|
122 |
+
pElement.parents( 'tr' )[0].remove();
|
123 |
+
if ( table.find( 'tr' ).length == 0 ) {
|
124 |
+
jQuery( '#mainwp-child_server_warnings' ).hide();
|
125 |
+
}
|
126 |
+
|
127 |
+
var data = {
|
128 |
+
action: 'mainwp-child_dismiss_warnings',
|
129 |
+
what: pAction,
|
130 |
+
warnings: <?php echo intval( $warnings ); ?>
|
131 |
+
};
|
132 |
+
|
133 |
+
jQuery.ajax( {
|
134 |
+
type: "POST",
|
135 |
+
url: ajaxurl,
|
136 |
+
data: data,
|
137 |
+
success: function ( resp ) {},
|
138 |
+
error: function () {},
|
139 |
+
dataType: 'json'
|
140 |
+
} );
|
141 |
+
|
142 |
+
return false;
|
143 |
+
};
|
144 |
+
jQuery( document ).on( 'click', '#mainwp-child-connect-warning-dismiss', function () {
|
145 |
+
return dismiss_warnings( jQuery( this ), 'warning' );
|
146 |
+
} );
|
147 |
+
jQuery( document ).on( 'click', '#mainwp-child-all-pages-warning-dismiss', function () {
|
148 |
+
return dismiss_warnings( jQuery( this ), 'conflict' );
|
149 |
+
} );
|
150 |
+
</script>
|
151 |
+
<style type="text/css">
|
152 |
+
.mainwp-child_info-box-red-warning {
|
153 |
+
background-color: rgba(187, 114, 57, 0.2) !important;
|
154 |
+
border-bottom: 4px solid #bb7239 !important;
|
155 |
+
border-top: 1px solid #bb7239 !important;
|
156 |
+
border-left: 1px solid #bb7239 !important;
|
157 |
+
border-right: 1px solid #bb7239 !important;
|
158 |
+
-webkit-border-radius: 3px;
|
159 |
+
-moz-border-radius: 3px;
|
160 |
+
border-radius: 3px;
|
161 |
+
margin: 1em 0 !important;
|
162 |
+
|
163 |
+
background-image: url( '<?php echo esc_url( plugins_url( 'images/mainwp-icon-orange.png', dirname( __FILE__ ) ) ); ?>' ) !important;
|
164 |
+
background-position: 1.5em 50% !important;
|
165 |
+
background-repeat: no-repeat !important;
|
166 |
+
background-size: 30px !important;
|
167 |
+
}
|
168 |
+
|
169 |
+
.mainwp-child_info-box-red-warning table {
|
170 |
+
background-color: rgba(187, 114, 57, 0) !important;
|
171 |
+
border: 0px;
|
172 |
+
padding-left: 4.5em;
|
173 |
+
background-position: 1.5em 50% !important;
|
174 |
+
background-repeat: no-repeat !important;
|
175 |
+
background-size: 30px !important;
|
176 |
+
}
|
177 |
+
</style>
|
178 |
+
|
179 |
+
<div class="updated mainwp-child_info-box-red-warning" id="mainwp-child_server_warnings">
|
180 |
+
<table id="mainwp-table" class="wp-list-table widefat" cellspacing="0">
|
181 |
+
<tbody id="the-sites-list" class="list:sites">
|
182 |
+
<?php
|
183 |
+
$warning = '';
|
184 |
+
if ( $warnings > 0 ) {
|
185 |
+
$warning .= '<tr><td colspan="2">This site may not connect to your dashboard or may have other issues. Check your <a href="options-general.php?page=mainwp_child_tab">MainWP server information page</a>.</td><td style="text-align: right;"><a href="#" id="mainwp-child-connect-warning-dismiss">Dismiss</a></td></tr>';
|
186 |
+
}
|
187 |
+
echo $warning;
|
188 |
+
?>
|
189 |
+
</tbody>
|
190 |
+
</table>
|
191 |
+
</div>
|
192 |
+
<?php
|
193 |
+
}
|
194 |
+
|
195 |
+
/**
|
196 |
+
* Method is_mainwp_pages()
|
197 |
+
*
|
198 |
+
* Get the current page and check it for "mainwp_".
|
199 |
+
*
|
200 |
+
* @return boolean ture|false.
|
201 |
+
*/
|
202 |
+
public static function is_mainwp_pages() {
|
203 |
+
$screen = get_current_screen();
|
204 |
+
if ( $screen && strpos( $screen->base, 'mainwp_' ) !== false && strpos( $screen->base, 'mainwp_child_tab' ) === false ) {
|
205 |
+
return true;
|
206 |
+
}
|
207 |
+
|
208 |
+
return false;
|
209 |
+
}
|
210 |
+
|
211 |
+
/**
|
212 |
+
* Render JavaScrip code for the Server Information page.
|
213 |
+
*
|
214 |
+
* @used-by MainWP_Child_Server_Information::render_page() Render the Server Information page.
|
215 |
+
*/
|
216 |
+
private static function render_page_js() {
|
217 |
+
?>
|
218 |
+
<script language="javascript">
|
219 |
+
|
220 |
+
/* FileSaver.js
|
221 |
+
* A saveAs() FileSaver implementation.
|
222 |
+
* 2013-01-23
|
223 |
+
*
|
224 |
+
* By Eli Grey, http://eligrey.com
|
225 |
+
* License: X11/MIT
|
226 |
+
* See LICENSE.md
|
227 |
+
*/
|
228 |
+
|
229 |
+
/*global self */
|
230 |
+
/*jslint bitwise: true, regexp: true, confusion: true, es5: true, vars: true, white: true, plusplus: true */
|
231 |
+
|
232 |
+
/*! @source http://purl.eligrey.com/github/FileSaver.js/blob/master/FileSaver.js */
|
233 |
+
|
234 |
+
var childSaveAs = childSaveAs
|
235 |
+
|| ( navigator.msSaveBlob && navigator.msSaveBlob.bind( navigator ) )
|
236 |
+
|| ( function( view ) {
|
237 |
+
"use strict";
|
238 |
+
var doc = view.document
|
239 |
+
, get_URL = function() {
|
240 |
+
return view.URL || view.webkitURL || view;
|
241 |
+
}
|
242 |
+
, URL = view.URL || view.webkitURL || view
|
243 |
+
, save_link = doc.createElementNS("http://www.w3.org/1999/xhtml", "a")
|
244 |
+
, can_use_save_link = "download" in save_link
|
245 |
+
, click = function(node) {
|
246 |
+
var event = doc.createEvent("MouseEvents");
|
247 |
+
event.initMouseEvent(
|
248 |
+
"click", true, false, view, 0, 0, 0, 0, 0
|
249 |
+
, false, false, false, false, 0, null
|
250 |
+
);
|
251 |
+
return node.dispatchEvent(event); // false if event was cancelled
|
252 |
+
}
|
253 |
+
, webkit_req_fs = view.webkitRequestFileSystem
|
254 |
+
, req_fs = view.requestFileSystem || webkit_req_fs || view.mozRequestFileSystem
|
255 |
+
, throw_outside = function (ex) {
|
256 |
+
(view.setImmediate || view.setTimeout)(function() {
|
257 |
+
throw ex;
|
258 |
+
}, 0);
|
259 |
+
}
|
260 |
+
, force_saveable_type = "application/octet-stream"
|
261 |
+
, fs_min_size = 0
|
262 |
+
, deletion_queue = []
|
263 |
+
, process_deletion_queue = function() {
|
264 |
+
var i = deletion_queue.length;
|
265 |
+
while (i--) {
|
266 |
+
var file = deletion_queue[i];
|
267 |
+
if (typeof file === "string") {
|
268 |
+
URL.revokeObjectURL(file);
|
269 |
+
} else {
|
270 |
+
file.remove();
|
271 |
+
}
|
272 |
+
}
|
273 |
+
deletion_queue.length = 0;
|
274 |
+
}
|
275 |
+
, dispatch = function(filesaver, event_types, event) {
|
276 |
+
event_types = [].concat(event_types);
|
277 |
+
var i = event_types.length;
|
278 |
+
while (i--) {
|
279 |
+
var listener = filesaver["on" + event_types[i]];
|
280 |
+
if (typeof listener === "function") {
|
281 |
+
try {
|
282 |
+
listener.call(filesaver, event || filesaver);
|
283 |
+
} catch (ex) {
|
284 |
+
throw_outside(ex);
|
285 |
+
}
|
286 |
+
}
|
287 |
+
}
|
288 |
+
}
|
289 |
+
, FileSaver = function( blob, name ) {
|
290 |
+
var
|
291 |
+
filesaver = this
|
292 |
+
, type = blob.type
|
293 |
+
, blob_changed = false
|
294 |
+
, object_url
|
295 |
+
, target_view
|
296 |
+
, get_object_url = function() {
|
297 |
+
var object_url = get_URL().createObjectURL(blob);
|
298 |
+
deletion_queue.push(object_url);
|
299 |
+
return object_url;
|
300 |
+
}
|
301 |
+
, dispatch_all = function() {
|
302 |
+
dispatch( filesaver, "writestart progress write writeend".split( " " ) );
|
303 |
+
}
|
304 |
+
, fs_error = function() {
|
305 |
+
if ( blob_changed || !object_url ) {
|
306 |
+
object_url = get_object_url( blob );
|
307 |
+
}
|
308 |
+
if (target_view) {
|
309 |
+
target_view.location.href = object_url;
|
310 |
+
}
|
311 |
+
filesaver.readyState = filesaver.DONE;
|
312 |
+
dispatch_all();
|
313 |
+
}
|
314 |
+
, abortable = function(func) {
|
315 |
+
return function() {
|
316 |
+
if (filesaver.readyState !== filesaver.DONE) {
|
317 |
+
return func.apply(this, arguments);
|
318 |
+
}
|
319 |
+
};
|
320 |
+
}
|
321 |
+
, create_if_not_found = {create: true, exclusive: false}
|
322 |
+
, slice
|
323 |
+
;
|
324 |
+
filesaver.readyState = filesaver.INIT;
|
325 |
+
if ( !name ) {
|
326 |
+
name = "download";
|
327 |
+
}
|
328 |
+
if ( can_use_save_link ) {
|
329 |
+
object_url = get_object_url( blob );
|
330 |
+
save_link.href = object_url;
|
331 |
+
save_link.download = name;
|
332 |
+
if ( click( save_link ) ) {
|
333 |
+
filesaver.readyState = filesaver.DONE;
|
334 |
+
dispatch_all();
|
335 |
+
return;
|
336 |
+
}
|
337 |
+
}
|
338 |
+
if ( view.chrome && type && type !== force_saveable_type ) {
|
339 |
+
slice = blob.slice || blob.webkitSlice;
|
340 |
+
blob = slice.call( blob, 0, blob.size, force_saveable_type );
|
341 |
+
blob_changed = true;
|
342 |
+
}
|
343 |
+
if (webkit_req_fs && name !== "download") {
|
344 |
+
name += ".download";
|
345 |
+
}
|
346 |
+
if ( type === force_saveable_type || webkit_req_fs ) {
|
347 |
+
target_view = view;
|
348 |
+
} else {
|
349 |
+
target_view = view.open();
|
350 |
+
}
|
351 |
+
if (!req_fs) {
|
352 |
+
fs_error();
|
353 |
+
return;
|
354 |
+
}
|
355 |
+
fs_min_size += blob.size;
|
356 |
+
req_fs(view.TEMPORARY, fs_min_size, abortable(function(fs) {
|
357 |
+
fs.root.getDirectory("saved", create_if_not_found, abortable(function(dir) {
|
358 |
+
var save = function() {
|
359 |
+
dir.getFile(name, create_if_not_found, abortable(function(file) {
|
360 |
+
file.createWriter(abortable(function(writer) {
|
361 |
+
writer.onwriteend = function(event) {
|
362 |
+
target_view.location.href = file.toURL();
|
363 |
+
deletion_queue.push(file);
|
364 |
+
filesaver.readyState = filesaver.DONE;
|
365 |
+
dispatch(filesaver, "writeend", event);
|
366 |
+
};
|
367 |
+
writer.onerror = function() {
|
368 |
+
var error = writer.error;
|
369 |
+
if (error.code !== error.ABORT_ERR) {
|
370 |
+
fs_error();
|
371 |
+
}
|
372 |
+
};
|
373 |
+
"writestart progress write abort".split(" ").forEach(function(event) {
|
374 |
+
writer["on" + event] = filesaver["on" + event];
|
375 |
+
});
|
376 |
+
writer.write(blob);
|
377 |
+
filesaver.abort = function() {
|
378 |
+
writer.abort();
|
379 |
+
filesaver.readyState = filesaver.DONE;
|
380 |
+
};
|
381 |
+
filesaver.readyState = filesaver.WRITING;
|
382 |
+
}), fs_error);
|
383 |
+
}), fs_error);
|
384 |
+
};
|
385 |
+
dir.getFile(name, {create: false}, abortable(function(file) {
|
386 |
+
file.remove();
|
387 |
+
save();
|
388 |
+
}), abortable(function(ex) {
|
389 |
+
if (ex.code === ex.NOT_FOUND_ERR) {
|
390 |
+
save();
|
391 |
+
} else {
|
392 |
+
fs_error();
|
393 |
+
}
|
394 |
+
}));
|
395 |
+
}), fs_error);
|
396 |
+
}), fs_error);
|
397 |
+
}
|
398 |
+
, FS_proto = FileSaver.prototype
|
399 |
+
, childSaveAs = function(blob, name) {
|
400 |
+
return new FileSaver(blob, name);
|
401 |
+
}
|
402 |
+
;
|
403 |
+
FS_proto.abort = function() {
|
404 |
+
var filesaver = this;
|
405 |
+
filesaver.readyState = filesaver.DONE;
|
406 |
+
dispatch(filesaver, "abort");
|
407 |
+
};
|
408 |
+
FS_proto.readyState = FS_proto.INIT = 0;
|
409 |
+
FS_proto.WRITING = 1;
|
410 |
+
FS_proto.DONE = 2;
|
411 |
+
|
412 |
+
FS_proto.error =
|
413 |
+
FS_proto.onwritestart =
|
414 |
+
FS_proto.onprogress =
|
415 |
+
FS_proto.onwrite =
|
416 |
+
FS_proto.onabort =
|
417 |
+
FS_proto.onerror =
|
418 |
+
FS_proto.onwriteend =
|
419 |
+
null;
|
420 |
+
|
421 |
+
view.addEventListener("unload", process_deletion_queue, false);
|
422 |
+
return childSaveAs;
|
423 |
+
}(self));
|
424 |
+
|
425 |
+
|
426 |
+
mwp_child_strCut = function(i,l,s,w) {
|
427 |
+
var o = i.toString();
|
428 |
+
if (!s) { s = '0'; }
|
429 |
+
while (o.length < parseInt(l)) {
|
430 |
+
if( w == 'undefined' ){
|
431 |
+
o = s + o;
|
432 |
+
}else{
|
433 |
+
o = o + s;
|
434 |
+
}
|
435 |
+
}
|
436 |
+
return o;
|
437 |
+
};
|
438 |
+
jQuery( document ).on( 'click', 'a.mwp-child-get-system-report-btn', function() {
|
439 |
+
var report = "";
|
440 |
+
jQuery( '.mwp_server_info_box thead, .mwp_server_info_box tbody' ).each( function() {
|
441 |
+
var td_len = [35, 55, 45, 12, 12];
|
442 |
+
var th_count = 0;
|
443 |
+
var i;
|
444 |
+
if ( jQuery( this ).is( 'thead' ) ) {
|
445 |
+
i = 0;
|
446 |
+
report = report + "\n### ";
|
447 |
+
th_count = jQuery( this ).find( 'th:not(".mwp-not-generate-row")' ).length;
|
448 |
+
jQuery( this ).find( 'th:not(".mwp-not-generate-row")' ).each( function() {
|
449 |
+
var len = td_len[i];
|
450 |
+
if ( i == 0 || i == th_count -1 )
|
451 |
+
len = len - 4;
|
452 |
+
report = report + mwp_child_strCut( jQuery.trim( jQuery( this ).text() ), len, ' ' );
|
453 |
+
i++;
|
454 |
+
} );
|
455 |
+
report = report + " ###\n\n";
|
456 |
+
} else {
|
457 |
+
jQuery( 'tr', jQuery( this ) ).each( function() {
|
458 |
+
if ( jQuery( this ).hasClass( 'mwp-not-generate-row' ) )
|
459 |
+
return;
|
460 |
+
i = 0;
|
461 |
+
jQuery( this ).find( 'td:not(".mwp-not-generate-row")' ).each( function() {
|
462 |
+
if (jQuery( this ).hasClass( 'mwp-hide-generate-row' ) ) {
|
463 |
+
report = report + mwp_child_strCut( ' ', td_len[i], ' ' );
|
464 |
+
i++;
|
465 |
+
return;
|
466 |
+
}
|
467 |
+
report = report + mwp_child_strCut( jQuery.trim( jQuery( this ).text() ), td_len[i], ' ' );
|
468 |
+
i++;
|
469 |
+
} );
|
470 |
+
report = report + "\n";
|
471 |
+
} );
|
472 |
+
}
|
473 |
+
} );
|
474 |
+
try {
|
475 |
+
jQuery( "#mwp-server-information" ).slideDown();
|
476 |
+
jQuery( "#mwp-server-information textarea" ).val( report ).focus().select();
|
477 |
+
jQuery( this ).fadeOut();
|
478 |
+
jQuery( '.mwp_child_close_srv_info' ).show();
|
479 |
+
return false;
|
480 |
+
} catch(e){ }
|
481 |
+
} );
|
482 |
+
|
483 |
+
jQuery( document ).on( 'click', 'a#mwp_child_close_srv_info', function() {
|
484 |
+
jQuery( '#mwp-server-information' ).hide();
|
485 |
+
jQuery( '.mwp_child_close_srv_info' ).hide();
|
486 |
+
jQuery( 'a.mwp-child-get-system-report-btn' ).show();
|
487 |
+
return false;
|
488 |
+
} );
|
489 |
+
jQuery( document ).on( 'click', '#mwp_child_download_srv_info', function() {
|
490 |
+
var server_info = jQuery( '#mwp-server-information textarea' ).val();
|
491 |
+
var blob = new Blob( [server_info], {type: "text/plain;charset=utf-8"} );
|
492 |
+
childSaveAs( blob, "server_child_information.txt" );
|
493 |
+
} );
|
494 |
+
</script>
|
495 |
+
<?php
|
496 |
+
}
|
497 |
+
|
498 |
+
/**
|
499 |
+
* Render the Server Information page.
|
500 |
+
*
|
501 |
+
* @uses MainWP_Child_Server_Information::render_page_js() Render JavaScrip code for the Server Information page.
|
502 |
+
* @uses MainWP_Child_Server_Information::render_server_infor() Render server information.
|
503 |
+
* @uses MainWP_Child_Server_Information::render_cron() Render cron schedules.
|
504 |
+
* @uses MainWP_Child_Server_Information::render_error_page() Render error log.
|
505 |
+
*/
|
506 |
+
public static function render_page() {
|
507 |
+
self::render_page_js();
|
508 |
+
?>
|
509 |
+
<style type="text/css">
|
510 |
+
#mwp-server-information {
|
511 |
+
display: none;
|
512 |
+
margin: 10px 0;
|
513 |
+
padding: 0;
|
514 |
+
position: relative;
|
515 |
+
}
|
516 |
+
|
517 |
+
#mwp-server-information textarea {
|
518 |
+
border-radius: 0;
|
519 |
+
font-family: monospace;
|
520 |
+
font-size: 12px;
|
521 |
+
height: 300px;
|
522 |
+
line-height: 20px;
|
523 |
+
margin: 0;
|
524 |
+
outline: 0 none;
|
525 |
+
padding: 20px;
|
526 |
+
resize: none;
|
527 |
+
width: 100%;
|
528 |
+
-moz-border-radius:0;
|
529 |
+
-webkit-border-radius:0;
|
530 |
+
}
|
531 |
+
|
532 |
+
.mwp_child_close_srv_info {
|
533 |
+
display: none;
|
534 |
+
float: right;
|
535 |
+
margin: 5px 0 5px;
|
536 |
+
}
|
537 |
+
</style>
|
538 |
+
<div class="wrap">
|
539 |
+
<div class="updated below-h2">
|
540 |
+
<p><?php esc_html_e( 'Please include this information when requesting support:', 'mainwp-child' ); ?></p>
|
541 |
+
<span class="mwp_child_close_srv_info">
|
542 |
+
<a href="#" id="mwp_child_download_srv_info"><?php esc_html_e( 'Download', 'mainwp-child' ); ?></a> | <a href="#" id="mwp_child_close_srv_info"><i class="fa fa-eye-slash"></i> <?php _e( 'Hide', 'mainwp-child' ); ?></a>
|
543 |
+
</span>
|
544 |
+
<p class="submit">
|
545 |
+
<a class="button-primary mwp-child-get-system-report-btn" href="#"><?php esc_html_e( 'Get system report', 'mainwp-child' ); ?></a>
|
546 |
+
</p>
|
547 |
+
<div id="mwp-server-information"><textarea readonly="readonly" wrap="off"></textarea></div>
|
548 |
+
</div>
|
549 |
+
<br/>
|
550 |
+
<div class="mwp_server_info_box">
|
551 |
+
<h2><?php esc_html_e( 'Server Information', 'mainwp-child' ); ?></h2>
|
552 |
+
<?php self::render_server_infor(); ?>
|
553 |
+
<h2><?php esc_html_e( 'Cron Schedules', 'mainwp-child' ); ?></h2>
|
554 |
+
<?php self::render_cron(); ?>
|
555 |
+
<h2><?php esc_html_e( 'Error Log', 'mainwp-child' ); ?></h2>
|
556 |
+
<?php self::render_error_page(); ?>
|
557 |
+
</div>
|
558 |
+
</div>
|
559 |
+
<?php
|
560 |
+
}
|
561 |
+
|
562 |
+
/**
|
563 |
+
* Render server information content.
|
564 |
+
*
|
565 |
+
* @uses MainWP_Child_Server_Information::render_system_infor_rows() Render system information rows.
|
566 |
+
* @uses MainWP_Child_Server_Information::render_php_settings_rows() Render PHP settings information rows.
|
567 |
+
* @uses MainWP_Child_Server_Information::render_mysql_infor_rows() Render MySQL settings information rows.
|
568 |
+
* @uses MainWP_Child_Server_Information::render_server_infor_rows() Render server settings information rows.
|
569 |
+
* @uses MainWP_Child_Server_Information::render_php_infor_rows() Render PHP information rows.
|
570 |
+
* @uses MainWP_Child_Server_Information::render_plugins_infor_rows() Render plugins information rows.
|
571 |
+
*
|
572 |
+
* @used-by MainWP_Child_Server_Information::render_page() Render the Server Information page.
|
573 |
+
*
|
574 |
+
* @uses \MainWP\Child\MainWP_Child_Branding::get_branding_title()
|
575 |
+
*/
|
576 |
+
private static function render_server_infor() {
|
577 |
+
$branding_title = MainWP_Child_Branding::instance()->get_branding_title();
|
578 |
+
if ( '' == $branding_title ) {
|
579 |
+
$branding_title = 'MainWP Child';
|
580 |
+
}
|
581 |
+
?>
|
582 |
+
<table id="mainwp-table" class="wp-list-table widefat" cellspacing="0">
|
583 |
+
<thead>
|
584 |
+
<tr>
|
585 |
+
<th scope="col" class="manage-column column-posts mwp-not-generate-row" style="width: 1px;"></th>
|
586 |
+
<th scope="col" class="manage-column column-posts"><span><?php esc_html_e( 'Server configuration', 'mainwp-child' ); ?></span></th>
|
587 |
+
<th scope="col" class="manage-column column-posts"><?php esc_html_e( 'Required value', 'mainwp-child' ); ?></th>
|
588 |
+
<th scope="col" class="manage-column column-posts"><?php esc_html_e( 'Value', 'mainwp-child' ); ?></th>
|
589 |
+
<th scope="col" class="manage-column column-posts"><?php esc_html_e( 'Status', 'mainwp-child' ); ?></th>
|
590 |
+
</tr>
|
591 |
+
</thead>
|
592 |
+
<tbody id="the-sites-list" class="list:sites">
|
593 |
+
<?php self::render_system_infor_rows( $branding_title ); ?>
|
594 |
+
<?php self::render_php_settings_rows(); ?>
|
595 |
+
<?php self::render_mysql_infor_rows(); ?>
|
596 |
+
<?php self::render_server_infor_rows(); ?>
|
597 |
+
<?php self::render_php_infor_rows(); ?>
|
598 |
+
<?php self::render_plugins_infor_rows( $branding_title ); ?>
|
599 |
+
</tbody>
|
600 |
+
</table>
|
601 |
+
<br/>
|
602 |
+
<?php
|
603 |
+
}
|
604 |
+
|
605 |
+
/**
|
606 |
+
* Render system information rows.
|
607 |
+
*
|
608 |
+
* @param string $branding_title Custom branding plgin title.
|
609 |
+
*
|
610 |
+
* @uses MainWP_Child_Server_Information_Base::get_mainwp_version() Get the MainWP Child plugin version number.
|
611 |
+
* @uses MainWP_Child_Server_Information_Base::get_current_version() Get the current MainWP Child plugin version.
|
612 |
+
* @uses MainWP_Child_Server_Information_Base::get_file_system_method() Get file system method.
|
613 |
+
* @uses MainWP_Child_Server_Information::render_file_system_method_check() Render the file system method check.
|
614 |
+
* @uses MainWP_Child_Server_Information::render_mainwp_version_check() Render the MainWP version check row.
|
615 |
+
* @uses MainWP_Child_Server_Information::render_row() Render the server information row.
|
616 |
+
* @uses get_option() Retrieves an option value based on an option name.
|
617 |
+
* @see https://developer.wordpress.org/reference/functions/get_option/
|
618 |
+
*
|
619 |
+
* @used-by MainWP_Child_Server_Information::render_server_infor() Render server information content.
|
620 |
+
*/
|
621 |
+
private static function render_system_infor_rows( $branding_title ) {
|
622 |
+
?>
|
623 |
+
<tr>
|
624 |
+
<td style="background: #333; color: #fff;" colspan="5"><?php echo esc_html( strtoupper( stripslashes( $branding_title ) ) ); ?></td>
|
625 |
+
</tr>
|
626 |
+
<tr>
|
627 |
+
<td></td>
|
628 |
+
<td><?php echo esc_html( stripslashes( $branding_title ) ) . ' ' . __( 'Version', 'mainwp-chil' ); ?></td>
|
629 |
+
<td><?php echo esc_html( self::get_mainwp_version() ); ?></td>
|
630 |
+
<td><?php echo esc_html( self::get_current_version() ); ?></td>
|
631 |
+
<td><?php echo esc_html( self::render_mainwp_version_check() ); ?></td>
|
632 |
+
</tr>
|
633 |
+
<?php self::render_mainwp_directory(); ?>
|
634 |
+
<tr>
|
635 |
+
<td style="background: #333; color: #fff;" colspan="5"><?php esc_html_e( 'WordPress', 'mainwp-child' ); ?></td>
|
636 |
+
</tr>
|
637 |
+
<?php self::render_row( 'WordPress Version', '>=', '3.4', 'get_wordpress_version' ); ?>
|
638 |
+
<?php self::render_row( 'WordPress Memory Limit', '>=', '64M', 'get_wordpress_memory_limit' ); ?>
|
639 |
+
<?php self::render_row( 'MultiSite Disabled', '=', true, 'check_if_multisite' ); ?>
|
640 |
+
<tr>
|
641 |
+
<td></td>
|
642 |
+
<td><?php esc_html_e( 'FileSystem Method', 'mainwp-child' ); ?></td>
|
643 |
+
<td><?php echo esc_html( '= direct' ); ?></td>
|
644 |
+
<td><?php echo esc_html( self::get_file_system_method() ); ?></td>
|
645 |
+
<td><?php echo esc_html( self::render_file_system_method_check() ); ?></td>
|
646 |
+
</tr>
|
647 |
+
<?php
|
648 |
+
}
|
649 |
+
|
650 |
+
/**
|
651 |
+
* Render the file system method check.
|
652 |
+
*
|
653 |
+
* @uses MainWP_Child_Server_Information_Base::get_file_system_method() Get file system method.
|
654 |
+
*
|
655 |
+
* @used-by MainWP_Child_Server_Information::render_system_infor_rows() Render system information rows.
|
656 |
+
*/
|
657 |
+
protected static function render_file_system_method_check() {
|
658 |
+
$fsmethod = self::get_file_system_method();
|
659 |
+
if ( 'direct' === $fsmethod ) {
|
660 |
+
echo '<span class="mainwp-pass"><i class="fa fa-check-circle"></i> Pass</span>';
|
661 |
+
} else {
|
662 |
+
echo '<span class="mainwp-warning"><i class="fa fa-exclamation-circle"></i> Warning</span>';
|
663 |
+
}
|
664 |
+
}
|
665 |
+
|
666 |
+
/**
|
667 |
+
* Render PHP settings information rows.
|
668 |
+
*
|
669 |
+
* @uses MainWP_Child_Server_Information::render_row() Render the server information row.
|
670 |
+
* @uses MainWP_Child_Server_Information::render_row_sec() Render the server information secondary row.
|
671 |
+
* @uses MainWP_Child_Server_Information_Base::get_php_safe_mode() Check if PHP is in Safe Mode.
|
672 |
+
*
|
673 |
+
* @used-by MainWP_Child_Server_Information::render_system_infor_rows() Render system information rows.
|
674 |
+
*/
|
675 |
+
private static function render_php_settings_rows() {
|
676 |
+
?>
|
677 |
+
<tr>
|
678 |
+
<td style="background: #333; color: #fff;"
|
679 |
+
colspan="5"><?php esc_html_e( 'PHP SETTINGS', 'mainwp-child' ); ?></td>
|
680 |
+
</tr>
|
681 |
+
<?php self::render_row( 'PHP Version', '>=', '5.6', 'get_php_version' ); ?>
|
682 |
+
<tr>
|
683 |
+
<td></td>
|
684 |
+
<td><?php esc_html_e( 'PHP Safe Mode Disabled', 'mainwp-child' ); ?></td>
|
685 |
+
<td colspan="3"><?php self::get_php_safe_mode(); ?></td>
|
686 |
+
</tr>
|
687 |
+
<?php
|
688 |
+
self::render_row_sec( 'PHP Max Execution Time', '>=', '30', 'get_max_execution_time', 'seconds', '=', '0' );
|
689 |
+
self::render_row_sec( 'PHP Max Input Time', '>=', '30', 'get_max_input_time', 'seconds', '=', '0' );
|
690 |
+
self::render_row( 'PHP Memory Limit', '>=', '128M', 'get_php_memory_limit', '(256M+ best for big backups)', null, null, true );
|
691 |
+
self::render_row( 'PCRE Backtracking Limit', '>=', '10000', 'get_output_buffer_size' );
|
692 |
+
self::render_row( 'PHP Upload Max Filesize', '>=', '2M', 'get_upload_max_filesize', '(2MB+ best for upload of big plugins)', null, null, true );
|
693 |
+
self::render_row( 'PHP Post Max Size', '>=', '2M', 'get_post_max_size', '(2MB+ best for upload of big plugins)', null, null, true );
|
694 |
+
self::render_row( 'SSL Extension Enabled', '=', true, 'get_ssl_support' );
|
695 |
+
self::render_row_sec( 'SSL Warnings', '=', '', 'get_ssl_warning', 'empty', '' );
|
696 |
+
self::render_row_sec( 'cURL Extension Enabled', '=', true, 'get_curl_support', '', '', null, '', null, self::ERROR );
|
697 |
+
self::render_row_sec( 'cURL Timeout', '>=', '300', 'get_curl_timeout', 'seconds', '=', '0' );
|
698 |
+
if ( function_exists( 'curl_version' ) ) {
|
699 |
+
self::render_row_sec( 'cURL Version', '>=', '7.18.1', 'get_curl_version', '', '', null );
|
700 |
+
$openssl_version = 'OpenSSL/1.1.0';
|
701 |
+
self::render_row_sec(
|
702 |
+
'cURL SSL Version',
|
703 |
+
'>=',
|
704 |
+
$openssl_version,
|
705 |
+
'get_curl_ssl_version',
|
706 |
+
'',
|
707 |
+
'',
|
708 |
+
null,
|
709 |
+
'',
|
710 |
+
'curlssl'
|
711 |
+
);
|
712 |
+
if ( ! self::curlssl_compare( $openssl_version, '>=' ) ) {
|
713 |
+
echo "<tr style=\"background:#fffaf3\"><td colspan='5'><span class=\"mainwp-warning\"><i class='fa fa-exclamation-circle'>" . sprintf( __( 'Your host needs to update OpenSSL to at least version 1.1.0 which is already over 4 years old and contains patches for over 60 vulnerabilities.%1$sThese range from Denial of Service to Remote Code Execution. %2$sClick here for more information.%3$s', 'mainwp' ), '<br/>', '<a href="https://community.letsencrypt.org/t/openssl-client-compatibility-changes-for-let-s-encrypt-certificates/143816" target="_blank">', '</a>' ) . '</span></td></tr>';
|
714 |
+
}
|
715 |
+
}
|
716 |
+
}
|
717 |
+
|
718 |
+
/**
|
719 |
+
* Render MySQL settings information rows.
|
720 |
+
*
|
721 |
+
* @uses MainWP_Child_Server_Information::render_row() Render the server information row.
|
722 |
+
*
|
723 |
+
* @used-by MainWP_Child_Server_Information::render_server_infor() Render server information content.
|
724 |
+
*/
|
725 |
+
private static function render_mysql_infor_rows() {
|
726 |
+
?>
|
727 |
+
<tr>
|
728 |
+
<td style="background: #333; color: #fff;" colspan="5"><?php esc_html_e( 'MySQL SETTINGS', 'mainwp-child' ); ?></td>
|
729 |
+
</tr>
|
730 |
+
<?php self::render_row( 'MySQL Version', '>=', '5.0', 'get_my_sql_version' ); ?>
|
731 |
+
<tr>
|
732 |
+
<td style="background: #333; color: #fff;" colspan="5"><?php esc_html_e( 'BACKUP ARCHIVE INFORMATION', 'mainwp-child' ); ?></td>
|
733 |
+
</tr>
|
734 |
+
<?php self::render_row( 'ZipArchive enabled in PHP', '=', true, 'get_zip_archive_enabled' ); ?>
|
735 |
+
<?php self::render_row( 'Tar GZip supported', '=', true, 'get_gzip_enabled' ); ?>
|
736 |
+
<?php self::render_row( 'Tar BZip2 supported', '=', true, 'get_bzip_enabled' ); ?>
|
737 |
+
<?php
|
738 |
+
}
|
739 |
+
|
740 |
+
/**
|
741 |
+
* Render plugins information rows.
|
742 |
+
*
|
743 |
+
* @param string $branding_title Custom branding plugin title.
|
744 |
+
*
|
745 |
+
* @uses get_plugins() Check the plugins directory and retrieve all plugin files with plugin data.
|
746 |
+
* @see https://developer.wordpress.org/reference/functions/get_plugins/
|
747 |
+
*
|
748 |
+
* @uses is_plugin_active() Determines whether a plugin is active.
|
749 |
+
* @see https://developer.wordpress.org/reference/functions/get_plugins/
|
750 |
+
*
|
751 |
+
* @used-by MainWP_Child_Server_Information::render_server_infor() Render server information content.
|
752 |
+
*/
|
753 |
+
private static function render_plugins_infor_rows( $branding_title ) {
|
754 |
+
?>
|
755 |
+
<tr>
|
756 |
+
<td style="background: #333; color: #fff;" colspan="5"><?php _e( 'WordPress PLUGINS', 'mainwp-child' ); ?></td>
|
757 |
+
</tr>
|
758 |
+
<?php
|
759 |
+
$all_plugins = get_plugins();
|
760 |
+
foreach ( $all_plugins as $slug => $plugin ) {
|
761 |
+
if ( ! empty( $branding_title ) && ( 'mainwp-child/mainwp-child.php' == $slug || 'mainwp-child-reports/mainwp-child-reports.php' == $slug ) ) {
|
762 |
+
if ( 'mainwp-child/mainwp-child.php' == $slug ) {
|
763 |
+
$plugin['Name'] = esc_html( stripslashes( $branding_title ) );
|
764 |
+
} elseif ( 'mainwp-child-reports/mainwp-child-reports.php' == $slug ) {
|
765 |
+
$plugin['Name'] = esc_html( stripslashes( $branding_title ) ) . ' reports';
|
766 |
+
}
|
767 |
+
}
|
768 |
+
?>
|
769 |
+
<tr>
|
770 |
+
<td></td>
|
771 |
+
<td><?php echo esc_html( $plugin['Name'] ); ?></td>
|
772 |
+
<td><?php echo esc_html( $plugin['Version'] ); ?></td>
|
773 |
+
<td><?php echo is_plugin_active( $slug ) ? __( 'Active', 'mainwp-child' ) : __( 'Inactive', 'mainwp-child' ); ?></td>
|
774 |
+
<td></td>
|
775 |
+
</tr>
|
776 |
+
<?php
|
777 |
+
}
|
778 |
+
}
|
779 |
+
|
780 |
+
/**
|
781 |
+
* Render PHP information rows.
|
782 |
+
*
|
783 |
+
* @uses MainWP_Child_Server_Information_Base::get_php_allow_url_fopen() Check if PHP Allow URL fopen is enabled.
|
784 |
+
* @uses MainWP_Child_Server_Information_Base::get_php_exif() Check if PHP exif is enabled.
|
785 |
+
* @uses MainWP_Child_Server_Information_Base::get_php_ip_tc() Check if PHP IP TC is enabled.
|
786 |
+
* @uses MainWP_Child_Server_Information_Base::get_php_xml() Check if PHP XML is enabled.
|
787 |
+
* @uses MainWP_Child_Server_Information_Base::mainwp_required_functions() Check for disabled PHP functions.
|
788 |
+
* @uses MainWP_Child_Server_Information_Base::get_loaded_php_extensions() Get loaded PHP extensions.
|
789 |
+
* @uses MainWP_Child_Server_Information_Base::get_sql_mode() Get current SQL mode.
|
790 |
+
*
|
791 |
+
* @used-by MainWP_Child_Server_Information::render_server_infor() Render server information content.
|
792 |
+
*/
|
793 |
+
private static function render_php_infor_rows() {
|
794 |
+
?>
|
795 |
+
<tr>
|
796 |
+
<td style="background: #333; color: #fff;" colspan="5"><?php esc_html_e( 'PHP INFORMATION', 'mainwp-child' ); ?></td>
|
797 |
+
</tr>
|
798 |
+
<tr>
|
799 |
+
<td></td>
|
800 |
+
<td><?php esc_html_e( 'PHP Allow URL fopen', 'mainwp-child' ); ?></td>
|
801 |
+
<td colspan="3"><?php self::get_php_allow_url_fopen(); ?></td>
|
802 |
+
</tr>
|
803 |
+
<tr>
|
804 |
+
<td></td>
|
805 |
+
<td><?php esc_html_e( 'PHP Exif Support', 'mainwp-child' ); ?></td>
|
806 |
+
<td colspan="3"><?php self::get_php_exif(); ?></td>
|
807 |
+
</tr>
|
808 |
+
<tr>
|
809 |
+
<td></td>
|
810 |
+
<td><?php esc_html_e( 'PHP IPTC Support', 'mainwp-child' ); ?></td>
|
811 |
+
<td colspan="3"><?php self::get_php_ip_tc(); ?></td>
|
812 |
+
</tr>
|
813 |
+
<tr>
|
814 |
+
<td></td>
|
815 |
+
<td><?php esc_html_e( 'PHP XML Support', 'mainwp-child' ); ?></td>
|
816 |
+
<td colspan="3"><?php self::get_php_xml(); ?></td>
|
817 |
+
</tr>
|
818 |
+
<tr>
|
819 |
+
<td></td>
|
820 |
+
<td><?php esc_html_e( 'PHP Disabled Functions', 'mainwp-child' ); ?></td>
|
821 |
+
<td colspan="3"><?php self::mainwp_required_functions(); ?></td>
|
822 |
+
</tr>
|
823 |
+
<tr>
|
824 |
+
<td></td>
|
825 |
+
<td><?php esc_html_e( 'PHP Loaded Extensions', 'mainwp-child' ); ?></td>
|
826 |
+
<td colspan="3" style="width: 73% !important;"><?php self::get_loaded_php_extensions(); ?></td>
|
827 |
+
</tr>
|
828 |
+
<tr>
|
829 |
+
<td style="background: #333; color: #fff;"
|
830 |
+
colspan="5"><?php esc_html_e( 'MySQL INFORMATION', 'mainwp-child' ); ?></td>
|
831 |
+
</tr>
|
832 |
+
<tr>
|
833 |
+
<td></td>
|
834 |
+
<td><?php esc_html_e( 'MySQL Mode', 'mainwp-child' ); ?></td>
|
835 |
+
<td colspan="3"><?php self::get_sql_mode(); ?></td>
|
836 |
+
</tr>
|
837 |
+
<tr>
|
838 |
+
<td></td>
|
839 |
+
<td><?php esc_html_e( 'MySQL Client Encoding', 'mainwp-child' ); ?></td>
|
840 |
+
<td colspan="3"><?php echo esc_html( defined( 'DB_CHARSET' ) ? DB_CHARSET : '' ); ?></td>
|
841 |
+
</tr>
|
842 |
+
<?php
|
843 |
+
}
|
844 |
+
|
845 |
+
/**
|
846 |
+
* Render server settings information rows.
|
847 |
+
*
|
848 |
+
* @uses MainWP_Child_Server_Information_Base::get_wp_root() Get WordPress root directory.
|
849 |
+
* @uses MainWP_Child_Server_Information_Base::get_server_name()Get server name.
|
850 |
+
* @uses MainWP_Child_Server_Information_Base::get_server_software() Get server software.
|
851 |
+
* @uses MainWP_Child_Server_Information_Base::get_os() Get operating system.
|
852 |
+
* @uses MainWP_Child_Server_Information_Base::get_architecture() Get System architecture.
|
853 |
+
* @uses MainWP_Child_Server_Information_Base::get_server_ip() Get server IP.
|
854 |
+
* @uses MainWP_Child_Server_Information_Base::get_server_protocol() Get server protocol.
|
855 |
+
* @uses MainWP_Child_Server_Information_Base::get_http_host() Get server HTTP host.
|
856 |
+
* @uses MainWP_Child_Server_Information_Base::get_https() Check if HTTPS is on.
|
857 |
+
* @uses MainWP_Child_Server_Information_Base::server_self_connect() Server self-connection test.
|
858 |
+
* @uses MainWP_Child_Server_Information_Base::get_user_agent() Get server user agent.
|
859 |
+
* @uses MainWP_Child_Server_Information_Base::get_server_port() Get server port.
|
860 |
+
* @uses MainWP_Child_Server_Information_Base::get_server_getaway_interface() Get current server gateway interface.
|
861 |
+
* @uses MainWP_Child_Server_Information_Base::memory_usage() Get the current Memory usage.
|
862 |
+
* @uses MainWP_Child_Server_Information_Base::get_complete_url() Get server complete URL.
|
863 |
+
* @uses MainWP_Child_Server_Information_Base::get_server_request_time() Get server request time.
|
864 |
+
* @uses MainWP_Child_Server_Information_Base::get_server_http_accept() Get server HTTP accept.
|
865 |
+
* @uses MainWP_Child_Server_Information_Base::get_server_accept_charset() Get server accepted charset.
|
866 |
+
* @uses MainWP_Child_Server_Information_Base::get_script_file_name() Get server script filename.
|
867 |
+
* @uses MainWP_Child_Server_Information_Base::get_current_page_uri() Get current page URL.
|
868 |
+
* @uses MainWP_Child_Server_Information_Base::get_remote_address() Get server remote address.
|
869 |
+
* @uses MainWP_Child_Server_Information_Base::get_remote_host() Get server remote host.
|
870 |
+
* @uses MainWP_Child_Server_Information_Base::get_remote_port() Get server remote port.
|
871 |
+
*
|
872 |
+
* @used-by MainWP_Child_Server_Information::render_server_infor() Render server information content.
|
873 |
+
*/
|
874 |
+
private static function render_server_infor_rows() {
|
875 |
+
?>
|
876 |
+
<tr>
|
877 |
+
<td style="background: #333; color: #fff;" colspan="5"><?php esc_html_e( 'SERVER INFORMATION', 'mainwp-child' ); ?></td>
|
878 |
+
</tr>
|
879 |
+
<tr>
|
880 |
+
<td></td>
|
881 |
+
<td><?php esc_html_e( 'WordPress Root Directory', 'mainwp-child' ); ?></td>
|
882 |
+
<td colspan="3"><?php self::get_wp_root(); ?></td>
|
883 |
+
</tr>
|
884 |
+
<tr>
|
885 |
+
<td></td>
|
886 |
+
<td><?php esc_html_e( 'Server Name', 'mainwp-child' ); ?></td>
|
887 |
+
<td colspan="3"><?php self::get_server_name(); ?></td>
|
888 |
+
</tr>
|
889 |
+
<tr>
|
890 |
+
<td></td>
|
891 |
+
<td><?php esc_html_e( 'Server Software', 'mainwp-child' ); ?></td>
|
892 |
+
<td colspan="3"><?php self::get_server_software(); ?></td>
|
893 |
+
</tr>
|
894 |
+
<tr>
|
895 |
+
<td></td>
|
896 |
+
<td><?php esc_html_e( 'Operating System', 'mainwp-child' ); ?></td>
|
897 |
+
<td colspan="3"><?php self::get_os(); ?></td>
|
898 |
+
</tr>
|
899 |
+
<tr>
|
900 |
+
<td></td>
|
901 |
+
<td><?php esc_html_e( 'Architecture', 'mainwp-child' ); ?></td>
|
902 |
+
<td colspan="3"><?php self::get_architecture(); ?></td>
|
903 |
+
</tr>
|
904 |
+
<tr>
|
905 |
+
<td></td>
|
906 |
+
<td><?php esc_html_e( 'Server IP', 'mainwp-child' ); ?></td>
|
907 |
+
<td colspan="3"><?php self::get_server_ip(); ?></td>
|
908 |
+
</tr>
|
909 |
+
<tr>
|
910 |
+
<td></td>
|
911 |
+
<td><?php esc_html_e( 'Server Protocol', 'mainwp-child' ); ?></td>
|
912 |
+
<td colspan="3"><?php self::get_server_protocol(); ?></td>
|
913 |
+
</tr>
|
914 |
+
<tr>
|
915 |
+
<td></td>
|
916 |
+
<td><?php esc_html_e( 'HTTP Host', 'mainwp-child' ); ?></td>
|
917 |
+
<td colspan="3"><?php self::get_http_host(); ?></td>
|
918 |
+
</tr>
|
919 |
+
<tr>
|
920 |
+
<td></td>
|
921 |
+
<td><?php esc_html_e( 'HTTPS', 'mainwp-child' ); ?></td>
|
922 |
+
<td colspan="3"><?php self::get_https(); ?></td>
|
923 |
+
</tr>
|
924 |
+
<tr>
|
925 |
+
<td></td>
|
926 |
+
<td><?php esc_html_e( 'Server self connect', 'mainwp-child' ); ?></td>
|
927 |
+
<td colspan="3"><?php self::server_self_connect(); ?></td>
|
928 |
+
</tr>
|
929 |
+
<tr>
|
930 |
+
<td></td>
|
931 |
+
<td><?php esc_html_e( 'User Agent', 'mainwp-child' ); ?></td>
|
932 |
+
<td colspan="3"><?php self::get_user_agent(); ?></td>
|
933 |
+
</tr>
|
934 |
+
<tr>
|
935 |
+
<td></td>
|
936 |
+
<td><?php esc_html_e( 'Server Port', 'mainwp-child' ); ?></td>
|
937 |
+
<td colspan="3"><?php self::get_server_port(); ?></td>
|
938 |
+
</tr>
|
939 |
+
<tr>
|
940 |
+
<td></td>
|
941 |
+
<td><?php esc_html_e( 'Gateway Interface', 'mainwp-child' ); ?></td>
|
942 |
+
<td colspan="3"><?php self::get_server_getaway_interface(); ?></td>
|
943 |
+
</tr>
|
944 |
+
<tr>
|
945 |
+
<td></td>
|
946 |
+
<td><?php esc_html_e( 'Memory Usage', 'mainwp-child' ); ?></td>
|
947 |
+
<td colspan="3"><?php self::memory_usage(); ?></td>
|
948 |
+
</tr>
|
949 |
+
<tr>
|
950 |
+
<td></td>
|
951 |
+
<td><?php esc_html_e( 'Complete URL', 'mainwp-child' ); ?></td>
|
952 |
+
<td colspan="3"><?php self::get_complete_url(); ?></td>
|
953 |
+
</tr>
|
954 |
+
<tr>
|
955 |
+
<td></td>
|
956 |
+
<td><?php esc_html_e( 'Request Time', 'mainwp-child' ); ?></td>
|
957 |
+
<td colspan="3"><?php self::get_server_request_time(); ?></td>
|
958 |
+
</tr>
|
959 |
+
<tr>
|
960 |
+
<td></td>
|
961 |
+
<td><?php esc_html_e( 'Accept Content', 'mainwp-child' ); ?></td>
|
962 |
+
<td colspan="3"><?php self::get_server_http_accept(); ?></td>
|
963 |
+
</tr>
|
964 |
+
<tr>
|
965 |
+
<td></td>
|
966 |
+
<td><?php esc_html_e( 'Accept-Charset Content', 'mainwp-child' ); ?></td>
|
967 |
+
<td colspan="3"><?php self::get_server_accept_charset(); ?></td>
|
968 |
+
</tr>
|
969 |
+
<tr>
|
970 |
+
<td></td>
|
971 |
+
<td><?php esc_html_e( 'Currently Executing Script Pathname', 'mainwp-child' ); ?></td>
|
972 |
+
<td colspan="3"><?php self::get_script_file_name(); ?></td>
|
973 |
+
</tr>
|
974 |
+
<tr>
|
975 |
+
<td></td>
|
976 |
+
<td><?php esc_html_e( 'Current Page URI', 'mainwp-child' ); ?></td>
|
977 |
+
<td colspan="3"><?php self::get_current_page_uri(); ?></td>
|
978 |
+
</tr>
|
979 |
+
<tr>
|
980 |
+
<td></td>
|
981 |
+
<td><?php esc_html_e( 'Remote Address', 'mainwp-child' ); ?></td>
|
982 |
+
<td colspan="3"><?php self::get_remote_address(); ?></td>
|
983 |
+
</tr>
|
984 |
+
<tr>
|
985 |
+
<td></td>
|
986 |
+
<td><?php esc_html_e( 'Remote Host', 'mainwp-child' ); ?></td>
|
987 |
+
<td colspan="3"><?php self::get_remote_host(); ?></td>
|
988 |
+
</tr>
|
989 |
+
<tr>
|
990 |
+
<td></td>
|
991 |
+
<td><?php esc_html_e( 'Remote Port', 'mainwp-child' ); ?></td>
|
992 |
+
<td colspan="3"><?php self::get_remote_port(); ?></td>
|
993 |
+
</tr>
|
994 |
+
<?php
|
995 |
+
}
|
996 |
+
|
997 |
+
/**
|
998 |
+
* Render the MainWP version check.
|
999 |
+
*
|
1000 |
+
* @uses MainWP_Child_Server_Information_Base::get_mainwp_version() Get the current MainWP Child plugin version.
|
1001 |
+
*
|
1002 |
+
* @uses get_option() Retrieves an option value based on an option name.
|
1003 |
+
* @see https://developer.wordpress.org/reference/functions/get_option/
|
1004 |
+
*
|
1005 |
+
* @used-by MainWP_Child_Server_Information::render_system_infor_rows() Render system information rows.
|
1006 |
+
*/
|
1007 |
+
protected static function render_mainwp_version_check() {
|
1008 |
+
$current = get_option( 'mainwp_child_plugin_version' );
|
1009 |
+
$latest = self::get_mainwp_version();
|
1010 |
+
if ( $current === $latest ) {
|
1011 |
+
echo '<span class="mainwp-pass"><i class="fa fa-check-circle"></i> Pass</span>';
|
1012 |
+
} else {
|
1013 |
+
echo '<span class="mainwp-warning"><i class="fa fa-exclamation-circle"></i> Warning</span>';
|
1014 |
+
}
|
1015 |
+
}
|
1016 |
+
|
1017 |
+
/**
|
1018 |
+
* Render cron schedules.
|
1019 |
+
*
|
1020 |
+
* @uses _get_cron_array() Retrieve cron info array option.
|
1021 |
+
* @see https://developer.wordpress.org/reference/functions/_get_cron_array/
|
1022 |
+
*
|
1023 |
+
* @uses wp_get_schedules() Retrieve supported event recurrence schedules.
|
1024 |
+
* @see https://developer.wordpress.org/reference/functions/wp_get_schedules/
|
1025 |
+
*
|
1026 |
+
* @uses \MainWP\Child\MainWP_Helper::format_timestamp() Format timestamp as per the WordPress general settings.
|
1027 |
+
*
|
1028 |
+
* @used-by \MainWP\Child\MainWP_Child_Server_Information::render_page() Render the Server Information page.
|
1029 |
+
*/
|
1030 |
+
private static function render_cron() {
|
1031 |
+
$cron_array = _get_cron_array();
|
1032 |
+
$schedules = wp_get_schedules();
|
1033 |
+
?>
|
1034 |
+
<table id="mainwp-table" class="wp-list-table widefat" cellspacing="0">
|
1035 |
+
<thead>
|
1036 |
+
<tr>
|
1037 |
+
<th scope="col" class="manage-column column-posts"><span><?php esc_html_e( 'Next due', 'mainwp-child' ); ?></span></th>
|
1038 |
+
<th scope="col" class="manage-column column-posts"><span><?php esc_html_e( 'Schedule', 'mainwp-child' ); ?></span></th>
|
1039 |
+
<th scope="col" class="manage-column column-posts"><span><?php esc_html_e( 'Hook', 'mainwp-child' ); ?></span></th>
|
1040 |
+
</tr>
|
1041 |
+
</thead>
|
1042 |
+
<tbody id="the-sites-list" class="list:sites">
|
1043 |
+
<?php
|
1044 |
+
foreach ( $cron_array as $time => $cron ) {
|
1045 |
+
foreach ( $cron as $hook => $cron_info ) {
|
1046 |
+
foreach ( $cron_info as $key => $schedule ) {
|
1047 |
+
?>
|
1048 |
+
<tr>
|
1049 |
+
<td><?php echo esc_html( MainWP_Helper::format_timestamp( MainWP_Helper::get_timestamp( $time ) ) ); ?></td>
|
1050 |
+
<td><?php echo esc_html( ( isset( $schedule['schedule'] ) && isset( $schedules[ $schedule['schedule'] ] ) && isset( $schedules[ $schedule['schedule'] ]['display'] ) ) ? $schedules[ $schedule['schedule'] ]['display'] : '' ); ?> </td>
|
1051 |
+
<td><?php echo esc_html( $hook ); ?></td>
|
1052 |
+
</tr>
|
1053 |
+
<?php
|
1054 |
+
}
|
1055 |
+
}
|
1056 |
+
}
|
1057 |
+
?>
|
1058 |
+
</tbody>
|
1059 |
+
</table>
|
1060 |
+
<?php
|
1061 |
+
}
|
1062 |
+
|
1063 |
+
/**
|
1064 |
+
* Render the MainWP directory check.
|
1065 |
+
*
|
1066 |
+
* @uses MainWP_Child_Server_Information_Base::check_mainwp_directory() Check if MainWP Directory is writeable.
|
1067 |
+
* @uses MainWP_Child_Server_Information::render_directory_row() Render the directroy check row.
|
1068 |
+
*
|
1069 |
+
* @used-by MainWP_Child_Server_Information::render_system_infor_rows() Render system information rows.
|
1070 |
+
*
|
1071 |
+
* @uses \MainWP\Child\MainWP_Child_Branding::get_branding_title()
|
1072 |
+
*/
|
1073 |
+
protected static function render_mainwp_directory() {
|
1074 |
+
$branding_title = MainWP_Child_Branding::instance()->get_branding_title();
|
1075 |
+
if ( '' == $branding_title ) {
|
1076 |
+
$branding_title = 'MainWP';
|
1077 |
+
}
|
1078 |
+
$branding_title .= ' Upload Directory';
|
1079 |
+
|
1080 |
+
$path = '';
|
1081 |
+
$message = 'Writable';
|
1082 |
+
|
1083 |
+
self::check_mainwp_directory( $message, $path );
|
1084 |
+
|
1085 |
+
self::render_directory_row( $branding_title, $path, 'Writable', $message, true );
|
1086 |
+
}
|
1087 |
+
|
1088 |
+
/**
|
1089 |
+
* Render the directroy check row.
|
1090 |
+
*
|
1091 |
+
* @param string $name Check name.
|
1092 |
+
* @param string $directory Directory to check.
|
1093 |
+
* @param string $check Check condition.
|
1094 |
+
* @param string $result Check result.
|
1095 |
+
* @param string $passed Show correct label depending on passed status.
|
1096 |
+
*
|
1097 |
+
* @used-by \MainWP\Child\MainWP_Child_Server_Information::render_mainwp_directory() Render the MainWP directory check.
|
1098 |
+
*
|
1099 |
+
* @uses \MainWP\Child\MainWP_Child_Branding::is_branding()
|
1100 |
+
*/
|
1101 |
+
protected static function render_directory_row( $name, $directory, $check, $result, $passed ) {
|
1102 |
+
?>
|
1103 |
+
<tr class="mwp-not-generate-row">
|
1104 |
+
<td></td>
|
1105 |
+
<td><?php echo esc_html( stripslashes( $name ) ); ?><br/><?php echo esc_html( ( MainWP_Child_Branding::instance()->is_branding() ) ? '' : $directory ); ?></td>
|
1106 |
+
<td><?php echo esc_html( $check ); ?></td>
|
1107 |
+
<td><?php echo esc_html( $result ); ?></td>
|
1108 |
+
<td><?php echo ( $passed ? '<span class="mainwp-pass"><i class="fa fa-check-circle"></i> Pass</span>' : '<span class="mainwp-warning"><i class="fa fa-exclamation-circle"></i> Warning</span>' ); ?></td>
|
1109 |
+
</tr>
|
1110 |
+
<?php
|
1111 |
+
}
|
1112 |
+
|
1113 |
+
/**
|
1114 |
+
* Render the server information check row.
|
1115 |
+
*
|
1116 |
+
* @param string $config Check name.
|
1117 |
+
* @param string $compare Comparison operator.
|
1118 |
+
* @param string $version Version for comparison.
|
1119 |
+
* @param string $getter Function to call to handle comparison.
|
1120 |
+
* @param string $extra_text Extra text to display in the row.
|
1121 |
+
* @param string $extra_compare Additional comparison operator.
|
1122 |
+
* @param string $extra_version Additional version to compare.
|
1123 |
+
* @param bool $size_compare Determies if size should be compared.
|
1124 |
+
*
|
1125 |
+
* @uses MainWP_Child_Server_Information_Base::check() Check Child Site system variables for any issues.
|
1126 |
+
*
|
1127 |
+
* @used-by MainWP_Child_Server_Information::render_system_infor_rows() Render system information rows.
|
1128 |
+
* @used-by MainWP_Child_Server_Information::render_php_settings_rows() Render PHP settings information rows.
|
1129 |
+
* @used-by MainWP_Child_Server_Information::render_mysql_infor_rows() Render MySQL settings information rows.
|
1130 |
+
*/
|
1131 |
+
protected static function render_row( $config, $compare, $version, $getter, $extra_text = '', $extra_compare = null, $extra_version = null, $size_compare = false ) {
|
1132 |
+
$currentVersion = call_user_func( array( self::get_class_name(), $getter ) );
|
1133 |
+
?>
|
1134 |
+
<tr>
|
1135 |
+
<td></td>
|
1136 |
+
<td><?php echo esc_html( esc_html( $config ) ); ?></td>
|
1137 |
+
<td><?php echo esc_html( esc_html( $compare ) ); ?><?php echo esc_html( ( true === $version ? 'true' : $version ) . ' ' . $extra_text ); ?></td>
|
1138 |
+
<td><?php echo esc_html( true === $currentVersion ? 'true' : $currentVersion ); ?></td>
|
1139 |
+
<td><?php echo ( self::check( $compare, $version, $getter, $extra_compare, $extra_version, $size_compare ) ? '<span class="mainwp-pass"><i class="fa fa-check-circle"></i> Pass</span>' : '<span class="mainwp-warning"><i class="fa fa-exclamation-circle"></i> Warning</span>' ); ?></td>
|
1140 |
+
</tr>
|
1141 |
+
<?php
|
1142 |
+
}
|
1143 |
+
|
1144 |
+
/**
|
1145 |
+
* Render the server information check secondary row.
|
1146 |
+
*
|
1147 |
+
* @param string $config Check name.
|
1148 |
+
* @param string $compare Comparison operator.
|
1149 |
+
* @param string $version Version for comparison.
|
1150 |
+
* @param string $getter Function to call to handle comparison.
|
1151 |
+
* @param string $extra_text Extra text to display in the row.
|
1152 |
+
* @param string $extra_compare Additional comparison operator.
|
1153 |
+
* @param string $extra_version Additional version to compare.
|
1154 |
+
* @param string $toolTip Tooltip to show.
|
1155 |
+
* @param string $whatType What type.
|
1156 |
+
* @param string $errorType Error type.
|
1157 |
+
*
|
1158 |
+
* @used-by MainWP_Child_Server_Information::render_php_settings_rows() Render PHP settings information rows.
|
1159 |
+
*/
|
1160 |
+
protected static function render_row_sec( $config, $compare, $version, $getter, $extra_text = '', $extra_compare = null, $extra_version = null, $toolTip = null, $whatType = null, $errorType = self::WARNING ) {
|
1161 |
+
$currentVersion = call_user_func( array( self::get_class_name(), $getter ) );
|
1162 |
+
?>
|
1163 |
+
<tr>
|
1164 |
+
<td></td>
|
1165 |
+
<td><?php echo $config; ?></td>
|
1166 |
+
<td><?php echo $compare; ?><?php echo ( true === $version ? 'true' : ( is_array( $version ) && isset( $version['version'] ) ? $version['version'] : $version ) ) . ' ' . $extra_text; ?></td>
|
1167 |
+
<td><?php echo( true === $currentVersion ? 'true' : $currentVersion ); ?></td>
|
1168 |
+
<?php if ( 'filesize' === $whatType ) { ?>
|
1169 |
+
<td><?php echo( self::filesize_compare( $currentVersion, $version, $compare ) ? '<span class="mainwp-pass"><i class="fa fa-check-circle"></i> Pass</span>' : self::render_warning_text( $errorType ) ); ?></td>
|
1170 |
+
<?php } elseif ( 'get_curl_ssl_version' === $getter ) { ?>
|
1171 |
+
<td><?php echo( self::curlssl_compare( $version, $compare ) ? '<span class="mainwp-pass"><i class="fa fa-check-circle"></i> Pass</span>' : self::render_warning_text( $errorType ) ); ?></td>
|
1172 |
+
<?php } elseif ( ( 'get_max_input_time' === $getter || 'get_max_execution_time' === $getter ) && -1 == $currentVersion ) { ?>
|
1173 |
+
<td><?php echo '<span class="mainwp-pass"><i class="fa fa-check-circle"></i> Pass</span>'; ?></td>
|
1174 |
+
<?php } else { ?>
|
1175 |
+
<td><?php echo ( version_compare( $currentVersion, $version, $compare ) || ( ( null != $extra_compare ) && version_compare( $currentVersion, $extra_version, $extra_compare ) ) ? '<span class="mainwp-pass"><i class="fa fa-check-circle"></i> Pass</span>' : self::render_warning_text( $errorType ) ); ?></td>
|
1176 |
+
<?php } ?>
|
1177 |
+
</tr>
|
1178 |
+
<?php
|
1179 |
+
}
|
1180 |
+
|
1181 |
+
/**
|
1182 |
+
* Render warning text.
|
1183 |
+
*
|
1184 |
+
* @param string $errorType Error type.
|
1185 |
+
*
|
1186 |
+
* @used-by MainWP_Child_Server_Information::render_row_sec() Render the server information check secondary row.
|
1187 |
+
*
|
1188 |
+
* @return string Warning message HTML.
|
1189 |
+
*/
|
1190 |
+
public static function render_warning_text( $errorType = self::WARNING ) {
|
1191 |
+
if ( self::WARNING == $errorType ) {
|
1192 |
+
return '<span class="mainwp-warning"><i class="fa fa-exclamation-circle"></i> Warning</span>';
|
1193 |
+
}
|
1194 |
+
return '<span class="mainwp-fail"><i class="fa fa-exclamation-circle"></i> Fail</span>';
|
1195 |
+
}
|
1196 |
+
|
1197 |
+
/**
|
1198 |
+
* Render the Error log page.
|
1199 |
+
*
|
1200 |
+
* @uses MainWP_Child_Server_Information::render_error_log() Render the error log content.
|
1201 |
+
*
|
1202 |
+
* @used-by MainWP_Child_Server_Information::render_page() Rener the Server Information page.
|
1203 |
+
*
|
1204 |
+
* Credits
|
1205 |
+
*
|
1206 |
+
* Plugin-Name: Error Log Dashboard Widget
|
1207 |
+
* Plugin URI: http://wordpress.org/extend/plugins/error-log-dashboard-widget/
|
1208 |
+
* Description: Robust zero-configuration and low-memory way to keep an eye on error log.
|
1209 |
+
* Author: Andrey "Rarst" Savchenko
|
1210 |
+
* Author URI: http://www.rarst.net/
|
1211 |
+
* Version: 1.0.2
|
1212 |
+
* License: GPLv2 or later
|
1213 |
+
* Includes last_lines() function by phant0m, licensed under cc-wiki and GPLv2+
|
1214 |
+
*/
|
1215 |
+
private static function render_error_page() {
|
1216 |
+
?>
|
1217 |
+
<table id="mainwp-table" class="wp-list-table widefat" cellspacing="0">
|
1218 |
+
<thead title="Click to Toggle" style="cursor: pointer;">
|
1219 |
+
<tr>
|
1220 |
+
<th scope="col" class="manage-column column-posts" style="width: 10%"><?php esc_html_e( 'Time', 'mainwp-child' ); ?></th>
|
1221 |
+
<th scope="col" class="manage-column column-posts"><?php esc_html_e( 'Error', 'mainwp-child' ); ?></th>
|
1222 |
+
</tr>
|
1223 |
+
</thead>
|
1224 |
+
<tbody class="list:sites" id="mainwp-error-log-table">
|
1225 |
+
<?php self::render_error_log(); ?>
|
1226 |
+
</tbody>
|
1227 |
+
</table>
|
1228 |
+
<?php
|
1229 |
+
}
|
1230 |
+
|
1231 |
+
/**
|
1232 |
+
* Render the error log content.
|
1233 |
+
*
|
1234 |
+
* @uses MainWP_Child_Server_Information::render_last_lines() Render the error log last lines.
|
1235 |
+
* @uses wp_kses_post() Sanitizes content for allowed HTML tags for post content.
|
1236 |
+
* @see https://developer.wordpress.org/reference/functions/wp_kses_post/
|
1237 |
+
*
|
1238 |
+
* @used-by MainWP_Child_Server_Information::render_error_page() Render the Error log page.
|
1239 |
+
*
|
1240 |
+
* @uses \MainWP\Child\MainWP_Child_Branding::get_branding_title()
|
1241 |
+
*/
|
1242 |
+
public static function render_error_log() {
|
1243 |
+
$log_errors = ini_get( 'log_errors' );
|
1244 |
+
if ( ! $log_errors ) {
|
1245 |
+
echo '<tr><td colspan="2">' . esc_html__( 'Error logging disabled.', 'mainwp-child' ) . '</td></tr>';
|
1246 |
+
}
|
1247 |
+
|
1248 |
+
$error_log = ini_get( 'error_log' );
|
1249 |
+
$logs = apply_filters( 'error_log_mainwp_logs', array( $error_log ) );
|
1250 |
+
$count = apply_filters( 'error_log_mainwp_lines', 10 );
|
1251 |
+
$lines = array();
|
1252 |
+
|
1253 |
+
foreach ( $logs as $log ) {
|
1254 |
+
if ( is_readable( $log ) ) {
|
1255 |
+
$lines = array_merge( $lines, self::render_last_lines( $log, $count ) );
|
1256 |
+
}
|
1257 |
+
}
|
1258 |
+
|
1259 |
+
$lines = array_map( 'trim', $lines );
|
1260 |
+
$lines = array_filter( $lines );
|
1261 |
+
|
1262 |
+
if ( empty( $lines ) ) {
|
1263 |
+
$branding_title = MainWP_Child_Branding::instance()->get_branding_title();
|
1264 |
+
if ( '' == $branding_title ) {
|
1265 |
+
$branding_title = 'MainWP';
|
1266 |
+
}
|
1267 |
+
$msg = esc_html( stripslashes( $branding_title ) ) . ' is unable to find your error logs, please contact your host for server error logs.';
|
1268 |
+
echo '<tr><td colspan="2">' . $msg . '</td></tr>';
|
1269 |
+
return;
|
1270 |
+
}
|
1271 |
+
|
1272 |
+
foreach ( $lines as $key => $line ) {
|
1273 |
+
|
1274 |
+
if ( false !== strpos( $line, ']' ) ) {
|
1275 |
+
list( $time, $error ) = explode( ']', $line, 2 );
|
1276 |
+
} else {
|
1277 |
+
list( $time, $error ) = array( '', $line );
|
1278 |
+
}
|
1279 |
+
|
1280 |
+
$time = trim( $time, '[]' );
|
1281 |
+
$error = trim( $error );
|
1282 |
+
$lines[ $key ] = compact( 'time', 'error' );
|
1283 |
+
}
|
1284 |
+
|
1285 |
+
if ( is_array( $error_log ) && count( $error_log ) > 1 ) {
|
1286 |
+
|
1287 |
+
uasort( $lines, array( __CLASS__, 'time_compare' ) );
|
1288 |
+
$lines = array_slice( $lines, 0, $count );
|
1289 |
+
}
|
1290 |
+
|
1291 |
+
foreach ( $lines as $line ) {
|
1292 |
+
|
1293 |
+
$error = esc_html( $line['error'] );
|
1294 |
+
$time = esc_html( $line['time'] );
|
1295 |
+
|
1296 |
+
if ( ! empty( $error ) ) {
|
1297 |
+
echo wp_kses_post( "<tr><td>{$time}</td><td>{$error}</td></tr>" );
|
1298 |
+
}
|
1299 |
+
}
|
1300 |
+
}
|
1301 |
+
|
1302 |
+
/**
|
1303 |
+
* Render the error log last lines.
|
1304 |
+
*
|
1305 |
+
* @param string $path Error log path.
|
1306 |
+
* @param int $line_count Line count.
|
1307 |
+
* @param int $block_size Block size.
|
1308 |
+
*
|
1309 |
+
* @return array Selected number of error log records to show.
|
1310 |
+
*/
|
1311 |
+
protected static function render_last_lines( $path, $line_count, $block_size = 512 ) {
|
1312 |
+
$lines = array();
|
1313 |
+
|
1314 |
+
// we will always have a fragment of a non-complete line.
|
1315 |
+
// keep this in here till we have our next entire line.
|
1316 |
+
$leftover = '';
|
1317 |
+
|
1318 |
+
// phpcs:disable WordPress.WP.AlternativeFunctions -- to custom read file.
|
1319 |
+
$fh = fopen( $path, 'r' );
|
1320 |
+
// go to the end of the file.
|
1321 |
+
fseek( $fh, 0, SEEK_END );
|
1322 |
+
|
1323 |
+
$count_lines = 0;
|
1324 |
+
do {
|
1325 |
+
// need to know whether we can actually go back.
|
1326 |
+
$can_read = $block_size;
|
1327 |
+
|
1328 |
+
if ( ftell( $fh ) <= $block_size ) {
|
1329 |
+
$can_read = ftell( $fh );
|
1330 |
+
}
|
1331 |
+
|
1332 |
+
if ( empty( $can_read ) ) {
|
1333 |
+
break;
|
1334 |
+
}
|
1335 |
+
|
1336 |
+
// go back as many bytes as we can.
|
1337 |
+
// read them to $data and then move the file pointer.
|
1338 |
+
// back to where we were.
|
1339 |
+
fseek( $fh, - $can_read, SEEK_CUR );
|
1340 |
+
$data = fread( $fh, $can_read );
|
1341 |
+
$data .= $leftover;
|
1342 |
+
fseek( $fh, - $can_read, SEEK_CUR );
|
1343 |
+
|
1344 |
+
// split lines by \n. Then reverse them, now the last line is most likely not a complete line which is why we do not directly add it, but append it to the data read the next time.
|
1345 |
+
$split_data = array_reverse( explode( "\n", $data ) );
|
1346 |
+
$new_lines = array_slice( $split_data, 0, - 1 );
|
1347 |
+
$lines = array_merge( $lines, $new_lines );
|
1348 |
+
$leftover = $split_data[ count( $split_data ) - 1 ];
|
1349 |
+
$count_lines = count( $lines );
|
1350 |
+
} while ( $count_lines < $line_count && 0 !== ftell( $fh ) );
|
1351 |
+
|
1352 |
+
if ( 0 === ftell( $fh ) ) {
|
1353 |
+
$lines[] = $leftover;
|
1354 |
+
}
|
1355 |
+
|
1356 |
+
fclose( $fh );
|
1357 |
+
|
1358 |
+
// phpcs:enable
|
1359 |
+
|
1360 |
+
// Usually, we will read too many lines, correct that here.
|
1361 |
+
return array_slice( $lines, 0, $line_count );
|
1362 |
+
}
|
1363 |
+
|
1364 |
+
/**
|
1365 |
+
* Render the connection details page content.
|
1366 |
+
*
|
1367 |
+
* @uses \MainWP\Child\MainWP_Child_Branding::get_branding_title()
|
1368 |
+
*/
|
1369 |
+
public static function render_connection_details() {
|
1370 |
+
$branding_title = MainWP_Child_Branding::instance()->get_branding_title();
|
1371 |
+
if ( '' == $branding_title ) {
|
1372 |
+
$branding_title = 'MainWP';
|
1373 |
+
}
|
1374 |
+
|
1375 |
+
/**
|
1376 |
+
* Current user global.
|
1377 |
+
*
|
1378 |
+
* @global string
|
1379 |
+
*/
|
1380 |
+
global $current_user;
|
1381 |
+
|
1382 |
+
$uniqueId = MainWP_Helper::get_site_unique_id();
|
1383 |
+
$details = array(
|
1384 |
+
'siteurl' => array(
|
1385 |
+
'title' => __( 'Site URL', 'mainwp-child' ),
|
1386 |
+
'value' => get_bloginfo( 'url' ),
|
1387 |
+
'desc' => get_bloginfo( 'url' ),
|
1388 |
+
),
|
1389 |
+
'adminuser' => array(
|
1390 |
+
'title' => __( 'Administrator name', 'mainwp-child' ),
|
1391 |
+
'value' => $current_user->user_login,
|
1392 |
+
'desc' => __( 'This is your Administrator username, however, you can use any existing Administrator username.', 'mainwp-child' ),
|
1393 |
+
),
|
1394 |
+
'friendly_name' => array(
|
1395 |
+
'title' => __( 'Friendly site name', 'mainwp-child' ),
|
1396 |
+
'value' => get_bloginfo( 'name' ),
|
1397 |
+
'desc' => __( 'For the friendly site name, you can use any name, this is just a suggestion.', 'mainwp-child' ),
|
1398 |
+
),
|
1399 |
+
'uniqueid' => array(
|
1400 |
+
'title' => __( 'Child unique security id', 'mainwp-child' ),
|
1401 |
+
'value' => ! empty( $uniqueId ) ? $uniqueId : __( 'Leave the field blank', 'mainwp-child' ),
|
1402 |
+
'desc' => sprintf( __( 'Child unique security id is not required, however, since you have enabled it, you need to add it to your %s dashboard.', 'mainwp-child' ), stripslashes( $branding_title ) ),
|
1403 |
+
),
|
1404 |
+
'verify_ssl' => array(
|
1405 |
+
'title' => __( 'Verify certificate', 'mainwp-child' ),
|
1406 |
+
'value' => __( 'Yes', 'mainwp-child' ),
|
1407 |
+
'desc' => __( 'If there is an issue with SSL certificate on this site, try to set this option to No.', 'mainwp-child' ),
|
1408 |
+
),
|
1409 |
+
'ssl_version' => array(
|
1410 |
+
'title' => __( 'SSL version', 'mainwp-child' ),
|
1411 |
+
'value' => __( 'Auto Detect', 'mainwp-child' ),
|
1412 |
+
'desc' => __( 'Auto Detect', 'mainwp-child' ),
|
1413 |
+
),
|
1414 |
+
|
1415 |
+
);
|
1416 |
+
?>
|
1417 |
+
<div class="postbox" id="connection_detail">
|
1418 |
+
<h3 class="mainwp_box_title"><span><?php _e( 'Connection details', 'mainwp-child' ); ?></span></h3>
|
1419 |
+
<div class="inside">
|
1420 |
+
<div class="mainwp-postbox-actions-top mainwp-padding-5">
|
1421 |
+
<?php echo sprintf( __( 'If you are trying to connect this child site to your %s Dashboard, you can use following details to do that. Please note that these are only suggested values.', 'mainwp-child' ), stripslashes( $branding_title ) ); ?>
|
1422 |
+
</div>
|
1423 |
+
<table id="mainwp-table" class="wp-list-table widefat" cellspacing="0" style="border: 0">
|
1424 |
+
<tbody>
|
1425 |
+
<?php
|
1426 |
+
foreach ( $details as $row ) {
|
1427 |
+
?>
|
1428 |
+
<tr>
|
1429 |
+
<th style="width: 20%"><strong><?php echo esc_html( $row['title'] ); ?></strong></th>
|
1430 |
+
<td style="width: 20%"><strong><?php echo esc_html( $row['value'] ); ?></strong></td>
|
1431 |
+
<td><?php echo esc_html( $row['desc'] ); ?></td>
|
1432 |
+
</tr>
|
1433 |
+
<?php
|
1434 |
+
}
|
1435 |
+
?>
|
1436 |
+
</tbody>
|
1437 |
+
</table>
|
1438 |
+
</div>
|
1439 |
+
</div>
|
1440 |
+
<?php
|
1441 |
+
}
|
1442 |
+
|
1443 |
+
}
|
class/class-mainwp-child-stats.php
CHANGED
@@ -1,1072 +1,1072 @@
|
|
1 |
-
<?php
|
2 |
-
/**
|
3 |
-
* MainWP Child Stats.
|
4 |
-
*
|
5 |
-
* Gather the child site data to send to the MainWP Dashboard.
|
6 |
-
*
|
7 |
-
* @package MainWP\Child
|
8 |
-
*/
|
9 |
-
|
10 |
-
namespace MainWP\Child;
|
11 |
-
|
12 |
-
//phpcs:disable Generic.Metrics.CyclomaticComplexity -- Required to achieve desired results, pull request solutions appreciated.
|
13 |
-
|
14 |
-
/**
|
15 |
-
* Class MainWP_Child_Stats
|
16 |
-
*
|
17 |
-
* Gather the child site data to send to the MainWP Dashboard.
|
18 |
-
*/
|
19 |
-
class MainWP_Child_Stats {
|
20 |
-
|
21 |
-
/**
|
22 |
-
* Public static variable to hold the single instance of the class.
|
23 |
-
*
|
24 |
-
* @var mixed Default null
|
25 |
-
*/
|
26 |
-
protected static $instance = null;
|
27 |
-
|
28 |
-
/**
|
29 |
-
* Class used to represent anonymous functions.
|
30 |
-
*
|
31 |
-
* @var null
|
32 |
-
*/
|
33 |
-
private $filterFunction = null;
|
34 |
-
|
35 |
-
/**
|
36 |
-
* Method get_class_name()
|
37 |
-
*
|
38 |
-
* Get class name.
|
39 |
-
*
|
40 |
-
* @return string __CLASS__ Class name.
|
41 |
-
*/
|
42 |
-
public static function get_class_name() {
|
43 |
-
return __CLASS__;
|
44 |
-
}
|
45 |
-
|
46 |
-
/**
|
47 |
-
* MainWP_Child_Stats constructor.
|
48 |
-
*
|
49 |
-
* Run any time class is called.
|
50 |
-
*/
|
51 |
-
public function __construct() {
|
52 |
-
|
53 |
-
/**
|
54 |
-
* Checks if 'last_checked'.
|
55 |
-
*
|
56 |
-
* @param $a Object to check.
|
57 |
-
* @return object|bool $a Return object or FALSE on failure.
|
58 |
-
*/
|
59 |
-
$this->filterFunction = function( $a ) {
|
60 |
-
if ( null == $a ) {
|
61 |
-
return false; }
|
62 |
-
if ( is_object( $a ) && property_exists( $a, 'last_checked' ) && ! property_exists( $a, 'checked' ) ) {
|
63 |
-
return false;
|
64 |
-
}
|
65 |
-
return $a;
|
66 |
-
};
|
67 |
-
}
|
68 |
-
|
69 |
-
/**
|
70 |
-
* Method get_instance()
|
71 |
-
*
|
72 |
-
* Create a public static instance.
|
73 |
-
*
|
74 |
-
* @return mixed Class instance.
|
75 |
-
*/
|
76 |
-
public static function get_instance() {
|
77 |
-
if ( null === self::$instance ) {
|
78 |
-
self::$instance = new self();
|
79 |
-
}
|
80 |
-
|
81 |
-
return self::$instance;
|
82 |
-
}
|
83 |
-
|
84 |
-
/**
|
85 |
-
* Show stats without login. only allowed while no account is added yet.
|
86 |
-
*
|
87 |
-
* @param array $information Child Site Stats.
|
88 |
-
*
|
89 |
-
* @uses \MainWP\Child\MainWP_Child::$version
|
90 |
-
* @uses \MainWP\Child\MainWP_Helper::is_wp_engine()
|
91 |
-
* @uses \MainWP\Child\MainWP_Helper::write()
|
92 |
-
*/
|
93 |
-
public function get_site_stats_no_auth( $information = array() ) {
|
94 |
-
if ( get_option( 'mainwp_child_pubkey' ) ) {
|
95 |
-
$hint = '<br/>' . __( 'Hint: Go to the child site, deactivate and reactivate the MainWP Child plugin and try again.', 'mainwp-child' );
|
96 |
-
MainWP_Helper::instance()->error( __( 'This site already contains a link. Please deactivate and reactivate the MainWP plugin.', 'mainwp-child' ) . $hint );
|
97 |
-
}
|
98 |
-
|
99 |
-
/**
|
100 |
-
* The installed version of WordPress.
|
101 |
-
*
|
102 |
-
* @global string $wp_version The installed version of WordPress.
|
103 |
-
*
|
104 |
-
* @uses \MainWP\Child\MainWP_Child::$version
|
105 |
-
* @uses \MainWP\Child\MainWP_Helper::write()
|
106 |
-
*/
|
107 |
-
global $wp_version;
|
108 |
-
|
109 |
-
$information['version'] = MainWP_Child::$version;
|
110 |
-
$information['wpversion'] = $wp_version;
|
111 |
-
$information['wpe'] = MainWP_Helper::is_wp_engine() ? 1 : 0;
|
112 |
-
MainWP_Helper::write( $information );
|
113 |
-
}
|
114 |
-
|
115 |
-
/**
|
116 |
-
* Check if ManageWP is installed.
|
117 |
-
*
|
118 |
-
* @param array $default Active plugins.
|
119 |
-
* @return array $default Active plugins array with managewp/init.php appended.
|
120 |
-
*/
|
121 |
-
public function default_option_active_plugins( $default ) {
|
122 |
-
if ( ! is_array( $default ) ) {
|
123 |
-
$default = array();
|
124 |
-
}
|
125 |
-
if ( ! in_array( 'managewp/init.php', $default ) ) {
|
126 |
-
$default[] = 'managewp/init.php';
|
127 |
-
}
|
128 |
-
|
129 |
-
return $default;
|
130 |
-
}
|
131 |
-
|
132 |
-
/**
|
133 |
-
* Get Child Site Stats.
|
134 |
-
*
|
135 |
-
* @param array $information Holder for return array.
|
136 |
-
* @param bool $exit Whether or not to exit the method. Default: true.
|
137 |
-
*
|
138 |
-
* @return array $information Child Site Stats.
|
139 |
-
*
|
140 |
-
* @uses \MainWP\Child\MainWP_Child_Stats::update_external_settings()
|
141 |
-
* @uses \MainWP\Child\MainWP_Child_Stats::stats_get_info()
|
142 |
-
* @uses \MainWP\Child\MainWP_Child_Stats::stats_wp_update()
|
143 |
-
* @uses \MainWP\Child\MainWP_Child_Stats::stats_plugin_update()
|
144 |
-
* @uses \MainWP\Child\MainWP_Child_Stats::stats_theme_update()
|
145 |
-
* @uses \MainWP\Child\MainWP_Child_Stats::stats_translation_updates()
|
146 |
-
* @uses \MainWP\Child\MainWP_Child_Stats::get_recent_number()
|
147 |
-
* @uses \MainWP\Child\MainWP_Child_Stats::scan_dir()
|
148 |
-
* @uses \MainWP\Child\MainWP_Child_Stats::stats_get_categories()
|
149 |
-
* @uses \MainWP\Child\MainWP_Child_Stats::stats_get_total_size()
|
150 |
-
* @uses \MainWP\Child\MainWP_Child_Stats::get_all_plugins_int()
|
151 |
-
* @uses \MainWP\Child\MainWP_Child_Stats::get_all_themes_int()
|
152 |
-
* @uses \MainWP\Child\MainWP_Child_Stats::get_health_check_site_status()
|
153 |
-
* @uses \MainWP\Child\MainWP_Child_Stats::stats_others_data()
|
154 |
-
* @uses \MainWP\Child\MainWP_Child_Stats::check_premium_updates()
|
155 |
-
* @uses \MainWP\Child\MainWP_Child_Branding::save_branding_options()
|
156 |
-
* @uses \MainWP\Child\MainWP_Child_Plugins_Check::may_outdate_number_change()
|
157 |
-
* @uses \MainWP\Child\MainWP_Child_Comments::get_recent_comments()
|
158 |
-
* @uses \MainWP\Child\MainWP_Child_Posts::get_recent_posts()
|
159 |
-
* @uses \MainWP\Child\MainWP_Child_DB::get_size()
|
160 |
-
* @uses \MainWP\Child\MainWP_Child_Users:::get_all_users_int()
|
161 |
-
* @uses \MainWP\Child\MainWP_Child_Plugins_Check::get_plugins_outdate_info()
|
162 |
-
* @uses \MainWP\Child\MainWP_Child_Themes_Check::get_themes_outdate_info()
|
163 |
-
* @uses \MainWP\Child\MainWP_Security::get_stats_security()
|
164 |
-
* @uses \MainWP\Child\MainWP_Connect::instance()::get_max_history()
|
165 |
-
* @uses \MainWP\Child\MainWP_Utility::get_lasttime_backup()
|
166 |
-
* @uses \MainWP\Child\MainWP_Utility::validate_mainwp_dir()
|
167 |
-
* @uses \MainWP\Child\MainWP_Helper::update_option()
|
168 |
-
* @uses \MainWP\Child\MainWP_Helper::set_limit()
|
169 |
-
* @uses \MainWP\Child\MainWP_Helper::log_debug()
|
170 |
-
* @uses \MainWP\Child\MainWP_Helper::write()
|
171 |
-
* @uses \MainWP\Child\MainWP_Child_Branding::save_branding_options()
|
172 |
-
* @uses \MainWP\Child\MainWP_Child_Comments::get_recent_comments()
|
173 |
-
* @uses \MainWP\Child\MainWP_Child_DB::get_size()
|
174 |
-
* @uses \MainWP\Child\MainWP_Child_Misc::get_security_stats()
|
175 |
-
* @uses \MainWP\Child\MainWP_Child_Plugins_Check::may_outdate_number_change()
|
176 |
-
* @uses \MainWP\Child\MainWP_Child_Plugins_Check::get_plugins_outdate_info()
|
177 |
-
* @uses \MainWP\Child\MainWP_Child_Posts::get_all_posts()
|
178 |
-
* @uses \MainWP\Child\MainWP_Child_Themes_Check::get_themes_outdate_info()
|
179 |
-
* @uses \MainWP\Child\MainWP_Child_Users::get_all_users_int()
|
180 |
-
* @uses \MainWP\Child\MainWP_Connect::get_max_history()
|
181 |
-
*/
|
182 |
-
public function get_site_stats( $information = array(), $exit = true ) {
|
183 |
-
|
184 |
-
if ( $exit ) {
|
185 |
-
$this->update_external_settings();
|
186 |
-
}
|
187 |
-
|
188 |
-
MainWP_Child_Branding::instance()->save_branding_options( 'branding_disconnected', '' );
|
189 |
-
if ( isset( $_POST['server'] ) ) {
|
190 |
-
MainWP_Helper::update_option( 'mainwp_child_server', ! empty( $_POST['server'] ) ? wp_unslash( $_POST['server'] ) : '' );
|
191 |
-
}
|
192 |
-
|
193 |
-
MainWP_Child_Plugins_Check::may_outdate_number_change();
|
194 |
-
|
195 |
-
$this->stats_get_info( $information );
|
196 |
-
|
197 |
-
include_once ABSPATH . '/wp-admin/includes/update.php';
|
198 |
-
|
199 |
-
$timeout = 3 * 60 * 60;
|
200 |
-
MainWP_Helper::set_limit( $timeout );
|
201 |
-
|
202 |
-
// Check for new versions.
|
203 |
-
$information['wp_updates'] = $this->stats_wp_update();
|
204 |
-
|
205 |
-
add_filter( 'default_option_active_plugins', array( &$this, 'default_option_active_plugins' ) );
|
206 |
-
add_filter( 'option_active_plugins', array( &$this, 'default_option_active_plugins' ) );
|
207 |
-
|
208 |
-
$premiumPlugins = array();
|
209 |
-
$premiumThemes = array();
|
210 |
-
|
211 |
-
// First check for new premium updates.
|
212 |
-
$this->check_premium_updates( $information, $premiumPlugins, $premiumThemes );
|
213 |
-
|
214 |
-
remove_filter( 'default_option_active_plugins', array( &$this, 'default_option_active_plugins' ) );
|
215 |
-
remove_filter( 'option_active_plugins', array( &$this, 'default_option_active_plugins' ) );
|
216 |
-
|
217 |
-
$information['plugin_updates'] = $this->stats_plugin_update( $premiumPlugins );
|
218 |
-
|
219 |
-
$information['theme_updates'] = $this->stats_theme_update( $premiumThemes );
|
220 |
-
|
221 |
-
$information['translation_updates'] = $this->stats_translation_updates();
|
222 |
-
|
223 |
-
$information['recent_comments'] = MainWP_Child_Comments::get_instance()->get_recent_comments( array( 'approve', 'hold' ), 5 );
|
224 |
-
|
225 |
-
$recent_number = $this->get_recent_number();
|
226 |
-
|
227 |
-
$information['recent_posts'] = MainWP_Child_Posts::get_instance()->get_recent_posts( array( 'publish', 'draft', 'pending', 'trash', 'future' ), $recent_number );
|
228 |
-
$information['recent_pages'] = MainWP_Child_Posts::get_instance()->get_recent_posts( array( 'publish', 'draft', 'pending', 'trash', 'future' ), $recent_number, 'page' );
|
229 |
-
$information['securityIssues'] = MainWP_Security::get_stats_security();
|
230 |
-
$information['securityStats'] = MainWP_Child_Misc::get_instance()->get_security_stats( true );
|
231 |
-
|
232 |
-
// Directory listings!
|
233 |
-
$information['directories'] = isset( $_POST['scan_dir'] ) && ! empty( $_POST['scan_dir'] ) ? $this->scan_dir( ABSPATH, 3 ) : '';
|
234 |
-
$information['categories'] = $this->stats_get_categories();
|
235 |
-
|
236 |
-
$totalsize = $this->stats_get_total_size();
|
237 |
-
if ( ! empty( $totalsize ) ) {
|
238 |
-
$information['totalsize'] = $totalsize;
|
239 |
-
}
|
240 |
-
|
241 |
-
$information['dbsize'] = MainWP_Child_DB::get_size();
|
242 |
-
|
243 |
-
$max_his = MainWP_Connect::instance()->get_max_history();
|
244 |
-
$auths = get_option( 'mainwp_child_auth' );
|
245 |
-
$information['extauth'] = ( $auths && isset( $auths[ $max_his ] ) ? $auths[ $max_his ] : null );
|
246 |
-
|
247 |
-
$information['plugins'] = $this->get_all_plugins_int( false );
|
248 |
-
$information['themes'] = $this->get_all_themes_int( false );
|
249 |
-
|
250 |
-
if ( isset( $_POST['optimize'] ) && ( '1' == $_POST['optimize'] ) ) {
|
251 |
-
$information['users'] = MainWP_Child_Users::get_instance()->get_all_users_int( 500 );
|
252 |
-
}
|
253 |
-
|
254 |
-
if ( ! empty( $_POST['primaryBackup'] ) ) {
|
255 |
-
$primary_bk = ! empty( $_POST['primaryBackup'] ) ? sanitize_text_field( wp_unslash( $_POST['primaryBackup'] ) ) : '';
|
256 |
-
$information['primaryLasttimeBackup'] = MainWP_Utility::get_lasttime_backup( $primary_bk );
|
257 |
-
}
|
258 |
-
|
259 |
-
$last_post = wp_get_recent_posts( array( 'numberposts' => absint( '1' ) ) );
|
260 |
-
if ( isset( $last_post[0] ) ) {
|
261 |
-
$last_post = $last_post[0];
|
262 |
-
}
|
263 |
-
if ( isset( $last_post ) && isset( $last_post['post_modified_gmt'] ) ) {
|
264 |
-
$information['last_post_gmt'] = strtotime( $last_post['post_modified_gmt'] );
|
265 |
-
}
|
266 |
-
$information['mainwpdir'] = ( MainWP_Utility::validate_mainwp_dir() ? 1 : - 1 );
|
267 |
-
$information['uniqueId'] = MainWP_Helper::get_site_unique_id();
|
268 |
-
$information['plugins_outdate_info'] = MainWP_Child_Plugins_Check::instance()->get_plugins_outdate_info();
|
269 |
-
$information['themes_outdate_info'] = MainWP_Child_Themes_Check::instance()->get_themes_outdate_info();
|
270 |
-
$information['health_site_status'] = $this->get_health_check_site_status();
|
271 |
-
|
272 |
-
if ( isset( $_POST['user'] ) ) {
|
273 |
-
$user = get_user_by( 'login', sanitize_text_field( wp_unslash( $_POST['user'] ) ) );
|
274 |
-
if ( $user && property_exists( $user, 'ID' ) && $user->ID ) {
|
275 |
-
$information['admin_nicename'] = $user->data->user_nicename;
|
276 |
-
$information['admin_useremail'] = $user->data->user_email;
|
277 |
-
}
|
278 |
-
}
|
279 |
-
|
280 |
-
try {
|
281 |
-
do_action( 'mainwp_child_site_stats' );
|
282 |
-
} catch ( \Exception $e ) {
|
283 |
-
MainWP_Helper::log_debug( $e->getMessage() );
|
284 |
-
}
|
285 |
-
|
286 |
-
if ( isset( $_POST['othersData'] ) ) {
|
287 |
-
$this->stats_others_data( $information );
|
288 |
-
}
|
289 |
-
|
290 |
-
if ( $exit ) {
|
291 |
-
MainWP_Helper::write( $information );
|
292 |
-
}
|
293 |
-
|
294 |
-
return $information;
|
295 |
-
}
|
296 |
-
|
297 |
-
/**
|
298 |
-
* Get other stats data.
|
299 |
-
*
|
300 |
-
* @param array $information Child Site Stats array.
|
301 |
-
*
|
302 |
-
* @uses \MainWP\Child\MainWP_Helper::update_option()
|
303 |
-
* @uses \MainWP\Child\MainWP_Helper::log_debug()
|
304 |
-
*/
|
305 |
-
private function stats_others_data( &$information ) {
|
306 |
-
|
307 |
-
$othersData = isset( $_POST['othersData'] ) ? json_decode( stripslashes( wp_unslash( $_POST['othersData'] ) ), true ) : array();
|
308 |
-
if ( ! is_array( $othersData ) ) {
|
309 |
-
$othersData = array();
|
310 |
-
}
|
311 |
-
|
312 |
-
if ( isset( $othersData['wpvulndbToken'] ) ) {
|
313 |
-
$wpvulndb_token = get_option( 'mainwp_child_wpvulndb_token', '' );
|
314 |
-
if ( $wpvulndb_token != $othersData['wpvulndbToken'] ) {
|
315 |
-
MainWP_Helper::update_option( 'mainwp_child_wpvulndb_token', $othersData['wpvulndbToken'] );
|
316 |
-
}
|
317 |
-
}
|
318 |
-
|
319 |
-
try {
|
320 |
-
$information = apply_filters_deprecated( 'mainwp-site-sync-others-data', array( $information, $othersData ), '4.0.7.1', 'mainwp_site_sync_others_data' );
|
321 |
-
$information = apply_filters( 'mainwp_site_sync_others_data', $information, $othersData );
|
322 |
-
|
323 |
-
} catch ( \Exception $e ) {
|
324 |
-
MainWP_Helper::log_debug( $e->getMessage() );
|
325 |
-
}
|
326 |
-
}
|
327 |
-
|
328 |
-
/**
|
329 |
-
* Translation update stats.
|
330 |
-
*
|
331 |
-
* @return array $results Returned results.
|
332 |
-
*/
|
333 |
-
private function stats_translation_updates() {
|
334 |
-
$results = array();
|
335 |
-
|
336 |
-
$translation_updates = wp_get_translation_updates();
|
337 |
-
if ( ! empty( $translation_updates ) ) {
|
338 |
-
foreach ( $translation_updates as $translation_update ) {
|
339 |
-
$new_translation_update = array(
|
340 |
-
'type' => $translation_update->type,
|
341 |
-
'slug' => $translation_update->slug,
|
342 |
-
'language' => $translation_update->language,
|
343 |
-
'version' => $translation_update->version,
|
344 |
-
);
|
345 |
-
if ( 'plugin' === $translation_update->type ) {
|
346 |
-
$all_plugins = get_plugins();
|
347 |
-
foreach ( $all_plugins as $file => $plugin ) {
|
348 |
-
$path = dirname( $file );
|
349 |
-
if ( $path == $translation_update->slug ) {
|
350 |
-
$new_translation_update['name'] = $plugin['Name'];
|
351 |
-
break;
|
352 |
-
}
|
353 |
-
}
|
354 |
-
} elseif ( 'theme' === $translation_update->type ) {
|
355 |
-
$theme = wp_get_theme( $translation_update->slug );
|
356 |
-
$new_translation_update['name'] = $theme->name;
|
357 |
-
} elseif ( ( 'core' === $translation_update->type ) && ( 'default' === $translation_update->slug ) ) {
|
358 |
-
$new_translation_update['name'] = 'WordPress core';
|
359 |
-
}
|
360 |
-
|
361 |
-
$results[] = $new_translation_update;
|
362 |
-
}
|
363 |
-
}
|
364 |
-
return $results;
|
365 |
-
}
|
366 |
-
|
367 |
-
/**
|
368 |
-
* Premium theme update stats.
|
369 |
-
*
|
370 |
-
* @param array $premiumThemes Array of premium themes.
|
371 |
-
*
|
372 |
-
* @return array $results Array of premium theme slugs.
|
373 |
-
*
|
374 |
-
* @uses MainWP_Child_Updates::get_instance()::upgrade_get_theme_updates()
|
375 |
-
* @uses \MainWP\Child\MainWP_Child_Updates::upgrade_get_theme_updates()
|
376 |
-
*/
|
377 |
-
private function stats_theme_update( $premiumThemes ) {
|
378 |
-
|
379 |
-
$results = array();
|
380 |
-
|
381 |
-
if ( null !== $this->filterFunction ) {
|
382 |
-
add_filter( 'pre_site_transient_update_themes', $this->filterFunction, 99 );
|
383 |
-
}
|
384 |
-
|
385 |
-
wp_update_themes();
|
386 |
-
include_once ABSPATH . '/wp-admin/includes/theme.php';
|
387 |
-
$theme_updates = MainWP_Child_Updates::get_instance()->upgrade_get_theme_updates();
|
388 |
-
if ( is_array( $theme_updates ) ) {
|
389 |
-
foreach ( $theme_updates as $slug => $theme_update ) {
|
390 |
-
$name = ( is_array( $theme_update ) ? $theme_update['Name'] : $theme_update->Name );
|
391 |
-
if ( in_array( $name, $premiumThemes ) ) {
|
392 |
-
continue;
|
393 |
-
}
|
394 |
-
$results[ $slug ] = $theme_update;
|
395 |
-
}
|
396 |
-
}
|
397 |
-
if ( null !== $this->filterFunction ) {
|
398 |
-
remove_filter( 'pre_site_transient_update_themes', $this->filterFunction, 99 );
|
399 |
-
}
|
400 |
-
|
401 |
-
// Fixes premium themes update.
|
402 |
-
$cached_themes_update = get_site_transient( 'mainwp_update_themes_cached' );
|
403 |
-
if ( is_array( $cached_themes_update ) && ( count( $cached_themes_update ) > 0 ) ) {
|
404 |
-
|
405 |
-
foreach ( $cached_themes_update as $slug => $theme_update ) {
|
406 |
-
$name = ( is_array( $theme_update ) ? $theme_update['Name'] : $theme_update->Name );
|
407 |
-
if ( in_array( $name, $premiumThemes ) ) {
|
408 |
-
continue;
|
409 |
-
}
|
410 |
-
if ( isset( $results[ $slug ] ) ) {
|
411 |
-
continue;
|
412 |
-
}
|
413 |
-
$results[ $slug ] = $theme_update;
|
414 |
-
}
|
415 |
-
}
|
416 |
-
|
417 |
-
return $results;
|
418 |
-
}
|
419 |
-
|
420 |
-
/**
|
421 |
-
* Get Server Info stats & append to end of Child Site stats.
|
422 |
-
*
|
423 |
-
* @param array $information Child Site Stats.
|
424 |
-
*
|
425 |
-
* @uses MainWP_Child::$version
|
426 |
-
* @uses MainWP_Child_Server_Information::get_php_memory_limit()
|
427 |
-
* @uses MainWP_Child_Server_Information::get_my_sql_version()
|
428 |
-
* @uses MainWP_Helper::is_wp_engine()
|
429 |
-
* @uses MainWP_Helper::update_option()
|
430 |
-
* @uses phpversion()
|
431 |
-
* @uses \MainWP\Child\MainWP_Child::$version
|
432 |
-
* @uses \MainWP\Child\MainWP_Child_Server_Information::get_php_memory_limit()
|
433 |
-
* @uses \MainWP\Child\MainWP_Child_Server_Information::get_my_sql_version()
|
434 |
-
*/
|
435 |
-
private function stats_get_info( &$information ) {
|
436 |
-
|
437 |
-
/**
|
438 |
-
* The installed version of WordPress.
|
439 |
-
*
|
440 |
-
* @global string $wp_version The installed version of WordPress.
|
441 |
-
*
|
442 |
-
* @uses \MainWP\Child\MainWP_Child::$version
|
443 |
-
* @uses \MainWP\Child\MainWP_Helper::is_wp_engine()
|
444 |
-
* @uses \MainWP\Child\MainWP_Helper::is_ssl_enabled()
|
445 |
-
* @uses \MainWP\Child\MainWP_Helper::update_option()
|
446 |
-
*/
|
447 |
-
global $wp_version;
|
448 |
-
|
449 |
-
$information['version'] = MainWP_Child::$version;
|
450 |
-
$information['wpversion'] = $wp_version;
|
451 |
-
$information['siteurl'] = get_option( 'siteurl' );
|
452 |
-
$information['wpe'] = MainWP_Helper::is_wp_engine() ? 1 : 0;
|
453 |
-
$theme_name = wp_get_theme()->get( 'Name' );
|
454 |
-
$information['site_info'] = array(
|
455 |
-
'wpversion' => $wp_version,
|
456 |
-
'debug_mode' => ( defined( 'WP_DEBUG' ) && true === WP_DEBUG ) ? true : false,
|
457 |
-
'phpversion' => phpversion(),
|
458 |
-
'child_version' => MainWP_Child::$version,
|
459 |
-
'memory_limit' => MainWP_Child_Server_Information::get_php_memory_limit(),
|
460 |
-
'mysql_version' => MainWP_Child_Server_Information::get_my_sql_version(),
|
461 |
-
'themeactivated' => $theme_name,
|
462 |
-
'ip' => isset( $_SERVER['SERVER_ADDR'] ) ? wp_unslash( $_SERVER['SERVER_ADDR'] ) : '',
|
463 |
-
);
|
464 |
-
|
465 |
-
// Try to switch to SSL if SSL is enabled in between.
|
466 |
-
$pubkey = get_option( 'mainwp_child_pubkey' );
|
467 |
-
$nossl = get_option( 'mainwp_child_nossl' );
|
468 |
-
if ( 1 == $nossl ) {
|
469 |
-
if ( isset( $pubkey ) && MainWP_Helper::is_ssl_enabled() ) {
|
470 |
-
MainWP_Helper::update_option( 'mainwp_child_nossl', 0, 'yes' );
|
471 |
-
$nossl = 0;
|
472 |
-
}
|
473 |
-
}
|
474 |
-
$information['nossl'] = ( 1 == $nossl ? 1 : 0 );
|
475 |
-
}
|
476 |
-
|
477 |
-
/**
|
478 |
-
* Get WordPress update stats.
|
479 |
-
*
|
480 |
-
* @return string|bool|null Return TRUE if the relationship is the one specified by the operator <=,
|
481 |
-
* FALSE otherwise, null by default.
|
482 |
-
*/
|
483 |
-
private function stats_wp_update() {
|
484 |
-
|
485 |
-
/**
|
486 |
-
* The installed version of WordPress.
|
487 |
-
*
|
488 |
-
* @global string $wp_version The installed version of WordPress.
|
489 |
-
*/
|
490 |
-
global $wp_version;
|
491 |
-
|
492 |
-
$result = null;
|
493 |
-
|
494 |
-
// Check for new versions.
|
495 |
-
if ( null !== $this->filterFunction ) {
|
496 |
-
add_filter( 'pre_site_transient_update_core', $this->filterFunction, 99 );
|
497 |
-
}
|
498 |
-
if ( null !== $this->filterFunction ) {
|
499 |
-
add_filter( 'pre_transient_update_core', $this->filterFunction, 99 );
|
500 |
-
}
|
501 |
-
|
502 |
-
wp_version_check();
|
503 |
-
|
504 |
-
$core_updates = get_core_updates();
|
505 |
-
|
506 |
-
if ( is_array( $core_updates ) && count( $core_updates ) > 0 ) {
|
507 |
-
foreach ( $core_updates as $core_update ) {
|
508 |
-
if ( 'latest' === $core_update->response ) {
|
509 |
-
break;
|
510 |
-
}
|
511 |
-
if ( 'upgrade' === $core_update->response && version_compare( $wp_version, $core_update->current, '<=' ) ) {
|
512 |
-
$result = $core_update->current;
|
513 |
-
}
|
514 |
-
}
|
515 |
-
}
|
516 |
-
|
517 |
-
if ( null !== $this->filterFunction ) {
|
518 |
-
remove_filter( 'pre_site_transient_update_core', $this->filterFunction, 99 );
|
519 |
-
}
|
520 |
-
|
521 |
-
if ( null !== $this->filterFunction ) {
|
522 |
-
remove_filter( 'pre_transient_update_core', $this->filterFunction, 99 );
|
523 |
-
}
|
524 |
-
|
525 |
-
return $result;
|
526 |
-
}
|
527 |
-
|
528 |
-
/**
|
529 |
-
* Check for premium updates.
|
530 |
-
*
|
531 |
-
* @param array $information Child Site stats.
|
532 |
-
* @param array $premiumPlugins Active premium plugins.
|
533 |
-
* @param array $premiumThemes Active premium themes.
|
534 |
-
*
|
535 |
-
* @uses \MainWP\Child\MainWP_Helper::update_option()
|
536 |
-
*/
|
537 |
-
private function check_premium_updates( &$information, &$premiumPlugins, &$premiumThemes ) {
|
538 |
-
|
539 |
-
// First check for new premium updates.
|
540 |
-
$update_check = apply_filters( 'mwp_premium_update_check', array() );
|
541 |
-
|
542 |
-
if ( ! empty( $update_check ) ) {
|
543 |
-
foreach ( $update_check as $updateFeedback ) {
|
544 |
-
if ( is_array( $updateFeedback['callback'] ) && isset( $updateFeedback['callback'][0] ) && isset( $updateFeedback['callback'][1] ) ) {
|
545 |
-
call_user_func( array( $updateFeedback['callback'][0], $updateFeedback['callback'][1] ) );
|
546 |
-
} elseif ( is_string( $updateFeedback['callback'] ) ) {
|
547 |
-
call_user_func( $updateFeedback['callback'] );
|
548 |
-
}
|
549 |
-
}
|
550 |
-
}
|
551 |
-
|
552 |
-
$informationPremiumUpdates = apply_filters( 'mwp_premium_update_notification', array() );
|
553 |
-
$premiumPlugins = array();
|
554 |
-
$premiumThemes = array();
|
555 |
-
|
556 |
-
if ( is_array( $informationPremiumUpdates ) ) {
|
557 |
-
$premiumUpdates = array();
|
558 |
-
$informationPremiumUpdatesLength = count( $informationPremiumUpdates );
|
559 |
-
for ( $i = 0; $i < $informationPremiumUpdatesLength; $i ++ ) {
|
560 |
-
if ( ! isset( $informationPremiumUpdates[ $i ]['new_version'] ) ) {
|
561 |
-
continue;
|
562 |
-
}
|
563 |
-
$slug = ( isset( $informationPremiumUpdates[ $i ]['slug'] ) ? $informationPremiumUpdates[ $i ]['slug'] : $informationPremiumUpdates[ $i ]['Name'] );
|
564 |
-
|
565 |
-
if ( 'plugin' === $informationPremiumUpdates[ $i ]['type'] ) {
|
566 |
-
$premiumPlugins[] = $slug;
|
567 |
-
} elseif ( 'theme' === $informationPremiumUpdates[ $i ]['type'] ) {
|
568 |
-
$premiumThemes[] = $slug;
|
569 |
-
}
|
570 |
-
|
571 |
-
$new_version = $informationPremiumUpdates[ $i ]['new_version'];
|
572 |
-
|
573 |
-
unset( $informationPremiumUpdates[ $i ]['old_version'] );
|
574 |
-
unset( $informationPremiumUpdates[ $i ]['new_version'] );
|
575 |
-
|
576 |
-
if ( ! isset( $information['premium_updates'] ) ) {
|
577 |
-
$information['premium_updates'] = array();
|
578 |
-
}
|
579 |
-
|
580 |
-
$information['premium_updates'][ $slug ] = $informationPremiumUpdates[ $i ];
|
581 |
-
$information['premium_updates'][ $slug ]['update'] = (object) array(
|
582 |
-
'new_version' => $new_version,
|
583 |
-
'premium' => true,
|
584 |
-
'slug' => $slug,
|
585 |
-
);
|
586 |
-
|
587 |
-
if ( ! in_array( $slug, $premiumUpdates ) ) {
|
588 |
-
$premiumUpdates[] = $slug;
|
589 |
-
}
|
590 |
-
}
|
591 |
-
MainWP_Helper::update_option( 'mainwp_premium_updates', $premiumUpdates );
|
592 |
-
}
|
593 |
-
}
|
594 |
-
|
595 |
-
/**
|
596 |
-
* Premium plugin update stats.
|
597 |
-
*
|
598 |
-
* @param array $premiumPlugins Active premium plugins.
|
599 |
-
* @return array $results Array of premium plugin slugs.
|
600 |
-
*/
|
601 |
-
private function stats_plugin_update( $premiumPlugins ) {
|
602 |
-
|
603 |
-
$results = array();
|
604 |
-
|
605 |
-
if ( null !== $this->filterFunction ) {
|
606 |
-
add_filter( 'pre_site_transient_update_plugins', $this->filterFunction, 99 );
|
607 |
-
}
|
608 |
-
|
609 |
-
/**
|
610 |
-
* Retrieve the name of the current filter or action.
|
611 |
-
*
|
612 |
-
* @global array $wp_current_filter Current filter.
|
613 |
-
*/
|
614 |
-
global $wp_current_filter;
|
615 |
-
|
616 |
-
$wp_current_filter[] = 'load-plugins.php'; // phpcs:ignore -- Required to achieve desired results, pull request solutions appreciated.
|
617 |
-
|
618 |
-
wp_update_plugins();
|
619 |
-
include_once ABSPATH . '/wp-admin/includes/plugin.php';
|
620 |
-
|
621 |
-
$plugin_updates = get_plugin_updates();
|
622 |
-
if ( is_array( $plugin_updates ) ) {
|
623 |
-
|
624 |
-
foreach ( $plugin_updates as $slug => $plugin_update ) {
|
625 |
-
if ( in_array( $plugin_update->Name, $premiumPlugins ) ) {
|
626 |
-
continue;
|
627 |
-
}
|
628 |
-
|
629 |
-
// Fixes incorrect info.
|
630 |
-
if ( ! property_exists( $plugin_update, 'update' ) || ! property_exists( $plugin_update->update, 'new_version' ) || empty( $plugin_update->update->new_version ) ) {
|
631 |
-
continue;
|
632 |
-
}
|
633 |
-
$plugin_update->active = is_plugin_active( $slug ) ? 1 : 0;
|
634 |
-
$results[ $slug ] = $plugin_update;
|
635 |
-
}
|
636 |
-
}
|
637 |
-
|
638 |
-
if ( null !== $this->filterFunction ) {
|
639 |
-
remove_filter( 'pre_site_transient_update_plugins', $this->filterFunction, 99 );
|
640 |
-
}
|
641 |
-
|
642 |
-
// Fixes premium plugins update.
|
643 |
-
$cached_plugins_update = get_site_transient( 'mainwp_update_plugins_cached' );
|
644 |
-
if ( is_array( $cached_plugins_update ) && ( count( $cached_plugins_update ) > 0 ) ) {
|
645 |
-
foreach ( $cached_plugins_update as $slug => $plugin_update ) {
|
646 |
-
|
647 |
-
// Fixes incorrect info.
|
648 |
-
if ( ! property_exists( $plugin_update, 'new_version' ) || empty( $plugin_update->new_version ) ) { // may do not need to check this?
|
649 |
-
// Fixes some premiums update info.
|
650 |
-
if ( property_exists( $plugin_update, 'update' ) ) {
|
651 |
-
if ( ! property_exists( $plugin_update->update, 'new_version' ) || empty( $plugin_update->update->new_version ) ) {
|
652 |
-
continue;
|
653 |
-
}
|
654 |
-
} else {
|
655 |
-
continue;
|
656 |
-
}
|
657 |
-
}
|
658 |
-
|
659 |
-
if ( ! isset( $results[ $slug ] ) ) {
|
660 |
-
$plugin_update->active = is_plugin_active( $slug ) ? 1 : 0;
|
661 |
-
$results[ $slug ] = $plugin_update;
|
662 |
-
}
|
663 |
-
}
|
664 |
-
}
|
665 |
-
|
666 |
-
return $results;
|
667 |
-
}
|
668 |
-
|
669 |
-
/**
|
670 |
-
* Ger category stats.
|
671 |
-
*
|
672 |
-
* @return array $categories Available Child Site Categories.
|
673 |
-
*/
|
674 |
-
private function stats_get_categories() {
|
675 |
-
|
676 |
-
$cats = get_categories(
|
677 |
-
array(
|
678 |
-
'hide_empty' => 0,
|
679 |
-
'hierarchical' => true,
|
680 |
-
'number' => 300,
|
681 |
-
)
|
682 |
-
);
|
683 |
-
$categories = array();
|
684 |
-
foreach ( $cats as $cat ) {
|
685 |
-
$categories[] = $cat->name;
|
686 |
-
}
|
687 |
-
|
688 |
-
return $categories;
|
689 |
-
}
|
690 |
-
|
691 |
-
/**
|
692 |
-
* Get total size of Child Site installation.
|
693 |
-
*
|
694 |
-
* @uses MainWP_Child_Stats::get_total_file_size()
|
695 |
-
*
|
696 |
-
* @return float|int|null $total Total file size or 0 or null.
|
697 |
-
*/
|
698 |
-
private function stats_get_total_size() {
|
699 |
-
$total = null;
|
700 |
-
|
701 |
-
$get_file_size = apply_filters_deprecated( 'mainwp-child-get-total-size', array( true ), '4.0.7.1', 'mainwp_child_get_total_size' );
|
702 |
-
$get_file_size = apply_filters( 'mainwp_child_get_total_size', $get_file_size );
|
703 |
-
$forced_get_file_size = apply_filters( 'mainwp_child_forced_get_total_size', false );
|
704 |
-
|
705 |
-
if ( $forced_get_file_size || ( $get_file_size && isset( $_POST['cloneSites'] ) && ( '0' !== $_POST['cloneSites'] ) ) ) {
|
706 |
-
$max_exe = ini_get( 'max_execution_time' );
|
707 |
-
if ( $forced_get_file_size || $max_exe > 20 ) {
|
708 |
-
$total = $this->get_total_file_size();
|
709 |
-
}
|
710 |
-
}
|
711 |
-
|
712 |
-
return $total;
|
713 |
-
}
|
714 |
-
|
715 |
-
/**
|
716 |
-
* Get recent number.
|
717 |
-
*
|
718 |
-
* @return int $recent_number Recent number.
|
719 |
-
*/
|
720 |
-
private function get_recent_number() {
|
721 |
-
|
722 |
-
$recent_number = 5;
|
723 |
-
|
724 |
-
if ( isset( $_POST ) && isset( $_POST['recent_number'] ) ) {
|
725 |
-
$recent_number = intval( wp_unslash( $_POST['recent_number'] ) );
|
726 |
-
if ( get_option( 'mainwp_child_recent_number', 5 ) != $recent_number ) {
|
727 |
-
update_option( 'mainwp_child_recent_number', $recent_number );
|
728 |
-
}
|
729 |
-
} else {
|
730 |
-
$recent_number = get_option( 'mainwp_child_recent_number', 5 );
|
731 |
-
}
|
732 |
-
|
733 |
-
if ( $recent_number <= 0 || $recent_number > 30 ) {
|
734 |
-
$recent_number = 5;
|
735 |
-
}
|
736 |
-
|
737 |
-
return $recent_number;
|
738 |
-
}
|
739 |
-
|
740 |
-
|
741 |
-
/**
|
742 |
-
* Update options: mainwp_child_clone_sites, mainwp_child_siteid, mainwp_child_pluginDir.
|
743 |
-
*
|
744 |
-
* @uses \MainWP\Child\MainWP_Helper::update_option()
|
745 |
-
*/
|
746 |
-
public function update_external_settings() {
|
747 |
-
if ( isset( $_POST['cloneSites'] ) ) {
|
748 |
-
if ( '0' !== $_POST['cloneSites'] ) {
|
749 |
-
$arr = isset( $_POST['cloneSites'] ) ? json_decode( urldecode( wp_unslash( $_POST['cloneSites'] ) ), 1 ) : '';
|
750 |
-
MainWP_Helper::update_option( 'mainwp_child_clone_sites', ( ! is_array( $arr ) ? array() : $arr ) );
|
751 |
-
} else {
|
752 |
-
MainWP_Helper::update_option( 'mainwp_child_clone_sites', '0' );
|
753 |
-
}
|
754 |
-
}
|
755 |
-
|
756 |
-
if ( isset( $_POST['siteId'] ) ) {
|
757 |
-
MainWP_Helper::update_option( 'mainwp_child_siteid', intval( wp_unslash( $_POST['siteId'] ) ) );
|
758 |
-
}
|
759 |
-
|
760 |
-
if ( isset( $_POST['pluginDir'] ) ) {
|
761 |
-
if ( get_option( 'mainwp_child_pluginDir' ) !== $_POST['pluginDir'] ) {
|
762 |
-
MainWP_Helper::update_option( 'mainwp_child_pluginDir', ( ! empty( $_POST['pluginDir'] ) ? wp_unslash( $_POST['pluginDir'] ) : '' ), 'yes' );
|
763 |
-
}
|
764 |
-
} elseif ( false !== get_option( 'mainwp_child_pluginDir' ) ) {
|
765 |
-
MainWP_Helper::update_option( 'mainwp_child_pluginDir', false, 'yes' );
|
766 |
-
}
|
767 |
-
}
|
768 |
-
|
769 |
-
/**
|
770 |
-
* Get total size of wp_content directory.
|
771 |
-
*
|
772 |
-
* @param string $directory WordPress content directory.
|
773 |
-
* @return float|int Return $size or 0.
|
774 |
-
*
|
775 |
-
* @uses \MainWP\Child\MainWP_Helper::funct_exists()
|
776 |
-
* @uses \MainWP\Child\MainWP_Helper::get_mainwp_dir()
|
777 |
-
* @uses \MainWP\Child\MainWP_Helper::ctype_digit()
|
778 |
-
*/
|
779 |
-
public function get_total_file_size( $directory = WP_CONTENT_DIR ) {
|
780 |
-
try {
|
781 |
-
if ( MainWP_Helper::funct_exists( 'popen' ) ) {
|
782 |
-
$uploadDir = MainWP_Helper::get_mainwp_dir();
|
783 |
-
$uploadDir = $uploadDir[0];
|
784 |
-
$popenHandle = popen( 'du -s ' . $directory . ' --exclude "' . str_replace( ABSPATH, '', $uploadDir ) . '"', 'r' ); // phpcs:ignore -- run if enabled.
|
785 |
-
if ( 'resource' === gettype( $popenHandle ) ) {
|
786 |
-
$size = fread( $popenHandle, 1024 ); //phpcs:ignore -- custom read file.
|
787 |
-
pclose( $popenHandle );
|
788 |
-
$size = substr( $size, 0, strpos( $size, "\t" ) );
|
789 |
-
if ( $size && MainWP_Helper::ctype_digit( $size ) ) {
|
790 |
-
return $size / 1024;
|
791 |
-
}
|
792 |
-
}
|
793 |
-
}
|
794 |
-
|
795 |
-
if ( MainWP_Helper::funct_exists( 'shell_exec' ) ) {
|
796 |
-
$uploadDir = MainWP_Helper::get_mainwp_dir();
|
797 |
-
$uploadDir = $uploadDir[0];
|
798 |
-
$size = shell_exec( 'du -s ' . $directory . ' --exclude "' . str_replace( ABSPATH, '', $uploadDir ) . '"' ); // phpcs:ignore -- run if enabled.
|
799 |
-
if ( null !== $size ) {
|
800 |
-
$size = substr( $size, 0, strpos( $size, "\t" ) );
|
801 |
-
if ( $size && MainWP_Helper::ctype_digit( $size ) ) {
|
802 |
-
return $size / 1024;
|
803 |
-
}
|
804 |
-
}
|
805 |
-
}
|
806 |
-
if ( class_exists( '\COM' ) ) {
|
807 |
-
$obj = new \COM( 'scripting.filesystemobject' );
|
808 |
-
|
809 |
-
if ( is_object( $obj ) ) {
|
810 |
-
$ref = $obj->getfolder( $directory );
|
811 |
-
|
812 |
-
$size = $ref->size;
|
813 |
-
|
814 |
-
$obj = null;
|
815 |
-
if ( MainWP_Helper::ctype_digit( $size ) ) {
|
816 |
-
return $size / 1024;
|
817 |
-
}
|
818 |
-
}
|
819 |
-
}
|
820 |
-
// to fix for window host, performance not good?
|
821 |
-
if ( class_exists( '\RecursiveIteratorIterator' ) ) {
|
822 |
-
$size = 0;
|
823 |
-
foreach ( new \RecursiveIteratorIterator( new \RecursiveDirectoryIterator( $directory ) ) as $file ) {
|
824 |
-
$size += $file->getSize();
|
825 |
-
}
|
826 |
-
if ( $size && MainWP_Helper::ctype_digit( $size ) ) {
|
827 |
-
return $size / 1024 / 1024;
|
828 |
-
}
|
829 |
-
}
|
830 |
-
return 0;
|
831 |
-
} catch ( \Exception $e ) {
|
832 |
-
return 0;
|
833 |
-
}
|
834 |
-
}
|
835 |
-
|
836 |
-
/**
|
837 |
-
* Scan directory.
|
838 |
-
*
|
839 |
-
* @param string $pDir Directory to scan.
|
840 |
-
* @param string $pLvl How deep to scan.
|
841 |
-
*
|
842 |
-
* @uses MainWP_Child_Stats::scan_dir()
|
843 |
-
* @uses MainWP_Child_Stats::int_scan_dir()
|
844 |
-
*
|
845 |
-
* @return array|null $output|$files
|
846 |
-
*/
|
847 |
-
public function scan_dir( $pDir, $pLvl ) {
|
848 |
-
$output = array();
|
849 |
-
if ( file_exists( $pDir ) && is_dir( $pDir ) ) {
|
850 |
-
if ( 'logs' === basename( $pDir ) ) {
|
851 |
-
return empty( $output ) ? null : $output;
|
852 |
-
}
|
853 |
-
if ( 0 === $pLvl ) {
|
854 |
-
return empty( $output ) ? null : $output;
|
855 |
-
}
|
856 |
-
$files = $this->int_scan_dir( $pDir );
|
857 |
-
if ( $files ) {
|
858 |
-
foreach ( $files as $file ) {
|
859 |
-
if ( ( '.' === $file ) || ( '..' === $file ) ) {
|
860 |
-
continue;
|
861 |
-
}
|
862 |
-
$newDir = $pDir . $file . DIRECTORY_SEPARATOR;
|
863 |
-
if ( is_dir( $newDir ) ) {
|
864 |
-
$output[ $file ] = $this->scan_dir( $newDir, $pLvl - 1, false );
|
865 |
-
}
|
866 |
-
}
|
867 |
-
|
868 |
-
unset( $files );
|
869 |
-
$files = null;
|
870 |
-
}
|
871 |
-
}
|
872 |
-
|
873 |
-
return empty( $output ) ? null : $output;
|
874 |
-
}
|
875 |
-
|
876 |
-
/**
|
877 |
-
* Initiate directory scan.
|
878 |
-
*
|
879 |
-
* @param string $dir Directory to scan.
|
880 |
-
*
|
881 |
-
* @return array|bool $out|FALSE Returns the entry name on success or FALSE on failure.
|
882 |
-
*/
|
883 |
-
public function int_scan_dir( $dir ) {
|
884 |
-
$dh = opendir( $dir );
|
885 |
-
if ( is_dir( $dir ) && $dh ) {
|
886 |
-
$cnt = 0;
|
887 |
-
$out = array();
|
888 |
-
$file = readdir( $dh );
|
889 |
-
while ( false !== $file ) {
|
890 |
-
$newDir = $dir . $file . DIRECTORY_SEPARATOR;
|
891 |
-
if ( ! is_dir( $newDir ) ) {
|
892 |
-
$file = readdir( $dh );
|
893 |
-
continue;
|
894 |
-
}
|
895 |
-
|
896 |
-
$out[] = $file;
|
897 |
-
$file = readdir( $dh );
|
898 |
-
|
899 |
-
if ( $cnt ++ > 10 ) {
|
900 |
-
break;
|
901 |
-
}
|
902 |
-
}
|
903 |
-
closedir( $dh );
|
904 |
-
|
905 |
-
return $out;
|
906 |
-
}
|
907 |
-
|
908 |
-
return false;
|
909 |
-
}
|
910 |
-
|
911 |
-
/**
|
912 |
-
* Get all themes.
|
913 |
-
*
|
914 |
-
* @uses \MainWP\Child\MainWP_Child_Stats::get_all_themes_int()
|
915 |
-
* @uses \MainWP\Child\MainWP_Helper::write()
|
916 |
-
*/
|
917 |
-
public function get_all_themes() {
|
918 |
-
$keyword = isset( $_POST['keyword'] ) ? sanitize_text_field( wp_unslash( $_POST['keyword'] ) ) : '';
|
919 |
-
$status = isset( $_POST['status'] ) ? sanitize_text_field( wp_unslash( $_POST['status'] ) ) : '';
|
920 |
-
$filter = isset( $_POST['filter'] ) ? sanitize_text_field( wp_unslash( $_POST['filter'] ) ) : true;
|
921 |
-
$rslt = $this->get_all_themes_int( $filter, $keyword, $status );
|
922 |
-
|
923 |
-
MainWP_Helper::write( $rslt );
|
924 |
-
}
|
925 |
-
|
926 |
-
/**
|
927 |
-
* Initiate get all themes.
|
928 |
-
*
|
929 |
-
* @param string $filter Sites filter field.
|
930 |
-
* @param string $keyword Keyword Search field.
|
931 |
-
* @param string $status Active or Inactive filed.
|
932 |
-
*
|
933 |
-
* @return array $rslt Returned themes results.
|
934 |
-
*/
|
935 |
-
public function get_all_themes_int( $filter, $keyword = '', $status = '' ) {
|
936 |
-
$rslt = array();
|
937 |
-
$themes = wp_get_themes();
|
938 |
-
|
939 |
-
if ( is_array( $themes ) ) {
|
940 |
-
$theme_name = wp_get_theme()->get( 'Name' );
|
941 |
-
|
942 |
-
foreach ( $themes as $theme ) {
|
943 |
-
$out = array();
|
944 |
-
$out['name'] = $theme->get( 'Name' );
|
945 |
-
$out['title'] = $theme->display( 'Name', true, false );
|
946 |
-
$out['description'] = $theme->display( 'Description', true, false );
|
947 |
-
$out['version'] = $theme->display( 'Version', true, false );
|
948 |
-
$out['active'] = ( $theme->get( 'Name' ) === $theme_name ) ? 1 : 0;
|
949 |
-
$out['slug'] = $theme->get_stylesheet();
|
950 |
-
if ( ! $filter ) {
|
951 |
-
if ( '' == $keyword || stristr( $out['title'], $keyword ) ) {
|
952 |
-
$rslt[] = $out;
|
953 |
-
}
|
954 |
-
} elseif ( ( ( 'active' === $status ) ? 1 : 0 ) === $out['active'] ) {
|
955 |
-
if ( '' == $keyword || stristr( $out['title'], $keyword ) ) {
|
956 |
-
$rslt[] = $out;
|
957 |
-
}
|
958 |
-
}
|
959 |
-
}
|
960 |
-
}
|
961 |
-
|
962 |
-
return $rslt;
|
963 |
-
}
|
964 |
-
|
965 |
-
/**
|
966 |
-
* Get all Plugins.
|
967 |
-
*
|
968 |
-
* @uses \MainWP\Child\MainWP_Child_Stats::get_all_plugins_int()
|
969 |
-
* @uses \MainWP\Child\MainWP_Helper::write()
|
970 |
-
*/
|
971 |
-
public function get_all_plugins() {
|
972 |
-
$keyword = isset( $_POST['keyword'] ) ? sanitize_text_field( wp_unslash( $_POST['keyword'] ) ) : '';
|
973 |
-
$status = isset( $_POST['status'] ) ? sanitize_text_field( wp_unslash( $_POST['status'] ) ) : '';
|
974 |
-
$filter = isset( $_POST['filter'] ) ? sanitize_text_field( wp_unslash( $_POST['filter'] ) ) : true;
|
975 |
-
$rslt = $this->get_all_plugins_int( $filter, $keyword, $status );
|
976 |
-
|
977 |
-
MainWP_Helper::write( $rslt );
|
978 |
-
}
|
979 |
-
|
980 |
-
/**
|
981 |
-
* Initiate get all plugins.
|
982 |
-
*
|
983 |
-
* @param string $filter Sites filter field.
|
984 |
-
* @param string $keyword Keyword Search field.
|
985 |
-
* @param string $status Active or Inactive filed.
|
986 |
-
*
|
987 |
-
* @return array $rslt Returned themes results.
|
988 |
-
*/
|
989 |
-
public function get_all_plugins_int( $filter, $keyword = '', $status = '' ) {
|
990 |
-
if ( ! function_exists( 'get_plugins' ) ) {
|
991 |
-
include_once ABSPATH . 'wp-admin/includes/plugin.php';
|
992 |
-
}
|
993 |
-
|
994 |
-
/**
|
995 |
-
* MainWP Child instance.
|
996 |
-
*
|
997 |
-
* @global object
|
998 |
-
*/
|
999 |
-
global $mainWPChild;
|
1000 |
-
|
1001 |
-
$rslt = array();
|
1002 |
-
$plugins = get_plugins();
|
1003 |
-
if ( is_array( $plugins ) ) {
|
1004 |
-
$active_plugins = get_option( 'active_plugins' );
|
1005 |
-
|
1006 |
-
foreach ( $plugins as $pluginslug => $plugin ) {
|
1007 |
-
$out = array();
|
1008 |
-
$out['mainwp'] = ( $pluginslug == $mainWPChild->plugin_slug ? 'T' : 'F' );
|
1009 |
-
$out['name'] = $plugin['Name'];
|
1010 |
-
$out['slug'] = $pluginslug;
|
1011 |
-
$out['description'] = $plugin['Description'];
|
1012 |
-
$out['version'] = $plugin['Version'];
|
1013 |
-
$out['active'] = is_plugin_active( $pluginslug ) ? 1 : 0;
|
1014 |
-
if ( ! $filter ) {
|
1015 |
-
if ( '' == $keyword || stristr( $out['name'], $keyword ) ) {
|
1016 |
-
$rslt[] = $out;
|
1017 |
-
}
|
1018 |
-
} elseif ( ( ( 'active' == $status ) ? 1 : 0 ) == $out['active'] ) {
|
1019 |
-
if ( '' == $keyword || stristr( $out['name'], $keyword ) ) {
|
1020 |
-
$rslt[] = $out;
|
1021 |
-
}
|
1022 |
-
}
|
1023 |
-
}
|
1024 |
-
}
|
1025 |
-
|
1026 |
-
$muplugins = get_mu_plugins();
|
1027 |
-
if ( is_array( $muplugins ) ) {
|
1028 |
-
foreach ( $muplugins as $pluginslug => $plugin ) {
|
1029 |
-
$out = array();
|
1030 |
-
$out['mainwp'] = ( $pluginslug == $mainWPChild->plugin_slug ? 'T' : 'F' );
|
1031 |
-
$out['name'] = $plugin['Name'];
|
1032 |
-
$out['slug'] = $pluginslug;
|
1033 |
-
$out['description'] = $plugin['Description'];
|
1034 |
-
$out['version'] = $plugin['Version'];
|
1035 |
-
$out['active'] = 1;
|
1036 |
-
$out['mu'] = 1;
|
1037 |
-
if ( ! $filter ) {
|
1038 |
-
if ( '' == $keyword || stristr( $out['name'], $keyword ) ) {
|
1039 |
-
$rslt[] = $out;
|
1040 |
-
}
|
1041 |
-
} elseif ( ( ( 'active' == $status ) ? 1 : 0 ) == $out['active'] ) {
|
1042 |
-
if ( '' == $keyword || stristr( $out['name'], $keyword ) ) {
|
1043 |
-
$rslt[] = $out;
|
1044 |
-
}
|
1045 |
-
}
|
1046 |
-
}
|
1047 |
-
}
|
1048 |
-
|
1049 |
-
return $rslt;
|
1050 |
-
}
|
1051 |
-
|
1052 |
-
/**
|
1053 |
-
* Get WP Site Health issues.
|
1054 |
-
*
|
1055 |
-
* @return array $issue_counts Returned issues.
|
1056 |
-
*/
|
1057 |
-
public function get_health_check_site_status() {
|
1058 |
-
$get_issues = get_transient( 'health-check-site-status-result' );
|
1059 |
-
$issue_counts = array();
|
1060 |
-
if ( false !== $get_issues ) {
|
1061 |
-
$issue_counts = json_decode( $get_issues, true );
|
1062 |
-
}
|
1063 |
-
if ( ! is_array( $issue_counts ) || ! $issue_counts ) {
|
1064 |
-
$issue_counts = array(
|
1065 |
-
'good' => 0,
|
1066 |
-
'recommended' => 0,
|
1067 |
-
'critical' => 0,
|
1068 |
-
);
|
1069 |
-
}
|
1070 |
-
return $issue_counts;
|
1071 |
-
}
|
1072 |
-
}
|
1 |
+
<?php
|
2 |
+
/**
|
3 |
+
* MainWP Child Stats.
|
4 |
+
*
|
5 |
+
* Gather the child site data to send to the MainWP Dashboard.
|
6 |
+
*
|
7 |
+
* @package MainWP\Child
|
8 |
+
*/
|
9 |
+
|
10 |
+
namespace MainWP\Child;
|
11 |
+
|
12 |
+
//phpcs:disable Generic.Metrics.CyclomaticComplexity -- Required to achieve desired results, pull request solutions appreciated.
|
13 |
+
|
14 |
+
/**
|
15 |
+
* Class MainWP_Child_Stats
|
16 |
+
*
|
17 |
+
* Gather the child site data to send to the MainWP Dashboard.
|
18 |
+
*/
|
19 |
+
class MainWP_Child_Stats {
|
20 |
+
|
21 |
+
/**
|
22 |
+
* Public static variable to hold the single instance of the class.
|
23 |
+
*
|
24 |
+
* @var mixed Default null
|
25 |
+
*/
|
26 |
+
protected static $instance = null;
|
27 |
+
|
28 |
+
/**
|
29 |
+
* Class used to represent anonymous functions.
|
30 |
+
*
|
31 |
+
* @var null
|
32 |
+
*/
|
33 |
+
private $filterFunction = null;
|
34 |
+
|
35 |
+
/**
|
36 |
+
* Method get_class_name()
|
37 |
+
*
|
38 |
+
* Get class name.
|
39 |
+
*
|
40 |
+
* @return string __CLASS__ Class name.
|
41 |
+
*/
|
42 |
+
public static function get_class_name() {
|
43 |
+
return __CLASS__;
|
44 |
+
}
|
45 |
+
|
46 |
+
/**
|
47 |
+
* MainWP_Child_Stats constructor.
|
48 |
+
*
|
49 |
+
* Run any time class is called.
|
50 |
+
*/
|
51 |
+
public function __construct() {
|
52 |
+
|
53 |
+
/**
|
54 |
+
* Checks if 'last_checked'.
|
55 |
+
*
|
56 |
+
* @param $a Object to check.
|
57 |
+
* @return object|bool $a Return object or FALSE on failure.
|
58 |
+
*/
|
59 |
+
$this->filterFunction = function( $a ) {
|
60 |
+
if ( null == $a ) {
|
61 |
+
return false; }
|
62 |
+
if ( is_object( $a ) && property_exists( $a, 'last_checked' ) && ! property_exists( $a, 'checked' ) ) {
|
63 |
+
return false;
|
64 |
+
}
|
65 |
+
return $a;
|
66 |
+
};
|
67 |
+
}
|
68 |
+
|
69 |
+
/**
|
70 |
+
* Method get_instance()
|
71 |
+
*
|
72 |
+
* Create a public static instance.
|
73 |
+
*
|
74 |
+
* @return mixed Class instance.
|
75 |
+
*/
|
76 |
+
public static function get_instance() {
|
77 |
+
if ( null === self::$instance ) {
|
78 |
+
self::$instance = new self();
|
79 |
+
}
|
80 |
+
|
81 |
+
return self::$instance;
|
82 |
+
}
|
83 |
+
|
84 |
+
/**
|
85 |
+
* Show stats without login. only allowed while no account is added yet.
|
86 |
+
*
|
87 |
+
* @param array $information Child Site Stats.
|
88 |
+
*
|
89 |
+
* @uses \MainWP\Child\MainWP_Child::$version
|
90 |
+
* @uses \MainWP\Child\MainWP_Helper::is_wp_engine()
|
91 |
+
* @uses \MainWP\Child\MainWP_Helper::write()
|
92 |
+
*/
|
93 |
+
public function get_site_stats_no_auth( $information = array() ) {
|
94 |
+
if ( get_option( 'mainwp_child_pubkey' ) ) {
|
95 |
+
$hint = '<br/>' . __( 'Hint: Go to the child site, deactivate and reactivate the MainWP Child plugin and try again.', 'mainwp-child' );
|
96 |
+
MainWP_Helper::instance()->error( __( 'This site already contains a link. Please deactivate and reactivate the MainWP plugin.', 'mainwp-child' ) . $hint );
|
97 |
+
}
|
98 |
+
|
99 |
+
/**
|
100 |
+
* The installed version of WordPress.
|
101 |
+
*
|
102 |
+
* @global string $wp_version The installed version of WordPress.
|
103 |
+
*
|
104 |
+
* @uses \MainWP\Child\MainWP_Child::$version
|
105 |
+
* @uses \MainWP\Child\MainWP_Helper::write()
|
106 |
+
*/
|
107 |
+
global $wp_version;
|
108 |
+
|
109 |
+
$information['version'] = MainWP_Child::$version;
|
110 |
+
$information['wpversion'] = $wp_version;
|
111 |
+
$information['wpe'] = MainWP_Helper::is_wp_engine() ? 1 : 0;
|
112 |
+
MainWP_Helper::write( $information );
|
113 |
+
}
|
114 |
+
|
115 |
+
/**
|
116 |
+
* Check if ManageWP is installed.
|
117 |
+
*
|
118 |
+
* @param array $default Active plugins.
|
119 |
+
* @return array $default Active plugins array with managewp/init.php appended.
|
120 |
+
*/
|
121 |
+
public function default_option_active_plugins( $default ) {
|
122 |
+
if ( ! is_array( $default ) ) {
|
123 |
+
$default = array();
|
124 |
+
}
|
125 |
+
if ( ! in_array( 'managewp/init.php', $default ) ) {
|
126 |
+
$default[] = 'managewp/init.php';
|
127 |
+
}
|
128 |
+
|
129 |
+
return $default;
|
130 |
+
}
|
131 |
+
|
132 |
+
/**
|
133 |
+
* Get Child Site Stats.
|
134 |
+
*
|
135 |
+
* @param array $information Holder for return array.
|
136 |
+
* @param bool $exit Whether or not to exit the method. Default: true.
|
137 |
+
*
|
138 |
+
* @return array $information Child Site Stats.
|
139 |
+
*
|
140 |
+
* @uses \MainWP\Child\MainWP_Child_Stats::update_external_settings()
|
141 |
+
* @uses \MainWP\Child\MainWP_Child_Stats::stats_get_info()
|
142 |
+
* @uses \MainWP\Child\MainWP_Child_Stats::stats_wp_update()
|
143 |
+
* @uses \MainWP\Child\MainWP_Child_Stats::stats_plugin_update()
|
144 |
+
* @uses \MainWP\Child\MainWP_Child_Stats::stats_theme_update()
|
145 |
+
* @uses \MainWP\Child\MainWP_Child_Stats::stats_translation_updates()
|
146 |
+
* @uses \MainWP\Child\MainWP_Child_Stats::get_recent_number()
|
147 |
+
* @uses \MainWP\Child\MainWP_Child_Stats::scan_dir()
|
148 |
+
* @uses \MainWP\Child\MainWP_Child_Stats::stats_get_categories()
|
149 |
+
* @uses \MainWP\Child\MainWP_Child_Stats::stats_get_total_size()
|
150 |
+
* @uses \MainWP\Child\MainWP_Child_Stats::get_all_plugins_int()
|
151 |
+
* @uses \MainWP\Child\MainWP_Child_Stats::get_all_themes_int()
|
152 |
+
* @uses \MainWP\Child\MainWP_Child_Stats::get_health_check_site_status()
|
153 |
+
* @uses \MainWP\Child\MainWP_Child_Stats::stats_others_data()
|
154 |
+
* @uses \MainWP\Child\MainWP_Child_Stats::check_premium_updates()
|
155 |
+
* @uses \MainWP\Child\MainWP_Child_Branding::save_branding_options()
|
156 |
+
* @uses \MainWP\Child\MainWP_Child_Plugins_Check::may_outdate_number_change()
|
157 |
+
* @uses \MainWP\Child\MainWP_Child_Comments::get_recent_comments()
|
158 |
+
* @uses \MainWP\Child\MainWP_Child_Posts::get_recent_posts()
|
159 |
+
* @uses \MainWP\Child\MainWP_Child_DB::get_size()
|
160 |
+
* @uses \MainWP\Child\MainWP_Child_Users:::get_all_users_int()
|
161 |
+
* @uses \MainWP\Child\MainWP_Child_Plugins_Check::get_plugins_outdate_info()
|
162 |
+
* @uses \MainWP\Child\MainWP_Child_Themes_Check::get_themes_outdate_info()
|
163 |
+
* @uses \MainWP\Child\MainWP_Security::get_stats_security()
|
164 |
+
* @uses \MainWP\Child\MainWP_Connect::instance()::get_max_history()
|
165 |
+
* @uses \MainWP\Child\MainWP_Utility::get_lasttime_backup()
|
166 |
+
* @uses \MainWP\Child\MainWP_Utility::validate_mainwp_dir()
|
167 |
+
* @uses \MainWP\Child\MainWP_Helper::update_option()
|
168 |
+
* @uses \MainWP\Child\MainWP_Helper::set_limit()
|
169 |
+
* @uses \MainWP\Child\MainWP_Helper::log_debug()
|
170 |
+
* @uses \MainWP\Child\MainWP_Helper::write()
|
171 |
+
* @uses \MainWP\Child\MainWP_Child_Branding::save_branding_options()
|
172 |
+
* @uses \MainWP\Child\MainWP_Child_Comments::get_recent_comments()
|
173 |
+
* @uses \MainWP\Child\MainWP_Child_DB::get_size()
|
174 |
+
* @uses \MainWP\Child\MainWP_Child_Misc::get_security_stats()
|
175 |
+
* @uses \MainWP\Child\MainWP_Child_Plugins_Check::may_outdate_number_change()
|
176 |
+
* @uses \MainWP\Child\MainWP_Child_Plugins_Check::get_plugins_outdate_info()
|
177 |
+
* @uses \MainWP\Child\MainWP_Child_Posts::get_all_posts()
|
178 |
+
* @uses \MainWP\Child\MainWP_Child_Themes_Check::get_themes_outdate_info()
|
179 |
+
* @uses \MainWP\Child\MainWP_Child_Users::get_all_users_int()
|
180 |
+
* @uses \MainWP\Child\MainWP_Connect::get_max_history()
|
181 |
+
*/
|
182 |
+
public function get_site_stats( $information = array(), $exit = true ) {
|
183 |
+
|
184 |
+
if ( $exit ) {
|
185 |
+
$this->update_external_settings();
|
186 |
+
}
|
187 |
+
|
188 |
+
MainWP_Child_Branding::instance()->save_branding_options( 'branding_disconnected', '' );
|
189 |
+
if ( isset( $_POST['server'] ) ) {
|
190 |
+
MainWP_Helper::update_option( 'mainwp_child_server', ! empty( $_POST['server'] ) ? wp_unslash( $_POST['server'] ) : '' );
|
191 |
+
}
|
192 |
+
|
193 |
+
MainWP_Child_Plugins_Check::may_outdate_number_change();
|
194 |
+
|
195 |
+
$this->stats_get_info( $information );
|
196 |
+
|
197 |
+
include_once ABSPATH . '/wp-admin/includes/update.php';
|
198 |
+
|
199 |
+
$timeout = 3 * 60 * 60;
|
200 |
+
MainWP_Helper::set_limit( $timeout );
|
201 |
+
|
202 |
+
// Check for new versions.
|
203 |
+
$information['wp_updates'] = $this->stats_wp_update();
|
204 |
+
|
205 |
+
add_filter( 'default_option_active_plugins', array( &$this, 'default_option_active_plugins' ) );
|
206 |
+
add_filter( 'option_active_plugins', array( &$this, 'default_option_active_plugins' ) );
|
207 |
+
|
208 |
+
$premiumPlugins = array();
|
209 |
+
$premiumThemes = array();
|
210 |
+
|
211 |
+
// First check for new premium updates.
|
212 |
+
$this->check_premium_updates( $information, $premiumPlugins, $premiumThemes );
|
213 |
+
|
214 |
+
remove_filter( 'default_option_active_plugins', array( &$this, 'default_option_active_plugins' ) );
|
215 |
+
remove_filter( 'option_active_plugins', array( &$this, 'default_option_active_plugins' ) );
|
216 |
+
|
217 |
+
$information['plugin_updates'] = $this->stats_plugin_update( $premiumPlugins );
|
218 |
+
|
219 |
+
$information['theme_updates'] = $this->stats_theme_update( $premiumThemes );
|
220 |
+
|
221 |
+
$information['translation_updates'] = $this->stats_translation_updates();
|
222 |
+
|
223 |
+
$information['recent_comments'] = MainWP_Child_Comments::get_instance()->get_recent_comments( array( 'approve', 'hold' ), 5 );
|
224 |
+
|
225 |
+
$recent_number = $this->get_recent_number();
|
226 |
+
|
227 |
+
$information['recent_posts'] = MainWP_Child_Posts::get_instance()->get_recent_posts( array( 'publish', 'draft', 'pending', 'trash', 'future' ), $recent_number );
|
228 |
+
$information['recent_pages'] = MainWP_Child_Posts::get_instance()->get_recent_posts( array( 'publish', 'draft', 'pending', 'trash', 'future' ), $recent_number, 'page' );
|
229 |
+
$information['securityIssues'] = MainWP_Security::get_stats_security();
|
230 |
+
$information['securityStats'] = MainWP_Child_Misc::get_instance()->get_security_stats( true );
|
231 |
+
|
232 |
+
// Directory listings!
|
233 |
+
$information['directories'] = isset( $_POST['scan_dir'] ) && ! empty( $_POST['scan_dir'] ) ? $this->scan_dir( ABSPATH, 3 ) : '';
|
234 |
+
$information['categories'] = $this->stats_get_categories();
|
235 |
+
|
236 |
+
$totalsize = $this->stats_get_total_size();
|
237 |
+
if ( ! empty( $totalsize ) ) {
|
238 |
+
$information['totalsize'] = $totalsize;
|
239 |
+
}
|
240 |
+
|
241 |
+
$information['dbsize'] = MainWP_Child_DB::get_size();
|
242 |
+
|
243 |
+
$max_his = MainWP_Connect::instance()->get_max_history();
|
244 |
+
$auths = get_option( 'mainwp_child_auth' );
|
245 |
+
$information['extauth'] = ( $auths && isset( $auths[ $max_his ] ) ? $auths[ $max_his ] : null );
|
246 |
+
|
247 |
+
$information['plugins'] = $this->get_all_plugins_int( false );
|
248 |
+
$information['themes'] = $this->get_all_themes_int( false );
|
249 |
+
|
250 |
+
if ( isset( $_POST['optimize'] ) && ( '1' == $_POST['optimize'] ) ) {
|
251 |
+
$information['users'] = MainWP_Child_Users::get_instance()->get_all_users_int( 500 );
|
252 |
+
}
|
253 |
+
|
254 |
+
if ( ! empty( $_POST['primaryBackup'] ) ) {
|
255 |
+
$primary_bk = ! empty( $_POST['primaryBackup'] ) ? sanitize_text_field( wp_unslash( $_POST['primaryBackup'] ) ) : '';
|
256 |
+
$information['primaryLasttimeBackup'] = MainWP_Utility::get_lasttime_backup( $primary_bk );
|
257 |
+
}
|
258 |
+
|
259 |
+
$last_post = wp_get_recent_posts( array( 'numberposts' => absint( '1' ) ) );
|
260 |
+
if ( isset( $last_post[0] ) ) {
|
261 |
+
$last_post = $last_post[0];
|
262 |
+
}
|
263 |
+
if ( isset( $last_post ) && isset( $last_post['post_modified_gmt'] ) ) {
|
264 |
+
$information['last_post_gmt'] = strtotime( $last_post['post_modified_gmt'] );
|
265 |
+
}
|
266 |
+
$information['mainwpdir'] = ( MainWP_Utility::validate_mainwp_dir() ? 1 : - 1 );
|
267 |
+
$information['uniqueId'] = MainWP_Helper::get_site_unique_id();
|
268 |
+
$information['plugins_outdate_info'] = MainWP_Child_Plugins_Check::instance()->get_plugins_outdate_info();
|
269 |
+
$information['themes_outdate_info'] = MainWP_Child_Themes_Check::instance()->get_themes_outdate_info();
|
270 |
+
$information['health_site_status'] = $this->get_health_check_site_status();
|
271 |
+
|
272 |
+
if ( isset( $_POST['user'] ) ) {
|
273 |
+
$user = get_user_by( 'login', sanitize_text_field( wp_unslash( $_POST['user'] ) ) );
|
274 |
+
if ( $user && property_exists( $user, 'ID' ) && $user->ID ) {
|
275 |
+
$information['admin_nicename'] = $user->data->user_nicename;
|
276 |
+
$information['admin_useremail'] = $user->data->user_email;
|
277 |
+
}
|
278 |
+
}
|
279 |
+
|
280 |
+
try {
|
281 |
+
do_action( 'mainwp_child_site_stats' );
|
282 |
+
} catch ( \Exception $e ) {
|
283 |
+
MainWP_Helper::log_debug( $e->getMessage() );
|
284 |
+
}
|
285 |
+
|
286 |
+
if ( isset( $_POST['othersData'] ) ) {
|
287 |
+
$this->stats_others_data( $information );
|
288 |
+
}
|
289 |
+
|
290 |
+
if ( $exit ) {
|
291 |
+
MainWP_Helper::write( $information );
|
292 |
+
}
|
293 |
+
|
294 |
+
return $information;
|
295 |
+
}
|
296 |
+
|
297 |
+
/**
|
298 |
+
* Get other stats data.
|
299 |
+
*
|
300 |
+
* @param array $information Child Site Stats array.
|
301 |
+
*
|
302 |
+
* @uses \MainWP\Child\MainWP_Helper::update_option()
|
303 |
+
* @uses \MainWP\Child\MainWP_Helper::log_debug()
|
304 |
+
*/
|
305 |
+
private function stats_others_data( &$information ) {
|
306 |
+
|
307 |
+
$othersData = isset( $_POST['othersData'] ) ? json_decode( stripslashes( wp_unslash( $_POST['othersData'] ) ), true ) : array();
|
308 |
+
if ( ! is_array( $othersData ) ) {
|
309 |
+
$othersData = array();
|
310 |
+
}
|
311 |
+
|
312 |
+
if ( isset( $othersData['wpvulndbToken'] ) ) {
|
313 |
+
$wpvulndb_token = get_option( 'mainwp_child_wpvulndb_token', '' );
|
314 |
+
if ( $wpvulndb_token != $othersData['wpvulndbToken'] ) {
|
315 |
+
MainWP_Helper::update_option( 'mainwp_child_wpvulndb_token', $othersData['wpvulndbToken'] );
|
316 |
+
}
|
317 |
+
}
|
318 |
+
|
319 |
+
try {
|
320 |
+
$information = apply_filters_deprecated( 'mainwp-site-sync-others-data', array( $information, $othersData ), '4.0.7.1', 'mainwp_site_sync_others_data' );
|
321 |
+
$information = apply_filters( 'mainwp_site_sync_others_data', $information, $othersData );
|
322 |
+
|
323 |
+
} catch ( \Exception $e ) {
|
324 |
+
MainWP_Helper::log_debug( $e->getMessage() );
|
325 |
+
}
|
326 |
+
}
|
327 |
+
|
328 |
+
/**
|
329 |
+
* Translation update stats.
|
330 |
+
*
|
331 |
+
* @return array $results Returned results.
|
332 |
+
*/
|
333 |
+
private function stats_translation_updates() {
|
334 |
+
$results = array();
|
335 |
+
|
336 |
+
$translation_updates = wp_get_translation_updates();
|
337 |
+
if ( ! empty( $translation_updates ) ) {
|
338 |
+
foreach ( $translation_updates as $translation_update ) {
|
339 |
+
$new_translation_update = array(
|
340 |
+
'type' => $translation_update->type,
|
341 |
+
'slug' => $translation_update->slug,
|
342 |
+
'language' => $translation_update->language,
|
343 |
+
'version' => $translation_update->version,
|
344 |
+
);
|
345 |
+
if ( 'plugin' === $translation_update->type ) {
|
346 |
+
$all_plugins = get_plugins();
|
347 |
+
foreach ( $all_plugins as $file => $plugin ) {
|
348 |
+
$path = dirname( $file );
|
349 |
+
if ( $path == $translation_update->slug ) {
|
350 |
+
$new_translation_update['name'] = $plugin['Name'];
|
351 |
+
break;
|
352 |
+
}
|
353 |
+
}
|
354 |
+
} elseif ( 'theme' === $translation_update->type ) {
|
355 |
+
$theme = wp_get_theme( $translation_update->slug );
|
356 |
+
$new_translation_update['name'] = $theme->name;
|
357 |
+
} elseif ( ( 'core' === $translation_update->type ) && ( 'default' === $translation_update->slug ) ) {
|
358 |
+
$new_translation_update['name'] = 'WordPress core';
|
359 |
+
}
|
360 |
+
|
361 |
+
$results[] = $new_translation_update;
|
362 |
+
}
|
363 |
+
}
|
364 |
+
return $results;
|
365 |
+
}
|
366 |
+
|
367 |
+
/**
|
368 |
+
* Premium theme update stats.
|
369 |
+
*
|
370 |
+
* @param array $premiumThemes Array of premium themes.
|
371 |
+
*
|
372 |
+
* @return array $results Array of premium theme slugs.
|
373 |
+
*
|
374 |
+
* @uses MainWP_Child_Updates::get_instance()::upgrade_get_theme_updates()
|
375 |
+
* @uses \MainWP\Child\MainWP_Child_Updates::upgrade_get_theme_updates()
|
376 |
+
*/
|
377 |
+
private function stats_theme_update( $premiumThemes ) {
|
378 |
+
|
379 |
+
$results = array();
|
380 |
+
|
381 |
+
if ( null !== $this->filterFunction ) {
|
382 |
+
add_filter( 'pre_site_transient_update_themes', $this->filterFunction, 99 );
|
383 |
+
}
|
384 |
+
|
385 |
+
wp_update_themes();
|
386 |
+
include_once ABSPATH . '/wp-admin/includes/theme.php';
|
387 |
+
$theme_updates = MainWP_Child_Updates::get_instance()->upgrade_get_theme_updates();
|
388 |
+
if ( is_array( $theme_updates ) ) {
|
389 |
+
foreach ( $theme_updates as $slug => $theme_update ) {
|
390 |
+
$name = ( is_array( $theme_update ) ? $theme_update['Name'] : $theme_update->Name );
|
391 |
+
if ( in_array( $name, $premiumThemes ) ) {
|
392 |
+
continue;
|
393 |
+
}
|
394 |
+
$results[ $slug ] = $theme_update;
|
395 |
+
}
|
396 |
+
}
|
397 |
+
if ( null !== $this->filterFunction ) {
|
398 |
+
remove_filter( 'pre_site_transient_update_themes', $this->filterFunction, 99 );
|
399 |
+
}
|
400 |
+
|
401 |
+
// Fixes premium themes update.
|
402 |
+
$cached_themes_update = get_site_transient( 'mainwp_update_themes_cached' );
|
403 |
+
if ( is_array( $cached_themes_update ) && ( count( $cached_themes_update ) > 0 ) ) {
|
404 |
+
|
405 |
+
foreach ( $cached_themes_update as $slug => $theme_update ) {
|
406 |
+
$name = ( is_array( $theme_update ) ? $theme_update['Name'] : $theme_update->Name );
|
407 |
+
if ( in_array( $name, $premiumThemes ) ) {
|
408 |
+
continue;
|
409 |
+
}
|
410 |
+
if ( isset( $results[ $slug ] ) ) {
|
411 |
+
continue;
|
412 |
+
}
|
413 |
+
$results[ $slug ] = $theme_update;
|
414 |
+
}
|
415 |
+
}
|
416 |
+
|
417 |
+
return $results;
|
418 |
+
}
|
419 |
+
|
420 |
+
/**
|
421 |
+
* Get Server Info stats & append to end of Child Site stats.
|
422 |
+
*
|
423 |
+
* @param array $information Child Site Stats.
|
424 |
+
*
|
425 |
+
* @uses MainWP_Child::$version
|
426 |
+
* @uses MainWP_Child_Server_Information::get_php_memory_limit()
|
427 |
+
* @uses MainWP_Child_Server_Information::get_my_sql_version()
|
428 |
+
* @uses MainWP_Helper::is_wp_engine()
|
429 |
+
* @uses MainWP_Helper::update_option()
|
430 |
+
* @uses phpversion()
|
431 |
+
* @uses \MainWP\Child\MainWP_Child::$version
|
432 |
+
* @uses \MainWP\Child\MainWP_Child_Server_Information::get_php_memory_limit()
|
433 |
+
* @uses \MainWP\Child\MainWP_Child_Server_Information::get_my_sql_version()
|
434 |
+
*/
|
435 |
+
private function stats_get_info( &$information ) {
|
436 |
+
|
437 |
+
/**
|
438 |
+
* The installed version of WordPress.
|
439 |
+
*
|
440 |
+
* @global string $wp_version The installed version of WordPress.
|
441 |
+
*
|
442 |
+
* @uses \MainWP\Child\MainWP_Child::$version
|
443 |
+
* @uses \MainWP\Child\MainWP_Helper::is_wp_engine()
|
444 |
+
* @uses \MainWP\Child\MainWP_Helper::is_ssl_enabled()
|
445 |
+
* @uses \MainWP\Child\MainWP_Helper::update_option()
|
446 |
+
*/
|
447 |
+
global $wp_version;
|
448 |
+
|
449 |
+
$information['version'] = MainWP_Child::$version;
|
450 |
+
$information['wpversion'] = $wp_version;
|
451 |
+
$information['siteurl'] = get_option( 'siteurl' );
|
452 |
+
$information['wpe'] = MainWP_Helper::is_wp_engine() ? 1 : 0;
|
453 |
+
$theme_name = wp_get_theme()->get( 'Name' );
|
454 |
+
$information['site_info'] = array(
|
455 |
+
'wpversion' => $wp_version,
|
456 |
+
'debug_mode' => ( defined( 'WP_DEBUG' ) && true === WP_DEBUG ) ? true : false,
|
457 |
+
'phpversion' => phpversion(),
|
458 |
+
'child_version' => MainWP_Child::$version,
|
459 |
+
'memory_limit' => MainWP_Child_Server_Information::get_php_memory_limit(),
|
460 |
+
'mysql_version' => MainWP_Child_Server_Information::get_my_sql_version(),
|
461 |
+
'themeactivated' => $theme_name,
|
462 |
+
'ip' => isset( $_SERVER['SERVER_ADDR'] ) ? wp_unslash( $_SERVER['SERVER_ADDR'] ) : '',
|
463 |
+
);
|
464 |
+
|
465 |
+
// Try to switch to SSL if SSL is enabled in between.
|
466 |
+
$pubkey = get_option( 'mainwp_child_pubkey' );
|
467 |
+
$nossl = get_option( 'mainwp_child_nossl' );
|
468 |
+
if ( 1 == $nossl ) {
|
469 |
+
if ( isset( $pubkey ) && MainWP_Helper::is_ssl_enabled() ) {
|
470 |
+
MainWP_Helper::update_option( 'mainwp_child_nossl', 0, 'yes' );
|
471 |
+
$nossl = 0;
|
472 |
+
}
|
473 |
+
}
|
474 |
+
$information['nossl'] = ( 1 == $nossl ? 1 : 0 );
|
475 |
+
}
|
476 |
+
|
477 |
+
/**
|
478 |
+
* Get WordPress update stats.
|
479 |
+
*
|
480 |
+
* @return string|bool|null Return TRUE if the relationship is the one specified by the operator <=,
|
481 |
+
* FALSE otherwise, null by default.
|
482 |
+
*/
|
483 |
+
private function stats_wp_update() {
|
484 |
+
|
485 |
+
/**
|
486 |
+
* The installed version of WordPress.
|
487 |
+
*
|
488 |
+
* @global string $wp_version The installed version of WordPress.
|
489 |
+
*/
|
490 |
+
global $wp_version;
|
491 |
+
|
492 |
+
$result = null;
|
493 |
+
|
494 |
+
// Check for new versions.
|
495 |
+
if ( null !== $this->filterFunction ) {
|
496 |
+
add_filter( 'pre_site_transient_update_core', $this->filterFunction, 99 );
|
497 |
+
}
|
498 |
+
if ( null !== $this->filterFunction ) {
|
499 |
+
add_filter( 'pre_transient_update_core', $this->filterFunction, 99 );
|
500 |
+
}
|
501 |
+
|
502 |
+
wp_version_check();
|
503 |
+
|
504 |
+
$core_updates = get_core_updates();
|
505 |
+
|
506 |
+
if ( is_array( $core_updates ) && count( $core_updates ) > 0 ) {
|
507 |
+
foreach ( $core_updates as $core_update ) {
|
508 |
+
if ( 'latest' === $core_update->response ) {
|
509 |
+
break;
|
510 |
+
}
|
511 |
+
if ( 'upgrade' === $core_update->response && version_compare( $wp_version, $core_update->current, '<=' ) ) {
|
512 |
+
$result = $core_update->current;
|
513 |
+
}
|
514 |
+
}
|
515 |
+
}
|
516 |
+
|
517 |
+
if ( null !== $this->filterFunction ) {
|
518 |
+
remove_filter( 'pre_site_transient_update_core', $this->filterFunction, 99 );
|
519 |
+
}
|
520 |
+
|
521 |
+
if ( null !== $this->filterFunction ) {
|
522 |
+
remove_filter( 'pre_transient_update_core', $this->filterFunction, 99 );
|
523 |
+
}
|
524 |
+
|
525 |
+
return $result;
|
526 |
+
}
|
527 |
+
|
528 |
+
/**
|
529 |
+
* Check for premium updates.
|
530 |
+
*
|
531 |
+
* @param array $information Child Site stats.
|
532 |
+
* @param array $premiumPlugins Active premium plugins.
|
533 |
+
* @param array $premiumThemes Active premium themes.
|
534 |
+
*
|
535 |
+
* @uses \MainWP\Child\MainWP_Helper::update_option()
|
536 |
+
*/
|
537 |
+
private function check_premium_updates( &$information, &$premiumPlugins, &$premiumThemes ) {
|
538 |
+
|
539 |
+
// First check for new premium updates.
|
540 |
+
$update_check = apply_filters( 'mwp_premium_update_check', array() );
|
541 |
+
|
542 |
+
if ( ! empty( $update_check ) ) {
|
543 |
+
foreach ( $update_check as $updateFeedback ) {
|
544 |
+
if ( is_array( $updateFeedback['callback'] ) && isset( $updateFeedback['callback'][0] ) && isset( $updateFeedback['callback'][1] ) ) {
|
545 |
+
call_user_func( array( $updateFeedback['callback'][0], $updateFeedback['callback'][1] ) );
|
546 |
+
} elseif ( is_string( $updateFeedback['callback'] ) ) {
|
547 |
+
call_user_func( $updateFeedback['callback'] );
|
548 |
+
}
|
549 |
+
}
|
550 |
+
}
|
551 |
+
|
552 |
+
$informationPremiumUpdates = apply_filters( 'mwp_premium_update_notification', array() );
|
553 |
+
$premiumPlugins = array();
|
554 |
+
$premiumThemes = array();
|
555 |
+
|
556 |
+
if ( is_array( $informationPremiumUpdates ) ) {
|
557 |
+
$premiumUpdates = array();
|
558 |
+
$informationPremiumUpdatesLength = count( $informationPremiumUpdates );
|
559 |
+
for ( $i = 0; $i < $informationPremiumUpdatesLength; $i ++ ) {
|
560 |
+
if ( ! isset( $informationPremiumUpdates[ $i ]['new_version'] ) ) {
|
561 |
+
continue;
|
562 |
+
}
|
563 |
+
$slug = ( isset( $informationPremiumUpdates[ $i ]['slug'] ) ? $informationPremiumUpdates[ $i ]['slug'] : $informationPremiumUpdates[ $i ]['Name'] );
|
564 |
+
|
565 |
+
if ( 'plugin' === $informationPremiumUpdates[ $i ]['type'] ) {
|
566 |
+
$premiumPlugins[] = $slug;
|
567 |
+
} elseif ( 'theme' === $informationPremiumUpdates[ $i ]['type'] ) {
|
568 |
+
$premiumThemes[] = $slug;
|
569 |
+
}
|
570 |
+
|
571 |
+
$new_version = $informationPremiumUpdates[ $i ]['new_version'];
|
572 |
+
|
573 |
+
unset( $informationPremiumUpdates[ $i ]['old_version'] );
|
574 |
+
unset( $informationPremiumUpdates[ $i ]['new_version'] );
|
575 |
+
|
576 |
+
if ( ! isset( $information['premium_updates'] ) ) {
|
577 |
+
$information['premium_updates'] = array();
|
578 |
+
}
|
579 |
+
|
580 |
+
$information['premium_updates'][ $slug ] = $informationPremiumUpdates[ $i ];
|
581 |
+
$information['premium_updates'][ $slug ]['update'] = (object) array(
|
582 |
+
'new_version' => $new_version,
|
583 |
+
'premium' => true,
|
584 |
+
'slug' => $slug,
|
585 |
+
);
|
586 |
+
|
587 |
+
if ( ! in_array( $slug, $premiumUpdates ) ) {
|
588 |
+
$premiumUpdates[] = $slug;
|
589 |
+
}
|
590 |
+
}
|
591 |
+
MainWP_Helper::update_option( 'mainwp_premium_updates', $premiumUpdates );
|
592 |
+
}
|
593 |
+
}
|
594 |
+
|
595 |
+
/**
|
596 |
+
* Premium plugin update stats.
|
597 |
+
*
|
598 |
+
* @param array $premiumPlugins Active premium plugins.
|
599 |
+
* @return array $results Array of premium plugin slugs.
|
600 |
+
*/
|
601 |
+
private function stats_plugin_update( $premiumPlugins ) {
|
602 |
+
|
603 |
+
$results = array();
|
604 |
+
|
605 |
+
if ( null !== $this->filterFunction ) {
|
606 |
+
add_filter( 'pre_site_transient_update_plugins', $this->filterFunction, 99 );
|
607 |
+
}
|
608 |
+
|
609 |
+
/**
|
610 |
+
* Retrieve the name of the current filter or action.
|
611 |
+
*
|
612 |
+
* @global array $wp_current_filter Current filter.
|
613 |
+
*/
|
614 |
+
global $wp_current_filter;
|
615 |
+
|
616 |
+
$wp_current_filter[] = 'load-plugins.php'; // phpcs:ignore -- Required to achieve desired results, pull request solutions appreciated.
|
617 |
+
|
618 |
+
wp_update_plugins();
|
619 |
+
include_once ABSPATH . '/wp-admin/includes/plugin.php';
|
620 |
+
|
621 |
+
$plugin_updates = get_plugin_updates();
|
622 |
+
if ( is_array( $plugin_updates ) ) {
|
623 |
+
|
624 |
+
foreach ( $plugin_updates as $slug => $plugin_update ) {
|
625 |
+
if ( in_array( $plugin_update->Name, $premiumPlugins ) ) {
|
626 |
+
continue;
|
627 |
+
}
|
628 |
+
|
629 |
+
// Fixes incorrect info.
|
630 |
+
if ( ! property_exists( $plugin_update, 'update' ) || ! property_exists( $plugin_update->update, 'new_version' ) || empty( $plugin_update->update->new_version ) ) {
|
631 |
+
continue;
|
632 |
+
}
|
633 |
+
$plugin_update->active = is_plugin_active( $slug ) ? 1 : 0;
|
634 |
+
$results[ $slug ] = $plugin_update;
|
635 |
+
}
|
636 |
+
}
|
637 |
+
|
638 |
+
if ( null !== $this->filterFunction ) {
|
639 |
+
remove_filter( 'pre_site_transient_update_plugins', $this->filterFunction, 99 );
|
640 |
+
}
|
641 |
+
|
642 |
+
// Fixes premium plugins update.
|
643 |
+
$cached_plugins_update = get_site_transient( 'mainwp_update_plugins_cached' );
|
644 |
+
if ( is_array( $cached_plugins_update ) && ( count( $cached_plugins_update ) > 0 ) ) {
|
645 |
+
foreach ( $cached_plugins_update as $slug => $plugin_update ) {
|
646 |
+
|
647 |
+
// Fixes incorrect info.
|
648 |
+
if ( ! property_exists( $plugin_update, 'new_version' ) || empty( $plugin_update->new_version ) ) { // may do not need to check this?
|
649 |
+
// Fixes some premiums update info.
|
650 |
+
if ( property_exists( $plugin_update, 'update' ) ) {
|
651 |
+
if ( ! property_exists( $plugin_update->update, 'new_version' ) || empty( $plugin_update->update->new_version ) ) {
|
652 |
+
continue;
|
653 |
+
}
|
654 |
+
} else {
|
655 |
+
continue;
|
656 |
+
}
|
657 |
+
}
|
658 |
+
|
659 |
+
if ( ! isset( $results[ $slug ] ) ) {
|
660 |
+
$plugin_update->active = is_plugin_active( $slug ) ? 1 : 0;
|
661 |
+
$results[ $slug ] = $plugin_update;
|
662 |
+
}
|
663 |
+
}
|
664 |
+
}
|
665 |
+
|
666 |
+
return $results;
|
667 |
+
}
|
668 |
+
|
669 |
+
/**
|
670 |
+
* Ger category stats.
|
671 |
+
*
|
672 |
+
* @return array $categories Available Child Site Categories.
|
673 |
+
*/
|
674 |
+
private function stats_get_categories() {
|
675 |
+
|
676 |
+
$cats = get_categories(
|
677 |
+
array(
|
678 |
+
'hide_empty' => 0,
|
679 |
+
'hierarchical' => true,
|
680 |
+
'number' => 300,
|
681 |
+
)
|
682 |
+
);
|
683 |
+
$categories = array();
|
684 |
+
foreach ( $cats as $cat ) {
|
685 |
+
$categories[] = $cat->name;
|
686 |
+
}
|
687 |
+
|
688 |
+
return $categories;
|
689 |
+
}
|
690 |
+
|
691 |
+
/**
|
692 |
+
* Get total size of Child Site installation.
|
693 |
+
*
|
694 |
+
* @uses MainWP_Child_Stats::get_total_file_size()
|
695 |
+
*
|
696 |
+
* @return float|int|null $total Total file size or 0 or null.
|
697 |
+
*/
|
698 |
+
private function stats_get_total_size() {
|
699 |
+
$total = null;
|
700 |
+
|
701 |
+
$get_file_size = apply_filters_deprecated( 'mainwp-child-get-total-size', array( true ), '4.0.7.1', 'mainwp_child_get_total_size' );
|
702 |
+
$get_file_size = apply_filters( 'mainwp_child_get_total_size', $get_file_size );
|
703 |
+
$forced_get_file_size = apply_filters( 'mainwp_child_forced_get_total_size', false );
|
704 |
+
|
705 |
+
if ( $forced_get_file_size || ( $get_file_size && isset( $_POST['cloneSites'] ) && ( '0' !== $_POST['cloneSites'] ) ) ) {
|
706 |
+
$max_exe = ini_get( 'max_execution_time' );
|
707 |
+
if ( $forced_get_file_size || $max_exe > 20 ) {
|
708 |
+
$total = $this->get_total_file_size();
|
709 |
+
}
|
710 |
+
}
|
711 |
+
|
712 |
+
return $total;
|
713 |
+
}
|
714 |
+
|
715 |
+
/**
|
716 |
+
* Get recent number.
|
717 |
+
*
|
718 |
+
* @return int $recent_number Recent number.
|
719 |
+
*/
|
720 |
+
private function get_recent_number() {
|
721 |
+
|
722 |
+
$recent_number = 5;
|
723 |
+
|
724 |
+
if ( isset( $_POST ) && isset( $_POST['recent_number'] ) ) {
|
725 |
+
$recent_number = intval( wp_unslash( $_POST['recent_number'] ) );
|
726 |
+
if ( get_option( 'mainwp_child_recent_number', 5 ) != $recent_number ) {
|
727 |
+
update_option( 'mainwp_child_recent_number', $recent_number );
|
728 |
+
}
|
729 |
+
} else {
|
730 |
+
$recent_number = get_option( 'mainwp_child_recent_number', 5 );
|
731 |
+
}
|
732 |
+
|
733 |
+
if ( $recent_number <= 0 || $recent_number > 30 ) {
|
734 |
+
$recent_number = 5;
|
735 |
+
}
|
736 |
+
|
737 |
+
return $recent_number;
|
738 |
+
}
|
739 |
+
|
740 |
+
|
741 |
+
/**
|
742 |
+
* Update options: mainwp_child_clone_sites, mainwp_child_siteid, mainwp_child_pluginDir.
|
743 |
+
*
|
744 |
+
* @uses \MainWP\Child\MainWP_Helper::update_option()
|
745 |
+
*/
|
746 |
+
public function update_external_settings() {
|
747 |
+
if ( isset( $_POST['cloneSites'] ) ) {
|
748 |
+
if ( '0' !== $_POST['cloneSites'] ) {
|
749 |
+
$arr = isset( $_POST['cloneSites'] ) ? json_decode( urldecode( wp_unslash( $_POST['cloneSites'] ) ), 1 ) : '';
|
750 |
+
MainWP_Helper::update_option( 'mainwp_child_clone_sites', ( ! is_array( $arr ) ? array() : $arr ) );
|
751 |
+
} else {
|
752 |
+
MainWP_Helper::update_option( 'mainwp_child_clone_sites', '0' );
|
753 |
+
}
|
754 |
+
}
|
755 |
+
|
756 |
+
if ( isset( $_POST['siteId'] ) ) {
|
757 |
+
MainWP_Helper::update_option( 'mainwp_child_siteid', intval( wp_unslash( $_POST['siteId'] ) ) );
|
758 |
+
}
|
759 |
+
|
760 |
+
if ( isset( $_POST['pluginDir'] ) ) {
|
761 |
+
if ( get_option( 'mainwp_child_pluginDir' ) !== $_POST['pluginDir'] ) {
|
762 |
+
MainWP_Helper::update_option( 'mainwp_child_pluginDir', ( ! empty( $_POST['pluginDir'] ) ? wp_unslash( $_POST['pluginDir'] ) : '' ), 'yes' );
|
763 |
+
}
|
764 |
+
} elseif ( false !== get_option( 'mainwp_child_pluginDir' ) ) {
|
765 |
+
MainWP_Helper::update_option( 'mainwp_child_pluginDir', false, 'yes' );
|
766 |
+
}
|
767 |
+
}
|
768 |
+
|
769 |
+
/**
|
770 |
+
* Get total size of wp_content directory.
|
771 |
+
*
|
772 |
+
* @param string $directory WordPress content directory.
|
773 |
+
* @return float|int Return $size or 0.
|
774 |
+
*
|
775 |
+
* @uses \MainWP\Child\MainWP_Helper::funct_exists()
|
776 |
+
* @uses \MainWP\Child\MainWP_Helper::get_mainwp_dir()
|
777 |
+
* @uses \MainWP\Child\MainWP_Helper::ctype_digit()
|
778 |
+
*/
|
779 |
+
public function get_total_file_size( $directory = WP_CONTENT_DIR ) {
|
780 |
+
try {
|
781 |
+
if ( MainWP_Helper::funct_exists( 'popen' ) ) {
|
782 |
+
$uploadDir = MainWP_Helper::get_mainwp_dir();
|
783 |
+
$uploadDir = $uploadDir[0];
|
784 |
+
$popenHandle = popen( 'du -s ' . $directory . ' --exclude "' . str_replace( ABSPATH, '', $uploadDir ) . '"', 'r' ); // phpcs:ignore -- run if enabled.
|
785 |
+
if ( 'resource' === gettype( $popenHandle ) ) {
|
786 |
+
$size = fread( $popenHandle, 1024 ); //phpcs:ignore -- custom read file.
|
787 |
+
pclose( $popenHandle );
|
788 |
+
$size = substr( $size, 0, strpos( $size, "\t" ) );
|
789 |
+
if ( $size && MainWP_Helper::ctype_digit( $size ) ) {
|
790 |
+
return $size / 1024;
|
791 |
+
}
|
792 |
+
}
|
793 |
+
}
|
794 |
+
|
795 |
+
if ( MainWP_Helper::funct_exists( 'shell_exec' ) ) {
|
796 |
+
$uploadDir = MainWP_Helper::get_mainwp_dir();
|
797 |
+
$uploadDir = $uploadDir[0];
|
798 |
+
$size = shell_exec( 'du -s ' . $directory . ' --exclude "' . str_replace( ABSPATH, '', $uploadDir ) . '"' ); // phpcs:ignore -- run if enabled.
|
799 |
+
if ( null !== $size ) {
|
800 |
+
$size = substr( $size, 0, strpos( $size, "\t" ) );
|
801 |
+
if ( $size && MainWP_Helper::ctype_digit( $size ) ) {
|
802 |
+
return $size / 1024;
|
803 |
+
}
|
804 |
+
}
|
805 |
+
}
|
806 |
+
if ( class_exists( '\COM' ) ) {
|
807 |
+
$obj = new \COM( 'scripting.filesystemobject' );
|
808 |
+
|
809 |
+
if ( is_object( $obj ) ) {
|
810 |
+
$ref = $obj->getfolder( $directory );
|
811 |
+
|
812 |
+
$size = $ref->size;
|
813 |
+
|
814 |
+
$obj = null;
|
815 |
+
if ( MainWP_Helper::ctype_digit( $size ) ) {
|
816 |
+
return $size / 1024;
|
817 |
+
}
|
818 |
+
}
|
819 |
+
}
|
820 |
+
// to fix for window host, performance not good?
|
821 |
+
if ( class_exists( '\RecursiveIteratorIterator' ) ) {
|
822 |
+
$size = 0;
|
823 |
+
foreach ( new \RecursiveIteratorIterator( new \RecursiveDirectoryIterator( $directory ) ) as $file ) {
|
824 |
+
$size += $file->getSize();
|
825 |
+
}
|
826 |
+
if ( $size && MainWP_Helper::ctype_digit( $size ) ) {
|
827 |
+
return $size / 1024 / 1024;
|
828 |
+
}
|
829 |
+
}
|
830 |
+
return 0;
|
831 |
+
} catch ( \Exception $e ) {
|
832 |
+
return 0;
|
833 |
+
}
|
834 |
+
}
|
835 |
+
|
836 |
+
/**
|
837 |
+
* Scan directory.
|
838 |
+
*
|
839 |
+
* @param string $pDir Directory to scan.
|
840 |
+
* @param string $pLvl How deep to scan.
|
841 |
+
*
|
842 |
+
* @uses MainWP_Child_Stats::scan_dir()
|
843 |
+
* @uses MainWP_Child_Stats::int_scan_dir()
|
844 |
+
*
|
845 |
+
* @return array|null $output|$files
|
846 |
+
*/
|
847 |
+
public function scan_dir( $pDir, $pLvl ) {
|
848 |
+
$output = array();
|
849 |
+
if ( file_exists( $pDir ) && is_dir( $pDir ) ) {
|
850 |
+
if ( 'logs' === basename( $pDir ) ) {
|
851 |
+
return empty( $output ) ? null : $output;
|
852 |
+
}
|
853 |
+
if ( 0 === $pLvl ) {
|
854 |
+
return empty( $output ) ? null : $output;
|
855 |
+
}
|
856 |
+
$files = $this->int_scan_dir( $pDir );
|
857 |
+
if ( $files ) {
|
858 |
+
foreach ( $files as $file ) {
|
859 |
+
if ( ( '.' === $file ) || ( '..' === $file ) ) {
|
860 |
+
continue;
|
861 |
+
}
|
862 |
+
$newDir = $pDir . $file . DIRECTORY_SEPARATOR;
|
863 |
+
if ( is_dir( $newDir ) ) {
|
864 |
+
$output[ $file ] = $this->scan_dir( $newDir, $pLvl - 1, false );
|
865 |
+
}
|
866 |
+
}
|
867 |
+
|
868 |
+
unset( $files );
|
869 |
+
$files = null;
|
870 |
+
}
|
871 |
+
}
|
872 |
+
|
873 |
+
return empty( $output ) ? null : $output;
|
874 |
+
}
|
875 |
+
|
876 |
+
/**
|
877 |
+
* Initiate directory scan.
|
878 |
+
*
|
879 |
+
* @param string $dir Directory to scan.
|
880 |
+
*
|
881 |
+
* @return array|bool $out|FALSE Returns the entry name on success or FALSE on failure.
|
882 |
+
*/
|
883 |
+
public function int_scan_dir( $dir ) {
|
884 |
+
$dh = opendir( $dir );
|
885 |
+
if ( is_dir( $dir ) && $dh ) {
|
886 |
+
$cnt = 0;
|
887 |
+
$out = array();
|
888 |
+
$file = readdir( $dh );
|
889 |
+
while ( false !== $file ) {
|
890 |
+
$newDir = $dir . $file . DIRECTORY_SEPARATOR;
|
891 |
+
if ( ! is_dir( $newDir ) ) {
|
892 |
+
$file = readdir( $dh );
|
893 |
+
continue;
|
894 |
+
}
|
895 |
+
|
896 |
+
$out[] = $file;
|
897 |
+
$file = readdir( $dh );
|
898 |
+
|
899 |
+
if ( $cnt ++ > 10 ) {
|
900 |
+
break;
|
901 |
+
}
|
902 |
+
}
|
903 |
+
closedir( $dh );
|
904 |
+
|
905 |
+
return $out;
|
906 |
+
}
|
907 |
+
|
908 |
+
return false;
|
909 |
+
}
|
910 |
+
|
911 |
+
/**
|
912 |
+
* Get all themes.
|
913 |
+
*
|
914 |
+
* @uses \MainWP\Child\MainWP_Child_Stats::get_all_themes_int()
|
915 |
+
* @uses \MainWP\Child\MainWP_Helper::write()
|
916 |
+
*/
|
917 |
+
public function get_all_themes() {
|
918 |
+
$keyword = isset( $_POST['keyword'] ) ? sanitize_text_field( wp_unslash( $_POST['keyword'] ) ) : '';
|
919 |
+
$status = isset( $_POST['status'] ) ? sanitize_text_field( wp_unslash( $_POST['status'] ) ) : '';
|
920 |
+
$filter = isset( $_POST['filter'] ) ? sanitize_text_field( wp_unslash( $_POST['filter'] ) ) : true;
|
921 |
+
$rslt = $this->get_all_themes_int( $filter, $keyword, $status );
|
922 |
+
|
923 |
+
MainWP_Helper::write( $rslt );
|
924 |
+
}
|
925 |
+
|
926 |
+
/**
|
927 |
+
* Initiate get all themes.
|
928 |
+
*
|
929 |
+
* @param string $filter Sites filter field.
|
930 |
+
* @param string $keyword Keyword Search field.
|
931 |
+
* @param string $status Active or Inactive filed.
|
932 |
+
*
|
933 |
+
* @return array $rslt Returned themes results.
|
934 |
+
*/
|
935 |
+
public function get_all_themes_int( $filter, $keyword = '', $status = '' ) {
|
936 |
+
$rslt = array();
|
937 |
+
$themes = wp_get_themes();
|
938 |
+
|
939 |
+
if ( is_array( $themes ) ) {
|
940 |
+
$theme_name = wp_get_theme()->get( 'Name' );
|
941 |
+
|
942 |
+
foreach ( $themes as $theme ) {
|
943 |
+
$out = array();
|
944 |
+
$out['name'] = $theme->get( 'Name' );
|
945 |
+
$out['title'] = $theme->display( 'Name', true, false );
|
946 |
+
$out['description'] = $theme->display( 'Description', true, false );
|
947 |
+
$out['version'] = $theme->display( 'Version', true, false );
|
948 |
+
$out['active'] = ( $theme->get( 'Name' ) === $theme_name ) ? 1 : 0;
|
949 |
+
$out['slug'] = $theme->get_stylesheet();
|
950 |
+
if ( ! $filter ) {
|
951 |
+
if ( '' == $keyword || stristr( $out['title'], $keyword ) ) {
|
952 |
+
$rslt[] = $out;
|
953 |
+
}
|
954 |
+
} elseif ( ( ( 'active' === $status ) ? 1 : 0 ) === $out['active'] ) {
|
955 |
+
if ( '' == $keyword || stristr( $out['title'], $keyword ) ) {
|
956 |
+
$rslt[] = $out;
|
957 |
+
}
|
958 |
+
}
|
959 |
+
}
|
960 |
+
}
|
961 |
+
|
962 |
+
return $rslt;
|
963 |
+
}
|
964 |
+
|
965 |
+
/**
|
966 |
+
* Get all Plugins.
|
967 |
+
*
|
968 |
+
* @uses \MainWP\Child\MainWP_Child_Stats::get_all_plugins_int()
|
969 |
+
* @uses \MainWP\Child\MainWP_Helper::write()
|
970 |
+
*/
|
971 |
+
public function get_all_plugins() {
|
972 |
+
$keyword = isset( $_POST['keyword'] ) ? sanitize_text_field( wp_unslash( $_POST['keyword'] ) ) : '';
|
973 |
+
$status = isset( $_POST['status'] ) ? sanitize_text_field( wp_unslash( $_POST['status'] ) ) : '';
|
974 |
+
$filter = isset( $_POST['filter'] ) ? sanitize_text_field( wp_unslash( $_POST['filter'] ) ) : true;
|
975 |
+
$rslt = $this->get_all_plugins_int( $filter, $keyword, $status );
|
976 |
+
|
977 |
+
MainWP_Helper::write( $rslt );
|
978 |
+
}
|
979 |
+
|
980 |
+
/**
|
981 |
+
* Initiate get all plugins.
|
982 |
+
*
|
983 |
+
* @param string $filter Sites filter field.
|
984 |
+
* @param string $keyword Keyword Search field.
|
985 |
+
* @param string $status Active or Inactive filed.
|
986 |
+
*
|
987 |
+
* @return array $rslt Returned themes results.
|
988 |
+
*/
|
989 |
+
public function get_all_plugins_int( $filter, $keyword = '', $status = '' ) {
|
990 |
+
if ( ! function_exists( 'get_plugins' ) ) {
|
991 |
+
include_once ABSPATH . 'wp-admin/includes/plugin.php';
|
992 |
+
}
|
993 |
+
|
994 |
+
/**
|
995 |
+
* MainWP Child instance.
|
996 |
+
*
|
997 |
+
* @global object
|
998 |
+
*/
|
999 |
+
global $mainWPChild;
|
1000 |
+
|
1001 |
+
$rslt = array();
|
1002 |
+
$plugins = get_plugins();
|
1003 |
+
if ( is_array( $plugins ) ) {
|
1004 |
+
$active_plugins = get_option( 'active_plugins' );
|
1005 |
+
|
1006 |
+
foreach ( $plugins as $pluginslug => $plugin ) {
|
1007 |
+
$out = array();
|
1008 |
+
$out['mainwp'] = ( $pluginslug == $mainWPChild->plugin_slug ? 'T' : 'F' );
|
1009 |
+
$out['name'] = $plugin['Name'];
|
1010 |
+
$out['slug'] = $pluginslug;
|
1011 |
+
$out['description'] = $plugin['Description'];
|
1012 |
+
$out['version'] = $plugin['Version'];
|
1013 |
+
$out['active'] = is_plugin_active( $pluginslug ) ? 1 : 0;
|
1014 |
+
if ( ! $filter ) {
|
1015 |
+
if ( '' == $keyword || stristr( $out['name'], $keyword ) ) {
|
1016 |
+
$rslt[] = $out;
|
1017 |
+
}
|
1018 |
+
} elseif ( ( ( 'active' == $status ) ? 1 : 0 ) == $out['active'] ) {
|
1019 |
+
if ( '' == $keyword || stristr( $out['name'], $keyword ) ) {
|
1020 |
+
$rslt[] = $out;
|
1021 |
+
}
|
1022 |
+
}
|
1023 |
+
}
|
1024 |
+
}
|
1025 |
+
|
1026 |
+
$muplugins = get_mu_plugins();
|
1027 |
+
if ( is_array( $muplugins ) ) {
|
1028 |
+
foreach ( $muplugins as $pluginslug => $plugin ) {
|
1029 |
+
$out = array();
|
1030 |
+
$out['mainwp'] = ( $pluginslug == $mainWPChild->plugin_slug ? 'T' : 'F' );
|
1031 |
+
$out['name'] = $plugin['Name'];
|
1032 |
+
$out['slug'] = $pluginslug;
|
1033 |
+
$out['description'] = $plugin['Description'];
|
1034 |
+
$out['version'] = $plugin['Version'];
|
1035 |
+
$out['active'] = 1;
|
1036 |
+
$out['mu'] = 1;
|
1037 |
+
if ( ! $filter ) {
|
1038 |
+
if ( '' == $keyword || stristr( $out['name'], $keyword ) ) {
|
1039 |
+
$rslt[] = $out;
|
1040 |
+
}
|
1041 |
+
} elseif ( ( ( 'active' == $status ) ? 1 : 0 ) == $out['active'] ) {
|
1042 |
+
if ( '' == $keyword || stristr( $out['name'], $keyword ) ) {
|
1043 |
+
$rslt[] = $out;
|
1044 |
+
}
|
1045 |
+
}
|
1046 |
+
}
|
1047 |
+
}
|
1048 |
+
|
1049 |
+
return $rslt;
|
1050 |
+
}
|
1051 |
+
|
1052 |
+
/**
|
1053 |
+
* Get WP Site Health issues.
|
1054 |
+
*
|
1055 |
+
* @return array $issue_counts Returned issues.
|
1056 |
+
*/
|
1057 |
+
public function get_health_check_site_status() {
|
1058 |
+
$get_issues = get_transient( 'health-check-site-status-result' );
|
1059 |
+
$issue_counts = array();
|
1060 |
+
if ( false !== $get_issues ) {
|
1061 |
+
$issue_counts = json_decode( $get_issues, true );
|
1062 |
+
}
|
1063 |
+
if ( ! is_array( $issue_counts ) || ! $issue_counts ) {
|
1064 |
+
$issue_counts = array(
|
1065 |
+
'good' => 0,
|
1066 |
+
'recommended' => 0,
|
1067 |
+
'critical' => 0,
|
1068 |
+
);
|
1069 |
+
}
|
1070 |
+
return $issue_counts;
|
1071 |
+
}
|
1072 |
+
}
|
class/class-mainwp-child-updates.php
CHANGED
@@ -1,997 +1,997 @@
|
|
1 |
-
<?php
|
2 |
-
/**
|
3 |
-
* MainWP Updates
|
4 |
-
*
|
5 |
-
* Manage updates on the site.
|
6 |
-
*
|
7 |
-
* @package MainWP\Child
|
8 |
-
*/
|
9 |
-
|
10 |
-
namespace MainWP\Child;
|
11 |
-
|
12 |
-
//phpcs:disable Generic.Metrics.CyclomaticComplexity -- Current complexity is the only way to achieve desired results, pull request solutions appreciated.
|
13 |
-
|
14 |
-
/**
|
15 |
-
* Class MainWP_Child_Updates
|
16 |
-
*
|
17 |
-
* Manage updates on the site.
|
18 |
-
*/
|
19 |
-
class MainWP_Child_Updates {
|
20 |
-
|
21 |
-
/**
|
22 |
-
* Public static variable to hold the single instance of the class.
|
23 |
-
*
|
24 |
-
* @var mixed Default null
|
25 |
-
*/
|
26 |
-
protected static $instance = null;
|
27 |
-
|
28 |
-
/**
|
29 |
-
* Private variable to filter update transients without last_checked and checked fields.
|
30 |
-
*
|
31 |
-
* @var object Filter update transients.
|
32 |
-
*/
|
33 |
-
private $filterFunction = null;
|
34 |
-
|
35 |
-
|
36 |
-
/**
|
37 |
-
* Method get_class_name()
|
38 |
-
*
|
39 |
-
* Get class name.
|
40 |
-
*
|
41 |
-
* @return string __CLASS__ Class name.
|
42 |
-
*/
|
43 |
-
public static function get_class_name() {
|
44 |
-
return __CLASS__;
|
45 |
-
}
|
46 |
-
|
47 |
-
/**
|
48 |
-
* MainWP_Child_Updates constructor.
|
49 |
-
*
|
50 |
-
* Run any time class is called.
|
51 |
-
*/
|
52 |
-
public function __construct() {
|
53 |
-
$this->filterFunction = function( $a ) {
|
54 |
-
if ( null == $a ) {
|
55 |
-
return false;
|
56 |
-
}
|
57 |
-
if ( is_object( $a ) && property_exists( $a, 'last_checked' ) && ! property_exists( $a, 'checked' ) ) {
|
58 |
-
return false;
|
59 |
-
}
|
60 |
-
return $a;
|
61 |
-
};
|
62 |
-
}
|
63 |
-
|
64 |
-
/**
|
65 |
-
* Method get_instance()
|
66 |
-
*
|
67 |
-
* Create a public static instance.
|
68 |
-
*
|
69 |
-
* @return mixed Class instance.
|
70 |
-
*/
|
71 |
-
public static function get_instance() {
|
72 |
-
if ( null === self::$instance ) {
|
73 |
-
self::$instance = new self();
|
74 |
-
}
|
75 |
-
|
76 |
-
return self::$instance;
|
77 |
-
}
|
78 |
-
|
79 |
-
/**
|
80 |
-
* Method include_updates()
|
81 |
-
*
|
82 |
-
* Include WP Core files required for performing updates.
|
83 |
-
*/
|
84 |
-
private function include_updates() {
|
85 |
-
include_once ABSPATH . '/wp-admin/includes/class-wp-upgrader.php';
|
86 |
-
|
87 |
-
if ( file_exists( ABSPATH . '/wp-admin/includes/screen.php' ) ) {
|
88 |
-
include_once ABSPATH . '/wp-admin/includes/screen.php';
|
89 |
-
}
|
90 |
-
if ( file_exists( ABSPATH . '/wp-admin/includes/template.php' ) ) {
|
91 |
-
include_once ABSPATH . '/wp-admin/includes/template.php';
|
92 |
-
}
|
93 |
-
if ( file_exists( ABSPATH . '/wp-admin/includes/misc.php' ) ) {
|
94 |
-
include_once ABSPATH . '/wp-admin/includes/misc.php';
|
95 |
-
}
|
96 |
-
include_once ABSPATH . '/wp-admin/includes/file.php';
|
97 |
-
include_once ABSPATH . '/wp-admin/includes/plugin.php';
|
98 |
-
include_once ABSPATH . '/wp-admin/includes/plugin-install.php';
|
99 |
-
}
|
100 |
-
|
101 |
-
/**
|
102 |
-
* Method upgrade_plugin_theme()
|
103 |
-
*
|
104 |
-
* Fire off plugins and themes updates and write feedback to the synchronization information.
|
105 |
-
*
|
106 |
-
* @uses \MainWP\Child\MainWP_Child_Updates::upgrade_plugin() Execute plugins updates.
|
107 |
-
* @uses \MainWP\Child\MainWP_Child_Updates::upgrade_theme() Execute themes updates.
|
108 |
-
* @uses \MainWP\Child\MainWP_Child_Stats::get_site_stats()
|
109 |
-
* @uses \MainWP\Child\MainWP_Helper::get_wp_filesystem()
|
110 |
-
* @uses \MainWP\Child\MainWP_Helper::instance()->error()
|
111 |
-
* @uses \MainWP\Child\MainWP_Helper::write()
|
112 |
-
*/
|
113 |
-
public function upgrade_plugin_theme() {
|
114 |
-
// Prevent disable/re-enable at upgrade.
|
115 |
-
if ( ! defined( 'DOING_CRON' ) ) {
|
116 |
-
|
117 |
-
/**
|
118 |
-
* Checks whether cron is in progress.
|
119 |
-
*
|
120 |
-
* @const ( bool ) Default: true
|
121 |
-
* @source https://code-reference.mainwp.com/classes/MainWP.Child.MainWP_Child_Updates.html
|
122 |
-
*/
|
123 |
-
define( 'DOING_CRON', true );
|
124 |
-
}
|
125 |
-
|
126 |
-
MainWP_Helper::get_wp_filesystem();
|
127 |
-
|
128 |
-
$this->include_updates();
|
129 |
-
|
130 |
-
$information = array();
|
131 |
-
$information['upgrades'] = array();
|
132 |
-
$mwp_premium_updates_todo = array();
|
133 |
-
$mwp_premium_updates_todo_slugs = array();
|
134 |
-
$premiumUpgrader = false;
|
135 |
-
|
136 |
-
if ( isset( $_POST['type'] ) && 'plugin' === $_POST['type'] ) {
|
137 |
-
$this->upgrade_plugin( $information, $mwp_premium_updates_todo, $mwp_premium_updates_todo_slugs, $premiumUpgrader );
|
138 |
-
} elseif ( isset( $_POST['type'] ) && 'theme' === $_POST['type'] ) {
|
139 |
-
$this->upgrade_theme( $information, $mwp_premium_updates_todo, $mwp_premium_updates_todo_slugs, $premiumUpgrader );
|
140 |
-
} else {
|
141 |
-
MainWP_Helper::instance()->error( __( 'Invalid request!', 'mainwp-child' ) );
|
142 |
-
}
|
143 |
-
|
144 |
-
if ( count( $mwp_premium_updates_todo ) > 0 ) {
|
145 |
-
$this->update_premiums_todo( $information, $premiumUpgrader, $mwp_premium_updates_todo, $mwp_premium_updates_todo_slugs );
|
146 |
-
}
|
147 |
-
|
148 |
-
$information['sync'] = MainWP_Child_Stats::get_instance()->get_site_stats( array(), false );
|
149 |
-
MainWP_Helper::write( $information );
|
150 |
-
}
|
151 |
-
|
152 |
-
/**
|
153 |
-
* Method upgrade_plugin()
|
154 |
-
*
|
155 |
-
* Initiate the plugin update process.
|
156 |
-
*
|
157 |
-
* @param array $information An array containing the synchronization information.
|
158 |
-
* @param array $mwp_premium_updates_todo An array containing the list of premium plugins to update.
|
159 |
-
* @param array $mwp_premium_updates_todo_slugs An array containing the list of premium plugins slugs to update.
|
160 |
-
* @param bool $premiumUpgrader If true, use premium upgrader.
|
161 |
-
*
|
162 |
-
* @uses MainWP_Child_Updates::to_upgrade_plugins() Complete the plugins update process.
|
163 |
-
* @uses MainWP_Child_Updates::to_support_some_premiums_updates() Custom support for some premium plugins.
|
164 |
-
* @uses \MainWP\Child\MainWP_Helper::instance()->error()
|
165 |
-
* @uses get_plugin_updates() The WordPress Core get plugin updates function.
|
166 |
-
* @see https://developer.wordpress.org/reference/functions/get_plugin_updates/
|
167 |
-
*
|
168 |
-
* @used-by MainWP_Child_Updates::upgrade_plugin_theme() Fire off plugins and themes updates and write feedback to the synchronization information.
|
169 |
-
*/
|
170 |
-
private function upgrade_plugin( &$information, &$mwp_premium_updates_todo, &$mwp_premium_updates_todo_slugs, &$premiumUpgrader ) {
|
171 |
-
|
172 |
-
include_once ABSPATH . '/wp-admin/includes/update.php';
|
173 |
-
if ( null !== $this->filterFunction ) {
|
174 |
-
add_filter( 'pre_site_transient_update_plugins', $this->filterFunction, 99 );
|
175 |
-
}
|
176 |
-
|
177 |
-
$plugins = isset( $_POST['list'] ) ? explode( ',', urldecode( wp_unslash( $_POST['list'] ) ) ) : array();
|
178 |
-
|
179 |
-
$this->to_support_some_premiums_updates( $plugins );
|
180 |
-
|
181 |
-
/**
|
182 |
-
* WordPress current filter.
|
183 |
-
*
|
184 |
-
* @global array $wp_current_filter WordPress current filter.
|
185 |
-
*/
|
186 |
-
global $wp_current_filter;
|
187 |
-
|
188 |
-
$wp_current_filter[] = 'load-plugins.php'; // phpcs:ignore -- Required for custom plugin installations, pull request solutions appreciated.
|
189 |
-
wp_update_plugins();
|
190 |
-
|
191 |
-
// prevent premium plugins re-create update info.
|
192 |
-
remove_all_filters( 'pre_set_site_transient_update_plugins' );
|
193 |
-
|
194 |
-
// support cached premium plugins update info, hooking in the bulk_upgrade().
|
195 |
-
add_filter( 'pre_site_transient_update_plugins', array( $this, 'set_cached_update_plugins' ) );
|
196 |
-
|
197 |
-
$information['plugin_updates'] = get_plugin_updates();
|
198 |
-
|
199 |
-
$plugins = isset( $_POST['list'] ) ? explode( ',', urldecode( wp_unslash( $_POST['list'] ) ) ) : array();
|
200 |
-
$premiumPlugins = array();
|
201 |
-
$premiumUpdates = get_option( 'mainwp_premium_updates' );
|
202 |
-
if ( is_array( $premiumUpdates ) ) {
|
203 |
-
$newPlugins = array();
|
204 |
-
foreach ( $plugins as $plugin ) {
|
205 |
-
if ( in_array( $plugin, $premiumUpdates ) ) {
|
206 |
-
$premiumPlugins[] = $plugin;
|
207 |
-
} else {
|
208 |
-
$newPlugins[] = $plugin;
|
209 |
-
}
|
210 |
-
}
|
211 |
-
$plugins = $newPlugins;
|
212 |
-
}
|
213 |
-
|
214 |
-
try {
|
215 |
-
$plugins = $this->check_update_requires( $plugins );
|
216 |
-
} catch ( \Exception $e ) {
|
217 |
-
$message = $e->getMessage();
|
218 |
-
MainWP_Helper::instance()->error( $message );
|
219 |
-
}
|
220 |
-
|
221 |
-
if ( count( $plugins ) > 0 ) {
|
222 |
-
$this->to_update_plugins( $information, $plugins );
|
223 |
-
}
|
224 |
-
|
225 |
-
// support cached premium plugins update info, hooking in the bulk_upgrade().
|
226 |
-
remove_filter( 'pre_site_transient_update_plugins', array( $this, 'set_cached_update_plugins' ), 10 );
|
227 |
-
delete_site_transient( 'mainwp_update_plugins_cached' ); // fix cached update info.
|
228 |
-
|
229 |
-
if ( count( $premiumPlugins ) > 0 ) {
|
230 |
-
$mwp_premium_updates = apply_filters( 'mwp_premium_perform_update', array() );
|
231 |
-
if ( is_array( $mwp_premium_updates ) && is_array( $premiumPlugins ) ) {
|
232 |
-
foreach ( $premiumPlugins as $premiumPlugin ) {
|
233 |
-
foreach ( $mwp_premium_updates as $key => $update ) {
|
234 |
-
$slug = ( isset( $update['slug'] ) ? $update['slug'] : $update['Name'] );
|
235 |
-
if ( 0 === strcmp( $slug, $premiumPlugin ) ) {
|
236 |
-
$mwp_premium_updates_todo[ $key ] = $update;
|
237 |
-
$mwp_premium_updates_todo_slugs[] = $premiumPlugin;
|
238 |
-
}
|
239 |
-
}
|
240 |
-
}
|
241 |
-
}
|
242 |
-
unset( $mwp_premium_updates );
|
243 |
-
// fix updates for Yithemes premium plugins that hook into upgrader_pre_download.
|
244 |
-
$url = 'update.php?action=update-selected&plugins=' . rawurlencode( implode( ',', $plugins ) );
|
245 |
-
$nonce = 'bulk-update-plugins';
|
246 |
-
$premiumUpgrader = new \Plugin_Upgrader( new \Bulk_Plugin_Upgrader_Skin( compact( 'nonce', 'url' ) ) );
|
247 |
-
}
|
248 |
-
|
249 |
-
if ( count( $plugins ) <= 0 && count( $premiumPlugins ) <= 0 ) {
|
250 |
-
MainWP_Helper::instance()->error( __( 'Invalid request!', 'mainwp-child' ) );
|
251 |
-
}
|
252 |
-
|
253 |
-
if ( null !== $this->filterFunction ) {
|
254 |
-
remove_filter( 'pre_site_transient_update_plugins', $this->filterFunction, 99 );
|
255 |
-
}
|
256 |
-
}
|
257 |
-
|
258 |
-
/**
|
259 |
-
* Method check_update_requires()
|
260 |
-
*
|
261 |
-
* Check update requires.
|
262 |
-
*
|
263 |
-
* @param array $plugins An array containing plugins to be updated.
|
264 |
-
*
|
265 |
-
* @return array An array of available plugins updates.
|
266 |
-
* @throws Exception|\Exception Error Exception.
|
267 |
-
*/
|
268 |
-
private function check_update_requires( $plugins ) {
|
269 |
-
if ( ! function_exists( 'is_php_version_compatible' ) || ! is_array( $plugins ) ) {
|
270 |
-
return $plugins;
|
271 |
-
}
|
272 |
-
|
273 |
-
$tmpPlugins = array();
|
274 |
-
foreach ( $plugins as $plugin ) {
|
275 |
-
|
276 |
-
$readme_file = WP_PLUGIN_DIR . '/' . dirname( $plugin ) . '/readme.txt';
|
277 |
-
$plugin_data = array(
|
278 |
-
'requires' => '',
|
279 |
-
'requires_php' => '',
|
280 |
-
);
|
281 |
-
|
282 |
-
if ( file_exists( $readme_file ) ) {
|
283 |
-
$plugin_data = get_file_data(
|
284 |
-
$readme_file,
|
285 |
-
array(
|
286 |
-
'requires' => 'Requires at least',
|
287 |
-
'requires_php' => 'Requires PHP',
|
288 |
-
),
|
289 |
-
'plugin'
|
290 |
-
);
|
291 |
-
}
|
292 |
-
|
293 |
-
$plugin_data = array_merge( $plugin_data, get_plugin_data( WP_PLUGIN_DIR . '/' . $plugin ) );
|
294 |
-
|
295 |
-
// Check for headers in the plugin's PHP file, give precedence to the plugin headers.
|
296 |
-
$plugin_data['requires'] = ! empty( $plugin_data['RequiresWP'] ) ? $plugin_data['RequiresWP'] : $plugin_data['requires'];
|
297 |
-
$plugin_data['requires_php'] = ! empty( $plugin_data['RequiresPHP'] ) ? $plugin_data['RequiresPHP'] : $plugin_data['requires_php'];
|
298 |
-
|
299 |
-
$plugin_data['wp_compatible'] = is_wp_version_compatible( $plugin_data['requires'] );
|
300 |
-
$plugin_data['php_compatible'] = is_php_version_compatible( $plugin_data['requires_php'] );
|
301 |
-
|
302 |
-
if ( ! $plugin_data['wp_compatible'] || ! $plugin_data['php_compatible'] ) {
|
303 |
-
// Current WordPress or PHP versions do not meet minimum requirements for update.
|
304 |
-
if ( 1 == count( $plugins ) ) {
|
305 |
-
throw new \Exception( 'Current WordPress or PHP versions do not meet minimum requirements for update.' );
|
306 |
-
}
|
307 |
-
continue;
|
308 |
-
}
|
309 |
-
|
310 |
-
$tmpPlugins[] = $plugin;
|
311 |
-
}
|
312 |
-
return $tmpPlugins;
|
313 |
-
}
|
314 |
-
|
315 |
-
/**
|
316 |
-
* Method to_update_plugins()
|
317 |
-
*
|
318 |
-
* Complete the plugins update process.
|
319 |
-
*
|
320 |
-
* @param array $information An array containing the synchronization information.
|
321 |
-
* @param array $plugins An array containing plugins to be updated.
|
322 |
-
*
|
323 |
-
* @uses \MainWP\Child\MainWP_Helper::instance()->error()
|
324 |
-
*
|
325 |
-
* @used-by MainWP_Child_Updates::upgrade_plugin() Initiate the plugin update process.
|
326 |
-
*/
|
327 |
-
private function to_update_plugins( &$information, $plugins ) {
|
328 |
-
$failed = true;
|
329 |
-
// fix updates for Yithemes premium plugins that hook into upgrader_pre_download.
|
330 |
-
$url = 'update.php?action=update-selected&plugins=' . rawurlencode( implode( ',', $plugins ) );
|
331 |
-
$nonce = 'bulk-update-plugins';
|
332 |
-
|
333 |
-
do_action( 'mainwp_child_before_update', 'plugin', $plugins );
|
334 |
-
|
335 |
-
$upgrader = new \Plugin_Upgrader( new \Bulk_Plugin_Upgrader_Skin( compact( 'nonce', 'url' ) ) );
|
336 |
-
$result = $upgrader->bulk_upgrade( $plugins );
|
337 |
-
|
338 |
-
do_action( 'mainwp_child_after_update', 'plugin', $result, $plugins );
|
339 |
-
|
340 |
-
if ( ! empty( $result ) ) {
|
341 |
-
foreach ( $result as $plugin => $info ) {
|
342 |
-
if ( empty( $info ) ) {
|
343 |
-
|
344 |
-
$information['upgrades'][ $plugin ] = false;
|
345 |
-
$api = apply_filters( 'plugins_api', false, 'plugin_information', array( 'slug' => $plugin ) );
|
346 |
-
|
347 |
-
if ( ! is_wp_error( $api ) && ! empty( $api ) ) {
|
348 |
-
if ( isset( $api->download_link ) ) {
|
349 |
-
$res = $upgrader->install( $api->download_link );
|
350 |
-
if ( ! is_wp_error( $res ) && ! ( is_null( $res ) ) ) {
|
351 |
-
$information['upgrades'][ $plugin ] = true;
|
352 |
-
}
|
353 |
-
}
|
354 |
-
}
|
355 |
-
} else {
|
356 |
-
$information['upgrades'][ $plugin ] = true;
|
357 |
-
}
|
358 |
-
}
|
359 |
-
$failed = false;
|
360 |
-
}
|
361 |
-
|
362 |
-
if ( $failed ) {
|
363 |
-
MainWP_Helper::instance()->error( __( 'Invalid request!', 'mainwp-child' ) );
|
364 |
-
}
|
365 |
-
}
|
366 |
-
|
367 |
-
/**
|
368 |
-
* Method upgrade_theme()
|
369 |
-
*
|
370 |
-
* Execute themes updates.
|
371 |
-
*
|
372 |
-
* @param array $information An array containing the synchronization information.
|
373 |
-
* @param array $mwp_premium_updates_todo An array containing the list of premium themes to update.
|
374 |
-
* @param array $mwp_premium_updates_todo_slugs An array containing the list of premium themes slugs to update.
|
375 |
-
* @param bool $premiumUpgrader If true, use premium upgrader.
|
376 |
-
*
|
377 |
-
* @uses \MainWP\Child\MainWP_Child_Updates::to_upgrade_themes() Complete the themes update process.
|
378 |
-
* @uses \MainWP\Child\MainWP_Child_Updates::upgrade_get_theme_updates() Get theme updates information.
|
379 |
-
* @uses \MainWP\Child\MainWP_Helper::instance()->error()
|
380 |
-
*
|
381 |
-
* @used-by \MainWP\Child\MainWP_Child_Updates::upgrade_plugin_theme() Fire off plugins and themes updates and write feedback to the synchronization information.
|
382 |
-
*/
|
383 |
-
private function upgrade_theme( &$information, &$mwp_premium_updates_todo, &$mwp_premium_updates_todo_slugs, &$premiumUpgrader ) {
|
384 |
-
|
385 |
-
$last_update = get_site_transient( 'update_themes' );
|
386 |
-
|
387 |
-
include_once ABSPATH . '/wp-admin/includes/update.php';
|
388 |
-
if ( null !== $this->filterFunction ) {
|
389 |
-
add_filter( 'pre_site_transient_update_themes', $this->filterFunction, 99 );
|
390 |
-
}
|
391 |
-
|
392 |
-
wp_update_themes();
|
393 |
-
include_once ABSPATH . '/wp-admin/includes/theme.php';
|
394 |
-
|
395 |
-
// to support cached premium themes update info, hooking in the bulk_upgrade().
|
396 |
-
add_filter( 'pre_site_transient_update_themes', array( $this, 'set_cached_update_themes' ) );
|
397 |
-
|
398 |
-
$information['theme_updates'] = $this->upgrade_get_theme_updates();
|
399 |
-
$themes = isset( $_POST['list'] ) ? explode( ',', wp_unslash( $_POST['list'] ) ) : array();
|
400 |
-
$premiumThemes = array();
|
401 |
-
$premiumUpdates = get_option( 'mainwp_premium_updates' );
|
402 |
-
if ( is_array( $premiumUpdates ) ) {
|
403 |
-
$newThemes = array();
|
404 |
-
foreach ( $themes as $theme ) {
|
405 |
-
if ( in_array( $theme, $premiumUpdates ) ) {
|
406 |
-
$premiumThemes[] = $theme;
|
407 |
-
} else {
|
408 |
-
$newThemes[] = $theme;
|
409 |
-
}
|
410 |
-
}
|
411 |
-
$themes = $newThemes;
|
412 |
-
}
|
413 |
-
|
414 |
-
if ( count( $themes ) > 0 ) {
|
415 |
-
$this->to_upgrade_themes( $information, $themes, $last_update );
|
416 |
-
}
|
417 |
-
|
418 |
-
remove_filter( 'pre_site_transient_update_themes', array( $this, 'set_cached_update_themes' ), 10 );
|
419 |
-
delete_site_transient( 'mainwp_update_themes_cached' ); // fix cached update info.
|
420 |
-
|
421 |
-
if ( count( $premiumThemes ) > 0 ) {
|
422 |
-
$mwp_premium_updates = apply_filters( 'mwp_premium_perform_update', array() );
|
423 |
-
$mwp_premium_updates_todo = array();
|
424 |
-
$mwp_premium_updates_todo_slugs = array();
|
425 |
-
if ( is_array( $premiumThemes ) && is_array( $mwp_premium_updates ) ) {
|
426 |
-
foreach ( $premiumThemes as $premiumTheme ) {
|
427 |
-
foreach ( $mwp_premium_updates as $key => $update ) {
|
428 |
-
$slug = ( isset( $update['slug'] ) ? $update['slug'] : $update['Name'] );
|
429 |
-
if ( 0 === strcmp( $slug, $premiumTheme ) ) {
|
430 |
-
$mwp_premium_updates_todo[ $key ] = $update;
|
431 |
-
$mwp_premium_updates_todo_slugs[] = $slug;
|
432 |
-
}
|
433 |
-
}
|
434 |
-
}
|
435 |
-
}
|
436 |
-
unset( $mwp_premium_updates );
|
437 |
-
$premiumUpgrader = new \Theme_Upgrader( new \Bulk_Theme_Upgrader_Skin( compact( 'nonce', 'url' ) ) );
|
438 |
-
}
|
439 |
-
if ( count( $themes ) <= 0 && count( $premiumThemes ) <= 0 ) {
|
440 |
-
MainWP_Helper::instance()->error( __( 'Invalid request!', 'mainwp-child' ) );
|
441 |
-
}
|
442 |
-
|
443 |
-
if ( null !== $this->filterFunction ) {
|
444 |
-
remove_filter( 'pre_site_transient_update_themes', $this->filterFunction, 99 );
|
445 |
-
}
|
446 |
-
}
|
447 |
-
|
448 |
-
/**
|
449 |
-
* Method to_upgrade_themes()
|
450 |
-
*
|
451 |
-
* Complete the themes update process.
|
452 |
-
*
|
453 |
-
* @param array $information An array containing the synchronization information.
|
454 |
-
* @param array $themes An array containing themes to be updated.
|
455 |
-
* @param string $last_update Contains the last update timestamp.
|
456 |
-
*
|
457 |
-
* @uses get_site_transient() Retrieves the value of a site transient.
|
458 |
-
* @see https://developer.wordpress.org/reference/functions/get_site_transient/
|
459 |
-
*
|
460 |
-
* @uses set_site_transient() Sets/updates the value of a site transient.
|
461 |
-
* @see https://developer.wordpress.org/reference/functions/set_site_transient/
|
462 |
-
*
|
463 |
-
* @used-by \MainWP\Child\MainWP_Child_Updates::upgrade_theme() Initiate the theme update process.
|
464 |
-
*
|
465 |
-
* @uses \MainWP\Child\MainWP_Helper::instance()->error()
|
466 |
-
*/
|
467 |
-
private function to_upgrade_themes( &$information, $themes, $last_update ) {
|
468 |
-
$addFilterToFixUpdate_optimizePressTheme = false;
|
469 |
-
if ( in_array( 'optimizePressTheme', $themes ) ) {
|
470 |
-
$addFilterToFixUpdate_optimizePressTheme = true;
|
471 |
-
add_filter( 'site_transient_update_themes', array( $this, 'hook_fix_optimize_press_theme_update' ), 99 );
|
472 |
-
}
|
473 |
-
|
474 |
-
if ( null !== $this->filterFunction ) {
|
475 |
-
remove_filter( 'pre_site_transient_update_plugins', $this->filterFunction, 99 );
|
476 |
-
}
|
477 |
-
|
478 |
-
$last_update2 = get_site_transient( 'update_themes' );
|
479 |
-
set_site_transient( 'update_themes', $last_update );
|
480 |
-
|
481 |
-
do_action( 'mainwp_child_before_update', 'theme', $themes );
|
482 |
-
|
483 |
-
$failed = true;
|
484 |
-
$upgrader = new \Theme_Upgrader( new \Bulk_Theme_Upgrader_Skin( compact( 'nonce', 'url' ) ) );
|
485 |
-
$result = $upgrader->bulk_upgrade( $themes );
|
486 |
-
|
487 |
-
do_action( 'mainwp_child_after_update', 'theme', $result, $themes );
|
488 |
-
|
489 |
-
if ( ! empty( $result ) ) {
|
490 |
-
foreach ( $result as $theme => $info ) {
|
491 |
-
if ( empty( $info ) ) {
|
492 |
-
$information['upgrades'][ $theme ] = false;
|
493 |
-
} else {
|
494 |
-
$information['upgrades'][ $theme ] = true;
|
495 |
-
}
|
496 |
-
}
|
497 |
-
$failed = false;
|
498 |
-
}
|
499 |
-
|
500 |
-
if ( $failed ) {
|
501 |
-
MainWP_Helper::instance()->error( __( 'Invalid request!', 'mainwp-child' ) );
|
502 |
-
}
|
503 |
-
|
504 |
-
if ( null !== $this->filterFunction ) {
|
505 |
-
add_filter( 'pre_site_transient_update_themes', $this->filterFunction, 99 );
|
506 |
-
}
|
507 |
-
|
508 |
-
set_site_transient( 'update_themes', $last_update2 );
|
509 |
-
|
510 |
-
if ( $addFilterToFixUpdate_optimizePressTheme ) {
|
511 |
-
remove_filter(
|
512 |
-
'site_transient_update_themes',
|
513 |
-
array(
|
514 |
-
$this,
|
515 |
-
'hook_fix_optimize_press_theme_update',
|
516 |
-
),
|
517 |
-
99
|
518 |
-
);
|
519 |
-
}
|
520 |
-
}
|
521 |
-
|
522 |
-
/**
|
523 |
-
* Method update_premiums_todo()
|
524 |
-
*
|
525 |
-
* Update premium plugins.
|
526 |
-
*
|
527 |
-
* @param array $information An array containing the synchronization information.
|
528 |
-
* @param bool $premiumUpgrader If true, use premium upgrader.
|
529 |
-
* @param array $mwp_premium_updates_todo An array containing the list of premium themes to update.
|
530 |
-
* @param array $mwp_premium_updates_todo_slugs An array containing the list of premium themes slugs to update.
|
531 |
-
*/
|
532 |
-
private function update_premiums_todo( &$information, $premiumUpgrader, $mwp_premium_updates_todo, $mwp_premium_updates_todo_slugs ) {
|
533 |
-
// Upgrade via WP.
|
534 |
-
// @see wp-admin/update.php.
|
535 |
-
$result = $premiumUpgrader->bulk_upgrade( $mwp_premium_updates_todo_slugs );
|
536 |
-
if ( ! empty( $result ) ) {
|
537 |
-
foreach ( $result as $plugin => $info ) {
|
538 |
-
if ( ! empty( $info ) ) {
|
539 |
-
$information['upgrades'][ $plugin ] = true;
|
540 |
-
|
541 |
-
foreach ( $mwp_premium_updates_todo as $key => $update ) {
|
542 |
-
$slug = ( isset( $update['slug'] ) ? $update['slug'] : $update['Name'] );
|
543 |
-
}
|
544 |
-
}
|
545 |
-
}
|
546 |
-
}
|
547 |
-
|
548 |
-
// Upgrade via callback.
|
549 |
-
foreach ( $mwp_premium_updates_todo as $update ) {
|
550 |
-
$slug = ( isset( $update['slug'] ) ? $update['slug'] : $update['Name'] );
|
551 |
-
|
552 |
-
if ( isset( $update['url'] ) ) {
|
553 |
-
$installer = new \WP_Upgrader();
|
554 |
-
$result = $installer->run(
|
555 |
-
array(
|
556 |
-
'package' => $update['url'],
|
557 |
-
'destination' => ( 'plugin' === $update['type'] ? WP_PLUGIN_DIR : WP_CONTENT_DIR . '/themes' ),
|
558 |
-
'clear_destination' => true,
|
559 |
-
'clear_working' => true,
|
560 |
-
'hook_extra' => array(),
|
561 |
-
)
|
562 |
-
);
|
563 |
-
$information['upgrades'][ $slug ] = ( ! is_wp_error( $result ) && ! empty( $result ) );
|
564 |
-
} elseif ( isset( $update['callback'] ) ) {
|
565 |
-
if ( is_array( $update['callback'] ) && isset( $update['callback'][0] ) && isset( $update['callback'][1] ) ) {
|
566 |
-
$update_result = call_user_func(
|
567 |
-
array(
|
568 |
-
$update['callback'][0],
|
569 |
-
$update['callback'][1],
|
570 |
-
)
|
571 |
-
);
|
572 |
-
$information['upgrades'][ $slug ] = $update_result && true;
|
573 |
-
} elseif ( is_string( $update['callback'] ) ) {
|
574 |
-
$update_result = call_user_func( $update['callback'] );
|
575 |
-
$information['upgrades'][ $slug ] = $update_result && true;
|
576 |
-
} else {
|
577 |
-
$information['upgrades'][ $slug ] = false;
|
578 |
-
}
|
579 |
-
} else {
|
580 |
-
$information['upgrades'][ $slug ] = false;
|
581 |
-
}
|
582 |
-
}
|
583 |
-
}
|
584 |
-
|
585 |
-
/**
|
586 |
-
* Method to_support_some_premiums_updates()
|
587 |
-
*
|
588 |
-
* Custom support for some premium plugins.
|
589 |
-
*
|
590 |
-
* @param array $plugins An array containing installed plugins information.
|
591 |
-
*
|
592 |
-
* @used-by MainWP_Child_Updates::upgrade_plugin() Initiate the plugin update process.
|
593 |
-
*/
|
594 |
-
private function to_support_some_premiums_updates( $plugins ) {
|
595 |
-
// Custom fix for the iThemes products.
|
596 |
-
if ( in_array( 'backupbuddy/backupbuddy.php', $plugins ) ) {
|
597 |
-
if ( isset( $GLOBALS['ithemes_updater_path'] ) ) {
|
598 |
-
if ( ! class_exists( '\Ithemes_Updater_Settings' ) ) {
|
599 |
-
require $GLOBALS['ithemes_updater_path'] . '/settings.php';
|
600 |
-
}
|
601 |
-
if ( class_exists( '\Ithemes_Updater_Settings' ) ) {
|
602 |
-
$ithemes_updater = new \Ithemes_Updater_Settings();
|
603 |
-
$ithemes_updater->update();
|
604 |
-
}
|
605 |
-
}
|
606 |
-
}
|
607 |
-
// Custom fix for the smart-manager-for-wp-e-commerce update.
|
608 |
-
if ( in_array( 'smart-manager-for-wp-e-commerce/smart-manager.php', $plugins ) ) {
|
609 |
-
if ( file_exists( plugin_dir_path( __FILE__ ) . '../../smart-manager-for-wp-e-commerce/pro/upgrade.php' ) && file_exists( plugin_dir_path( __FILE__ ) . '../../smart-manager-for-wp-e-commerce/smart-manager.php' ) ) {
|
610 |
-
include_once plugin_dir_path( __FILE__ ) . '../../smart-manager-for-wp-e-commerce/smart-manager.php';
|
611 |
-
include_once plugin_dir_path( __FILE__ ) . '../../smart-manager-for-wp-e-commerce/pro/upgrade.php';
|
612 |
-
}
|
613 |
-
}
|
614 |
-
}
|
615 |
-
|
616 |
-
/**
|
617 |
-
* Method upgrade_get_theme_updates()
|
618 |
-
*
|
619 |
-
* Get theme updates information.
|
620 |
-
*
|
621 |
-
* @return array An array of available theme updates information.
|
622 |
-
*
|
623 |
-
* @uses get_theme_updates() The WordPress Core get theme updates function.
|
624 |
-
* @see https://developer.wordpress.org/reference/functions/get_theme_updates/
|
625 |
-
*
|
626 |
-
* @used-by \MainWP\Child\MainWP_Child_Updates::upgrade_theme() Execute themes updates.
|
627 |
-
* @uses \MainWP\Child\MainWP_Helper::search()
|
628 |
-
*/
|
629 |
-
public function upgrade_get_theme_updates() {
|
630 |
-
$themeUpdates = get_theme_updates();
|
631 |
-
$newThemeUpdates = array();
|
632 |
-
$theme_name = wp_get_theme()->get( 'Name' );
|
633 |
-
if ( is_array( $themeUpdates ) ) {
|
634 |
-
foreach ( $themeUpdates as $slug => $themeUpdate ) {
|
635 |
-
$newThemeUpdate = array();
|
636 |
-
$newThemeUpdate['update'] = $themeUpdate->update;
|
637 |
-
$newThemeUpdate['Name'] = MainWP_Helper::search( $themeUpdate, 'Name' );
|
638 |
-
$newThemeUpdate['Version'] = MainWP_Helper::search( $themeUpdate, 'Version' );
|
639 |
-
$newThemeUpdate['active'] = ( $newThemeUpdate['Name'] === $theme_name ) ? 1 : 0;
|
640 |
-
$newThemeUpdates[ $slug ] = $newThemeUpdate;
|
641 |
-
}
|
642 |
-
}
|
643 |
-
|
644 |
-
return $newThemeUpdates;
|
645 |
-
}
|
646 |
-
|
647 |
-
/**
|
648 |
-
* Method hook_fix_optimize_press_theme_update()
|
649 |
-
*
|
650 |
-
* Cutom support for the Optimize Press theme.
|
651 |
-
*
|
652 |
-
* @param object $transient Object containig the update transient information.
|
653 |
-
*
|
654 |
-
* @used-by MainWP_Child_Update::to_upgrade_themes() Complete the themes update process.
|
655 |
-
*
|
656 |
-
* @return object $transient Object containig the update transient information.
|
657 |
-
*/
|
658 |
-
public function hook_fix_optimize_press_theme_update( $transient ) {
|
659 |
-
if ( ! defined( 'OP_FUNC' ) ) {
|
660 |
-
return $transient;
|
661 |
-
}
|
662 |
-
|
663 |
-
$theme_slug = 'optimizePressTheme';
|
664 |
-
|
665 |
-
if ( ! function_exists( 'op_sl_update' ) ) {
|
666 |
-
require_once OP_FUNC . 'options.php';
|
667 |
-
require_once OP_FUNC . 'sl_api.php';
|
668 |
-
}
|
669 |
-
$apiResponse = op_sl_update( 'theme' );
|
670 |
-
|
671 |
-
if ( is_wp_error( $apiResponse ) ) {
|
672 |
-
return $transient;
|
673 |
-
}
|
674 |
-
|
675 |
-
$obj = new \stdClass();
|
676 |
-
$obj->slug = $theme_slug;
|
677 |
-
$obj->new_version = $apiResponse->new_version;
|
678 |
-
$obj->url = $apiResponse->url;
|
679 |
-
$obj->package = $apiResponse->s3_package;
|
680 |
-
$obj->sections = array(
|
681 |
-
'description' => $apiResponse->section->description,
|
682 |
-
'changelog' => $apiResponse->section->changelog,
|
683 |
-
);
|
684 |
-
|
685 |
-
$transient->response[ $theme_slug ] = (array) $obj;
|
686 |
-
|
687 |
-
return $transient;
|
688 |
-
}
|
689 |
-
|
690 |
-
/**
|
691 |
-
* Method set_cached_update_plugins()
|
692 |
-
*
|
693 |
-
* Support cached premium plugins update info, hooking in the bulk_upgrade().
|
694 |
-
*
|
695 |
-
* @param bool $false true|false.
|
696 |
-
* @param object $_transient_data Contains the transient data.
|
697 |
-
*
|
698 |
-
* @uses get_site_transient() Retrieves the value of a site transient.
|
699 |
-
* @see https://developer.wordpress.org/reference/functions/get_site_transient/
|
700 |
-
*
|
701 |
-
* @return object $_transient_data Contains the updated transient data.
|
702 |
-
*/
|
703 |
-
public function set_cached_update_plugins( $false = false, $_transient_data = null ) {
|
704 |
-
|
705 |
-
if ( ! is_object( $_transient_data ) ) {
|
706 |
-
$_transient_data = new \stdClass();
|
707 |
-
}
|
708 |
-
|
709 |
-
$pre = false;
|
710 |
-
$cached_update_info = get_site_transient( 'mainwp_update_plugins_cached' );
|
711 |
-
if ( is_array( $cached_update_info ) && count( $cached_update_info ) > 0 ) {
|
712 |
-
foreach ( $cached_update_info as $slug => $info ) {
|
713 |
-
if ( ! isset( $_transient_data->response[ $slug ] ) && isset( $info->update ) ) {
|
714 |
-
$_transient_data->response[ $slug ] = $info->update;
|
715 |
-
$pre = true;
|
716 |
-
}
|
717 |
-
}
|
718 |
-
}
|
719 |
-
|
720 |
-
if ( false == $pre ) {
|
721 |
-
return $false;
|
722 |
-
}
|
723 |
-
|
724 |
-
return $_transient_data;
|
725 |
-
}
|
726 |
-
|
727 |
-
/**
|
728 |
-
* Method set_cached_update_themes()
|
729 |
-
*
|
730 |
-
* Support cached premium themes update info, hooking in the bulk_upgrade().
|
731 |
-
*
|
732 |
-
* @param bool $false true|false.
|
733 |
-
* @param object $_transient_data Contains the transient data.
|
734 |
-
*
|
735 |
-
* @uses get_site_transient() Retrieves the value of a site transient.
|
736 |
-
* @see https://developer.wordpress.org/reference/functions/get_site_transient/
|
737 |
-
*
|
738 |
-
* @return object $_transient_data Contains the updated transient data.
|
739 |
-
*/
|
740 |
-
public function set_cached_update_themes( $false = false, $_transient_data = null ) {
|
741 |
-
|
742 |
-
if ( ! is_object( $_transient_data ) ) {
|
743 |
-
$_transient_data = new \stdClass();
|
744 |
-
}
|
745 |
-
|
746 |
-
$pre = false;
|
747 |
-
$cached_update_info = get_site_transient( 'mainwp_update_themes_cached' );
|
748 |
-
if ( is_array( $cached_update_info ) && count( $cached_update_info ) > 0 ) {
|
749 |
-
foreach ( $cached_update_info as $slug => $info ) {
|
750 |
-
if ( ! isset( $_transient_data->response[ $slug ] ) && isset( $info->update ) ) {
|
751 |
-
$_transient_data->response[ $slug ] = $info->update;
|
752 |
-
$pre = true;
|
753 |
-
}
|
754 |
-
}
|
755 |
-
}
|
756 |
-
|
757 |
-
if ( false == $pre ) {
|
758 |
-
return $false;
|
759 |
-
}
|
760 |
-
|
761 |
-
return $_transient_data;
|
762 |
-
}
|
763 |
-
|
764 |
-
/**
|
765 |
-
* Method detect_premium_themesplugins_updates()
|
766 |
-
*
|
767 |
-
* Detect premium plugins and themes updates.
|
768 |
-
*
|
769 |
-
* @uses get_site_transient() Retrieves the value of a site transient.
|
770 |
-
* @see https://developer.wordpress.org/reference/functions/get_site_transient/
|
771 |
-
*
|
772 |
-
* @uses set_site_transient() Sets/updates the value of a site transient.
|
773 |
-
* @see https://developer.wordpress.org/reference/functions/set_site_transient/
|
774 |
-
*
|
775 |
-
* @uses \MainWP\Child\MainWP_Child_Callable::is_callable_function()
|
776 |
-
* @uses \MainWP\Child\MainWP_Child_Callable::call_function()
|
777 |
-
*/
|
778 |
-
public function detect_premium_themesplugins_updates() {
|
779 |
-
|
780 |
-
if ( isset( $_GET['_detect_plugins_updates'] ) && 'yes' == $_GET['_detect_plugins_updates'] ) {
|
781 |
-
// to fix some premium plugins update notification.
|
782 |
-
$current = get_site_transient( 'update_plugins' );
|
783 |
-
set_site_transient( 'update_plugins', $current );
|
784 |
-
|
785 |
-
add_filter( 'pre_site_transient_update_plugins', $this->filterFunction, 99 );
|
786 |
-
$plugins = get_plugin_updates();
|
787 |
-
remove_filter( 'pre_site_transient_update_plugins', $this->filterFunction, 99 );
|
788 |
-
|
789 |
-
set_site_transient( 'mainwp_update_plugins_cached', $plugins, DAY_IN_SECONDS );
|
790 |
-
}
|
791 |
-
|
792 |
-
if ( isset( $_GET['_detect_themes_updates'] ) && 'yes' == $_GET['_detect_themes_updates'] ) {
|
793 |
-
add_filter( 'pre_site_transient_update_themes', $this->filterFunction, 99 );
|
794 |
-
$themes = get_theme_updates();
|
795 |
-
remove_filter( 'pre_site_transient_update_themes', $this->filterFunction, 99 );
|
796 |
-
|
797 |
-
set_site_transient( 'mainwp_update_themes_cached', $themes, DAY_IN_SECONDS );
|
798 |
-
}
|
799 |
-
|
800 |
-
$type = isset( $_GET['_request_update_premiums_type'] ) ? sanitize_text_field( wp_unslash( $_GET['_request_update_premiums_type'] ) ) : '';
|
801 |
-
|
802 |
-
if ( 'plugin' == $type || 'theme' == $type ) {
|
803 |
-
$list = isset( $_GET['list'] ) ? wp_unslash( $_GET['list'] ) : '';
|
804 |
-
|
805 |
-
if ( ! empty( $list ) ) {
|
806 |
-
$_POST['type'] = $type;
|
807 |
-
$_POST['list'] = $list;
|
808 |
-
|
809 |
-
$function = 'upgradeplugintheme'; // to call function upgrade_plugin_theme().
|
810 |
-
if ( MainWP_Child_Callable::get_instance()->is_callable_function( $function ) ) {
|
811 |
-
MainWP_Child_Callable::get_instance()->call_function( $function );
|
812 |
-
}
|
813 |
-
}
|
814 |
-
}
|
815 |
-
}
|
816 |
-
|
817 |
-
/**
|
818 |
-
* Method upgrade_wp()
|
819 |
-
*
|
820 |
-
* Initiate the WordPress core files update.
|
821 |
-
*
|
822 |
-
* @uses \MainWP\Child\MainWP_Child_Updates::do_upgrade_wp() Run the WordPress Core update.
|
823 |
-
* @uses \MainWP\Child\MainWP_Helper::get_wp_filesystem()
|
824 |
-
* @uses \MainWP\Child\MainWP_Helper::write()
|
825 |
-
*/
|
826 |
-
public function upgrade_wp() {
|
827 |
-
|
828 |
-
/**
|
829 |
-
* The installed version of WordPress.
|
830 |
-
*
|
831 |
-
* @global string $wp_version The installed version of WordPress.
|
832 |
-
*/
|
833 |
-
global $wp_version;
|
834 |
-
|
835 |
-
MainWP_Helper::get_wp_filesystem();
|
836 |
-
|
837 |
-
$information = array();
|
838 |
-
|
839 |
-
include_once ABSPATH . '/wp-admin/includes/update.php';
|
840 |
-
include_once ABSPATH . '/wp-admin/includes/class-wp-upgrader.php';
|
841 |
-
|
842 |
-
if ( file_exists( ABSPATH . '/wp-admin/includes/screen.php' ) ) {
|
843 |
-
include_once ABSPATH . '/wp-admin/includes/screen.php';
|
844 |
-
}
|
845 |
-
if ( file_exists( ABSPATH . '/wp-admin/includes/template.php' ) ) {
|
846 |
-
include_once ABSPATH . '/wp-admin/includes/template.php';
|
847 |
-
}
|
848 |
-
include_once ABSPATH . '/wp-admin/includes/file.php';
|
849 |
-
include_once ABSPATH . '/wp-admin/includes/misc.php';
|
850 |
-
|
851 |
-
if ( null !== $this->filterFunction ) {
|
852 |
-
add_filter( 'pre_site_transient_update_core', $this->filterFunction, 99 );
|
853 |
-
}
|
854 |
-
if ( null !== $this->filterFunction ) {
|
855 |
-
add_filter( 'pre_transient_update_core', $this->filterFunction, 99 );
|
856 |
-
}
|
857 |
-
$this->do_upgrade_wp( $information );
|
858 |
-
|
859 |
-
if ( null !== $this->filterFunction ) {
|
860 |
-
remove_filter( 'pre_site_transient_update_core', $this->filterFunction, 99 );
|
861 |
-
}
|
862 |
-
if ( null !== $this->filterFunction ) {
|
863 |
-
remove_filter( 'pre_transient_update_core', $this->filterFunction, 99 );
|
864 |
-
}
|
865 |
-
|
866 |
-
MainWP_Helper::write( $information );
|
867 |
-
}
|
868 |
-
|
869 |
-
/**
|
870 |
-
* Method do_upgrade_wp()
|
871 |
-
*
|
872 |
-
* Run the WordPress Core update.
|
873 |
-
*
|
874 |
-
* @param array $information An array containing the synchronization information.
|
875 |
-
*
|
876 |
-
* @used-by MainWP_Child_Updates::upgrade_wp() Initiate the WordPress core files update.
|
877 |
-
*/
|
878 |
-
private function do_upgrade_wp( &$information ) {
|
879 |
-
// Check for new versions.
|
880 |
-
wp_version_check();
|
881 |
-
|
882 |
-
$core_updates = get_core_updates();
|
883 |
-
if ( is_array( $core_updates ) && count( $core_updates ) > 0 ) {
|
884 |
-
foreach ( $core_updates as $core_update ) {
|
885 |
-
if ( 'latest' === $core_update->response ) {
|
886 |
-
$information['upgrade'] = 'SUCCESS';
|
887 |
-
} elseif ( 'upgrade' === $core_update->response && get_locale() === $core_update->locale && version_compare( $wp_version, $core_update->current, '<=' ) ) {
|
888 |
-
// Upgrade!
|
889 |
-
$upgrade = false;
|
890 |
-
if ( class_exists( '\Core_Upgrader' ) ) {
|
891 |
-
$core = new \Core_Upgrader();
|
892 |
-
$upgrade = $core->upgrade( $core_update );
|
893 |
-
}
|
894 |
-
// If this does not work - add code from /wp-admin/includes/class-wp-upgrader.php in the newer versions.
|
895 |
-
// So users can upgrade older versions too.
|
896 |
-
// 3rd option: 'wp_update_core'.
|
897 |
-
|
898 |
-
if ( ! is_wp_error( $upgrade ) ) {
|
899 |
-
$information['upgrade'] = 'SUCCESS';
|
900 |
-
} else {
|
901 |
-
$information['upgrade'] = 'WPERROR';
|
902 |
-
}
|
903 |
-
break;
|
904 |
-
}
|
905 |
-
}
|
906 |
-
|
907 |
-
if ( ! isset( $information['upgrade'] ) ) {
|
908 |
-
foreach ( $core_updates as $core_update ) {
|
909 |
-
if ( 'upgrade' === $core_update->response && version_compare( $wp_version, $core_update->current, '<=' ) ) {
|
910 |
-
// Upgrade!
|
911 |
-
$upgrade = false;
|
912 |
-
if ( class_exists( '\Core_Upgrader' ) ) {
|
913 |
-
$core = new \Core_Upgrader();
|
914 |
-
$upgrade = $core->upgrade( $core_update );
|
915 |
-
}
|
916 |
-
// If this does not work - add code from /wp-admin/includes/class-wp-upgrader.php in the newer versions
|
917 |
-
// So users can upgrade older versions too.
|
918 |
-
// 3rd option: 'wp_update_core'.
|
919 |
-
if ( ! is_wp_error( $upgrade ) ) {
|
920 |
-
$information['upgrade'] = 'SUCCESS';
|
921 |
-
} else {
|
922 |
-
$information['upgrade'] = 'WPERROR';
|
923 |
-
}
|
924 |
-
break;
|
925 |
-
}
|
926 |
-
}
|
927 |
-
}
|
928 |
-
} else {
|
929 |
-
$information['upgrade'] = 'NORESPONSE';
|
930 |
-
}
|
931 |
-
}
|
932 |
-
|
933 |
-
/**
|
934 |
-
* Method upgrade_translation()
|
935 |
-
*
|
936 |
-
* Update translations and set feedback to the sync information.
|
937 |
-
*
|
938 |
-
* @uses \MainWP\Child\MainWP_Child_Stats::get_site_stats()
|
939 |
-
* @uses \MainWP\Child\MainWP_Helper::write()
|
940 |
-
*/
|
941 |
-
public function upgrade_translation() {
|
942 |
-
/**
|
943 |
-
* Checks whether cron is in progress.
|
944 |
-
*
|
945 |
-
* @const ( bool ) Default: true
|
946 |
-
* @source https://code-reference.mainwp.com/classes/MainWP.Child.MainWP_Child_Callable.html
|
947 |
-
*/
|
948 |
-
define( 'DOING_CRON', true );
|
949 |
-
|
950 |
-
MainWP_Helper::get_wp_filesystem();
|
951 |
-
include_once ABSPATH . '/wp-admin/includes/class-wp-upgrader.php';
|
952 |
-
if ( file_exists( ABSPATH . '/wp-admin/includes/screen.php' ) ) {
|
953 |
-
include_once ABSPATH . '/wp-admin/includes/screen.php';
|
954 |
-
}
|
955 |
-
if ( file_exists( ABSPATH . '/wp-admin/includes/template.php' ) ) {
|
956 |
-
include_once ABSPATH . '/wp-admin/includes/template.php';
|
957 |
-
}
|
958 |
-
if ( file_exists( ABSPATH . '/wp-admin/includes/misc.php' ) ) {
|
959 |
-
include_once ABSPATH . '/wp-admin/includes/misc.php';
|
960 |
-
}
|
961 |
-
include_once ABSPATH . '/wp-admin/includes/file.php';
|
962 |
-
|
963 |
-
include_once ABSPATH . 'wp-admin/includes/class-wp-upgrader.php';
|
964 |
-
|
965 |
-
wp_version_check();
|
966 |
-
wp_update_themes();
|
967 |
-
wp_update_plugins();
|
968 |
-
|
969 |
-
$upgrader = new \Language_Pack_Upgrader( new \Language_Pack_Upgrader_Skin( compact( 'url', 'nonce', 'title', 'context' ) ) );
|
970 |
-
$translations = isset( $_POST['list'] ) ? explode( ',', urldecode( $_POST['list'] ) ) : array();
|
971 |
-
$all_language_updates = wp_get_translation_updates();
|
972 |
-
|
973 |
-
$language_updates = array();
|
974 |
-
foreach ( $all_language_updates as $current_language_update ) {
|
975 |
-
if ( in_array( $current_language_update->slug, $translations ) ) {
|
976 |
-
$language_updates[] = $current_language_update;
|
977 |
-
}
|
978 |
-
}
|
979 |
-
|
980 |
-
$result = count( $language_updates ) == 0 ? false : $upgrader->bulk_upgrade( $language_updates );
|
981 |
-
if ( ! empty( $result ) ) {
|
982 |
-
$count_result = count( $result );
|
983 |
-
for ( $i = 0; $i < $count_result; $i++ ) {
|
984 |
-
if ( empty( $result[ $i ] ) || is_wp_error( $result[ $i ] ) ) {
|
985 |
-
$information['upgrades'][ $language_updates[ $i ]->slug ] = false;
|
986 |
-
} else {
|
987 |
-
$information['upgrades'][ $language_updates[ $i ]->slug ] = true;
|
988 |
-
}
|
989 |
-
}
|
990 |
-
} else {
|
991 |
-
$information['upgrades'] = array(); // Fix error message when translations updated.
|
992 |
-
}
|
993 |
-
$information['sync'] = MainWP_Child_Stats::get_instance()->get_site_stats( array(), false );
|
994 |
-
MainWP_Helper::write( $information );
|
995 |
-
}
|
996 |
-
|
997 |
-
}
|
1 |
+
<?php
|
2 |
+
/**
|
3 |
+
* MainWP Updates
|
4 |
+
*
|
5 |
+
* Manage updates on the site.
|
6 |
+
*
|
7 |
+
* @package MainWP\Child
|
8 |
+
*/
|
9 |
+
|
10 |
+
namespace MainWP\Child;
|
11 |
+
|
12 |
+
//phpcs:disable Generic.Metrics.CyclomaticComplexity -- Current complexity is the only way to achieve desired results, pull request solutions appreciated.
|
13 |
+
|
14 |
+
/**
|
15 |
+
* Class MainWP_Child_Updates
|
16 |
+
*
|
17 |
+
* Manage updates on the site.
|
18 |
+
*/
|
19 |
+
class MainWP_Child_Updates {
|
20 |
+
|
21 |
+
/**
|
22 |
+
* Public static variable to hold the single instance of the class.
|
23 |
+
*
|
24 |
+
* @var mixed Default null
|
25 |
+
*/
|
26 |
+
protected static $instance = null;
|
27 |
+
|
28 |
+
/**
|
29 |
+
* Private variable to filter update transients without last_checked and checked fields.
|
30 |
+
*
|
31 |
+
* @var object Filter update transients.
|
32 |
+
*/
|
33 |
+
private $filterFunction = null;
|
34 |
+
|
35 |
+
|
36 |
+
/**
|
37 |
+
* Method get_class_name()
|
38 |
+
*
|
39 |
+
* Get class name.
|
40 |
+
*
|
41 |
+
* @return string __CLASS__ Class name.
|
42 |
+
*/
|
43 |
+
public static function get_class_name() {
|
44 |
+
return __CLASS__;
|
45 |
+
}
|
46 |
+
|
47 |
+
/**
|
48 |
+
* MainWP_Child_Updates constructor.
|
49 |
+
*
|
50 |
+
* Run any time class is called.
|
51 |
+
*/
|
52 |
+
public function __construct() {
|
53 |
+
$this->filterFunction = function( $a ) {
|
54 |
+
if ( null == $a ) {
|
55 |
+
return false;
|
56 |
+
}
|
57 |
+
if ( is_object( $a ) && property_exists( $a, 'last_checked' ) && ! property_exists( $a, 'checked' ) ) {
|
58 |
+
return false;
|
59 |
+
}
|
60 |
+
return $a;
|
61 |
+
};
|
62 |
+
}
|
63 |
+
|
64 |
+
/**
|
65 |
+
* Method get_instance()
|
66 |
+
*
|
67 |
+
* Create a public static instance.
|
68 |
+
*
|
69 |
+
* @return mixed Class instance.
|
70 |
+
*/
|
71 |
+
public static function get_instance() {
|
72 |
+
if ( null === self::$instance ) {
|
73 |
+
self::$instance = new self();
|
74 |
+
}
|
75 |
+
|
76 |
+
return self::$instance;
|
77 |
+
}
|
78 |
+
|
79 |
+
/**
|
80 |
+
* Method include_updates()
|
81 |
+
*
|
82 |
+
* Include WP Core files required for performing updates.
|
83 |
+
*/
|
84 |
+
private function include_updates() {
|
85 |
+
include_once ABSPATH . '/wp-admin/includes/class-wp-upgrader.php';
|
86 |
+
|
87 |
+
if ( file_exists( ABSPATH . '/wp-admin/includes/screen.php' ) ) {
|
88 |
+
include_once ABSPATH . '/wp-admin/includes/screen.php';
|
89 |
+
}
|
90 |
+
if ( file_exists( ABSPATH . '/wp-admin/includes/template.php' ) ) {
|
91 |
+
include_once ABSPATH . '/wp-admin/includes/template.php';
|
92 |
+
}
|
93 |
+
if ( file_exists( ABSPATH . '/wp-admin/includes/misc.php' ) ) {
|
94 |
+
include_once ABSPATH . '/wp-admin/includes/misc.php';
|
95 |
+
}
|
96 |
+
include_once ABSPATH . '/wp-admin/includes/file.php';
|
97 |
+
include_once ABSPATH . '/wp-admin/includes/plugin.php';
|
98 |
+
include_once ABSPATH . '/wp-admin/includes/plugin-install.php';
|
99 |
+
}
|
100 |
+
|
101 |
+
/**
|
102 |
+
* Method upgrade_plugin_theme()
|
103 |
+
*
|
104 |
+
* Fire off plugins and themes updates and write feedback to the synchronization information.
|
105 |
+
*
|
106 |
+
* @uses \MainWP\Child\MainWP_Child_Updates::upgrade_plugin() Execute plugins updates.
|
107 |
+
* @uses \MainWP\Child\MainWP_Child_Updates::upgrade_theme() Execute themes updates.
|
108 |
+
* @uses \MainWP\Child\MainWP_Child_Stats::get_site_stats()
|
109 |
+
* @uses \MainWP\Child\MainWP_Helper::get_wp_filesystem()
|
110 |
+
* @uses \MainWP\Child\MainWP_Helper::instance()->error()
|
111 |
+
* @uses \MainWP\Child\MainWP_Helper::write()
|
112 |
+
*/
|
113 |
+
public function upgrade_plugin_theme() {
|
114 |
+
// Prevent disable/re-enable at upgrade.
|
115 |
+
if ( ! defined( 'DOING_CRON' ) ) {
|
116 |
+
|
117 |
+
/**
|
118 |
+
* Checks whether cron is in progress.
|
119 |
+
*
|
120 |
+
* @const ( bool ) Default: true
|
121 |
+
* @source https://code-reference.mainwp.com/classes/MainWP.Child.MainWP_Child_Updates.html
|
122 |
+
*/
|
123 |
+
define( 'DOING_CRON', true );
|
124 |
+
}
|
125 |
+
|
126 |
+
MainWP_Helper::get_wp_filesystem();
|
127 |
+
|
128 |
+
$this->include_updates();
|
129 |
+
|
130 |
+
$information = array();
|
131 |
+
$information['upgrades'] = array();
|
132 |
+
$mwp_premium_updates_todo = array();
|
133 |
+
$mwp_premium_updates_todo_slugs = array();
|
134 |
+
$premiumUpgrader = false;
|
135 |
+
|
136 |
+
if ( isset( $_POST['type'] ) && 'plugin' === $_POST['type'] ) {
|
137 |
+
$this->upgrade_plugin( $information, $mwp_premium_updates_todo, $mwp_premium_updates_todo_slugs, $premiumUpgrader );
|
138 |
+
} elseif ( isset( $_POST['type'] ) && 'theme' === $_POST['type'] ) {
|
139 |
+
$this->upgrade_theme( $information, $mwp_premium_updates_todo, $mwp_premium_updates_todo_slugs, $premiumUpgrader );
|
140 |
+
} else {
|
141 |
+
MainWP_Helper::instance()->error( __( 'Invalid request!', 'mainwp-child' ) );
|
142 |
+
}
|
143 |
+
|
144 |
+
if ( count( $mwp_premium_updates_todo ) > 0 ) {
|
145 |
+
$this->update_premiums_todo( $information, $premiumUpgrader, $mwp_premium_updates_todo, $mwp_premium_updates_todo_slugs );
|
146 |
+
}
|
147 |
+
|
148 |
+
$information['sync'] = MainWP_Child_Stats::get_instance()->get_site_stats( array(), false );
|
149 |
+
MainWP_Helper::write( $information );
|
150 |
+
}
|
151 |
+
|
152 |
+
/**
|
153 |
+
* Method upgrade_plugin()
|
154 |
+
*
|
155 |
+
* Initiate the plugin update process.
|
156 |
+
*
|
157 |
+
* @param array $information An array containing the synchronization information.
|
158 |
+
* @param array $mwp_premium_updates_todo An array containing the list of premium plugins to update.
|
159 |
+
* @param array $mwp_premium_updates_todo_slugs An array containing the list of premium plugins slugs to update.
|
160 |
+
* @param bool $premiumUpgrader If true, use premium upgrader.
|
161 |
+
*
|
162 |
+
* @uses MainWP_Child_Updates::to_upgrade_plugins() Complete the plugins update process.
|
163 |
+
* @uses MainWP_Child_Updates::to_support_some_premiums_updates() Custom support for some premium plugins.
|
164 |
+
* @uses \MainWP\Child\MainWP_Helper::instance()->error()
|
165 |
+
* @uses get_plugin_updates() The WordPress Core get plugin updates function.
|
166 |
+
* @see https://developer.wordpress.org/reference/functions/get_plugin_updates/
|
167 |
+
*
|
168 |
+
* @used-by MainWP_Child_Updates::upgrade_plugin_theme() Fire off plugins and themes updates and write feedback to the synchronization information.
|
169 |
+
*/
|
170 |
+
private function upgrade_plugin( &$information, &$mwp_premium_updates_todo, &$mwp_premium_updates_todo_slugs, &$premiumUpgrader ) {
|
171 |
+
|
172 |
+
include_once ABSPATH . '/wp-admin/includes/update.php';
|
173 |
+
if ( null !== $this->filterFunction ) {
|
174 |
+
add_filter( 'pre_site_transient_update_plugins', $this->filterFunction, 99 );
|
175 |
+
}
|
176 |
+
|
177 |
+
$plugins = isset( $_POST['list'] ) ? explode( ',', urldecode( wp_unslash( $_POST['list'] ) ) ) : array();
|
178 |
+
|
179 |
+
$this->to_support_some_premiums_updates( $plugins );
|
180 |
+
|
181 |
+
/**
|
182 |
+
* WordPress current filter.
|
183 |
+
*
|
184 |
+
* @global array $wp_current_filter WordPress current filter.
|
185 |
+
*/
|
186 |
+
global $wp_current_filter;
|
187 |
+
|
188 |
+
$wp_current_filter[] = 'load-plugins.php'; // phpcs:ignore -- Required for custom plugin installations, pull request solutions appreciated.
|
189 |
+
wp_update_plugins();
|
190 |
+
|
191 |
+
// prevent premium plugins re-create update info.
|
192 |
+
remove_all_filters( 'pre_set_site_transient_update_plugins' );
|
193 |
+
|
194 |
+
// support cached premium plugins update info, hooking in the bulk_upgrade().
|
195 |
+
add_filter( 'pre_site_transient_update_plugins', array( $this, 'set_cached_update_plugins' ) );
|
196 |
+
|
197 |
+
$information['plugin_updates'] = get_plugin_updates();
|
198 |
+
|
199 |
+
$plugins = isset( $_POST['list'] ) ? explode( ',', urldecode( wp_unslash( $_POST['list'] ) ) ) : array();
|
200 |
+
$premiumPlugins = array();
|
201 |
+
$premiumUpdates = get_option( 'mainwp_premium_updates' );
|
202 |
+
if ( is_array( $premiumUpdates ) ) {
|
203 |
+
$newPlugins = array();
|
204 |
+
foreach ( $plugins as $plugin ) {
|
205 |
+
if ( in_array( $plugin, $premiumUpdates ) ) {
|
206 |
+
$premiumPlugins[] = $plugin;
|
207 |
+
} else {
|
208 |
+
$newPlugins[] = $plugin;
|
209 |
+
}
|
210 |
+
}
|
211 |
+
$plugins = $newPlugins;
|
212 |
+
}
|
213 |
+
|
214 |
+
try {
|
215 |
+
$plugins = $this->check_update_requires( $plugins );
|
216 |
+
} catch ( \Exception $e ) {
|
217 |
+
$message = $e->getMessage();
|
218 |
+
MainWP_Helper::instance()->error( $message );
|
219 |
+
}
|
220 |
+
|
221 |
+
if ( count( $plugins ) > 0 ) {
|
222 |
+
$this->to_update_plugins( $information, $plugins );
|
223 |
+
}
|
224 |
+
|
225 |
+
// support cached premium plugins update info, hooking in the bulk_upgrade().
|
226 |
+
remove_filter( 'pre_site_transient_update_plugins', array( $this, 'set_cached_update_plugins' ), 10 );
|
227 |
+
delete_site_transient( 'mainwp_update_plugins_cached' ); // fix cached update info.
|
228 |
+
|
229 |
+
if ( count( $premiumPlugins ) > 0 ) {
|
230 |
+
$mwp_premium_updates = apply_filters( 'mwp_premium_perform_update', array() );
|
231 |
+
if ( is_array( $mwp_premium_updates ) && is_array( $premiumPlugins ) ) {
|
232 |
+
foreach ( $premiumPlugins as $premiumPlugin ) {
|
233 |
+
foreach ( $mwp_premium_updates as $key => $update ) {
|
234 |
+
$slug = ( isset( $update['slug'] ) ? $update['slug'] : $update['Name'] );
|
235 |
+
if ( 0 === strcmp( $slug, $premiumPlugin ) ) {
|
236 |
+
$mwp_premium_updates_todo[ $key ] = $update;
|
237 |
+
$mwp_premium_updates_todo_slugs[] = $premiumPlugin;
|
238 |
+
}
|
239 |
+
}
|
240 |
+
}
|
241 |
+
}
|
242 |
+
unset( $mwp_premium_updates );
|
243 |
+
// fix updates for Yithemes premium plugins that hook into upgrader_pre_download.
|
244 |
+
$url = 'update.php?action=update-selected&plugins=' . rawurlencode( implode( ',', $plugins ) );
|
245 |
+
$nonce = 'bulk-update-plugins';
|
246 |
+
$premiumUpgrader = new \Plugin_Upgrader( new \Bulk_Plugin_Upgrader_Skin( compact( 'nonce', 'url' ) ) );
|
247 |
+
}
|
248 |
+
|
249 |
+
if ( count( $plugins ) <= 0 && count( $premiumPlugins ) <= 0 ) {
|
250 |
+
MainWP_Helper::instance()->error( __( 'Invalid request!', 'mainwp-child' ) );
|
251 |
+
}
|
252 |
+
|
253 |
+
if ( null !== $this->filterFunction ) {
|
254 |
+
remove_filter( 'pre_site_transient_update_plugins', $this->filterFunction, 99 );
|
255 |
+
}
|
256 |
+
}
|
257 |
+
|
258 |
+
/**
|
259 |
+
* Method check_update_requires()
|
260 |
+
*
|
261 |
+
* Check update requires.
|
262 |
+
*
|
263 |
+
* @param array $plugins An array containing plugins to be updated.
|
264 |
+
*
|
265 |
+
* @return array An array of available plugins updates.
|
266 |
+
* @throws Exception|\Exception Error Exception.
|
267 |
+
*/
|
268 |
+
private function check_update_requires( $plugins ) {
|
269 |
+
if ( ! function_exists( 'is_php_version_compatible' ) || ! is_array( $plugins ) ) {
|
270 |
+
return $plugins;
|
271 |
+
}
|
272 |
+
|
273 |
+
$tmpPlugins = array();
|
274 |
+
foreach ( $plugins as $plugin ) {
|
275 |
+
|
276 |
+
$readme_file = WP_PLUGIN_DIR . '/' . dirname( $plugin ) . '/readme.txt';
|
277 |
+
$plugin_data = array(
|
278 |
+
'requires' => '',
|
279 |
+
'requires_php' => '',
|
280 |
+
);
|
281 |
+
|
282 |
+
if ( file_exists( $readme_file ) ) {
|
283 |
+
$plugin_data = get_file_data(
|
284 |
+
$readme_file,
|
285 |
+
array(
|
286 |
+
'requires' => 'Requires at least',
|
287 |
+
'requires_php' => 'Requires PHP',
|
288 |
+
),
|
289 |
+
'plugin'
|
290 |
+
);
|
291 |
+
}
|
292 |
+
|
293 |
+
$plugin_data = array_merge( $plugin_data, get_plugin_data( WP_PLUGIN_DIR . '/' . $plugin ) );
|
294 |
+
|
295 |
+
// Check for headers in the plugin's PHP file, give precedence to the plugin headers.
|
296 |
+
$plugin_data['requires'] = ! empty( $plugin_data['RequiresWP'] ) ? $plugin_data['RequiresWP'] : $plugin_data['requires'];
|
297 |
+
$plugin_data['requires_php'] = ! empty( $plugin_data['RequiresPHP'] ) ? $plugin_data['RequiresPHP'] : $plugin_data['requires_php'];
|
298 |
+
|
299 |
+
$plugin_data['wp_compatible'] = is_wp_version_compatible( $plugin_data['requires'] );
|
300 |
+
$plugin_data['php_compatible'] = is_php_version_compatible( $plugin_data['requires_php'] );
|
301 |
+
|
302 |
+
if ( ! $plugin_data['wp_compatible'] || ! $plugin_data['php_compatible'] ) {
|
303 |
+
// Current WordPress or PHP versions do not meet minimum requirements for update.
|
304 |
+
if ( 1 == count( $plugins ) ) {
|
305 |
+
throw new \Exception( 'Current WordPress or PHP versions do not meet minimum requirements for update.' );
|
306 |
+
}
|
307 |
+
continue;
|
308 |
+
}
|
309 |
+
|
310 |
+
$tmpPlugins[] = $plugin;
|
311 |
+
}
|
312 |
+
return $tmpPlugins;
|
313 |
+
}
|
314 |
+
|
315 |
+
/**
|
316 |
+
* Method to_update_plugins()
|
317 |
+
*
|
318 |
+
* Complete the plugins update process.
|
319 |
+
*
|
320 |
+
* @param array $information An array containing the synchronization information.
|
321 |
+
* @param array $plugins An array containing plugins to be updated.
|
322 |
+
*
|
323 |
+
* @uses \MainWP\Child\MainWP_Helper::instance()->error()
|
324 |
+
*
|
325 |
+
* @used-by MainWP_Child_Updates::upgrade_plugin() Initiate the plugin update process.
|
326 |
+
*/
|
327 |
+
private function to_update_plugins( &$information, $plugins ) {
|
328 |
+
$failed = true;
|
329 |
+
// fix updates for Yithemes premium plugins that hook into upgrader_pre_download.
|
330 |
+
$url = 'update.php?action=update-selected&plugins=' . rawurlencode( implode( ',', $plugins ) );
|
331 |
+
$nonce = 'bulk-update-plugins';
|
332 |
+
|
333 |
+
do_action( 'mainwp_child_before_update', 'plugin', $plugins );
|
334 |
+
|
335 |
+
$upgrader = new \Plugin_Upgrader( new \Bulk_Plugin_Upgrader_Skin( compact( 'nonce', 'url' ) ) );
|
336 |
+
$result = $upgrader->bulk_upgrade( $plugins );
|
337 |
+
|
338 |
+
do_action( 'mainwp_child_after_update', 'plugin', $result, $plugins );
|
339 |
+
|
340 |
+
if ( ! empty( $result ) ) {
|
341 |
+
foreach ( $result as $plugin => $info ) {
|
342 |
+
if ( empty( $info ) ) {
|
343 |
+
|
344 |
+
$information['upgrades'][ $plugin ] = false;
|
345 |
+
$api = apply_filters( 'plugins_api', false, 'plugin_information', array( 'slug' => $plugin ) );
|
346 |
+
|
347 |
+
if ( ! is_wp_error( $api ) && ! empty( $api ) ) {
|
348 |
+
if ( isset( $api->download_link ) ) {
|
349 |
+
$res = $upgrader->install( $api->download_link );
|
350 |
+
if ( ! is_wp_error( $res ) && ! ( is_null( $res ) ) ) {
|
351 |
+
$information['upgrades'][ $plugin ] = true;
|
352 |
+
}
|
353 |
+
}
|
354 |
+
}
|
355 |
+
} else {
|
356 |
+
$information['upgrades'][ $plugin ] = true;
|
357 |
+
}
|
358 |
+
}
|
359 |
+
$failed = false;
|
360 |
+
}
|
361 |
+
|
362 |
+
if ( $failed ) {
|
363 |
+
MainWP_Helper::instance()->error( __( 'Invalid request!', 'mainwp-child' ) );
|
364 |
+
}
|
365 |
+
}
|
366 |
+
|
367 |
+
/**
|
368 |
+
* Method upgrade_theme()
|
369 |
+
*
|
370 |
+
* Execute themes updates.
|
371 |
+
*
|
372 |
+
* @param array $information An array containing the synchronization information.
|
373 |
+
* @param array $mwp_premium_updates_todo An array containing the list of premium themes to update.
|
374 |
+
* @param array $mwp_premium_updates_todo_slugs An array containing the list of premium themes slugs to update.
|
375 |
+
* @param bool $premiumUpgrader If true, use premium upgrader.
|
376 |
+
*
|
377 |
+
* @uses \MainWP\Child\MainWP_Child_Updates::to_upgrade_themes() Complete the themes update process.
|
378 |
+
* @uses \MainWP\Child\MainWP_Child_Updates::upgrade_get_theme_updates() Get theme updates information.
|
379 |
+
* @uses \MainWP\Child\MainWP_Helper::instance()->error()
|
380 |
+
*
|
381 |
+
* @used-by \MainWP\Child\MainWP_Child_Updates::upgrade_plugin_theme() Fire off plugins and themes updates and write feedback to the synchronization information.
|
382 |
+
*/
|
383 |
+
private function upgrade_theme( &$information, &$mwp_premium_updates_todo, &$mwp_premium_updates_todo_slugs, &$premiumUpgrader ) {
|
384 |
+
|
385 |
+
$last_update = get_site_transient( 'update_themes' );
|
386 |
+
|
387 |
+
include_once ABSPATH . '/wp-admin/includes/update.php';
|
388 |
+
if ( null !== $this->filterFunction ) {
|
389 |
+
add_filter( 'pre_site_transient_update_themes', $this->filterFunction, 99 );
|
390 |
+
}
|
391 |
+
|
392 |
+
wp_update_themes();
|
393 |
+
include_once ABSPATH . '/wp-admin/includes/theme.php';
|
394 |
+
|
395 |
+
// to support cached premium themes update info, hooking in the bulk_upgrade().
|
396 |
+
add_filter( 'pre_site_transient_update_themes', array( $this, 'set_cached_update_themes' ) );
|
397 |
+
|
398 |
+
$information['theme_updates'] = $this->upgrade_get_theme_updates();
|
399 |
+
$themes = isset( $_POST['list'] ) ? explode( ',', wp_unslash( $_POST['list'] ) ) : array();
|
400 |
+
$premiumThemes = array();
|
401 |
+
$premiumUpdates = get_option( 'mainwp_premium_updates' );
|
402 |
+
if ( is_array( $premiumUpdates ) ) {
|
403 |
+
$newThemes = array();
|
404 |
+
foreach ( $themes as $theme ) {
|
405 |
+
if ( in_array( $theme, $premiumUpdates ) ) {
|
406 |
+
$premiumThemes[] = $theme;
|
407 |
+
} else {
|
408 |
+
$newThemes[] = $theme;
|
409 |
+
}
|
410 |
+
}
|
411 |
+
$themes = $newThemes;
|
412 |
+
}
|
413 |
+
|
414 |
+
if ( count( $themes ) > 0 ) {
|
415 |
+
$this->to_upgrade_themes( $information, $themes, $last_update );
|
416 |
+
}
|
417 |
+
|
418 |
+
remove_filter( 'pre_site_transient_update_themes', array( $this, 'set_cached_update_themes' ), 10 );
|
419 |
+
delete_site_transient( 'mainwp_update_themes_cached' ); // fix cached update info.
|
420 |
+
|
421 |
+
if ( count( $premiumThemes ) > 0 ) {
|
422 |
+
$mwp_premium_updates = apply_filters( 'mwp_premium_perform_update', array() );
|
423 |
+
$mwp_premium_updates_todo = array();
|
424 |
+
$mwp_premium_updates_todo_slugs = array();
|
425 |
+
if ( is_array( $premiumThemes ) && is_array( $mwp_premium_updates ) ) {
|
426 |
+
foreach ( $premiumThemes as $premiumTheme ) {
|
427 |
+
foreach ( $mwp_premium_updates as $key => $update ) {
|
428 |
+
$slug = ( isset( $update['slug'] ) ? $update['slug'] : $update['Name'] );
|
429 |
+
if ( 0 === strcmp( $slug, $premiumTheme ) ) {
|
430 |
+
$mwp_premium_updates_todo[ $key ] = $update;
|
431 |
+
$mwp_premium_updates_todo_slugs[] = $slug;
|
432 |
+
}
|
433 |
+
}
|
434 |
+
}
|
435 |
+
}
|
436 |
+
unset( $mwp_premium_updates );
|
437 |
+
$premiumUpgrader = new \Theme_Upgrader( new \Bulk_Theme_Upgrader_Skin( compact( 'nonce', 'url' ) ) );
|
438 |
+
}
|
439 |
+
if ( count( $themes ) <= 0 && count( $premiumThemes ) <= 0 ) {
|
440 |
+
MainWP_Helper::instance()->error( __( 'Invalid request!', 'mainwp-child' ) );
|
441 |
+
}
|
442 |
+
|
443 |
+
if ( null !== $this->filterFunction ) {
|
444 |
+
remove_filter( 'pre_site_transient_update_themes', $this->filterFunction, 99 );
|
445 |
+
}
|
446 |
+
}
|
447 |
+
|
448 |
+
/**
|
449 |
+
* Method to_upgrade_themes()
|
450 |
+
*
|
451 |
+
* Complete the themes update process.
|
452 |
+
*
|
453 |
+
* @param array $information An array containing the synchronization information.
|
454 |
+
* @param array $themes An array containing themes to be updated.
|
455 |
+
* @param string $last_update Contains the last update timestamp.
|
456 |
+
*
|
457 |
+
* @uses get_site_transient() Retrieves the value of a site transient.
|
458 |
+
* @see https://developer.wordpress.org/reference/functions/get_site_transient/
|
459 |
+
*
|
460 |
+
* @uses set_site_transient() Sets/updates the value of a site transient.
|
461 |
+
* @see https://developer.wordpress.org/reference/functions/set_site_transient/
|
462 |
+
*
|
463 |
+
* @used-by \MainWP\Child\MainWP_Child_Updates::upgrade_theme() Initiate the theme update process.
|
464 |
+
*
|
465 |
+
* @uses \MainWP\Child\MainWP_Helper::instance()->error()
|
466 |
+
*/
|
467 |
+
private function to_upgrade_themes( &$information, $themes, $last_update ) {
|
468 |
+
$addFilterToFixUpdate_optimizePressTheme = false;
|
469 |
+
if ( in_array( 'optimizePressTheme', $themes ) ) {
|
470 |
+
$addFilterToFixUpdate_optimizePressTheme = true;
|
471 |
+
add_filter( 'site_transient_update_themes', array( $this, 'hook_fix_optimize_press_theme_update' ), 99 );
|
472 |
+
}
|
473 |
+
|
474 |
+
if ( null !== $this->filterFunction ) {
|
475 |
+
remove_filter( 'pre_site_transient_update_plugins', $this->filterFunction, 99 );
|
476 |
+
}
|
477 |
+
|
478 |
+
$last_update2 = get_site_transient( 'update_themes' );
|
479 |
+
set_site_transient( 'update_themes', $last_update );
|
480 |
+
|
481 |
+
do_action( 'mainwp_child_before_update', 'theme', $themes );
|
482 |
+
|
483 |
+
$failed = true;
|
484 |
+
$upgrader = new \Theme_Upgrader( new \Bulk_Theme_Upgrader_Skin( compact( 'nonce', 'url' ) ) );
|
485 |
+
$result = $upgrader->bulk_upgrade( $themes );
|
486 |
+
|
487 |
+
do_action( 'mainwp_child_after_update', 'theme', $result, $themes );
|
488 |
+
|
489 |
+
if ( ! empty( $result ) ) {
|
490 |
+
foreach ( $result as $theme => $info ) {
|
491 |
+
if ( empty( $info ) ) {
|
492 |
+
$information['upgrades'][ $theme ] = false;
|
493 |
+
} else {
|
494 |
+
$information['upgrades'][ $theme ] = true;
|
495 |
+
}
|
496 |
+
}
|
497 |
+
$failed = false;
|
498 |
+
}
|
499 |
+
|
500 |
+
if ( $failed ) {
|
501 |
+
MainWP_Helper::instance()->error( __( 'Invalid request!', 'mainwp-child' ) );
|
502 |
+
}
|
503 |
+
|
504 |
+
if ( null !== $this->filterFunction ) {
|
505 |
+
add_filter( 'pre_site_transient_update_themes', $this->filterFunction, 99 );
|
506 |
+
}
|
507 |
+
|
508 |
+
set_site_transient( 'update_themes', $last_update2 );
|
509 |
+
|
510 |
+
if ( $addFilterToFixUpdate_optimizePressTheme ) {
|
511 |
+
remove_filter(
|
512 |
+
'site_transient_update_themes',
|
513 |
+
array(
|
514 |
+
$this,
|
515 |
+
'hook_fix_optimize_press_theme_update',
|
516 |
+
),
|
517 |
+
99
|
518 |
+
);
|
519 |
+
}
|
520 |
+
}
|
521 |
+
|
522 |
+
/**
|
523 |
+
* Method update_premiums_todo()
|
524 |
+
*
|
525 |
+
* Update premium plugins.
|
526 |
+
*
|
527 |
+
* @param array $information An array containing the synchronization information.
|
528 |
+
* @param bool $premiumUpgrader If true, use premium upgrader.
|
529 |
+
* @param array $mwp_premium_updates_todo An array containing the list of premium themes to update.
|
530 |
+
* @param array $mwp_premium_updates_todo_slugs An array containing the list of premium themes slugs to update.
|
531 |
+
*/
|
532 |
+
private function update_premiums_todo( &$information, $premiumUpgrader, $mwp_premium_updates_todo, $mwp_premium_updates_todo_slugs ) {
|
533 |
+
// Upgrade via WP.
|
534 |
+
// @see wp-admin/update.php.
|
535 |
+
$result = $premiumUpgrader->bulk_upgrade( $mwp_premium_updates_todo_slugs );
|
536 |
+
if ( ! empty( $result ) ) {
|
537 |
+
foreach ( $result as $plugin => $info ) {
|
538 |
+
if ( ! empty( $info ) ) {
|
539 |
+
$information['upgrades'][ $plugin ] = true;
|
540 |
+
|
541 |
+
foreach ( $mwp_premium_updates_todo as $key => $update ) {
|
542 |
+
$slug = ( isset( $update['slug'] ) ? $update['slug'] : $update['Name'] );
|
543 |
+
}
|
544 |
+
}
|
545 |
+
}
|
546 |
+
}
|
547 |
+
|
548 |
+
// Upgrade via callback.
|
549 |
+
foreach ( $mwp_premium_updates_todo as $update ) {
|
550 |
+
$slug = ( isset( $update['slug'] ) ? $update['slug'] : $update['Name'] );
|
551 |
+
|
552 |
+
if ( isset( $update['url'] ) ) {
|
553 |
+
$installer = new \WP_Upgrader();
|
554 |
+
$result = $installer->run(
|
555 |
+
array(
|
556 |
+
'package' => $update['url'],
|
557 |
+
'destination' => ( 'plugin' === $update['type'] ? WP_PLUGIN_DIR : WP_CONTENT_DIR . '/themes' ),
|
558 |
+
'clear_destination' => true,
|
559 |
+
'clear_working' => true,
|
560 |
+
'hook_extra' => array(),
|
561 |
+
)
|
562 |
+
);
|
563 |
+
$information['upgrades'][ $slug ] = ( ! is_wp_error( $result ) && ! empty( $result ) );
|
564 |
+
} elseif ( isset( $update['callback'] ) ) {
|
565 |
+
if ( is_array( $update['callback'] ) && isset( $update['callback'][0] ) && isset( $update['callback'][1] ) ) {
|
566 |
+
$update_result = call_user_func(
|
567 |
+
array(
|
568 |
+
$update['callback'][0],
|
569 |
+
$update['callback'][1],
|
570 |
+
)
|
571 |
+
);
|
572 |
+
$information['upgrades'][ $slug ] = $update_result && true;
|
573 |
+
} elseif ( is_string( $update['callback'] ) ) {
|
574 |
+
$update_result = call_user_func( $update['callback'] );
|
575 |
+
$information['upgrades'][ $slug ] = $update_result && true;
|
576 |
+
} else {
|
577 |
+
$information['upgrades'][ $slug ] = false;
|
578 |
+
}
|
579 |
+
} else {
|
580 |
+
$information['upgrades'][ $slug ] = false;
|
581 |
+
}
|
582 |
+
}
|
583 |
+
}
|
584 |
+
|
585 |
+
/**
|
586 |
+
* Method to_support_some_premiums_updates()
|
587 |
+
*
|
588 |
+
* Custom support for some premium plugins.
|
589 |
+
*
|
590 |
+
* @param array $plugins An array containing installed plugins information.
|
591 |
+
*
|
592 |
+
* @used-by MainWP_Child_Updates::upgrade_plugin() Initiate the plugin update process.
|
593 |
+
*/
|
594 |
+
private function to_support_some_premiums_updates( $plugins ) {
|
595 |
+
// Custom fix for the iThemes products.
|
596 |
+
if ( in_array( 'backupbuddy/backupbuddy.php', $plugins ) ) {
|
597 |
+
if ( isset( $GLOBALS['ithemes_updater_path'] ) ) {
|
598 |
+
if ( ! class_exists( '\Ithemes_Updater_Settings' ) ) {
|
599 |
+
require $GLOBALS['ithemes_updater_path'] . '/settings.php';
|
600 |
+
}
|
601 |
+
if ( class_exists( '\Ithemes_Updater_Settings' ) ) {
|
602 |
+
$ithemes_updater = new \Ithemes_Updater_Settings();
|
603 |
+
$ithemes_updater->update();
|
604 |
+
}
|
605 |
+
}
|
606 |
+
}
|
607 |
+
// Custom fix for the smart-manager-for-wp-e-commerce update.
|
608 |
+
if ( in_array( 'smart-manager-for-wp-e-commerce/smart-manager.php', $plugins ) ) {
|
609 |
+
if ( file_exists( plugin_dir_path( __FILE__ ) . '../../smart-manager-for-wp-e-commerce/pro/upgrade.php' ) && file_exists( plugin_dir_path( __FILE__ ) . '../../smart-manager-for-wp-e-commerce/smart-manager.php' ) ) {
|
610 |
+
include_once plugin_dir_path( __FILE__ ) . '../../smart-manager-for-wp-e-commerce/smart-manager.php';
|
611 |
+
include_once plugin_dir_path( __FILE__ ) . '../../smart-manager-for-wp-e-commerce/pro/upgrade.php';
|
612 |
+
}
|
613 |
+
}
|
614 |
+
}
|
615 |
+
|
616 |
+
/**
|
617 |
+
* Method upgrade_get_theme_updates()
|
618 |
+
*
|
619 |
+
* Get theme updates information.
|
620 |
+
*
|
621 |
+
* @return array An array of available theme updates information.
|
622 |
+
*
|
623 |
+
* @uses get_theme_updates() The WordPress Core get theme updates function.
|
624 |
+
* @see https://developer.wordpress.org/reference/functions/get_theme_updates/
|
625 |
+
*
|
626 |
+
* @used-by \MainWP\Child\MainWP_Child_Updates::upgrade_theme() Execute themes updates.
|
627 |
+
* @uses \MainWP\Child\MainWP_Helper::search()
|
628 |
+
*/
|
629 |
+
public function upgrade_get_theme_updates() {
|
630 |
+
$themeUpdates = get_theme_updates();
|
631 |
+
$newThemeUpdates = array();
|
632 |
+
$theme_name = wp_get_theme()->get( 'Name' );
|
633 |
+
if ( is_array( $themeUpdates ) ) {
|
634 |
+
foreach ( $themeUpdates as $slug => $themeUpdate ) {
|
635 |
+
$newThemeUpdate = array();
|
636 |
+
$newThemeUpdate['update'] = $themeUpdate->update;
|
637 |
+
$newThemeUpdate['Name'] = MainWP_Helper::search( $themeUpdate, 'Name' );
|
638 |
+
$newThemeUpdate['Version'] = MainWP_Helper::search( $themeUpdate, 'Version' );
|
639 |
+
$newThemeUpdate['active'] = ( $newThemeUpdate['Name'] === $theme_name ) ? 1 : 0;
|
640 |
+
$newThemeUpdates[ $slug ] = $newThemeUpdate;
|
641 |
+
}
|
642 |
+
}
|
643 |
+
|
644 |
+
return $newThemeUpdates;
|
645 |
+
}
|
646 |
+
|
647 |
+
/**
|
648 |
+
* Method hook_fix_optimize_press_theme_update()
|
649 |
+
*
|
650 |
+
* Cutom support for the Optimize Press theme.
|
651 |
+
*
|
652 |
+
* @param object $transient Object containig the update transient information.
|
653 |
+
*
|
654 |
+
* @used-by MainWP_Child_Update::to_upgrade_themes() Complete the themes update process.
|
655 |
+
*
|
656 |
+
* @return object $transient Object containig the update transient information.
|
657 |
+
*/
|
658 |
+
public function hook_fix_optimize_press_theme_update( $transient ) {
|
659 |
+
if ( ! defined( 'OP_FUNC' ) ) {
|
660 |
+
return $transient;
|
661 |
+
}
|
662 |
+
|
663 |
+
$theme_slug = 'optimizePressTheme';
|
664 |
+
|
665 |
+
if ( ! function_exists( 'op_sl_update' ) ) {
|
666 |
+
require_once OP_FUNC . 'options.php';
|
667 |
+
require_once OP_FUNC . 'sl_api.php';
|
668 |
+
}
|
669 |
+
$apiResponse = op_sl_update( 'theme' );
|
670 |
+
|
671 |
+
if ( is_wp_error( $apiResponse ) ) {
|
672 |
+
return $transient;
|
673 |
+
}
|
674 |
+
|
675 |
+
$obj = new \stdClass();
|
676 |
+
$obj->slug = $theme_slug;
|
677 |
+
$obj->new_version = $apiResponse->new_version;
|
678 |
+
$obj->url = $apiResponse->url;
|
679 |
+
$obj->package = $apiResponse->s3_package;
|
680 |
+
$obj->sections = array(
|
681 |
+
'description' => $apiResponse->section->description,
|
682 |
+
'changelog' => $apiResponse->section->changelog,
|
683 |
+
);
|
684 |
+
|
685 |
+
$transient->response[ $theme_slug ] = (array) $obj;
|
686 |
+
|
687 |
+
return $transient;
|
688 |
+
}
|
689 |
+
|
690 |
+
/**
|
691 |
+
* Method set_cached_update_plugins()
|
692 |
+
*
|
693 |
+
* Support cached premium plugins update info, hooking in the bulk_upgrade().
|
694 |
+
*
|
695 |
+
* @param bool $false true|false.
|
696 |
+
* @param object $_transient_data Contains the transient data.
|
697 |
+
*
|
698 |
+
* @uses get_site_transient() Retrieves the value of a site transient.
|
699 |
+
* @see https://developer.wordpress.org/reference/functions/get_site_transient/
|
700 |
+
*
|
701 |
+
* @return object $_transient_data Contains the updated transient data.
|
702 |
+
*/
|
703 |
+
public function set_cached_update_plugins( $false = false, $_transient_data = null ) {
|
704 |
+
|
705 |
+
if ( ! is_object( $_transient_data ) ) {
|
706 |
+
$_transient_data = new \stdClass();
|
707 |
+
}
|
708 |
+
|
709 |
+
$pre = false;
|
710 |
+
$cached_update_info = get_site_transient( 'mainwp_update_plugins_cached' );
|
711 |
+
if ( is_array( $cached_update_info ) && count( $cached_update_info ) > 0 ) {
|
712 |
+
foreach ( $cached_update_info as $slug => $info ) {
|
713 |
+
if ( ! isset( $_transient_data->response[ $slug ] ) && isset( $info->update ) ) {
|
714 |
+
$_transient_data->response[ $slug ] = $info->update;
|
715 |
+
$pre = true;
|
716 |
+
}
|
717 |
+
}
|
718 |
+
}
|
719 |
+
|
720 |
+
if ( false == $pre ) {
|
721 |
+
return $false;
|
722 |
+
}
|
723 |
+
|
724 |
+
return $_transient_data;
|
725 |
+
}
|
726 |
+
|
727 |
+
/**
|
728 |
+
* Method set_cached_update_themes()
|
729 |
+
*
|
730 |
+
* Support cached premium themes update info, hooking in the bulk_upgrade().
|
731 |
+
*
|
732 |
+
* @param bool $false true|false.
|
733 |
+
* @param object $_transient_data Contains the transient data.
|
734 |
+
*
|
735 |
+
* @uses get_site_transient() Retrieves the value of a site transient.
|
736 |
+
* @see https://developer.wordpress.org/reference/functions/get_site_transient/
|
737 |
+
*
|
738 |
+
* @return object $_transient_data Contains the updated transient data.
|
739 |
+
*/
|
740 |
+
public function set_cached_update_themes( $false = false, $_transient_data = null ) {
|
741 |
+
|
742 |
+
if ( ! is_object( $_transient_data ) ) {
|
743 |
+
$_transient_data = new \stdClass();
|
744 |
+
}
|
745 |
+
|
746 |
+
$pre = false;
|
747 |
+
$cached_update_info = get_site_transient( 'mainwp_update_themes_cached' );
|
748 |
+
if ( is_array( $cached_update_info ) && count( $cached_update_info ) > 0 ) {
|
749 |
+
foreach ( $cached_update_info as $slug => $info ) {
|
750 |
+
if ( ! isset( $_transient_data->response[ $slug ] ) && isset( $info->update ) ) {
|
751 |
+
$_transient_data->response[ $slug ] = $info->update;
|
752 |
+
$pre = true;
|
753 |
+
}
|
754 |
+
}
|
755 |
+
}
|
756 |
+
|
757 |
+
if ( false == $pre ) {
|
758 |
+
return $false;
|
759 |
+
}
|
760 |
+
|
761 |
+
return $_transient_data;
|
762 |
+
}
|
763 |
+
|
764 |
+
/**
|
765 |
+
* Method detect_premium_themesplugins_updates()
|
766 |
+
*
|
767 |
+
* Detect premium plugins and themes updates.
|
768 |
+
*
|
769 |
+
* @uses get_site_transient() Retrieves the value of a site transient.
|
770 |
+
* @see https://developer.wordpress.org/reference/functions/get_site_transient/
|
771 |
+
*
|
772 |
+
* @uses set_site_transient() Sets/updates the value of a site transient.
|
773 |
+
* @see https://developer.wordpress.org/reference/functions/set_site_transient/
|
774 |
+
*
|
775 |
+
* @uses \MainWP\Child\MainWP_Child_Callable::is_callable_function()
|
776 |
+
* @uses \MainWP\Child\MainWP_Child_Callable::call_function()
|
777 |
+
*/
|
778 |
+
public function detect_premium_themesplugins_updates() {
|
779 |
+
|
780 |
+
if ( isset( $_GET['_detect_plugins_updates'] ) && 'yes' == $_GET['_detect_plugins_updates'] ) {
|
781 |
+
// to fix some premium plugins update notification.
|
782 |
+
$current = get_site_transient( 'update_plugins' );
|
783 |
+
set_site_transient( 'update_plugins', $current );
|
784 |
+
|
785 |
+
add_filter( 'pre_site_transient_update_plugins', $this->filterFunction, 99 );
|
786 |
+
$plugins = get_plugin_updates();
|
787 |
+
remove_filter( 'pre_site_transient_update_plugins', $this->filterFunction, 99 );
|
788 |
+
|
789 |
+
set_site_transient( 'mainwp_update_plugins_cached', $plugins, DAY_IN_SECONDS );
|
790 |
+
}
|
791 |
+
|
792 |
+
if ( isset( $_GET['_detect_themes_updates'] ) && 'yes' == $_GET['_detect_themes_updates'] ) {
|
793 |
+
add_filter( 'pre_site_transient_update_themes', $this->filterFunction, 99 );
|
794 |
+
$themes = get_theme_updates();
|
795 |
+
remove_filter( 'pre_site_transient_update_themes', $this->filterFunction, 99 );
|
796 |
+
|
797 |
+
set_site_transient( 'mainwp_update_themes_cached', $themes, DAY_IN_SECONDS );
|
798 |
+
}
|
799 |
+
|
800 |
+
$type = isset( $_GET['_request_update_premiums_type'] ) ? sanitize_text_field( wp_unslash( $_GET['_request_update_premiums_type'] ) ) : '';
|
801 |
+
|
802 |
+
if ( 'plugin' == $type || 'theme' == $type ) {
|
803 |
+
$list = isset( $_GET['list'] ) ? wp_unslash( $_GET['list'] ) : '';
|
804 |
+
|
805 |
+
if ( ! empty( $list ) ) {
|
806 |
+
$_POST['type'] = $type;
|
807 |
+
$_POST['list'] = $list;
|
808 |
+
|
809 |
+
$function = 'upgradeplugintheme'; // to call function upgrade_plugin_theme().
|
810 |
+
if ( MainWP_Child_Callable::get_instance()->is_callable_function( $function ) ) {
|
811 |
+
MainWP_Child_Callable::get_instance()->call_function( $function );
|
812 |
+
}
|
813 |
+
}
|
814 |
+
}
|
815 |
+
}
|
816 |
+
|
817 |
+
/**
|
818 |
+
* Method upgrade_wp()
|
819 |
+
*
|
820 |
+
* Initiate the WordPress core files update.
|
821 |
+
*
|
822 |
+
* @uses \MainWP\Child\MainWP_Child_Updates::do_upgrade_wp() Run the WordPress Core update.
|
823 |
+
* @uses \MainWP\Child\MainWP_Helper::get_wp_filesystem()
|
824 |
+
* @uses \MainWP\Child\MainWP_Helper::write()
|
825 |
+
*/
|
826 |
+
public function upgrade_wp() {
|
827 |
+
|
828 |
+
/**
|
829 |
+
* The installed version of WordPress.
|
830 |
+
*
|
831 |
+
* @global string $wp_version The installed version of WordPress.
|
832 |
+
*/
|
833 |
+
global $wp_version;
|
834 |
+
|
835 |
+
MainWP_Helper::get_wp_filesystem();
|
836 |
+
|
837 |
+
$information = array();
|
838 |
+
|
839 |
+
include_once ABSPATH . '/wp-admin/includes/update.php';
|
840 |
+
include_once ABSPATH . '/wp-admin/includes/class-wp-upgrader.php';
|
841 |
+
|
842 |
+
if ( file_exists( ABSPATH . '/wp-admin/includes/screen.php' ) ) {
|
843 |
+
include_once ABSPATH . '/wp-admin/includes/screen.php';
|
844 |
+
}
|
845 |
+
if ( file_exists( ABSPATH . '/wp-admin/includes/template.php' ) ) {
|
846 |
+
include_once ABSPATH . '/wp-admin/includes/template.php';
|
847 |
+
}
|
848 |
+
include_once ABSPATH . '/wp-admin/includes/file.php';
|
849 |
+
include_once ABSPATH . '/wp-admin/includes/misc.php';
|
850 |
+
|
851 |
+
if ( null !== $this->filterFunction ) {
|
852 |
+
add_filter( 'pre_site_transient_update_core', $this->filterFunction, 99 );
|
853 |
+
}
|
854 |
+
if ( null !== $this->filterFunction ) {
|
855 |
+
add_filter( 'pre_transient_update_core', $this->filterFunction, 99 );
|
856 |
+
}
|
857 |
+
$this->do_upgrade_wp( $information );
|
858 |
+
|
859 |
+
if ( null !== $this->filterFunction ) {
|
860 |
+
remove_filter( 'pre_site_transient_update_core', $this->filterFunction, 99 );
|
861 |
+
}
|
862 |
+
if ( null !== $this->filterFunction ) {
|
863 |
+
remove_filter( 'pre_transient_update_core', $this->filterFunction, 99 );
|
864 |
+
}
|
865 |
+
|
866 |
+
MainWP_Helper::write( $information );
|
867 |
+
}
|
868 |
+
|
869 |
+
/**
|
870 |
+
* Method do_upgrade_wp()
|
871 |
+
*
|
872 |
+
* Run the WordPress Core update.
|
873 |
+
*
|
874 |
+
* @param array $information An array containing the synchronization information.
|
875 |
+
*
|
876 |
+
* @used-by MainWP_Child_Updates::upgrade_wp() Initiate the WordPress core files update.
|
877 |
+
*/
|
878 |
+
private function do_upgrade_wp( &$information ) {
|
879 |
+
// Check for new versions.
|
880 |
+
wp_version_check();
|
881 |
+
|
882 |
+
$core_updates = get_core_updates();
|
883 |
+
if ( is_array( $core_updates ) && count( $core_updates ) > 0 ) {
|
884 |
+
foreach ( $core_updates as $core_update ) {
|
885 |
+
if ( 'latest' === $core_update->response ) {
|
886 |
+
$information['upgrade'] = 'SUCCESS';
|
887 |
+
} elseif ( 'upgrade' === $core_update->response && get_locale() === $core_update->locale && version_compare( $wp_version, $core_update->current, '<=' ) ) {
|
888 |
+
// Upgrade!
|
889 |
+
$upgrade = false;
|
890 |
+
if ( class_exists( '\Core_Upgrader' ) ) {
|
891 |
+
$core = new \Core_Upgrader();
|
892 |
+
$upgrade = $core->upgrade( $core_update );
|
893 |
+
}
|
894 |
+
// If this does not work - add code from /wp-admin/includes/class-wp-upgrader.php in the newer versions.
|
895 |
+
// So users can upgrade older versions too.
|
896 |
+
// 3rd option: 'wp_update_core'.
|
897 |
+
|
898 |
+
if ( ! is_wp_error( $upgrade ) ) {
|
899 |
+
$information['upgrade'] = 'SUCCESS';
|
900 |
+
} else {
|
901 |
+
$information['upgrade'] = 'WPERROR';
|
902 |
+
}
|
903 |
+
break;
|
904 |
+
}
|
905 |
+
}
|
906 |
+
|
907 |
+
if ( ! isset( $information['upgrade'] ) ) {
|
908 |
+
foreach ( $core_updates as $core_update ) {
|
909 |
+
if ( 'upgrade' === $core_update->response && version_compare( $wp_version, $core_update->current, '<=' ) ) {
|
910 |
+
// Upgrade!
|
911 |
+
$upgrade = false;
|
912 |
+
if ( class_exists( '\Core_Upgrader' ) ) {
|
913 |
+
$core = new \Core_Upgrader();
|
914 |
+
$upgrade = $core->upgrade( $core_update );
|
915 |
+
}
|
916 |
+
// If this does not work - add code from /wp-admin/includes/class-wp-upgrader.php in the newer versions
|
917 |
+
// So users can upgrade older versions too.
|
918 |
+
// 3rd option: 'wp_update_core'.
|
919 |
+
if ( ! is_wp_error( $upgrade ) ) {
|
920 |
+
$information['upgrade'] = 'SUCCESS';
|
921 |
+
} else {
|
922 |
+
$information['upgrade'] = 'WPERROR';
|
923 |
+
}
|
924 |
+
break;
|
925 |
+
}
|
926 |
+
}
|
927 |
+
}
|
928 |
+
} else {
|
929 |
+
$information['upgrade'] = 'NORESPONSE';
|
930 |
+
}
|
931 |
+
}
|
932 |
+
|
933 |
+
/**
|
934 |
+
* Method upgrade_translation()
|
935 |
+
*
|
936 |
+
* Update translations and set feedback to the sync information.
|
937 |
+
*
|
938 |
+
* @uses \MainWP\Child\MainWP_Child_Stats::get_site_stats()
|
939 |
+
* @uses \MainWP\Child\MainWP_Helper::write()
|
940 |
+
*/
|
941 |
+
public function upgrade_translation() {
|
942 |
+
/**
|
943 |
+
* Checks whether cron is in progress.
|
944 |
+
*
|
945 |
+
* @const ( bool ) Default: true
|
946 |
+
* @source https://code-reference.mainwp.com/classes/MainWP.Child.MainWP_Child_Callable.html
|
947 |
+
*/
|
948 |
+
define( 'DOING_CRON', true );
|
949 |
+
|
950 |
+
MainWP_Helper::get_wp_filesystem();
|
951 |
+
include_once ABSPATH . '/wp-admin/includes/class-wp-upgrader.php';
|
952 |
+
if ( file_exists( ABSPATH . '/wp-admin/includes/screen.php' ) ) {
|
953 |
+
include_once ABSPATH . '/wp-admin/includes/screen.php';
|
954 |
+
}
|
955 |
+
if ( file_exists( ABSPATH . '/wp-admin/includes/template.php' ) ) {
|
956 |
+
include_once ABSPATH . '/wp-admin/includes/template.php';
|
957 |
+
}
|
958 |
+
if ( file_exists( ABSPATH . '/wp-admin/includes/misc.php' ) ) {
|
959 |
+
include_once ABSPATH . '/wp-admin/includes/misc.php';
|
960 |
+
}
|
961 |
+
include_once ABSPATH . '/wp-admin/includes/file.php';
|
962 |
+
|
963 |
+
include_once ABSPATH . 'wp-admin/includes/class-wp-upgrader.php';
|
964 |
+
|
965 |
+
wp_version_check();
|
966 |
+
wp_update_themes();
|
967 |
+
wp_update_plugins();
|
968 |
+
|
969 |
+
$upgrader = new \Language_Pack_Upgrader( new \Language_Pack_Upgrader_Skin( compact( 'url', 'nonce', 'title', 'context' ) ) );
|
970 |
+
$translations = isset( $_POST['list'] ) ? explode( ',', urldecode( $_POST['list'] ) ) : array();
|
971 |
+
$all_language_updates = wp_get_translation_updates();
|
972 |
+
|
973 |
+
$language_updates = array();
|
974 |
+
foreach ( $all_language_updates as $current_language_update ) {
|
975 |
+
if ( in_array( $current_language_update->slug, $translations ) ) {
|
976 |
+
$language_updates[] = $current_language_update;
|
977 |
+
}
|
978 |
+
}
|
979 |
+
|
980 |
+
$result = count( $language_updates ) == 0 ? false : $upgrader->bulk_upgrade( $language_updates );
|
981 |
+
if ( ! empty( $result ) ) {
|
982 |
+
$count_result = count( $result );
|
983 |
+
for ( $i = 0; $i < $count_result; $i++ ) {
|
984 |
+
if ( empty( $result[ $i ] ) || is_wp_error( $result[ $i ] ) ) {
|
985 |
+
$information['upgrades'][ $language_updates[ $i ]->slug ] = false;
|
986 |
+
} else {
|
987 |
+
$information['upgrades'][ $language_updates[ $i ]->slug ] = true;
|
988 |
+
}
|
989 |
+
}
|
990 |
+
} else {
|
991 |
+
$information['upgrades'] = array(); // Fix error message when translations updated.
|
992 |
+
}
|
993 |
+
$information['sync'] = MainWP_Child_Stats::get_instance()->get_site_stats( array(), false );
|
994 |
+
MainWP_Helper::write( $information );
|
995 |
+
}
|
996 |
+
|
997 |
+
}
|
class/class-mainwp-child-users.php
CHANGED
@@ -62,7 +62,7 @@ class MainWP_Child_Users {
|
|
62 |
*
|
63 |
* @uses \MainWP\Child\MainWP_Helper::write()
|
64 |
*/
|
65 |
-
public function user_action() {
|
66 |
$action = ! empty( $_POST['action'] ) ? sanitize_text_field( wp_unslash( $_POST['action'] ) ) : '';
|
67 |
$extra = isset( $_POST['extra'] ) ? wp_unslash( $_POST['extra'] ) : '';
|
68 |
$userId = isset( $_POST['id'] ) ? sanitize_text_field( wp_unslash( $_POST['id'] ) ) : '';
|
62 |
*
|
63 |
* @uses \MainWP\Child\MainWP_Helper::write()
|
64 |
*/
|
65 |
+
public function user_action() { // phpcs:ignore -- Current complexity is the only way to achieve desired results, pull request solutions appreciated.
|
66 |
$action = ! empty( $_POST['action'] ) ? sanitize_text_field( wp_unslash( $_POST['action'] ) ) : '';
|
67 |
$extra = isset( $_POST['extra'] ) ? wp_unslash( $_POST['extra'] ) : '';
|
68 |
$userId = isset( $_POST['id'] ) ? sanitize_text_field( wp_unslash( $_POST['id'] ) ) : '';
|
class/class-mainwp-child-woocommerce-status.php
CHANGED
@@ -1,493 +1,493 @@
|
|
1 |
-
<?php
|
2 |
-
/**
|
3 |
-
* MainWP Child Woocomerce Status
|
4 |
-
*
|
5 |
-
* MainWP WooCommerce Status Extension handler.
|
6 |
-
*
|
7 |
-
* @link https://mainwp.com/extension/woocommerce-status/
|
8 |
-
*
|
9 |
-
* @package MainWP\Child
|
10 |
-
*
|
11 |
-
* Credits
|
12 |
-
*
|
13 |
-
* Plugin-Name: WooCommerce
|
14 |
-
* Plugin URI: https://woocommerce.com/
|
15 |
-
* Author: Automattic
|
16 |
-
* Author URI: https://woocommerce.com
|
17 |
-
*/
|
18 |
-
|
19 |
-
namespace MainWP\Child;
|
20 |
-
|
21 |
-
// phpcs:disable PSR1.Classes.ClassDeclaration, WordPress.WP.AlternativeFunctions -- Required to achieve desired results, pull request solutions appreciated.
|
22 |
-
|
23 |
-
/**
|
24 |
-
* Class MainWP_Child_WooCommerce_Status
|
25 |
-
*
|
26 |
-
* MainWP WooCommerce Status Extension handler.
|
27 |
-
*/
|
28 |
-
class MainWP_Child_WooCommerce_Status {
|
29 |
-
|
30 |
-
/**
|
31 |
-
* Public static variable to hold the single instance of the class.
|
32 |
-
*
|
33 |
-
* @var mixed Default null
|
34 |
-
*/
|
35 |
-
public static $instance = null;
|
36 |
-
|
37 |
-
/**
|
38 |
-
* Method instance()
|
39 |
-
*
|
40 |
-
* Create a public static instance.
|
41 |
-
*
|
42 |
-
* @return mixed Class instance.
|
43 |
-
*/
|
44 |
-
public static function instance() {
|
45 |
-
if ( null === self::$instance ) {
|
46 |
-
self::$instance = new self();
|
47 |
-
}
|
48 |
-
|
49 |
-
return self::$instance;
|
50 |
-
}
|
51 |
-
|
52 |
-
/**
|
53 |
-
* MainWP_Child_WooCommerce_Status constructor.
|
54 |
-
*
|
55 |
-
* Run any time class is called.
|
56 |
-
*/
|
57 |
-
public function __construct() {
|
58 |
-
add_action( 'mainwp_child_deactivation', array( $this, 'child_deactivation' ) );
|
59 |
-
}
|
60 |
-
|
61 |
-
/**
|
62 |
-
* MainWP Child Plugin deactivation hooks.
|
63 |
-
*/
|
64 |
-
public function child_deactivation() {
|
65 |
-
}
|
66 |
-
|
67 |
-
/**
|
68 |
-
* MainWP Child Woocommerce actions: sync_data, report_data, update_wc_db.
|
69 |
-
*
|
70 |
-
* @uses \MainWP\Child\MainWP_Helper::write()
|
71 |
-
*/
|
72 |
-
public function action() {
|
73 |
-
$information = array();
|
74 |
-
if ( ! class_exists( '\WooCommerce' ) || ! defined( 'WC_VERSION' ) ) {
|
75 |
-
$information['error'] = 'NO_WOOCOMMERCE';
|
76 |
-
MainWP_Helper::write( $information );
|
77 |
-
}
|
78 |
-
|
79 |
-
$is_ver220 = $this->is_version_220();
|
80 |
-
if ( isset( $_POST['mwp_action'] ) ) {
|
81 |
-
$mwp_action = ! empty( $_POST['mwp_action'] ) ? sanitize_text_field( wp_unslash( $_POST['mwp_action'] ) ) : '';
|
82 |
-
switch ( $mwp_action ) {
|
83 |
-
case 'sync_data':
|
84 |
-
$information = ! $is_ver220 ? $this->sync_data() : $this->sync_data_two();
|
85 |
-
break;
|
86 |
-
case 'report_data':
|
87 |
-
$information = ! $is_ver220 ? $this->report_data() : $this->report_data_two();
|
88 |
-
break;
|
89 |
-
case 'update_wc_db':
|
90 |
-
$information = $this->update_wc_db();
|
91 |
-
break;
|
92 |
-
}
|
93 |
-
}
|
94 |
-
MainWP_Helper::write( $information );
|
95 |
-
}
|
96 |
-
|
97 |
-
/**
|
98 |
-
* Compare woocommerce versions.
|
99 |
-
*
|
100 |
-
* By default, version_compare returns -1 if the first version is lower than the second,
|
101 |
-
* 0 if they are equal, and 1 if the second is lower.
|
102 |
-
* When using the optional operator argument, the function will return true if the relationship is
|
103 |
-
* the one specified by the operator, false otherwise.
|
104 |
-
*
|
105 |
-
* @return bool|int Comparison response.
|
106 |
-
*/
|
107 |
-
public function is_version_220() {
|
108 |
-
return version_compare( WC()->version, '2.2.0', '>=' );
|
109 |
-
}
|
110 |
-
|
111 |
-
/**
|
112 |
-
* Sync Woocommerce data.
|
113 |
-
*
|
114 |
-
* @return array $information Woocommerce data grabed.
|
115 |
-
*/
|
116 |
-
public function sync_data() {
|
117 |
-
|
118 |
-
/**
|
119 |
-
* Object, providing access to the WordPress database.
|
120 |
-
*
|
121 |
-
* @global object $wpdb WordPress Database instance.
|
122 |
-
*/
|
123 |
-
global $wpdb;
|
124 |
-
|
125 |
-
$file = WP_PLUGIN_DIR . '/woocommerce/includes/admin/reports/class-wc-admin-report.php';
|
126 |
-
if ( file_exists( $file ) ) {
|
127 |
-
include_once $file;
|
128 |
-
} else {
|
129 |
-
return false;
|
130 |
-
}
|
131 |
-
|
132 |
-
// Get sales.
|
133 |
-
$sales = $wpdb->get_var(
|
134 |
-
$wpdb->prepare(
|
135 |
-
"SELECT SUM( postmeta.meta_value ) FROM {$wpdb->posts} as posts
|
136 |
-
LEFT JOIN {$wpdb->term_relationships} AS rel ON posts.ID=rel.object_ID
|
137 |
-
LEFT JOIN {$wpdb->term_taxonomy} AS tax USING( term_taxonomy_id )
|
138 |
-
LEFT JOIN {$wpdb->terms} AS term USING( term_id )
|
139 |
-
LEFT JOIN {$wpdb->postmeta} AS postmeta ON posts.ID = postmeta.post_id
|
140 |
-
WHERE posts.post_type = 'shop_order'
|
141 |
-
AND posts.post_status = 'publish'
|
142 |
-
AND tax.taxonomy = 'shop_order_status'
|
143 |
-
AND term.slug IN ( '" . implode( "','", apply_filters( 'woocommerce_reports_order_statuses', array( 'completed', 'processing', 'on-hold' ) ) ) . "' ) " . // phpcs:ignore -- safe query.
|
144 |
-
" AND postmeta.meta_key = '_order_total'
|
145 |
-
AND posts.post_date >= %s
|
146 |
-
AND posts.post_date <= %s",
|
147 |
-
date( 'Y-m-01' ), // phpcs:ignore -- local time.
|
148 |
-
date( 'Y-m-d H:i:s' ) // phpcs:ignore -- local time.
|
149 |
-
)
|
150 |
-
);
|
151 |
-
|
152 |
-
// Get top seller.
|
153 |
-
$top_seller = $wpdb->get_row(
|
154 |
-
$wpdb->prepare( // phpcs:ignore -- safe query.
|
155 |
-
"SELECT SUM( order_item_meta.meta_value ) as qty, order_item_meta_2.meta_value as product_id
|
156 |
-
FROM {$wpdb->posts} as posts
|
157 |
-
LEFT JOIN {$wpdb->term_relationships} AS rel ON posts.ID=rel.object_ID
|
158 |
-
LEFT JOIN {$wpdb->term_taxonomy} AS tax USING( term_taxonomy_id )
|
159 |
-
LEFT JOIN {$wpdb->terms} AS term USING( term_id )
|
160 |
-
LEFT JOIN {$wpdb->prefix}woocommerce_order_items AS order_items ON posts.ID = order_id
|
161 |
-
LEFT JOIN {$wpdb->prefix}woocommerce_order_itemmeta AS order_item_meta ON order_items.order_item_id = order_item_meta.order_item_id
|
162 |
-
LEFT JOIN {$wpdb->prefix}woocommerce_order_itemmeta AS order_item_meta_2 ON order_items.order_item_id = order_item_meta_2.order_item_id
|
163 |
-
WHERE posts.post_type = 'shop_order'
|
164 |
-
AND posts.post_status = 'publish'
|
165 |
-
AND tax.taxonomy = 'shop_order_status'
|
166 |
-
AND term.slug IN ( '" . implode( "','", apply_filters( 'woocommerce_reports_order_statuses', array( 'completed', 'processing', 'on-hold' ) ) ) . "' ) " . // phpcs:ignore -- safe query.
|
167 |
-
" AND order_item_meta.meta_key = '_qty'
|
168 |
-
AND order_item_meta_2.meta_key = '_product_id'
|
169 |
-
AND posts.post_date >= %s
|
170 |
-
AND posts.post_date <= %s
|
171 |
-
GROUP BY product_id
|
172 |
-
ORDER BY qty DESC
|
173 |
-
LIMIT 1",
|
174 |
-
date( 'Y-m-01' ), // phpcs:ignore -- local time.
|
175 |
-
date( 'Y-m-d H:i:s' ) // phpcs:ignore -- local time.
|
176 |
-
)
|
177 |
-
);
|
178 |
-
|
179 |
-
if ( ! empty( $top_seller ) ) {
|
180 |
-
$top_seller->name = get_the_title( $top_seller->product_id );
|
181 |
-
}
|
182 |
-
|
183 |
-
// Counts.
|
184 |
-
$on_hold_count = get_term_by( 'slug', 'on-hold', 'shop_order_status' )->count;
|
185 |
-
$processing_count = get_term_by( 'slug', 'processing', 'shop_order_status' )->count;
|
186 |
-
|
187 |
-
// Get products using a query.
|
188 |
-
$stock = absint( max( get_option( 'woocommerce_notify_low_stock_amount' ), 1 ) );
|
189 |
-
$nostock = absint( max( get_option( 'woocommerce_notify_no_stock_amount' ), 0 ) );
|
190 |
-
|
191 |
-
$query_from = "FROM {$wpdb->posts} as posts INNER JOIN {$wpdb->postmeta} AS postmeta ON posts.ID = postmeta.post_id INNER JOIN {$wpdb->postmeta} AS postmeta2 ON posts.ID = postmeta2.post_id WHERE 1=1 AND posts.post_type IN ('product', 'product_variation') AND posts.post_status = 'publish' AND ( postmeta.meta_key = '_stock' AND CAST(postmeta.meta_value AS SIGNED) <= '{$stock}' AND CAST(postmeta.meta_value AS SIGNED) > '{$nostock}' AND postmeta.meta_value != '' ) AND ( ( postmeta2.meta_key = '_manage_stock' AND postmeta2.meta_value = 'yes' ) OR ( posts.post_type = 'product_variation' ) )";
|
192 |
-
|
193 |
-
$lowinstock_count = absint( $wpdb->get_var( "SELECT COUNT( DISTINCT posts.ID ) {$query_from};" ) ); //phpcs:ignore -- safe query.
|
194 |
-
|
195 |
-
$query_from = "FROM {$wpdb->posts} as posts INNER JOIN {$wpdb->postmeta} AS postmeta ON posts.ID = postmeta.post_id INNER JOIN {$wpdb->postmeta} AS postmeta2 ON posts.ID = postmeta2.post_id WHERE 1=1 AND posts.post_type IN ('product', 'product_variation') AND posts.post_status = 'publish' AND ( postmeta.meta_key = '_stock' AND CAST(postmeta.meta_value AS SIGNED) <= '{$nostock}' AND postmeta.meta_value != '' ) AND ( ( postmeta2.meta_key = '_manage_stock' AND postmeta2.meta_value = 'yes' ) OR ( posts.post_type = 'product_variation' ) )";
|
196 |
-
|
197 |
-
$outofstock_count = absint( $wpdb->get_var( "SELECT COUNT( DISTINCT posts.ID ) {$query_from};" ) ); //phpcs:ignore -- safe query.
|
198 |
-
|
199 |
-
$data = array(
|
200 |
-
'sales' => $sales,
|
201 |
-
'formated_sales' => wc_price( $sales ),
|
202 |
-
'top_seller' => $top_seller,
|
203 |
-
'onhold' => $on_hold_count,
|
204 |
-
'awaiting' => $processing_count,
|
205 |
-
'stock' => $stock,
|
206 |
-
'nostock' => $nostock,
|
207 |
-
'lowstock' => $lowinstock_count,
|
208 |
-
'outstock' => $outofstock_count,
|
209 |
-
);
|
210 |
-
|
211 |
-
$data = apply_filters( 'mainwp_child_woocom_sync_data', $data );
|
212 |
-
|
213 |
-
$information['data'] = $data;
|
214 |
-
|
215 |
-
return $information;
|
216 |
-
}
|
217 |
-
|
218 |
-
/**
|
219 |
-
* Woocommerce report data.
|
220 |
-
*
|
221 |
-
* @return array $information Woocommerce data grabed.
|
222 |
-
*/
|
223 |
-
public function report_data() {
|
224 |
-
|
225 |
-
/**
|
226 |
-
* Object, providing access to the WordPress database.
|
227 |
-
*
|
228 |
-
* @global object $wpdb WordPress Database instance.
|
229 |
-
*/
|
230 |
-
global $wpdb;
|
231 |
-
|
232 |
-
$file = WP_PLUGIN_DIR . '/woocommerce/includes/admin/reports/class-wc-admin-report.php';
|
233 |
-
if ( file_exists( $file ) ) {
|
234 |
-
include_once $file;
|
235 |
-
} else {
|
236 |
-
return false;
|
237 |
-
}
|
238 |
-
|
239 |
-
$start_date = isset( $_POST['start_date'] ) ? sanitize_text_field( wp_unslash( $_POST['start_date'] ) ) : '';
|
240 |
-
$end_date = isset( $_POST['end_date'] ) ? sanitize_text_field( wp_unslash( $_POST['end_date'] ) ) : '';
|
241 |
-
|
242 |
-
$start_date = date( 'Y-m-d H:i:s', $start_date ); // phpcs:ignore -- local time.
|
243 |
-
$end_date = date( 'Y-m-d H:i:s', $end_date ); // phpcs:ignore -- local time.
|
244 |
-
|
245 |
-
// Get sales.
|
246 |
-
$sales = $wpdb->get_var(
|
247 |
-
"SELECT SUM( postmeta.meta_value ) FROM {$wpdb->posts} as posts
|
248 |
-
LEFT JOIN {$wpdb->term_relationships} AS rel ON posts.ID=rel.object_ID
|
249 |
-
LEFT JOIN {$wpdb->term_taxonomy} AS tax USING( term_taxonomy_id )
|
250 |
-
LEFT JOIN {$wpdb->terms} AS term USING( term_id )
|
251 |
-
LEFT JOIN {$wpdb->postmeta} AS postmeta ON posts.ID = postmeta.post_id
|
252 |
-
WHERE posts.post_type = 'shop_order'
|
253 |
-
AND posts.post_status = 'publish'
|
254 |
-
AND tax.taxonomy = 'shop_order_status'
|
255 |
-
AND term.slug IN ( '" . implode( "','", apply_filters( 'woocommerce_reports_order_statuses', array( 'completed', 'processing', 'on-hold' ) ) ) . "' ) " . // phpcs:ignore -- safe query.
|
256 |
-
" AND postmeta.meta_key = '_order_total'
|
257 |
-
AND posts.post_date >= STR_TO_DATE(" . $wpdb->prepare( '%s', $start_date ) . ", '%Y-%m-%d %H:%i:%s')
|
258 |
-
AND posts.post_date <= STR_TO_DATE(" . $wpdb->prepare( '%s', $end_date ) . ", '%Y-%m-%d %H:%i:%s')"
|
259 |
-
);
|
260 |
-
|
261 |
-
// Get top seller.
|
262 |
-
$top_seller = $wpdb->get_row(
|
263 |
-
"SELECT SUM( order_item_meta.meta_value ) as qty, order_item_meta_2.meta_value as product_id
|
264 |
-
FROM {$wpdb->posts} as posts
|
265 |
-
LEFT JOIN {$wpdb->term_relationships} AS rel ON posts.ID=rel.object_ID
|
266 |
-
LEFT JOIN {$wpdb->term_taxonomy} AS tax USING( term_taxonomy_id )
|
267 |
-
LEFT JOIN {$wpdb->terms} AS term USING( term_id )
|
268 |
-
LEFT JOIN {$wpdb->prefix}woocommerce_order_items AS order_items ON posts.ID = order_id
|
269 |
-
LEFT JOIN {$wpdb->prefix}woocommerce_order_itemmeta AS order_item_meta ON order_items.order_item_id = order_item_meta.order_item_id
|
270 |
-
LEFT JOIN {$wpdb->prefix}woocommerce_order_itemmeta AS order_item_meta_2 ON order_items.order_item_id = order_item_meta_2.order_item_id
|
271 |
-
WHERE posts.post_type = 'shop_order'
|
272 |
-
AND posts.post_status = 'publish'
|
273 |
-
AND tax.taxonomy = 'shop_order_status'
|
274 |
-
AND term.slug IN ( '" . implode( "','", apply_filters( 'woocommerce_reports_order_statuses', array( 'completed', 'processing', 'on-hold' ) ) ) . "' ) " . // phpcs:ignore -- safe query.
|
275 |
-
" AND order_item_meta.meta_key = '_qty'
|
276 |
-
AND order_item_meta_2.meta_key = '_product_id'
|
277 |
-
AND posts.post_date >= STR_TO_DATE(" . $wpdb->prepare( '%s', $start_date ) . ", '%Y-%m-%d %H:%i:%s' )
|
278 |
-
AND posts.post_date <= STR_TO_DATE(" . $wpdb->prepare( '%s', $end_date ) . ", '%Y-%m-%d %H:%i:%s' )
|
279 |
-
GROUP BY product_id
|
280 |
-
ORDER BY qty DESC
|
281 |
-
LIMIT 1"
|
282 |
-
);
|
283 |
-
|
284 |
-
if ( ! empty( $top_seller ) ) {
|
285 |
-
$top_seller->name = get_the_title( $top_seller->product_id );
|
286 |
-
}
|
287 |
-
|
288 |
-
// Counts.
|
289 |
-
$on_hold_count = get_term_by( 'slug', 'on-hold', 'shop_order_status' )->count;
|
290 |
-
$processing_count = get_term_by( 'slug', 'processing', 'shop_order_status' )->count;
|
291 |
-
|
292 |
-
// Get products using a query.
|
293 |
-
$stock = absint( max( get_option( 'woocommerce_notify_low_stock_amount' ), 1 ) );
|
294 |
-
$nostock = absint( max( get_option( 'woocommerce_notify_no_stock_amount' ), 0 ) );
|
295 |
-
|
296 |
-
$query_from = "FROM {$wpdb->posts} as posts INNER JOIN {$wpdb->postmeta} AS postmeta ON posts.ID = postmeta.post_id INNER JOIN {$wpdb->postmeta} AS postmeta2 ON posts.ID = postmeta2.post_id WHERE 1=1 AND posts.post_type IN ('product', 'product_variation') AND posts.post_status = 'publish' AND ( postmeta.meta_key = '_stock' AND CAST(postmeta.meta_value AS SIGNED) <= '{$stock}' AND CAST(postmeta.meta_value AS SIGNED) > '{$nostock}' AND postmeta.meta_value != '' ) AND ( ( postmeta2.meta_key = '_manage_stock' AND postmeta2.meta_value = 'yes' ) OR ( posts.post_type = 'product_variation' ) )";
|
297 |
-
|
298 |
-
$lowinstock_count = absint( $wpdb->get_var( "SELECT COUNT( DISTINCT posts.ID ) {$query_from};" ) ); //phpcs:ignore -- safe query.
|
299 |
-
|
300 |
-
$query_from = "FROM {$wpdb->posts} as posts INNER JOIN {$wpdb->postmeta} AS postmeta ON posts.ID = postmeta.post_id INNER JOIN {$wpdb->postmeta} AS postmeta2 ON posts.ID = postmeta2.post_id WHERE 1=1 AND posts.post_type IN ('product', 'product_variation') AND posts.post_status = 'publish' AND ( postmeta.meta_key = '_stock' AND CAST(postmeta.meta_value AS SIGNED) <= '{$nostock}' AND postmeta.meta_value != '' ) AND ( ( postmeta2.meta_key = '_manage_stock' AND postmeta2.meta_value = 'yes' ) OR ( posts.post_type = 'product_variation' ) )";
|
301 |
-
|
302 |
-
$outofstock_count = absint( $wpdb->get_var( "SELECT COUNT( DISTINCT posts.ID ) {$query_from};" ) ); //phpcs:ignore -- safe query.
|
303 |
-
|
304 |
-
$data = array(
|
305 |
-
'sales' => $sales,
|
306 |
-
'formated_sales' => wc_price( $sales ),
|
307 |
-
'top_seller' => $top_seller,
|
308 |
-
'onhold' => $on_hold_count,
|
309 |
-
'awaiting' => $processing_count,
|
310 |
-
'stock' => $stock,
|
311 |
-
'nostock' => $nostock,
|
312 |
-
'lowstock' => $lowinstock_count,
|
313 |
-
'outstock' => $outofstock_count,
|
314 |
-
);
|
315 |
-
|
316 |
-
$data = apply_filters( 'mainwp_child_woocom_report_data', $data );
|
317 |
-
|
318 |
-
$information['data'] = $data;
|
319 |
-
|
320 |
-
return $information;
|
321 |
-
}
|
322 |
-
|
323 |
-
/**
|
324 |
-
* Sync Woocommerce data for current month.
|
325 |
-
*/
|
326 |
-
public function sync_data_two() {
|
327 |
-
$start_date = date( 'Y-m-01 00:00:00', time() ); // phpcs:ignore -- local time.
|
328 |
-
$end_date = date( 'Y-m-d H:i:s', time() ); // phpcs:ignore -- local time.
|
329 |
-
|
330 |
-
$start_date = strtotime( $start_date );
|
331 |
-
$end_date = strtotime( $end_date );
|
332 |
-
|
333 |
-
return $this->get_woocom_data( $start_date, $end_date );
|
334 |
-
}
|
335 |
-
|
336 |
-
/**
|
337 |
-
* Sync Woocomerce data for specific date range.
|
338 |
-
*/
|
339 |
-
public function report_data_two() {
|
340 |
-
$start_date = isset( $_POST['start_date'] ) ? sanitize_text_field( wp_unslash( $_POST['start_date'] ) ) : '';
|
341 |
-
$end_date = isset( $_POST['end_date'] ) ? sanitize_text_field( wp_unslash( $_POST['end_date'] ) ) : '';
|
342 |
-
|
343 |
-
return $this->get_woocom_data( $start_date, $end_date );
|
344 |
-
}
|
345 |
-
|
346 |
-
/**
|
347 |
-
* Check if woocomerce DB needs to be updated.
|
348 |
-
*
|
349 |
-
* @return bool true|false.
|
350 |
-
*/
|
351 |
-
public function check_db_update() {
|
352 |
-
if ( version_compare( get_option( 'woocommerce_db_version' ), WC_VERSION, '<' ) ) {
|
353 |
-
return true;
|
354 |
-
}
|
355 |
-
return false;
|
356 |
-
}
|
357 |
-
|
358 |
-
/**
|
359 |
-
* Get Woocommerce data.
|
360 |
-
*
|
361 |
-
* @param string $start_date Start Date.
|
362 |
-
* @param string $end_date End Date.
|
363 |
-
*
|
364 |
-
* @return array $information Woocommerce data grabed.
|
365 |
-
*/
|
366 |
-
public function get_woocom_data( $start_date, $end_date ) {
|
367 |
-
|
368 |
-
/**
|
369 |
-
* Object, providing access to the WordPress database.
|
370 |
-
*
|
371 |
-
* @global object $wpdb WordPress Database instance.
|
372 |
-
*/
|
373 |
-
global $wpdb;
|
374 |
-
|
375 |
-
$file = WP_PLUGIN_DIR . '/woocommerce/includes/admin/reports/class-wc-admin-report.php';
|
376 |
-
if ( file_exists( $file ) ) {
|
377 |
-
include_once $file;
|
378 |
-
} else {
|
379 |
-
return false;
|
380 |
-
}
|
381 |
-
|
382 |
-
$start_date = date( 'Y-m-d H:i:s', $start_date ); // phpcs:ignore -- local time. Required to achieve desired results, pull request solutions appreciated.
|
383 |
-
$end_date = date( 'Y-m-d H:i:s', $end_date ); // phpcs:ignore -- local time. Required to achieve desired results, pull request solutions appreciated.
|
384 |
-
|
385 |
-
// Sales.
|
386 |
-
$query = array();
|
387 |
-
$query['fields'] = "SELECT SUM( postmeta.meta_value ) FROM {$wpdb->posts} as posts";
|
388 |
-
$query['join'] = "INNER JOIN {$wpdb->postmeta} AS postmeta ON posts.ID = postmeta.post_id ";
|
389 |
-
$query['where'] = "WHERE posts.post_type IN ( '" . implode( "','", wc_get_order_types( 'reports' ) ) . "' ) ";
|
390 |
-
$query['where'] .= "AND posts.post_status IN ( 'wc-" . implode( "','wc-", apply_filters( 'woocommerce_reports_order_statuses', array( 'completed', 'processing', 'on-hold' ) ) ) . "' ) ";
|
391 |
-
$query['where'] .= "AND postmeta.meta_key = '_order_total' ";
|
392 |
-
$query['where'] .= 'AND posts.post_date >= STR_TO_DATE(' . $wpdb->prepare( '%s', $start_date ) . ", '%Y-%m-%d %H:%i:%s' ) ";
|
393 |
-
$query['where'] .= 'AND posts.post_date <= STR_TO_DATE(' . $wpdb->prepare( '%s', $end_date ) . ", '%Y-%m-%d %H:%i:%s' ) ";
|
394 |
-
|
395 |
-
$sales = $wpdb->get_var( implode( ' ', apply_filters( 'woocommerce_dashboard_status_widget_sales_query', $query ) ) ); // phpcs:ignore -- safe query.
|
396 |
-
|
397 |
-
// Get top seller.
|
398 |
-
$query = array();
|
399 |
-
$query['fields'] = "SELECT SUM( order_item_meta.meta_value ) as qty, order_item_meta_2.meta_value as product_id FROM {$wpdb->posts} as posts";
|
400 |
-
$query['join'] = "INNER JOIN {$wpdb->prefix}woocommerce_order_items AS order_items ON posts.ID = order_id ";
|
401 |
-
$query['join'] .= "INNER JOIN {$wpdb->prefix}woocommerce_order_itemmeta AS order_item_meta ON order_items.order_item_id = order_item_meta.order_item_id ";
|
402 |
-
$query['join'] .= "INNER JOIN {$wpdb->prefix}woocommerce_order_itemmeta AS order_item_meta_2 ON order_items.order_item_id = order_item_meta_2.order_item_id ";
|
403 |
-
$query['where'] = "WHERE posts.post_type IN ( '" . implode( "','", wc_get_order_types( 'order-count' ) ) . "' ) ";
|
404 |
-
$query['where'] .= "AND posts.post_status IN ( 'wc-" . implode( "','wc-", apply_filters( 'woocommerce_reports_order_statuses', array( 'completed', 'processing', 'on-hold' ) ) ) . "' ) ";
|
405 |
-
$query['where'] .= "AND order_item_meta.meta_key = '_qty' ";
|
406 |
-
$query['where'] .= "AND order_item_meta_2.meta_key = '_product_id' ";
|
407 |
-
$query['where'] .= 'AND posts.post_date >= STR_TO_DATE(' . $wpdb->prepare( '%s', $start_date ) . ", '%Y-%m-%d %H:%i:%s') ";
|
408 |
-
$query['where'] .= 'AND posts.post_date <= STR_TO_DATE(' . $wpdb->prepare( '%s', $end_date ) . ", '%Y-%m-%d %H:%i:%s') ";
|
409 |
-
$query['groupby'] = 'GROUP BY product_id';
|
410 |
-
$query['orderby'] = 'ORDER BY qty DESC';
|
411 |
-
$query['limits'] = 'LIMIT 1';
|
412 |
-
|
413 |
-
$top_seller = $wpdb->get_row( implode( ' ', $query ) ); // phpcs:ignore -- safe query.
|
414 |
-
|
415 |
-
if ( ! empty( $top_seller ) ) {
|
416 |
-
$top_seller->name = get_the_title( $top_seller->product_id );
|
417 |
-
}
|
418 |
-
|
419 |
-
// Counts.
|
420 |
-
$on_hold_count = 0;
|
421 |
-
$processing_count = 0;
|
422 |
-
|
423 |
-
foreach ( wc_get_order_types( 'order-count' ) as $type ) {
|
424 |
-
$counts = (array) wp_count_posts( $type );
|
425 |
-
$on_hold_count += isset( $counts['wc-on-hold'] ) ? $counts['wc-on-hold'] : 0;
|
426 |
-
$processing_count += isset( $counts['wc-processing'] ) ? $counts['wc-processing'] : 0;
|
427 |
-
}
|
428 |
-
|
429 |
-
// Get products using a query.
|
430 |
-
$stock = absint( max( get_option( 'woocommerce_notify_low_stock_amount' ), 1 ) );
|
431 |
-
$nostock = absint( max( get_option( 'woocommerce_notify_no_stock_amount' ), 0 ) );
|
432 |
-
|
433 |
-
$query_from = "FROM {$wpdb->posts} as posts INNER JOIN {$wpdb->postmeta} AS postmeta ON posts.ID = postmeta.post_id INNER JOIN {$wpdb->postmeta} AS postmeta2 ON posts.ID = postmeta2.post_id WHERE 1=1 AND posts.post_type IN ('product', 'product_variation') AND posts.post_status = 'publish' AND ( postmeta.meta_key = '_stock' AND CAST(postmeta.meta_value AS SIGNED) <= '{$stock}' AND CAST(postmeta.meta_value AS SIGNED) > '{$nostock}' AND postmeta.meta_value != '' ) AND ( ( postmeta2.meta_key = '_manage_stock' AND postmeta2.meta_value = 'yes' ) OR ( posts.post_type = 'product_variation' ) )";
|
434 |
-
|
435 |
-
$lowinstock_count = absint( $wpdb->get_var( "SELECT COUNT( DISTINCT posts.ID ) {$query_from};" ) ); //phpcs:ignore -- safe query.
|
436 |
-
|
437 |
-
$query_from = "FROM {$wpdb->posts} as posts INNER JOIN {$wpdb->postmeta} AS postmeta ON posts.ID = postmeta.post_id INNER JOIN {$wpdb->postmeta} AS postmeta2 ON posts.ID = postmeta2.post_id WHERE 1=1 AND posts.post_type IN ('product', 'product_variation') AND posts.post_status = 'publish' AND ( postmeta.meta_key = '_stock' AND CAST(postmeta.meta_value AS SIGNED) <= '{$nostock}' AND postmeta.meta_value != '' ) AND ( ( postmeta2.meta_key = '_manage_stock' AND postmeta2.meta_value = 'yes' ) OR ( posts.post_type = 'product_variation' ) ) ";
|
438 |
-
|
439 |
-
$outofstock_count = absint( $wpdb->get_var( "SELECT COUNT( DISTINCT posts.ID ) {$query_from};" ) ); //phpcs:ignore -- safe query.
|
440 |
-
|
441 |
-
$data = array(
|
442 |
-
'sales' => $sales,
|
443 |
-
'formated_sales' => wc_price( $sales ),
|
444 |
-
'top_seller' => $top_seller,
|
445 |
-
'onhold' => $on_hold_count,
|
446 |
-
'awaiting' => $processing_count,
|
447 |
-
'stock' => $stock,
|
448 |
-
'nostock' => $nostock,
|
449 |
-
'lowstock' => $lowinstock_count,
|
450 |
-
'outstock' => $outofstock_count,
|
451 |
-
);
|
452 |
-
|
453 |
-
$data = apply_filters( 'mainwp_child_woocom_get_data', $data );
|
454 |
-
|
455 |
-
$information['data'] = $data;
|
456 |
-
$information['need_db_update'] = $this->check_db_update();
|
457 |
-
return $information;
|
458 |
-
}
|
459 |
-
|
460 |
-
/**
|
461 |
-
* Update Woocommerce Database.
|
462 |
-
*
|
463 |
-
* @return string[] Success.
|
464 |
-
*/
|
465 |
-
private static function update_wc_db() {
|
466 |
-
include_once WC()->plugin_path() . '/includes/class-wc-background-updater.php';
|
467 |
-
$background_updater = new \WC_Background_Updater();
|
468 |
-
|
469 |
-
$current_db_version = get_option( 'woocommerce_db_version' );
|
470 |
-
$logger = wc_get_logger();
|
471 |
-
$update_queued = false;
|
472 |
-
|
473 |
-
foreach ( \WC_Install::get_db_update_callbacks() as $version => $update_callbacks ) {
|
474 |
-
if ( version_compare( $current_db_version, $version, '<' ) ) {
|
475 |
-
foreach ( $update_callbacks as $update_callback ) {
|
476 |
-
$logger->info(
|
477 |
-
sprintf( 'Queuing %s - %s', $version, $update_callback ),
|
478 |
-
array( 'source' => 'wc_db_updates' )
|
479 |
-
);
|
480 |
-
$background_updater->push_to_queue( $update_callback );
|
481 |
-
$update_queued = true;
|
482 |
-
}
|
483 |
-
}
|
484 |
-
}
|
485 |
-
|
486 |
-
if ( $update_queued ) {
|
487 |
-
$background_updater->save()->dispatch();
|
488 |
-
}
|
489 |
-
|
490 |
-
return array( 'result' => 'success' );
|
491 |
-
}
|
492 |
-
|
493 |
-
}
|
1 |
+
<?php
|
2 |
+
/**
|
3 |
+
* MainWP Child Woocomerce Status
|
4 |
+
*
|
5 |
+
* MainWP WooCommerce Status Extension handler.
|
6 |
+
*
|
7 |
+
* @link https://mainwp.com/extension/woocommerce-status/
|
8 |
+
*
|
9 |
+
* @package MainWP\Child
|
10 |
+
*
|
11 |
+
* Credits
|
12 |
+
*
|
13 |
+
* Plugin-Name: WooCommerce
|
14 |
+
* Plugin URI: https://woocommerce.com/
|
15 |
+
* Author: Automattic
|
16 |
+
* Author URI: https://woocommerce.com
|
17 |
+
*/
|
18 |
+
|
19 |
+
namespace MainWP\Child;
|
20 |
+
|
21 |
+
// phpcs:disable PSR1.Classes.ClassDeclaration, WordPress.WP.AlternativeFunctions -- Required to achieve desired results, pull request solutions appreciated.
|
22 |
+
|
23 |
+
/**
|
24 |
+
* Class MainWP_Child_WooCommerce_Status
|
25 |
+
*
|
26 |
+
* MainWP WooCommerce Status Extension handler.
|
27 |
+
*/
|
28 |
+
class MainWP_Child_WooCommerce_Status {
|
29 |
+
|
30 |
+
/**
|
31 |
+
* Public static variable to hold the single instance of the class.
|
32 |
+
*
|
33 |
+
* @var mixed Default null
|
34 |
+
*/
|
35 |
+
public static $instance = null;
|
36 |
+
|
37 |
+
/**
|
38 |
+
* Method instance()
|
39 |
+
*
|
40 |
+
* Create a public static instance.
|
41 |
+
*
|
42 |
+
* @return mixed Class instance.
|
43 |
+
*/
|
44 |
+
public static function instance() {
|
45 |
+
if ( null === self::$instance ) {
|
46 |
+
self::$instance = new self();
|
47 |
+
}
|
48 |
+
|
49 |
+
return self::$instance;
|
50 |
+
}
|
51 |
+
|
52 |
+
/**
|
53 |
+
* MainWP_Child_WooCommerce_Status constructor.
|
54 |
+
*
|
55 |
+
* Run any time class is called.
|
56 |
+
*/
|
57 |
+
public function __construct() {
|
58 |
+
add_action( 'mainwp_child_deactivation', array( $this, 'child_deactivation' ) );
|
59 |
+
}
|
60 |
+
|
61 |
+
/**
|
62 |
+
* MainWP Child Plugin deactivation hooks.
|
63 |
+
*/
|
64 |
+
public function child_deactivation() {
|
65 |
+
}
|
66 |
+
|
67 |
+
/**
|
68 |
+
* MainWP Child Woocommerce actions: sync_data, report_data, update_wc_db.
|
69 |
+
*
|
70 |
+
* @uses \MainWP\Child\MainWP_Helper::write()
|
71 |
+
*/
|
72 |
+
public function action() {
|
73 |
+
$information = array();
|
74 |
+
if ( ! class_exists( '\WooCommerce' ) || ! defined( 'WC_VERSION' ) ) {
|
75 |
+
$information['error'] = 'NO_WOOCOMMERCE';
|
76 |
+
MainWP_Helper::write( $information );
|
77 |
+
}
|
78 |
+
|
79 |
+
$is_ver220 = $this->is_version_220();
|
80 |
+
if ( isset( $_POST['mwp_action'] ) ) {
|
81 |
+
$mwp_action = ! empty( $_POST['mwp_action'] ) ? sanitize_text_field( wp_unslash( $_POST['mwp_action'] ) ) : '';
|
82 |
+
switch ( $mwp_action ) {
|
83 |
+
case 'sync_data':
|
84 |
+
$information = ! $is_ver220 ? $this->sync_data() : $this->sync_data_two();
|
85 |
+
break;
|
86 |
+
case 'report_data':
|
87 |
+
$information = ! $is_ver220 ? $this->report_data() : $this->report_data_two();
|
88 |
+
break;
|
89 |
+
case 'update_wc_db':
|
90 |
+
$information = $this->update_wc_db();
|
91 |
+
break;
|
92 |
+
}
|
93 |
+
}
|
94 |
+
MainWP_Helper::write( $information );
|
95 |
+
}
|
96 |
+
|
97 |
+
/**
|
98 |
+
* Compare woocommerce versions.
|
99 |
+
*
|
100 |
+
* By default, version_compare returns -1 if the first version is lower than the second,
|
101 |
+
* 0 if they are equal, and 1 if the second is lower.
|
102 |
+
* When using the optional operator argument, the function will return true if the relationship is
|
103 |
+
* the one specified by the operator, false otherwise.
|
104 |
+
*
|
105 |
+
* @return bool|int Comparison response.
|
106 |
+
*/
|
107 |
+
public function is_version_220() {
|
108 |
+
return version_compare( WC()->version, '2.2.0', '>=' );
|
109 |
+
}
|
110 |
+
|
111 |
+
/**
|
112 |
+
* Sync Woocommerce data.
|
113 |
+
*
|
114 |
+
* @return array $information Woocommerce data grabed.
|
115 |
+
*/
|
116 |
+
public function sync_data() {
|
117 |
+
|
118 |
+
/**
|
119 |
+
* Object, providing access to the WordPress database.
|
120 |
+
*
|
121 |
+
* @global object $wpdb WordPress Database instance.
|
122 |
+
*/
|
123 |
+
global $wpdb;
|
124 |
+
|
125 |
+
$file = WP_PLUGIN_DIR . '/woocommerce/includes/admin/reports/class-wc-admin-report.php';
|
126 |
+
if ( file_exists( $file ) ) {
|
127 |
+
include_once $file;
|
128 |
+
} else {
|
129 |
+
return false;
|
130 |
+
}
|
131 |
+
|
132 |
+
// Get sales.
|
133 |
+
$sales = $wpdb->get_var(
|
134 |
+
$wpdb->prepare(
|
135 |
+
"SELECT SUM( postmeta.meta_value ) FROM {$wpdb->posts} as posts
|
136 |
+
LEFT JOIN {$wpdb->term_relationships} AS rel ON posts.ID=rel.object_ID
|
137 |
+
LEFT JOIN {$wpdb->term_taxonomy} AS tax USING( term_taxonomy_id )
|
138 |
+
LEFT JOIN {$wpdb->terms} AS term USING( term_id )
|
139 |
+
LEFT JOIN {$wpdb->postmeta} AS postmeta ON posts.ID = postmeta.post_id
|
140 |
+
WHERE posts.post_type = 'shop_order'
|
141 |
+
AND posts.post_status = 'publish'
|
142 |
+
AND tax.taxonomy = 'shop_order_status'
|
143 |
+
AND term.slug IN ( '" . implode( "','", apply_filters( 'woocommerce_reports_order_statuses', array( 'completed', 'processing', 'on-hold' ) ) ) . "' ) " . // phpcs:ignore -- safe query.
|
144 |
+
" AND postmeta.meta_key = '_order_total'
|
145 |
+
AND posts.post_date >= %s
|
146 |
+
AND posts.post_date <= %s",
|
147 |
+
date( 'Y-m-01' ), // phpcs:ignore -- local time.
|
148 |
+
date( 'Y-m-d H:i:s' ) // phpcs:ignore -- local time.
|
149 |
+
)
|
150 |
+
);
|
151 |
+
|
152 |
+
// Get top seller.
|
153 |
+
$top_seller = $wpdb->get_row(
|
154 |
+
$wpdb->prepare( // phpcs:ignore -- safe query.
|
155 |
+
"SELECT SUM( order_item_meta.meta_value ) as qty, order_item_meta_2.meta_value as product_id
|
156 |
+
FROM {$wpdb->posts} as posts
|
157 |
+
LEFT JOIN {$wpdb->term_relationships} AS rel ON posts.ID=rel.object_ID
|
158 |
+
LEFT JOIN {$wpdb->term_taxonomy} AS tax USING( term_taxonomy_id )
|
159 |
+
LEFT JOIN {$wpdb->terms} AS term USING( term_id )
|
160 |
+
LEFT JOIN {$wpdb->prefix}woocommerce_order_items AS order_items ON posts.ID = order_id
|
161 |
+
LEFT JOIN {$wpdb->prefix}woocommerce_order_itemmeta AS order_item_meta ON order_items.order_item_id = order_item_meta.order_item_id
|
162 |
+
LEFT JOIN {$wpdb->prefix}woocommerce_order_itemmeta AS order_item_meta_2 ON order_items.order_item_id = order_item_meta_2.order_item_id
|
163 |
+
WHERE posts.post_type = 'shop_order'
|
164 |
+
AND posts.post_status = 'publish'
|
165 |
+
AND tax.taxonomy = 'shop_order_status'
|
166 |
+
AND term.slug IN ( '" . implode( "','", apply_filters( 'woocommerce_reports_order_statuses', array( 'completed', 'processing', 'on-hold' ) ) ) . "' ) " . // phpcs:ignore -- safe query.
|
167 |
+
" AND order_item_meta.meta_key = '_qty'
|
168 |
+
AND order_item_meta_2.meta_key = '_product_id'
|
169 |
+
AND posts.post_date >= %s
|
170 |
+
AND posts.post_date <= %s
|
171 |
+
GROUP BY product_id
|
172 |
+
ORDER BY qty DESC
|
173 |
+
LIMIT 1",
|
174 |
+
date( 'Y-m-01' ), // phpcs:ignore -- local time.
|
175 |
+
date( 'Y-m-d H:i:s' ) // phpcs:ignore -- local time.
|
176 |
+
)
|
177 |
+
);
|
178 |
+
|
179 |
+
if ( ! empty( $top_seller ) ) {
|
180 |
+
$top_seller->name = get_the_title( $top_seller->product_id );
|
181 |
+
}
|
182 |
+
|
183 |
+
// Counts.
|
184 |
+
$on_hold_count = get_term_by( 'slug', 'on-hold', 'shop_order_status' )->count;
|
185 |
+
$processing_count = get_term_by( 'slug', 'processing', 'shop_order_status' )->count;
|
186 |
+
|
187 |
+
// Get products using a query.
|
188 |
+
$stock = absint( max( get_option( 'woocommerce_notify_low_stock_amount' ), 1 ) );
|
189 |
+
$nostock = absint( max( get_option( 'woocommerce_notify_no_stock_amount' ), 0 ) );
|
190 |
+
|
191 |
+
$query_from = "FROM {$wpdb->posts} as posts INNER JOIN {$wpdb->postmeta} AS postmeta ON posts.ID = postmeta.post_id INNER JOIN {$wpdb->postmeta} AS postmeta2 ON posts.ID = postmeta2.post_id WHERE 1=1 AND posts.post_type IN ('product', 'product_variation') AND posts.post_status = 'publish' AND ( postmeta.meta_key = '_stock' AND CAST(postmeta.meta_value AS SIGNED) <= '{$stock}' AND CAST(postmeta.meta_value AS SIGNED) > '{$nostock}' AND postmeta.meta_value != '' ) AND ( ( postmeta2.meta_key = '_manage_stock' AND postmeta2.meta_value = 'yes' ) OR ( posts.post_type = 'product_variation' ) )";
|
192 |
+
|
193 |
+
$lowinstock_count = absint( $wpdb->get_var( "SELECT COUNT( DISTINCT posts.ID ) {$query_from};" ) ); //phpcs:ignore -- safe query.
|
194 |
+
|
195 |
+
$query_from = "FROM {$wpdb->posts} as posts INNER JOIN {$wpdb->postmeta} AS postmeta ON posts.ID = postmeta.post_id INNER JOIN {$wpdb->postmeta} AS postmeta2 ON posts.ID = postmeta2.post_id WHERE 1=1 AND posts.post_type IN ('product', 'product_variation') AND posts.post_status = 'publish' AND ( postmeta.meta_key = '_stock' AND CAST(postmeta.meta_value AS SIGNED) <= '{$nostock}' AND postmeta.meta_value != '' ) AND ( ( postmeta2.meta_key = '_manage_stock' AND postmeta2.meta_value = 'yes' ) OR ( posts.post_type = 'product_variation' ) )";
|
196 |
+
|
197 |
+
$outofstock_count = absint( $wpdb->get_var( "SELECT COUNT( DISTINCT posts.ID ) {$query_from};" ) ); //phpcs:ignore -- safe query.
|
198 |
+
|
199 |
+
$data = array(
|
200 |
+
'sales' => $sales,
|
201 |
+
'formated_sales' => wc_price( $sales ),
|
202 |
+
'top_seller' => $top_seller,
|
203 |
+
'onhold' => $on_hold_count,
|
204 |
+
'awaiting' => $processing_count,
|
205 |
+
'stock' => $stock,
|
206 |
+
'nostock' => $nostock,
|
207 |
+
'lowstock' => $lowinstock_count,
|
208 |
+
'outstock' => $outofstock_count,
|
209 |
+
);
|
210 |
+
|
211 |
+
$data = apply_filters( 'mainwp_child_woocom_sync_data', $data );
|
212 |
+
|
213 |
+
$information['data'] = $data;
|
214 |
+
|
215 |
+
return $information;
|
216 |
+
}
|
217 |
+
|
218 |
+
/**
|
219 |
+
* Woocommerce report data.
|
220 |
+
*
|
221 |
+
* @return array $information Woocommerce data grabed.
|
222 |
+
*/
|
223 |
+
public function report_data() {
|
224 |
+
|
225 |
+
/**
|
226 |
+
* Object, providing access to the WordPress database.
|
227 |
+
*
|
228 |
+
* @global object $wpdb WordPress Database instance.
|
229 |
+
*/
|
230 |
+
global $wpdb;
|
231 |
+
|
232 |
+
$file = WP_PLUGIN_DIR . '/woocommerce/includes/admin/reports/class-wc-admin-report.php';
|
233 |
+
if ( file_exists( $file ) ) {
|
234 |
+
include_once $file;
|
235 |
+
} else {
|
236 |
+
return false;
|
237 |
+
}
|
238 |
+
|
239 |
+
$start_date = isset( $_POST['start_date'] ) ? sanitize_text_field( wp_unslash( $_POST['start_date'] ) ) : '';
|
240 |
+
$end_date = isset( $_POST['end_date'] ) ? sanitize_text_field( wp_unslash( $_POST['end_date'] ) ) : '';
|
241 |
+
|
242 |
+
$start_date = date( 'Y-m-d H:i:s', $start_date ); // phpcs:ignore -- local time.
|
243 |
+
$end_date = date( 'Y-m-d H:i:s', $end_date ); // phpcs:ignore -- local time.
|
244 |
+
|
245 |
+
// Get sales.
|
246 |
+
$sales = $wpdb->get_var(
|
247 |
+
"SELECT SUM( postmeta.meta_value ) FROM {$wpdb->posts} as posts
|
248 |
+
LEFT JOIN {$wpdb->term_relationships} AS rel ON posts.ID=rel.object_ID
|
249 |
+
LEFT JOIN {$wpdb->term_taxonomy} AS tax USING( term_taxonomy_id )
|
250 |
+
LEFT JOIN {$wpdb->terms} AS term USING( term_id )
|
251 |
+
LEFT JOIN {$wpdb->postmeta} AS postmeta ON posts.ID = postmeta.post_id
|
252 |
+
WHERE posts.post_type = 'shop_order'
|
253 |
+
AND posts.post_status = 'publish'
|
254 |
+
AND tax.taxonomy = 'shop_order_status'
|
255 |
+
AND term.slug IN ( '" . implode( "','", apply_filters( 'woocommerce_reports_order_statuses', array( 'completed', 'processing', 'on-hold' ) ) ) . "' ) " . // phpcs:ignore -- safe query.
|
256 |
+
" AND postmeta.meta_key = '_order_total'
|
257 |
+
AND posts.post_date >= STR_TO_DATE(" . $wpdb->prepare( '%s', $start_date ) . ", '%Y-%m-%d %H:%i:%s')
|
258 |
+
AND posts.post_date <= STR_TO_DATE(" . $wpdb->prepare( '%s', $end_date ) . ", '%Y-%m-%d %H:%i:%s')"
|
259 |
+
);
|
260 |
+
|
261 |
+
// Get top seller.
|
262 |
+
$top_seller = $wpdb->get_row(
|
263 |
+
"SELECT SUM( order_item_meta.meta_value ) as qty, order_item_meta_2.meta_value as product_id
|
264 |
+
FROM {$wpdb->posts} as posts
|
265 |
+
LEFT JOIN {$wpdb->term_relationships} AS rel ON posts.ID=rel.object_ID
|
266 |
+
LEFT JOIN {$wpdb->term_taxonomy} AS tax USING( term_taxonomy_id )
|
267 |
+
LEFT JOIN {$wpdb->terms} AS term USING( term_id )
|
268 |
+
LEFT JOIN {$wpdb->prefix}woocommerce_order_items AS order_items ON posts.ID = order_id
|
269 |
+
LEFT JOIN {$wpdb->prefix}woocommerce_order_itemmeta AS order_item_meta ON order_items.order_item_id = order_item_meta.order_item_id
|
270 |
+
LEFT JOIN {$wpdb->prefix}woocommerce_order_itemmeta AS order_item_meta_2 ON order_items.order_item_id = order_item_meta_2.order_item_id
|
271 |
+
WHERE posts.post_type = 'shop_order'
|
272 |
+
AND posts.post_status = 'publish'
|
273 |
+
AND tax.taxonomy = 'shop_order_status'
|
274 |
+
AND term.slug IN ( '" . implode( "','", apply_filters( 'woocommerce_reports_order_statuses', array( 'completed', 'processing', 'on-hold' ) ) ) . "' ) " . // phpcs:ignore -- safe query.
|
275 |
+
" AND order_item_meta.meta_key = '_qty'
|
276 |
+
AND order_item_meta_2.meta_key = '_product_id'
|
277 |
+
AND posts.post_date >= STR_TO_DATE(" . $wpdb->prepare( '%s', $start_date ) . ", '%Y-%m-%d %H:%i:%s' )
|
278 |
+
AND posts.post_date <= STR_TO_DATE(" . $wpdb->prepare( '%s', $end_date ) . ", '%Y-%m-%d %H:%i:%s' )
|
279 |
+
GROUP BY product_id
|
280 |
+
ORDER BY qty DESC
|
281 |
+
LIMIT 1"
|
282 |
+
);
|
283 |
+
|
284 |
+
if ( ! empty( $top_seller ) ) {
|
285 |
+
$top_seller->name = get_the_title( $top_seller->product_id );
|
286 |
+
}
|
287 |
+
|
288 |
+
// Counts.
|
289 |
+
$on_hold_count = get_term_by( 'slug', 'on-hold', 'shop_order_status' )->count;
|
290 |
+
$processing_count = get_term_by( 'slug', 'processing', 'shop_order_status' )->count;
|
291 |
+
|
292 |
+
// Get products using a query.
|
293 |
+
$stock = absint( max( get_option( 'woocommerce_notify_low_stock_amount' ), 1 ) );
|
294 |
+
$nostock = absint( max( get_option( 'woocommerce_notify_no_stock_amount' ), 0 ) );
|
295 |
+
|
296 |
+
$query_from = "FROM {$wpdb->posts} as posts INNER JOIN {$wpdb->postmeta} AS postmeta ON posts.ID = postmeta.post_id INNER JOIN {$wpdb->postmeta} AS postmeta2 ON posts.ID = postmeta2.post_id WHERE 1=1 AND posts.post_type IN ('product', 'product_variation') AND posts.post_status = 'publish' AND ( postmeta.meta_key = '_stock' AND CAST(postmeta.meta_value AS SIGNED) <= '{$stock}' AND CAST(postmeta.meta_value AS SIGNED) > '{$nostock}' AND postmeta.meta_value != '' ) AND ( ( postmeta2.meta_key = '_manage_stock' AND postmeta2.meta_value = 'yes' ) OR ( posts.post_type = 'product_variation' ) )";
|
297 |
+
|
298 |
+
$lowinstock_count = absint( $wpdb->get_var( "SELECT COUNT( DISTINCT posts.ID ) {$query_from};" ) ); //phpcs:ignore -- safe query.
|
299 |
+
|
300 |
+
$query_from = "FROM {$wpdb->posts} as posts INNER JOIN {$wpdb->postmeta} AS postmeta ON posts.ID = postmeta.post_id INNER JOIN {$wpdb->postmeta} AS postmeta2 ON posts.ID = postmeta2.post_id WHERE 1=1 AND posts.post_type IN ('product', 'product_variation') AND posts.post_status = 'publish' AND ( postmeta.meta_key = '_stock' AND CAST(postmeta.meta_value AS SIGNED) <= '{$nostock}' AND postmeta.meta_value != '' ) AND ( ( postmeta2.meta_key = '_manage_stock' AND postmeta2.meta_value = 'yes' ) OR ( posts.post_type = 'product_variation' ) )";
|
301 |
+
|
302 |
+
$outofstock_count = absint( $wpdb->get_var( "SELECT COUNT( DISTINCT posts.ID ) {$query_from};" ) ); //phpcs:ignore -- safe query.
|
303 |
+
|
304 |
+
$data = array(
|
305 |
+
'sales' => $sales,
|
306 |
+
'formated_sales' => wc_price( $sales ),
|
307 |
+
'top_seller' => $top_seller,
|
308 |
+
'onhold' => $on_hold_count,
|
309 |
+
'awaiting' => $processing_count,
|
310 |
+
'stock' => $stock,
|
311 |
+
'nostock' => $nostock,
|
312 |
+
'lowstock' => $lowinstock_count,
|
313 |
+
'outstock' => $outofstock_count,
|
314 |
+
);
|
315 |
+
|
316 |
+
$data = apply_filters( 'mainwp_child_woocom_report_data', $data );
|
317 |
+
|
318 |
+
$information['data'] = $data;
|
319 |
+
|
320 |
+
return $information;
|
321 |
+
}
|
322 |
+
|
323 |
+
/**
|
324 |
+
* Sync Woocommerce data for current month.
|
325 |
+
*/
|
326 |
+
public function sync_data_two() {
|
327 |
+
$start_date = date( 'Y-m-01 00:00:00', time() ); // phpcs:ignore -- local time.
|
328 |
+
$end_date = date( 'Y-m-d H:i:s', time() ); // phpcs:ignore -- local time.
|
329 |
+
|
330 |
+
$start_date = strtotime( $start_date );
|
331 |
+
$end_date = strtotime( $end_date );
|
332 |
+
|
333 |
+
return $this->get_woocom_data( $start_date, $end_date );
|
334 |
+
}
|
335 |
+
|
336 |
+
/**
|
337 |
+
* Sync Woocomerce data for specific date range.
|
338 |
+
*/
|
339 |
+
public function report_data_two() {
|
340 |
+
$start_date = isset( $_POST['start_date'] ) ? sanitize_text_field( wp_unslash( $_POST['start_date'] ) ) : '';
|
341 |
+
$end_date = isset( $_POST['end_date'] ) ? sanitize_text_field( wp_unslash( $_POST['end_date'] ) ) : '';
|
342 |
+
|
343 |
+
return $this->get_woocom_data( $start_date, $end_date );
|
344 |
+
}
|
345 |
+
|
346 |
+
/**
|
347 |
+
* Check if woocomerce DB needs to be updated.
|
348 |
+
*
|
349 |
+
* @return bool true|false.
|
350 |
+
*/
|
351 |
+
public function check_db_update() {
|
352 |
+
if ( version_compare( get_option( 'woocommerce_db_version' ), WC_VERSION, '<' ) ) {
|
353 |
+
return true;
|
354 |
+
}
|
355 |
+
return false;
|
356 |
+
}
|
357 |
+
|
358 |
+
/**
|
359 |
+
* Get Woocommerce data.
|
360 |
+
*
|
361 |
+
* @param string $start_date Start Date.
|
362 |
+
* @param string $end_date End Date.
|
363 |
+
*
|
364 |
+
* @return array $information Woocommerce data grabed.
|
365 |
+
*/
|
366 |
+
public function get_woocom_data( $start_date, $end_date ) {
|
367 |
+
|
368 |
+
/**
|
369 |
+
* Object, providing access to the WordPress database.
|
370 |
+
*
|
371 |
+
* @global object $wpdb WordPress Database instance.
|
372 |
+
*/
|
373 |
+
global $wpdb;
|
374 |
+
|
375 |
+
$file = WP_PLUGIN_DIR . '/woocommerce/includes/admin/reports/class-wc-admin-report.php';
|
376 |
+
if ( file_exists( $file ) ) {
|
377 |
+
include_once $file;
|
378 |
+
} else {
|
379 |
+
return false;
|
380 |
+
}
|
381 |
+
|
382 |
+
$start_date = date( 'Y-m-d H:i:s', $start_date ); // phpcs:ignore -- local time. Required to achieve desired results, pull request solutions appreciated.
|
383 |
+
$end_date = date( 'Y-m-d H:i:s', $end_date ); // phpcs:ignore -- local time. Required to achieve desired results, pull request solutions appreciated.
|
384 |
+
|
385 |
+
// Sales.
|
386 |
+
$query = array();
|
387 |
+
$query['fields'] = "SELECT SUM( postmeta.meta_value ) FROM {$wpdb->posts} as posts";
|
388 |
+
$query['join'] = "INNER JOIN {$wpdb->postmeta} AS postmeta ON posts.ID = postmeta.post_id ";
|
389 |
+
$query['where'] = "WHERE posts.post_type IN ( '" . implode( "','", wc_get_order_types( 'reports' ) ) . "' ) ";
|
390 |
+
$query['where'] .= "AND posts.post_status IN ( 'wc-" . implode( "','wc-", apply_filters( 'woocommerce_reports_order_statuses', array( 'completed', 'processing', 'on-hold' ) ) ) . "' ) ";
|
391 |
+
$query['where'] .= "AND postmeta.meta_key = '_order_total' ";
|
392 |
+
$query['where'] .= 'AND posts.post_date >= STR_TO_DATE(' . $wpdb->prepare( '%s', $start_date ) . ", '%Y-%m-%d %H:%i:%s' ) ";
|
393 |
+
$query['where'] .= 'AND posts.post_date <= STR_TO_DATE(' . $wpdb->prepare( '%s', $end_date ) . ", '%Y-%m-%d %H:%i:%s' ) ";
|
394 |
+
|
395 |
+
$sales = $wpdb->get_var( implode( ' ', apply_filters( 'woocommerce_dashboard_status_widget_sales_query', $query ) ) ); // phpcs:ignore -- safe query.
|
396 |
+
|
397 |
+
// Get top seller.
|
398 |
+
$query = array();
|
399 |
+
$query['fields'] = "SELECT SUM( order_item_meta.meta_value ) as qty, order_item_meta_2.meta_value as product_id FROM {$wpdb->posts} as posts";
|
400 |
+
$query['join'] = "INNER JOIN {$wpdb->prefix}woocommerce_order_items AS order_items ON posts.ID = order_id ";
|
401 |
+
$query['join'] .= "INNER JOIN {$wpdb->prefix}woocommerce_order_itemmeta AS order_item_meta ON order_items.order_item_id = order_item_meta.order_item_id ";
|
402 |
+
$query['join'] .= "INNER JOIN {$wpdb->prefix}woocommerce_order_itemmeta AS order_item_meta_2 ON order_items.order_item_id = order_item_meta_2.order_item_id ";
|
403 |
+
$query['where'] = "WHERE posts.post_type IN ( '" . implode( "','", wc_get_order_types( 'order-count' ) ) . "' ) ";
|
404 |
+
$query['where'] .= "AND posts.post_status IN ( 'wc-" . implode( "','wc-", apply_filters( 'woocommerce_reports_order_statuses', array( 'completed', 'processing', 'on-hold' ) ) ) . "' ) ";
|
405 |
+
$query['where'] .= "AND order_item_meta.meta_key = '_qty' ";
|
406 |
+
$query['where'] .= "AND order_item_meta_2.meta_key = '_product_id' ";
|
407 |
+
$query['where'] .= 'AND posts.post_date >= STR_TO_DATE(' . $wpdb->prepare( '%s', $start_date ) . ", '%Y-%m-%d %H:%i:%s') ";
|
408 |
+
$query['where'] .= 'AND posts.post_date <= STR_TO_DATE(' . $wpdb->prepare( '%s', $end_date ) . ", '%Y-%m-%d %H:%i:%s') ";
|
409 |
+
$query['groupby'] = 'GROUP BY product_id';
|
410 |
+
$query['orderby'] = 'ORDER BY qty DESC';
|
411 |
+
$query['limits'] = 'LIMIT 1';
|
412 |
+
|
413 |
+
$top_seller = $wpdb->get_row( implode( ' ', $query ) ); // phpcs:ignore -- safe query.
|
414 |
+
|
415 |
+
if ( ! empty( $top_seller ) ) {
|
416 |
+
$top_seller->name = get_the_title( $top_seller->product_id );
|
417 |
+
}
|
418 |
+
|
419 |
+
// Counts.
|
420 |
+
$on_hold_count = 0;
|
421 |
+
$processing_count = 0;
|
422 |
+
|
423 |
+
foreach ( wc_get_order_types( 'order-count' ) as $type ) {
|
424 |
+
$counts = (array) wp_count_posts( $type );
|
425 |
+
$on_hold_count += isset( $counts['wc-on-hold'] ) ? $counts['wc-on-hold'] : 0;
|
426 |
+
$processing_count += isset( $counts['wc-processing'] ) ? $counts['wc-processing'] : 0;
|
427 |
+
}
|
428 |
+
|
429 |
+
// Get products using a query.
|
430 |
+
$stock = absint( max( get_option( 'woocommerce_notify_low_stock_amount' ), 1 ) );
|
431 |
+
$nostock = absint( max( get_option( 'woocommerce_notify_no_stock_amount' ), 0 ) );
|
432 |
+
|
433 |
+
$query_from = "FROM {$wpdb->posts} as posts INNER JOIN {$wpdb->postmeta} AS postmeta ON posts.ID = postmeta.post_id INNER JOIN {$wpdb->postmeta} AS postmeta2 ON posts.ID = postmeta2.post_id WHERE 1=1 AND posts.post_type IN ('product', 'product_variation') AND posts.post_status = 'publish' AND ( postmeta.meta_key = '_stock' AND CAST(postmeta.meta_value AS SIGNED) <= '{$stock}' AND CAST(postmeta.meta_value AS SIGNED) > '{$nostock}' AND postmeta.meta_value != '' ) AND ( ( postmeta2.meta_key = '_manage_stock' AND postmeta2.meta_value = 'yes' ) OR ( posts.post_type = 'product_variation' ) )";
|
434 |
+
|
435 |
+
$lowinstock_count = absint( $wpdb->get_var( "SELECT COUNT( DISTINCT posts.ID ) {$query_from};" ) ); //phpcs:ignore -- safe query.
|
436 |
+
|
437 |
+
$query_from = "FROM {$wpdb->posts} as posts INNER JOIN {$wpdb->postmeta} AS postmeta ON posts.ID = postmeta.post_id INNER JOIN {$wpdb->postmeta} AS postmeta2 ON posts.ID = postmeta2.post_id WHERE 1=1 AND posts.post_type IN ('product', 'product_variation') AND posts.post_status = 'publish' AND ( postmeta.meta_key = '_stock' AND CAST(postmeta.meta_value AS SIGNED) <= '{$nostock}' AND postmeta.meta_value != '' ) AND ( ( postmeta2.meta_key = '_manage_stock' AND postmeta2.meta_value = 'yes' ) OR ( posts.post_type = 'product_variation' ) ) ";
|
438 |
+
|
439 |
+
$outofstock_count = absint( $wpdb->get_var( "SELECT COUNT( DISTINCT posts.ID ) {$query_from};" ) ); //phpcs:ignore -- safe query.
|
440 |
+
|
441 |
+
$data = array(
|
442 |
+
'sales' => $sales,
|
443 |
+
'formated_sales' => wc_price( $sales ),
|
444 |
+
'top_seller' => $top_seller,
|
445 |
+
'onhold' => $on_hold_count,
|
446 |
+
'awaiting' => $processing_count,
|
447 |
+
'stock' => $stock,
|
448 |
+
'nostock' => $nostock,
|
449 |
+
'lowstock' => $lowinstock_count,
|
450 |
+
'outstock' => $outofstock_count,
|
451 |
+
);
|
452 |
+
|
453 |
+
$data = apply_filters( 'mainwp_child_woocom_get_data', $data );
|
454 |
+
|
455 |
+
$information['data'] = $data;
|
456 |
+
$information['need_db_update'] = $this->check_db_update();
|
457 |
+
return $information;
|
458 |
+
}
|
459 |
+
|
460 |
+
/**
|
461 |
+
* Update Woocommerce Database.
|
462 |
+
*
|
463 |
+
* @return string[] Success.
|
464 |
+
*/
|
465 |
+
private static function update_wc_db() {
|
466 |
+
include_once WC()->plugin_path() . '/includes/class-wc-background-updater.php';
|
467 |
+
$background_updater = new \WC_Background_Updater();
|
468 |
+
|
469 |
+
$current_db_version = get_option( 'woocommerce_db_version' );
|
470 |
+
$logger = wc_get_logger();
|
471 |
+
$update_queued = false;
|
472 |
+
|
473 |
+
foreach ( \WC_Install::get_db_update_callbacks() as $version => $update_callbacks ) {
|
474 |
+
if ( version_compare( $current_db_version, $version, '<' ) ) {
|
475 |
+
foreach ( $update_callbacks as $update_callback ) {
|
476 |
+
$logger->info(
|
477 |
+
sprintf( 'Queuing %s - %s', $version, $update_callback ),
|
478 |
+
array( 'source' => 'wc_db_updates' )
|
479 |
+
);
|
480 |
+
$background_updater->push_to_queue( $update_callback );
|
481 |
+
$update_queued = true;
|
482 |
+
}
|
483 |
+
}
|
484 |
+
}
|
485 |
+
|
486 |
+
if ( $update_queued ) {
|
487 |
+
$background_updater->save()->dispatch();
|
488 |
+
}
|
489 |
+
|
490 |
+
return array( 'result' => 'success' );
|
491 |
+
}
|
492 |
+
|
493 |
+
}
|
class/class-mainwp-child-wordfence.php
CHANGED
@@ -1,4023 +1,4020 @@
|
|
1 |
-
<?php
|
2 |
-
/**
|
3 |
-
* MainWP Wordfence
|
4 |
-
*
|
5 |
-
* MainWP Wordfence extension handler.
|
6 |
-
*
|
7 |
-
* @link https://mainwp.com/extension/wordfence/
|
8 |
-
* @package MainWP\Child
|
9 |
-
*
|
10 |
-
* Credits
|
11 |
-
*
|
12 |
-
* Plugin-Name: Wordfence Security
|
13 |
-
* Plugin-URI: https://www.wordfence.com/
|
14 |
-
* Author: Wordfence
|
15 |
-
* Author URI: https://www.wordfence.com/
|
16 |
-
*/
|
17 |
-
|
18 |
-
namespace MainWP\Child;
|
19 |
-
|
20 |
-
// phpcs:disable PSR1.Classes.ClassDeclaration, WordPress.WP.AlternativeFunctions -- Required to achieve desired results, pull request solutions appreciated.
|
21 |
-
|
22 |
-
/**
|
23 |
-
* Class MainWP_Child_Wordfence
|
24 |
-
*
|
25 |
-
* MainWP Wordfence extension handler.
|
26 |
-
*/
|
27 |
-
class MainWP_Child_Wordfence {
|
28 |
-
|
29 |
-
/**
|
30 |
-
* Public static variable to hold the single instance of the class.
|
31 |
-
*
|
32 |
-
* @var mixed Default null
|
33 |
-
*/
|
34 |
-
public static $instance = null;
|
35 |
-
|
36 |
-
/**
|
37 |
-
* Public variable to hold the information if the Wordfence plugin is installed on the child site.
|
38 |
-
*
|
39 |
-
* @var bool If Wordfence intalled, return true, if not, return false.
|
40 |
-
*/
|
41 |
-
public $is_wordfence_installed = false;
|
42 |
-
|
43 |
-
/**
|
44 |
-
* Public variable to hold the information about the language domain.
|
45 |
-
*
|
46 |
-
* @var string 'mainwp-child' languge domain.
|
47 |
-
*/
|
48 |
-
public $plugin_translate = 'mainwp-child';
|
49 |
-
|
50 |
-
const OPTIONS_TYPE_GLOBAL = 'global';
|
51 |
-
const OPTIONS_TYPE_FIREWALL = 'firewall';
|
52 |
-
const OPTIONS_TYPE_BLOCKING = 'blocking';
|
53 |
-
const OPTIONS_TYPE_SCANNER = 'scanner';
|
54 |
-
const OPTIONS_TYPE_TWO_FACTOR = 'twofactor';
|
55 |
-
const OPTIONS_TYPE_LIVE_TRAFFIC = 'livetraffic';
|
56 |
-
const OPTIONS_TYPE_COMMENT_SPAM = 'commentspam';
|
57 |
-
const OPTIONS_TYPE_DIAGNOSTICS = 'diagnostics';
|
58 |
-
const OPTIONS_TYPE_ALL = 'alloptions';
|
59 |
-
|
60 |
-
/**
|
61 |
-
* Public static variable to hold the information about Wordfence options.
|
62 |
-
*
|
63 |
-
* @var array Supported Wordfence options.
|
64 |
-
*/
|
65 |
-
public static $options_filter = array(
|
66 |
-
'alertEmails',
|
67 |
-
'displayTopLevelOptions',
|
68 |
-
'displayTopLevelBlocking',
|
69 |
-
'displayTopLevelLiveTraffic',
|
70 |
-
'alertOn_adminLogin',
|
71 |
-
'alertOn_firstAdminLoginOnly',
|
72 |
-
'alertOn_scanIssues', // new.
|
73 |
-
'alertOn_wafDeactivated', // new.
|
74 |
-
'alertOn_severityLevel', // new.
|
75 |
-
'alertOn_loginLockout',
|
76 |
-
'alertOn_breachLogin',
|
77 |
-
'alertOn_lostPasswdForm',
|
78 |
-
'alertOn_nonAdminLogin',
|
79 |
-
'alertOn_firstNonAdminLoginOnly',
|
80 |
-
'alertOn_wordfenceDeactivated',
|
81 |
-
'alertOn_update',
|
82 |
-
'alertOn_block',
|
83 |
-
'alert_maxHourly',
|
84 |
-
'autoUpdate',
|
85 |
-
'firewallEnabled',
|
86 |
-
'howGetIPs',
|
87 |
-
'liveTrafficEnabled',
|
88 |
-
'loginSec_blockAdminReg',
|
89 |
-
'loginSec_countFailMins',
|
90 |
-
'loginSec_disableAuthorScan',
|
91 |
-
'notification_updatesNeeded',
|
92 |
-
'notification_securityAlerts',
|
93 |
-
'notification_promotions',
|
94 |
-
'notification_blogHighlights',
|
95 |
-
'notification_productUpdates',
|
96 |
-
'notification_scanStatus',
|
97 |
-
'loginSec_lockInvalidUsers',
|
98 |
-
'loginSec_breachPasswds_enabled',
|
99 |
-
'loginSec_breachPasswds',
|
100 |
-
'loginSec_lockoutMins',
|
101 |
-
'loginSec_maskLoginErrors',
|
102 |
-
'loginSec_maxFailures',
|
103 |
-
'loginSec_maxForgotPasswd',
|
104 |
-
'loginSec_strongPasswds_enabled',
|
105 |
-
'loginSec_strongPasswds',
|
106 |
-
'loginSec_userBlacklist',
|
107 |
-
'loginSecurityEnabled',
|
108 |
-
'other_scanOutside',
|
109 |
-
'scan_exclude',
|
110 |
-
'scan_maxIssues',
|
111 |
-
'scan_maxDuration',
|
112 |
-
'scansEnabled_checkReadableConfig',
|
113 |
-
'scansEnabled_suspectedFiles',
|
114 |
-
'scansEnabled_comments',
|
115 |
-
'scansEnabled_core',
|
116 |
-
'scansEnabled_diskSpace',
|
117 |
-
'scansEnabled_dns',
|
118 |
-
'scansEnabled_fileContents',
|
119 |
-
'scansEnabled_fileContentsGSB',
|
120 |
-
'scan_include_extra',
|
121 |
-
'scansEnabled_checkHowGetIPs',
|
122 |
-
'scansEnabled_highSense',
|
123 |
-
'lowResourceScansEnabled',
|
124 |
-
'scansEnabled_malware',
|
125 |
-
'scansEnabled_oldVersions',
|
126 |
-
'scansEnabled_suspiciousAdminUsers',
|
127 |
-
'scansEnabled_passwds',
|
128 |
-
'scansEnabled_plugins',
|
129 |
-
'scansEnabled_coreUnknown',
|
130 |
-
'scansEnabled_posts',
|
131 |
-
'scansEnabled_scanImages',
|
132 |
-
'scansEnabled_themes',
|
133 |
-
'scheduledScansEnabled',
|
134 |
-
'securityLevel',
|
135 |
-
'neverBlockBG',
|
136 |
-
'maxGlobalRequests',
|
137 |
-
'maxGlobalRequests_action',
|
138 |
-
'maxRequestsCrawlers',
|
139 |
-
'maxRequestsCrawlers_action',
|
140 |
-
'max404Crawlers',
|
141 |
-
'max404Crawlers_action',
|
142 |
-
'maxRequestsHumans',
|
143 |
-
'maxRequestsHumans_action',
|
144 |
-
'max404Humans',
|
145 |
-
'max404Humans_action',
|
146 |
-
'blockedTime',
|
147 |
-
'liveTraf_ignorePublishers',
|
148 |
-
'liveTraf_displayExpandedRecords',
|
149 |
-
'liveTraf_ignoreUsers',
|
150 |
-
'liveTraf_ignoreIPs',
|
151 |
-
'liveTraf_ignoreUA',
|
152 |
-
'liveTraf_maxRows',
|
153 |
-
'liveTraf_maxAge',
|
154 |
-
'displayTopLevelLiveTraffic',
|
155 |
-
'whitelisted',
|
156 |
-
'bannedURLs',
|
157 |
-
'other_hideWPVersion',
|
158 |
-
'other_noAnonMemberComments',
|
159 |
-
'other_scanComments',
|
160 |
-
'other_pwStrengthOnUpdate',
|
161 |
-
'other_WFNet',
|
162 |
-
'maxMem',
|
163 |
-
'maxExecutionTime',
|
164 |
-
'actUpdateInterval',
|
165 |
-
'debugOn',
|
166 |
-
'deleteTablesOnDeact',
|
167 |
-
'liveActivityPauseEnabled',
|
168 |
-
'startScansRemotely',
|
169 |
-
'disableCodeExecutionUploads',
|
170 |
-
'scansEnabled_checkGSB',
|
171 |
-
'checkSpamIP',
|
172 |
-
'spamvertizeCheck',
|
173 |
-
'email_summary_enabled',
|
174 |
-
'email_summary_dashboard_widget_enabled',
|
175 |
-
'ssl_verify',
|
176 |
-
'email_summary_interval',
|
177 |
-
'email_summary_excluded_directories',
|
178 |
-
'allowed404s',
|
179 |
-
'wafAlertWhitelist',
|
180 |
-
'wafAlertOnAttacks',
|
181 |
-
'howGetIPs_trusted_proxies',
|
182 |
-
'other_bypassLitespeedNoabort',
|
183 |
-
'disableWAFIPBlocking',
|
184 |
-
'other_blockBadPOST',
|
185 |
-
'blockCustomText',
|
186 |
-
'displayTopLevelBlocking',
|
187 |
-
'betaThreatDefenseFeed',
|
188 |
-
'wordfenceI18n',
|
189 |
-
'avoid_php_input',
|
190 |
-
'scanType',
|
191 |
-
'schedMode',
|
192 |
-
'wafStatus',
|
193 |
-
'learningModeGracePeriodEnabled',
|
194 |
-
'learningModeGracePeriod',
|
195 |
-
);
|
196 |
-
|
197 |
-
/**
|
198 |
-
* Public static variable to hold the information about Wordfence diagnostic parameters.
|
199 |
-
*
|
200 |
-
* @var array Supported diagnostic parameters.
|
201 |
-
*/
|
202 |
-
public static $diagnosticParams = array(
|
203 |
-
'debugOn',
|
204 |
-
'startScansRemotely',
|
205 |
-
'ssl_verify',
|
206 |
-
'betaThreatDefenseFeed',
|
207 |
-
'wordfenceI18n',
|
208 |
-
'avoid_php_input',
|
209 |
-
);
|
210 |
-
|
211 |
-
/**
|
212 |
-
* Public static variable to hold the information about Wordfence firewall options.
|
213 |
-
*
|
214 |
-
* @var array Supported firewall options.
|
215 |
-
*/
|
216 |
-
public static $firewall_options_filter = array(
|
217 |
-
'wafStatus',
|
218 |
-
'learningModeGracePeriodEnabled',
|
219 |
-
'learningModeGracePeriod',
|
220 |
-
);
|
221 |
-
|
222 |
-
/**
|
223 |
-
* Method instance()
|
224 |
-
*
|
225 |
-
* Create a public static instance.
|
226 |
-
*
|
227 |
-
* @return mixed Class instance.
|
228 |
-
*/
|
229 |
-
public static function instance() {
|
230 |
-
if ( null === self::$instance ) {
|
231 |
-
self::$instance = new self();
|
232 |
-
}
|
233 |
-
|
234 |
-
return self::$instance;
|
235 |
-
}
|
236 |
-
|
237 |
-
/**
|
238 |
-
* MainWP_Child_Wordfence constructor.
|
239 |
-
*
|
240 |
-
* Run any time class is called.
|
241 |
-
*/
|
242 |
-
public function __construct() {
|
243 |
-
add_action( 'mainwp_child_deactivation', array( $this, 'deactivation' ) );
|
244 |
-
|
245 |
-
require_once ABSPATH . 'wp-admin/includes/plugin.php';
|
246 |
-
|
247 |
-
if ( is_plugin_active( 'wordfence/wordfence.php' ) && file_exists( plugin_dir_path( __FILE__ ) . '../../wordfence/wordfence.php' ) ) {
|
248 |
-
require_once plugin_dir_path( __FILE__ ) . '../../wordfence/wordfence.php';
|
249 |
-
$this->is_wordfence_installed = true;
|
250 |
-
}
|
251 |
-
|
252 |
-
if ( $this->is_wordfence_installed ) {
|
253 |
-
add_action( 'wp_ajax_mainwp_wordfence_download_htaccess', array( $this, 'download_htaccess' ) );
|
254 |
-
}
|
255 |
-
}
|
256 |
-
|
257 |
-
/**
|
258 |
-
* Method wordfence_init()
|
259 |
-
*
|
260 |
-
* Initiate action hooks.
|
261 |
-
*
|
262 |
-
* @return void
|
263 |
-
*/
|
264 |
-
public function wordfence_init() {
|
265 |
-
if ( ! $this->is_wordfence_installed ) {
|
266 |
-
return;
|
267 |
-
}
|
268 |
-
add_action( 'mainwp_child_site_stats', array( $this, 'do_site_stats' ) );
|
269 |
-
if ( 'hide' === get_option( 'mainwp_wordfence_hide_plugin' ) ) {
|
270 |
-
add_filter( 'all_plugins', array( $this, 'all_plugins' ) );
|
271 |
-
add_action( 'admin_menu', array( $this, 'remove_menu' ) );
|
272 |
-
add_action( 'admin_init', array( $this, 'admin_init' ) );
|
273 |
-
}
|
274 |
-
$this->init_cron();
|
275 |
-
}
|
276 |
-
|
277 |
-
/**
|
278 |
-
* Method admin_init()
|
279 |
-
*
|
280 |
-
* Remove remove the Wordfence meta-box (widget) when 'admin_init' action fires.
|
281 |
-
*/
|
282 |
-
public function admin_init() {
|
283 |
-
remove_meta_box( 'wordfence_activity_report_widget', 'dashboard', 'normal' );
|
284 |
-
}
|
285 |
-
|
286 |
-
/**
|
287 |
-
* Method do_site_stats()
|
288 |
-
*
|
289 |
-
* Add support for the reporting system.
|
290 |
-
*/
|
291 |
-
public function do_site_stats() {
|
292 |
-
do_action( 'mainwp_child_reports_log', 'wordfence' );
|
293 |
-
}
|
294 |
-
|
295 |
-
/**
|
296 |
-
* Method do_reports_log()
|
297 |
-
*
|
298 |
-
* Add Wordfence data to the reports reports database table.
|
299 |
-
*
|
300 |
-
* @param string $ext Current extension.
|
301 |
-
*
|
302 |
-
* @uses \MainWP\Child\MainWP_Child_DB::to_query()
|
303 |
-
* @uses \MainWP\Child\MainWP_Child_DB::fetch_array()
|
304 |
-
*/
|
305 |
-
public function do_reports_log( $ext = '' ) {
|
306 |
-
if ( 'wordfence' !== $ext ) {
|
307 |
-
return;
|
308 |
-
}
|
309 |
-
if ( ! $this->is_wordfence_installed ) {
|
310 |
-
return;
|
311 |
-
}
|
312 |
-
|
313 |
-
/**
|
314 |
-
* Object, providing access to the WordPress database.
|
315 |
-
*
|
316 |
-
* @global object $wpdb WordPress Database instance.
|
317 |
-
*/
|
318 |
-
global $wpdb;
|
319 |
-
|
320 |
-
$lastcheck = get_option( 'mainwp_wordfence_lastcheck_scan' );
|
321 |
-
if ( false == $lastcheck ) {
|
322 |
-
$lastcheck = time() - 3600 * 24 * 10;
|
323 |
-
}
|
324 |
-
|
325 |
-
$
|
326 |
-
|
327 |
-
|
328 |
-
$table_wfStatus =
|
329 |
-
|
330 |
-
|
331 |
-
|
332 |
-
$
|
333 |
-
|
334 |
-
|
335 |
-
|
336 |
-
|
337 |
-
|
338 |
-
|
339 |
-
|
340 |
-
|
341 |
-
|
342 |
-
|
343 |
-
|
344 |
-
|
345 |
-
$
|
346 |
-
$
|
347 |
-
|
348 |
-
|
349 |
-
|
350 |
-
|
351 |
-
|
352 |
-
|
353 |
-
|
354 |
-
|
355 |
-
|
356 |
-
|
357 |
-
|
358 |
-
|
359 |
-
|
360 |
-
|
361 |
-
|
362 |
-
|
363 |
-
|
364 |
-
*
|
365 |
-
*
|
366 |
-
*
|
367 |
-
|
368 |
-
|
369 |
-
|
370 |
-
|
371 |
-
|
372 |
-
|
373 |
-
|
374 |
-
|
375 |
-
|
376 |
-
|
377 |
-
|
378 |
-
|
379 |
-
|
380 |
-
|
381 |
-
|
382 |
-
|
383 |
-
|
384 |
-
|
385 |
-
|
386 |
-
|
387 |
-
|
388 |
-
|
389 |
-
|
390 |
-
|
391 |
-
|
392 |
-
|
393 |
-
|
394 |
-
|
395 |
-
|
396 |
-
|
397 |
-
|
398 |
-
|
399 |
-
|
400 |
-
*
|
401 |
-
*
|
402 |
-
|
403 |
-
|
404 |
-
|
405 |
-
|
406 |
-
|
407 |
-
|
408 |
-
|
409 |
-
|
410 |
-
|
411 |
-
|
412 |
-
|
413 |
-
|
414 |
-
*
|
415 |
-
*
|
416 |
-
*
|
417 |
-
*
|
418 |
-
|
419 |
-
|
420 |
-
|
421 |
-
|
422 |
-
|
423 |
-
|
424 |
-
|
425 |
-
|
426 |
-
|
427 |
-
|
428 |
-
|
429 |
-
|
430 |
-
|
431 |
-
|
432 |
-
|
433 |
-
|
434 |
-
|
435 |
-
|
436 |
-
|
437 |
-
|
438 |
-
|
439 |
-
|
440 |
-
|
441 |
-
|
442 |
-
|
443 |
-
|
444 |
-
|
445 |
-
|
446 |
-
|
447 |
-
|
448 |
-
|
449 |
-
|
450 |
-
|
451 |
-
|
452 |
-
|
453 |
-
|
454 |
-
|
455 |
-
*
|
456 |
-
*
|
457 |
-
*
|
458 |
-
*
|
459 |
-
* @
|
460 |
-
* @
|
461 |
-
*
|
462 |
-
* @uses \MainWP\Child\MainWP_Child_Wordfence::
|
463 |
-
* @uses \MainWP\Child\MainWP_Child_Wordfence::
|
464 |
-
* @uses \MainWP\Child\MainWP_Child_Wordfence::
|
465 |
-
* @uses \MainWP\Child\MainWP_Child_Wordfence::
|
466 |
-
* @uses \MainWP\Child\MainWP_Child_Wordfence::
|
467 |
-
* @uses \MainWP\Child\MainWP_Child_Wordfence::
|
468 |
-
* @uses \MainWP\Child\MainWP_Child_Wordfence::
|
469 |
-
* @uses \MainWP\Child\MainWP_Child_Wordfence::
|
470 |
-
* @uses \MainWP\Child\MainWP_Child_Wordfence::
|
471 |
-
* @uses \MainWP\Child\MainWP_Child_Wordfence::
|
472 |
-
* @uses \MainWP\Child\MainWP_Child_Wordfence::
|
473 |
-
* @uses \MainWP\Child\MainWP_Child_Wordfence::
|
474 |
-
* @uses \MainWP\Child\MainWP_Child_Wordfence::
|
475 |
-
* @uses \MainWP\Child\MainWP_Child_Wordfence::
|
476 |
-
* @uses \MainWP\Child\MainWP_Child_Wordfence::
|
477 |
-
* @uses \MainWP\Child\MainWP_Child_Wordfence::
|
478 |
-
* @uses \MainWP\Child\MainWP_Child_Wordfence::
|
479 |
-
* @uses \MainWP\Child\MainWP_Child_Wordfence::
|
480 |
-
* @uses \MainWP\Child\MainWP_Child_Wordfence::
|
481 |
-
* @uses \MainWP\Child\MainWP_Child_Wordfence::
|
482 |
-
* @uses \MainWP\Child\MainWP_Child_Wordfence::
|
483 |
-
* @uses \MainWP\Child\MainWP_Child_Wordfence::
|
484 |
-
* @uses \MainWP\Child\MainWP_Child_Wordfence::
|
485 |
-
* @uses \MainWP\Child\MainWP_Child_Wordfence::
|
486 |
-
* @uses \MainWP\Child\MainWP_Child_Wordfence::
|
487 |
-
* @uses \MainWP\Child\MainWP_Child_Wordfence::
|
488 |
-
* @uses \MainWP\Child\MainWP_Child_Wordfence::
|
489 |
-
* @uses \MainWP\Child\MainWP_Child_Wordfence::
|
490 |
-
* @uses \MainWP\Child\MainWP_Child_Wordfence::
|
491 |
-
* @uses \MainWP\Child\MainWP_Child_Wordfence::
|
492 |
-
* @uses \MainWP\Child\MainWP_Child_Wordfence::
|
493 |
-
* @uses \MainWP\Child\MainWP_Child_Wordfence::
|
494 |
-
* @uses \MainWP\Child\MainWP_Child_Wordfence::
|
495 |
-
* @uses \MainWP\Child\MainWP_Child_Wordfence::
|
496 |
-
* @uses \MainWP\Child\MainWP_Child_Wordfence::
|
497 |
-
* @uses \MainWP\Child\MainWP_Child_Wordfence::
|
498 |
-
* @uses \MainWP\Child\MainWP_Child_Wordfence::
|
499 |
-
* @uses \MainWP\Child\MainWP_Child_Wordfence::
|
500 |
-
* @uses \MainWP\Child\MainWP_Child_Wordfence::
|
501 |
-
* @uses \MainWP\Child\MainWP_Child_Wordfence::
|
502 |
-
* @uses \MainWP\Child\MainWP_Child_Wordfence::
|
503 |
-
* @uses \MainWP\Child\MainWP_Child_Wordfence::
|
504 |
-
* @uses \MainWP\Child\MainWP_Child_Wordfence::
|
505 |
-
* @uses \MainWP\Child\MainWP_Child_Wordfence::
|
506 |
-
* @uses \MainWP\Child\MainWP_Child_Wordfence::
|
507 |
-
* @uses \MainWP\Child\MainWP_Child_Wordfence::
|
508 |
-
* @uses \MainWP\Child\MainWP_Child_Wordfence::
|
509 |
-
* @uses \MainWP\Child\MainWP_Child_Wordfence::
|
510 |
-
* @uses \MainWP\Child\MainWP_Child_Wordfence::
|
511 |
-
* @uses \MainWP\Child\MainWP_Child_Wordfence::
|
512 |
-
* @uses \MainWP\Child\MainWP_Child_Wordfence::
|
513 |
-
* @uses \MainWP\Child\MainWP_Child_Wordfence::
|
514 |
-
* @uses \MainWP\Child\MainWP_Child_Wordfence::
|
515 |
-
* @uses \MainWP\Child\MainWP_Child_Wordfence::
|
516 |
-
* @uses \MainWP\Child\MainWP_Child_Wordfence::
|
517 |
-
* @uses \MainWP\Child\MainWP_Child_Wordfence::
|
518 |
-
* @uses \MainWP\Child\MainWP_Child_Wordfence::
|
519 |
-
* @uses \MainWP\Child\MainWP_Child_Wordfence::
|
520 |
-
* @uses \MainWP\Child\MainWP_Child_Wordfence::
|
521 |
-
* @uses \MainWP\Child\MainWP_Child_Wordfence::
|
522 |
-
* @uses \MainWP\Child\MainWP_Child_Wordfence::
|
523 |
-
* @uses \MainWP\Child\MainWP_Child_Wordfence::
|
524 |
-
* @uses \MainWP\Child\MainWP_Child_Wordfence::
|
525 |
-
* @uses \MainWP\Child\MainWP_Child_Wordfence::
|
526 |
-
* @uses \MainWP\Child\MainWP_Child_Wordfence::
|
527 |
-
* @uses \MainWP\Child\MainWP_Child_Wordfence::
|
528 |
-
* @uses \MainWP\Child\
|
529 |
-
|
530 |
-
|
531 |
-
|
532 |
-
|
533 |
-
|
534 |
-
|
535 |
-
|
536 |
-
|
537 |
-
|
538 |
-
|
539 |
-
|
540 |
-
|
541 |
-
|
542 |
-
|
543 |
-
|
544 |
-
|
545 |
-
|
546 |
-
|
547 |
-
|
548 |
-
case '
|
549 |
-
$information = $this->
|
550 |
-
break;
|
551 |
-
case '
|
552 |
-
$information = $this->
|
553 |
-
break;
|
554 |
-
case '
|
555 |
-
$information = $this->
|
556 |
-
break;
|
557 |
-
case '
|
558 |
-
$information = $this->
|
559 |
-
break;
|
560 |
-
case '
|
561 |
-
$information = $this->
|
562 |
-
break;
|
563 |
-
case '
|
564 |
-
$information = $this->
|
565 |
-
break;
|
566 |
-
case '
|
567 |
-
$information = $this->
|
568 |
-
break;
|
569 |
-
case '
|
570 |
-
$information = $this->
|
571 |
-
break;
|
572 |
-
case '
|
573 |
-
$information = $this->
|
574 |
-
break;
|
575 |
-
case '
|
576 |
-
$information = $this->
|
577 |
-
break;
|
578 |
-
case '
|
579 |
-
$information = $this->
|
580 |
-
break;
|
581 |
-
case '
|
582 |
-
$information = $this->
|
583 |
-
break;
|
584 |
-
case '
|
585 |
-
$information = $this->
|
586 |
-
break;
|
587 |
-
case '
|
588 |
-
$information = $this->
|
589 |
-
break;
|
590 |
-
case '
|
591 |
-
$information = $this->
|
592 |
-
break;
|
593 |
-
case '
|
594 |
-
$information = $this->
|
595 |
-
break;
|
596 |
-
case '
|
597 |
-
$information = $this->
|
598 |
-
break;
|
599 |
-
case '
|
600 |
-
$information = $this->
|
601 |
-
break;
|
602 |
-
case '
|
603 |
-
$information = $this->
|
604 |
-
break;
|
605 |
-
case '
|
606 |
-
$information = $this->
|
607 |
-
break;
|
608 |
-
case '
|
609 |
-
$information = $this->
|
610 |
-
break;
|
611 |
-
case '
|
612 |
-
$information = $this->
|
613 |
-
break;
|
614 |
-
case '
|
615 |
-
$information = $this->
|
616 |
-
break;
|
617 |
-
case '
|
618 |
-
$information = $this->
|
619 |
-
break;
|
620 |
-
case '
|
621 |
-
$information = $this->
|
622 |
-
break;
|
623 |
-
case '
|
624 |
-
$information = $this->
|
625 |
-
break;
|
626 |
-
case '
|
627 |
-
$information = $this->
|
628 |
-
break;
|
629 |
-
case '
|
630 |
-
$information = $this->
|
631 |
-
break;
|
632 |
-
case '
|
633 |
-
$information = $this->
|
634 |
-
break;
|
635 |
-
case '
|
636 |
-
$information = $this->
|
637 |
-
break;
|
638 |
-
case '
|
639 |
-
$information = $this->
|
640 |
-
break;
|
641 |
-
case '
|
642 |
-
$information = $this->
|
643 |
-
break;
|
644 |
-
case '
|
645 |
-
$information = $this->
|
646 |
-
break;
|
647 |
-
case '
|
648 |
-
$information = $this->
|
649 |
-
break;
|
650 |
-
case '
|
651 |
-
$information = $this->
|
652 |
-
break;
|
653 |
-
case '
|
654 |
-
$information =
|
655 |
-
break;
|
656 |
-
case '
|
657 |
-
$information =
|
658 |
-
break;
|
659 |
-
case '
|
660 |
-
$information = $this->
|
661 |
-
break;
|
662 |
-
case '
|
663 |
-
$information = $this->
|
664 |
-
break;
|
665 |
-
case '
|
666 |
-
$information = $this->
|
667 |
-
break;
|
668 |
-
case '
|
669 |
-
$information = $this->
|
670 |
-
break;
|
671 |
-
case '
|
672 |
-
$information = $this->
|
673 |
-
break;
|
674 |
-
case '
|
675 |
-
$information = $this->
|
676 |
-
break;
|
677 |
-
case '
|
678 |
-
$information = $this->
|
679 |
-
break;
|
680 |
-
case '
|
681 |
-
$information = $this->
|
682 |
-
break;
|
683 |
-
case '
|
684 |
-
$information = $this->
|
685 |
-
break;
|
686 |
-
case '
|
687 |
-
$information = $this->
|
688 |
-
break;
|
689 |
-
case '
|
690 |
-
$information = $this->
|
691 |
-
break;
|
692 |
-
case '
|
693 |
-
$information = $this->
|
694 |
-
break;
|
695 |
-
case '
|
696 |
-
$information = $this->
|
697 |
-
break;
|
698 |
-
case '
|
699 |
-
$information = $this->
|
700 |
-
break;
|
701 |
-
case '
|
702 |
-
$information = $this->
|
703 |
-
break;
|
704 |
-
case '
|
705 |
-
$information = $this->
|
706 |
-
break;
|
707 |
-
case '
|
708 |
-
$information = $this->
|
709 |
-
break;
|
710 |
-
case '
|
711 |
-
$information = $this->
|
712 |
-
break;
|
713 |
-
case '
|
714 |
-
$information = $this->
|
715 |
-
break;
|
716 |
-
case '
|
717 |
-
$information = $this->
|
718 |
-
break;
|
719 |
-
case '
|
720 |
-
$information = $this->
|
721 |
-
break;
|
722 |
-
case '
|
723 |
-
$information = $this->
|
724 |
-
break;
|
725 |
-
case '
|
726 |
-
$information = $this->
|
727 |
-
break;
|
728 |
-
case '
|
729 |
-
$information = $this->
|
730 |
-
break;
|
731 |
-
case '
|
732 |
-
$information = $this->
|
733 |
-
break;
|
734 |
-
case '
|
735 |
-
$information = $this->
|
736 |
-
break;
|
737 |
-
case '
|
738 |
-
$information = $this->
|
739 |
-
break;
|
740 |
-
case '
|
741 |
-
$information = $this->
|
742 |
-
break;
|
743 |
-
case '
|
744 |
-
$information = $this->
|
745 |
-
break;
|
746 |
-
case '
|
747 |
-
$information = $this->
|
748 |
-
break;
|
749 |
-
case '
|
750 |
-
$information = $this->
|
751 |
-
break;
|
752 |
-
|
753 |
-
|
754 |
-
|
755 |
-
|
756 |
-
|
757 |
-
|
758 |
-
|
759 |
-
|
760 |
-
|
761 |
-
*
|
762 |
-
*
|
763 |
-
|
764 |
-
|
765 |
-
|
766 |
-
|
767 |
-
|
768 |
-
|
769 |
-
'
|
770 |
-
'
|
771 |
-
'
|
772 |
-
'
|
773 |
-
'
|
774 |
-
'
|
775 |
-
'
|
776 |
-
'
|
777 |
-
'
|
778 |
-
'
|
779 |
-
'
|
780 |
-
'
|
781 |
-
'
|
782 |
-
'
|
783 |
-
'
|
784 |
-
'
|
785 |
-
'
|
786 |
-
'
|
787 |
-
'
|
788 |
-
'
|
789 |
-
'
|
790 |
-
'
|
791 |
-
'
|
792 |
-
'
|
793 |
-
'
|
794 |
-
'
|
795 |
-
'
|
796 |
-
'
|
797 |
-
'
|
798 |
-
'
|
799 |
-
'
|
800 |
-
'
|
801 |
-
'
|
802 |
-
'
|
803 |
-
'
|
804 |
-
'
|
805 |
-
'
|
806 |
-
|
807 |
-
|
808 |
-
|
809 |
-
|
810 |
-
|
811 |
-
|
812 |
-
'
|
813 |
-
'
|
814 |
-
'
|
815 |
-
'
|
816 |
-
'
|
817 |
-
'
|
818 |
-
|
819 |
-
|
820 |
-
|
821 |
-
|
822 |
-
|
823 |
-
|
824 |
-
'
|
825 |
-
'
|
826 |
-
'
|
827 |
-
'
|
828 |
-
'
|
829 |
-
'
|
830 |
-
'
|
831 |
-
'
|
832 |
-
'
|
833 |
-
'
|
834 |
-
'
|
835 |
-
'
|
836 |
-
'
|
837 |
-
'
|
838 |
-
'
|
839 |
-
'
|
840 |
-
'
|
841 |
-
'
|
842 |
-
'
|
843 |
-
'
|
844 |
-
'
|
845 |
-
'
|
846 |
-
'
|
847 |
-
'
|
848 |
-
'
|
849 |
-
'
|
850 |
-
'
|
851 |
-
'
|
852 |
-
'
|
853 |
-
'
|
854 |
-
'
|
855 |
-
'
|
856 |
-
'
|
857 |
-
'
|
858 |
-
'
|
859 |
-
'
|
860 |
-
'
|
861 |
-
|
862 |
-
|
863 |
-
|
864 |
-
|
865 |
-
|
866 |
-
|
867 |
-
'
|
868 |
-
'
|
869 |
-
'
|
870 |
-
'
|
871 |
-
'
|
872 |
-
'
|
873 |
-
'
|
874 |
-
'
|
875 |
-
'
|
876 |
-
'
|
877 |
-
'
|
878 |
-
'
|
879 |
-
'
|
880 |
-
'
|
881 |
-
'
|
882 |
-
'
|
883 |
-
'
|
884 |
-
'
|
885 |
-
'
|
886 |
-
'
|
887 |
-
'
|
888 |
-
'
|
889 |
-
'
|
890 |
-
'
|
891 |
-
'
|
892 |
-
'
|
893 |
-
'
|
894 |
-
'
|
895 |
-
'
|
896 |
-
'
|
897 |
-
'
|
898 |
-
|
899 |
-
|
900 |
-
'
|
901 |
-
|
902 |
-
|
903 |
-
'
|
904 |
-
'
|
905 |
-
'
|
906 |
-
|
907 |
-
|
908 |
-
|
909 |
-
|
910 |
-
|
911 |
-
|
912 |
-
|
913 |
-
|
914 |
-
|
915 |
-
|
916 |
-
|
917 |
-
|
918 |
-
case self::
|
919 |
-
$options = $
|
920 |
-
break;
|
921 |
-
case self::
|
922 |
-
$options = $
|
923 |
-
break;
|
924 |
-
case self::
|
925 |
-
$options = $
|
926 |
-
break;
|
927 |
-
case self::
|
928 |
-
$options = $
|
929 |
-
break;
|
930 |
-
case self::
|
931 |
-
$options = $
|
932 |
-
break;
|
933 |
-
case self::
|
934 |
-
$options = $blocking_opts;
|
935 |
-
break;
|
936 |
-
|
937 |
-
|
938 |
-
|
939 |
-
|
940 |
-
|
941 |
-
|
942 |
-
|
943 |
-
|
944 |
-
*
|
945 |
-
*
|
946 |
-
*
|
947 |
-
*
|
948 |
-
|
949 |
-
|
950 |
-
|
951 |
-
|
952 |
-
|
953 |
-
|
954 |
-
|
955 |
-
|
956 |
-
|
957 |
-
|
958 |
-
|
959 |
-
|
960 |
-
|
961 |
-
|
962 |
-
*
|
963 |
-
*
|
964 |
-
*
|
965 |
-
*
|
966 |
-
|
967 |
-
|
968 |
-
|
969 |
-
|
970 |
-
|
971 |
-
\
|
972 |
-
|
973 |
-
|
974 |
-
|
975 |
-
|
976 |
-
|
977 |
-
|
978 |
-
|
979 |
-
|
980 |
-
|
981 |
-
*
|
982 |
-
*
|
983 |
-
*
|
984 |
-
*
|
985 |
-
|
986 |
-
|
987 |
-
|
988 |
-
|
989 |
-
|
990 |
-
|
991 |
-
|
992 |
-
|
993 |
-
|
994 |
-
*
|
995 |
-
*
|
996 |
-
*
|
997 |
-
*
|
998 |
-
|
999 |
-
|
1000 |
-
|
1001 |
-
|
1002 |
-
|
1003 |
-
|
1004 |
-
|
1005 |
-
|
1006 |
-
|
1007 |
-
*
|
1008 |
-
*
|
1009 |
-
*
|
1010 |
-
*
|
1011 |
-
*
|
1012 |
-
*
|
1013 |
-
|
1014 |
-
|
1015 |
-
|
1016 |
-
|
1017 |
-
|
1018 |
-
|
1019 |
-
|
1020 |
-
|
1021 |
-
|
1022 |
-
|
1023 |
-
|
1024 |
-
|
1025 |
-
|
1026 |
-
*
|
1027 |
-
*
|
1028 |
-
*
|
1029 |
-
*
|
1030 |
-
|
1031 |
-
|
1032 |
-
|
1033 |
-
|
1034 |
-
|
1035 |
-
|
1036 |
-
|
1037 |
-
|
1038 |
-
|
1039 |
-
|
1040 |
-
|
1041 |
-
|
1042 |
-
|
1043 |
-
|
1044 |
-
|
1045 |
-
|
1046 |
-
$information
|
1047 |
-
|
1048 |
-
|
1049 |
-
|
1050 |
-
|
1051 |
-
|
1052 |
-
|
1053 |
-
*
|
1054 |
-
*
|
1055 |
-
*
|
1056 |
-
*
|
1057 |
-
|
1058 |
-
|
1059 |
-
|
1060 |
-
|
1061 |
-
|
1062 |
-
|
1063 |
-
|
1064 |
-
|
1065 |
-
|
1066 |
-
*
|
1067 |
-
*
|
1068 |
-
*
|
1069 |
-
*
|
1070 |
-
|
1071 |
-
|
1072 |
-
|
1073 |
-
|
1074 |
-
|
1075 |
-
$
|
1076 |
-
$
|
1077 |
-
|
1078 |
-
|
1079 |
-
|
1080 |
-
|
1081 |
-
|
1082 |
-
|
1083 |
-
'
|
1084 |
-
'
|
1085 |
-
'
|
1086 |
-
'
|
1087 |
-
'
|
1088 |
-
'
|
1089 |
-
'
|
1090 |
-
'
|
1091 |
-
|
1092 |
-
|
1093 |
-
|
1094 |
-
|
1095 |
-
|
1096 |
-
|
1097 |
-
|
1098 |
-
*
|
1099 |
-
*
|
1100 |
-
*
|
1101 |
-
*
|
1102 |
-
|
1103 |
-
|
1104 |
-
|
1105 |
-
|
1106 |
-
|
1107 |
-
$
|
1108 |
-
$
|
1109 |
-
|
1110 |
-
$
|
1111 |
-
|
1112 |
-
|
1113 |
-
|
1114 |
-
'
|
1115 |
-
'
|
1116 |
-
'
|
1117 |
-
'
|
1118 |
-
'
|
1119 |
-
'
|
1120 |
-
'
|
1121 |
-
|
1122 |
-
|
1123 |
-
|
1124 |
-
|
1125 |
-
|
1126 |
-
|
1127 |
-
|
1128 |
-
|
1129 |
-
*
|
1130 |
-
*
|
1131 |
-
*
|
1132 |
-
*
|
1133 |
-
*
|
1134 |
-
*
|
1135 |
-
|
1136 |
-
|
1137 |
-
|
1138 |
-
|
1139 |
-
|
1140 |
-
|
1141 |
-
'
|
1142 |
-
|
1143 |
-
|
1144 |
-
|
1145 |
-
|
1146 |
-
|
1147 |
-
|
1148 |
-
|
1149 |
-
|
1150 |
-
|
1151 |
-
|
1152 |
-
|
1153 |
-
|
1154 |
-
|
1155 |
-
*
|
1156 |
-
*
|
1157 |
-
*
|
1158 |
-
*
|
1159 |
-
*
|
1160 |
-
*
|
1161 |
-
|
1162 |
-
|
1163 |
-
|
1164 |
-
|
1165 |
-
|
1166 |
-
|
1167 |
-
|
1168 |
-
|
1169 |
-
|
1170 |
-
|
1171 |
-
|
1172 |
-
|
1173 |
-
|
1174 |
-
$
|
1175 |
-
|
1176 |
-
|
1177 |
-
|
1178 |
-
|
1179 |
-
|
1180 |
-
|
1181 |
-
|
1182 |
-
|
1183 |
-
|
1184 |
-
|
1185 |
-
*
|
1186 |
-
*
|
1187 |
-
*
|
1188 |
-
*
|
1189 |
-
|
1190 |
-
|
1191 |
-
|
1192 |
-
|
1193 |
-
|
1194 |
-
$
|
1195 |
-
|
1196 |
-
|
1197 |
-
|
1198 |
-
|
1199 |
-
|
1200 |
-
|
1201 |
-
*
|
1202 |
-
*
|
1203 |
-
*
|
1204 |
-
*
|
1205 |
-
|
1206 |
-
|
1207 |
-
|
1208 |
-
|
1209 |
-
|
1210 |
-
|
1211 |
-
|
1212 |
-
|
1213 |
-
|
1214 |
-
|
1215 |
-
|
1216 |
-
|
1217 |
-
|
1218 |
-
|
1219 |
-
|
1220 |
-
|
1221 |
-
|
1222 |
-
|
1223 |
-
|
1224 |
-
|
1225 |
-
|
1226 |
-
*
|
1227 |
-
*
|
1228 |
-
*
|
1229 |
-
*
|
1230 |
-
|
1231 |
-
|
1232 |
-
|
1233 |
-
|
1234 |
-
|
1235 |
-
|
1236 |
-
|
1237 |
-
|
1238 |
-
|
1239 |
-
|
1240 |
-
|
1241 |
-
$wfIssues->
|
1242 |
-
|
1243 |
-
|
1244 |
-
|
1245 |
-
|
1246 |
-
|
1247 |
-
|
1248 |
-
|
1249 |
-
|
1250 |
-
|
1251 |
-
|
1252 |
-
*
|
1253 |
-
*
|
1254 |
-
*
|
1255 |
-
*
|
1256 |
-
|
1257 |
-
|
1258 |
-
|
1259 |
-
|
1260 |
-
|
1261 |
-
|
1262 |
-
|
1263 |
-
|
1264 |
-
|
1265 |
-
|
1266 |
-
|
1267 |
-
|
1268 |
-
|
1269 |
-
|
1270 |
-
|
1271 |
-
|
1272 |
-
|
1273 |
-
*
|
1274 |
-
*
|
1275 |
-
*
|
1276 |
-
*
|
1277 |
-
|
1278 |
-
|
1279 |
-
|
1280 |
-
|
1281 |
-
|
1282 |
-
|
1283 |
-
|
1284 |
-
|
1285 |
-
|
1286 |
-
|
1287 |
-
|
1288 |
-
|
1289 |
-
|
1290 |
-
*
|
1291 |
-
*
|
1292 |
-
*
|
1293 |
-
*
|
1294 |
-
|
1295 |
-
|
1296 |
-
|
1297 |
-
|
1298 |
-
|
1299 |
-
|
1300 |
-
|
1301 |
-
$
|
1302 |
-
$
|
1303 |
-
|
1304 |
-
|
1305 |
-
|
1306 |
-
|
1307 |
-
|
1308 |
-
|
1309 |
-
|
1310 |
-
|
1311 |
-
$
|
1312 |
-
|
1313 |
-
|
1314 |
-
|
1315 |
-
|
1316 |
-
|
1317 |
-
|
1318 |
-
|
1319 |
-
|
1320 |
-
$
|
1321 |
-
$
|
1322 |
-
}
|
1323 |
-
|
1324 |
-
|
1325 |
-
|
1326 |
-
|
1327 |
-
|
1328 |
-
|
1329 |
-
|
1330 |
-
$errors[] = $
|
1331 |
-
continue;
|
1332 |
-
}
|
1333 |
-
|
1334 |
-
|
1335 |
-
|
1336 |
-
|
1337 |
-
|
1338 |
-
|
1339 |
-
|
1340 |
-
|
1341 |
-
|
1342 |
-
|
1343 |
-
|
1344 |
-
|
1345 |
-
|
1346 |
-
|
1347 |
-
|
1348 |
-
|
1349 |
-
|
1350 |
-
|
1351 |
-
|
1352 |
-
|
1353 |
-
|
1354 |
-
|
1355 |
-
|
1356 |
-
|
1357 |
-
|
1358 |
-
|
1359 |
-
|
1360 |
-
|
1361 |
-
|
1362 |
-
|
1363 |
-
|
1364 |
-
$
|
1365 |
-
$
|
1366 |
-
|
1367 |
-
|
1368 |
-
|
1369 |
-
$headMsg = "$verb
|
1370 |
-
$bodyMsg = "$verb $filesWorkedOn files
|
1371 |
-
} elseif ( $
|
1372 |
-
$headMsg = "
|
1373 |
-
$bodyMsg = "
|
1374 |
-
}
|
1375 |
-
$headMsg =
|
1376 |
-
$bodyMsg = "We
|
1377 |
-
}
|
1378 |
-
|
1379 |
-
|
1380 |
-
|
1381 |
-
|
1382 |
-
|
1383 |
-
|
1384 |
-
|
1385 |
-
|
1386 |
-
|
1387 |
-
|
1388 |
-
|
1389 |
-
|
1390 |
-
|
1391 |
-
|
1392 |
-
|
1393 |
-
*
|
1394 |
-
*
|
1395 |
-
*
|
1396 |
-
*
|
1397 |
-
|
1398 |
-
|
1399 |
-
|
1400 |
-
|
1401 |
-
|
1402 |
-
|
1403 |
-
|
1404 |
-
|
1405 |
-
|
1406 |
-
*
|
1407 |
-
*
|
1408 |
-
*
|
1409 |
-
*
|
1410 |
-
|
1411 |
-
|
1412 |
-
|
1413 |
-
|
1414 |
-
|
1415 |
-
|
1416 |
-
|
1417 |
-
|
1418 |
-
if ( ! $issue ) {
|
1419 |
-
return array( 'errorMsg' => 'Could not delete file because
|
1420 |
-
}
|
1421 |
-
|
1422 |
-
|
1423 |
-
|
1424 |
-
$
|
1425 |
-
|
1426 |
-
|
1427 |
-
if (
|
1428 |
-
|
1429 |
-
|
1430 |
-
|
1431 |
-
|
1432 |
-
|
1433 |
-
|
1434 |
-
|
1435 |
-
|
1436 |
-
|
1437 |
-
|
1438 |
-
|
1439 |
-
|
1440 |
-
|
1441 |
-
|
1442 |
-
|
1443 |
-
|
1444 |
-
|
1445 |
-
|
1446 |
-
*
|
1447 |
-
*
|
1448 |
-
*
|
1449 |
-
*
|
1450 |
-
|
1451 |
-
|
1452 |
-
|
1453 |
-
|
1454 |
-
|
1455 |
-
|
1456 |
-
|
1457 |
-
|
1458 |
-
|
1459 |
-
|
1460 |
-
|
1461 |
-
$
|
1462 |
-
|
1463 |
-
|
1464 |
-
|
1465 |
-
|
1466 |
-
|
1467 |
-
|
1468 |
-
|
1469 |
-
|
1470 |
-
|
1471 |
-
|
1472 |
-
|
1473 |
-
|
1474 |
-
|
1475 |
-
|
1476 |
-
|
1477 |
-
|
1478 |
-
|
1479 |
-
|
1480 |
-
|
1481 |
-
|
1482 |
-
|
1483 |
-
|
1484 |
-
|
1485 |
-
|
1486 |
-
|
1487 |
-
|
1488 |
-
|
1489 |
-
|
1490 |
-
|
1491 |
-
|
1492 |
-
|
1493 |
-
|
1494 |
-
|
1495 |
-
|
1496 |
-
|
1497 |
-
|
1498 |
-
|
1499 |
-
|
1500 |
-
|
1501 |
-
*
|
1502 |
-
*
|
1503 |
-
*
|
1504 |
-
*
|
1505 |
-
*
|
1506 |
-
* @
|
1507 |
-
* @
|
1508 |
-
*
|
1509 |
-
* @
|
1510 |
-
|
1511 |
-
|
1512 |
-
|
1513 |
-
|
1514 |
-
|
1515 |
-
|
1516 |
-
|
1517 |
-
|
1518 |
-
|
1519 |
-
|
1520 |
-
|
1521 |
-
|
1522 |
-
|
1523 |
-
|
1524 |
-
|
1525 |
-
$c
|
1526 |
-
$res .= chr( $c & 0xFF );
|
1527 |
-
}
|
1528 |
-
|
1529 |
-
|
1530 |
-
|
1531 |
-
|
1532 |
-
|
1533 |
-
|
1534 |
-
|
1535 |
-
|
1536 |
-
|
1537 |
-
|
1538 |
-
|
1539 |
-
|
1540 |
-
*
|
1541 |
-
*
|
1542 |
-
*
|
1543 |
-
*
|
1544 |
-
*
|
1545 |
-
*
|
1546 |
-
*
|
1547 |
-
*
|
1548 |
-
|
1549 |
-
|
1550 |
-
|
1551 |
-
|
1552 |
-
|
1553 |
-
|
1554 |
-
|
1555 |
-
|
1556 |
-
|
1557 |
-
|
1558 |
-
|
1559 |
-
$
|
1560 |
-
|
1561 |
-
|
1562 |
-
|
1563 |
-
|
1564 |
-
|
1565 |
-
|
1566 |
-
|
1567 |
-
$
|
1568 |
-
|
1569 |
-
|
1570 |
-
|
1571 |
-
|
1572 |
-
|
1573 |
-
|
1574 |
-
|
1575 |
-
|
1576 |
-
|
1577 |
-
|
1578 |
-
|
1579 |
-
|
1580 |
-
|
1581 |
-
|
1582 |
-
|
1583 |
-
|
1584 |
-
|
1585 |
-
|
1586 |
-
|
1587 |
-
|
1588 |
-
|
1589 |
-
|
1590 |
-
|
1591 |
-
|
1592 |
-
|
1593 |
-
|
1594 |
-
|
1595 |
-
|
1596 |
-
|
1597 |
-
|
1598 |
-
|
1599 |
-
|
1600 |
-
|
1601 |
-
|
1602 |
-
|
1603 |
-
|
1604 |
-
|
1605 |
-
|
1606 |
-
|
1607 |
-
|
1608 |
-
|
1609 |
-
|
1610 |
-
|
1611 |
-
|
1612 |
-
|
1613 |
-
|
1614 |
-
|
1615 |
-
if (
|
1616 |
-
|
1617 |
-
}
|
1618 |
-
|
1619 |
-
|
1620 |
-
|
1621 |
-
|
1622 |
-
|
1623 |
-
|
1624 |
-
|
1625 |
-
|
1626 |
-
|
1627 |
-
|
1628 |
-
|
1629 |
-
|
1630 |
-
|
1631 |
-
|
1632 |
-
|
1633 |
-
|
1634 |
-
|
1635 |
-
|
1636 |
-
|
1637 |
-
|
1638 |
-
|
1639 |
-
|
1640 |
-
|
1641 |
-
|
1642 |
-
|
1643 |
-
|
1644 |
-
|
1645 |
-
|
1646 |
-
|
1647 |
-
|
1648 |
-
|
1649 |
-
|
1650 |
-
|
1651 |
-
|
1652 |
-
|
1653 |
-
|
1654 |
-
|
1655 |
-
|
1656 |
-
|
1657 |
-
|
1658 |
-
|
1659 |
-
|
1660 |
-
|
1661 |
-
|
1662 |
-
|
1663 |
-
|
1664 |
-
|
1665 |
-
|
1666 |
-
|
1667 |
-
|
1668 |
-
|
1669 |
-
|
1670 |
-
|
1671 |
-
|
1672 |
-
|
1673 |
-
|
1674 |
-
|
1675 |
-
\
|
1676 |
-
|
1677 |
-
\wfConfig::set( '
|
1678 |
-
\wfActivityReport::
|
1679 |
-
}
|
1680 |
-
|
1681 |
-
|
1682 |
-
|
1683 |
-
|
1684 |
-
|
1685 |
-
|
1686 |
-
|
1687 |
-
|
1688 |
-
|
1689 |
-
|
1690 |
-
|
1691 |
-
|
1692 |
-
|
1693 |
-
|
1694 |
-
|
1695 |
-
|
1696 |
-
|
1697 |
-
|
1698 |
-
|
1699 |
-
|
1700 |
-
|
1701 |
-
|
1702 |
-
|
1703 |
-
|
1704 |
-
|
1705 |
-
$
|
1706 |
-
|
1707 |
-
|
1708 |
-
$
|
1709 |
-
|
1710 |
-
|
1711 |
-
|
1712 |
-
|
1713 |
-
|
1714 |
-
|
1715 |
-
\
|
1716 |
-
|
1717 |
-
|
1718 |
-
|
1719 |
-
$
|
1720 |
-
|
1721 |
-
|
1722 |
-
|
1723 |
-
|
1724 |
-
|
1725 |
-
|
1726 |
-
}
|
1727 |
-
|
1728 |
-
|
1729 |
-
|
1730 |
-
|
1731 |
-
|
1732 |
-
|
1733 |
-
|
1734 |
-
|
1735 |
-
|
1736 |
-
|
1737 |
-
|
1738 |
-
|
1739 |
-
|
1740 |
-
|
1741 |
-
|
1742 |
-
|
1743 |
-
|
1744 |
-
|
1745 |
-
|
1746 |
-
|
1747 |
-
|
1748 |
-
|
1749 |
-
|
1750 |
-
|
1751 |
-
|
1752 |
-
|
1753 |
-
|
1754 |
-
|
1755 |
-
}
|
1756 |
-
|
1757 |
-
|
1758 |
-
|
1759 |
-
}
|
1760 |
-
|
1761 |
-
|
1762 |
-
|
1763 |
-
|
1764 |
-
|
1765 |
-
|
1766 |
-
|
1767 |
-
|
1768 |
-
|
1769 |
-
|
1770 |
-
|
1771 |
-
|
1772 |
-
|
1773 |
-
|
1774 |
-
|
1775 |
-
)
|
1776 |
-
|
1777 |
-
if ( isset( $keyData['
|
1778 |
-
|
1779 |
-
|
1780 |
-
|
1781 |
-
|
1782 |
-
\
|
1783 |
-
|
1784 |
-
|
1785 |
-
|
1786 |
-
\wfConfig::
|
1787 |
-
|
1788 |
-
|
1789 |
-
|
1790 |
-
\wfConfig::
|
1791 |
-
|
1792 |
-
|
1793 |
-
|
1794 |
-
|
1795 |
-
|
1796 |
-
|
1797 |
-
|
1798 |
-
|
1799 |
-
|
1800 |
-
|
1801 |
-
|
1802 |
-
|
1803 |
-
|
1804 |
-
|
1805 |
-
|
1806 |
-
|
1807 |
-
|
1808 |
-
|
1809 |
-
}
|
1810 |
-
|
1811 |
-
|
1812 |
-
|
1813 |
-
|
1814 |
-
|
1815 |
-
|
1816 |
-
$result
|
1817 |
-
|
1818 |
-
|
1819 |
-
|
1820 |
-
|
1821 |
-
|
1822 |
-
|
1823 |
-
|
1824 |
-
|
1825 |
-
|
1826 |
-
|
1827 |
-
|
1828 |
-
*
|
1829 |
-
*
|
1830 |
-
*
|
1831 |
-
*
|
1832 |
-
|
1833 |
-
|
1834 |
-
|
1835 |
-
|
1836 |
-
|
1837 |
-
|
1838 |
-
|
1839 |
-
|
1840 |
-
|
1841 |
-
*
|
1842 |
-
*
|
1843 |
-
*
|
1844 |
-
*
|
1845 |
-
*
|
1846 |
-
*
|
1847 |
-
*
|
1848 |
-
*
|
1849 |
-
|
1850 |
-
|
1851 |
-
|
1852 |
-
|
1853 |
-
|
1854 |
-
|
1855 |
-
|
1856 |
-
|
1857 |
-
|
1858 |
-
|
1859 |
-
|
1860 |
-
|
1861 |
-
$
|
1862 |
-
$
|
1863 |
-
$opts
|
1864 |
-
|
1865 |
-
|
1866 |
-
|
1867 |
-
|
1868 |
-
|
1869 |
-
|
1870 |
-
|
1871 |
-
|
1872 |
-
|
1873 |
-
|
1874 |
-
|
1875 |
-
|
1876 |
-
|
1877 |
-
|
1878 |
-
|
1879 |
-
|
1880 |
-
|
1881 |
-
|
1882 |
-
|
1883 |
-
|
1884 |
-
|
1885 |
-
|
1886 |
-
|
1887 |
-
|
1888 |
-
|
1889 |
-
|
1890 |
-
|
1891 |
-
|
1892 |
-
|
1893 |
-
|
1894 |
-
|
1895 |
-
|
1896 |
-
|
1897 |
-
|
1898 |
-
|
1899 |
-
|
1900 |
-
|
1901 |
-
|
1902 |
-
|
1903 |
-
|
1904 |
-
|
1905 |
-
|
1906 |
-
|
1907 |
-
|
1908 |
-
|
1909 |
-
|
1910 |
-
|
1911 |
-
|
1912 |
-
|
1913 |
-
|
1914 |
-
|
1915 |
-
|
1916 |
-
|
1917 |
-
|
1918 |
-
|
1919 |
-
|
1920 |
-
|
1921 |
-
|
1922 |
-
|
1923 |
-
|
1924 |
-
|
1925 |
-
|
1926 |
-
|
1927 |
-
|
1928 |
-
|
1929 |
-
|
1930 |
-
\
|
1931 |
-
|
1932 |
-
\wfConfig::set( '
|
1933 |
-
\wfActivityReport::
|
1934 |
-
}
|
1935 |
-
|
1936 |
-
|
1937 |
-
|
1938 |
-
|
1939 |
-
|
1940 |
-
|
1941 |
-
|
1942 |
-
|
1943 |
-
|
1944 |
-
|
1945 |
-
|
1946 |
-
|
1947 |
-
|
1948 |
-
|
1949 |
-
$
|
1950 |
-
|
1951 |
-
|
1952 |
-
|
1953 |
-
|
1954 |
-
|
1955 |
-
|
1956 |
-
|
1957 |
-
|
1958 |
-
|
1959 |
-
|
1960 |
-
|
1961 |
-
|
1962 |
-
|
1963 |
-
|
1964 |
-
|
1965 |
-
|
1966 |
-
|
1967 |
-
|
1968 |
-
|
1969 |
-
|
1970 |
-
|
1971 |
-
|
1972 |
-
|
1973 |
-
|
1974 |
-
|
1975 |
-
|
1976 |
-
|
1977 |
-
|
1978 |
-
|
1979 |
-
|
1980 |
-
|
1981 |
-
|
1982 |
-
|
1983 |
-
|
1984 |
-
|
1985 |
-
|
1986 |
-
|
1987 |
-
|
1988 |
-
|
1989 |
-
|
1990 |
-
|
1991 |
-
|
1992 |
-
|
1993 |
-
$
|
1994 |
-
|
1995 |
-
|
1996 |
-
|
1997 |
-
|
1998 |
-
|
1999 |
-
|
2000 |
-
|
2001 |
-
$result
|
2002 |
-
|
2003 |
-
|
2004 |
-
|
2005 |
-
|
2006 |
-
|
2007 |
-
|
2008 |
-
|
2009 |
-
*
|
2010 |
-
*
|
2011 |
-
*
|
2012 |
-
*
|
2013 |
-
*
|
2014 |
-
*
|
2015 |
-
|
2016 |
-
|
2017 |
-
|
2018 |
-
|
2019 |
-
|
2020 |
-
|
2021 |
-
$
|
2022 |
-
|
2023 |
-
|
2024 |
-
|
2025 |
-
|
2026 |
-
|
2027 |
-
|
2028 |
-
|
2029 |
-
//
|
2030 |
-
$export['
|
2031 |
-
|
2032 |
-
//
|
2033 |
-
|
2034 |
-
|
2035 |
-
|
2036 |
-
|
2037 |
-
|
2038 |
-
|
2039 |
-
|
2040 |
-
|
2041 |
-
|
2042 |
-
|
2043 |
-
|
2044 |
-
|
2045 |
-
|
2046 |
-
|
2047 |
-
|
2048 |
-
|
2049 |
-
|
2050 |
-
|
2051 |
-
|
2052 |
-
|
2053 |
-
|
2054 |
-
|
2055 |
-
*
|
2056 |
-
*
|
2057 |
-
*
|
2058 |
-
*
|
2059 |
-
*
|
2060 |
-
*
|
2061 |
-
|
2062 |
-
|
2063 |
-
|
2064 |
-
|
2065 |
-
|
2066 |
-
|
2067 |
-
|
2068 |
-
|
2069 |
-
|
2070 |
-
|
2071 |
-
|
2072 |
-
|
2073 |
-
|
2074 |
-
|
2075 |
-
|
2076 |
-
|
2077 |
-
|
2078 |
-
|
2079 |
-
|
2080 |
-
|
2081 |
-
|
2082 |
-
|
2083 |
-
|
2084 |
-
|
2085 |
-
|
2086 |
-
|
2087 |
-
|
2088 |
-
|
2089 |
-
|
2090 |
-
|
2091 |
-
|
2092 |
-
|
2093 |
-
|
2094 |
-
|
2095 |
-
|
2096 |
-
|
2097 |
-
|
2098 |
-
|
2099 |
-
|
2100 |
-
|
2101 |
-
|
2102 |
-
|
2103 |
-
|
2104 |
-
|
2105 |
-
|
2106 |
-
|
2107 |
-
|
2108 |
-
|
2109 |
-
|
2110 |
-
|
2111 |
-
|
2112 |
-
|
2113 |
-
|
2114 |
-
|
2115 |
-
|
2116 |
-
|
2117 |
-
|
2118 |
-
|
2119 |
-
|
2120 |
-
|
2121 |
-
|
2122 |
-
|
2123 |
-
|
2124 |
-
|
2125 |
-
|
2126 |
-
|
2127 |
-
|
2128 |
-
|
2129 |
-
*
|
2130 |
-
*
|
2131 |
-
*
|
2132 |
-
*
|
2133 |
-
|
2134 |
-
|
2135 |
-
|
2136 |
-
|
2137 |
-
|
2138 |
-
|
2139 |
-
|
2140 |
-
|
2141 |
-
|
2142 |
-
|
2143 |
-
|
2144 |
-
|
2145 |
-
|
2146 |
-
|
2147 |
-
|
2148 |
-
|
2149 |
-
*
|
2150 |
-
*
|
2151 |
-
*
|
2152 |
-
*
|
2153 |
-
|
2154 |
-
|
2155 |
-
|
2156 |
-
|
2157 |
-
|
2158 |
-
|
2159 |
-
|
2160 |
-
|
2161 |
-
|
2162 |
-
|
2163 |
-
|
2164 |
-
|
2165 |
-
|
2166 |
-
|
2167 |
-
|
2168 |
-
);
|
2169 |
-
|
2170 |
-
|
2171 |
-
|
2172 |
-
|
2173 |
-
$type
|
2174 |
-
|
2175 |
-
|
2176 |
-
|
2177 |
-
|
2178 |
-
|
2179 |
-
$events
|
2180 |
-
} elseif ( '
|
2181 |
-
|
2182 |
-
|
2183 |
-
|
2184 |
-
|
2185 |
-
|
2186 |
-
|
2187 |
-
|
2188 |
-
|
2189 |
-
|
2190 |
-
|
2191 |
-
|
2192 |
-
|
2193 |
-
$jsonData
|
2194 |
-
|
2195 |
-
|
2196 |
-
|
2197 |
-
|
2198 |
-
|
2199 |
-
|
2200 |
-
*
|
2201 |
-
*
|
2202 |
-
*
|
2203 |
-
*
|
2204 |
-
|
2205 |
-
|
2206 |
-
|
2207 |
-
|
2208 |
-
|
2209 |
-
$
|
2210 |
-
$
|
2211 |
-
$return
|
2212 |
-
|
2213 |
-
|
2214 |
-
|
2215 |
-
|
2216 |
-
|
2217 |
-
|
2218 |
-
*
|
2219 |
-
*
|
2220 |
-
*
|
2221 |
-
*
|
2222 |
-
|
2223 |
-
|
2224 |
-
|
2225 |
-
|
2226 |
-
|
2227 |
-
|
2228 |
-
|
2229 |
-
|
2230 |
-
|
2231 |
-
|
2232 |
-
*
|
2233 |
-
*
|
2234 |
-
*
|
2235 |
-
*
|
2236 |
-
|
2237 |
-
|
2238 |
-
|
2239 |
-
|
2240 |
-
|
2241 |
-
|
2242 |
-
|
2243 |
-
|
2244 |
-
|
2245 |
-
|
2246 |
-
*
|
2247 |
-
*
|
2248 |
-
*
|
2249 |
-
*
|
2250 |
-
|
2251 |
-
|
2252 |
-
|
2253 |
-
|
2254 |
-
|
2255 |
-
|
2256 |
-
|
2257 |
-
|
2258 |
-
|
2259 |
-
|
2260 |
-
*
|
2261 |
-
*
|
2262 |
-
*
|
2263 |
-
*
|
2264 |
-
|
2265 |
-
|
2266 |
-
|
2267 |
-
|
2268 |
-
|
2269 |
-
|
2270 |
-
|
2271 |
-
|
2272 |
-
|
2273 |
-
|
2274 |
-
*
|
2275 |
-
*
|
2276 |
-
*
|
2277 |
-
*
|
2278 |
-
|
2279 |
-
|
2280 |
-
|
2281 |
-
|
2282 |
-
|
2283 |
-
|
2284 |
-
|
2285 |
-
|
2286 |
-
|
2287 |
-
|
2288 |
-
*
|
2289 |
-
*
|
2290 |
-
*
|
2291 |
-
*
|
2292 |
-
|
2293 |
-
|
2294 |
-
|
2295 |
-
|
2296 |
-
|
2297 |
-
|
2298 |
-
|
2299 |
-
|
2300 |
-
|
2301 |
-
|
2302 |
-
*
|
2303 |
-
*
|
2304 |
-
*
|
2305 |
-
*
|
2306 |
-
|
2307 |
-
|
2308 |
-
|
2309 |
-
|
2310 |
-
|
2311 |
-
|
2312 |
-
|
2313 |
-
|
2314 |
-
|
2315 |
-
|
2316 |
-
*
|
2317 |
-
*
|
2318 |
-
*
|
2319 |
-
*
|
2320 |
-
|
2321 |
-
|
2322 |
-
|
2323 |
-
|
2324 |
-
|
2325 |
-
|
2326 |
-
|
2327 |
-
|
2328 |
-
|
2329 |
-
|
2330 |
-
*
|
2331 |
-
*
|
2332 |
-
*
|
2333 |
-
*
|
2334 |
-
|
2335 |
-
|
2336 |
-
|
2337 |
-
|
2338 |
-
|
2339 |
-
|
2340 |
-
|
2341 |
-
|
2342 |
-
|
2343 |
-
|
2344 |
-
*
|
2345 |
-
*
|
2346 |
-
*
|
2347 |
-
*
|
2348 |
-
|
2349 |
-
|
2350 |
-
|
2351 |
-
|
2352 |
-
|
2353 |
-
|
2354 |
-
|
2355 |
-
|
2356 |
-
|
2357 |
-
|
2358 |
-
*
|
2359 |
-
*
|
2360 |
-
*
|
2361 |
-
*
|
2362 |
-
|
2363 |
-
|
2364 |
-
|
2365 |
-
|
2366 |
-
|
2367 |
-
|
2368 |
-
|
2369 |
-
|
2370 |
-
|
2371 |
-
|
2372 |
-
*
|
2373 |
-
*
|
2374 |
-
*
|
2375 |
-
*
|
2376 |
-
|
2377 |
-
|
2378 |
-
|
2379 |
-
|
2380 |
-
|
2381 |
-
|
2382 |
-
|
2383 |
-
|
2384 |
-
|
2385 |
-
|
2386 |
-
*
|
2387 |
-
*
|
2388 |
-
*
|
2389 |
-
*
|
2390 |
-
|
2391 |
-
|
2392 |
-
|
2393 |
-
|
2394 |
-
|
2395 |
-
|
2396 |
-
|
2397 |
-
|
2398 |
-
|
2399 |
-
|
2400 |
-
*
|
2401 |
-
*
|
2402 |
-
*
|
2403 |
-
*
|
2404 |
-
|
2405 |
-
|
2406 |
-
|
2407 |
-
|
2408 |
-
|
2409 |
-
|
2410 |
-
|
2411 |
-
|
2412 |
-
|
2413 |
-
|
2414 |
-
*
|
2415 |
-
*
|
2416 |
-
*
|
2417 |
-
*
|
2418 |
-
|
2419 |
-
|
2420 |
-
|
2421 |
-
|
2422 |
-
|
2423 |
-
|
2424 |
-
|
2425 |
-
|
2426 |
-
|
2427 |
-
|
2428 |
-
|
2429 |
-
|
2430 |
-
|
2431 |
-
*
|
2432 |
-
*
|
2433 |
-
*
|
2434 |
-
*
|
2435 |
-
|
2436 |
-
|
2437 |
-
|
2438 |
-
|
2439 |
-
|
2440 |
-
|
2441 |
-
|
2442 |
-
|
2443 |
-
|
2444 |
-
|
2445 |
-
*
|
2446 |
-
*
|
2447 |
-
*
|
2448 |
-
*
|
2449 |
-
|
2450 |
-
|
2451 |
-
|
2452 |
-
|
2453 |
-
|
2454 |
-
|
2455 |
-
|
2456 |
-
|
2457 |
-
|
2458 |
-
|
2459 |
-
*
|
2460 |
-
*
|
2461 |
-
*
|
2462 |
-
*
|
2463 |
-
|
2464 |
-
|
2465 |
-
|
2466 |
-
|
2467 |
-
|
2468 |
-
|
2469 |
-
|
2470 |
-
|
2471 |
-
|
2472 |
-
|
2473 |
-
*
|
2474 |
-
*
|
2475 |
-
*
|
2476 |
-
*
|
2477 |
-
|
2478 |
-
|
2479 |
-
|
2480 |
-
|
2481 |
-
|
2482 |
-
|
2483 |
-
|
2484 |
-
|
2485 |
-
|
2486 |
-
|
2487 |
-
*
|
2488 |
-
*
|
2489 |
-
*
|
2490 |
-
*
|
2491 |
-
*
|
2492 |
-
*
|
2493 |
-
|
2494 |
-
|
2495 |
-
|
2496 |
-
|
2497 |
-
|
2498 |
-
|
2499 |
-
|
2500 |
-
|
2501 |
-
|
2502 |
-
$data['
|
2503 |
-
|
2504 |
-
|
2505 |
-
|
2506 |
-
|
2507 |
-
|
2508 |
-
|
2509 |
-
|
2510 |
-
|
2511 |
-
|
2512 |
-
|
2513 |
-
|
2514 |
-
|
2515 |
-
|
2516 |
-
|
2517 |
-
|
2518 |
-
|
2519 |
-
|
2520 |
-
|
2521 |
-
|
2522 |
-
|
2523 |
-
|
2524 |
-
|
2525 |
-
|
2526 |
-
|
2527 |
-
|
2528 |
-
|
2529 |
-
|
2530 |
-
|
2531 |
-
|
2532 |
-
|
2533 |
-
'
|
2534 |
-
|
2535 |
-
|
2536 |
-
|
2537 |
-
|
2538 |
-
|
2539 |
-
|
2540 |
-
|
2541 |
-
|
2542 |
-
|
2543 |
-
|
2544 |
-
|
2545 |
-
|
2546 |
-
|
2547 |
-
|
2548 |
-
|
2549 |
-
|
2550 |
-
|
2551 |
-
|
2552 |
-
|
2553 |
-
|
2554 |
-
*
|
2555 |
-
*
|
2556 |
-
*
|
2557 |
-
*
|
2558 |
-
|
2559 |
-
|
2560 |
-
|
2561 |
-
|
2562 |
-
|
2563 |
-
|
2564 |
-
|
2565 |
-
|
2566 |
-
|
2567 |
-
|
2568 |
-
|
2569 |
-
|
2570 |
-
|
2571 |
-
|
2572 |
-
|
2573 |
-
|
2574 |
-
|
2575 |
-
|
2576 |
-
*
|
2577 |
-
*
|
2578 |
-
*
|
2579 |
-
*
|
2580 |
-
|
2581 |
-
|
2582 |
-
|
2583 |
-
|
2584 |
-
|
2585 |
-
|
2586 |
-
|
2587 |
-
|
2588 |
-
|
2589 |
-
|
2590 |
-
|
2591 |
-
|
2592 |
-
|
2593 |
-
if ( isset( $value['data']['
|
2594 |
-
$value['data']['
|
2595 |
-
}
|
2596 |
-
|
2597 |
-
|
2598 |
-
|
2599 |
-
|
2600 |
-
|
2601 |
-
|
2602 |
-
|
2603 |
-
|
2604 |
-
|
2605 |
-
|
2606 |
-
|
2607 |
-
|
2608 |
-
|
2609 |
-
)
|
2610 |
-
|
2611 |
-
|
2612 |
-
|
2613 |
-
$compoundMessage
|
2614 |
-
|
2615 |
-
|
2616 |
-
|
2617 |
-
|
2618 |
-
|
2619 |
-
|
2620 |
-
|
2621 |
-
|
2622 |
-
|
2623 |
-
|
2624 |
-
|
2625 |
-
|
2626 |
-
|
2627 |
-
|
2628 |
-
|
2629 |
-
|
2630 |
-
|
2631 |
-
|
2632 |
-
|
2633 |
-
|
2634 |
-
|
2635 |
-
|
2636 |
-
|
2637 |
-
|
2638 |
-
|
2639 |
-
|
2640 |
-
|
2641 |
-
|
2642 |
-
|
2643 |
-
|
2644 |
-
*
|
2645 |
-
*
|
2646 |
-
*
|
2647 |
-
*
|
2648 |
-
|
2649 |
-
|
2650 |
-
|
2651 |
-
|
2652 |
-
|
2653 |
-
|
2654 |
-
|
2655 |
-
|
2656 |
-
|
2657 |
-
|
2658 |
-
*
|
2659 |
-
*
|
2660 |
-
*
|
2661 |
-
*
|
2662 |
-
|
2663 |
-
|
2664 |
-
|
2665 |
-
|
2666 |
-
|
2667 |
-
|
2668 |
-
|
2669 |
-
|
2670 |
-
|
2671 |
-
*
|
2672 |
-
*
|
2673 |
-
*
|
2674 |
-
*
|
2675 |
-
|
2676 |
-
|
2677 |
-
|
2678 |
-
|
2679 |
-
|
2680 |
-
|
2681 |
-
|
2682 |
-
|
2683 |
-
|
2684 |
-
|
2685 |
-
*
|
2686 |
-
*
|
2687 |
-
*
|
2688 |
-
*
|
2689 |
-
|
2690 |
-
|
2691 |
-
|
2692 |
-
|
2693 |
-
|
2694 |
-
|
2695 |
-
|
2696 |
-
|
2697 |
-
|
2698 |
-
|
2699 |
-
*
|
2700 |
-
*
|
2701 |
-
*
|
2702 |
-
*
|
2703 |
-
|
2704 |
-
|
2705 |
-
|
2706 |
-
|
2707 |
-
|
2708 |
-
|
2709 |
-
|
2710 |
-
|
2711 |
-
|
2712 |
-
*
|
2713 |
-
*
|
2714 |
-
*
|
2715 |
-
*
|
2716 |
-
|
2717 |
-
|
2718 |
-
|
2719 |
-
|
2720 |
-
|
2721 |
-
|
2722 |
-
|
2723 |
-
|
2724 |
-
|
2725 |
-
*
|
2726 |
-
*
|
2727 |
-
*
|
2728 |
-
*
|
2729 |
-
|
2730 |
-
|
2731 |
-
|
2732 |
-
|
2733 |
-
|
2734 |
-
|
2735 |
-
|
2736 |
-
|
2737 |
-
|
2738 |
-
|
2739 |
-
|
2740 |
-
|
2741 |
-
|
2742 |
-
*
|
2743 |
-
*
|
2744 |
-
*
|
2745 |
-
*
|
2746 |
-
|
2747 |
-
|
2748 |
-
|
2749 |
-
|
2750 |
-
|
2751 |
-
|
2752 |
-
|
2753 |
-
|
2754 |
-
|
2755 |
-
\wfConfig::set( '
|
2756 |
-
\wfConfig::set( '
|
2757 |
-
\wfConfig::set( '
|
2758 |
-
\wfConfig::set( '
|
2759 |
-
\wfConfig::set( '
|
2760 |
-
\wfConfig::set( '
|
2761 |
-
|
2762 |
-
|
2763 |
-
|
2764 |
-
|
2765 |
-
|
2766 |
-
|
2767 |
-
|
2768 |
-
*
|
2769 |
-
*
|
2770 |
-
*
|
2771 |
-
*
|
2772 |
-
|
2773 |
-
|
2774 |
-
|
2775 |
-
|
2776 |
-
|
2777 |
-
|
2778 |
-
|
2779 |
-
|
2780 |
-
|
2781 |
-
|
2782 |
-
|
2783 |
-
|
2784 |
-
|
2785 |
-
|
2786 |
-
|
2787 |
-
|
2788 |
-
|
2789 |
-
|
2790 |
-
|
2791 |
-
|
2792 |
-
|
2793 |
-
|
2794 |
-
|
2795 |
-
|
2796 |
-
*
|
2797 |
-
*
|
2798 |
-
*
|
2799 |
-
*
|
2800 |
-
|
2801 |
-
|
2802 |
-
|
2803 |
-
|
2804 |
-
|
2805 |
-
|
2806 |
-
|
2807 |
-
|
2808 |
-
|
2809 |
-
|
2810 |
-
|
2811 |
-
|
2812 |
-
|
2813 |
-
|
2814 |
-
|
2815 |
-
|
2816 |
-
|
2817 |
-
|
2818 |
-
|
2819 |
-
|
2820 |
-
|
2821 |
-
|
2822 |
-
|
2823 |
-
|
2824 |
-
|
2825 |
-
|
2826 |
-
|
2827 |
-
|
2828 |
-
|
2829 |
-
|
2830 |
-
*
|
2831 |
-
*
|
2832 |
-
*
|
2833 |
-
*
|
2834 |
-
|
2835 |
-
|
2836 |
-
|
2837 |
-
|
2838 |
-
|
2839 |
-
|
2840 |
-
|
2841 |
-
|
2842 |
-
|
2843 |
-
|
2844 |
-
|
2845 |
-
|
2846 |
-
|
2847 |
-
|
2848 |
-
|
2849 |
-
|
2850 |
-
|
2851 |
-
|
2852 |
-
|
2853 |
-
|
2854 |
-
|
2855 |
-
|
2856 |
-
|
2857 |
-
|
2858 |
-
|
2859 |
-
|
2860 |
-
|
2861 |
-
|
2862 |
-
|
2863 |
-
|
2864 |
-
|
2865 |
-
|
2866 |
-
|
2867 |
-
}
|
2868 |
-
|
2869 |
-
|
2870 |
-
|
2871 |
-
|
2872 |
-
|
2873 |
-
|
2874 |
-
|
2875 |
-
|
2876 |
-
|
2877 |
-
|
2878 |
-
|
2879 |
-
|
2880 |
-
|
2881 |
-
|
2882 |
-
|
2883 |
-
|
2884 |
-
|
2885 |
-
|
2886 |
-
|
2887 |
-
|
2888 |
-
|
2889 |
-
|
2890 |
-
|
2891 |
-
|
2892 |
-
|
2893 |
-
|
2894 |
-
|
2895 |
-
|
2896 |
-
|
2897 |
-
|
2898 |
-
|
2899 |
-
|
2900 |
-
|
2901 |
-
|
2902 |
-
|
2903 |
-
|
2904 |
-
|
2905 |
-
if ( $
|
2906 |
-
|
2907 |
-
|
2908 |
-
|
2909 |
-
|
2910 |
-
|
2911 |
-
|
2912 |
-
|
2913 |
-
|
2914 |
-
|
2915 |
-
|
2916 |
-
|
2917 |
-
|
2918 |
-
|
2919 |
-
|
2920 |
-
|
2921 |
-
|
2922 |
-
|
2923 |
-
|
2924 |
-
|
2925 |
-
|
2926 |
-
|
2927 |
-
|
2928 |
-
|
2929 |
-
|
2930 |
-
|
2931 |
-
|
2932 |
-
|
2933 |
-
|
2934 |
-
|
2935 |
-
|
2936 |
-
|
2937 |
-
|
2938 |
-
|
2939 |
-
|
2940 |
-
|
2941 |
-
|
2942 |
-
|
2943 |
-
|
2944 |
-
|
2945 |
-
|
2946 |
-
|
2947 |
-
*
|
2948 |
-
|
2949 |
-
* @
|
2950 |
-
|
2951 |
-
|
2952 |
-
|
2953 |
-
|
2954 |
-
|
2955 |
-
|
2956 |
-
|
2957 |
-
|
2958 |
-
|
2959 |
-
|
2960 |
-
|
2961 |
-
|
2962 |
-
|
2963 |
-
|
2964 |
-
|
2965 |
-
|
2966 |
-
|
2967 |
-
|
2968 |
-
|
2969 |
-
|
2970 |
-
|
2971 |
-
|
2972 |
-
|
2973 |
-
|
2974 |
-
|
2975 |
-
|
2976 |
-
|
2977 |
-
|
2978 |
-
|
2979 |
-
|
2980 |
-
|
2981 |
-
*
|
2982 |
-
*
|
2983 |
-
*
|
2984 |
-
*
|
2985 |
-
|
2986 |
-
|
2987 |
-
|
2988 |
-
|
2989 |
-
|
2990 |
-
|
2991 |
-
|
2992 |
-
|
2993 |
-
|
2994 |
-
|
2995 |
-
|
2996 |
-
|
2997 |
-
|
2998 |
-
|
2999 |
-
|
3000 |
-
|
3001 |
-
|
3002 |
-
|
3003 |
-
|
3004 |
-
|
3005 |
-
|
3006 |
-
*
|
3007 |
-
*
|
3008 |
-
*
|
3009 |
-
*
|
3010 |
-
|
3011 |
-
|
3012 |
-
|
3013 |
-
|
3014 |
-
|
3015 |
-
|
3016 |
-
|
3017 |
-
|
3018 |
-
|
3019 |
-
|
3020 |
-
|
3021 |
-
|
3022 |
-
|
3023 |
-
|
3024 |
-
$url =
|
3025 |
-
$url = preg_replace( '
|
3026 |
-
|
3027 |
-
|
3028 |
-
$
|
3029 |
-
|
3030 |
-
|
3031 |
-
|
3032 |
-
|
3033 |
-
|
3034 |
-
|
3035 |
-
|
3036 |
-
|
3037 |
-
*
|
3038 |
-
*
|
3039 |
-
*
|
3040 |
-
*
|
3041 |
-
|
3042 |
-
|
3043 |
-
|
3044 |
-
|
3045 |
-
|
3046 |
-
|
3047 |
-
|
3048 |
-
|
3049 |
-
|
3050 |
-
|
3051 |
-
|
3052 |
-
|
3053 |
-
|
3054 |
-
|
3055 |
-
|
3056 |
-
|
3057 |
-
|
3058 |
-
|
3059 |
-
|
3060 |
-
|
3061 |
-
|
3062 |
-
|
3063 |
-
|
3064 |
-
|
3065 |
-
|
3066 |
-
*
|
3067 |
-
*
|
3068 |
-
*
|
3069 |
-
*
|
3070 |
-
|
3071 |
-
|
3072 |
-
|
3073 |
-
|
3074 |
-
|
3075 |
-
|
3076 |
-
|
3077 |
-
|
3078 |
-
|
3079 |
-
|
3080 |
-
|
3081 |
-
|
3082 |
-
|
3083 |
-
|
3084 |
-
|
3085 |
-
|
3086 |
-
|
3087 |
-
|
3088 |
-
|
3089 |
-
|
3090 |
-
|
3091 |
-
|
3092 |
-
|
3093 |
-
|
3094 |
-
|
3095 |
-
|
3096 |
-
*
|
3097 |
-
*
|
3098 |
-
*
|
3099 |
-
*
|
3100 |
-
|
3101 |
-
|
3102 |
-
|
3103 |
-
|
3104 |
-
|
3105 |
-
|
3106 |
-
|
3107 |
-
|
3108 |
-
|
3109 |
-
|
3110 |
-
|
3111 |
-
|
3112 |
-
|
3113 |
-
|
3114 |
-
|
3115 |
-
|
3116 |
-
|
3117 |
-
|
3118 |
-
|
3119 |
-
|
3120 |
-
|
3121 |
-
}
|
3122 |
-
if ( $s['
|
3123 |
-
$body .= '<br />
|
3124 |
-
|
3125 |
-
|
3126 |
-
|
3127 |
-
|
3128 |
-
|
3129 |
-
|
3130 |
-
|
3131 |
-
|
3132 |
-
|
3133 |
-
|
3134 |
-
|
3135 |
-
|
3136 |
-
|
3137 |
-
|
3138 |
-
|
3139 |
-
|
3140 |
-
|
3141 |
-
|
3142 |
-
|
3143 |
-
|
3144 |
-
|
3145 |
-
|
3146 |
-
|
3147 |
-
|
3148 |
-
|
3149 |
-
|
3150 |
-
*
|
3151 |
-
*
|
3152 |
-
*
|
3153 |
-
*
|
3154 |
-
|
3155 |
-
|
3156 |
-
|
3157 |
-
|
3158 |
-
|
3159 |
-
|
3160 |
-
|
3161 |
-
|
3162 |
-
|
3163 |
-
$ex =
|
3164 |
-
}
|
3165 |
-
|
3166 |
-
|
3167 |
-
|
3168 |
-
|
3169 |
-
|
3170 |
-
|
3171 |
-
|
3172 |
-
|
3173 |
-
|
3174 |
-
|
3175 |
-
|
3176 |
-
|
3177 |
-
|
3178 |
-
|
3179 |
-
|
3180 |
-
|
3181 |
-
|
3182 |
-
|
3183 |
-
|
3184 |
-
|
3185 |
-
|
3186 |
-
|
3187 |
-
|
3188 |
-
|
3189 |
-
|
3190 |
-
|
3191 |
-
*
|
3192 |
-
*
|
3193 |
-
*
|
3194 |
-
*
|
3195 |
-
|
3196 |
-
|
3197 |
-
|
3198 |
-
|
3199 |
-
|
3200 |
-
|
3201 |
-
|
3202 |
-
|
3203 |
-
|
3204 |
-
|
3205 |
-
|
3206 |
-
|
3207 |
-
|
3208 |
-
|
3209 |
-
|
3210 |
-
|
3211 |
-
|
3212 |
-
*
|
3213 |
-
*
|
3214 |
-
*
|
3215 |
-
*
|
3216 |
-
|
3217 |
-
|
3218 |
-
|
3219 |
-
|
3220 |
-
|
3221 |
-
|
3222 |
-
|
3223 |
-
|
3224 |
-
|
3225 |
-
|
3226 |
-
$
|
3227 |
-
$
|
3228 |
-
|
3229 |
-
|
3230 |
-
|
3231 |
-
|
3232 |
-
|
3233 |
-
|
3234 |
-
|
3235 |
-
|
3236 |
-
|
3237 |
-
|
3238 |
-
|
3239 |
-
|
3240 |
-
|
3241 |
-
|
3242 |
-
|
3243 |
-
|
3244 |
-
|
3245 |
-
|
3246 |
-
|
3247 |
-
|
3248 |
-
|
3249 |
-
|
3250 |
-
|
3251 |
-
|
3252 |
-
|
3253 |
-
|
3254 |
-
|
3255 |
-
|
3256 |
-
|
3257 |
-
*
|
3258 |
-
*
|
3259 |
-
*
|
3260 |
-
*
|
3261 |
-
|
3262 |
-
|
3263 |
-
|
3264 |
-
|
3265 |
-
|
3266 |
-
|
3267 |
-
$
|
3268 |
-
$
|
3269 |
-
$
|
3270 |
-
$
|
3271 |
-
$
|
3272 |
-
|
3273 |
-
$
|
3274 |
-
|
3275 |
-
|
3276 |
-
|
3277 |
-
|
3278 |
-
|
3279 |
-
|
3280 |
-
|
3281 |
-
|
3282 |
-
|
3283 |
-
|
3284 |
-
|
3285 |
-
|
3286 |
-
|
3287 |
-
|
3288 |
-
|
3289 |
-
|
3290 |
-
|
3291 |
-
|
3292 |
-
|
3293 |
-
|
3294 |
-
|
3295 |
-
|
3296 |
-
|
3297 |
-
|
3298 |
-
|
3299 |
-
|
3300 |
-
|
3301 |
-
|
3302 |
-
|
3303 |
-
|
3304 |
-
|
3305 |
-
|
3306 |
-
|
3307 |
-
|
3308 |
-
|
3309 |
-
|
3310 |
-
|
3311 |
-
'
|
3312 |
-
|
3313 |
-
|
3314 |
-
|
3315 |
-
|
3316 |
-
|
3317 |
-
?>
|
3318 |
-
|
3319 |
-
|
3320 |
-
|
3321 |
-
|
3322 |
-
|
3323 |
-
|
3324 |
-
|
3325 |
-
|
3326 |
-
|
3327 |
-
|
3328 |
-
|
3329 |
-
|
3330 |
-
|
3331 |
-
|
3332 |
-
|
3333 |
-
|
3334 |
-
|
3335 |
-
|
3336 |
-
<
|
3337 |
-
</div>
|
3338 |
-
|
3339 |
-
|
3340 |
-
|
3341 |
-
|
3342 |
-
|
3343 |
-
|
3344 |
-
|
3345 |
-
|
3346 |
-
|
3347 |
-
|
3348 |
-
|
3349 |
-
|
3350 |
-
|
3351 |
-
|
3352 |
-
'
|
3353 |
-
|
3354 |
-
|
3355 |
-
|
3356 |
-
|
3357 |
-
|
3358 |
-
|
3359 |
-
|
3360 |
-
|
3361 |
-
|
3362 |
-
|
3363 |
-
|
3364 |
-
|
3365 |
-
|
3366 |
-
|
3367 |
-
|
3368 |
-
|
3369 |
-
|
3370 |
-
|
3371 |
-
|
3372 |
-
|
3373 |
-
|
3374 |
-
|
3375 |
-
|
3376 |
-
|
3377 |
-
'
|
3378 |
-
|
3379 |
-
|
3380 |
-
|
3381 |
-
|
3382 |
-
|
3383 |
-
|
3384 |
-
|
3385 |
-
|
3386 |
-
|
3387 |
-
|
3388 |
-
|
3389 |
-
|
3390 |
-
|
3391 |
-
|
3392 |
-
|
3393 |
-
<
|
3394 |
-
</div>
|
3395 |
-
|
3396 |
-
|
3397 |
-
|
3398 |
-
|
3399 |
-
|
3400 |
-
|
3401 |
-
|
3402 |
-
|
3403 |
-
|
3404 |
-
|
3405 |
-
|
3406 |
-
|
3407 |
-
|
3408 |
-
|
3409 |
-
|
3410 |
-
|
3411 |
-
|
3412 |
-
|
3413 |
-
|
3414 |
-
'
|
3415 |
-
|
3416 |
-
|
3417 |
-
|
3418 |
-
|
3419 |
-
|
3420 |
-
|
3421 |
-
|
3422 |
-
|
3423 |
-
|
3424 |
-
|
3425 |
-
|
3426 |
-
|
3427 |
-
|
3428 |
-
$
|
3429 |
-
$
|
3430 |
-
|
3431 |
-
|
3432 |
-
|
3433 |
-
|
3434 |
-
|
3435 |
-
|
3436 |
-
|
3437 |
-
|
3438 |
-
|
3439 |
-
|
3440 |
-
|
3441 |
-
|
3442 |
-
|
3443 |
-
$output
|
3444 |
-
|
3445 |
-
|
3446 |
-
|
3447 |
-
|
3448 |
-
|
3449 |
-
|
3450 |
-
|
3451 |
-
|
3452 |
-
|
3453 |
-
|
3454 |
-
|
3455 |
-
|
3456 |
-
|
3457 |
-
|
3458 |
-
|
3459 |
-
|
3460 |
-
|
3461 |
-
|
3462 |
-
|
3463 |
-
|
3464 |
-
|
3465 |
-
|
3466 |
-
|
3467 |
-
|
3468 |
-
|
3469 |
-
|
3470 |
-
|
3471 |
-
|
3472 |
-
|
3473 |
-
|
3474 |
-
<
|
3475 |
-
</div>
|
3476 |
-
|
3477 |
-
|
3478 |
-
|
3479 |
-
|
3480 |
-
|
3481 |
-
|
3482 |
-
|
3483 |
-
|
3484 |
-
|
3485 |
-
|
3486 |
-
|
3487 |
-
|
3488 |
-
|
3489 |
-
|
3490 |
-
'
|
3491 |
-
|
3492 |
-
|
3493 |
-
|
3494 |
-
'
|
3495 |
-
|
3496 |
-
|
3497 |
-
|
3498 |
-
'
|
3499 |
-
|
3500 |
-
|
3501 |
-
|
3502 |
-
'
|
3503 |
-
|
3504 |
-
|
3505 |
-
|
3506 |
-
'
|
3507 |
-
|
3508 |
-
|
3509 |
-
|
3510 |
-
|
3511 |
-
|
3512 |
-
'
|
3513 |
-
'
|
3514 |
-
|
3515 |
-
|
3516 |
-
|
3517 |
-
|
3518 |
-
|
3519 |
-
|
3520 |
-
|
3521 |
-
|
3522 |
-
|
3523 |
-
'
|
3524 |
-
|
3525 |
-
|
3526 |
-
|
3527 |
-
|
3528 |
-
|
3529 |
-
|
3530 |
-
|
3531 |
-
|
3532 |
-
|
3533 |
-
'
|
3534 |
-
|
3535 |
-
|
3536 |
-
|
3537 |
-
|
3538 |
-
|
3539 |
-
|
3540 |
-
|
3541 |
-
|
3542 |
-
|
3543 |
-
|
3544 |
-
'
|
3545 |
-
'
|
3546 |
-
'
|
3547 |
-
|
3548 |
-
|
3549 |
-
|
3550 |
-
|
3551 |
-
|
3552 |
-
|
3553 |
-
|
3554 |
-
|
3555 |
-
|
3556 |
-
|
3557 |
-
|
3558 |
-
|
3559 |
-
|
3560 |
-
|
3561 |
-
|
3562 |
-
'
|
3563 |
-
|
3564 |
-
|
3565 |
-
|
3566 |
-
'
|
3567 |
-
|
3568 |
-
|
3569 |
-
|
3570 |
-
'
|
3571 |
-
|
3572 |
-
|
3573 |
-
|
3574 |
-
'
|
3575 |
-
|
3576 |
-
|
3577 |
-
|
3578 |
-
'
|
3579 |
-
|
3580 |
-
|
3581 |
-
|
3582 |
-
'
|
3583 |
-
|
3584 |
-
|
3585 |
-
|
3586 |
-
|
3587 |
-
|
3588 |
-
|
3589 |
-
|
3590 |
-
|
3591 |
-
'
|
3592 |
-
|
3593 |
-
|
3594 |
-
|
3595 |
-
'
|
3596 |
-
|
3597 |
-
|
3598 |
-
|
3599 |
-
'
|
3600 |
-
|
3601 |
-
|
3602 |
-
|
3603 |
-
'
|
3604 |
-
|
3605 |
-
|
3606 |
-
|
3607 |
-
'
|
3608 |
-
|
3609 |
-
|
3610 |
-
|
3611 |
-
'
|
3612 |
-
|
3613 |
-
|
3614 |
-
|
3615 |
-
'
|
3616 |
-
|
3617 |
-
|
3618 |
-
|
3619 |
-
|
3620 |
-
|
3621 |
-
|
3622 |
-
|
3623 |
-
|
3624 |
-
'
|
3625 |
-
|
3626 |
-
|
3627 |
-
|
3628 |
-
'
|
3629 |
-
|
3630 |
-
|
3631 |
-
|
3632 |
-
|
3633 |
-
|
3634 |
-
|
3635 |
-
|
3636 |
-
|
3637 |
-
|
3638 |
-
|
3639 |
-
|
3640 |
-
|
3641 |
-
|
3642 |
-
|
3643 |
-
|
3644 |
-
|
3645 |
-
|
3646 |
-
|
3647 |
-
|
3648 |
-
|
3649 |
-
|
3650 |
-
|
3651 |
-
|
3652 |
-
|
3653 |
-
|
3654 |
-
|
3655 |
-
|
3656 |
-
|
3657 |
-
|
3658 |
-
|
3659 |
-
|
3660 |
-
|
3661 |
-
|
3662 |
-
|
3663 |
-
|
3664 |
-
|
3665 |
-
|
3666 |
-
|
3667 |
-
<
|
3668 |
-
</div>
|
3669 |
-
|
3670 |
-
|
3671 |
-
|
3672 |
-
|
3673 |
-
|
3674 |
-
|
3675 |
-
|
3676 |
-
|
3677 |
-
|
3678 |
-
|
3679 |
-
|
3680 |
-
|
3681 |
-
|
3682 |
-
|
3683 |
-
|
3684 |
-
|
3685 |
-
|
3686 |
-
|
3687 |
-
|
3688 |
-
|
3689 |
-
|
3690 |
-
|
3691 |
-
|
3692 |
-
|
3693 |
-
|
3694 |
-
|
3695 |
-
|
3696 |
-
|
3697 |
-
|
3698 |
-
|
3699 |
-
|
3700 |
-
|
3701 |
-
|
3702 |
-
|
3703 |
-
<
|
3704 |
-
</div>
|
3705 |
-
|
3706 |
-
|
3707 |
-
|
3708 |
-
|
3709 |
-
|
3710 |
-
|
3711 |
-
|
3712 |
-
|
3713 |
-
|
3714 |
-
|
3715 |
-
|
3716 |
-
|
3717 |
-
|
3718 |
-
|
3719 |
-
|
3720 |
-
|
3721 |
-
|
3722 |
-
|
3723 |
-
|
3724 |
-
|
3725 |
-
|
3726 |
-
|
3727 |
-
|
3728 |
-
|
3729 |
-
|
3730 |
-
|
3731 |
-
|
3732 |
-
|
3733 |
-
|
3734 |
-
|
3735 |
-
|
3736 |
-
|
3737 |
-
|
3738 |
-
|
3739 |
-
|
3740 |
-
|
3741 |
-
<
|
3742 |
-
</div>
|
3743 |
-
|
3744 |
-
|
3745 |
-
|
3746 |
-
|
3747 |
-
|
3748 |
-
|
3749 |
-
|
3750 |
-
|
3751 |
-
|
3752 |
-
|
3753 |
-
|
3754 |
-
|
3755 |
-
<
|
3756 |
-
|
3757 |
-
|
3758 |
-
|
3759 |
-
|
3760 |
-
|
3761 |
-
|
3762 |
-
|
3763 |
-
|
3764 |
-
|
3765 |
-
|
3766 |
-
|
3767 |
-
|
3768 |
-
|
3769 |
-
|
3770 |
-
|
3771 |
-
|
3772 |
-
|
3773 |
-
|
3774 |
-
|
3775 |
-
|
3776 |
-
|
3777 |
-
|
3778 |
-
|
3779 |
-
|
3780 |
-
<
|
3781 |
-
</div>
|
3782 |
-
|
3783 |
-
|
3784 |
-
|
3785 |
-
|
3786 |
-
|
3787 |
-
|
3788 |
-
|
3789 |
-
|
3790 |
-
|
3791 |
-
|
3792 |
-
|
3793 |
-
|
3794 |
-
|
3795 |
-
|
3796 |
-
|
3797 |
-
|
3798 |
-
|
3799 |
-
|
3800 |
-
|
3801 |
-
|
3802 |
-
|
3803 |
-
|
3804 |
-
|
3805 |
-
|
3806 |
-
|
3807 |
-
|
3808 |
-
|
3809 |
-
|
3810 |
-
|
3811 |
-
|
3812 |
-
|
3813 |
-
|
3814 |
-
|
3815 |
-
|
3816 |
-
|
3817 |
-
$wfdb
|
3818 |
-
|
3819 |
-
|
3820 |
-
|
3821 |
-
|
3822 |
-
|
3823 |
-
|
3824 |
-
|
3825 |
-
|
3826 |
-
|
3827 |
-
|
3828 |
-
|
3829 |
-
|
3830 |
-
|
3831 |
-
|
3832 |
-
|
3833 |
-
|
3834 |
-
<
|
3835 |
-
</div>
|
3836 |
-
|
3837 |
-
|
3838 |
-
|
3839 |
-
|
3840 |
-
|
3841 |
-
|
3842 |
-
|
3843 |
-
|
3844 |
-
|
3845 |
-
|
3846 |
-
|
3847 |
-
|
3848 |
-
|
3849 |
-
|
3850 |
-
|
3851 |
-
|
3852 |
-
|
3853 |
-
|
3854 |
-
|
3855 |
-
|
3856 |
-
|
3857 |
-
|
3858 |
-
|
3859 |
-
|
3860 |
-
|
3861 |
-
|
3862 |
-
|
3863 |
-
|
3864 |
-
|
3865 |
-
|
3866 |
-
|
3867 |
-
|
3868 |
-
|
3869 |
-
|
3870 |
-
|
3871 |
-
|
3872 |
-
|
3873 |
-
|
3874 |
-
|
3875 |
-
|
3876 |
-
|
3877 |
-
|
3878 |
-
|
3879 |
-
|
3880 |
-
|
3881 |
-
|
3882 |
-
|
3883 |
-
|
3884 |
-
|
3885 |
-
<
|
3886 |
-
</div>
|
3887 |
-
|
3888 |
-
|
3889 |
-
|
3890 |
-
|
3891 |
-
|
3892 |
-
|
3893 |
-
|
3894 |
-
|
3895 |
-
|
3896 |
-
|
3897 |
-
|
3898 |
-
|
3899 |
-
|
3900 |
-
|
3901 |
-
<
|
3902 |
-
|
3903 |
-
|
3904 |
-
|
3905 |
-
|
3906 |
-
|
3907 |
-
|
3908 |
-
|
3909 |
-
|
3910 |
-
|
3911 |
-
|
3912 |
-
|
3913 |
-
|
3914 |
-
|
3915 |
-
|
3916 |
-
|
3917 |
-
|
3918 |
-
|
3919 |
-
|
3920 |
-
|
3921 |
-
|
3922 |
-
|
3923 |
-
|
3924 |
-
|
3925 |
-
|
3926 |
-
|
3927 |
-
|
3928 |
-
|
3929 |
-
|
3930 |
-
|
3931 |
-
|
3932 |
-
|
3933 |
-
|
3934 |
-
|
3935 |
-
|
3936 |
-
|
3937 |
-
|
3938 |
-
|
3939 |
-
|
3940 |
-
|
3941 |
-
|
3942 |
-
|
3943 |
-
|
3944 |
-
|
3945 |
-
|
3946 |
-
|
3947 |
-
|
3948 |
-
|
3949 |
-
|
3950 |
-
|
3951 |
-
|
3952 |
-
|
3953 |
-
|
3954 |
-
|
3955 |
-
|
3956 |
-
|
3957 |
-
|
3958 |
-
|
3959 |
-
|
3960 |
-
|
3961 |
-
|
3962 |
-
|
3963 |
-
|
3964 |
-
|
3965 |
-
|
3966 |
-
|
3967 |
-
|
3968 |
-
|
3969 |
-
*
|
3970 |
-
*
|
3971 |
-
*
|
3972 |
-
*
|
3973 |
-
|
3974 |
-
|
3975 |
-
|
3976 |
-
|
3977 |
-
|
3978 |
-
$
|
3979 |
-
|
3980 |
-
|
3981 |
-
|
3982 |
-
|
3983 |
-
|
3984 |
-
|
3985 |
-
|
3986 |
-
|
3987 |
-
|
3988 |
-
|
3989 |
-
*
|
3990 |
-
*
|
3991 |
-
*
|
3992 |
-
*
|
3993 |
-
|
3994 |
-
|
3995 |
-
|
3996 |
-
|
3997 |
-
|
3998 |
-
|
3999 |
-
|
4000 |
-
|
4001 |
-
|
4002 |
-
|
4003 |
-
|
4004 |
-
|
4005 |
-
|
4006 |
-
*
|
4007 |
-
*
|
4008 |
-
*
|
4009 |
-
*
|
4010 |
-
|
4011 |
-
|
4012 |
-
|
4013 |
-
|
4014 |
-
|
4015 |
-
|
4016 |
-
|
4017 |
-
|
4018 |
-
|
4019 |
-
|
4020 |
-
|
4021 |
-
return array( 'ok' => 1 );
|
4022 |
-
}
|
4023 |
-
}
|
1 |
+
<?php
|
2 |
+
/**
|
3 |
+
* MainWP Wordfence
|
4 |
+
*
|
5 |
+
* MainWP Wordfence extension handler.
|
6 |
+
*
|
7 |
+
* @link https://mainwp.com/extension/wordfence/
|
8 |
+
* @package MainWP\Child
|
9 |
+
*
|
10 |
+
* Credits
|
11 |
+
*
|
12 |
+
* Plugin-Name: Wordfence Security
|
13 |
+
* Plugin-URI: https://www.wordfence.com/
|
14 |
+
* Author: Wordfence
|
15 |
+
* Author URI: https://www.wordfence.com/
|
16 |
+
*/
|
17 |
+
|
18 |
+
namespace MainWP\Child;
|
19 |
+
|
20 |
+
// phpcs:disable PSR1.Classes.ClassDeclaration, WordPress.WP.AlternativeFunctions -- Required to achieve desired results, pull request solutions appreciated.
|
21 |
+
|
22 |
+
/**
|
23 |
+
* Class MainWP_Child_Wordfence
|
24 |
+
*
|
25 |
+
* MainWP Wordfence extension handler.
|
26 |
+
*/
|
27 |
+
class MainWP_Child_Wordfence {
|
28 |
+
|
29 |
+
/**
|
30 |
+
* Public static variable to hold the single instance of the class.
|
31 |
+
*
|
32 |
+
* @var mixed Default null
|
33 |
+
*/
|
34 |
+
public static $instance = null;
|
35 |
+
|
36 |
+
/**
|
37 |
+
* Public variable to hold the information if the Wordfence plugin is installed on the child site.
|
38 |
+
*
|
39 |
+
* @var bool If Wordfence intalled, return true, if not, return false.
|
40 |
+
*/
|
41 |
+
public $is_wordfence_installed = false;
|
42 |
+
|
43 |
+
/**
|
44 |
+
* Public variable to hold the information about the language domain.
|
45 |
+
*
|
46 |
+
* @var string 'mainwp-child' languge domain.
|
47 |
+
*/
|
48 |
+
public $plugin_translate = 'mainwp-child';
|
49 |
+
|
50 |
+
const OPTIONS_TYPE_GLOBAL = 'global';
|
51 |
+
const OPTIONS_TYPE_FIREWALL = 'firewall';
|
52 |
+
const OPTIONS_TYPE_BLOCKING = 'blocking';
|
53 |
+
const OPTIONS_TYPE_SCANNER = 'scanner';
|
54 |
+
const OPTIONS_TYPE_TWO_FACTOR = 'twofactor';
|
55 |
+
const OPTIONS_TYPE_LIVE_TRAFFIC = 'livetraffic';
|
56 |
+
const OPTIONS_TYPE_COMMENT_SPAM = 'commentspam';
|
57 |
+
const OPTIONS_TYPE_DIAGNOSTICS = 'diagnostics';
|
58 |
+
const OPTIONS_TYPE_ALL = 'alloptions';
|
59 |
+
|
60 |
+
/**
|
61 |
+
* Public static variable to hold the information about Wordfence options.
|
62 |
+
*
|
63 |
+
* @var array Supported Wordfence options.
|
64 |
+
*/
|
65 |
+
public static $options_filter = array(
|
66 |
+
'alertEmails',
|
67 |
+
'displayTopLevelOptions',
|
68 |
+
'displayTopLevelBlocking',
|
69 |
+
'displayTopLevelLiveTraffic',
|
70 |
+
'alertOn_adminLogin',
|
71 |
+
'alertOn_firstAdminLoginOnly',
|
72 |
+
'alertOn_scanIssues', // new.
|
73 |
+
'alertOn_wafDeactivated', // new.
|
74 |
+
'alertOn_severityLevel', // new.
|
75 |
+
'alertOn_loginLockout',
|
76 |
+
'alertOn_breachLogin',
|
77 |
+
'alertOn_lostPasswdForm',
|
78 |
+
'alertOn_nonAdminLogin',
|
79 |
+
'alertOn_firstNonAdminLoginOnly',
|
80 |
+
'alertOn_wordfenceDeactivated',
|
81 |
+
'alertOn_update',
|
82 |
+
'alertOn_block',
|
83 |
+
'alert_maxHourly',
|
84 |
+
'autoUpdate',
|
85 |
+
'firewallEnabled',
|
86 |
+
'howGetIPs',
|
87 |
+
'liveTrafficEnabled',
|
88 |
+
'loginSec_blockAdminReg',
|
89 |
+
'loginSec_countFailMins',
|
90 |
+
'loginSec_disableAuthorScan',
|
91 |
+
'notification_updatesNeeded',
|
92 |
+
'notification_securityAlerts',
|
93 |
+
'notification_promotions',
|
94 |
+
'notification_blogHighlights',
|
95 |
+
'notification_productUpdates',
|
96 |
+
'notification_scanStatus',
|
97 |
+
'loginSec_lockInvalidUsers',
|
98 |
+
'loginSec_breachPasswds_enabled',
|
99 |
+
'loginSec_breachPasswds',
|
100 |
+
'loginSec_lockoutMins',
|
101 |
+
'loginSec_maskLoginErrors',
|
102 |
+
'loginSec_maxFailures',
|
103 |
+
'loginSec_maxForgotPasswd',
|
104 |
+
'loginSec_strongPasswds_enabled',
|
105 |
+
'loginSec_strongPasswds',
|
106 |
+
'loginSec_userBlacklist',
|
107 |
+
'loginSecurityEnabled',
|
108 |
+
'other_scanOutside',
|
109 |
+
'scan_exclude',
|
110 |
+
'scan_maxIssues',
|
111 |
+
'scan_maxDuration',
|
112 |
+
'scansEnabled_checkReadableConfig',
|
113 |
+
'scansEnabled_suspectedFiles',
|
114 |
+
'scansEnabled_comments',
|
115 |
+
'scansEnabled_core',
|
116 |
+
'scansEnabled_diskSpace',
|
117 |
+
'scansEnabled_dns',
|
118 |
+
'scansEnabled_fileContents',
|
119 |
+
'scansEnabled_fileContentsGSB',
|
120 |
+
'scan_include_extra',
|
121 |
+
'scansEnabled_checkHowGetIPs',
|
122 |
+
'scansEnabled_highSense',
|
123 |
+
'lowResourceScansEnabled',
|
124 |
+
'scansEnabled_malware',
|
125 |
+
'scansEnabled_oldVersions',
|
126 |
+
'scansEnabled_suspiciousAdminUsers',
|
127 |
+
'scansEnabled_passwds',
|
128 |
+
'scansEnabled_plugins',
|
129 |
+
'scansEnabled_coreUnknown',
|
130 |
+
'scansEnabled_posts',
|
131 |
+
'scansEnabled_scanImages',
|
132 |
+
'scansEnabled_themes',
|
133 |
+
'scheduledScansEnabled',
|
134 |
+
'securityLevel',
|
135 |
+
'neverBlockBG',
|
136 |
+
'maxGlobalRequests',
|
137 |
+
'maxGlobalRequests_action',
|
138 |
+
'maxRequestsCrawlers',
|
139 |
+
'maxRequestsCrawlers_action',
|
140 |
+
'max404Crawlers',
|
141 |
+
'max404Crawlers_action',
|
142 |
+
'maxRequestsHumans',
|
143 |
+
'maxRequestsHumans_action',
|
144 |
+
'max404Humans',
|
145 |
+
'max404Humans_action',
|
146 |
+
'blockedTime',
|
147 |
+
'liveTraf_ignorePublishers',
|
148 |
+
'liveTraf_displayExpandedRecords',
|
149 |
+
'liveTraf_ignoreUsers',
|
150 |
+
'liveTraf_ignoreIPs',
|
151 |
+
'liveTraf_ignoreUA',
|
152 |
+
'liveTraf_maxRows',
|
153 |
+
'liveTraf_maxAge',
|
154 |
+
'displayTopLevelLiveTraffic',
|
155 |
+
'whitelisted',
|
156 |
+
'bannedURLs',
|
157 |
+
'other_hideWPVersion',
|
158 |
+
'other_noAnonMemberComments',
|
159 |
+
'other_scanComments',
|
160 |
+
'other_pwStrengthOnUpdate',
|
161 |
+
'other_WFNet',
|
162 |
+
'maxMem',
|
163 |
+
'maxExecutionTime',
|
164 |
+
'actUpdateInterval',
|
165 |
+
'debugOn',
|
166 |
+
'deleteTablesOnDeact',
|
167 |
+
'liveActivityPauseEnabled',
|
168 |
+
'startScansRemotely',
|
169 |
+
'disableCodeExecutionUploads',
|
170 |
+
'scansEnabled_checkGSB',
|
171 |
+
'checkSpamIP',
|
172 |
+
'spamvertizeCheck',
|
173 |
+
'email_summary_enabled',
|
174 |
+
'email_summary_dashboard_widget_enabled',
|
175 |
+
'ssl_verify',
|
176 |
+
'email_summary_interval',
|
177 |
+
'email_summary_excluded_directories',
|
178 |
+
'allowed404s',
|
179 |
+
'wafAlertWhitelist',
|
180 |
+
'wafAlertOnAttacks',
|
181 |
+
'howGetIPs_trusted_proxies',
|
182 |
+
'other_bypassLitespeedNoabort',
|
183 |
+
'disableWAFIPBlocking',
|
184 |
+
'other_blockBadPOST',
|
185 |
+
'blockCustomText',
|
186 |
+
'displayTopLevelBlocking',
|
187 |
+
'betaThreatDefenseFeed',
|
188 |
+
'wordfenceI18n',
|
189 |
+
'avoid_php_input',
|
190 |
+
'scanType',
|
191 |
+
'schedMode',
|
192 |
+
'wafStatus',
|
193 |
+
'learningModeGracePeriodEnabled',
|
194 |
+
'learningModeGracePeriod',
|
195 |
+
);
|
196 |
+
|
197 |
+
/**
|
198 |
+
* Public static variable to hold the information about Wordfence diagnostic parameters.
|
199 |
+
*
|
200 |
+
* @var array Supported diagnostic parameters.
|
201 |
+
*/
|
202 |
+
public static $diagnosticParams = array(
|
203 |
+
'debugOn',
|
204 |
+
'startScansRemotely',
|
205 |
+
'ssl_verify',
|
206 |
+
'betaThreatDefenseFeed',
|
207 |
+
'wordfenceI18n',
|
208 |
+
'avoid_php_input',
|
209 |
+
);
|
210 |
+
|
211 |
+
/**
|
212 |
+
* Public static variable to hold the information about Wordfence firewall options.
|
213 |
+
*
|
214 |
+
* @var array Supported firewall options.
|
215 |
+
*/
|
216 |
+
public static $firewall_options_filter = array(
|
217 |
+
'wafStatus',
|
218 |
+
'learningModeGracePeriodEnabled',
|
219 |
+
'learningModeGracePeriod',
|
220 |
+
);
|
221 |
+
|
222 |
+
/**
|
223 |
+
* Method instance()
|
224 |
+
*
|
225 |
+
* Create a public static instance.
|
226 |
+
*
|
227 |
+
* @return mixed Class instance.
|
228 |
+
*/
|
229 |
+
public static function instance() {
|
230 |
+
if ( null === self::$instance ) {
|
231 |
+
self::$instance = new self();
|
232 |
+
}
|
233 |
+
|
234 |
+
return self::$instance;
|
235 |
+
}
|
236 |
+
|
237 |
+
/**
|
238 |
+
* MainWP_Child_Wordfence constructor.
|
239 |
+
*
|
240 |
+
* Run any time class is called.
|
241 |
+
*/
|
242 |
+
public function __construct() {
|
243 |
+
add_action( 'mainwp_child_deactivation', array( $this, 'deactivation' ) );
|
244 |
+
|
245 |
+
require_once ABSPATH . 'wp-admin/includes/plugin.php';
|
246 |
+
|
247 |
+
if ( is_plugin_active( 'wordfence/wordfence.php' ) && file_exists( plugin_dir_path( __FILE__ ) . '../../wordfence/wordfence.php' ) ) {
|
248 |
+
require_once plugin_dir_path( __FILE__ ) . '../../wordfence/wordfence.php';
|
249 |
+
$this->is_wordfence_installed = true;
|
250 |
+
}
|
251 |
+
|
252 |
+
if ( $this->is_wordfence_installed ) {
|
253 |
+
add_action( 'wp_ajax_mainwp_wordfence_download_htaccess', array( $this, 'download_htaccess' ) );
|
254 |
+
}
|
255 |
+
}
|
256 |
+
|
257 |
+
/**
|
258 |
+
* Method wordfence_init()
|
259 |
+
*
|
260 |
+
* Initiate action hooks.
|
261 |
+
*
|
262 |
+
* @return void
|
263 |
+
*/
|
264 |
+
public function wordfence_init() {
|
265 |
+
if ( ! $this->is_wordfence_installed ) {
|
266 |
+
return;
|
267 |
+
}
|
268 |
+
add_action( 'mainwp_child_site_stats', array( $this, 'do_site_stats' ) );
|
269 |
+
if ( 'hide' === get_option( 'mainwp_wordfence_hide_plugin' ) ) {
|
270 |
+
add_filter( 'all_plugins', array( $this, 'all_plugins' ) );
|
271 |
+
add_action( 'admin_menu', array( $this, 'remove_menu' ) );
|
272 |
+
add_action( 'admin_init', array( $this, 'admin_init' ) );
|
273 |
+
}
|
274 |
+
$this->init_cron();
|
275 |
+
}
|
276 |
+
|
277 |
+
/**
|
278 |
+
* Method admin_init()
|
279 |
+
*
|
280 |
+
* Remove remove the Wordfence meta-box (widget) when 'admin_init' action fires.
|
281 |
+
*/
|
282 |
+
public function admin_init() {
|
283 |
+
remove_meta_box( 'wordfence_activity_report_widget', 'dashboard', 'normal' );
|
284 |
+
}
|
285 |
+
|
286 |
+
/**
|
287 |
+
* Method do_site_stats()
|
288 |
+
*
|
289 |
+
* Add support for the reporting system.
|
290 |
+
*/
|
291 |
+
public function do_site_stats() {
|
292 |
+
do_action( 'mainwp_child_reports_log', 'wordfence' );
|
293 |
+
}
|
294 |
+
|
295 |
+
/**
|
296 |
+
* Method do_reports_log()
|
297 |
+
*
|
298 |
+
* Add Wordfence data to the reports reports database table.
|
299 |
+
*
|
300 |
+
* @param string $ext Current extension.
|
301 |
+
*
|
302 |
+
* @uses \MainWP\Child\MainWP_Child_DB::to_query()
|
303 |
+
* @uses \MainWP\Child\MainWP_Child_DB::fetch_array()
|
304 |
+
*/
|
305 |
+
public function do_reports_log( $ext = '' ) {
|
306 |
+
if ( 'wordfence' !== $ext ) {
|
307 |
+
return;
|
308 |
+
}
|
309 |
+
if ( ! $this->is_wordfence_installed ) {
|
310 |
+
return;
|
311 |
+
}
|
312 |
+
|
313 |
+
/**
|
314 |
+
* Object, providing access to the WordPress database.
|
315 |
+
*
|
316 |
+
* @global object $wpdb WordPress Database instance.
|
317 |
+
*/
|
318 |
+
global $wpdb;
|
319 |
+
|
320 |
+
$lastcheck = get_option( 'mainwp_wordfence_lastcheck_scan' );
|
321 |
+
if ( false == $lastcheck ) {
|
322 |
+
$lastcheck = time() - 3600 * 24 * 10;
|
323 |
+
}
|
324 |
+
|
325 |
+
$table_wfStatus = \wfDB::networkTable( 'wfStatus' );
|
326 |
+
|
327 |
+
// fix prepare sql empty.
|
328 |
+
$sql = sprintf( "SELECT * FROM {$table_wfStatus} WHERE ctime >= %d AND level = 10 AND type = 'info' ", $lastcheck );
|
329 |
+
$sql .= " AND msg LIKE 'SUM_FINAL%' ";
|
330 |
+
$rows = MainWP_Child_DB::to_query( $sql, $wpdb->dbh );
|
331 |
+
|
332 |
+
$scan_time = array();
|
333 |
+
if ( $rows ) {
|
334 |
+
while ( $row = MainWP_Child_DB::fetch_array( $rows ) ) {
|
335 |
+
$scan_time[ $row['ctime'] ] = $row['msg'];
|
336 |
+
}
|
337 |
+
}
|
338 |
+
|
339 |
+
if ( $scan_time ) {
|
340 |
+
$message = 'Wordfence scan completed';
|
341 |
+
foreach ( $scan_time as $ctime => $details ) {
|
342 |
+
$sql = sprintf( "SELECT * FROM {$table_wfStatus} WHERE ctime > %d AND ctime < %d AND level = 10 AND type = 'info' ", $ctime, $ctime + 100 ); // to get nearest SUM_FINAL msg.
|
343 |
+
$sql .= " AND msg LIKE 'SUM_FINAL%' ";
|
344 |
+
|
345 |
+
$sum_rows = MainWP_Child_DB::to_query( $sql, $wpdb->dbh );
|
346 |
+
$result = '';
|
347 |
+
if ( $sum_rows ) {
|
348 |
+
$sum_row = MainWP_Child_DB::fetch_array( $sum_rows );
|
349 |
+
if ( is_array( $sum_row ) && isset( $sum_row['msg'] ) ) {
|
350 |
+
$result = $sum_row['msg'];
|
351 |
+
}
|
352 |
+
}
|
353 |
+
do_action( 'mainwp_reports_wordfence_scan', $message, $ctime, $details, $result );
|
354 |
+
}
|
355 |
+
}
|
356 |
+
|
357 |
+
update_option( 'mainwp_wordfence_lastcheck_scan', time() );
|
358 |
+
}
|
359 |
+
|
360 |
+
/**
|
361 |
+
* Method get_substr()
|
362 |
+
*
|
363 |
+
* Get sub string.
|
364 |
+
*
|
365 |
+
* @param string $s String to get sub string.
|
366 |
+
* @param int $count count number.
|
367 |
+
*/
|
368 |
+
public function get_substr( $s, $count = 2 ) {
|
369 |
+
$p = 0;
|
370 |
+
for ( $i = 0; $i < $count; $i++ ) {
|
371 |
+
$p = strpos( $s, ' ', $p + 1 );
|
372 |
+
}
|
373 |
+
return substr( $s, 0, $p );
|
374 |
+
}
|
375 |
+
|
376 |
+
/**
|
377 |
+
* Method init_cron()
|
378 |
+
*
|
379 |
+
* Manage scheduled events.
|
380 |
+
*/
|
381 |
+
public function init_cron() {
|
382 |
+
$sched = wp_next_scheduled( 'mainwp_child_wordfence_cron_scan' );
|
383 |
+
$sch = get_option( 'mainwp_child_wordfence_cron_time' );
|
384 |
+
if ( 'twicedaily' === $sch || 'daily' === $sch || 'weekly' === $sch || 'monthly' === $sch ) {
|
385 |
+
add_action( 'mainwp_child_wordfence_cron_scan', array( $this, 'wfc_cron_scan' ) );
|
386 |
+
if ( false === $sched ) {
|
387 |
+
$sched = wp_schedule_event( time(), $sch, 'mainwp_child_wordfence_cron_scan' );
|
388 |
+
}
|
389 |
+
} else {
|
390 |
+
if ( false !== $sched ) {
|
391 |
+
wp_unschedule_event( $sched, 'mainwp_child_wordfence_cron_scan' );
|
392 |
+
}
|
393 |
+
}
|
394 |
+
}
|
395 |
+
|
396 |
+
/**
|
397 |
+
* Method wfc_cron_scan()
|
398 |
+
*
|
399 |
+
* Trigger the Wordfence scan via Cron job.
|
400 |
+
*
|
401 |
+
* @uses MainWP_Child_Wordfence::start_scan() Start the Wordfence scan by calling wordfence::ajax_scan_callback().
|
402 |
+
*/
|
403 |
+
public function wfc_cron_scan() {
|
404 |
+
if ( ! class_exists( '\wordfence' ) || ! class_exists( '\wfScanEngine' ) ) {
|
405 |
+
return;
|
406 |
+
}
|
407 |
+
$this->start_scan();
|
408 |
+
}
|
409 |
+
|
410 |
+
/**
|
411 |
+
* Method all_plugins()
|
412 |
+
*
|
413 |
+
* Remove the Wordfence plugin from the list of all plugins when the plugin is hidden.
|
414 |
+
*
|
415 |
+
* @param array $plugins Array containing all installed plugins.
|
416 |
+
*
|
417 |
+
* @return array $plugins Array containing all installed plugins without the Wordfence.
|
418 |
+
*/
|
419 |
+
public function all_plugins( $plugins ) {
|
420 |
+
foreach ( $plugins as $key => $value ) {
|
421 |
+
$plugin_slug = basename( $key, '.php' );
|
422 |
+
if ( 'wordfence' === $plugin_slug ) {
|
423 |
+
unset( $plugins[ $key ] );
|
424 |
+
}
|
425 |
+
}
|
426 |
+
|
427 |
+
return $plugins;
|
428 |
+
}
|
429 |
+
|
430 |
+
/**
|
431 |
+
* Method remove_menu()
|
432 |
+
*
|
433 |
+
* Remove the Wordfence menu item when the plugin is hidden.
|
434 |
+
*/
|
435 |
+
public function remove_menu() {
|
436 |
+
remove_menu_page( 'Wordfence' );
|
437 |
+
}
|
438 |
+
|
439 |
+
/**
|
440 |
+
* Method deactivation()
|
441 |
+
*
|
442 |
+
* Unschedule scheduled events on MainWP Child plugin deactivation.
|
443 |
+
*/
|
444 |
+
public function deactivation() {
|
445 |
+
$sched = wp_next_scheduled( 'mainwp_child_wordfence_cron_scan' );
|
446 |
+
if ( $sched ) {
|
447 |
+
wp_unschedule_event( $sched, 'mainwp_child_wordfence_cron_scan' );
|
448 |
+
}
|
449 |
+
}
|
450 |
+
|
451 |
+
/**
|
452 |
+
* Method actions()
|
453 |
+
*
|
454 |
+
* Fire off certain Wordfence plugin actions.
|
455 |
+
*
|
456 |
+
* @return void
|
457 |
+
* @throws \Exception Error message.
|
458 |
+
*
|
459 |
+
* @uses \MainWP\Child\MainWP_Child_Wordfence::start_scan()
|
460 |
+
* @uses \MainWP\Child\MainWP_Child_Wordfence::kill_scan()
|
461 |
+
* @uses \MainWP\Child\MainWP_Child_Wordfence::request_scan()
|
462 |
+
* @uses \MainWP\Child\MainWP_Child_Wordfence::kill_ajax_scan()
|
463 |
+
* @uses \MainWP\Child\MainWP_Child_Wordfence::set_showhide()
|
464 |
+
* @uses \MainWP\Child\MainWP_Child_Wordfence::get_log()
|
465 |
+
* @uses \MainWP\Child\MainWP_Child_Wordfence::update_log()
|
466 |
+
* @uses \MainWP\Child\MainWP_Child_Wordfence::load_issues()
|
467 |
+
* @uses \MainWP\Child\MainWP_Child_Wordfence::ajax_load_issues_callback()
|
468 |
+
* @uses \MainWP\Child\MainWP_Child_Wordfence::load_waf_data()
|
469 |
+
* @uses \MainWP\Child\MainWP_Child_Wordfence::update_all_issues()
|
470 |
+
* @uses \MainWP\Child\MainWP_Child_Wordfence::update_issues_status()
|
471 |
+
* @uses \MainWP\Child\MainWP_Child_Wordfence::update_issue_status()
|
472 |
+
* @uses \MainWP\Child\MainWP_Child_Wordfence::delete_issues()
|
473 |
+
* @uses \MainWP\Child\MainWP_Child_Wordfence::bulk_operation()
|
474 |
+
* @uses \MainWP\Child\MainWP_Child_Wordfence::bulk_ajax_operation()
|
475 |
+
* @uses \MainWP\Child\MainWP_Child_Wordfence::delete_file()
|
476 |
+
* @uses \MainWP\Child\MainWP_Child_Wordfence::restore_file()
|
477 |
+
* @uses \MainWP\Child\MainWP_Child_Wordfence::save_setting()
|
478 |
+
* @uses \MainWP\Child\MainWP_Child_Wordfence::save_settings_new()
|
479 |
+
* @uses \MainWP\Child\MainWP_Child_Wordfence::save_options()
|
480 |
+
* @uses \MainWP\Child\MainWP_Child_Wordfence::recent_traffic()
|
481 |
+
* @uses \MainWP\Child\MainWP_Child_Wordfence::ticker()
|
482 |
+
* @uses \MainWP\Child\MainWP_Child_Wordfence::reverse_lookup()
|
483 |
+
* @uses \MainWP\Child\MainWP_Child_Wordfence::ajax_block_ip_callback()
|
484 |
+
* @uses \MainWP\Child\MainWP_Child_Wordfence::whois()
|
485 |
+
* @uses \MainWP\Child\MainWP_Child_Wordfence::ajax_create_block_callback()
|
486 |
+
* @uses \MainWP\Child\MainWP_Child_Wordfence::ajax_get_blocks_callback()
|
487 |
+
* @uses \MainWP\Child\MainWP_Child_Wordfence::ajax_delete_blocks_callback()
|
488 |
+
* @uses \MainWP\Child\MainWP_Child_Wordfence::ajax_make_permanent_blocks_callback()
|
489 |
+
* @uses \MainWP\Child\MainWP_Child_Wordfence::unblock_ip()
|
490 |
+
* @uses \MainWP\Child\MainWP_Child_Wordfence::load_static_panel()
|
491 |
+
* @uses \MainWP\Child\MainWP_Child_Wordfence::downgrade_license()
|
492 |
+
* @uses \MainWP\Child\MainWP_Child_Wordfence::import_settings()
|
493 |
+
* @uses \MainWP\Child\MainWP_Child_Wordfence::export_settings()
|
494 |
+
* @uses \MainWP\Child\MainWP_Child_Wordfence::save_cache_config()
|
495 |
+
* @uses \MainWP\Child\MainWP_Child_Wordfence::check_falcon_htaccess()
|
496 |
+
* @uses \MainWP\Child\MainWP_Child_Wordfence::check_htaccess()
|
497 |
+
* @uses \MainWP\Child\MainWP_Child_Wordfence::save_cache_options()
|
498 |
+
* @uses \MainWP\Child\MainWP_Child_Wordfence::clear_page_cache()
|
499 |
+
* @uses \MainWP\Child\MainWP_Child_Wordfence::get_cache_stats()
|
500 |
+
* @uses \MainWP\Child\MainWP_Child_Wordfence::add_cache_exclusion()
|
501 |
+
* @uses \MainWP\Child\MainWP_Child_Wordfence::load_cache_exclusions()
|
502 |
+
* @uses \MainWP\Child\MainWP_Child_Wordfence::remove_cache_exclusion()
|
503 |
+
* @uses \MainWP\Child\MainWP_Child_Wordfence::get_diagnostics()
|
504 |
+
* @uses \MainWP\Child\MainWP_Child_Wordfence::update_waf_rules()
|
505 |
+
* @uses \MainWP\Child\MainWP_Child_Wordfence::update_waf_rules_new()
|
506 |
+
* @uses \MainWP\Child\MainWP_Child_Wordfence::save_debugging_config()
|
507 |
+
* @uses \MainWP\Child\MainWP_Child_Wordfence::load_live_traffic()
|
508 |
+
* @uses \MainWP\Child\MainWP_Child_Wordfence::whitelist_waf_param_key()
|
509 |
+
* @uses \MainWP\Child\MainWP_Child_Wordfence::hide_file_htaccess()
|
510 |
+
* @uses \MainWP\Child\MainWP_Child_Wordfence::fix_fpd()
|
511 |
+
* @uses \MainWP\Child\MainWP_Child_Wordfence::disable_directory_listing()
|
512 |
+
* @uses \MainWP\Child\MainWP_Child_Wordfence::delete_database_option()
|
513 |
+
* @uses \MainWP\Child\MainWP_Child_Wordfence::mis_configured_how_get_ips_choice()
|
514 |
+
* @uses \MainWP\Child\MainWP_Child_Wordfence::delete_admin_user()
|
515 |
+
* @uses \MainWP\Child\MainWP_Child_Wordfence::revoke_admin_user()
|
516 |
+
* @uses \MainWP\Child\MainWP_Child_Wordfence::clear_all_blocked()
|
517 |
+
* @uses \MainWP\Child\MainWP_Child_Wordfence::permanently_block_all_ips()
|
518 |
+
* @uses \MainWP\Child\MainWP_Child_Wordfence::unlock_out_ip()
|
519 |
+
* @uses \MainWP\Child\MainWP_Child_Wordfence::unblock_range()
|
520 |
+
* @uses \MainWP\Child\MainWP_Child_Wordfence::block_ip_ua_range()
|
521 |
+
* @uses \MainWP\Child\MainWP_Child_Wordfence::load_block_ranges()
|
522 |
+
* @uses \MainWP\Child\MainWP_Child_Wordfence::save_waf_config()
|
523 |
+
* @uses \MainWP\Child\MainWP_Child_Wordfence::whitelist_bulk_delete()
|
524 |
+
* @uses \MainWP\Child\MainWP_Child_Wordfence::whitelist_bulk_enable()
|
525 |
+
* @uses \MainWP\Child\MainWP_Child_Wordfence::whitelist_bulk_disable()
|
526 |
+
* @uses \MainWP\Child\MainWP_Child_Wordfence::update_config()
|
527 |
+
* @uses \MainWP\Child\MainWP_Child_Wordfence::save_country_blocking()
|
528 |
+
* @uses \MainWP\Child\MainWP_Helper::write()
|
529 |
+
*/
|
530 |
+
public function action() { // phpcs:ignore -- Current complexity is the only way to achieve desired results, pull request solutions appreciated.
|
531 |
+
$information = array();
|
532 |
+
if ( ! $this->is_wordfence_installed ) {
|
533 |
+
MainWP_Helper::write( array( 'error' => __( 'Please install the Wordfence plugin on the child site.', $this->plugin_translate ) ) );
|
534 |
+
return;
|
535 |
+
}
|
536 |
+
|
537 |
+
if ( ! class_exists( '\wordfence' ) || ! class_exists( '\wfScanEngine' ) ) {
|
538 |
+
$information['error'] = 'NO_WORDFENCE';
|
539 |
+
MainWP_Helper::write( $information );
|
540 |
+
}
|
541 |
+
if ( isset( $_POST['mwp_action'] ) ) {
|
542 |
+
|
543 |
+
$mwp_action = ! empty( $_POST['mwp_action'] ) ? sanitize_text_field( wp_unslash( $_POST['mwp_action'] ) ) : '';
|
544 |
+
switch ( $mwp_action ) {
|
545 |
+
case 'start_scan':
|
546 |
+
$information = $this->start_scan();
|
547 |
+
break;
|
548 |
+
case 'kill_scan':
|
549 |
+
$information = $this->kill_scan();
|
550 |
+
break;
|
551 |
+
case 'requestScan':
|
552 |
+
$information = $this->request_scan();
|
553 |
+
break;
|
554 |
+
case 'killScan':
|
555 |
+
$information = $this->kill_ajax_scan();
|
556 |
+
break;
|
557 |
+
case 'set_showhide':
|
558 |
+
$information = $this->set_showhide();
|
559 |
+
break;
|
560 |
+
case 'get_log':
|
561 |
+
$information = $this->get_log();
|
562 |
+
break;
|
563 |
+
case 'update_log':
|
564 |
+
$information = $this->update_log();
|
565 |
+
break;
|
566 |
+
case 'load_issues': // not used in from version 2.0 of WF ext!
|
567 |
+
$information = $this->load_issues();
|
568 |
+
break;
|
569 |
+
case 'loadIssues':
|
570 |
+
$information = $this->ajax_load_issues_callback();
|
571 |
+
break;
|
572 |
+
case 'load_wafData':
|
573 |
+
$information = $this->load_waf_data();
|
574 |
+
break;
|
575 |
+
case 'update_all_issues':
|
576 |
+
$information = $this->update_all_issues();
|
577 |
+
break;
|
578 |
+
case 'update_issues_status':
|
579 |
+
$information = $this->update_issues_status();
|
580 |
+
break;
|
581 |
+
case 'updateIssueStatus':
|
582 |
+
$information = $this->update_issue_status();
|
583 |
+
break;
|
584 |
+
case 'delete_issues':
|
585 |
+
$information = $this->delete_issues();
|
586 |
+
break;
|
587 |
+
case 'bulk_operation':
|
588 |
+
$information = $this->bulk_operation();
|
589 |
+
break;
|
590 |
+
case 'bulkOperation':
|
591 |
+
$information = $this->bulk_ajax_operation(); // new version.
|
592 |
+
break;
|
593 |
+
case 'delete_file':
|
594 |
+
$information = $this->delete_file();
|
595 |
+
break;
|
596 |
+
case 'restore_file':
|
597 |
+
$information = $this->restore_file();
|
598 |
+
break;
|
599 |
+
case 'save_setting':
|
600 |
+
$information = $this->save_setting();
|
601 |
+
break;
|
602 |
+
case 'save_settings_new':
|
603 |
+
$information = $this->save_settings_new();
|
604 |
+
break;
|
605 |
+
case 'saveOptions':
|
606 |
+
$information = $this->save_options();
|
607 |
+
break;
|
608 |
+
case 'recentTraffic':
|
609 |
+
$information = $this->recent_traffic();
|
610 |
+
break;
|
611 |
+
case 'ticker':
|
612 |
+
$information = $this->ticker();
|
613 |
+
break;
|
614 |
+
case 'reverse_lookup':
|
615 |
+
$information = $this->reverse_lookup();
|
616 |
+
break;
|
617 |
+
case 'block_ip':
|
618 |
+
$information = $this->ajax_block_ip_callback();
|
619 |
+
break;
|
620 |
+
case 'whois':
|
621 |
+
$information = $this->whois();
|
622 |
+
break;
|
623 |
+
case 'createBlock':
|
624 |
+
$information = $this->ajax_create_block_callback();
|
625 |
+
break;
|
626 |
+
case 'getBlocks':
|
627 |
+
$information = $this->ajax_get_blocks_callback();
|
628 |
+
break;
|
629 |
+
case 'deleteBlocks':
|
630 |
+
$information = $this->ajax_delete_blocks_callback();
|
631 |
+
break;
|
632 |
+
case 'makePermanentBlocks':
|
633 |
+
$information = $this->ajax_make_permanent_blocks_callback();
|
634 |
+
break;
|
635 |
+
case 'unblock_ip':
|
636 |
+
$information = $this->unblock_ip();
|
637 |
+
break;
|
638 |
+
case 'load_static_panel':
|
639 |
+
$information = $this->load_static_panel();
|
640 |
+
break;
|
641 |
+
case 'downgrade_license':
|
642 |
+
$information = $this->downgrade_license();
|
643 |
+
break;
|
644 |
+
case 'import_settings':
|
645 |
+
$information = $this->import_settings();
|
646 |
+
break;
|
647 |
+
case 'export_settings':
|
648 |
+
$information = $this->export_settings();
|
649 |
+
break;
|
650 |
+
case 'save_cache_config':
|
651 |
+
$information = $this->save_cache_config();
|
652 |
+
break;
|
653 |
+
case 'check_falcon_htaccess':
|
654 |
+
$information = self::check_falcon_htaccess();
|
655 |
+
break;
|
656 |
+
case 'checkHtaccess':
|
657 |
+
$information = $this->check_htaccess();
|
658 |
+
break;
|
659 |
+
case 'save_cache_options':
|
660 |
+
$information = $this->save_cache_options();
|
661 |
+
break;
|
662 |
+
case 'clear_page_cache':
|
663 |
+
$information = $this->clear_page_cache();
|
664 |
+
break;
|
665 |
+
case 'get_cache_stats':
|
666 |
+
$information = $this->get_cache_stats();
|
667 |
+
break;
|
668 |
+
case 'add_cache_exclusion':
|
669 |
+
$information = $this->add_cache_exclusion();
|
670 |
+
break;
|
671 |
+
case 'load_cache_exclusions':
|
672 |
+
$information = $this->load_cache_exclusions();
|
673 |
+
break;
|
674 |
+
case 'remove_cache_exclusion':
|
675 |
+
$information = $this->remove_cache_exclusion();
|
676 |
+
break;
|
677 |
+
case 'get_diagnostics':
|
678 |
+
$information = $this->get_diagnostics();
|
679 |
+
break;
|
680 |
+
case 'update_waf_rules':
|
681 |
+
$information = $this->update_waf_rules();
|
682 |
+
break;
|
683 |
+
case 'update_waf_rules_new':
|
684 |
+
$information = $this->update_waf_rules_new();
|
685 |
+
break;
|
686 |
+
case 'save_debugging_config':
|
687 |
+
$information = $this->save_debugging_config();
|
688 |
+
break;
|
689 |
+
case 'load_live_traffic':
|
690 |
+
$information = $this->load_live_traffic();
|
691 |
+
break;
|
692 |
+
case 'white_list_waf':
|
693 |
+
$information = $this->whitelist_waf_param_key();
|
694 |
+
break;
|
695 |
+
case 'hide_file_htaccess':
|
696 |
+
$information = $this->hide_file_htaccess();
|
697 |
+
break;
|
698 |
+
case 'fix_fpd':
|
699 |
+
$information = $this->fix_fpd();
|
700 |
+
break;
|
701 |
+
case 'disable_directory_listing':
|
702 |
+
$information = $this->disable_directory_listing();
|
703 |
+
break;
|
704 |
+
case 'delete_database_option':
|
705 |
+
$information = $this->delete_database_option();
|
706 |
+
break;
|
707 |
+
case 'misconfigured_howget_ips_choice':
|
708 |
+
$information = $this->mis_configured_how_get_ips_choice();
|
709 |
+
break;
|
710 |
+
case 'delete_admin_user':
|
711 |
+
$information = $this->delete_admin_user();
|
712 |
+
break;
|
713 |
+
case 'revoke_admin_user':
|
714 |
+
$information = $this->revoke_admin_user();
|
715 |
+
break;
|
716 |
+
case 'clear_all_blocked':
|
717 |
+
$information = $this->clear_all_blocked();
|
718 |
+
break;
|
719 |
+
case 'permanently_block_all_ips':
|
720 |
+
$information = $this->permanently_block_all_ips();
|
721 |
+
break;
|
722 |
+
case 'unlockout_ip':
|
723 |
+
$information = $this->unlock_out_ip();
|
724 |
+
break;
|
725 |
+
case 'unblock_range':
|
726 |
+
$information = $this->unblock_range();
|
727 |
+
break;
|
728 |
+
case 'block_ip_ua_range':
|
729 |
+
$information = $this->block_ip_ua_range();
|
730 |
+
break;
|
731 |
+
case 'load_block_ranges':
|
732 |
+
$information = $this->load_block_ranges();
|
733 |
+
break;
|
734 |
+
case 'save_waf_config':
|
735 |
+
$information = $this->save_waf_config();
|
736 |
+
break;
|
737 |
+
case 'whitelist_bulk_delete':
|
738 |
+
$information = $this->whitelist_bulk_delete();
|
739 |
+
break;
|
740 |
+
case 'whitelist_bulk_enable':
|
741 |
+
$information = $this->whitelist_bulk_enable();
|
742 |
+
break;
|
743 |
+
case 'whitelist_bulk_disable':
|
744 |
+
$information = $this->whitelist_bulk_disable();
|
745 |
+
break;
|
746 |
+
case 'update_config':
|
747 |
+
$information = $this->update_config();
|
748 |
+
break;
|
749 |
+
case 'save_country_blocking':
|
750 |
+
$information = $this->save_country_blocking();
|
751 |
+
break;
|
752 |
+
}
|
753 |
+
}
|
754 |
+
MainWP_Helper::write( $information );
|
755 |
+
}
|
756 |
+
|
757 |
+
/**
|
758 |
+
* Method get_section_settings()
|
759 |
+
*
|
760 |
+
* @param string $section Contains the group (section) of Wordfence settings options.
|
761 |
+
*
|
762 |
+
* @return array Array containing the selected section options.
|
763 |
+
*/
|
764 |
+
public static function get_section_settings( $section ) {
|
765 |
+
$general_opts = array(
|
766 |
+
'scheduleScan',
|
767 |
+
'apiKey',
|
768 |
+
'autoUpdate',
|
769 |
+
'alertEmails',
|
770 |
+
'displayTopLevelOptions',
|
771 |
+
'displayTopLevelBlocking',
|
772 |
+
'displayTopLevelLiveTraffic',
|
773 |
+
'howGetIPs',
|
774 |
+
'howGetIPs_trusted_proxies',
|
775 |
+
'other_hideWPVersion',
|
776 |
+
'disableCodeExecutionUploads',
|
777 |
+
'liveActivityPauseEnabled',
|
778 |
+
'actUpdateInterval',
|
779 |
+
'other_bypassLitespeedNoabort',
|
780 |
+
'deleteTablesOnDeact',
|
781 |
+
'notification_updatesNeeded',
|
782 |
+
'notification_securityAlerts',
|
783 |
+
'notification_promotions',
|
784 |
+
'notification_blogHighlights',
|
785 |
+
'notification_productUpdates',
|
786 |
+
'notification_scanStatus',
|
787 |
+
'alertOn_update',
|
788 |
+
'alertOn_wordfenceDeactivated',
|
789 |
+
'alertOn_block',
|
790 |
+
'alertOn_loginLockout',
|
791 |
+
'alertOn_breachLogin',
|
792 |
+
'alertOn_lostPasswdForm',
|
793 |
+
'alertOn_adminLogin',
|
794 |
+
'alertOn_firstAdminLoginOnly',
|
795 |
+
'alertOn_scanIssues', // new.
|
796 |
+
'alertOn_wafDeactivated', // new.
|
797 |
+
'alertOn_severityLevel', // new.
|
798 |
+
'alertOn_nonAdminLogin',
|
799 |
+
'alertOn_firstNonAdminLoginOnly',
|
800 |
+
'wafAlertOnAttacks',
|
801 |
+
'alert_maxHourly',
|
802 |
+
'email_summary_enabled',
|
803 |
+
'email_summary_interval',
|
804 |
+
'email_summary_excluded_directories',
|
805 |
+
'email_summary_dashboard_widget_enabled',
|
806 |
+
);
|
807 |
+
|
808 |
+
$traffic_opts = array(
|
809 |
+
'liveTrafficEnabled',
|
810 |
+
'liveTraf_ignorePublishers',
|
811 |
+
'liveTraf_displayExpandedRecords',
|
812 |
+
'liveTraf_ignoreUsers',
|
813 |
+
'liveTraf_ignoreIPs',
|
814 |
+
'liveTraf_ignoreUA',
|
815 |
+
'liveTraf_maxRows',
|
816 |
+
'liveTraf_maxAge',
|
817 |
+
'displayTopLevelLiveTraffic',
|
818 |
+
);
|
819 |
+
|
820 |
+
$firewall_opts = array(
|
821 |
+
'disableWAFIPBlocking',
|
822 |
+
'whitelisted',
|
823 |
+
'whitelistedServices',
|
824 |
+
'bannedURLs',
|
825 |
+
'wafAlertWhitelist',
|
826 |
+
'firewallEnabled',
|
827 |
+
'neverBlockBG',
|
828 |
+
'maxGlobalRequests',
|
829 |
+
'maxGlobalRequests_action',
|
830 |
+
'maxRequestsCrawlers',
|
831 |
+
'maxRequestsCrawlers_action',
|
832 |
+
'max404Crawlers',
|
833 |
+
'max404Crawlers_action',
|
834 |
+
'maxRequestsHumans',
|
835 |
+
'maxRequestsHumans_action',
|
836 |
+
'max404Humans',
|
837 |
+
'max404Humans_action',
|
838 |
+
'blockedTime',
|
839 |
+
'allowed404s',
|
840 |
+
'loginSecurityEnabled',
|
841 |
+
'loginSec_maxFailures',
|
842 |
+
'loginSec_maxForgotPasswd',
|
843 |
+
'loginSec_countFailMins',
|
844 |
+
'loginSec_lockoutMins',
|
845 |
+
'loginSec_lockInvalidUsers',
|
846 |
+
'loginSec_breachPasswds_enabled',
|
847 |
+
'loginSec_breachPasswds',
|
848 |
+
'loginSec_userBlacklist',
|
849 |
+
'loginSec_strongPasswds_enabled',
|
850 |
+
'loginSec_strongPasswds',
|
851 |
+
'loginSec_maskLoginErrors',
|
852 |
+
'loginSec_blockAdminReg',
|
853 |
+
'loginSec_disableAuthorScan',
|
854 |
+
'other_blockBadPOST',
|
855 |
+
'blockCustomText',
|
856 |
+
'other_pwStrengthOnUpdate',
|
857 |
+
'other_WFNet',
|
858 |
+
'wafStatus',
|
859 |
+
'learningModeGracePeriodEnabled',
|
860 |
+
'learningModeGracePeriod',
|
861 |
+
);
|
862 |
+
|
863 |
+
$scan_opts = array(
|
864 |
+
'scansEnabled_checkGSB',
|
865 |
+
'spamvertizeCheck',
|
866 |
+
'checkSpamIP',
|
867 |
+
'scansEnabled_checkHowGetIPs',
|
868 |
+
'scansEnabled_checkReadableConfig',
|
869 |
+
'scansEnabled_suspectedFiles',
|
870 |
+
'scansEnabled_core',
|
871 |
+
'scansEnabled_themes',
|
872 |
+
'scansEnabled_plugins',
|
873 |
+
'scansEnabled_coreUnknown',
|
874 |
+
'scansEnabled_malware',
|
875 |
+
'scansEnabled_fileContents',
|
876 |
+
'scansEnabled_fileContentsGSB',
|
877 |
+
'scansEnabled_posts',
|
878 |
+
'scansEnabled_comments',
|
879 |
+
'scansEnabled_suspiciousOptions',
|
880 |
+
'scansEnabled_oldVersions',
|
881 |
+
'scansEnabled_suspiciousAdminUsers',
|
882 |
+
'scansEnabled_passwds',
|
883 |
+
'scansEnabled_diskSpace',
|
884 |
+
'scansEnabled_dns',
|
885 |
+
'other_scanOutside',
|
886 |
+
'scansEnabled_scanImages',
|
887 |
+
'scansEnabled_highSense',
|
888 |
+
'scheduledScansEnabled',
|
889 |
+
'lowResourceScansEnabled',
|
890 |
+
'scan_maxIssues',
|
891 |
+
'scan_maxDuration',
|
892 |
+
'maxMem',
|
893 |
+
'maxExecutionTime',
|
894 |
+
'scan_exclude',
|
895 |
+
'scan_include_extra',
|
896 |
+
'scanType',
|
897 |
+
'schedMode',
|
898 |
+
);
|
899 |
+
$diagnostics_opts = array(
|
900 |
+
'debugOn',
|
901 |
+
'startScansRemotely',
|
902 |
+
'ssl_verify',
|
903 |
+
'betaThreatDefenseFeed',
|
904 |
+
'wordfenceI18n',
|
905 |
+
'avoid_php_input',
|
906 |
+
);
|
907 |
+
|
908 |
+
$blocking_opts = array(
|
909 |
+
'displayTopLevelBlocking',
|
910 |
+
);
|
911 |
+
|
912 |
+
$options = array();
|
913 |
+
|
914 |
+
switch ( $section ) {
|
915 |
+
case self::OPTIONS_TYPE_GLOBAL:
|
916 |
+
$options = $general_opts;
|
917 |
+
break;
|
918 |
+
case self::OPTIONS_TYPE_LIVE_TRAFFIC:
|
919 |
+
$options = $traffic_opts;
|
920 |
+
break;
|
921 |
+
case self::OPTIONS_TYPE_FIREWALL:
|
922 |
+
$options = $firewall_opts;
|
923 |
+
break;
|
924 |
+
case self::OPTIONS_TYPE_SCANNER:
|
925 |
+
$options = $scan_opts;
|
926 |
+
break;
|
927 |
+
case self::OPTIONS_TYPE_DIAGNOSTICS:
|
928 |
+
$options = $diagnostics_opts;
|
929 |
+
break;
|
930 |
+
case self::OPTIONS_TYPE_BLOCKING:
|
931 |
+
$options = $blocking_opts;
|
932 |
+
break;
|
933 |
+
case self::OPTIONS_TYPE_ALL:
|
934 |
+
$options = array_merge( $general_opts, $traffic_opts, $firewall_opts, $scan_opts, $diagnostics_opts, $blocking_opts );
|
935 |
+
break;
|
936 |
+
}
|
937 |
+
return $options;
|
938 |
+
}
|
939 |
+
|
940 |
+
/**
|
941 |
+
* Method start_scan()
|
942 |
+
*
|
943 |
+
* Start the Wordfence scan by calling wordfence::ajax_scan_callback().
|
944 |
+
*
|
945 |
+
* @used-by MainWP_Child_Wordfence::actions() Fire off certain Wordfence plugin actions.
|
946 |
+
* @used-by MainWP_Child_Wordfence::wfc_cron_can() Trigger the Wordfence scan via Cron job.
|
947 |
+
* @return array Action result.
|
948 |
+
*/
|
949 |
+
private function start_scan() {
|
950 |
+
$information = \wordfence::ajax_scan_callback();
|
951 |
+
if ( is_array( $information ) && isset( $information['ok'] ) ) {
|
952 |
+
$information['result'] = 'SUCCESS';
|
953 |
+
}
|
954 |
+
|
955 |
+
return $information;
|
956 |
+
}
|
957 |
+
|
958 |
+
/**
|
959 |
+
* Method kill_scan()
|
960 |
+
*
|
961 |
+
* Stop the Wordfence scan by calling wordfence::status(), \wfUtils::clearScanLock() and \wfScanEngine::requestKill().
|
962 |
+
*
|
963 |
+
* @used-by MainWP_Child_Wordfence::actions() Fire off certain Wordfence plugin actions.
|
964 |
+
*
|
965 |
+
* @return array Action result.
|
966 |
+
*/
|
967 |
+
private function kill_scan() {
|
968 |
+
\wordfence::status( 1, 'info', 'Scan kill request received.' );
|
969 |
+
\wordfence::status( 10, 'info', 'SUM_KILLED:A request was received to kill the previous scan.' );
|
970 |
+
\wfUtils::clearScanLock(); // Clear the lock now because there may not be a scan running to pick up the kill request and clear the lock.
|
971 |
+
\wfScanEngine::requestKill();
|
972 |
+
return array(
|
973 |
+
'ok' => 1,
|
974 |
+
);
|
975 |
+
}
|
976 |
+
|
977 |
+
/**
|
978 |
+
* Method request_scan()
|
979 |
+
*
|
980 |
+
* Request the Wordfence scan by returning wordfence::ajax_scan_callback().
|
981 |
+
*
|
982 |
+
* @used-by MainWP_Child_Wordfence::actions() Fire off certain Wordfence plugin actions.
|
983 |
+
*
|
984 |
+
* @return array Action result.
|
985 |
+
*/
|
986 |
+
private function request_scan() {
|
987 |
+
return \wordfence::ajax_scan_callback();
|
988 |
+
}
|
989 |
+
|
990 |
+
/**
|
991 |
+
* Method kill_ajax_scan()
|
992 |
+
*
|
993 |
+
* Stop the Wordfence AJAX scan by returning wordfence::ajax_killScan_callback().
|
994 |
+
*
|
995 |
+
* @used-by MainWP_Child_Wordfence::actions() Fire off certain Wordfence plugin actions.
|
996 |
+
*
|
997 |
+
* @return array Action result.
|
998 |
+
*/
|
999 |
+
private function kill_ajax_scan() {
|
1000 |
+
return \wordfence::ajax_killScan_callback();
|
1001 |
+
}
|
1002 |
+
|
1003 |
+
/**
|
1004 |
+
* Method set_showhide()
|
1005 |
+
*
|
1006 |
+
* Hide or unhide the Wordfence plugin.
|
1007 |
+
*
|
1008 |
+
* @return array Action result.
|
1009 |
+
*
|
1010 |
+
* @uses \MainWP\Child\MainWP_Helper::update_option()
|
1011 |
+
*
|
1012 |
+
* @used-by MainWP_Child_Wordfence::actions() Fire off certain Wordfence plugin actions.
|
1013 |
+
*/
|
1014 |
+
public function set_showhide() {
|
1015 |
+
$hide = isset( $_POST['showhide'] ) && ( 'hide' === $_POST['showhide'] ) ? 'hide' : '';
|
1016 |
+
MainWP_Helper::update_option( 'mainwp_wordfence_hide_plugin', $hide, 'yes' );
|
1017 |
+
$information['result'] = 'SUCCESS';
|
1018 |
+
|
1019 |
+
return $information;
|
1020 |
+
}
|
1021 |
+
|
1022 |
+
/**
|
1023 |
+
* Method get_log()
|
1024 |
+
*
|
1025 |
+
* Get the Wordfence log.
|
1026 |
+
*
|
1027 |
+
* @used-by MainWP_Child_Wordfence::actions() Fire off certain Wordfence plugin actions.
|
1028 |
+
*
|
1029 |
+
* @return array Action result.
|
1030 |
+
*/
|
1031 |
+
public function get_log() {
|
1032 |
+
$information = array();
|
1033 |
+
$wfLog = \wordfence::getLog();
|
1034 |
+
if ( $wfLog ) {
|
1035 |
+
$information['events'] = $wfLog->getStatusEvents( 0 );
|
1036 |
+
|
1037 |
+
if ( method_exists( $wfLog, 'getSummaryEvents' ) ) {
|
1038 |
+
$information['summary'] = $wfLog->getSummaryEvents();
|
1039 |
+
} else {
|
1040 |
+
$information['summary'] = '';
|
1041 |
+
}
|
1042 |
+
}
|
1043 |
+
$information['debugOn'] = \wfConfig::get( 'debugOn', false );
|
1044 |
+
$information['timeOffset'] = 3600 * get_option( 'gmt_offset' );
|
1045 |
+
|
1046 |
+
return $information;
|
1047 |
+
}
|
1048 |
+
|
1049 |
+
/**
|
1050 |
+
* Method update_log()
|
1051 |
+
*
|
1052 |
+
* Updated the Wordfence activity log via wordfence::ajax_activityLogUpdate_callback().
|
1053 |
+
*
|
1054 |
+
* @used-by MainWP_Child_Wordfence::actions() Fire off certain Wordfence plugin actions.
|
1055 |
+
*
|
1056 |
+
* @return array Action result.
|
1057 |
+
*/
|
1058 |
+
public function update_log() {
|
1059 |
+
return \wordfence::ajax_activityLogUpdate_callback();
|
1060 |
+
}
|
1061 |
+
|
1062 |
+
/**
|
1063 |
+
* Method load_issues()
|
1064 |
+
*
|
1065 |
+
* Load issues detected by Wordfence.
|
1066 |
+
*
|
1067 |
+
* @used-by MainWP_Child_Wordfence::actions() Fire off certain Wordfence plugin actions.
|
1068 |
+
*
|
1069 |
+
* @return array Action result.
|
1070 |
+
*/
|
1071 |
+
public function load_issues() {
|
1072 |
+
$offset = isset( $_POST['offset'] ) ? intval( $_POST['offset'] ) : 0;
|
1073 |
+
$limit = isset( $_POST['limit'] ) ? intval( $_POST['limit'] ) : WORDFENCE_SCAN_ISSUES_PER_PAGE;
|
1074 |
+
|
1075 |
+
$i = new \wfIssues();
|
1076 |
+
$iss = $i->getIssues( $offset, $limit );
|
1077 |
+
$counts = $i->getIssueCounts();
|
1078 |
+
|
1079 |
+
return array(
|
1080 |
+
'issuesLists' => $iss,
|
1081 |
+
'issueCounts' => $counts,
|
1082 |
+
'lastScanCompleted' => \wfConfig::get( 'lastScanCompleted' ),
|
1083 |
+
'apiKey' => \wfConfig::get( 'apiKey' ),
|
1084 |
+
'isPaid' => \wfConfig::get( 'isPaid' ),
|
1085 |
+
'lastscan_timestamp' => $this->get_lastscan(),
|
1086 |
+
'isNginx' => \wfUtils::isNginx() ? 1 : 0,
|
1087 |
+
'todayAttBlocked' => $this->count_attacks_blocked( 1 ),
|
1088 |
+
'weekAttBlocked' => $this->count_attacks_blocked( 7 ),
|
1089 |
+
'monthAttBlocked' => $this->count_attacks_blocked( 30 ),
|
1090 |
+
'wafData' => self::get_waf_data(),
|
1091 |
+
);
|
1092 |
+
}
|
1093 |
+
|
1094 |
+
/**
|
1095 |
+
* Method ajax_load_issues_callback()
|
1096 |
+
*
|
1097 |
+
* Load issues detected by Wordfence (Callback).
|
1098 |
+
*
|
1099 |
+
* @used-by MainWP_Child_Wordfence::actions() Fire off certain Wordfence plugin actions.
|
1100 |
+
*
|
1101 |
+
* @return array Action result.
|
1102 |
+
*/
|
1103 |
+
public static function ajax_load_issues_callback() {
|
1104 |
+
$offset = isset( $_POST['offset'] ) ? intval( $_POST['offset'] ) : 0;
|
1105 |
+
$limit = isset( $_POST['limit'] ) ? intval( $_POST['limit'] ) : WORDFENCE_SCAN_ISSUES_PER_PAGE;
|
1106 |
+
|
1107 |
+
$i = new \wfIssues();
|
1108 |
+
$iss = $i->getIssues( $offset, $limit );
|
1109 |
+
$counts = $i->getIssueCounts();
|
1110 |
+
$return = array(
|
1111 |
+
'issuesLists' => $iss,
|
1112 |
+
'issueCounts' => $counts,
|
1113 |
+
'lastScanCompleted' => \wfConfig::get( 'lastScanCompleted' ),
|
1114 |
+
'apiKey' => \wfConfig::get( 'apiKey' ),
|
1115 |
+
'isPaid' => \wfConfig::get( 'isPaid' ),
|
1116 |
+
'lastscan_timestamp' => self::instance()->get_lastscan(),
|
1117 |
+
'todayAttBlocked' => self::instance()->count_attacks_blocked( 1 ),
|
1118 |
+
'weekAttBlocked' => self::instance()->count_attacks_blocked( 7 ),
|
1119 |
+
'monthAttBlocked' => self::instance()->count_attacks_blocked( 30 ),
|
1120 |
+
'issueCount' => $i->getIssueCount(),
|
1121 |
+
);
|
1122 |
+
return $return;
|
1123 |
+
}
|
1124 |
+
|
1125 |
+
/**
|
1126 |
+
* Method load_waf_data()
|
1127 |
+
*
|
1128 |
+
* Load the web application firewall (WAF) data.
|
1129 |
+
*
|
1130 |
+
* @uses get_waf_data() Get the WAF data.
|
1131 |
+
*
|
1132 |
+
* @used-by MainWP_Child_Wordfence::actions() Fire off certain Wordfence plugin actions.
|
1133 |
+
*
|
1134 |
+
* @return array Action result.
|
1135 |
+
*/
|
1136 |
+
public function load_waf_data() {
|
1137 |
+
$return = array(
|
1138 |
+
'wafData' => self::get_waf_data(),
|
1139 |
+
'ip' => \wfUtils::getIP(),
|
1140 |
+
'ajaxWatcherDisabled_front' => (bool) \wfConfig::get( 'ajaxWatcherDisabled_front' ),
|
1141 |
+
'ajaxWatcherDisabled_admin' => (bool) \wfConfig::get( 'ajaxWatcherDisabled_admin' ),
|
1142 |
+
);
|
1143 |
+
|
1144 |
+
if ( class_exists( '\wfFirewall' ) ) {
|
1145 |
+
$firewall = new \wfFirewall();
|
1146 |
+
$return['isSubDirectoryInstallation'] = $firewall->isSubDirectoryInstallation();
|
1147 |
+
}
|
1148 |
+
return $return;
|
1149 |
+
}
|
1150 |
+
|
1151 |
+
/**
|
1152 |
+
* Method count_attacks_blocked()
|
1153 |
+
*
|
1154 |
+
* Get the number of blocked attackes.
|
1155 |
+
*
|
1156 |
+
* @param int $maxAgeDays Contains the number of days to count blocked attacks form.
|
1157 |
+
*
|
1158 |
+
* @used-by MainWP_Child_Wordfence::actions() Fire off certain Wordfence plugin actions.
|
1159 |
+
*
|
1160 |
+
* @return array Action result.
|
1161 |
+
*/
|
1162 |
+
public function count_attacks_blocked( $maxAgeDays ) {
|
1163 |
+
|
1164 |
+
/**
|
1165 |
+
* Object, providing access to the WordPress database.
|
1166 |
+
*
|
1167 |
+
* @global object $wpdb WordPress Database instance.
|
1168 |
+
*/
|
1169 |
+
global $wpdb;
|
1170 |
+
|
1171 |
+
$table_wfBlockedIPLog = \wfDB::networkTable( 'wfBlockedIPLog' );
|
1172 |
+
$interval = 'FLOOR(UNIX_TIMESTAMP(DATE_SUB(NOW(), interval ' . $maxAgeDays . ' day)) / 86400)';
|
1173 |
+
// phpcs:disable -- third party code, safe.
|
1174 |
+
return $wpdb->get_var(
|
1175 |
+
<<<SQL
|
1176 |
+
SELECT SUM(blockCount) as blockCount FROM {$table_wfBlockedIPLog} WHERE unixday >= {$interval}
|
1177 |
+
SQL
|
1178 |
+
);
|
1179 |
+
}
|
1180 |
+
|
1181 |
+
/**
|
1182 |
+
* Method get_lastscan()
|
1183 |
+
*
|
1184 |
+
* Get date and time of the last Wordfence scan.
|
1185 |
+
*
|
1186 |
+
* @used-by MainWP_Child_Wordfence::actions() Fire off certain Wordfence plugin actions.
|
1187 |
+
*
|
1188 |
+
* @return string Last scan timestamp.
|
1189 |
+
*/
|
1190 |
+
public function get_lastscan() {
|
1191 |
+
$wfdb = new \wfDB();
|
1192 |
+
$table_wfStatus = \wfDB::networkTable( 'wfStatus' );
|
1193 |
+
$ctime = $wfdb->querySingle( "SELECT MAX(ctime) FROM {$table_wfStatus} WHERE msg LIKE '%SUM_PREP:Preparing a new scan.%'" );
|
1194 |
+
return $ctime;
|
1195 |
+
}
|
1196 |
+
|
1197 |
+
/**
|
1198 |
+
* Method update_all_issues()
|
1199 |
+
*
|
1200 |
+
* Handle (delete ignored, delete new or ignore all new) all issues detected by Wordfence.
|
1201 |
+
*
|
1202 |
+
* @used-by MainWP_Child_Wordfence::actions() Fire off certain Wordfence plugin actions.
|
1203 |
+
*
|
1204 |
+
* @return array Action result.
|
1205 |
+
*/
|
1206 |
+
public function update_all_issues() {
|
1207 |
+
$op = isset( $_POST['op'] ) ? sanitize_text_field( wp_unslash( $_POST['op'] ) ) : '';
|
1208 |
+
$i = new \wfIssues();
|
1209 |
+
if ( 'deleteIgnored' === $op ) {
|
1210 |
+
$i->deleteIgnored();
|
1211 |
+
} elseif ( 'deleteNew' === $op ) {
|
1212 |
+
$i->deleteNew();
|
1213 |
+
} elseif ( 'ignoreAllNew' === $op ) {
|
1214 |
+
$i->ignoreAllNew();
|
1215 |
+
} else {
|
1216 |
+
return array( 'errorMsg' => 'An invalid operation was called.' );
|
1217 |
+
}
|
1218 |
+
|
1219 |
+
return array( 'ok' => 1 );
|
1220 |
+
}
|
1221 |
+
|
1222 |
+
/**
|
1223 |
+
* Method update_issue_status()
|
1224 |
+
*
|
1225 |
+
* Update status of an issue detected by Wordfence.
|
1226 |
+
*
|
1227 |
+
* @used-by MainWP_Child_Wordfence::actions() Fire off certain Wordfence plugin actions.
|
1228 |
+
*
|
1229 |
+
* @return array Action result.
|
1230 |
+
*/
|
1231 |
+
public function update_issue_status() {
|
1232 |
+
$wfIssues = new \wfIssues();
|
1233 |
+
$status = isset( $_POST['status'] ) ? sanitize_text_field( wp_unslash( $_POST['status'] ) ) : '';
|
1234 |
+
$issueID = isset( $_POST['id'] ) ? sanitize_text_field( wp_unslash( $_POST['id'] ) ) : '';
|
1235 |
+
if ( ! preg_match( '/^(?:new|delete|ignoreP|ignoreC)$/', $status ) ) {
|
1236 |
+
return array( 'errorMsg' => 'An invalid status was specified when trying to update that issue.' );
|
1237 |
+
}
|
1238 |
+
$wfIssues->updateIssue( $issueID, $status );
|
1239 |
+
\wfScanEngine::refreshScanNotification( $wfIssues );
|
1240 |
+
|
1241 |
+
$counts = $wfIssues->getIssueCounts();
|
1242 |
+
return array(
|
1243 |
+
'ok' => 1,
|
1244 |
+
'issueCounts' => $counts,
|
1245 |
+
);
|
1246 |
+
}
|
1247 |
+
|
1248 |
+
/**
|
1249 |
+
* Method update_issue_status()
|
1250 |
+
*
|
1251 |
+
* Update status of issues detected by Wordfence.
|
1252 |
+
*
|
1253 |
+
* @used-by MainWP_Child_Wordfence::actions() Fire off certain Wordfence plugin actions.
|
1254 |
+
*
|
1255 |
+
* @return array Action result.
|
1256 |
+
*/
|
1257 |
+
public function update_issues_status() {
|
1258 |
+
$wfIssues = new \wfIssues();
|
1259 |
+
$status = isset( $_POST['status'] ) ? sanitize_text_field( wp_unslash( $_POST['status'] ) ) : '';
|
1260 |
+
$issueID = isset( $_POST['id'] ) ? sanitize_text_field( wp_unslash( $_POST['id'] ) ) : '';
|
1261 |
+
if ( ! preg_match( '/^(?:new|delete|ignoreP|ignoreC)$/', $status ) ) {
|
1262 |
+
return array( 'errorMsg' => 'An invalid status was specified when trying to update that issue.' );
|
1263 |
+
}
|
1264 |
+
$wfIssues->updateIssue( $issueID, $status );
|
1265 |
+
|
1266 |
+
return array( 'ok' => 1 );
|
1267 |
+
}
|
1268 |
+
|
1269 |
+
/**
|
1270 |
+
* Method delete_issues()
|
1271 |
+
*
|
1272 |
+
* Delete issues detected by Wordfence.
|
1273 |
+
*
|
1274 |
+
* @used-by MainWP_Child_Wordfence::actions() Fire off certain Wordfence plugin actions.
|
1275 |
+
*
|
1276 |
+
* @return array Action result.
|
1277 |
+
*/
|
1278 |
+
public function delete_issues() {
|
1279 |
+
$wfIssues = new \wfIssues();
|
1280 |
+
$issueID = isset( $_POST['id'] ) ? sanitize_text_field( wp_unslash( $_POST['id'] ) ) : '';
|
1281 |
+
$wfIssues->deleteIssue( $issueID );
|
1282 |
+
|
1283 |
+
return array( 'ok' => 1 );
|
1284 |
+
}
|
1285 |
+
|
1286 |
+
/**
|
1287 |
+
* Method bulk_operation()
|
1288 |
+
*
|
1289 |
+
* Handle the Wordfence bulk operations.
|
1290 |
+
*
|
1291 |
+
* @used-by MainWP_Child_Wordfence::actions() Fire off certain Wordfence plugin actions.
|
1292 |
+
*
|
1293 |
+
* @return array Action result.
|
1294 |
+
*/
|
1295 |
+
public function bulk_operation() {
|
1296 |
+
$op = isset( $_POST['op'] ) ? sanitize_text_field( wp_unslash( $_POST['op'] ) ) : '';
|
1297 |
+
if ( 'del' === $op || 'repair' === $op ) {
|
1298 |
+
$ids = isset( $_POST['ids'] ) ? array_map( 'sanitize_text_field', wp_unslash( $_POST['ids'] ) ) : array();
|
1299 |
+
$filesWorkedOn = 0;
|
1300 |
+
$errors = array();
|
1301 |
+
$issues = new \wfIssues();
|
1302 |
+
foreach ( $ids as $id ) {
|
1303 |
+
$issue = $issues->getIssueByID( $id );
|
1304 |
+
if ( ! $issue ) {
|
1305 |
+
$errors[] = "Could not delete one of the files because we could not find the issue. Perhaps it's been resolved?";
|
1306 |
+
continue;
|
1307 |
+
}
|
1308 |
+
$file = $issue['data']['file'];
|
1309 |
+
$localFile = ABSPATH . '/' . preg_replace( '/^[\.\/]+/', '', $file );
|
1310 |
+
$localFile = realpath( $localFile );
|
1311 |
+
if ( strpos( $localFile, ABSPATH ) !== 0 ) {
|
1312 |
+
$errors[] = 'An invalid file was requested: ' . htmlentities( $file );
|
1313 |
+
continue;
|
1314 |
+
}
|
1315 |
+
if ( 'del' === $op ) {
|
1316 |
+
if ( unlink( $localFile ) ) {
|
1317 |
+
$issues->updateIssue( $id, 'delete' );
|
1318 |
+
$filesWorkedOn ++;
|
1319 |
+
} else {
|
1320 |
+
$err = error_get_last();
|
1321 |
+
$errors[] = 'Could not delete file ' . htmlentities( $file ) . '. Error was: ' . htmlentities( $err['message'] );
|
1322 |
+
}
|
1323 |
+
} elseif ( 'repair' === $op ) {
|
1324 |
+
$dat = $issue['data'];
|
1325 |
+
$result = \wordfence::getWPFileContent( $dat['file'], $dat['cType'], $dat['cName'], $dat['cVersion'] );
|
1326 |
+
if ( $result['cerrorMsg'] ) {
|
1327 |
+
$errors[] = $result['cerrorMsg'];
|
1328 |
+
continue;
|
1329 |
+
} elseif ( ! $result['fileContent'] ) {
|
1330 |
+
$errors[] = 'We could not get the original file of ' . htmlentities( $file ) . ' to do a repair.';
|
1331 |
+
continue;
|
1332 |
+
}
|
1333 |
+
|
1334 |
+
if ( preg_match( '/\.\./', $file ) ) {
|
1335 |
+
$errors[] = 'An invalid file ' . htmlentities( $file ) . ' was specified for repair.';
|
1336 |
+
continue;
|
1337 |
+
}
|
1338 |
+
$fh = fopen( $localFile, 'w' );
|
1339 |
+
if ( ! $fh ) {
|
1340 |
+
$err = error_get_last();
|
1341 |
+
if ( preg_match( '/Permission denied/i', $err['message'] ) ) {
|
1342 |
+
$errMsg = "You don't have permission to repair " . htmlentities( $file ) . '. You need to either fix the file manually using FTP or change the file permissions and ownership so that your web server has write access to repair the file.';
|
1343 |
+
} else {
|
1344 |
+
$errMsg = 'We could not write to ' . htmlentities( $file ) . '. The error was: ' . $err['message'];
|
1345 |
+
}
|
1346 |
+
$errors[] = $errMsg;
|
1347 |
+
continue;
|
1348 |
+
}
|
1349 |
+
flock( $fh, LOCK_EX );
|
1350 |
+
$bytes = fwrite( $fh, $result['fileContent'] );
|
1351 |
+
flock( $fh, LOCK_UN );
|
1352 |
+
fclose( $fh );
|
1353 |
+
if ( $bytes < 1 ) {
|
1354 |
+
$errors[] = 'We could not write to ' . htmlentities( $file ) . ". ( $bytes bytes written ) You may not have permission to modify files on your WordPress server.";
|
1355 |
+
continue;
|
1356 |
+
}
|
1357 |
+
$filesWorkedOn ++;
|
1358 |
+
$issues->updateIssue( $id, 'delete' );
|
1359 |
+
}
|
1360 |
+
}
|
1361 |
+
$headMsg = '';
|
1362 |
+
$bodyMsg = '';
|
1363 |
+
$verb = 'del' === $op ? 'Deleted' : 'Repaired';
|
1364 |
+
$verb2 = 'del' === $op ? 'delete' : 'repair';
|
1365 |
+
if ( $filesWorkedOn > 0 && count( $errors ) > 0 ) {
|
1366 |
+
$headMsg = "$verb some files with errors";
|
1367 |
+
$bodyMsg = "$verb $filesWorkedOn files but we encountered the following errors with other files: " . implode( '<br />', $errors );
|
1368 |
+
} elseif ( $filesWorkedOn > 0 ) {
|
1369 |
+
$headMsg = "$verb $filesWorkedOn files successfully";
|
1370 |
+
$bodyMsg = "$verb $filesWorkedOn files successfully. No errors were encountered.";
|
1371 |
+
} elseif ( count( $errors ) > 0 ) {
|
1372 |
+
$headMsg = "Could not $verb2 files";
|
1373 |
+
$bodyMsg = "We could not $verb2 any of the files you selected. We encountered the following errors: " . implode( '<br />', $errors );
|
1374 |
+
} else {
|
1375 |
+
$headMsg = 'Nothing done';
|
1376 |
+
$bodyMsg = "We didn't $verb2 anything and no errors were found.";
|
1377 |
+
}
|
1378 |
+
|
1379 |
+
return array(
|
1380 |
+
'ok' => 1,
|
1381 |
+
'bulkHeading' => $headMsg,
|
1382 |
+
'bulkBody' => $bodyMsg,
|
1383 |
+
);
|
1384 |
+
} else {
|
1385 |
+
return array( 'errorMsg' => 'Invalid bulk operation selected' );
|
1386 |
+
}
|
1387 |
+
}
|
1388 |
+
|
1389 |
+
/**
|
1390 |
+
* Method bulk_ajax_operation()
|
1391 |
+
*
|
1392 |
+
* Handle the Wordfence bulk operations via AJAX.
|
1393 |
+
*
|
1394 |
+
* @used-by MainWP_Child_Wordfence::actions() Fire off certain Wordfence plugin actions.
|
1395 |
+
*
|
1396 |
+
* @return array Action result.
|
1397 |
+
*/
|
1398 |
+
public function bulk_ajax_operation() {
|
1399 |
+
return \wordfence::ajax_bulkOperation_callback();
|
1400 |
+
}
|
1401 |
+
|
1402 |
+
/**
|
1403 |
+
* Method delete_file()
|
1404 |
+
*
|
1405 |
+
* Delete corrupted files to fix issues detected by Wordfence.
|
1406 |
+
*
|
1407 |
+
* @used-by MainWP_Child_Wordfence::actions() Fire off certain Wordfence plugin actions.
|
1408 |
+
*
|
1409 |
+
* @return array Action result.
|
1410 |
+
*/
|
1411 |
+
public function delete_file() {
|
1412 |
+
$issueID =sanitize_text_field( wp_unslash( $_POST['issueID'] ) );
|
1413 |
+
$wfIssues = new \wfIssues();
|
1414 |
+
$issue = $wfIssues->getIssueByID( $issueID );
|
1415 |
+
if ( ! $issue ) {
|
1416 |
+
return array( 'errorMsg' => 'Could not delete file because we could not find that issue.' );
|
1417 |
+
}
|
1418 |
+
if ( ! $issue['data']['file'] ) {
|
1419 |
+
return array( 'errorMsg' => 'Could not delete file because that issue does not appear to be a file related issue.' );
|
1420 |
+
}
|
1421 |
+
$file = $issue['data']['file'];
|
1422 |
+
$localFile = ABSPATH . '/' . preg_replace( '/^[\.\/]+/', '', $file );
|
1423 |
+
$localFile = realpath( $localFile );
|
1424 |
+
if ( strpos( $localFile, ABSPATH ) !== 0 ) {
|
1425 |
+
return array( 'errorMsg' => 'An invalid file was requested for deletion.' );
|
1426 |
+
}
|
1427 |
+
if ( unlink( $localFile ) ) {
|
1428 |
+
$wfIssues->updateIssue( $issueID, 'delete' );
|
1429 |
+
|
1430 |
+
return array(
|
1431 |
+
'ok' => 1,
|
1432 |
+
'localFile' => $localFile,
|
1433 |
+
'file' => $file,
|
1434 |
+
);
|
1435 |
+
} else {
|
1436 |
+
$err = error_get_last();
|
1437 |
+
|
1438 |
+
return array( 'errorMsg' => 'Could not delete file ' . htmlentities( $file ) . '. The error was: ' . htmlentities( $err['message'] ) );
|
1439 |
+
}
|
1440 |
+
}
|
1441 |
+
|
1442 |
+
/**
|
1443 |
+
* Method restore_file()
|
1444 |
+
*
|
1445 |
+
* Restore files deleted by Wordfence.
|
1446 |
+
*
|
1447 |
+
* @used-by MainWP_Child_Wordfence::actions() Fire off certain Wordfence plugin actions.
|
1448 |
+
*
|
1449 |
+
* @return array Action result.
|
1450 |
+
*/
|
1451 |
+
public function restore_file() {
|
1452 |
+
$issueID = isset( $_POST['issueID'] ) ? sanitize_text_field( wp_unslash( $_POST['issueID'] ) ) : '';
|
1453 |
+
$wfIssues = new \wfIssues();
|
1454 |
+
$issue = $wfIssues->getIssueByID( $issueID );
|
1455 |
+
if ( ! $issue ) {
|
1456 |
+
return array( 'cerrorMsg' => 'We could not find that issue in our database.' );
|
1457 |
+
}
|
1458 |
+
$dat = $issue['data'];
|
1459 |
+
$result = \wordfence::getWPFileContent( $dat['file'], $dat['cType'], ( isset( $dat['cName'] ) ? $dat['cName'] : '' ), ( isset( $dat['cVersion'] ) ? $dat['cVersion'] : '' ) );
|
1460 |
+
$file = $dat['file'];
|
1461 |
+
if ( isset( $result['cerrorMsg'] ) && $result['cerrorMsg'] ) {
|
1462 |
+
return $result;
|
1463 |
+
} elseif ( ! $result['fileContent'] ) {
|
1464 |
+
return array( 'cerrorMsg' => 'We could not get the original file to do a repair.' );
|
1465 |
+
}
|
1466 |
+
|
1467 |
+
if ( preg_match( '/\.\./', $file ) ) {
|
1468 |
+
return array( 'cerrorMsg' => 'An invalid file was specified for repair.' );
|
1469 |
+
}
|
1470 |
+
$localFile = ABSPATH . '/' . preg_replace( '/^[\.\/]+/', '', $file );
|
1471 |
+
$fh = fopen( $localFile, 'w' );
|
1472 |
+
if ( ! $fh ) {
|
1473 |
+
$err = error_get_last();
|
1474 |
+
if ( preg_match( '/Permission denied/i', $err['message'] ) ) {
|
1475 |
+
$errMsg = "You don't have permission to repair that file. You need to either fix the file manually using FTP or change the file permissions and ownership so that your web server has write access to repair the file.";
|
1476 |
+
} else {
|
1477 |
+
$errMsg = 'We could not write to that file. The error was: ' . $err['message'];
|
1478 |
+
}
|
1479 |
+
|
1480 |
+
return array( 'cerrorMsg' => $errMsg );
|
1481 |
+
}
|
1482 |
+
flock( $fh, LOCK_EX );
|
1483 |
+
$bytes = fwrite( $fh, $result['fileContent'] );
|
1484 |
+
flock( $fh, LOCK_UN );
|
1485 |
+
fclose( $fh );
|
1486 |
+
if ( $bytes < 1 ) {
|
1487 |
+
return array( 'cerrorMsg' => "We could not write to that file. ( $bytes bytes written ) You may not have permission to modify files on your WordPress server." );
|
1488 |
+
}
|
1489 |
+
$wfIssues->updateIssue( $issueID, 'delete' );
|
1490 |
+
|
1491 |
+
return array(
|
1492 |
+
'ok' => 1,
|
1493 |
+
'file' => $localFile,
|
1494 |
+
);
|
1495 |
+
}
|
1496 |
+
|
1497 |
+
/**
|
1498 |
+
* Method simple_crypt()
|
1499 |
+
*
|
1500 |
+
* Encrypt or decrypt data.
|
1501 |
+
*
|
1502 |
+
* @param string $key Contains the cryption key.
|
1503 |
+
* @param array $data Array containing data that needs to be encrypted or decrypted.
|
1504 |
+
* @param string $action Contains preferred action, encrypt or decrypt.
|
1505 |
+
*
|
1506 |
+
* @used-by save_settings_new() Save new Wordfence settigns.
|
1507 |
+
* @used-by save_settings() Save Wordfence settigns.
|
1508 |
+
*
|
1509 |
+
* @return string Encrypted or decrypted data.
|
1510 |
+
*/
|
1511 |
+
public function simple_crypt( $key, $data, $action = 'encrypt' ) {
|
1512 |
+
$res = '';
|
1513 |
+
if ( 'encrypt' == $action ) {
|
1514 |
+
$string = base64_encode( serialize( $data ) ); // phpcs:ignore WordPress.PHP.DiscouragedPHPFunctions -- Required for backwards compatibility.
|
1515 |
+
} else {
|
1516 |
+
$string = $data;
|
1517 |
+
}
|
1518 |
+
$string_lenght = strlen( $string );
|
1519 |
+
for ( $i = 0; $i < $string_lenght; $i++ ) {
|
1520 |
+
$c = ord( substr( $string, $i ) );
|
1521 |
+
if ( 'encrypt' == $action ) {
|
1522 |
+
$c += ord( substr( $key, ( ( $i + 1 ) % strlen( $key ) ) ) );
|
1523 |
+
$res .= chr( $c & 0xFF );
|
1524 |
+
} else {
|
1525 |
+
$c -= ord( substr( $key, ( ( $i + 1 ) % strlen( $key ) ) ) );
|
1526 |
+
$res .= chr( abs( $c ) & 0xFF );
|
1527 |
+
}
|
1528 |
+
}
|
1529 |
+
|
1530 |
+
if ( 'encrypt' !== $action ) {
|
1531 |
+
$res = unserialize( base64_decode( $res ) ); // phpcs:ignore WordPress.PHP.DiscouragedPHPFunctions -- Required for backwards compatibility.
|
1532 |
+
}
|
1533 |
+
return $res;
|
1534 |
+
}
|
1535 |
+
|
1536 |
+
/**
|
1537 |
+
* Method save_settings_new()
|
1538 |
+
*
|
1539 |
+
* Save new Wordfence settings.
|
1540 |
+
*
|
1541 |
+
* @uses simple_crypt() Encrypt or decrypt data.
|
1542 |
+
*
|
1543 |
+
* @used-by MainWP_Child_Wordfence::actions() Fire off certain Wordfence plugin actions.
|
1544 |
+
*
|
1545 |
+
* @throws \Exception Error message.
|
1546 |
+
*
|
1547 |
+
* @return array Action result.
|
1548 |
+
*/
|
1549 |
+
public function save_settings_new() {
|
1550 |
+
if ( isset( $_POST['encrypted'] ) ) {
|
1551 |
+
$settings = $this->simple_crypt( 'thisisakey', $_POST['settings'], 'decrypt' ); // custom fix to pass through security rules of Dreamhost!
|
1552 |
+
} else {
|
1553 |
+
$settings = isset( $_POST['settings'] ) ? maybe_unserialize( base64_decode( wp_unslash( $_POST['settings'] ) ) ) : ''; // phpcs:ignore WordPress.PHP.DiscouragedPHPFunctions -- Required for backwards compatibility.
|
1554 |
+
}
|
1555 |
+
|
1556 |
+
$section = isset( $_POST['savingSection'] ) ? sanitize_text_field( wp_unslash( $_POST['savingSection'] ) ) : '';
|
1557 |
+
$saving_opts = self::get_section_settings( $section );
|
1558 |
+
|
1559 |
+
$result = array();
|
1560 |
+
|
1561 |
+
if ( is_array( $settings ) && count( $settings ) > 0 && count( $saving_opts ) > 0 ) {
|
1562 |
+
|
1563 |
+
$reload = '';
|
1564 |
+
$opts = $settings;
|
1565 |
+
|
1566 |
+
// if saving then validate data!
|
1567 |
+
if ( in_array( 'liveTraf_ignoreUsers', $saving_opts ) ) {
|
1568 |
+
$validUsers = array();
|
1569 |
+
$invalidUsers = array();
|
1570 |
+
foreach ( explode( ',', $opts['liveTraf_ignoreUsers'] ) as $val ) {
|
1571 |
+
$val = trim( $val );
|
1572 |
+
if ( strlen( $val ) > 0 ) {
|
1573 |
+
if ( get_user_by( 'login', $val ) ) {
|
1574 |
+
$validUsers[] = $val;
|
1575 |
+
} else {
|
1576 |
+
$invalidUsers[] = $val;
|
1577 |
+
}
|
1578 |
+
}
|
1579 |
+
}
|
1580 |
+
|
1581 |
+
if ( count( $invalidUsers ) > 0 ) {
|
1582 |
+
$result['invalid_users'] = htmlentities( implode( ', ', $invalidUsers ) );
|
1583 |
+
}
|
1584 |
+
|
1585 |
+
if ( count( $validUsers ) > 0 ) {
|
1586 |
+
$opts['liveTraf_ignoreUsers'] = implode( ',', $validUsers );
|
1587 |
+
} else {
|
1588 |
+
$opts['liveTraf_ignoreUsers'] = '';
|
1589 |
+
}
|
1590 |
+
}
|
1591 |
+
|
1592 |
+
// if saving then validate data!
|
1593 |
+
if ( in_array( 'other_WFNet', $saving_opts ) ) {
|
1594 |
+
if ( ! $opts['other_WFNet'] ) {
|
1595 |
+
$wfdb = new \wfDB();
|
1596 |
+
$table_wfBlocks7 = \wfDB::networkTable( 'wfBlocks7' );
|
1597 |
+
$wfdb->queryWrite( "delete from {$table_wfBlocks7} where wfsn=1 and permanent=0" );
|
1598 |
+
}
|
1599 |
+
}
|
1600 |
+
|
1601 |
+
$regenerateHtaccess = false;
|
1602 |
+
// if saving then validate data!
|
1603 |
+
if ( in_array( 'bannedURLs', $saving_opts ) ) {
|
1604 |
+
if ( \wfConfig::get( 'bannedURLs', false ) !== $opts['bannedURLs'] ) {
|
1605 |
+
$regenerateHtaccess = true;
|
1606 |
+
}
|
1607 |
+
}
|
1608 |
+
// save the settings!
|
1609 |
+
foreach ( $opts as $key => $val ) {
|
1610 |
+
// check saving section fields.
|
1611 |
+
if ( in_array( $key, $saving_opts ) ) {
|
1612 |
+
if ( 'apiKey' == $key ) { // Don't save API key yet!
|
1613 |
+
continue;
|
1614 |
+
}
|
1615 |
+
if ( in_array( $key, self::$firewall_options_filter ) ) {
|
1616 |
+
\wfWAF::getInstance()->getStorageEngine()->setConfig( $key, $val );
|
1617 |
+
} elseif ( 'whitelistedServices' == $key ) {
|
1618 |
+
if (is_string($val)) { //Already JSON.
|
1619 |
+
\wfConfig::set($key, $val);
|
1620 |
+
} else {
|
1621 |
+
\wfConfig::setJSON($key, (array) $val);
|
1622 |
+
}
|
1623 |
+
// set whitelistedServiceIPs.
|
1624 |
+
\wfWAF::getInstance()->getStorageEngine()->setConfig('whitelistedServiceIPs', @json_encode(\wfUtils::whitelistedServiceIPs()), 'synced');
|
1625 |
+
if (method_exists(\wfWAF::getInstance()->getStorageEngine(), 'purgeIPBlocks')) {
|
1626 |
+
\wfWAF::getInstance()->getStorageEngine()->purgeIPBlocks(\wfWAFStorageInterface::IP_BLOCKS_BLACKLIST);
|
1627 |
+
}
|
1628 |
+
} elseif ( 'betaThreatDefenseFeed' == $key ) {
|
1629 |
+
$val = \wfUtils::truthyToBoolean($val);
|
1630 |
+
\wfConfig::set($key, $val);
|
1631 |
+
if (class_exists('\wfWAFConfig')) {
|
1632 |
+
\wfWAFConfig::set('betaThreatDefenseFeed', $val, 'synced');
|
1633 |
+
}
|
1634 |
+
} else {
|
1635 |
+
\wfConfig::set( $key, $val ); // save it!
|
1636 |
+
}
|
1637 |
+
}
|
1638 |
+
}
|
1639 |
+
|
1640 |
+
if ( $regenerateHtaccess && ( 'falcon' == \wfConfig::get( 'cacheType' ) ) ) {
|
1641 |
+
\wfCache::addHtaccessCode( 'add' );
|
1642 |
+
}
|
1643 |
+
|
1644 |
+
// if saving then validate data!
|
1645 |
+
if ( in_array( 'autoUpdate', $saving_opts ) ) {
|
1646 |
+
if ( '1' === $opts['autoUpdate'] ) {
|
1647 |
+
\wfConfig::enableAutoUpdate();
|
1648 |
+
} elseif ( '0' === $opts['autoUpdate'] ) {
|
1649 |
+
\wfConfig::disableAutoUpdate();
|
1650 |
+
}
|
1651 |
+
}
|
1652 |
+
|
1653 |
+
// if saving then validate data!
|
1654 |
+
if ( in_array( 'disableCodeExecutionUploads', $saving_opts ) ) {
|
1655 |
+
if ( isset( $opts['disableCodeExecutionUploads'] ) ) {
|
1656 |
+
try {
|
1657 |
+
if ( $opts['disableCodeExecutionUploads'] ) {
|
1658 |
+
\wfConfig::disableCodeExecutionForUploads();
|
1659 |
+
} else {
|
1660 |
+
\wfConfig::removeCodeExecutionProtectionForUploads();
|
1661 |
+
}
|
1662 |
+
} catch ( \wfConfigException $e ) {
|
1663 |
+
return array( 'error' => $e->getMessage() );
|
1664 |
+
}
|
1665 |
+
}
|
1666 |
+
}
|
1667 |
+
|
1668 |
+
// if saving then validate data!
|
1669 |
+
if ( in_array( 'email_summary_enabled', $saving_opts ) ) {
|
1670 |
+
if ( isset( $opts['email_summary_enabled'] ) ) {
|
1671 |
+
if ( ! empty( $opts['email_summary_enabled'] ) ) {
|
1672 |
+
\wfConfig::set( 'email_summary_enabled', 1 );
|
1673 |
+
\wfConfig::set( 'email_summary_interval', $opts['email_summary_interval'] );
|
1674 |
+
\wfConfig::set( 'email_summary_excluded_directories', $opts['email_summary_excluded_directories'] );
|
1675 |
+
\wfActivityReport::scheduleCronJob();
|
1676 |
+
} else {
|
1677 |
+
\wfConfig::set( 'email_summary_enabled', 0 );
|
1678 |
+
\wfActivityReport::disableCronJob();
|
1679 |
+
}
|
1680 |
+
}
|
1681 |
+
}
|
1682 |
+
|
1683 |
+
// if saving then validate data!
|
1684 |
+
if ( in_array( 'scheduleScan', $saving_opts ) ) {
|
1685 |
+
$sch = isset( $opts['scheduleScan'] ) ? $opts['scheduleScan'] : '';
|
1686 |
+
if ( get_option( 'mainwp_child_wordfence_cron_time' ) !== $sch ) {
|
1687 |
+
update_option( 'mainwp_child_wordfence_cron_time', $sch );
|
1688 |
+
$sched = wp_next_scheduled( 'mainwp_child_wordfence_cron_scan' );
|
1689 |
+
if ( false !== $sched ) {
|
1690 |
+
wp_unschedule_event( $sched, 'mainwp_child_wordfence_cron_scan' );
|
1691 |
+
}
|
1692 |
+
}
|
1693 |
+
}
|
1694 |
+
|
1695 |
+
$result['cacheType'] = \wfConfig::get( 'cacheType' );
|
1696 |
+
$result['paidKeyMsg'] = false;
|
1697 |
+
|
1698 |
+
// if saving then validate data!
|
1699 |
+
if ( in_array( 'apiKey', $saving_opts ) ) {
|
1700 |
+
|
1701 |
+
$apiKey = trim( $_POST['apiKey'] );
|
1702 |
+
$apiKey = strtolower( trim( $apiKey ) );
|
1703 |
+
$existingAPIKey = \wfConfig::get( 'apiKey', '' );
|
1704 |
+
|
1705 |
+
$ping = false;
|
1706 |
+
if ( empty( $apiKey ) && empty( $existingAPIKey ) ) { // then try to get one.
|
1707 |
+
|
1708 |
+
$api = new \wfAPI( '', \wfUtils::getWPVersion() );
|
1709 |
+
try {
|
1710 |
+
$keyData = $api->call( 'get_anon_api_key' );
|
1711 |
+
if ( $keyData['ok'] && $keyData['apiKey'] ) {
|
1712 |
+
\wfConfig::set( 'apiKey', $keyData['apiKey'] );
|
1713 |
+
\wfConfig::set( 'isPaid', 0 );
|
1714 |
+
\wfConfig::set( 'keyType', \wfAPI::KEY_TYPE_FREE );
|
1715 |
+
\wordfence::licenseStatusChanged();
|
1716 |
+
$result['apiKey'] = $keyData['apiKey'];
|
1717 |
+
$apiKey = $keyData['apiKey'];
|
1718 |
+
$result['isPaid'] = 0;
|
1719 |
+
$reload = 'reload';
|
1720 |
+
} else {
|
1721 |
+
throw new \Exception( "The Wordfence server's response did not contain the expected elements." );
|
1722 |
+
}
|
1723 |
+
} catch ( \Exception $e ) {
|
1724 |
+
$result['error'] = 'Your options have been saved, but you left your license key blank, so we tried to get you a free license key from the Wordfence servers. There was a problem fetching the free key: ' . wp_kses( $e->getMessage(), array() );
|
1725 |
+
return $result;
|
1726 |
+
}
|
1727 |
+
} elseif ( ! empty( $apiKey ) && $existingAPIKey != $apiKey ) {
|
1728 |
+
$api = new \wfAPI( $apiKey, \wfUtils::getWPVersion() );
|
1729 |
+
try {
|
1730 |
+
$res = $api->call( 'check_api_key', array(), array( 'previousLicense' => $existingAPIKey ) );
|
1731 |
+
if ( $res['ok'] && isset( $res['isPaid'] ) ) {
|
1732 |
+
|
1733 |
+
$isPaid = \wfUtils::truthyToBoolean( $res['isPaid'] );
|
1734 |
+
\wfConfig::set( 'apiKey', $apiKey );
|
1735 |
+
\wfConfig::set( 'isPaid', $isPaid ); // res['isPaid'] is boolean coming back as JSON and turned back into PHP struct. Assuming JSON to PHP handles bools.
|
1736 |
+
\wordfence::licenseStatusChanged();
|
1737 |
+
if ( ! $isPaid ) {
|
1738 |
+
\wfConfig::set( 'keyType', \wfAPI::KEY_TYPE_FREE );
|
1739 |
+
}
|
1740 |
+
|
1741 |
+
$result['apiKey'] = $apiKey;
|
1742 |
+
$result['isPaid'] = $isPaid;
|
1743 |
+
if ( $isPaid ) {
|
1744 |
+
$result['paidKeyMsg'] = true;
|
1745 |
+
}
|
1746 |
+
|
1747 |
+
$ping = true;
|
1748 |
+
$reload = 'reload';
|
1749 |
+
} else {
|
1750 |
+
throw new \Exception( 'We could not understand the Wordfence API server reply when updating your API key.' );
|
1751 |
+
}
|
1752 |
+
} catch ( \Exception $e ) {
|
1753 |
+
$result['error'] = 'Your options have been saved. However we noticed you changed your API key and we tried to verify it with the Wordfence servers and received an error: ' . htmlentities( $e->getMessage() );
|
1754 |
+
return $result;
|
1755 |
+
}
|
1756 |
+
} else {
|
1757 |
+
$ping = true;
|
1758 |
+
$apiKey = $existingAPIKey;
|
1759 |
+
}
|
1760 |
+
|
1761 |
+
if ( $ping ) {
|
1762 |
+
|
1763 |
+
$api = new \wfAPI( $apiKey, \wfUtils::getWPVersion() );
|
1764 |
+
try {
|
1765 |
+
$keyType = \wfAPI::KEY_TYPE_FREE;
|
1766 |
+
$keyData = $api->call(
|
1767 |
+
'ping_api_key',
|
1768 |
+
array(),
|
1769 |
+
array(
|
1770 |
+
'supportHash' => \wfConfig::get( 'supportHash', '' ),
|
1771 |
+
'whitelistHash' => \wfConfig::get( 'whitelistHash', '' ),
|
1772 |
+
)
|
1773 |
+
);
|
1774 |
+
if ( isset( $keyData['_isPaidKey'] ) ) {
|
1775 |
+
$keyType = \wfConfig::get( 'keyType' );
|
1776 |
+
}
|
1777 |
+
if ( isset( $keyData['dashboard'] ) ) {
|
1778 |
+
\wfConfig::set( 'lastDashboardCheck', time() );
|
1779 |
+
\wfDashboard::processDashboardResponse( $keyData['dashboard'] );
|
1780 |
+
}
|
1781 |
+
if ( isset( $keyData['support'] ) && isset( $keyData['supportHash'] ) ) {
|
1782 |
+
\wfConfig::set( 'supportContent', $keyData['support'] );
|
1783 |
+
\wfConfig::set( 'supportHash', $keyData['supportHash'] );
|
1784 |
+
}
|
1785 |
+
if ( isset( $keyData['_whitelist'] ) && isset( $keyData['_whitelistHash'] ) ) {
|
1786 |
+
\wfConfig::setJSON( 'whitelistPresets', $keyData['_whitelist'] );
|
1787 |
+
\wfConfig::set( 'whitelistHash', $keyData['_whitelistHash'] );
|
1788 |
+
}
|
1789 |
+
if ( isset( $keyData['scanSchedule'] ) && is_array( $keyData['scanSchedule'] ) ) {
|
1790 |
+
\wfConfig::set_ser( 'noc1ScanSchedule', $keyData['scanSchedule'] );
|
1791 |
+
if ( \wfScanner::shared()->schedulingMode() == \wfScanner::SCAN_SCHEDULING_MODE_AUTOMATIC ) {
|
1792 |
+
\wfScanner::shared()->scheduleScans();
|
1793 |
+
}
|
1794 |
+
}
|
1795 |
+
|
1796 |
+
\wfConfig::set( 'keyType', $keyType );
|
1797 |
+
|
1798 |
+
if ( ! isset( $result['apiKey'] ) ) {
|
1799 |
+
$isPaid = ( \wfAPI::KEY_TYPE_FREE == $keyType ) ? false : true;
|
1800 |
+
$result['apiKey'] = $apiKey;
|
1801 |
+
$result['isPaid'] = $isPaid;
|
1802 |
+
if ( $isPaid ) {
|
1803 |
+
$result['paidKeyMsg'] = true;
|
1804 |
+
}
|
1805 |
+
}
|
1806 |
+
} catch ( \Exception $e ) {
|
1807 |
+
$result['error'] = 'Your options have been saved. However we tried to verify your license key with the Wordfence servers and received an error: ' . wp_kses( $e->getMessage(), array() );
|
1808 |
+
return $result;
|
1809 |
+
}
|
1810 |
+
}
|
1811 |
+
}
|
1812 |
+
|
1813 |
+
$result['ok'] = 1;
|
1814 |
+
$result['reload'] = $reload;
|
1815 |
+
|
1816 |
+
return $result;
|
1817 |
+
} else {
|
1818 |
+
$result['error'] = 'Empty settings';
|
1819 |
+
}
|
1820 |
+
|
1821 |
+
return $result;
|
1822 |
+
}
|
1823 |
+
|
1824 |
+
/**
|
1825 |
+
* Method recent_traffic()
|
1826 |
+
*
|
1827 |
+
* Load the recent traffic.
|
1828 |
+
*
|
1829 |
+
* @used-by MainWP_Child_Wordfence::actions() Fire off certain Wordfence plugin actions.
|
1830 |
+
*
|
1831 |
+
* @return array Action result.
|
1832 |
+
*/
|
1833 |
+
public static function recent_traffic() {
|
1834 |
+
return \wordfence::ajax_recentTraffic_callback();
|
1835 |
+
}
|
1836 |
+
|
1837 |
+
/**
|
1838 |
+
* Method save_settings()
|
1839 |
+
*
|
1840 |
+
* Save Wordfence settings.
|
1841 |
+
*
|
1842 |
+
* @uses simple_crypt() Encrypt or decrypt data.
|
1843 |
+
*
|
1844 |
+
* @used-by MainWP_Child_Wordfence::actions() Fire off certain Wordfence plugin actions.
|
1845 |
+
*
|
1846 |
+
* @throws \Exception Error message.
|
1847 |
+
*
|
1848 |
+
* @return array Action result.
|
1849 |
+
*/
|
1850 |
+
public function save_setting() {
|
1851 |
+
if ( isset( $_POST['encrypted'] ) ) {
|
1852 |
+
$settings = $this->simple_crypt( 'thisisakey', $_POST['settings'], 'decrypt' ); // to fix pass through sec rules of Dreamhost!
|
1853 |
+
} else {
|
1854 |
+
$settings = isset( $_POST['settings'] ) ? maybe_unserialize( base64_decode( wp_unslash( $_POST['settings'] ) ) ) : ''; // phpcs:ignore WordPress.PHP.DiscouragedPHPFunctions -- base64_encode function is used for http encode compatible..
|
1855 |
+
}
|
1856 |
+
|
1857 |
+
if ( is_array( $settings ) && count( $settings ) > 0 ) {
|
1858 |
+
$result = array();
|
1859 |
+
$reload = '';
|
1860 |
+
$opts = $settings;
|
1861 |
+
$validUsers = array();
|
1862 |
+
$invalidUsers = array();
|
1863 |
+
foreach ( explode( ',', $opts['liveTraf_ignoreUsers'] ) as $val ) {
|
1864 |
+
$val = trim( $val );
|
1865 |
+
if ( strlen( $val ) > 0 ) {
|
1866 |
+
if ( get_user_by( 'login', $val ) ) {
|
1867 |
+
$validUsers[] = $val;
|
1868 |
+
} else {
|
1869 |
+
$invalidUsers[] = $val;
|
1870 |
+
}
|
1871 |
+
}
|
1872 |
+
}
|
1873 |
+
|
1874 |
+
if ( count( $invalidUsers ) > 0 ) {
|
1875 |
+
$result['invalid_users'] = htmlentities( implode( ', ', $invalidUsers ) );
|
1876 |
+
}
|
1877 |
+
|
1878 |
+
if ( count( $validUsers ) > 0 ) {
|
1879 |
+
$opts['liveTraf_ignoreUsers'] = implode( ',', $validUsers );
|
1880 |
+
} else {
|
1881 |
+
$opts['liveTraf_ignoreUsers'] = '';
|
1882 |
+
}
|
1883 |
+
|
1884 |
+
if ( ! $opts['other_WFNet'] ) {
|
1885 |
+
$wfdb = new \wfDB();
|
1886 |
+
$table_wfBlocks7 = \wfDB::networkTable( 'wfBlocks7' );
|
1887 |
+
$wfdb->queryWrite( "delete from {$table_wfBlocks7} where wfsn=1 and permanent=0" );
|
1888 |
+
}
|
1889 |
+
|
1890 |
+
$regenerateHtaccess = false;
|
1891 |
+
if ( \wfConfig::get( 'bannedURLs', false ) !== $opts['bannedURLs'] ) {
|
1892 |
+
$regenerateHtaccess = true;
|
1893 |
+
}
|
1894 |
+
|
1895 |
+
foreach ( $opts as $key => $val ) {
|
1896 |
+
if ( in_array( $key, self::$options_filter ) ) {
|
1897 |
+
if ( 'apiKey' !== $key ) { // Don't save API key yet!
|
1898 |
+
\wfConfig::set( $key, $val );
|
1899 |
+
}
|
1900 |
+
}
|
1901 |
+
}
|
1902 |
+
|
1903 |
+
if ( $regenerateHtaccess && ( 'falcon' == \wfConfig::get( 'cacheType' ) ) ) {
|
1904 |
+
\wfCache::addHtaccessCode( 'add' );
|
1905 |
+
}
|
1906 |
+
|
1907 |
+
if ( '1' === $opts['autoUpdate'] ) {
|
1908 |
+
\wfConfig::enableAutoUpdate();
|
1909 |
+
} elseif ( '0' === $opts['autoUpdate'] ) {
|
1910 |
+
\wfConfig::disableAutoUpdate();
|
1911 |
+
}
|
1912 |
+
|
1913 |
+
if ( isset( $opts['disableCodeExecutionUploads'] ) ) {
|
1914 |
+
try {
|
1915 |
+
if ( $opts['disableCodeExecutionUploads'] ) {
|
1916 |
+
\wfConfig::disableCodeExecutionForUploads();
|
1917 |
+
} else {
|
1918 |
+
\wfConfig::removeCodeExecutionProtectionForUploads();
|
1919 |
+
}
|
1920 |
+
} catch ( \wfConfig\Exception $e ) {
|
1921 |
+
return array( 'error' => $e->getMessage() );
|
1922 |
+
}
|
1923 |
+
}
|
1924 |
+
|
1925 |
+
if ( isset( $opts['email_summary_enabled'] ) ) {
|
1926 |
+
if ( ! empty( $opts['email_summary_enabled'] ) ) {
|
1927 |
+
\wfConfig::set( 'email_summary_enabled', 1 );
|
1928 |
+
\wfConfig::set( 'email_summary_interval', $opts['email_summary_interval'] );
|
1929 |
+
\wfConfig::set( 'email_summary_excluded_directories', $opts['email_summary_excluded_directories'] );
|
1930 |
+
\wfActivityReport::scheduleCronJob();
|
1931 |
+
} else {
|
1932 |
+
\wfConfig::set( 'email_summary_enabled', 0 );
|
1933 |
+
\wfActivityReport::disableCronJob();
|
1934 |
+
}
|
1935 |
+
}
|
1936 |
+
|
1937 |
+
$sch = isset( $opts['scheduleScan'] ) ? $opts['scheduleScan'] : '';
|
1938 |
+
if ( get_option( 'mainwp_child_wordfence_cron_time' ) !== $sch ) {
|
1939 |
+
update_option( 'mainwp_child_wordfence_cron_time', $sch );
|
1940 |
+
$sched = wp_next_scheduled( 'mainwp_child_wordfence_cron_scan' );
|
1941 |
+
if ( false !== $sched ) {
|
1942 |
+
wp_unschedule_event( $sched, 'mainwp_child_wordfence_cron_scan' );
|
1943 |
+
}
|
1944 |
+
}
|
1945 |
+
|
1946 |
+
$result['cacheType'] = \wfConfig::get( 'cacheType' );
|
1947 |
+
$result['paidKeyMsg'] = false;
|
1948 |
+
$apiKey = trim( $_POST['apiKey'] );
|
1949 |
+
if ( ! $apiKey ) { // Empty API key (after trim above), then try to get one.
|
1950 |
+
$api = new \wfAPI( '', \wfUtils::getWPVersion() );
|
1951 |
+
try {
|
1952 |
+
$keyData = $api->call( 'get_anon_api_key' );
|
1953 |
+
if ( $keyData['ok'] && $keyData['apiKey'] ) {
|
1954 |
+
\wfConfig::set( 'apiKey', $keyData['apiKey'] );
|
1955 |
+
\wfConfig::set( 'isPaid', 0 );
|
1956 |
+
$result['apiKey'] = $keyData['apiKey'];
|
1957 |
+
$result['isPaid'] = 0;
|
1958 |
+
$reload = 'reload';
|
1959 |
+
} else {
|
1960 |
+
throw new \Exception( "We could not understand the Wordfence server's response because it did not contain an 'ok' and 'apiKey' element." );
|
1961 |
+
}
|
1962 |
+
} catch ( \Exception $e ) {
|
1963 |
+
$result['error'] = 'Your options have been saved, but we encountered a problem. You left your API key blank, so we tried to get you a free API key from the Wordfence servers. However we encountered a problem fetching the free key: ' . htmlentities( $e->getMessage() );
|
1964 |
+
|
1965 |
+
return $result;
|
1966 |
+
}
|
1967 |
+
} elseif ( \wfConfig::get( 'apiKey' ) !== $apiKey ) {
|
1968 |
+
$api = new \wfAPI( $apiKey, \wfUtils::getWPVersion() );
|
1969 |
+
try {
|
1970 |
+
$res = $api->call( 'check_api_key', array(), array() );
|
1971 |
+
if ( $res['ok'] && isset( $res['isPaid'] ) ) {
|
1972 |
+
\wfConfig::set( 'apiKey', $apiKey );
|
1973 |
+
\wfConfig::set( 'isPaid', $res['isPaid'] ); // res['isPaid'] is boolean coming back as JSON and turned back into PHP struct. Assuming JSON to PHP handles bools.
|
1974 |
+
$result['apiKey'] = $apiKey;
|
1975 |
+
$result['isPaid'] = $res['isPaid'];
|
1976 |
+
if ( $res['isPaid'] ) {
|
1977 |
+
$result['paidKeyMsg'] = true;
|
1978 |
+
}
|
1979 |
+
$reload = 'reload';
|
1980 |
+
} else {
|
1981 |
+
throw new \Exception( 'We could not understand the Wordfence API server reply when updating your API key.' );
|
1982 |
+
}
|
1983 |
+
} catch ( \Exception $e ) {
|
1984 |
+
$result['error'] = 'Your options have been saved. However we noticed you changed your API key and we tried to verify it with the Wordfence servers and received an error: ' . htmlentities( $e->getMessage() );
|
1985 |
+
|
1986 |
+
return $result;
|
1987 |
+
}
|
1988 |
+
} else {
|
1989 |
+
try {
|
1990 |
+
$api = new \wfAPI( $apiKey, \wfUtils::getWPVersion() );
|
1991 |
+
$res = $api->call( 'ping_api_key', array(), array() );
|
1992 |
+
} catch ( \Exception $e ) {
|
1993 |
+
$result['error'] = 'Your options have been saved. However we noticed you do not change your API key and we tried to verify it with the Wordfence servers and received an error: ' . htmlentities( $e->getMessage() );
|
1994 |
+
|
1995 |
+
return $result;
|
1996 |
+
}
|
1997 |
+
}
|
1998 |
+
$result['ok'] = 1;
|
1999 |
+
$result['reload'] = $reload;
|
2000 |
+
|
2001 |
+
return $result;
|
2002 |
+
}
|
2003 |
+
}
|
2004 |
+
|
2005 |
+
/**
|
2006 |
+
* Method export_settings()
|
2007 |
+
*
|
2008 |
+
* Export the Wordfence settings.
|
2009 |
+
*
|
2010 |
+
* @used-by MainWP_Child_Wordfence::actions() Fire off certain Wordfence plugin actions.
|
2011 |
+
*
|
2012 |
+
* @throws \Exception Error message.
|
2013 |
+
*
|
2014 |
+
* @return array Action result.
|
2015 |
+
*/
|
2016 |
+
public function export_settings() {
|
2017 |
+
|
2018 |
+
$export = array();
|
2019 |
+
|
2020 |
+
// Basic Options.
|
2021 |
+
$keys = \wfConfig::getExportableOptionsKeys();
|
2022 |
+
foreach ( $keys as $key ) {
|
2023 |
+
$export[ $key ] = \wfConfig::get( $key, '' );
|
2024 |
+
}
|
2025 |
+
|
2026 |
+
// Serialized Options.
|
2027 |
+
$export['scanSched'] = \wfConfig::get_ser( 'scanSched', array() );
|
2028 |
+
|
2029 |
+
// Table-based Options.
|
2030 |
+
$export['blocks'] = \wfBlock::exportBlocks();
|
2031 |
+
|
2032 |
+
// Make the API call.
|
2033 |
+
try {
|
2034 |
+
$api = new \wfAPI( \wfConfig::get( 'apiKey' ), \wfUtils::getWPVersion() );
|
2035 |
+
$res = $api->call( 'export_options', array(), array( 'export' => wp_json_encode( $export ) ) );
|
2036 |
+
if ( $res['ok'] && $res['token'] ) {
|
2037 |
+
return array(
|
2038 |
+
'ok' => 1,
|
2039 |
+
'token' => $res['token'],
|
2040 |
+
);
|
2041 |
+
} elseif ( $res['err'] ) {
|
2042 |
+
return array( 'errorExport' => __( 'An error occurred: ', 'wordfence' ) . $res['err'] );
|
2043 |
+
} else {
|
2044 |
+
throw new \Exception( __( 'Invalid response: ', 'wordfence' ) );
|
2045 |
+
}
|
2046 |
+
} catch ( \Exception $e ) {
|
2047 |
+
return array( 'errorExport' => __( 'An error occurred: ', 'wordfence' ) . $e->getMessage() );
|
2048 |
+
}
|
2049 |
+
}
|
2050 |
+
|
2051 |
+
/**
|
2052 |
+
* Method import_settings()
|
2053 |
+
*
|
2054 |
+
* Import the Wordfence settings.
|
2055 |
+
*
|
2056 |
+
* @used-by MainWP_Child_Wordfence::actions() Fire off certain Wordfence plugin actions.
|
2057 |
+
*
|
2058 |
+
* @throws \Exception Error message.
|
2059 |
+
*
|
2060 |
+
* @return array Action result.
|
2061 |
+
*/
|
2062 |
+
public function import_settings() {
|
2063 |
+
$token = isset( $_POST['token'] ) ? sanitize_text_field( wp_unslash( $_POST['token'] ) ) : '';
|
2064 |
+
try {
|
2065 |
+
$api = new \wfAPI( \wfConfig::get( 'apiKey' ), \wfUtils::getWPVersion() );
|
2066 |
+
$res = $api->call( 'import_options', array(), array( 'token' => $token ) );
|
2067 |
+
if ( $res['ok'] && $res['export'] ) {
|
2068 |
+
$totalSet = 0;
|
2069 |
+
$import = json_decode( $res['export'], true );
|
2070 |
+
if ( ! is_array( $import ) ) {
|
2071 |
+
return array( 'errorImport' => __( 'An error occurred: Invalid options format received.', 'wordfence' ) );
|
2072 |
+
}
|
2073 |
+
|
2074 |
+
// Basic Options.
|
2075 |
+
$keys = \wfConfig::getExportableOptionsKeys();
|
2076 |
+
$toSet = array();
|
2077 |
+
foreach ( $keys as $key ) {
|
2078 |
+
if ( isset( $import[ $key ] ) ) {
|
2079 |
+
$toSet[ $key ] = $import[ $key ];
|
2080 |
+
}
|
2081 |
+
}
|
2082 |
+
|
2083 |
+
if ( count( $toSet ) ) {
|
2084 |
+
$validation = \wfConfig::validate( $toSet );
|
2085 |
+
$skipped = array();
|
2086 |
+
if ( true !== $validation ) {
|
2087 |
+
foreach ( $validation as $error ) {
|
2088 |
+
$skipped[ $error['option'] ] = $error['error'];
|
2089 |
+
unset( $toSet[ $error['option'] ] );
|
2090 |
+
}
|
2091 |
+
}
|
2092 |
+
|
2093 |
+
$totalSet += count( $toSet );
|
2094 |
+
\wfConfig::save( \wfConfig::clean( $toSet ) );
|
2095 |
+
}
|
2096 |
+
|
2097 |
+
// Serialized Options.
|
2098 |
+
if ( isset( $import['scanSched'] ) && is_array( $import['scanSched'] ) ) {
|
2099 |
+
\wfConfig::set_ser( 'scanSched', $import['scanSched'] );
|
2100 |
+
\wfScanner::shared()->scheduleScans();
|
2101 |
+
$totalSet++;
|
2102 |
+
}
|
2103 |
+
|
2104 |
+
// Table-based Options.
|
2105 |
+
if ( isset( $import['blocks'] ) && is_array( $import['blocks'] ) ) {
|
2106 |
+
\wfBlock::importBlocks( $import['blocks'] );
|
2107 |
+
$totalSet += count( $import['blocks'] );
|
2108 |
+
}
|
2109 |
+
|
2110 |
+
return array(
|
2111 |
+
'ok' => 1,
|
2112 |
+
'totalSet' => $totalSet,
|
2113 |
+
'settings' => $this->get_settings(),
|
2114 |
+
);
|
2115 |
+
} elseif ( $res['err'] ) {
|
2116 |
+
return array( 'errorImport' => 'An error occurred: ' . $res['err'] );
|
2117 |
+
} else {
|
2118 |
+
throw new \Exception( 'Invalid response: ' );
|
2119 |
+
}
|
2120 |
+
} catch ( \Exception $e ) {
|
2121 |
+
return array( 'errorImport' => 'An error occurred: ' . $e->getMessage() );
|
2122 |
+
}
|
2123 |
+
}
|
2124 |
+
|
2125 |
+
/**
|
2126 |
+
* Method get_settings()
|
2127 |
+
*
|
2128 |
+
* Get the Wordfence settings.
|
2129 |
+
*
|
2130 |
+
* @used-by MainWP_Child_Wordfence::actions() Fire off certain Wordfence plugin actions.
|
2131 |
+
*
|
2132 |
+
* @return array Action result.
|
2133 |
+
*/
|
2134 |
+
public function get_settings() {
|
2135 |
+
$keys = \wfConfig::getExportableOptionsKeys();
|
2136 |
+
$settings = array();
|
2137 |
+
foreach ( $keys as $key ) {
|
2138 |
+
$settings[ $key ] = \wfConfig::get( $key, '' );
|
2139 |
+
}
|
2140 |
+
$settings['apiKey'] = \wfConfig::get( 'apiKey' );
|
2141 |
+
$settings['isPaid'] = \wfConfig::get( 'isPaid' );
|
2142 |
+
return $settings;
|
2143 |
+
}
|
2144 |
+
|
2145 |
+
/**
|
2146 |
+
* Method ticker()
|
2147 |
+
*
|
2148 |
+
* Wordfence ticker.
|
2149 |
+
*
|
2150 |
+
* @used-by MainWP_Child_Wordfence::actions() Fire off certain Wordfence plugin actions.
|
2151 |
+
*
|
2152 |
+
* @return array Action result.
|
2153 |
+
*/
|
2154 |
+
public function ticker() {
|
2155 |
+
$wfdb = new \wfDB();
|
2156 |
+
|
2157 |
+
$serverTime = $wfdb->querySingle( 'select unix_timestamp()' );
|
2158 |
+
|
2159 |
+
$table_wfStatus = \wfDB::networkTable( 'wfStatus' );
|
2160 |
+
|
2161 |
+
$jsonData = array(
|
2162 |
+
'serverTime' => $serverTime,
|
2163 |
+
'serverMicrotime' => microtime( true ),
|
2164 |
+
'msg' => $wfdb->querySingle( "select msg from {$table_wfStatus} where level < 3 order by ctime desc limit 1" ),
|
2165 |
+
);
|
2166 |
+
|
2167 |
+
$events = array();
|
2168 |
+
$alsoGet = isset( $_POST['alsoGet'] ) ? sanitize_text_field( wp_unslash( $_POST['alsoGet'] ) ) : '';
|
2169 |
+
if ( preg_match( '/^logList_(404|hit|human|ruser|crawler|gCrawler|loginLogout)$/', $alsoGet, $m ) ) {
|
2170 |
+
$type = $m[1];
|
2171 |
+
$newestEventTime = isset( $_POST['otherParams'] ) ? wp_unslash( $_POST['otherParams'] ) : '';
|
2172 |
+
$listType = 'hits';
|
2173 |
+
if ( 'loginLogout' === $type ) {
|
2174 |
+
$listType = 'logins';
|
2175 |
+
}
|
2176 |
+
$events = \wordfence::getLog()->getHits( $listType, $type, $newestEventTime );
|
2177 |
+
} elseif ( 'perfStats' === $alsoGet ) {
|
2178 |
+
$newestEventTime = isset( $_POST['otherParams'] ) ? wp_unslash( $_POST['otherParams'] ) : '';
|
2179 |
+
$events = \wordfence::getLog()->getPerfStats( $newestEventTime );
|
2180 |
+
} elseif ( 'liveTraffic' == $alsoGet ) {
|
2181 |
+
if ( get_site_option( 'wordfence_syncAttackDataAttempts' ) > 10 ) {
|
2182 |
+
\wordfence::syncAttackData( false );
|
2183 |
+
}
|
2184 |
+
$results = \wordfence::ajax_loadLiveTraffic_callback();
|
2185 |
+
$events = $results['data'];
|
2186 |
+
if ( isset( $results['sql'] ) ) {
|
2187 |
+
$jsonData['sql'] = $results['sql'];
|
2188 |
+
}
|
2189 |
+
}
|
2190 |
+
$jsonData['events'] = $events;
|
2191 |
+
$jsonData['alsoGet'] = $alsoGet; // send it back so we don't load data if panel has changed!
|
2192 |
+
$jsonData['cacheType'] = \wfConfig::get( 'cacheType' );
|
2193 |
+
return $jsonData;
|
2194 |
+
}
|
2195 |
+
|
2196 |
+
/**
|
2197 |
+
* Method load_live_traffic()
|
2198 |
+
*
|
2199 |
+
* Load the Wordfence live traffic.
|
2200 |
+
*
|
2201 |
+
* @used-by MainWP_Child_Wordfence::actions() Fire off certain Wordfence plugin actions.
|
2202 |
+
*
|
2203 |
+
* @return array Action result.
|
2204 |
+
*/
|
2205 |
+
public static function load_live_traffic() {
|
2206 |
+
$wfdb = new \wfDB();
|
2207 |
+
$serverTime = $wfdb->querySingle( 'select unix_timestamp()' );
|
2208 |
+
$return = \wordfence::ajax_loadLiveTraffic_callback();
|
2209 |
+
$return['serverTime'] = $serverTime;
|
2210 |
+
$return['serverMicrotime'] = microtime( true );
|
2211 |
+
return $return;
|
2212 |
+
}
|
2213 |
+
|
2214 |
+
/**
|
2215 |
+
* Method whitelist_waf_param_key()
|
2216 |
+
*
|
2217 |
+
* Whitelist WAF parameter key.
|
2218 |
+
*
|
2219 |
+
* @used-by MainWP_Child_Wordfence::actions() Fire off certain Wordfence plugin actions.
|
2220 |
+
*
|
2221 |
+
* @return array Action result.
|
2222 |
+
*/
|
2223 |
+
public function whitelist_waf_param_key() {
|
2224 |
+
$return = \wordfence::ajax_whitelistWAFParamKey_callback();
|
2225 |
+
return $return;
|
2226 |
+
}
|
2227 |
+
|
2228 |
+
/**
|
2229 |
+
* Method hide_file_htaccess()
|
2230 |
+
*
|
2231 |
+
* Hide the .htaccess file.
|
2232 |
+
*
|
2233 |
+
* @used-by MainWP_Child_Wordfence::actions() Fire off certain Wordfence plugin actions.
|
2234 |
+
*
|
2235 |
+
* @return array Action result.
|
2236 |
+
*/
|
2237 |
+
public function hide_file_htaccess() {
|
2238 |
+
$return = \wordfence::ajax_hideFileHtaccess_callback();
|
2239 |
+
return $return;
|
2240 |
+
}
|
2241 |
+
|
2242 |
+
/**
|
2243 |
+
* Method fix_fpd()
|
2244 |
+
*
|
2245 |
+
* Fix the FPD issue.
|
2246 |
+
*
|
2247 |
+
* @used-by MainWP_Child_Wordfence::actions() Fire off certain Wordfence plugin actions.
|
2248 |
+
*
|
2249 |
+
* @return array Action result.
|
2250 |
+
*/
|
2251 |
+
public static function fix_fpd() {
|
2252 |
+
$return = \wordfence::ajax_fixFPD_callback();
|
2253 |
+
return $return;
|
2254 |
+
}
|
2255 |
+
|
2256 |
+
/**
|
2257 |
+
* Method disable_directory_listing()
|
2258 |
+
*
|
2259 |
+
* Disable the directory listing security issue.
|
2260 |
+
*
|
2261 |
+
* @used-by MainWP_Child_Wordfence::actions() Fire off certain Wordfence plugin actions.
|
2262 |
+
*
|
2263 |
+
* @return array Action result.
|
2264 |
+
*/
|
2265 |
+
public static function disable_directory_listing() {
|
2266 |
+
$return = \wordfence::ajax_disableDirectoryListing_callback();
|
2267 |
+
return $return;
|
2268 |
+
}
|
2269 |
+
|
2270 |
+
/**
|
2271 |
+
* Method delete_database_option()
|
2272 |
+
*
|
2273 |
+
* Delete the database option.
|
2274 |
+
*
|
2275 |
+
* @used-by MainWP_Child_Wordfence::actions() Fire off certain Wordfence plugin actions.
|
2276 |
+
*
|
2277 |
+
* @return array Action result.
|
2278 |
+
*/
|
2279 |
+
public static function delete_database_option() {
|
2280 |
+
$return = \wordfence::ajax_deleteDatabaseOption_callback();
|
2281 |
+
return $return;
|
2282 |
+
}
|
2283 |
+
|
2284 |
+
/**
|
2285 |
+
* Method mis_configured_how_get_ips_choice()
|
2286 |
+
*
|
2287 |
+
* Misconfigured how to get IPs choice.
|
2288 |
+
*
|
2289 |
+
* @used-by MainWP_Child_Wordfence::actions() Fire off certain Wordfence plugin actions.
|
2290 |
+
*
|
2291 |
+
* @return array Action result.
|
2292 |
+
*/
|
2293 |
+
public static function mis_configured_how_get_ips_choice() {
|
2294 |
+
$return = \wordfence::ajax_misconfiguredHowGetIPsChoice_callback();
|
2295 |
+
return $return;
|
2296 |
+
}
|
2297 |
+
|
2298 |
+
/**
|
2299 |
+
* Method delete_admin_user()
|
2300 |
+
*
|
2301 |
+
* Delete the 'admin' user.
|
2302 |
+
*
|
2303 |
+
* @used-by MainWP_Child_Wordfence::actions() Fire off certain Wordfence plugin actions.
|
2304 |
+
*
|
2305 |
+
* @return array Action result.
|
2306 |
+
*/
|
2307 |
+
public static function delete_admin_user() {
|
2308 |
+
$return = \wordfence::ajax_deleteAdminUser_callback();
|
2309 |
+
return $return;
|
2310 |
+
}
|
2311 |
+
|
2312 |
+
/**
|
2313 |
+
* Method revoke_admin_user()
|
2314 |
+
*
|
2315 |
+
* Revoke the 'admin' user.
|
2316 |
+
*
|
2317 |
+
* @used-by MainWP_Child_Wordfence::actions() Fire off certain Wordfence plugin actions.
|
2318 |
+
*
|
2319 |
+
* @return array Action result.
|
2320 |
+
*/
|
2321 |
+
public static function revoke_admin_user() {
|
2322 |
+
$return = \wordfence::ajax_revokeAdminUser_callback();
|
2323 |
+
return $return;
|
2324 |
+
}
|
2325 |
+
|
2326 |
+
/**
|
2327 |
+
* Method clear_all_blocked()
|
2328 |
+
*
|
2329 |
+
* Clear all blocked IPs.
|
2330 |
+
*
|
2331 |
+
* @used-by MainWP_Child_Wordfence::actions() Fire off certain Wordfence plugin actions.
|
2332 |
+
*
|
2333 |
+
* @return array Action result.
|
2334 |
+
*/
|
2335 |
+
public static function clear_all_blocked() {
|
2336 |
+
$return = \wordfence::ajax_clearAllBlocked_callback();
|
2337 |
+
return $return;
|
2338 |
+
}
|
2339 |
+
|
2340 |
+
/**
|
2341 |
+
* Method permanently_block_all_ips()
|
2342 |
+
*
|
2343 |
+
* Permanently block all IPs.
|
2344 |
+
*
|
2345 |
+
* @used-by MainWP_Child_Wordfence::actions() Fire off certain Wordfence plugin actions.
|
2346 |
+
*
|
2347 |
+
* @return array Action result.
|
2348 |
+
*/
|
2349 |
+
public static function permanently_block_all_ips() {
|
2350 |
+
$return = \wordfence::ajax_permanentlyBlockAllIPs_callback();
|
2351 |
+
return $return;
|
2352 |
+
}
|
2353 |
+
|
2354 |
+
/**
|
2355 |
+
* Method unlock_out_ip()
|
2356 |
+
*
|
2357 |
+
* Unlock out IP.
|
2358 |
+
*
|
2359 |
+
* @used-by MainWP_Child_Wordfence::actions() Fire off certain Wordfence plugin actions.
|
2360 |
+
*
|
2361 |
+
* @return array Action result.
|
2362 |
+
*/
|
2363 |
+
public static function unlock_out_ip() {
|
2364 |
+
$return = \wordfence::ajax_unlockOutIP_callback();
|
2365 |
+
return $return;
|
2366 |
+
}
|
2367 |
+
|
2368 |
+
/**
|
2369 |
+
* Method unblock_range()
|
2370 |
+
*
|
2371 |
+
* Unblock IP range.
|
2372 |
+
*
|
2373 |
+
* @used-by MainWP_Child_Wordfence::actions() Fire off certain Wordfence plugin actions.
|
2374 |
+
*
|
2375 |
+
* @return array Action result.
|
2376 |
+
*/
|
2377 |
+
public static function unblock_range() {
|
2378 |
+
$return = \wordfence::ajax_unblockRange_callback();
|
2379 |
+
return $return;
|
2380 |
+
}
|
2381 |
+
|
2382 |
+
/**
|
2383 |
+
* Method block_ip_ua_range()
|
2384 |
+
*
|
2385 |
+
* Blcock IP UA range.
|
2386 |
+
*
|
2387 |
+
* @used-by MainWP_Child_Wordfence::actions() Fire off certain Wordfence plugin actions.
|
2388 |
+
*
|
2389 |
+
* @return array Action result.
|
2390 |
+
*/
|
2391 |
+
public static function block_ip_ua_range() {
|
2392 |
+
$return = \wordfence::ajax_blockIPUARange_callback();
|
2393 |
+
return $return;
|
2394 |
+
}
|
2395 |
+
|
2396 |
+
/**
|
2397 |
+
* Method load_block_ranges()
|
2398 |
+
*
|
2399 |
+
* Load blocked IP ranges.
|
2400 |
+
*
|
2401 |
+
* @used-by MainWP_Child_Wordfence::actions() Fire off certain Wordfence plugin actions.
|
2402 |
+
*
|
2403 |
+
* @return array Action result.
|
2404 |
+
*/
|
2405 |
+
public static function load_block_ranges() {
|
2406 |
+
$return = \wordfence::ajax_loadBlockRanges_callback();
|
2407 |
+
return $return;
|
2408 |
+
}
|
2409 |
+
|
2410 |
+
/**
|
2411 |
+
* Method save_waf_config()
|
2412 |
+
*
|
2413 |
+
* Save WAF settigns.
|
2414 |
+
*
|
2415 |
+
* @used-by MainWP_Child_Wordfence::actions() Fire off certain Wordfence plugin actions.
|
2416 |
+
*
|
2417 |
+
* @return array Action result.
|
2418 |
+
*/
|
2419 |
+
public static function save_waf_config() {
|
2420 |
+
$return = \wordfence::ajax_saveWAFConfig_callback();
|
2421 |
+
if ( is_array( $return ) && isset( $return['data'] ) ) {
|
2422 |
+
$return['learningModeGracePeriod'] = \wfWAF::getInstance()->getStorageEngine()->getConfig( 'learningModeGracePeriod' );
|
2423 |
+
}
|
2424 |
+
return $return;
|
2425 |
+
}
|
2426 |
+
|
2427 |
+
/**
|
2428 |
+
* Method whitelist_bulk_delete()
|
2429 |
+
*
|
2430 |
+
* Delete in bulk whitelist items.
|
2431 |
+
*
|
2432 |
+
* @used-by MainWP_Child_Wordfence::actions() Fire off certain Wordfence plugin actions.
|
2433 |
+
*
|
2434 |
+
* @return array Action result.
|
2435 |
+
*/
|
2436 |
+
public static function whitelist_bulk_delete() {
|
2437 |
+
$return = \wordfence::ajax_whitelistBulkDelete_callback();
|
2438 |
+
return $return;
|
2439 |
+
}
|
2440 |
+
|
2441 |
+
/**
|
2442 |
+
* Method whitelist_bulk_enable()
|
2443 |
+
*
|
2444 |
+
* Enable in bulk whitelist items.
|
2445 |
+
*
|
2446 |
+
* @used-by MainWP_Child_Wordfence::actions() Fire off certain Wordfence plugin actions.
|
2447 |
+
*
|
2448 |
+
* @return array Action result.
|
2449 |
+
*/
|
2450 |
+
public static function whitelist_bulk_enable() {
|
2451 |
+
$return = \wordfence::ajax_whitelistBulkEnable_callback();
|
2452 |
+
return $return;
|
2453 |
+
}
|
2454 |
+
|
2455 |
+
/**
|
2456 |
+
* Method whitelist_bulk_disable()
|
2457 |
+
*
|
2458 |
+
* Disable in bulk whitelist items.
|
2459 |
+
*
|
2460 |
+
* @used-by MainWP_Child_Wordfence::actions() Fire off certain Wordfence plugin actions.
|
2461 |
+
*
|
2462 |
+
* @return array Action result.
|
2463 |
+
*/
|
2464 |
+
public static function whitelist_bulk_disable() {
|
2465 |
+
$return = \wordfence::ajax_whitelistBulkDisable_callback();
|
2466 |
+
return $return;
|
2467 |
+
}
|
2468 |
+
|
2469 |
+
/**
|
2470 |
+
* Method update_config()
|
2471 |
+
*
|
2472 |
+
* Update Wordfence configuration.
|
2473 |
+
*
|
2474 |
+
* @used-by MainWP_Child_Wordfence::actions() Fire off certain Wordfence plugin actions.
|
2475 |
+
*
|
2476 |
+
* @return array Action result.
|
2477 |
+
*/
|
2478 |
+
public static function update_config() {
|
2479 |
+
$return = \wordfence::ajax_updateConfig_callback();
|
2480 |
+
return $return;
|
2481 |
+
}
|
2482 |
+
|
2483 |
+
/**
|
2484 |
+
* Method get_waf_data()
|
2485 |
+
*
|
2486 |
+
* Get the WAF data.
|
2487 |
+
*
|
2488 |
+
* @param bool $updated If updated, set true, if not, set false.
|
2489 |
+
*
|
2490 |
+
* @used-by MainWP_Child_Wordfence::load_waf_data() Load the WAF data.
|
2491 |
+
*
|
2492 |
+
* @return array Action result.
|
2493 |
+
*/
|
2494 |
+
private static function get_waf_data( $updated = null ) {
|
2495 |
+
if ( ! class_exists( '\wfWAF' ) ) {
|
2496 |
+
return false;
|
2497 |
+
}
|
2498 |
+
|
2499 |
+
$data['learningMode'] = \wfWAF::getInstance()->isInLearningMode();
|
2500 |
+
$data['rules'] = \wfWAF::getInstance()->getRules();
|
2501 |
+
/** @var wfWAFRule $rule */
|
2502 |
+
foreach ( $data['rules'] as $ruleID => $rule ) {
|
2503 |
+
$data['rules'][ $ruleID ] = $rule->toArray();
|
2504 |
+
}
|
2505 |
+
|
2506 |
+
$whitelistedURLParams = \wfWAF::getInstance()->getStorageEngine()->getConfig( 'whitelistedURLParams', array() );
|
2507 |
+
$data['whitelistedURLParams'] = array();
|
2508 |
+
foreach ( $whitelistedURLParams as $urlParamKey => $rules ) {
|
2509 |
+
list( $path, $paramKey ) = explode( '|', $urlParamKey );
|
2510 |
+
$whitelistData = null;
|
2511 |
+
foreach ( $rules as $ruleID => $whitelistedData ) {
|
2512 |
+
if ( null === $whitelistData ) {
|
2513 |
+
$whitelistData = $whitelistedData;
|
2514 |
+
continue;
|
2515 |
+
}
|
2516 |
+
if ( 'all' === $ruleID ) {
|
2517 |
+
$whitelistData = $whitelistedData;
|
2518 |
+
break;
|
2519 |
+
}
|
2520 |
+
}
|
2521 |
+
|
2522 |
+
if ( is_array( $whitelistData ) && array_key_exists( 'userID', $whitelistData ) && function_exists( 'get_user_by' ) ) {
|
2523 |
+
$user = get_user_by( 'id', $whitelistData['userID'] );
|
2524 |
+
if ( $user ) {
|
2525 |
+
$whitelistData['username'] = $user->user_login;
|
2526 |
+
}
|
2527 |
+
}
|
2528 |
+
|
2529 |
+
$data['whitelistedURLParams'][] = array(
|
2530 |
+
'path' => $path,
|
2531 |
+
'paramKey' => $paramKey,
|
2532 |
+
'ruleID' => array_keys( $rules ),
|
2533 |
+
'data' => $whitelistData,
|
2534 |
+
);
|
2535 |
+
}
|
2536 |
+
|
2537 |
+
$data['disabledRules'] = (array) \wfWAF::getInstance()->getStorageEngine()->getConfig( 'disabledRules' );
|
2538 |
+
$lastUpdated = \wfWAF::getInstance()->getStorageEngine()->getConfig( 'rulesLastUpdated' );
|
2539 |
+
if ( $lastUpdated ) {
|
2540 |
+
$data['rulesLastUpdated'] = $lastUpdated;
|
2541 |
+
}
|
2542 |
+
$data['isPaid'] = (bool) \wfConfig::get( 'isPaid', 0 );
|
2543 |
+
|
2544 |
+
if ( null !== $updated ) {
|
2545 |
+
$data['updated'] = (bool) $updated;
|
2546 |
+
}
|
2547 |
+
return $data;
|
2548 |
+
}
|
2549 |
+
|
2550 |
+
/**
|
2551 |
+
* Method reverse_lookup()
|
2552 |
+
*
|
2553 |
+
* Reverse lookup.
|
2554 |
+
*
|
2555 |
+
* @used-by MainWP_Child_Wordfence::actions() Fire off certain Wordfence plugin actions.
|
2556 |
+
*
|
2557 |
+
* @return array Action result.
|
2558 |
+
*/
|
2559 |
+
public function reverse_lookup() {
|
2560 |
+
$ips = explode( ',', $_POST['ips'] );
|
2561 |
+
$res = array();
|
2562 |
+
foreach ( $ips as $ip ) {
|
2563 |
+
$res[ $ip ] = \wfUtils::reverseLookup( $ip );
|
2564 |
+
}
|
2565 |
+
|
2566 |
+
return array(
|
2567 |
+
'ok' => 1,
|
2568 |
+
'ips' => $res,
|
2569 |
+
);
|
2570 |
+
}
|
2571 |
+
|
2572 |
+
/**
|
2573 |
+
* Method save_options()
|
2574 |
+
*
|
2575 |
+
* Save Wordfence options.
|
2576 |
+
*
|
2577 |
+
* @used-by MainWP_Child_Wordfence::actions() Fire off certain Wordfence plugin actions.
|
2578 |
+
*
|
2579 |
+
* @return array Action result.
|
2580 |
+
*/
|
2581 |
+
public function save_options() {
|
2582 |
+
$changes = json_decode( stripslashes( $_POST['changes'] ), true );
|
2583 |
+
if ( ! empty( $_POST['changes'] ) && false !== $changes ) {
|
2584 |
+
try {
|
2585 |
+
if ( is_array( $changes ) && isset( $changes['whitelistedURLParams'] ) && isset( $changes['whitelistedURLParams']['add'] ) ) {
|
2586 |
+
$user = wp_get_current_user();
|
2587 |
+
foreach ( $changes['whitelistedURLParams']['add'] as $key => &$value ) :
|
2588 |
+
if ( isset( $value['data'] ) ) {
|
2589 |
+
|
2590 |
+
if ( isset( $value['data']['userID'] ) ) {
|
2591 |
+
$value['data']['userID'] = $user->ID;
|
2592 |
+
}
|
2593 |
+
if ( isset( $value['data']['username'] ) ) {
|
2594 |
+
$value['data']['username'] = $user->user_login;
|
2595 |
+
}
|
2596 |
+
}
|
2597 |
+
endforeach;
|
2598 |
+
}
|
2599 |
+
|
2600 |
+
$errors = \wfConfig::validate( $changes );
|
2601 |
+
|
2602 |
+
if ( true !== $errors ) {
|
2603 |
+
if ( count( $errors ) == 1 ) {
|
2604 |
+
return array(
|
2605 |
+
'error' => sprintf( __( 'An error occurred while saving the configuration: %s', 'wordfence' ), $errors[0]['error'] ),
|
2606 |
+
);
|
2607 |
+
} elseif ( count( $errors ) > 1 ) {
|
2608 |
+
$compoundMessage = array();
|
2609 |
+
foreach ( $errors as $e ) {
|
2610 |
+
$compoundMessage[] = $e['error'];
|
2611 |
+
}
|
2612 |
+
return array(
|
2613 |
+
'error' => sprintf( __( 'Errors occurred while saving the configuration: %s', 'wordfence' ), implode( ', ', $compoundMessage ) ),
|
2614 |
+
);
|
2615 |
+
}
|
2616 |
+
|
2617 |
+
return array(
|
2618 |
+
'error' => __( 'Errors occurred while saving the configuration.', 'wordfence' ),
|
2619 |
+
);
|
2620 |
+
}
|
2621 |
+
|
2622 |
+
\wfConfig::save( $changes );
|
2623 |
+
return array( 'success' => true );
|
2624 |
+
} catch ( \wfWAFStorageFile\Exception $e ) {
|
2625 |
+
return array(
|
2626 |
+
'error' => __( 'An error occurred while saving the configuration.', 'wordfence' ),
|
2627 |
+
);
|
2628 |
+
} catch ( \Exception $e ) {
|
2629 |
+
return array(
|
2630 |
+
'error' => $e->getMessage(),
|
2631 |
+
);
|
2632 |
+
}
|
2633 |
+
}
|
2634 |
+
|
2635 |
+
return array(
|
2636 |
+
'error' => __( 'No configuration changes were provided to save.', 'wordfence' ),
|
2637 |
+
);
|
2638 |
+
}
|
2639 |
+
|
2640 |
+
/**
|
2641 |
+
* Method ajax_get_blocks_callback()
|
2642 |
+
*
|
2643 |
+
* Get the list of blocked items.
|
2644 |
+
*
|
2645 |
+
* @used-by MainWP_Child_Wordfence::actions() Fire off certain Wordfence plugin actions.
|
2646 |
+
*
|
2647 |
+
* @return array Action result.
|
2648 |
+
*/
|
2649 |
+
public function ajax_get_blocks_callback() {
|
2650 |
+
$information = \wordfence::ajax_getBlocks_callback();
|
2651 |
+
return $information;
|
2652 |
+
}
|
2653 |
+
|
2654 |
+
/**
|
2655 |
+
* Method ajax_create_block_callback()
|
2656 |
+
*
|
2657 |
+
* Create the block rule.
|
2658 |
+
*
|
2659 |
+
* @used-by MainWP_Child_Wordfence::actions() Fire off certain Wordfence plugin actions.
|
2660 |
+
*
|
2661 |
+
* @return array Action result.
|
2662 |
+
*/
|
2663 |
+
public function ajax_create_block_callback() {
|
2664 |
+
return \wordfence::ajax_createBlock_callback();
|
2665 |
+
}
|
2666 |
+
|
2667 |
+
/**
|
2668 |
+
* Method ajax_delete_blocks_callback()
|
2669 |
+
*
|
2670 |
+
* Delete blocked item.
|
2671 |
+
*
|
2672 |
+
* @used-by MainWP_Child_Wordfence::actions() Fire off certain Wordfence plugin actions.
|
2673 |
+
*
|
2674 |
+
* @return array Action result.
|
2675 |
+
*/
|
2676 |
+
public static function ajax_delete_blocks_callback() {
|
2677 |
+
$information = \wordfence::ajax_deleteBlocks_callback();
|
2678 |
+
return $information;
|
2679 |
+
}
|
2680 |
+
|
2681 |
+
/**
|
2682 |
+
* Method ajax_make_permanent_blocks_callback()
|
2683 |
+
*
|
2684 |
+
* Make permanent blocks.
|
2685 |
+
*
|
2686 |
+
* @used-by MainWP_Child_Wordfence::actions() Fire off certain Wordfence plugin actions.
|
2687 |
+
*
|
2688 |
+
* @return array Action result.
|
2689 |
+
*/
|
2690 |
+
public static function ajax_make_permanent_blocks_callback() {
|
2691 |
+
$information = \wordfence::ajax_makePermanentBlocks_callback();
|
2692 |
+
return $information;
|
2693 |
+
}
|
2694 |
+
|
2695 |
+
/**
|
2696 |
+
* Method ajax_block_ip_callback()
|
2697 |
+
*
|
2698 |
+
* Block IP address.
|
2699 |
+
*
|
2700 |
+
* @used-by MainWP_Child_Wordfence::actions() Fire off certain Wordfence plugin actions.
|
2701 |
+
*
|
2702 |
+
* @return array Action result.
|
2703 |
+
*/
|
2704 |
+
public function ajax_block_ip_callback() {
|
2705 |
+
return \wordfence::ajax_blockIP_callback();
|
2706 |
+
}
|
2707 |
+
|
2708 |
+
/**
|
2709 |
+
* Method whois()
|
2710 |
+
*
|
2711 |
+
* Trigger the WhoIS check.
|
2712 |
+
*
|
2713 |
+
* @used-by MainWP_Child_Wordfence::actions() Fire off certain Wordfence plugin actions.
|
2714 |
+
*
|
2715 |
+
* @return array Action result.
|
2716 |
+
*/
|
2717 |
+
public function whois() {
|
2718 |
+
return \wordfence::ajax_whois_callback();
|
2719 |
+
}
|
2720 |
+
|
2721 |
+
/**
|
2722 |
+
* Method unblock_ip()
|
2723 |
+
*
|
2724 |
+
* Unblock IP address.
|
2725 |
+
*
|
2726 |
+
* @used-by MainWP_Child_Wordfence::actions() Fire off certain Wordfence plugin actions.
|
2727 |
+
*
|
2728 |
+
* @return array Action result.
|
2729 |
+
*/
|
2730 |
+
public function unblock_ip() {
|
2731 |
+
$IP = isset( $_POST['IP'] ) ? sanitize_text_field( wp_unslash( $_POST['IP'] ) ) : '';
|
2732 |
+
if ( ! empty( $IP ) ) {
|
2733 |
+
\wfBlock::unblockIP( $IP );
|
2734 |
+
return array( 'success' => 1 );
|
2735 |
+
}
|
2736 |
+
}
|
2737 |
+
|
2738 |
+
/**
|
2739 |
+
* Method save_country_blocking()
|
2740 |
+
*
|
2741 |
+
* Save country blocknig settings.
|
2742 |
+
*
|
2743 |
+
* @used-by MainWP_Child_Wordfence::actions() Fire off certain Wordfence plugin actions.
|
2744 |
+
*
|
2745 |
+
* @return array Action result.
|
2746 |
+
*/
|
2747 |
+
public static function save_country_blocking() {
|
2748 |
+
if ( ! \wfConfig::get( 'isPaid' ) ) {
|
2749 |
+
return array( 'error' => 'Sorry but this feature is only available for paid customers.' );
|
2750 |
+
}
|
2751 |
+
$settings = isset( $_POST['settings'] ) ? wp_unslash( $_POST['settings'] ) : array();
|
2752 |
+
\wfConfig::set( 'cbl_action', $settings['blockAction'] );
|
2753 |
+
\wfConfig::set( 'cbl_countries', $settings['codes'] );
|
2754 |
+
\wfConfig::set( 'cbl_redirURL', $settings['redirURL'] );
|
2755 |
+
\wfConfig::set( 'cbl_loggedInBlocked', $settings['loggedInBlocked'] );
|
2756 |
+
\wfConfig::set( 'cbl_loginFormBlocked', $settings['loginFormBlocked'] );
|
2757 |
+
\wfConfig::set( 'cbl_restOfSiteBlocked', $settings['restOfSiteBlocked'] );
|
2758 |
+
\wfConfig::set( 'cbl_bypassRedirURL', $settings['bypassRedirURL'] );
|
2759 |
+
\wfConfig::set( 'cbl_bypassRedirDest', $settings['bypassRedirDest'] );
|
2760 |
+
\wfConfig::set( 'cbl_bypassViewURL', $settings['bypassViewURL'] );
|
2761 |
+
return array( 'ok' => 1 );
|
2762 |
+
}
|
2763 |
+
|
2764 |
+
/**
|
2765 |
+
* Method load_static_panel()
|
2766 |
+
*
|
2767 |
+
* Load static panel.
|
2768 |
+
*
|
2769 |
+
* @used-by MainWP_Child_Wordfence::actions() Fire off certain Wordfence plugin actions.
|
2770 |
+
*
|
2771 |
+
* @return array Action result.
|
2772 |
+
*/
|
2773 |
+
public function load_static_panel() {
|
2774 |
+
$mode = isset( $_POST['mode'] ) ? sanitize_text_field( wp_unslash( $_POST['mode'] ) ) : '';
|
2775 |
+
$wfLog = \wordfence::getLog();
|
2776 |
+
if ( 'topScanners' === $mode || 'topLeechers' === $mode ) {
|
2777 |
+
$results = $wfLog->getLeechers( $mode );
|
2778 |
+
} elseif ( 'blockedIPs' === $mode ) {
|
2779 |
+
$results = $wfLog->getBlockedIPs();
|
2780 |
+
} elseif ( 'lockedOutIPs' === $mode ) {
|
2781 |
+
$results = $wfLog->getLockedOutIPs();
|
2782 |
+
} elseif ( 'throttledIPs' === $mode ) {
|
2783 |
+
$results = $wfLog->getThrottledIPs();
|
2784 |
+
}
|
2785 |
+
|
2786 |
+
return array(
|
2787 |
+
'ok' => 1,
|
2788 |
+
'results' => $results,
|
2789 |
+
);
|
2790 |
+
}
|
2791 |
+
|
2792 |
+
/**
|
2793 |
+
* Method downgrade_license()
|
2794 |
+
*
|
2795 |
+
* Downgrade Wordfence license.
|
2796 |
+
*
|
2797 |
+
* @used-by MainWP_Child_Wordfence::actions() Fire off certain Wordfence plugin actions.
|
2798 |
+
*
|
2799 |
+
* @return array Action result.
|
2800 |
+
*/
|
2801 |
+
public function downgrade_license() {
|
2802 |
+
$api = new \wfAPI( '', \wfUtils::getWPVersion() );
|
2803 |
+
$return = array();
|
2804 |
+
try {
|
2805 |
+
$keyData = $api->call( 'get_anon_api_key' );
|
2806 |
+
if ( $keyData['ok'] && $keyData['apiKey'] ) {
|
2807 |
+
\wfConfig::set( 'apiKey', $keyData['apiKey'] );
|
2808 |
+
\wfConfig::set( 'isPaid', 0 );
|
2809 |
+
$return['apiKey'] = $keyData['apiKey'];
|
2810 |
+
$return['isPaid'] = 0;
|
2811 |
+
// When downgrading we must disable all two factor authentication because it can lock an admin out if we don't.
|
2812 |
+
\wfConfig::set_ser( 'twoFactorUsers', array() );
|
2813 |
+
} else {
|
2814 |
+
throw new \Exception( 'Could not understand the response we received from the Wordfence servers when applying for a free API key.' );
|
2815 |
+
}
|
2816 |
+
} catch ( \Exception $e ) {
|
2817 |
+
$return['errorMsg'] = 'Could not fetch free API key from Wordfence: ' . htmlentities( $e->getMessage() );
|
2818 |
+
|
2819 |
+
return $return;
|
2820 |
+
}
|
2821 |
+
$return['ok'] = 1;
|
2822 |
+
|
2823 |
+
return $return;
|
2824 |
+
}
|
2825 |
+
|
2826 |
+
/**
|
2827 |
+
* Method save_cache_config()
|
2828 |
+
*
|
2829 |
+
* Save caching configuration.
|
2830 |
+
*
|
2831 |
+
* @used-by MainWP_Child_Wordfence::actions() Fire off certain Wordfence plugin actions.
|
2832 |
+
*
|
2833 |
+
* @return array Action result.
|
2834 |
+
*/
|
2835 |
+
public static function save_cache_config() {
|
2836 |
+
$noEditHtaccess = '1';
|
2837 |
+
if ( isset( $_POST['needToCheckFalconHtaccess'] ) && ! empty( $_POST['needToCheckFalconHtaccess'] ) ) {
|
2838 |
+
$checkHtaccess = self::check_falcon_htaccess();
|
2839 |
+
if ( isset( $checkHtaccess['ok'] ) ) {
|
2840 |
+
$noEditHtaccess = '0';
|
2841 |
+
}
|
2842 |
+
} elseif ( isset( $_POST['noEditHtaccess'] ) ) {
|
2843 |
+
$noEditHtaccess = isset( $_POST['noEditHtaccess'] ) ? sanitize_text_field( wp_unslash( $_POST['noEditHtaccess'] ) ) : '1';
|
2844 |
+
}
|
2845 |
+
|
2846 |
+
$cacheType = isset( $_POST['cacheType'] ) ? sanitize_text_field( wp_unslash( $_POST['cacheType'] ) ) : '';
|
2847 |
+
if ( 'falcon' == $cacheType || 'php' == $cacheType ) {
|
2848 |
+
$plugins = get_plugins();
|
2849 |
+
$badPlugins = array();
|
2850 |
+
foreach ( $plugins as $pluginFile => $data ) {
|
2851 |
+
if ( is_plugin_active( $pluginFile ) ) {
|
2852 |
+
if ( 'w3-total-cache/w3-total-cache.php' == $pluginFile ) {
|
2853 |
+
$badPlugins[] = 'W3 Total Cache';
|
2854 |
+
} elseif ( 'quick-cache/quick-cache.php' == $pluginFile ) {
|
2855 |
+
$badPlugins[] = 'Quick Cache';
|
2856 |
+
} elseif ( 'wp-super-cache/wp-cache.php' == $pluginFile ) {
|
2857 |
+
$badPlugins[] = 'WP Super Cache';
|
2858 |
+
} elseif ( 'wp-fast-cache/wp-fast-cache.php' == $pluginFile ) {
|
2859 |
+
$badPlugins[] = 'WP Fast Cache';
|
2860 |
+
} elseif ( 'wp-fastest-cache/wpFastestCache.php' == $pluginFile ) {
|
2861 |
+
$badPlugins[] = 'WP Fastest Cache';
|
2862 |
+
}
|
2863 |
+
}
|
2864 |
+
}
|
2865 |
+
if ( count( $badPlugins ) > 0 ) {
|
2866 |
+
return array( 'errorMsg' => 'You can not enable caching in Wordfence with other caching plugins enabled. This may cause conflicts. You need to disable other caching plugins first. Wordfence caching is very fast and does not require other caching plugins to be active. The plugins you have that conflict are: ' . implode( ', ', $badPlugins ) . '. Disable these plugins, then return to this page and enable Wordfence caching.' );
|
2867 |
+
}
|
2868 |
+
$siteURL = site_url();
|
2869 |
+
if ( preg_match( '/^https?:\/\/[^\/]+\/[^\/]+\/[^\/]+\/.+/i', $siteURL ) ) {
|
2870 |
+
return array( 'errorMsg' => "Wordfence caching currently does not support sites that are installed in a subdirectory and have a home page that is more than 2 directory levels deep. e.g. we don't support sites who's home page is http://example.com/levelOne/levelTwo/levelThree" );
|
2871 |
+
}
|
2872 |
+
}
|
2873 |
+
if ( 'falcon' == $cacheType ) {
|
2874 |
+
if ( ! get_option( 'permalink_structure', '' ) ) {
|
2875 |
+
return array( 'errorMsg' => 'You need to enable Permalinks for your site to use Falcon Engine. You can enable Permalinks in WordPress by going to the Settings - Permalinks menu and enabling it there. Permalinks change your site URL structure from something that looks like /p=123 to pretty URLs like /my-new-post-today/ that are generally more search engine friendly.' );
|
2876 |
+
}
|
2877 |
+
}
|
2878 |
+
$warnHtaccess = false;
|
2879 |
+
if ( 'disable' == $cacheType || 'php' == $cacheType ) {
|
2880 |
+
$removeError = \wfCache::addHtaccessCode( 'remove' );
|
2881 |
+
$removeError2 = \wfCache::updateBlockedIPs( 'remove' );
|
2882 |
+
if ( $removeError || $removeError2 ) {
|
2883 |
+
$warnHtaccess = true;
|
2884 |
+
}
|
2885 |
+
}
|
2886 |
+
if ( 'php' == $cacheType || 'falcon' == $cacheType ) {
|
2887 |
+
$err = \wfCache::cacheDirectoryTest();
|
2888 |
+
if ( $err ) {
|
2889 |
+
return array(
|
2890 |
+
'ok' => 1,
|
2891 |
+
'heading' => 'Could not write to cache directory',
|
2892 |
+
'body' => "To enable caching, Wordfence needs to be able to create and write to the /wp-content/wfcache/ directory. We did some tests that indicate this is not possible. You need to manually create the /wp-content/wfcache/ directory and make it writable by Wordfence. The error we encountered was during our tests was: $err",
|
2893 |
+
);
|
2894 |
+
}
|
2895 |
+
}
|
2896 |
+
|
2897 |
+
// Mainly we clear the cache here so that any footer cache diagnostic comments are rebuilt. We could just leave it intact unless caching is being disabled.
|
2898 |
+
if ( \wfConfig::get( 'cacheType', false ) != $cacheType ) {
|
2899 |
+
\wfCache::scheduleCacheClear();
|
2900 |
+
}
|
2901 |
+
$htMsg = '';
|
2902 |
+
if ( $warnHtaccess ) {
|
2903 |
+
$htMsg = " <strong style='color: #F00;'>Warning: We could not remove the caching code from your .htaccess file. you need to remove this manually yourself.</strong> ";
|
2904 |
+
}
|
2905 |
+
if ( 'disable' == $cacheType ) {
|
2906 |
+
\wfConfig::set( 'cacheType', false );
|
2907 |
+
return array(
|
2908 |
+
'ok' => 1,
|
2909 |
+
'heading' => 'Caching successfully disabled.',
|
2910 |
+
'body' => "{$htMsg}Caching has been disabled on your system.<br /><br /><center><input type='button' name='wfReload' value='Click here now to refresh this page' onclick='window.location.reload(true);' /></center>",
|
2911 |
+
);
|
2912 |
+
} elseif ( 'php' == $cacheType ) {
|
2913 |
+
\wfConfig::set( 'cacheType', 'php' );
|
2914 |
+
return array(
|
2915 |
+
'ok' => 1,
|
2916 |
+
'heading' => 'Wordfence Basic Caching Enabled',
|
2917 |
+
'body' => "{$htMsg}Wordfence basic caching has been enabled on your system.<br /><br /><center><input type='button' name='wfReload' value='Click here now to refresh this page' onclick='window.location.reload(true);' /></center>",
|
2918 |
+
);
|
2919 |
+
} elseif ( 'falcon' == $cacheType ) {
|
2920 |
+
if ( '1' != $noEditHtaccess ) {
|
2921 |
+
$err = \wfCache::addHtaccessCode( 'add' );
|
2922 |
+
if ( $err ) {
|
2923 |
+
return array(
|
2924 |
+
'ok' => 1,
|
2925 |
+
'heading' => 'Wordfence could not edit .htaccess',
|
2926 |
+
'body' => 'Wordfence could not edit your .htaccess code. The error was: ' . $err,
|
2927 |
+
);
|
2928 |
+
}
|
2929 |
+
}
|
2930 |
+
\wfConfig::set( 'cacheType', 'falcon' );
|
2931 |
+
\wfCache::scheduleUpdateBlockedIPs(); // Runs every 5 mins until we change cachetype.
|
2932 |
+
return array(
|
2933 |
+
'ok' => 1,
|
2934 |
+
'heading' => 'Wordfence Falcon Engine Activated!',
|
2935 |
+
'body' => "Wordfence Falcon Engine has been activated on your system. You will see this icon appear on the Wordfence admin pages as long as Falcon is active indicating your site is running in high performance mode:<div class='wfFalconImage'></div><center><input type='button' name='wfReload' value='Click here now to refresh this page' onclick='window.location.reload(true);' /></center>",
|
2936 |
+
);
|
2937 |
+
}
|
2938 |
+
return array( 'errorMsg' => 'An error occurred.' );
|
2939 |
+
}
|
2940 |
+
|
2941 |
+
/**
|
2942 |
+
* Method check_falcon_htaccess()
|
2943 |
+
*
|
2944 |
+
* Check the .htaccess for the Wordfence falcon settings.
|
2945 |
+
*
|
2946 |
+
* @return array Action result.
|
2947 |
+
*
|
2948 |
+
* @used-by MainWP_Child_Wordfence::actions() Fire off certain Wordfence plugin actions.
|
2949 |
+
* @uses \MainWP\Child\MainWP_Utility::create_nonce_without_session()
|
2950 |
+
*/
|
2951 |
+
public static function check_falcon_htaccess() {
|
2952 |
+
if ( \wfUtils::isNginx() ) {
|
2953 |
+
return array( 'nginx' => 1 );
|
2954 |
+
}
|
2955 |
+
$file = \wfCache::getHtaccessPath();
|
2956 |
+
if ( ! $file ) {
|
2957 |
+
return array(
|
2958 |
+
'err' => 'We could not find your .htaccess file to modify it.',
|
2959 |
+
'code' => \wfCache::getHtaccessCode(),
|
2960 |
+
);
|
2961 |
+
}
|
2962 |
+
$fh = fopen( $file, 'r+' );
|
2963 |
+
if ( ! $fh ) {
|
2964 |
+
$err = error_get_last();
|
2965 |
+
return array(
|
2966 |
+
'err' => 'We found your .htaccess file but could not open it for writing: ' . $err['message'],
|
2967 |
+
'code' => \wfCache::getHtaccessCode(),
|
2968 |
+
);
|
2969 |
+
}
|
2970 |
+
$download_url = admin_url( 'admin-ajax.php' ) . '?action=mainwp_wordfence_download_htaccess&_wpnonce=' . MainWP_Utility::create_nonce_without_session( 'mainwp_download_htaccess' );
|
2971 |
+
return array(
|
2972 |
+
'ok' => 1,
|
2973 |
+
'download_url' => $download_url,
|
2974 |
+
);
|
2975 |
+
}
|
2976 |
+
|
2977 |
+
/**
|
2978 |
+
* Method check_htaccess()
|
2979 |
+
*
|
2980 |
+
* Check the .htaccess file.
|
2981 |
+
*
|
2982 |
+
* @used-by MainWP_Child_Wordfence::actions() Fire off certain Wordfence plugin actions.
|
2983 |
+
*
|
2984 |
+
* @return array Action result.
|
2985 |
+
*/
|
2986 |
+
public static function check_htaccess() {
|
2987 |
+
if ( \wfUtils::isNginx() ) {
|
2988 |
+
return array( 'nginx' => 1 );
|
2989 |
+
}
|
2990 |
+
$file = \wfCache::getHtaccessPath();
|
2991 |
+
if ( ! $file ) {
|
2992 |
+
return array( 'err' => 'We could not find your .htaccess file to modify it.' );
|
2993 |
+
}
|
2994 |
+
$fh = fopen( $file, 'r+' );
|
2995 |
+
if ( ! $fh ) {
|
2996 |
+
$err = error_get_last();
|
2997 |
+
return array( 'err' => 'We found your .htaccess file but could not open it for writing: ' . $err['message'] );
|
2998 |
+
}
|
2999 |
+
return array( 'ok' => 1 );
|
3000 |
+
}
|
3001 |
+
|
3002 |
+
/**
|
3003 |
+
* Method download_htaccess()
|
3004 |
+
*
|
3005 |
+
* Download the .htaccess file.
|
3006 |
+
*
|
3007 |
+
* @return void Action result.
|
3008 |
+
*
|
3009 |
+
* @used-by \MainWP\Child\MainWP_Child_Wordfence::actions() Fire off certain Wordfence plugin actions.
|
3010 |
+
* @uses \MainWP\Child\MainWP_Utility::verify_nonce_without_session()
|
3011 |
+
*/
|
3012 |
+
public static function download_htaccess() {
|
3013 |
+
if ( ! isset( $_GET['_wpnonce'] ) || empty( $_GET['_wpnonce'] ) ) {
|
3014 |
+
die( '-1' );
|
3015 |
+
}
|
3016 |
+
|
3017 |
+
if ( ! MainWP_Utility::verify_nonce_without_session( $_GET['_wpnonce'], 'mainwp_download_htaccess' ) ) {
|
3018 |
+
die( '-2' );
|
3019 |
+
}
|
3020 |
+
|
3021 |
+
$url = site_url();
|
3022 |
+
$url = preg_replace( '/^https?:\/\//i', '', $url );
|
3023 |
+
$url = preg_replace( '/[^a-zA-Z0-9\.]+/', '_', $url );
|
3024 |
+
$url = preg_replace( '/^_+/', '', $url );
|
3025 |
+
$url = preg_replace( '/_+$/', '', $url );
|
3026 |
+
header( 'Content-Type: application/octet-stream' );
|
3027 |
+
header( 'Content-Disposition: attachment; filename="htaccess_Backup_for_' . $url . '.txt"' );
|
3028 |
+
$file = \wfCache::getHtaccessPath();
|
3029 |
+
readfile( $file );
|
3030 |
+
die();
|
3031 |
+
}
|
3032 |
+
|
3033 |
+
/**
|
3034 |
+
* Method save_cache_options()
|
3035 |
+
*
|
3036 |
+
* Save the caching options.
|
3037 |
+
*
|
3038 |
+
* @used-by MainWP_Child_Wordfence::actions() Fire off certain Wordfence plugin actions.
|
3039 |
+
*
|
3040 |
+
* @return array Action result.
|
3041 |
+
*/
|
3042 |
+
public static function save_cache_options() {
|
3043 |
+
$changed = false;
|
3044 |
+
if ( \wfConfig::get( 'allowHTTPSCaching', false ) != $_POST['allowHTTPSCaching'] ) {
|
3045 |
+
$changed = true;
|
3046 |
+
}
|
3047 |
+
\wfConfig::set( 'allowHTTPSCaching', '1' == $_POST['allowHTTPSCaching'] ? 1 : 0 );
|
3048 |
+
\wfConfig::set( 'clearCacheSched', 1 == $_POST['clearCacheSched'] ? '1' : 0 );
|
3049 |
+
if ( $changed && \wfConfig::get( 'cacheType', false ) == 'falcon' ) {
|
3050 |
+
$err = \wfCache::addHtaccessCode( 'add' );
|
3051 |
+
if ( $err ) {
|
3052 |
+
return array(
|
3053 |
+
'updateErr' => 'Wordfence could not edit your .htaccess file. The error was: ' . $err,
|
3054 |
+
'code' => \wfCache::getHtaccessCode(),
|
3055 |
+
);
|
3056 |
+
}
|
3057 |
+
}
|
3058 |
+
\wfCache::scheduleCacheClear();
|
3059 |
+
return array( 'ok' => 1 );
|
3060 |
+
}
|
3061 |
+
|
3062 |
+
/**
|
3063 |
+
* Method clear_page_cache()
|
3064 |
+
*
|
3065 |
+
* Clear the page cache.
|
3066 |
+
*
|
3067 |
+
* @used-by MainWP_Child_Wordfence::actions() Fire off certain Wordfence plugin actions.
|
3068 |
+
*
|
3069 |
+
* @return array Action result.
|
3070 |
+
*/
|
3071 |
+
public static function clear_page_cache() {
|
3072 |
+
$stats = \wfCache::clearPageCache();
|
3073 |
+
if ( $stats['error'] ) {
|
3074 |
+
$body = 'A total of ' . $stats['totalErrors'] . ' errors occurred while trying to clear your cache. The last error was: ' . $stats['error'];
|
3075 |
+
return array(
|
3076 |
+
'ok' => 1,
|
3077 |
+
'heading' => 'Error occurred while clearing cache',
|
3078 |
+
'body' => $body,
|
3079 |
+
);
|
3080 |
+
}
|
3081 |
+
$body = 'A total of ' . $stats['filesDeleted'] . ' files were deleted and ' . $stats['dirsDeleted'] . ' directories were removed. We cleared a total of ' . $stats['totalData'] . 'KB of data in the cache.';
|
3082 |
+
if ( $stats['totalErrors'] > 0 ) {
|
3083 |
+
$body .= ' A total of ' . $stats['totalErrors'] . ' errors were encountered. This probably means that we could not remove some of the files or directories in the cache. Please use your CPanel or file manager to remove the rest of the files in the directory: ' . WP_CONTENT_DIR . '/wfcache/';
|
3084 |
+
}
|
3085 |
+
return array(
|
3086 |
+
'ok' => 1,
|
3087 |
+
'heading' => 'Page Cache Cleared',
|
3088 |
+
'body' => $body,
|
3089 |
+
);
|
3090 |
+
}
|
3091 |
+
|
3092 |
+
/**
|
3093 |
+
* Method get_cache_stats()
|
3094 |
+
*
|
3095 |
+
* Get the cache statistics data.
|
3096 |
+
*
|
3097 |
+
* @used-by MainWP_Child_Wordfence::actions() Fire off certain Wordfence plugin actions.
|
3098 |
+
*
|
3099 |
+
* @return array Action result.
|
3100 |
+
*/
|
3101 |
+
public static function get_cache_stats() {
|
3102 |
+
$s = \wfCache::getCacheStats();
|
3103 |
+
if ( 0 == $s['files'] ) {
|
3104 |
+
return array(
|
3105 |
+
'ok' => 1,
|
3106 |
+
'heading' => 'Cache Stats',
|
3107 |
+
'body' => 'The cache is currently empty. It may be disabled or it may have been recently cleared.',
|
3108 |
+
);
|
3109 |
+
}
|
3110 |
+
$body = 'Total files in cache: ' . $s['files'] .
|
3111 |
+
'<br />Total directories in cache: ' . $s['dirs'] .
|
3112 |
+
'<br />Total data: ' . $s['data'] . 'KB';
|
3113 |
+
if ( $s['compressedFiles'] > 0 ) {
|
3114 |
+
$body .= '<br />Files: ' . $s['uncompressedFiles'] .
|
3115 |
+
'<br />Data: ' . $s['uncompressedKBytes'] . 'KB' .
|
3116 |
+
'<br />Compressed files: ' . $s['compressedFiles'] .
|
3117 |
+
'<br />Compressed data: ' . $s['compressedKBytes'] . 'KB';
|
3118 |
+
}
|
3119 |
+
if ( $s['largestFile'] > 0 ) {
|
3120 |
+
$body .= '<br />Largest file: ' . $s['largestFile'] . 'KB';
|
3121 |
+
}
|
3122 |
+
if ( false !== $s['oldestFile'] ) {
|
3123 |
+
$body .= '<br />Oldest file in cache created ';
|
3124 |
+
if ( time() - $s['oldestFile'] < 300 ) {
|
3125 |
+
$body .= ( time() - $s['oldestFile'] ) . ' seconds ago';
|
3126 |
+
} else {
|
3127 |
+
$body .= human_time_diff( $s['oldestFile'] ) . ' ago.';
|
3128 |
+
}
|
3129 |
+
}
|
3130 |
+
if ( false !== $s['newestFile'] ) {
|
3131 |
+
$body .= '<br />Newest file in cache created ';
|
3132 |
+
if ( time() - $s['newestFile'] < 300 ) {
|
3133 |
+
$body .= ( time() - $s['newestFile'] ) . ' seconds ago';
|
3134 |
+
} else {
|
3135 |
+
$body .= human_time_diff( $s['newestFile'] ) . ' ago.';
|
3136 |
+
}
|
3137 |
+
}
|
3138 |
+
|
3139 |
+
return array(
|
3140 |
+
'ok' => 1,
|
3141 |
+
'heading' => 'Cache Stats',
|
3142 |
+
'body' => $body,
|
3143 |
+
);
|
3144 |
+
}
|
3145 |
+
|
3146 |
+
/**
|
3147 |
+
* Method add_cache_exclusion()
|
3148 |
+
*
|
3149 |
+
* Add caching exclusions.
|
3150 |
+
*
|
3151 |
+
* @used-by MainWP_Child_Wordfence::actions() Fire off certain Wordfence plugin actions.
|
3152 |
+
*
|
3153 |
+
* @return array Action result.
|
3154 |
+
*/
|
3155 |
+
public static function add_cache_exclusion() {
|
3156 |
+
$ex = \wfConfig::get( 'cacheExclusions', false );
|
3157 |
+
if ( $ex ) {
|
3158 |
+
$ex = unserialize( $ex ); // phpcs:ignore -- third party credit.
|
3159 |
+
} else {
|
3160 |
+
$ex = array();
|
3161 |
+
}
|
3162 |
+
if ( isset( $_POST['cacheExclusions'] ) ) {
|
3163 |
+
$ex = isset( $_POST['cacheExclusions'] ) ? wp_unslash( $_POST['cacheExclusions'] ) : '';
|
3164 |
+
} else {
|
3165 |
+
$ex[] = array(
|
3166 |
+
'pt' => isset( $_POST['patternType'] ) ? wp_unslash( $_POST['patternType'] ) : '',
|
3167 |
+
'p' => isset( $_POST['pattern'] ) ? wp_unslash( $_POST['pattern'] ) : '',
|
3168 |
+
'id' => isset( $_POST['id'] ) ? wp_unslash( $_POST['id'] ) : '',
|
3169 |
+
);
|
3170 |
+
}
|
3171 |
+
\wfConfig::set( 'cacheExclusions', serialize( $ex ) ); // phpcs:ignore -- third party credit.
|
3172 |
+
\wfCache::scheduleCacheClear();
|
3173 |
+
if ( \wfConfig::get( 'cacheType', false ) == 'falcon' && preg_match( '/^(?:uac|uaeq|cc)$/', $_POST['patternType'] ) ) {
|
3174 |
+
if ( \wfCache::addHtaccessCode( 'add' ) ) {
|
3175 |
+
return array(
|
3176 |
+
'errorMsg' => 'We added the rule you requested but could not modify your .htaccess file. Please delete this rule, check the permissions on your .htaccess file and then try again.',
|
3177 |
+
'ex' => $ex,
|
3178 |
+
);
|
3179 |
+
}
|
3180 |
+
}
|
3181 |
+
return array(
|
3182 |
+
'ok' => 1,
|
3183 |
+
'ex' => $ex,
|
3184 |
+
);
|
3185 |
+
}
|
3186 |
+
|
3187 |
+
/**
|
3188 |
+
* Method load_cache_exclusions()
|
3189 |
+
*
|
3190 |
+
* Load caching exclusions.
|
3191 |
+
*
|
3192 |
+
* @used-by MainWP_Child_Wordfence::actions() Fire off certain Wordfence plugin actions.
|
3193 |
+
*
|
3194 |
+
* @return array Action result.
|
3195 |
+
*/
|
3196 |
+
public static function load_cache_exclusions() {
|
3197 |
+
$ex = \wfConfig::get( 'cacheExclusions', false );
|
3198 |
+
if ( ! $ex ) {
|
3199 |
+
return array( 'ex' => false );
|
3200 |
+
}
|
3201 |
+
$ex = unserialize( $ex ); // phpcs:ignore -- third party credit.
|
3202 |
+
return array(
|
3203 |
+
'ok' => 1,
|
3204 |
+
'ex' => $ex,
|
3205 |
+
);
|
3206 |
+
}
|
3207 |
+
|
3208 |
+
/**
|
3209 |
+
* Method remove_cache_exclusion()
|
3210 |
+
*
|
3211 |
+
* Remove caching exclusions.
|
3212 |
+
*
|
3213 |
+
* @used-by MainWP_Child_Wordfence::actions() Fire off certain Wordfence plugin actions.
|
3214 |
+
*
|
3215 |
+
* @return array Action result.
|
3216 |
+
*/
|
3217 |
+
public static function remove_cache_exclusion() {
|
3218 |
+
$id = isset( $_POST['id'] ) ? sanitize_text_field( wp_unslash( $_POST['id'] ) ) : '';
|
3219 |
+
$ex = \wfConfig::get( 'cacheExclusions', false );
|
3220 |
+
if ( ! $ex ) {
|
3221 |
+
return array( 'ok' => 1 );
|
3222 |
+
}
|
3223 |
+
$ex = unserialize( $ex ); // phpcs:ignore -- third party credit.
|
3224 |
+
$rewriteHtaccess = false;
|
3225 |
+
$removed = false;
|
3226 |
+
$count_ex = count( $ex );
|
3227 |
+
for ( $i = 0; $i < $count_ex; $i++ ) {
|
3228 |
+
if ( (string) $ex[ $i ]['id'] == (string) $id ) {
|
3229 |
+
if ( \wfConfig::get( 'cacheType', false ) == 'falcon' && preg_match( '/^(?:uac|uaeq|cc)$/', $ex[ $i ]['pt'] ) ) {
|
3230 |
+
$rewriteHtaccess = true;
|
3231 |
+
}
|
3232 |
+
array_splice( $ex, $i, 1 );
|
3233 |
+
// Dont break in case of dups!
|
3234 |
+
$removed = true;
|
3235 |
+
}
|
3236 |
+
}
|
3237 |
+
$return = array( 'ex' => $ex );
|
3238 |
+
if ( ! $removed ) {
|
3239 |
+
$return['error'] = 'Not found the cache exclusion.';
|
3240 |
+
return $return;
|
3241 |
+
}
|
3242 |
+
|
3243 |
+
\wfConfig::set( 'cacheExclusions', serialize( $ex ) ); // phpcs:ignore -- third party credit.
|
3244 |
+
if ( $rewriteHtaccess && \wfCache::addHtaccessCode( 'add' ) ) {
|
3245 |
+
$return['errorMsg'] = "We removed that rule but could not rewrite your .htaccess file. You're going to have to manually remove this rule from your .htaccess file. Please reload this page now.";
|
3246 |
+
return $return;
|
3247 |
+
}
|
3248 |
+
|
3249 |
+
$return['ok'] = 1;
|
3250 |
+
return $return;
|
3251 |
+
}
|
3252 |
+
|
3253 |
+
/**
|
3254 |
+
* Method get_diagnostics()
|
3255 |
+
*
|
3256 |
+
* Get the diagnostics data.
|
3257 |
+
*
|
3258 |
+
* @used-by MainWP_Child_Wordfence::actions() Fire off certain Wordfence plugin actions.
|
3259 |
+
*
|
3260 |
+
* @return array Action result.
|
3261 |
+
*/
|
3262 |
+
public function get_diagnostics() {
|
3263 |
+
|
3264 |
+
$diagnostic = new \wfDiagnostic();
|
3265 |
+
$plugins = get_plugins();
|
3266 |
+
$activePlugins = array_flip( get_option( 'active_plugins' ) );
|
3267 |
+
$activeNetworkPlugins = is_multisite() ? array_flip( wp_get_active_network_plugins() ) : array();
|
3268 |
+
$muPlugins = get_mu_plugins();
|
3269 |
+
$themes = wp_get_themes();
|
3270 |
+
$currentTheme = wp_get_theme();
|
3271 |
+
$cols = 3;
|
3272 |
+
|
3273 |
+
$w = new \wfConfig();
|
3274 |
+
|
3275 |
+
$inEmail = false;
|
3276 |
+
ob_start();
|
3277 |
+
|
3278 |
+
?>
|
3279 |
+
<div id="wf-diagnostics">
|
3280 |
+
<form id="wfConfigForm" style="overflow-x: auto;">
|
3281 |
+
<?php
|
3282 |
+
foreach ( $diagnostic->getResults() as $title => $tests ) :
|
3283 |
+
$key = sanitize_key( 'wf-diagnostics-' . $title );
|
3284 |
+
$hasFailingTest = false;
|
3285 |
+
foreach ( $tests['results'] as $result ) {
|
3286 |
+
if ( ! $result['test'] ) {
|
3287 |
+
$hasFailingTest = true;
|
3288 |
+
break;
|
3289 |
+
}
|
3290 |
+
}
|
3291 |
+
|
3292 |
+
if ( $inEmail ) :
|
3293 |
+
?>
|
3294 |
+
<table>
|
3295 |
+
<thead>
|
3296 |
+
<tr>
|
3297 |
+
<th colspan="<?php echo $cols; ?>"><?php echo esc_html( __( $title, 'wordfence' ) ); ?></th>
|
3298 |
+
</tr>
|
3299 |
+
</thead>
|
3300 |
+
<tbody>
|
3301 |
+
<?php foreach ( $tests['results'] as $result ) : ?>
|
3302 |
+
<tr>
|
3303 |
+
<td style="width: 75%;" colspan="<?php echo $cols - 1; ?>">
|
3304 |
+
<?php
|
3305 |
+
echo wp_kses(
|
3306 |
+
$result['label'],
|
3307 |
+
array(
|
3308 |
+
'code' => array(),
|
3309 |
+
'strong' => array(),
|
3310 |
+
'em' => array(),
|
3311 |
+
'a' => array( 'href' => true ),
|
3312 |
+
)
|
3313 |
+
);
|
3314 |
+
?>
|
3315 |
+
</td>
|
3316 |
+
<td>
|
3317 |
+
<?php if ( $result['test'] ) : ?>
|
3318 |
+
<div class="wf-result-success"><?php echo esc_html( $result['message'] ); ?></div>
|
3319 |
+
<?php else : ?>
|
3320 |
+
<div class="wf-result-error"><?php echo esc_html( $result['message'] ); ?></div>
|
3321 |
+
<?php endif; ?>
|
3322 |
+
</td>
|
3323 |
+
</tr>
|
3324 |
+
<?php endforeach; ?>
|
3325 |
+
</tbody>
|
3326 |
+
</table>
|
3327 |
+
<?php else : ?>
|
3328 |
+
<div class="wf-block <?php echo ( \wfPersistenceController::shared()->isActive( $key ) ? ' wf-active' : '' ) . ( $hasFailingTest ? ' wf-diagnostic-fail' : '' ); ?>" data-persistence-key="<?php echo esc_attr( $key ); ?>">
|
3329 |
+
<div class="wf-block-header">
|
3330 |
+
<div class="wf-block-header-content">
|
3331 |
+
<div class="wf-block-title">
|
3332 |
+
<strong><?php echo esc_html( __( $title, 'wordfence' ) ); ?></strong>
|
3333 |
+
<span class="wf-text-small"><?php echo esc_html( __( $tests['description'], 'wordfence' ) ); ?></span>
|
3334 |
+
</div>
|
3335 |
+
<div class="wf-block-header-action">
|
3336 |
+
<div class="wf-block-header-action-disclosure"></div>
|
3337 |
+
</div>
|
3338 |
+
</div>
|
3339 |
+
</div>
|
3340 |
+
<div class="wf-block-content wf-clearfix">
|
3341 |
+
<ul class="wf-block-list">
|
3342 |
+
<?php foreach ( $tests['results'] as $result ) : ?>
|
3343 |
+
<li>
|
3344 |
+
<div style="width: 75%;" colspan="<?php echo $cols - 1; ?>">
|
3345 |
+
<?php
|
3346 |
+
echo wp_kses(
|
3347 |
+
$result['label'],
|
3348 |
+
array(
|
3349 |
+
'code' => array(),
|
3350 |
+
'strong' => array(),
|
3351 |
+
'em' => array(),
|
3352 |
+
'a' => array( 'href' => true ),
|
3353 |
+
)
|
3354 |
+
);
|
3355 |
+
?>
|
3356 |
+
</div>
|
3357 |
+
<?php if ( $result['test'] ) : ?>
|
3358 |
+
<div class="wf-result-success"><?php echo esc_html( $result['message'] ); ?></div>
|
3359 |
+
<?php else : ?>
|
3360 |
+
<div class="wf-result-error"><?php echo esc_html( $result['message'] ); ?></div>
|
3361 |
+
<?php endif; ?>
|
3362 |
+
</li>
|
3363 |
+
<?php endforeach; ?>
|
3364 |
+
</ul>
|
3365 |
+
</div>
|
3366 |
+
</div>
|
3367 |
+
<?php endif; ?>
|
3368 |
+
<?php endforeach; ?>
|
3369 |
+
<?php
|
3370 |
+
$howGet = \wfConfig::get( 'howGetIPs', false );
|
3371 |
+
list( $currentIP, $currentServerVarForIP ) = \wfUtils::getIPAndServerVariable();
|
3372 |
+
$howGetHasErrors = false;
|
3373 |
+
foreach ( array(
|
3374 |
+
'REMOTE_ADDR' => 'REMOTE_ADDR',
|
3375 |
+
'HTTP_CF_CONNECTING_IP' => 'CF-Connecting-IP',
|
3376 |
+
'HTTP_X_REAL_IP' => 'X-Real-IP',
|
3377 |
+
'HTTP_X_FORWARDED_FOR' => 'X-Forwarded-For',
|
3378 |
+
) as $variable => $label ) {
|
3379 |
+
if ( ! ( $currentServerVarForIP && $currentServerVarForIP === $variable ) && $howGet === $variable ) {
|
3380 |
+
$howGetHasErrors = true;
|
3381 |
+
break;
|
3382 |
+
}
|
3383 |
+
}
|
3384 |
+
?>
|
3385 |
+
<div class="wf-block<?php echo ( $howGetHasErrors ? ' wf-diagnostic-fail' : '' ) . ( \wfPersistenceController::shared()->isActive( 'wf-diagnostics-client-ip' ) ? ' wf-active' : '' ); ?>" data-persistence-key="<?php echo esc_attr( 'wf-diagnostics-client-ip' ); ?>">
|
3386 |
+
<div class="wf-block-header">
|
3387 |
+
<div class="wf-block-header-content">
|
3388 |
+
<div class="wf-block-title">
|
3389 |
+
<strong><?php esc_html_e( 'IP Detection', 'wordfence' ); ?></strong>
|
3390 |
+
<span class="wf-text-small"><?php esc_html_e( 'Methods of detecting a visitor\'s IP address.', 'wordfence' ); ?></span>
|
3391 |
+
</div>
|
3392 |
+
<div class="wf-block-header-action">
|
3393 |
+
<div class="wf-block-header-action-disclosure"></div>
|
3394 |
+
</div>
|
3395 |
+
</div>
|
3396 |
+
</div>
|
3397 |
+
<div class="wf-block-content wf-clearfix wf-padding-no-left wf-padding-no-right">
|
3398 |
+
<table class="wf-striped-table"<?php echo ! empty( $inEmail ) ? ' border=1' : ''; ?>>
|
3399 |
+
<tbody class="thead">
|
3400 |
+
<tr>
|
3401 |
+
<th><?php esc_html_e( 'IPs', 'wordfence' ); ?></th>
|
3402 |
+
<th><?php esc_html_e( 'Value', 'wordfence' ); ?></th>
|
3403 |
+
<th><?php esc_html_e( 'Used', 'wordfence' ); ?></th>
|
3404 |
+
</tr>
|
3405 |
+
</tbody>
|
3406 |
+
<tbody>
|
3407 |
+
<?php
|
3408 |
+
$howGet = \wfConfig::get( 'howGetIPs', false );
|
3409 |
+
list( $currentIP, $currentServerVarForIP ) = \wfUtils::getIPAndServerVariable();
|
3410 |
+
foreach ( array(
|
3411 |
+
'REMOTE_ADDR' => 'REMOTE_ADDR',
|
3412 |
+
'HTTP_CF_CONNECTING_IP' => 'CF-Connecting-IP',
|
3413 |
+
'HTTP_X_REAL_IP' => 'X-Real-IP',
|
3414 |
+
'HTTP_X_FORWARDED_FOR' => 'X-Forwarded-For',
|
3415 |
+
) as $variable => $label ) :
|
3416 |
+
?>
|
3417 |
+
<tr>
|
3418 |
+
<td><?php echo $label; ?></td>
|
3419 |
+
<td>
|
3420 |
+
<?php
|
3421 |
+
if ( ! array_key_exists( $variable, $_SERVER ) ) {
|
3422 |
+
echo '(not set)';
|
3423 |
+
} else {
|
3424 |
+
if ( false !== strpos( $_SERVER[ $variable ], ',' ) ) {
|
3425 |
+
$trustedProxies = explode( "\n", \wfConfig::get( 'howGetIPs_trusted_proxies', '' ) );
|
3426 |
+
$items = preg_replace( '/[\s,]/', '', explode( ',', $_SERVER[ $variable ] ) );
|
3427 |
+
$items = array_reverse( $items );
|
3428 |
+
$output = '';
|
3429 |
+
$markedSelectedAddress = false;
|
3430 |
+
foreach ( $items as $index => $i ) {
|
3431 |
+
foreach ( $trustedProxies as $proxy ) {
|
3432 |
+
if ( ! empty( $proxy ) ) {
|
3433 |
+
if ( \wfUtils::subnetContainsIP( $proxy, $i ) && $index < count( $items ) - 1 ) {
|
3434 |
+
$output = esc_html( $i ) . ', ' . $output;
|
3435 |
+
continue 2;
|
3436 |
+
}
|
3437 |
+
}
|
3438 |
+
}
|
3439 |
+
if ( ! $markedSelectedAddress ) {
|
3440 |
+
$output = '<strong>' . esc_html( $i ) . '</strong>, ' . $output;
|
3441 |
+
$markedSelectedAddress = true;
|
3442 |
+
} else {
|
3443 |
+
$output = esc_html( $i ) . ', ' . $output;
|
3444 |
+
}
|
3445 |
+
}
|
3446 |
+
echo substr( $output, 0, -2 );
|
3447 |
+
} else {
|
3448 |
+
echo esc_html( $_SERVER[ $variable ] );
|
3449 |
+
}
|
3450 |
+
}
|
3451 |
+
?>
|
3452 |
+
</td>
|
3453 |
+
<?php if ( $currentServerVarForIP && $currentServerVarForIP === $variable ) : ?>
|
3454 |
+
<td class="wf-result-success">In use</td>
|
3455 |
+
<?php elseif ( $howGet === $variable ) : ?>
|
3456 |
+
<td class="wf-result-error">Configured, but not valid</td>
|
3457 |
+
<?php else : ?>
|
3458 |
+
<td></td>
|
3459 |
+
<?php endif; ?>
|
3460 |
+
</tr>
|
3461 |
+
<?php endforeach; ?>
|
3462 |
+
</tbody>
|
3463 |
+
</table>
|
3464 |
+
</div>
|
3465 |
+
</div>
|
3466 |
+
<div class="wf-block<?php echo( \wfPersistenceController::shared()->isActive( 'wf-diagnostics-wordpress-constants' ) ? ' wf-active' : '' ); ?>" data-persistence-key="<?php echo esc_attr( 'wf-diagnostics-wordpress-constants' ); ?>">
|
3467 |
+
<div class="wf-block-header">
|
3468 |
+
<div class="wf-block-header-content">
|
3469 |
+
<div class="wf-block-title">
|
3470 |
+
<strong><?php _e( 'WordPress Settings', 'wordfence' ); ?></strong>
|
3471 |
+
<span class="wf-text-small"><?php _e( 'WordPress version and internal settings/constants.', 'wordfence' ); ?></span>
|
3472 |
+
</div>
|
3473 |
+
<div class="wf-block-header-action">
|
3474 |
+
<div class="wf-block-header-action-disclosure"></div>
|
3475 |
+
</div>
|
3476 |
+
</div>
|
3477 |
+
</div>
|
3478 |
+
<div class="wf-block-content wf-clearfix wf-padding-no-left wf-padding-no-right">
|
3479 |
+
<table class="wf-striped-table"<?php echo ! empty( $inEmail ) ? ' border=1' : ''; ?>>
|
3480 |
+
<tbody>
|
3481 |
+
<?php
|
3482 |
+
require ABSPATH . 'wp-includes/version.php';
|
3483 |
+
$postRevisions = ( defined( 'WP_POST_REVISIONS' ) ? WP_POST_REVISIONS : true );
|
3484 |
+
$wordPressValues = array(
|
3485 |
+
'WordPress Version' => array(
|
3486 |
+
'description' => '',
|
3487 |
+
'value' => $wp_version,
|
3488 |
+
),
|
3489 |
+
'WP_DEBUG' => array(
|
3490 |
+
'description' => 'WordPress debug mode',
|
3491 |
+
'value' => ( defined( 'WP_DEBUG' ) && WP_DEBUG ? 'On' : 'Off' ),
|
3492 |
+
),
|
3493 |
+
'WP_DEBUG_LOG' => array(
|
3494 |
+
'description' => 'WordPress error logging override',
|
3495 |
+
'value' => defined( 'WP_DEBUG_LOG' ) ? ( WP_DEBUG_LOG ? 'Enabled' : 'Disabled' ) : '(not set)',
|
3496 |
+
),
|
3497 |
+
'WP_DEBUG_DISPLAY' => array(
|
3498 |
+
'description' => 'WordPress error display override',
|
3499 |
+
'value' => defined( 'WP_DEBUG_DISPLAY' ) ? ( WP_DEBUG_LOG ? 'Enabled' : 'Disabled' ) : '(not set)',
|
3500 |
+
),
|
3501 |
+
'SCRIPT_DEBUG' => array(
|
3502 |
+
'description' => 'WordPress script debug mode',
|
3503 |
+
'value' => ( defined( 'SCRIPT_DEBUG' ) && SCRIPT_DEBUG ? 'On' : 'Off' ),
|
3504 |
+
),
|
3505 |
+
'SAVEQUERIES' => array(
|
3506 |
+
'description' => 'WordPress query debug mode',
|
3507 |
+
'value' => ( defined( 'SAVEQUERIES' ) && SAVEQUERIES ? 'On' : 'Off' ),
|
3508 |
+
),
|
3509 |
+
'DB_CHARSET' => 'Database character set',
|
3510 |
+
'DB_COLLATE' => 'Database collation',
|
3511 |
+
'WP_SITEURL' => 'Explicitly set site URL',
|
3512 |
+
'WP_HOME' => 'Explicitly set blog URL',
|
3513 |
+
'WP_CONTENT_DIR' => array(
|
3514 |
+
'description' => '"wp-content" folder is in default location',
|
3515 |
+
'value' => ( realpath( WP_CONTENT_DIR ) === realpath( ABSPATH . 'wp-content' ) ? 'Yes' : 'No' ),
|
3516 |
+
),
|
3517 |
+
'WP_CONTENT_URL' => 'URL to the "wp-content" folder',
|
3518 |
+
'WP_PLUGIN_DIR' => array(
|
3519 |
+
'description' => '"plugins" folder is in default location',
|
3520 |
+
'value' => ( realpath( WP_PLUGIN_DIR ) === realpath( ABSPATH . 'wp-content/plugins' ) ? 'Yes' : 'No' ),
|
3521 |
+
),
|
3522 |
+
'WP_LANG_DIR' => array(
|
3523 |
+
'description' => '"languages" folder is in default location',
|
3524 |
+
'value' => ( realpath( WP_LANG_DIR ) === realpath( ABSPATH . 'wp-content/languages' ) ? 'Yes' : 'No' ),
|
3525 |
+
),
|
3526 |
+
'WPLANG' => 'Language choice',
|
3527 |
+
'UPLOADS' => 'Custom upload folder location',
|
3528 |
+
'TEMPLATEPATH' => array(
|
3529 |
+
'description' => 'Theme template folder override',
|
3530 |
+
'value' => ( defined( 'TEMPLATEPATH' ) && realpath( get_template_directory() ) !== realpath( TEMPLATEPATH ) ? 'Overridden' : '(not set)' ), //phpcs:ignore -- use to check defined
|
3531 |
+
),
|
3532 |
+
'STYLESHEETPATH' => array(
|
3533 |
+
'description' => 'Theme stylesheet folder override',
|
3534 |
+
'value' => ( defined( 'STYLESHEETPATH' ) && realpath( get_stylesheet_directory() ) !== realpath( STYLESHEETPATH ) ? 'Overridden' : '(not set)' ), //phpcs:ignore -- use to check defined
|
3535 |
+
),
|
3536 |
+
'AUTOSAVE_INTERVAL' => 'Post editing automatic saving interval',
|
3537 |
+
'WP_POST_REVISIONS' => array(
|
3538 |
+
'description' => 'Post revisions saved by WordPress',
|
3539 |
+
'value' => is_numeric( $postRevisions ) ? $postRevisions : ( $postRevisions ? 'Unlimited' : 'None' ),
|
3540 |
+
),
|
3541 |
+
'COOKIE_DOMAIN' => 'WordPress cookie domain',
|
3542 |
+
'COOKIEPATH' => 'WordPress cookie path',
|
3543 |
+
'SITECOOKIEPATH' => 'WordPress site cookie path',
|
3544 |
+
'ADMIN_COOKIE_PATH' => 'WordPress admin cookie path',
|
3545 |
+
'PLUGINS_COOKIE_PATH' => 'WordPress plugins cookie path',
|
3546 |
+
'WP_ALLOW_MULTISITE' => array(
|
3547 |
+
'description' => 'Multisite/network ability enabled',
|
3548 |
+
'value' => ( defined( 'WP_ALLOW_MULTISITE' ) && WP_ALLOW_MULTISITE ? 'Yes' : 'No' ),
|
3549 |
+
),
|
3550 |
+
'NOBLOGREDIRECT' => 'URL redirected to if the visitor tries to access a nonexistent blog',
|
3551 |
+
'CONCATENATE_SCRIPTS' => array(
|
3552 |
+
'description' => 'Concatenate JavaScript files',
|
3553 |
+
'value' => ( defined( 'CONCATENATE_SCRIPTS' ) && CONCATENATE_SCRIPTS ? 'Yes' : 'No' ),
|
3554 |
+
),
|
3555 |
+
'WP_MEMORY_LIMIT' => 'WordPress memory limit',
|
3556 |
+
'WP_MAX_MEMORY_LIMIT' => 'Administrative memory limit',
|
3557 |
+
'WP_CACHE' => array(
|
3558 |
+
'description' => 'Built-in caching',
|
3559 |
+
'value' => ( defined( 'WP_CACHE' ) && WP_CACHE ? 'Enabled' : 'Disabled' ),
|
3560 |
+
),
|
3561 |
+
'CUSTOM_USER_TABLE' => array(
|
3562 |
+
'description' => 'Custom "users" table',
|
3563 |
+
'value' => ( defined( 'CUSTOM_USER_TABLE' ) ? 'Set' : '(not set)' ),
|
3564 |
+
),
|
3565 |
+
'CUSTOM_USER_META_TABLE' => array(
|
3566 |
+
'description' => 'Custom "usermeta" table',
|
3567 |
+
'value' => ( defined( 'CUSTOM_USER_META_TABLE' ) ? 'Set' : '(not set)' ),
|
3568 |
+
),
|
3569 |
+
'FS_CHMOD_DIR' => array(
|
3570 |
+
'description' => 'Overridden permissions for a new folder',
|
3571 |
+
'value' => defined( 'FS_CHMOD_DIR' ) ? decoct( FS_CHMOD_DIR ) : '(not set)',
|
3572 |
+
),
|
3573 |
+
'FS_CHMOD_FILE' => array(
|
3574 |
+
'description' => 'Overridden permissions for a new file',
|
3575 |
+
'value' => defined( 'FS_CHMOD_FILE' ) ? decoct( FS_CHMOD_FILE ) : '(not set)',
|
3576 |
+
),
|
3577 |
+
'ALTERNATE_WP_CRON' => array(
|
3578 |
+
'description' => 'Alternate WP cron',
|
3579 |
+
'value' => ( defined( 'ALTERNATE_WP_CRON' ) && ALTERNATE_WP_CRON ? 'Enabled' : 'Disabled' ),
|
3580 |
+
),
|
3581 |
+
'DISABLE_WP_CRON' => array(
|
3582 |
+
'description' => 'WP cron status',
|
3583 |
+
'value' => ( defined( 'DISABLE_WP_CRON' ) && DISABLE_WP_CRON ? 'Disabled' : 'Enabled' ),
|
3584 |
+
),
|
3585 |
+
'WP_CRON_LOCK_TIMEOUT' => 'Cron running frequency lock',
|
3586 |
+
'EMPTY_TRASH_DAYS' => array(
|
3587 |
+
'description' => 'Interval the trash is automatically emptied at in days',
|
3588 |
+
'value' => ( EMPTY_TRASH_DAYS > 0 ? EMPTY_TRASH_DAYS : 'Never' ),
|
3589 |
+
),
|
3590 |
+
'WP_ALLOW_REPAIR' => array(
|
3591 |
+
'description' => 'Automatic database repair',
|
3592 |
+
'value' => ( defined( 'WP_ALLOW_REPAIR' ) && WP_ALLOW_REPAIR ? 'Enabled' : 'Disabled' ),
|
3593 |
+
),
|
3594 |
+
'DO_NOT_UPGRADE_GLOBAL_TABLES' => array(
|
3595 |
+
'description' => 'Do not upgrade global tables',
|
3596 |
+
'value' => ( defined( 'DO_NOT_UPGRADE_GLOBAL_TABLES' ) && DO_NOT_UPGRADE_GLOBAL_TABLES ? 'Yes' : 'No' ),
|
3597 |
+
),
|
3598 |
+
'DISALLOW_FILE_EDIT' => array(
|
3599 |
+
'description' => 'Disallow plugin/theme editing',
|
3600 |
+
'value' => ( defined( 'DISALLOW_FILE_EDIT' ) && DISALLOW_FILE_EDIT ? 'Yes' : 'No' ),
|
3601 |
+
),
|
3602 |
+
'DISALLOW_FILE_MODS' => array(
|
3603 |
+
'description' => 'Disallow plugin/theme update and installation',
|
3604 |
+
'value' => ( defined( 'DISALLOW_FILE_MODS' ) && DISALLOW_FILE_MODS ? 'Yes' : 'No' ),
|
3605 |
+
),
|
3606 |
+
'IMAGE_EDIT_OVERWRITE' => array(
|
3607 |
+
'description' => 'Overwrite image edits when restoring the original',
|
3608 |
+
'value' => ( defined( 'IMAGE_EDIT_OVERWRITE' ) && IMAGE_EDIT_OVERWRITE ? 'Yes' : 'No' ),
|
3609 |
+
),
|
3610 |
+
'FORCE_SSL_ADMIN' => array(
|
3611 |
+
'description' => 'Force SSL for administrative logins',
|
3612 |
+
'value' => ( defined( 'FORCE_SSL_ADMIN' ) && FORCE_SSL_ADMIN ? 'Yes' : 'No' ),
|
3613 |
+
),
|
3614 |
+
'WP_HTTP_BLOCK_EXTERNAL' => array(
|
3615 |
+
'description' => 'Block external URL requests',
|
3616 |
+
'value' => ( defined( 'WP_HTTP_BLOCK_EXTERNAL' ) && WP_HTTP_BLOCK_EXTERNAL ? 'Yes' : 'No' ),
|
3617 |
+
),
|
3618 |
+
'WP_ACCESSIBLE_HOSTS' => 'Whitelisted hosts',
|
3619 |
+
'WP_AUTO_UPDATE_CORE' => array(
|
3620 |
+
'description' => 'Automatic WP Core updates',
|
3621 |
+
'value' => defined( 'WP_AUTO_UPDATE_CORE' ) ? ( is_bool( WP_AUTO_UPDATE_CORE ) ? ( WP_AUTO_UPDATE_CORE ? 'Everything' : 'None' ) : WP_AUTO_UPDATE_CORE ) : 'Default',
|
3622 |
+
),
|
3623 |
+
'WP_PROXY_HOST' => array(
|
3624 |
+
'description' => 'Hostname for a proxy server',
|
3625 |
+
'value' => defined( 'WP_PROXY_HOST' ) ? WP_PROXY_HOST : '(not set)',
|
3626 |
+
),
|
3627 |
+
'WP_PROXY_PORT' => array(
|
3628 |
+
'description' => 'Port for a proxy server',
|
3629 |
+
'value' => defined( 'WP_PROXY_PORT' ) ? WP_PROXY_PORT : '(not set)',
|
3630 |
+
),
|
3631 |
+
);
|
3632 |
+
|
3633 |
+
foreach ( $wordPressValues as $settingName => $settingData ) :
|
3634 |
+
$escapedName = esc_html( $settingName );
|
3635 |
+
$escapedDescription = '';
|
3636 |
+
$escapedValue = '(not set)';
|
3637 |
+
if ( is_array( $settingData ) ) {
|
3638 |
+
$escapedDescription = esc_html( $settingData['description'] );
|
3639 |
+
if ( isset( $settingData['value'] ) ) {
|
3640 |
+
$escapedValue = esc_html( $settingData['value'] );
|
3641 |
+
}
|
3642 |
+
} else {
|
3643 |
+
$escapedDescription = esc_html( $settingData );
|
3644 |
+
if ( defined( $settingName ) ) {
|
3645 |
+
$escapedValue = esc_html( constant( $settingName ) );
|
3646 |
+
}
|
3647 |
+
}
|
3648 |
+
?>
|
3649 |
+
<tr>
|
3650 |
+
<td><strong><?php echo $escapedName; ?></strong></td>
|
3651 |
+
<td><?php echo $escapedDescription; ?></td>
|
3652 |
+
<td><?php echo $escapedValue; ?></td>
|
3653 |
+
</tr>
|
3654 |
+
<?php endforeach ?>
|
3655 |
+
</tbody>
|
3656 |
+
</table>
|
3657 |
+
</div>
|
3658 |
+
</div>
|
3659 |
+
<div class="wf-block<?php echo( \wfPersistenceController::shared()->isActive( 'wf-diagnostics-wordpress-plugins' ) ? ' wf-active' : '' ); ?>" data-persistence-key="<?php echo esc_attr( 'wf-diagnostics-wordpress-plugins' ); ?>">
|
3660 |
+
<div class="wf-block-header">
|
3661 |
+
<div class="wf-block-header-content">
|
3662 |
+
<div class="wf-block-title">
|
3663 |
+
<strong><?php _e( 'WordPress Plugins', 'wordfence' ); ?></strong>
|
3664 |
+
<span class="wf-text-small"><?php _e( 'Status of installed plugins.', 'wordfence' ); ?></span>
|
3665 |
+
</div>
|
3666 |
+
<div class="wf-block-header-action">
|
3667 |
+
<div class="wf-block-header-action-disclosure"></div>
|
3668 |
+
</div>
|
3669 |
+
</div>
|
3670 |
+
</div>
|
3671 |
+
<div class="wf-block-content wf-clearfix wf-padding-no-left wf-padding-no-right">
|
3672 |
+
<table class="wf-striped-table"<?php echo ! empty( $inEmail ) ? ' border=1' : ''; ?>>
|
3673 |
+
<tbody>
|
3674 |
+
<?php foreach ( $plugins as $plugin => $pluginData ) : ?>
|
3675 |
+
<tr>
|
3676 |
+
<td colspan="<?php echo $cols - 1; ?>">
|
3677 |
+
<strong><?php echo esc_html( $pluginData['Name'] ); ?></strong>
|
3678 |
+
<?php if ( ! empty( $pluginData['Version'] ) ) : ?>
|
3679 |
+
- Version <?php echo esc_html( $pluginData['Version'] ); ?>
|
3680 |
+
<?php endif ?>
|
3681 |
+
</td>
|
3682 |
+
<?php if ( array_key_exists( trailingslashit( WP_PLUGIN_DIR ) . $plugin, $activeNetworkPlugins ) ) : ?>
|
3683 |
+
<td class="wf-result-success">Network Activated</td>
|
3684 |
+
<?php elseif ( array_key_exists( $plugin, $activePlugins ) ) : ?>
|
3685 |
+
<td class="wf-result-success">Active</td>
|
3686 |
+
<?php else : ?>
|
3687 |
+
<td class="wf-result-inactive">Inactive</td>
|
3688 |
+
<?php endif ?>
|
3689 |
+
</tr>
|
3690 |
+
<?php endforeach ?>
|
3691 |
+
</tbody>
|
3692 |
+
</table>
|
3693 |
+
</div>
|
3694 |
+
</div>
|
3695 |
+
<div class="wf-block<?php echo( \wfPersistenceController::shared()->isActive( 'wf-diagnostics-mu-wordpress-plugins' ) ? ' wf-active' : '' ); ?>" data-persistence-key="<?php echo esc_attr( 'wf-diagnostics-mu-wordpress-plugins' ); ?>">
|
3696 |
+
<div class="wf-block-header">
|
3697 |
+
<div class="wf-block-header-content">
|
3698 |
+
<div class="wf-block-title">
|
3699 |
+
<strong><?php _e( 'Must-Use WordPress Plugins', 'wordfence' ); ?></strong>
|
3700 |
+
<span class="wf-text-small"><?php _e( 'WordPress "mu-plugins" that are always active, incluing those provided by hosts.', 'wordfence' ); ?></span>
|
3701 |
+
</div>
|
3702 |
+
<div class="wf-block-header-action">
|
3703 |
+
<div class="wf-block-header-action-disclosure"></div>
|
3704 |
+
</div>
|
3705 |
+
</div>
|
3706 |
+
</div>
|
3707 |
+
<div class="wf-block-content wf-clearfix wf-padding-no-left wf-padding-no-right">
|
3708 |
+
<table class="wf-striped-table"<?php echo ! empty( $inEmail ) ? ' border=1' : ''; ?>>
|
3709 |
+
<?php if ( ! empty( $muPlugins ) ) : ?>
|
3710 |
+
<tbody>
|
3711 |
+
<?php foreach ( $muPlugins as $plugin => $pluginData ) : ?>
|
3712 |
+
<tr>
|
3713 |
+
<td colspan="<?php echo $cols - 1; ?>">
|
3714 |
+
<strong><?php echo esc_html( $pluginData['Name'] ); ?></strong>
|
3715 |
+
<?php if ( ! empty( $pluginData['Version'] ) ) : ?>
|
3716 |
+
- Version <?php echo esc_html( $pluginData['Version'] ); ?>
|
3717 |
+
<?php endif ?>
|
3718 |
+
</td>
|
3719 |
+
<td class="wf-result-success">Active</td>
|
3720 |
+
</tr>
|
3721 |
+
<?php endforeach ?>
|
3722 |
+
</tbody>
|
3723 |
+
<?php else : ?>
|
3724 |
+
<tbody>
|
3725 |
+
<tr>
|
3726 |
+
<td colspan="<?php echo $cols; ?>">No MU-Plugins</td>
|
3727 |
+
</tr>
|
3728 |
+
</tbody>
|
3729 |
+
<?php endif ?>
|
3730 |
+
</table>
|
3731 |
+
</div>
|
3732 |
+
</div>
|
3733 |
+
<div class="wf-block<?php echo( \wfPersistenceController::shared()->isActive( 'wf-diagnostics-wordpress-themes' ) ? ' wf-active' : '' ); ?>" data-persistence-key="<?php echo esc_attr( 'wf-diagnostics-wordpress-themes' ); ?>">
|
3734 |
+
<div class="wf-block-header">
|
3735 |
+
<div class="wf-block-header-content">
|
3736 |
+
<div class="wf-block-title">
|
3737 |
+
<strong><?php _e( 'Themes', 'wordfence' ); ?></strong>
|
3738 |
+
<span class="wf-text-small"><?php _e( 'Status of installed themes.', 'wordfence' ); ?></span>
|
3739 |
+
</div>
|
3740 |
+
<div class="wf-block-header-action">
|
3741 |
+
<div class="wf-block-header-action-disclosure"></div>
|
3742 |
+
</div>
|
3743 |
+
</div>
|
3744 |
+
</div>
|
3745 |
+
<div class="wf-block-content wf-clearfix wf-padding-no-left wf-padding-no-right">
|
3746 |
+
<table class="wf-striped-table"<?php echo ! empty( $inEmail ) ? ' border=1' : ''; ?>>
|
3747 |
+
<?php if ( ! empty( $themes ) ) : ?>
|
3748 |
+
<tbody>
|
3749 |
+
<?php foreach ( $themes as $theme => $themeData ) : ?>
|
3750 |
+
<tr>
|
3751 |
+
<td colspan="<?php echo $cols - 1; ?>">
|
3752 |
+
<strong><?php echo esc_html( $themeData['Name'] ); ?></strong>
|
3753 |
+
Version <?php echo esc_html( $themeData['Version'] ); ?></td>
|
3754 |
+
<?php if ( $currentTheme instanceof WP_Theme && $theme === $currentTheme->get_stylesheet() ) : ?>
|
3755 |
+
<td class="wf-result-success">Active</td>
|
3756 |
+
<?php else : ?>
|
3757 |
+
<td class="wf-result-inactive">Inactive</td>
|
3758 |
+
<?php endif ?>
|
3759 |
+
</tr>
|
3760 |
+
<?php endforeach ?>
|
3761 |
+
</tbody>
|
3762 |
+
<?php else : ?>
|
3763 |
+
<tbody>
|
3764 |
+
<tr>
|
3765 |
+
<td colspan="<?php echo $cols; ?>">No Themes</td>
|
3766 |
+
</tr>
|
3767 |
+
</tbody>
|
3768 |
+
<?php endif ?>
|
3769 |
+
</table>
|
3770 |
+
</div>
|
3771 |
+
</div>
|
3772 |
+
<div class="wf-block<?php echo( \wfPersistenceController::shared()->isActive( 'wf-diagnostics-wordpress-cron-jobs' ) ? ' wf-active' : '' ); ?>" data-persistence-key="<?php echo esc_attr( 'wf-diagnostics-wordpress-cron-jobs' ); ?>">
|
3773 |
+
<div class="wf-block-header">
|
3774 |
+
<div class="wf-block-header-content">
|
3775 |
+
<div class="wf-block-title">
|
3776 |
+
<strong><?php _e( 'Cron Jobs', 'wordfence' ); ?></strong>
|
3777 |
+
<span class="wf-text-small"><?php _e( 'List of WordPress cron jobs scheduled by WordPress, plugins, or themes.', 'wordfence' ); ?></span>
|
3778 |
+
</div>
|
3779 |
+
<div class="wf-block-header-action">
|
3780 |
+
<div class="wf-block-header-action-disclosure"></div>
|
3781 |
+
</div>
|
3782 |
+
</div>
|
3783 |
+
</div>
|
3784 |
+
<div class="wf-block-content wf-clearfix wf-padding-no-left wf-padding-no-right">
|
3785 |
+
<table class="wf-striped-table"<?php echo ! empty( $inEmail ) ? ' border=1' : ''; ?>>
|
3786 |
+
<tbody>
|
3787 |
+
<?php
|
3788 |
+
$cron = _get_cron_array();
|
3789 |
+
foreach ( $cron as $timestamp => $values ) {
|
3790 |
+
if ( is_array( $values ) ) {
|
3791 |
+
foreach ( $values as $cron_job => $v ) {
|
3792 |
+
if ( is_numeric( $timestamp ) ) {
|
3793 |
+
?>
|
3794 |
+
<tr>
|
3795 |
+
<td colspan="<?php echo $cols - 1; ?>"><?php echo esc_html( date( 'r', $timestamp ) ); // phpcs:ignore -- local time. ?></td>
|
3796 |
+
<td><?php echo esc_html( $cron_job ); ?></td>
|
3797 |
+
</tr>
|
3798 |
+
<?php
|
3799 |
+
}
|
3800 |
+
}
|
3801 |
+
}
|
3802 |
+
}
|
3803 |
+
?>
|
3804 |
+
</tbody>
|
3805 |
+
</table>
|
3806 |
+
</div>
|
3807 |
+
</div>
|
3808 |
+
|
3809 |
+
<?php
|
3810 |
+
|
3811 |
+
/** @global object $wpdb WordPress Database instance. */
|
3812 |
+
global $wpdb;
|
3813 |
+
|
3814 |
+
$wfdb = new \wfDB();
|
3815 |
+
// This must be done this way because MySQL with InnoDB tables does a full regeneration of all metadata if we don't. That takes a long time with a large table count.
|
3816 |
+
$tables = $wfdb->querySelect( 'SELECT SQL_CALC_FOUND_ROWS TABLE_NAME FROM information_schema.TABLES WHERE TABLE_SCHEMA=DATABASE() ORDER BY TABLE_NAME ASC LIMIT 250' );
|
3817 |
+
$total = $wfdb->querySingle( 'SELECT FOUND_ROWS()' );
|
3818 |
+
foreach ( $tables as &$t ) {
|
3819 |
+
$t = "'" . esc_sql( $t['TABLE_NAME'] ) . "'";
|
3820 |
+
}
|
3821 |
+
unset( $t );
|
3822 |
+
$q = $wfdb->querySelect( 'SHOW TABLE STATUS WHERE Name IN (' . implode( ',', $tables ) . ')' );
|
3823 |
+
if ( $q ) :
|
3824 |
+
$databaseCols = count( $q[0] );
|
3825 |
+
?>
|
3826 |
+
<div class="wf-block<?php echo( \wfPersistenceController::shared()->isActive( 'wf-diagnostics-database-tables' ) ? ' wf-active' : '' ); ?>" data-persistence-key="<?php echo esc_attr( 'wf-diagnostics-database-tables' ); ?>">
|
3827 |
+
<div class="wf-block-header">
|
3828 |
+
<div class="wf-block-header-content">
|
3829 |
+
<div class="wf-block-title">
|
3830 |
+
<strong><?php _e( 'Database Tables', 'wordfence' ); ?></strong>
|
3831 |
+
<span class="wf-text-small"><?php _e( 'Database table names, sizes, timestamps, and other metadata.', 'wordfence' ); ?></span>
|
3832 |
+
</div>
|
3833 |
+
<div class="wf-block-header-action">
|
3834 |
+
<div class="wf-block-header-action-disclosure"></div>
|
3835 |
+
</div>
|
3836 |
+
</div>
|
3837 |
+
</div>
|
3838 |
+
<div class="wf-block-content wf-clearfix wf-padding-no-left wf-padding-no-right">
|
3839 |
+
<div style="max-width: 100%; overflow: auto; padding: 1px;">
|
3840 |
+
<table class="wf-striped-table"<?php echo ! empty( $inEmail ) ? ' border=1' : ''; ?>>
|
3841 |
+
<tbody class="thead thead-subhead" style="font-size: 85%">
|
3842 |
+
<?php $val = \wfUtils::array_first( $q ); ?>
|
3843 |
+
<tr>
|
3844 |
+
<?php foreach ( $val as $tkey => $tval ) : ?>
|
3845 |
+
<th><?php echo esc_html( $tkey ); ?></th>
|
3846 |
+
<?php endforeach; ?>
|
3847 |
+
</tr>
|
3848 |
+
</tbody>
|
3849 |
+
<tbody style="font-size: 85%">
|
3850 |
+
<?php
|
3851 |
+
$count = 0;
|
3852 |
+
foreach ( $q as $val ) {
|
3853 |
+
?>
|
3854 |
+
<tr>
|
3855 |
+
<?php foreach ( $val as $tkey => $tval ) : ?>
|
3856 |
+
<td><?php echo esc_html( $tval ); ?></td>
|
3857 |
+
<?php endforeach; ?>
|
3858 |
+
</tr>
|
3859 |
+
<?php
|
3860 |
+
$count++;
|
3861 |
+
if ( $count >= 250 ) {
|
3862 |
+
?>
|
3863 |
+
<tr>
|
3864 |
+
<td colspan="<?php echo $databaseCols; ?>">and <?php echo $total - $count; ?> more</td>
|
3865 |
+
</tr>
|
3866 |
+
<?php
|
3867 |
+
break;
|
3868 |
+
}
|
3869 |
+
}
|
3870 |
+
?>
|
3871 |
+
</tbody>
|
3872 |
+
</table>
|
3873 |
+
</div>
|
3874 |
+
</div>
|
3875 |
+
</div>
|
3876 |
+
<?php endif; ?>
|
3877 |
+
<div class="wf-block<?php echo( \wfPersistenceController::shared()->isActive( 'wf-diagnostics-log-files' ) ? ' wf-active' : '' ); ?>" data-persistence-key="<?php echo esc_attr( 'wf-diagnostics-log-files' ); ?>">
|
3878 |
+
<div class="wf-block-header">
|
3879 |
+
<div class="wf-block-header-content">
|
3880 |
+
<div class="wf-block-title">
|
3881 |
+
<strong><?php _e( 'Log Files', 'wordfence' ); ?></strong>
|
3882 |
+
<span class="wf-text-small"><?php _e( 'PHP error logs generated by your site, if enabled by your host.', 'wordfence' ); ?></span>
|
3883 |
+
</div>
|
3884 |
+
<div class="wf-block-header-action">
|
3885 |
+
<div class="wf-block-header-action-disclosure"></div>
|
3886 |
+
</div>
|
3887 |
+
</div>
|
3888 |
+
</div>
|
3889 |
+
<div class="wf-block-content wf-clearfix wf-padding-no-left wf-padding-no-right">
|
3890 |
+
<div style="max-width: 100%; overflow: auto; padding: 1px;">
|
3891 |
+
<table class="wf-striped-table"<?php echo ! empty( $inEmail ) ? ' border=1' : ''; ?>>
|
3892 |
+
<tbody class="thead thead-subhead" style="font-size: 85%">
|
3893 |
+
<tr>
|
3894 |
+
<th>File</th>
|
3895 |
+
<th>Download</th>
|
3896 |
+
</tr>
|
3897 |
+
</tbody>
|
3898 |
+
<tbody style="font-size: 85%">
|
3899 |
+
<?php
|
3900 |
+
$errorLogs = \wfErrorLogHandler::getErrorLogs();
|
3901 |
+
if ( count( $errorLogs ) < 1 ) :
|
3902 |
+
?>
|
3903 |
+
<tr>
|
3904 |
+
<td colspan="2"><em>No log files found.</em></td>
|
3905 |
+
</tr>
|
3906 |
+
<?php
|
3907 |
+
else :
|
3908 |
+
foreach ( $errorLogs as $log => $readable ) :
|
3909 |
+
?>
|
3910 |
+
<tr>
|
3911 |
+
<td style="width: 100%"><?php echo esc_html( $log ) . ' (' . \wfUtils::formatBytes( filesize( $log ) ) . ')'; ?></td>
|
3912 |
+
<td style="white-space: nowrap; text-align: right;"><?php echo( $readable ? '<a href="#" data-logfile="' . esc_html( $log ) . '" class="downloadLogFile" target="_blank" rel="noopener noreferrer">Download</a>' : '<em>Requires downloading from the server directly</em>' ); ?></td>
|
3913 |
+
</tr>
|
3914 |
+
<?php
|
3915 |
+
endforeach;
|
3916 |
+
endif;
|
3917 |
+
?>
|
3918 |
+
</tbody>
|
3919 |
+
</table>
|
3920 |
+
</div>
|
3921 |
+
</div>
|
3922 |
+
</div>
|
3923 |
+
</form>
|
3924 |
+
</div>
|
3925 |
+
<script type="application/javascript">
|
3926 |
+
jQuery( document ).ready( function ( $ ) {
|
3927 |
+
$( '.wf-block-header-action-disclosure' ).each( function() {
|
3928 |
+
$( this ).closest( '.wf-block-header' ).css( 'cursor', 'pointer' );
|
3929 |
+
$( this ).closest( '.wf-block-header' ).on( 'click', function( e ) {
|
3930 |
+
// Let links in the header work.
|
3931 |
+
if ( e.target && e.target.nodeName === 'A' && e.target.href ) {
|
3932 |
+
return;
|
3933 |
+
}
|
3934 |
+
e.preventDefault();
|
3935 |
+
e.stopPropagation();
|
3936 |
+
if ( $( this ).closest( '.wf-block' ).hasClass( 'wf-disabled' ) ) {
|
3937 |
+
return;
|
3938 |
+
}
|
3939 |
+
var isActive = $( this ).closest( '.wf-block' ).hasClass( 'wf-active' );
|
3940 |
+
if ( isActive ) {
|
3941 |
+
$( this ).closest( '.wf-block' ).find( '.wf-block-content' ).slideUp( {
|
3942 |
+
always: function() {
|
3943 |
+
$( this ).closest( '.wf-block' ).removeClass( 'wf-active' );
|
3944 |
+
}
|
3945 |
+
} );
|
3946 |
+
} else {
|
3947 |
+
$( this ).closest( '.wf-block' ).find( '.wf-block-content' ).slideDown( {
|
3948 |
+
always: function() {
|
3949 |
+
$( this ).closest( '.wf-block' ).addClass( 'wf-active' );
|
3950 |
+
}
|
3951 |
+
} );
|
3952 |
+
}
|
3953 |
+
} );
|
3954 |
+
} );
|
3955 |
+
} );
|
3956 |
+
</script>
|
3957 |
+
<?php
|
3958 |
+
$html = ob_get_clean();
|
3959 |
+
return array(
|
3960 |
+
'ok' => 1,
|
3961 |
+
'html' => $html,
|
3962 |
+
);
|
3963 |
+
}
|
3964 |
+
|
3965 |
+
/**
|
3966 |
+
* Method update_waf_rules()
|
3967 |
+
*
|
3968 |
+
* Update WAF rules.
|
3969 |
+
*
|
3970 |
+
* @used-by MainWP_Child_Wordfence::actions() Fire off certain Wordfence plugin actions.
|
3971 |
+
*
|
3972 |
+
* @return array Action result.
|
3973 |
+
*/
|
3974 |
+
public static function update_waf_rules() {
|
3975 |
+
$event = new \wfWAFCronFetchRulesEvent( time() - 2 );
|
3976 |
+
$event->setWaf( \wfWAF::getInstance() );
|
3977 |
+
$event->fire();
|
3978 |
+
$isPaid = (bool) \wfConfig::get( 'isPaid', 0 );
|
3979 |
+
return array(
|
3980 |
+
'ok' => 1,
|
3981 |
+
'isPaid' => $isPaid,
|
3982 |
+
);
|
3983 |
+
}
|
3984 |
+
|
3985 |
+
/**
|
3986 |
+
* Method update_waf_rules_new()
|
3987 |
+
*
|
3988 |
+
* Update new WAF rules.
|
3989 |
+
*
|
3990 |
+
* @used-by MainWP_Child_Wordfence::actions() Fire off certain Wordfence plugin actions.
|
3991 |
+
*
|
3992 |
+
* @return array Action result.
|
3993 |
+
*/
|
3994 |
+
public static function update_waf_rules_new() {
|
3995 |
+
$event = new \wfWAFCronFetchRulesEvent( time() - 2 );
|
3996 |
+
$event->setWaf( \wfWAF::getInstance() );
|
3997 |
+
$success = $event->fire();
|
3998 |
+
|
3999 |
+
return self::get_waf_data( $success );
|
4000 |
+
}
|
4001 |
+
|
4002 |
+
/**
|
4003 |
+
* Method save_debugging_config()
|
4004 |
+
*
|
4005 |
+
* Save the debugging configuration.
|
4006 |
+
*
|
4007 |
+
* @used-by MainWP_Child_Wordfence::actions() Fire off certain Wordfence plugin actions.
|
4008 |
+
*
|
4009 |
+
* @return array Action result.
|
4010 |
+
*/
|
4011 |
+
public static function save_debugging_config() {
|
4012 |
+
$settings = isset( $_POST['settings'] ) ? wp_unslash( $_POST['settings'] ) : array();
|
4013 |
+
foreach ( self::$diagnosticParams as $param ) {
|
4014 |
+
if ( isset( $settings[ $param ] ) ) {
|
4015 |
+
\wfConfig::set( $param, $settings[ $param ] );
|
4016 |
+
}
|
4017 |
+
}
|
4018 |
+
return array( 'ok' => 1 );
|
4019 |
+
}
|
4020 |
+
}
|
|
|
|
|
|
class/class-mainwp-child.php
CHANGED
@@ -1,456 +1,456 @@
|
|
1 |
-
<?php
|
2 |
-
/**
|
3 |
-
* MainWP Child
|
4 |
-
*
|
5 |
-
* @package MainWP\Child
|
6 |
-
*/
|
7 |
-
|
8 |
-
namespace MainWP\Child;
|
9 |
-
|
10 |
-
// phpcs:disable -- required for debugging.
|
11 |
-
if ( isset( $_REQUEST['mainwpsignature'] ) ) {
|
12 |
-
// if not debug.
|
13 |
-
if ( ! defined('MAINWP_CHILD_DEBUG') || false == MAINWP_CHILD_DEBUG ) {
|
14 |
-
ini_set( 'display_errors', false );
|
15 |
-
error_reporting( 0 );
|
16 |
-
}
|
17 |
-
}
|
18 |
-
|
19 |
-
// phpcs:enable
|
20 |
-
|
21 |
-
require_once ABSPATH . '/wp-admin/includes/file.php';
|
22 |
-
require_once ABSPATH . '/wp-admin/includes/plugin.php';
|
23 |
-
|
24 |
-
/**
|
25 |
-
* Class MainWP_Child
|
26 |
-
*
|
27 |
-
* Manage all MainWP features.
|
28 |
-
*/
|
29 |
-
class MainWP_Child {
|
30 |
-
|
31 |
-
/**
|
32 |
-
* Public static variable containing the latest MainWP Child plugin version.
|
33 |
-
*
|
34 |
-
* @var string MainWP Child plugin version.
|
35 |
-
*/
|
36 |
-
public static $version = '4.1.
|
37 |
-
|
38 |
-
/**
|
39 |
-
* Private variable containing the latest MainWP Child update version.
|
40 |
-
*
|
41 |
-
* @var string MainWP Child update version.
|
42 |
-
*/
|
43 |
-
private $update_version = '1.5';
|
44 |
-
|
45 |
-
/**
|
46 |
-
* Public variable containing the MainWP Child plugin slug.
|
47 |
-
*
|
48 |
-
* @var string MainWP Child plugin slug.
|
49 |
-
*/
|
50 |
-
public $plugin_slug;
|
51 |
-
|
52 |
-
/**
|
53 |
-
* Private variable containing the MainWP Child plugin directory.
|
54 |
-
*
|
55 |
-
* @var string MainWP Child plugin directory.
|
56 |
-
*/
|
57 |
-
private $plugin_dir;
|
58 |
-
|
59 |
-
/**
|
60 |
-
* MainWP_Child constructor.
|
61 |
-
*
|
62 |
-
* Run any time class is called.
|
63 |
-
*
|
64 |
-
* @param resource $plugin_file MainWP Child plugin file.
|
65 |
-
*
|
66 |
-
* @uses \MainWP\Child\MainWP_Child_Branding::save_branding_options()
|
67 |
-
* @uses \MainWP\Child\MainWP_Child_Plugins_Check::instance()
|
68 |
-
* @uses \MainWP\Child\MainWP_Child_Server_Information::init()
|
69 |
-
* @uses \MainWP\Child\MainWP_Child_Themes_Check::instance()
|
70 |
-
* @uses \MainWP\Child\MainWP_Child_Updates::get_instance()
|
71 |
-
* @uses \MainWP\Child\MainWP_Client_Report::init()
|
72 |
-
* @uses \MainWP\Child\MainWP_Clone::init()
|
73 |
-
* @uses \MainWP\Child\MainWP_Connect::check_other_auth()
|
74 |
-
* @uses \MainWP\Child\MainWP_Pages::init()
|
75 |
-
* @uses \MainWP\Child\MainWP_Helper::update_option()
|
76 |
-
* @uses \MainWP\Child\MainWP_Utility::run_saved_snippets()
|
77 |
-
* @uses \MainWP\Child\MainWP_Utility::get_class_name()
|
78 |
-
*/
|
79 |
-
public function __construct( $plugin_file ) {
|
80 |
-
$this->update();
|
81 |
-
$this->load_all_options();
|
82 |
-
|
83 |
-
$this->plugin_slug = plugin_basename( $plugin_file );
|
84 |
-
|
85 |
-
add_action( 'template_redirect', array( $this, 'template_redirect' ) );
|
86 |
-
add_action( 'init', array( &$this, 'init_check_login' ), 1 );
|
87 |
-
add_action( 'init', array( &$this, 'parse_init' ), 9999 );
|
88 |
-
add_action( 'init', array( &$this, 'localization' ), 33 );
|
89 |
-
add_action( 'admin_init', array( &$this, 'admin_init' ) );
|
90 |
-
|
91 |
-
// support for better detection for premium plugins.
|
92 |
-
add_action( 'pre_current_active_plugins', array( MainWP_Child_Updates::get_instance(), 'detect_premium_themesplugins_updates' ) );
|
93 |
-
|
94 |
-
// support for better detection for premium themes.
|
95 |
-
add_action( 'core_upgrade_preamble', array( MainWP_Child_Updates::get_instance(), 'detect_premium_themesplugins_updates' ) );
|
96 |
-
|
97 |
-
MainWP_Pages::get_instance()->init();
|
98 |
-
|
99 |
-
if ( is_admin() ) {
|
100 |
-
MainWP_Helper::update_option( 'mainwp_child_plugin_version', self::$version, 'yes' );
|
101 |
-
}
|
102 |
-
|
103 |
-
MainWP_Connect::instance()->check_other_auth();
|
104 |
-
|
105 |
-
MainWP_Clone::instance()->init();
|
106 |
-
MainWP_Child_Server_Information::init();
|
107 |
-
MainWP_Client_Report::instance()->init();
|
108 |
-
MainWP_Child_Plugins_Check::instance();
|
109 |
-
MainWP_Child_Themes_Check::instance();
|
110 |
-
MainWP_Utility::instance()->run_saved_snippets();
|
111 |
-
|
112 |
-
if ( ! get_option( 'mainwp_child_pubkey' ) ) {
|
113 |
-
MainWP_Child_Branding::instance()->save_branding_options( 'branding_disconnected', 'yes' );
|
114 |
-
}
|
115 |
-
|
116 |
-
if ( defined( 'DOING_CRON' ) && DOING_CRON ) {
|
117 |
-
if ( isset( $_GET['mainwp_child_run'] ) && ! empty( $_GET['mainwp_child_run'] ) ) {
|
118 |
-
add_action( 'init', array( MainWP_Utility::get_class_name(), 'cron_active' ), PHP_INT_MAX );
|
119 |
-
}
|
120 |
-
}
|
121 |
-
}
|
122 |
-
|
123 |
-
/**
|
124 |
-
* Method load_all_options()
|
125 |
-
*
|
126 |
-
* Load all MainWP Child plugin options.
|
127 |
-
*
|
128 |
-
* @return array|bool Return array of options or false on failure.
|
129 |
-
*/
|
130 |
-
public function load_all_options() {
|
131 |
-
|
132 |
-
/**
|
133 |
-
* WP Database object.
|
134 |
-
*
|
135 |
-
* @global object $wpdb WordPress object.
|
136 |
-
*/
|
137 |
-
global $wpdb;
|
138 |
-
|
139 |
-
if ( ! defined( 'WP_INSTALLING' ) || ! is_multisite() ) {
|
140 |
-
$alloptions = wp_cache_get( 'alloptions', 'options' );
|
141 |
-
} else {
|
142 |
-
$alloptions = false;
|
143 |
-
}
|
144 |
-
|
145 |
-
if ( ! defined( 'WP_INSTALLING' ) || ! is_multisite() ) {
|
146 |
-
$notoptions = wp_cache_get( 'notoptions', 'options' );
|
147 |
-
} else {
|
148 |
-
$notoptions = false;
|
149 |
-
}
|
150 |
-
|
151 |
-
if ( ! isset( $alloptions['mainwp_child_server'] ) ) {
|
152 |
-
$suppress = $wpdb->suppress_errors();
|
153 |
-
$options = array(
|
154 |
-
'mainwp_child_auth',
|
155 |
-
'mainwp_child_reports_db',
|
156 |
-
'mainwp_child_pluginDir',
|
157 |
-
'mainwp_updraftplus_hide_plugin',
|
158 |
-
'mainwp_backwpup_ext_enabled',
|
159 |
-
'mainwp_child_server',
|
160 |
-
'mainwp_pagespeed_hide_plugin',
|
161 |
-
'mainwp_child_clone_permalink',
|
162 |
-
'mainwp_child_restore_permalink',
|
163 |
-
'mainwp_ext_snippets_enabled',
|
164 |
-
'mainwp_child_pubkey',
|
165 |
-
'mainwp_child_nossl',
|
166 |
-
'mainwp_security',
|
167 |
-
'mainwp_backupwordpress_ext_enabled',
|
168 |
-
'mainwp_pagespeed_ext_enabled',
|
169 |
-
'mainwp_linkschecker_ext_enabled',
|
170 |
-
'mainwp_child_branding_settings',
|
171 |
-
'mainwp_child_plugintheme_days_outdate',
|
172 |
-
'mainwp_wp_staging_ext_enabled',
|
173 |
-
);
|
174 |
-
$query = "SELECT option_name, option_value FROM $wpdb->options WHERE option_name in (";
|
175 |
-
foreach ( $options as $option ) {
|
176 |
-
$query .= "'" . $option . "', ";
|
177 |
-
}
|
178 |
-
$query = substr( $query, 0, strlen( $query ) - 2 );
|
179 |
-
$query .= ")"; // phpcs:ignore -- simple style problem.
|
180 |
-
|
181 |
-
$alloptions_db = $wpdb->get_results( $query ); // phpcs:ignore -- safe query, required to achieve desired results, pull request solutions appreciated.
|
182 |
-
$wpdb->suppress_errors( $suppress );
|
183 |
-
if ( ! is_array( $alloptions ) ) {
|
184 |
-
$alloptions = array();
|
185 |
-
}
|
186 |
-
if ( is_array( $alloptions_db ) ) {
|
187 |
-
foreach ( (array) $alloptions_db as $o ) {
|
188 |
-
$alloptions[ $o->option_name ] = $o->option_value;
|
189 |
-
unset( $options[ array_search( $o->option_name, $options ) ] );
|
190 |
-
}
|
191 |
-
foreach ( $options as $option ) {
|
192 |
-
$notoptions[ $option ] = true;
|
193 |
-
}
|
194 |
-
if ( ! defined( 'WP_INSTALLING' ) || ! is_multisite() ) {
|
195 |
-
wp_cache_set( 'alloptions', $alloptions, 'options' );
|
196 |
-
wp_cache_set( 'notoptions', $notoptions, 'options' );
|
197 |
-
}
|
198 |
-
}
|
199 |
-
}
|
200 |
-
|
201 |
-
return $alloptions;
|
202 |
-
}
|
203 |
-
|
204 |
-
/**
|
205 |
-
* Method update()
|
206 |
-
*
|
207 |
-
* Update the MainWP Child plugin version (mainwp_child_update_version) option.
|
208 |
-
*
|
209 |
-
* @return void
|
210 |
-
*
|
211 |
-
* @uses \MainWP\Child\MainWP_Helper::update_option()
|
212 |
-
*/
|
213 |
-
public function update() {
|
214 |
-
$update_version = get_option( 'mainwp_child_update_version' );
|
215 |
-
|
216 |
-
if ( $update_version === $this->update_version ) {
|
217 |
-
return;
|
218 |
-
}
|
219 |
-
|
220 |
-
MainWP_Helper::update_option( 'mainwp_child_update_version', $this->update_version, 'yes' );
|
221 |
-
}
|
222 |
-
|
223 |
-
/**
|
224 |
-
* Method localization()
|
225 |
-
*
|
226 |
-
* Load the MainWP Child plugin textdomains.
|
227 |
-
*/
|
228 |
-
public function localization() {
|
229 |
-
load_plugin_textdomain( 'mainwp-child', false, dirname( dirname( plugin_basename( __FILE__ ) ) ) . '/languages/' );
|
230 |
-
}
|
231 |
-
|
232 |
-
/**
|
233 |
-
* Method template_redirect()
|
234 |
-
*
|
235 |
-
* Handle the template redirect for 404 maintenance alerts.
|
236 |
-
*
|
237 |
-
* @uses \MainWP\Child\MainWP_Utility::maintenance_alert()
|
238 |
-
*/
|
239 |
-
public function template_redirect() {
|
240 |
-
MainWP_Utility::instance()->maintenance_alert();
|
241 |
-
}
|
242 |
-
|
243 |
-
/**
|
244 |
-
* Method parse_init()
|
245 |
-
*
|
246 |
-
* Parse the init hook.
|
247 |
-
*
|
248 |
-
* @return void
|
249 |
-
*
|
250 |
-
* @uses \MainWP\Child\MainWP_Child_Callable::init_call_functions()
|
251 |
-
* @uses \MainWP\Child\MainWP_Clone::request_clone_funct()
|
252 |
-
* @uses \MainWP\Child\MainWP_Connect::parse_login_required()
|
253 |
-
* @uses \MainWP\Child\MainWP_Connect::register_site()
|
254 |
-
* @uses \MainWP\Child\MainWP_Connect::auth()
|
255 |
-
* @uses \MainWP\Child\MainWP_Connect::parse_init_auth()
|
256 |
-
* @uses \MainWP\Child\MainWP_Security::fix_all()
|
257 |
-
* @uses \MainWP\Child\MainWP_Utility::fix_for_custom_themes()
|
258 |
-
*/
|
259 |
-
public function parse_init() {
|
260 |
-
|
261 |
-
if ( isset( $_REQUEST['cloneFunc'] ) ) {
|
262 |
-
$valid_clone = MainWP_Clone::instance()->request_clone_funct();
|
263 |
-
if ( ! $valid_clone ) {
|
264 |
-
return;
|
265 |
-
}
|
266 |
-
}
|
267 |
-
|
268 |
-
// if login required.
|
269 |
-
if ( isset( $_REQUEST['login_required'] ) && ( '1' === $_REQUEST['login_required'] ) && isset( $_REQUEST['user'] ) ) {
|
270 |
-
$valid_login_required = MainWP_Connect::instance()->parse_login_required();
|
271 |
-
// return if login required are not valid, if login is valid will redirect to admin side.
|
272 |
-
if ( ! $valid_login_required ) {
|
273 |
-
return;
|
274 |
-
}
|
275 |
-
}
|
276 |
-
|
277 |
-
MainWP_Security::fix_all();
|
278 |
-
|
279 |
-
// Register does not require auth, so we register here.
|
280 |
-
if ( isset( $_POST['function'] ) && 'register' === $_POST['function'] ) {
|
281 |
-
|
282 |
-
/**
|
283 |
-
* Checks whether cron is in progress.
|
284 |
-
*
|
285 |
-
* @const ( bool ) Default: true
|
286 |
-
* @source https://code-reference.mainwp.com/classes/MainWP.Child.MainWP_Child.html
|
287 |
-
*/
|
288 |
-
define( 'DOING_CRON', true );
|
289 |
-
|
290 |
-
MainWP_Utility::fix_for_custom_themes();
|
291 |
-
MainWP_Connect::instance()->register_site(); // register the site and exit.
|
292 |
-
}
|
293 |
-
|
294 |
-
$mainwpsignature = isset( $_POST['mainwpsignature'] ) ? rawurldecode( wp_unslash( $_POST['mainwpsignature'] ) ) : '';
|
295 |
-
$function = isset( $_POST['function'] ) ? sanitize_text_field( wp_unslash( $_POST['function'] ) ) : null;
|
296 |
-
$nonce = isset( $_POST['nonce'] ) ? sanitize_text_field( wp_unslash( $_POST['nonce'] ) ) : '';
|
297 |
-
$nossl = isset( $_POST['nossl'] ) ? sanitize_text_field( wp_unslash( $_POST['nossl'] ) ) : 0;
|
298 |
-
|
299 |
-
// Authenticate here.
|
300 |
-
$auth = MainWP_Connect::instance()->auth( $mainwpsignature, $function, $nonce, $nossl );
|
301 |
-
|
302 |
-
// Parse auth, if it is not correct actions then exit with message or return.
|
303 |
-
if ( ! MainWP_Connect::instance()->parse_init_auth( $auth ) ) {
|
304 |
-
return;
|
305 |
-
}
|
306 |
-
|
307 |
-
$this->parse_init_extensions();
|
308 |
-
|
309 |
-
/**
|
310 |
-
* WordPress submenu no privilege.
|
311 |
-
*
|
312 |
-
* @global string
|
313 |
-
*/
|
314 |
-
global $_wp_submenu_nopriv;
|
315 |
-
|
316 |
-
if ( null === $_wp_submenu_nopriv ) {
|
317 |
-
$_wp_submenu_nopriv = array(); // phpcs:ignore -- Required to fix warnings, pull request solutions appreciated.
|
318 |
-
}
|
319 |
-
|
320 |
-
// execute callable functions here.
|
321 |
-
MainWP_Child_Callable::get_instance()->init_call_functions( $auth );
|
322 |
-
}
|
323 |
-
|
324 |
-
/**
|
325 |
-
* Method init_check_login()
|
326 |
-
*
|
327 |
-
* Initiate the check login process.
|
328 |
-
*
|
329 |
-
* @uses MainWP_Connect::check_login()
|
330 |
-
*/
|
331 |
-
public function init_check_login() {
|
332 |
-
MainWP_Connect::instance()->check_login();
|
333 |
-
}
|
334 |
-
|
335 |
-
/**
|
336 |
-
* Method admin_init()
|
337 |
-
*
|
338 |
-
* If the current user is administrator initiate the admin ajax.
|
339 |
-
*
|
340 |
-
* @uses \MainWP\Child\MainWP_Clone::init_ajax()
|
341 |
-
* @uses \MainWP\Child\MainWP_Helper::is_admin()
|
342 |
-
*/
|
343 |
-
public function admin_init() {
|
344 |
-
if ( MainWP_Helper::is_admin() && is_admin() ) {
|
345 |
-
MainWP_Clone::instance()->init_ajax();
|
346 |
-
}
|
347 |
-
}
|
348 |
-
|
349 |
-
/**
|
350 |
-
* Method parse_init_extensions()
|
351 |
-
*
|
352 |
-
* Parse MainWP Extension initiations.
|
353 |
-
*
|
354 |
-
* @uses \MainWP\Child\MainWP_Child_Branding::branding_init()
|
355 |
-
* @uses \MainWP\Child\MainWP_Client_Report::creport_init()
|
356 |
-
* @uses \MainWP\Child\MainWP_Child_IThemes_Security::ithemes_init()
|
357 |
-
* @uses \MainWP\Child\MainWP_Child_Updraft_Plus_Backups::updraftplus_init()
|
358 |
-
* @uses \MainWP\Child\MainWP_Child_Back_Up_WordPress::init()
|
359 |
-
* @uses \MainWP\Child\MainWP_Child_WP_Rocket::init()
|
360 |
-
* @uses \MainWP\Child\MainWP_Child_Back_WP_Up::init()
|
361 |
-
* @uses \MainWP\Child\MainWP_Child_Back_Up_Buddy::instance()
|
362 |
-
* @uses \MainWP\Child\MainWP_Child_Wordfence::wordfence_init()
|
363 |
-
* @uses \MainWP\Child\MainWP_Child_Timecapsule::init()
|
364 |
-
* @uses \MainWP\Child\MainWP_Child_Staging::init()
|
365 |
-
* @uses \MainWP\Child\MainWP_Child_Pagespeed::init()
|
366 |
-
* @uses \MainWP\Child\MainWP_Child_Links_Checker::init()
|
367 |
-
* @uses \MainWP\Child\MainWP_Child_WPvivid_BackupRestore::init()
|
368 |
-
*/
|
369 |
-
private function parse_init_extensions() {
|
370 |
-
MainWP_Child_Branding::instance()->branding_init();
|
371 |
-
MainWP_Client_Report::instance()->creport_init();
|
372 |
-
MainWP_Child_IThemes_Security::instance()->ithemes_init();
|
373 |
-
MainWP_Child_Updraft_Plus_Backups::instance()->updraftplus_init();
|
374 |
-
MainWP_Child_Back_Up_WordPress::instance()->init();
|
375 |
-
MainWP_Child_WP_Rocket::instance()->init();
|
376 |
-
MainWP_Child_Back_WP_Up::instance()->init();
|
377 |
-
MainWP_Child_Back_Up_Buddy::instance();
|
378 |
-
MainWP_Child_Wordfence::instance()->wordfence_init();
|
379 |
-
MainWP_Child_Timecapsule::instance()->init();
|
380 |
-
MainWP_Child_Staging::instance()->init();
|
381 |
-
MainWP_Child_Pagespeed::instance()->init();
|
382 |
-
MainWP_Child_Links_Checker::instance()->init();
|
383 |
-
MainWP_Child_WPvivid_BackupRestore::instance()->init();
|
384 |
-
}
|
385 |
-
|
386 |
-
/**
|
387 |
-
* Method deactivation()
|
388 |
-
*
|
389 |
-
* Deactivate the MainWP Child plugin and delete unwanted data.
|
390 |
-
*
|
391 |
-
* @param bool $deact Whether or not to deactivate pugin. Default: true.
|
392 |
-
*/
|
393 |
-
public function deactivation( $deact = true ) {
|
394 |
-
|
395 |
-
$mu_plugin_enabled = apply_filters( 'mainwp_child_mu_plugin_enabled', false );
|
396 |
-
if ( $mu_plugin_enabled ) {
|
397 |
-
return;
|
398 |
-
}
|
399 |
-
|
400 |
-
$to_delete = array(
|
401 |
-
'mainwp_child_pubkey',
|
402 |
-
'mainwp_child_nonce',
|
403 |
-
'mainwp_child_nossl',
|
404 |
-
'mainwp_child_nossl_key',
|
405 |
-
'mainwp_security',
|
406 |
-
'mainwp_child_server',
|
407 |
-
);
|
408 |
-
$to_delete[] = 'mainwp_ext_snippets_enabled';
|
409 |
-
$to_delete[] = 'mainwp_ext_code_snippets';
|
410 |
-
|
411 |
-
foreach ( $to_delete as $delete ) {
|
412 |
-
if ( get_option( $delete ) ) {
|
413 |
-
delete_option( $delete );
|
414 |
-
wp_cache_delete( $delete, 'options' );
|
415 |
-
}
|
416 |
-
}
|
417 |
-
|
418 |
-
if ( $deact ) {
|
419 |
-
do_action( 'mainwp_child_deactivation' );
|
420 |
-
}
|
421 |
-
}
|
422 |
-
|
423 |
-
/**
|
424 |
-
* Method activation()
|
425 |
-
*
|
426 |
-
* Activate the MainWP Child plugin and delete unwanted data.
|
427 |
-
*
|
428 |
-
* @uses \MainWP\Child\MainWP_Helper::update_option()
|
429 |
-
*/
|
430 |
-
public function activation() {
|
431 |
-
$mu_plugin_enabled = apply_filters( 'mainwp_child_mu_plugin_enabled', false );
|
432 |
-
if ( $mu_plugin_enabled ) {
|
433 |
-
return;
|
434 |
-
}
|
435 |
-
|
436 |
-
$to_delete = array(
|
437 |
-
'mainwp_child_pubkey',
|
438 |
-
'mainwp_child_nonce',
|
439 |
-
'mainwp_child_nossl',
|
440 |
-
'mainwp_child_nossl_key',
|
441 |
-
);
|
442 |
-
foreach ( $to_delete as $delete ) {
|
443 |
-
if ( get_option( $delete ) ) {
|
444 |
-
delete_option( $delete );
|
445 |
-
}
|
446 |
-
}
|
447 |
-
|
448 |
-
MainWP_Helper::update_option( 'mainwp_child_activated_once', true );
|
449 |
-
|
450 |
-
$to_delete = array( 'mainwp_ext_snippets_enabled', 'mainwp_ext_code_snippets' );
|
451 |
-
foreach ( $to_delete as $delete ) {
|
452 |
-
delete_option( $delete );
|
453 |
-
}
|
454 |
-
}
|
455 |
-
|
456 |
-
}
|
1 |
+
<?php
|
2 |
+
/**
|
3 |
+
* MainWP Child
|
4 |
+
*
|
5 |
+
* @package MainWP\Child
|
6 |
+
*/
|
7 |
+
|
8 |
+
namespace MainWP\Child;
|
9 |
+
|
10 |
+
// phpcs:disable -- required for debugging.
|
11 |
+
if ( isset( $_REQUEST['mainwpsignature'] ) ) {
|
12 |
+
// if not debug.
|
13 |
+
if ( ! defined('MAINWP_CHILD_DEBUG') || false == MAINWP_CHILD_DEBUG ) {
|
14 |
+
ini_set( 'display_errors', false );
|
15 |
+
error_reporting( 0 );
|
16 |
+
}
|
17 |
+
}
|
18 |
+
|
19 |
+
// phpcs:enable
|
20 |
+
|
21 |
+
require_once ABSPATH . '/wp-admin/includes/file.php';
|
22 |
+
require_once ABSPATH . '/wp-admin/includes/plugin.php';
|
23 |
+
|
24 |
+
/**
|
25 |
+
* Class MainWP_Child
|
26 |
+
*
|
27 |
+
* Manage all MainWP features.
|
28 |
+
*/
|
29 |
+
class MainWP_Child {
|
30 |
+
|
31 |
+
/**
|
32 |
+
* Public static variable containing the latest MainWP Child plugin version.
|
33 |
+
*
|
34 |
+
* @var string MainWP Child plugin version.
|
35 |
+
*/
|
36 |
+
public static $version = '4.1.10';
|
37 |
+
|
38 |
+
/**
|
39 |
+
* Private variable containing the latest MainWP Child update version.
|
40 |
+
*
|
41 |
+
* @var string MainWP Child update version.
|
42 |
+
*/
|
43 |
+
private $update_version = '1.5';
|
44 |
+
|
45 |
+
/**
|
46 |
+
* Public variable containing the MainWP Child plugin slug.
|
47 |
+
*
|
48 |
+
* @var string MainWP Child plugin slug.
|
49 |
+
*/
|
50 |
+
public $plugin_slug;
|
51 |
+
|
52 |
+
/**
|
53 |
+
* Private variable containing the MainWP Child plugin directory.
|
54 |
+
*
|
55 |
+
* @var string MainWP Child plugin directory.
|
56 |
+
*/
|
57 |
+
private $plugin_dir;
|
58 |
+
|
59 |
+
/**
|
60 |
+
* MainWP_Child constructor.
|
61 |
+
*
|
62 |
+
* Run any time class is called.
|
63 |
+
*
|
64 |
+
* @param resource $plugin_file MainWP Child plugin file.
|
65 |
+
*
|
66 |
+
* @uses \MainWP\Child\MainWP_Child_Branding::save_branding_options()
|
67 |
+
* @uses \MainWP\Child\MainWP_Child_Plugins_Check::instance()
|
68 |
+
* @uses \MainWP\Child\MainWP_Child_Server_Information::init()
|
69 |
+
* @uses \MainWP\Child\MainWP_Child_Themes_Check::instance()
|
70 |
+
* @uses \MainWP\Child\MainWP_Child_Updates::get_instance()
|
71 |
+
* @uses \MainWP\Child\MainWP_Client_Report::init()
|
72 |
+
* @uses \MainWP\Child\MainWP_Clone::init()
|
73 |
+
* @uses \MainWP\Child\MainWP_Connect::check_other_auth()
|
74 |
+
* @uses \MainWP\Child\MainWP_Pages::init()
|
75 |
+
* @uses \MainWP\Child\MainWP_Helper::update_option()
|
76 |
+
* @uses \MainWP\Child\MainWP_Utility::run_saved_snippets()
|
77 |
+
* @uses \MainWP\Child\MainWP_Utility::get_class_name()
|
78 |
+
*/
|
79 |
+
public function __construct( $plugin_file ) {
|
80 |
+
$this->update();
|
81 |
+
$this->load_all_options();
|
82 |
+
|
83 |
+
$this->plugin_slug = plugin_basename( $plugin_file );
|
84 |
+
|
85 |
+
add_action( 'template_redirect', array( $this, 'template_redirect' ) );
|
86 |
+
add_action( 'init', array( &$this, 'init_check_login' ), 1 );
|
87 |
+
add_action( 'init', array( &$this, 'parse_init' ), 9999 );
|
88 |
+
add_action( 'init', array( &$this, 'localization' ), 33 );
|
89 |
+
add_action( 'admin_init', array( &$this, 'admin_init' ) );
|
90 |
+
|
91 |
+
// support for better detection for premium plugins.
|
92 |
+
add_action( 'pre_current_active_plugins', array( MainWP_Child_Updates::get_instance(), 'detect_premium_themesplugins_updates' ) );
|
93 |
+
|
94 |
+
// support for better detection for premium themes.
|
95 |
+
add_action( 'core_upgrade_preamble', array( MainWP_Child_Updates::get_instance(), 'detect_premium_themesplugins_updates' ) );
|
96 |
+
|
97 |
+
MainWP_Pages::get_instance()->init();
|
98 |
+
|
99 |
+
if ( is_admin() ) {
|
100 |
+
MainWP_Helper::update_option( 'mainwp_child_plugin_version', self::$version, 'yes' );
|
101 |
+
}
|
102 |
+
|
103 |
+
MainWP_Connect::instance()->check_other_auth();
|
104 |
+
|
105 |
+
MainWP_Clone::instance()->init();
|
106 |
+
MainWP_Child_Server_Information::init();
|
107 |
+
MainWP_Client_Report::instance()->init();
|
108 |
+
MainWP_Child_Plugins_Check::instance();
|
109 |
+
MainWP_Child_Themes_Check::instance();
|
110 |
+
MainWP_Utility::instance()->run_saved_snippets();
|
111 |
+
|
112 |
+
if ( ! get_option( 'mainwp_child_pubkey' ) ) {
|
113 |
+
MainWP_Child_Branding::instance()->save_branding_options( 'branding_disconnected', 'yes' );
|
114 |
+
}
|
115 |
+
|
116 |
+
if ( defined( 'DOING_CRON' ) && DOING_CRON ) {
|
117 |
+
if ( isset( $_GET['mainwp_child_run'] ) && ! empty( $_GET['mainwp_child_run'] ) ) {
|
118 |
+
add_action( 'init', array( MainWP_Utility::get_class_name(), 'cron_active' ), PHP_INT_MAX );
|
119 |
+
}
|
120 |
+
}
|
121 |
+
}
|
122 |
+
|
123 |
+
/**
|
124 |
+
* Method load_all_options()
|
125 |
+
*
|
126 |
+
* Load all MainWP Child plugin options.
|
127 |
+
*
|
128 |
+
* @return array|bool Return array of options or false on failure.
|
129 |
+
*/
|
130 |
+
public function load_all_options() {
|
131 |
+
|
132 |
+
/**
|
133 |
+
* WP Database object.
|
134 |
+
*
|
135 |
+
* @global object $wpdb WordPress object.
|
136 |
+
*/
|
137 |
+
global $wpdb;
|
138 |
+
|
139 |
+
if ( ! defined( 'WP_INSTALLING' ) || ! is_multisite() ) {
|
140 |
+
$alloptions = wp_cache_get( 'alloptions', 'options' );
|
141 |
+
} else {
|
142 |
+
$alloptions = false;
|
143 |
+
}
|
144 |
+
|
145 |
+
if ( ! defined( 'WP_INSTALLING' ) || ! is_multisite() ) {
|
146 |
+
$notoptions = wp_cache_get( 'notoptions', 'options' );
|
147 |
+
} else {
|
148 |
+
$notoptions = false;
|
149 |
+
}
|
150 |
+
|
151 |
+
if ( ! isset( $alloptions['mainwp_child_server'] ) ) {
|
152 |
+
$suppress = $wpdb->suppress_errors();
|
153 |
+
$options = array(
|
154 |
+
'mainwp_child_auth',
|
155 |
+
'mainwp_child_reports_db',
|
156 |
+
'mainwp_child_pluginDir',
|
157 |
+
'mainwp_updraftplus_hide_plugin',
|
158 |
+
'mainwp_backwpup_ext_enabled',
|
159 |
+
'mainwp_child_server',
|
160 |
+
'mainwp_pagespeed_hide_plugin',
|
161 |
+
'mainwp_child_clone_permalink',
|
162 |
+
'mainwp_child_restore_permalink',
|
163 |
+
'mainwp_ext_snippets_enabled',
|
164 |
+
'mainwp_child_pubkey',
|
165 |
+
'mainwp_child_nossl',
|
166 |
+
'mainwp_security',
|
167 |
+
'mainwp_backupwordpress_ext_enabled',
|
168 |
+
'mainwp_pagespeed_ext_enabled',
|
169 |
+
'mainwp_linkschecker_ext_enabled',
|
170 |
+
'mainwp_child_branding_settings',
|
171 |
+
'mainwp_child_plugintheme_days_outdate',
|
172 |
+
'mainwp_wp_staging_ext_enabled',
|
173 |
+
);
|
174 |
+
$query = "SELECT option_name, option_value FROM $wpdb->options WHERE option_name in (";
|
175 |
+
foreach ( $options as $option ) {
|
176 |
+
$query .= "'" . $option . "', ";
|
177 |
+
}
|
178 |
+
$query = substr( $query, 0, strlen( $query ) - 2 );
|
179 |
+
$query .= ")"; // phpcs:ignore -- simple style problem.
|
180 |
+
|
181 |
+
$alloptions_db = $wpdb->get_results( $query ); // phpcs:ignore -- safe query, required to achieve desired results, pull request solutions appreciated.
|
182 |
+
$wpdb->suppress_errors( $suppress );
|
183 |
+
if ( ! is_array( $alloptions ) ) {
|
184 |
+
$alloptions = array();
|
185 |
+
}
|
186 |
+
if ( is_array( $alloptions_db ) ) {
|
187 |
+
foreach ( (array) $alloptions_db as $o ) {
|
188 |
+
$alloptions[ $o->option_name ] = $o->option_value;
|
189 |
+
unset( $options[ array_search( $o->option_name, $options ) ] );
|
190 |
+
}
|
191 |
+
foreach ( $options as $option ) {
|
192 |
+
$notoptions[ $option ] = true;
|
193 |
+
}
|
194 |
+
if ( ! defined( 'WP_INSTALLING' ) || ! is_multisite() ) {
|
195 |
+
wp_cache_set( 'alloptions', $alloptions, 'options' );
|
196 |
+
wp_cache_set( 'notoptions', $notoptions, 'options' );
|
197 |
+
}
|
198 |
+
}
|
199 |
+
}
|
200 |
+
|
201 |
+
return $alloptions;
|
202 |
+
}
|
203 |
+
|
204 |
+
/**
|
205 |
+
* Method update()
|
206 |
+
*
|
207 |
+
* Update the MainWP Child plugin version (mainwp_child_update_version) option.
|
208 |
+
*
|
209 |
+
* @return void
|
210 |
+
*
|
211 |
+
* @uses \MainWP\Child\MainWP_Helper::update_option()
|
212 |
+
*/
|
213 |
+
public function update() {
|
214 |
+
$update_version = get_option( 'mainwp_child_update_version' );
|
215 |
+
|
216 |
+
if ( $update_version === $this->update_version ) {
|
217 |
+
return;
|
218 |
+
}
|
219 |
+
|
220 |
+
MainWP_Helper::update_option( 'mainwp_child_update_version', $this->update_version, 'yes' );
|
221 |
+
}
|
222 |
+
|
223 |
+
/**
|
224 |
+
* Method localization()
|
225 |
+
*
|
226 |
+
* Load the MainWP Child plugin textdomains.
|
227 |
+
*/
|
228 |
+
public function localization() {
|
229 |
+
load_plugin_textdomain( 'mainwp-child', false, dirname( dirname( plugin_basename( __FILE__ ) ) ) . '/languages/' );
|
230 |
+
}
|
231 |
+
|
232 |
+
/**
|
233 |
+
* Method template_redirect()
|
234 |
+
*
|
235 |
+
* Handle the template redirect for 404 maintenance alerts.
|
236 |
+
*
|
237 |
+
* @uses \MainWP\Child\MainWP_Utility::maintenance_alert()
|
238 |
+
*/
|
239 |
+
public function template_redirect() {
|
240 |
+
MainWP_Utility::instance()->maintenance_alert();
|
241 |
+
}
|
242 |
+
|
243 |
+
/**
|
244 |
+
* Method parse_init()
|
245 |
+
*
|
246 |
+
* Parse the init hook.
|
247 |
+
*
|
248 |
+
* @return void
|
249 |
+
*
|
250 |
+
* @uses \MainWP\Child\MainWP_Child_Callable::init_call_functions()
|
251 |
+
* @uses \MainWP\Child\MainWP_Clone::request_clone_funct()
|
252 |
+
* @uses \MainWP\Child\MainWP_Connect::parse_login_required()
|
253 |
+
* @uses \MainWP\Child\MainWP_Connect::register_site()
|
254 |
+
* @uses \MainWP\Child\MainWP_Connect::auth()
|
255 |
+
* @uses \MainWP\Child\MainWP_Connect::parse_init_auth()
|
256 |
+
* @uses \MainWP\Child\MainWP_Security::fix_all()
|
257 |
+
* @uses \MainWP\Child\MainWP_Utility::fix_for_custom_themes()
|
258 |
+
*/
|
259 |
+
public function parse_init() {
|
260 |
+
|
261 |
+
if ( isset( $_REQUEST['cloneFunc'] ) ) {
|
262 |
+
$valid_clone = MainWP_Clone::instance()->request_clone_funct();
|
263 |
+
if ( ! $valid_clone ) {
|
264 |
+
return;
|
265 |
+
}
|
266 |
+
}
|
267 |
+
|
268 |
+
// if login required.
|
269 |
+
if ( isset( $_REQUEST['login_required'] ) && ( '1' === $_REQUEST['login_required'] ) && isset( $_REQUEST['user'] ) ) {
|
270 |
+
$valid_login_required = MainWP_Connect::instance()->parse_login_required();
|
271 |
+
// return if login required are not valid, if login is valid will redirect to admin side.
|
272 |
+
if ( ! $valid_login_required ) {
|
273 |
+
return;
|
274 |
+
}
|
275 |
+
}
|
276 |
+
|
277 |
+
MainWP_Security::fix_all();
|
278 |
+
|
279 |
+
// Register does not require auth, so we register here.
|
280 |
+
if ( isset( $_POST['function'] ) && 'register' === $_POST['function'] ) {
|
281 |
+
|
282 |
+
/**
|
283 |
+
* Checks whether cron is in progress.
|
284 |
+
*
|
285 |
+
* @const ( bool ) Default: true
|
286 |
+
* @source https://code-reference.mainwp.com/classes/MainWP.Child.MainWP_Child.html
|
287 |
+
*/
|
288 |
+
define( 'DOING_CRON', true );
|
289 |
+
|
290 |
+
MainWP_Utility::fix_for_custom_themes();
|
291 |
+
MainWP_Connect::instance()->register_site(); // register the site and exit.
|
292 |
+
}
|
293 |
+
|
294 |
+
$mainwpsignature = isset( $_POST['mainwpsignature'] ) ? rawurldecode( wp_unslash( $_POST['mainwpsignature'] ) ) : '';
|
295 |
+
$function = isset( $_POST['function'] ) ? sanitize_text_field( wp_unslash( $_POST['function'] ) ) : null;
|
296 |
+
$nonce = isset( $_POST['nonce'] ) ? sanitize_text_field( wp_unslash( $_POST['nonce'] ) ) : '';
|
297 |
+
$nossl = isset( $_POST['nossl'] ) ? sanitize_text_field( wp_unslash( $_POST['nossl'] ) ) : 0;
|
298 |
+
|
299 |
+
// Authenticate here.
|
300 |
+
$auth = MainWP_Connect::instance()->auth( $mainwpsignature, $function, $nonce, $nossl );
|
301 |
+
|
302 |
+
// Parse auth, if it is not correct actions then exit with message or return.
|
303 |
+
if ( ! MainWP_Connect::instance()->parse_init_auth( $auth ) ) {
|
304 |
+
return;
|
305 |
+
}
|
306 |
+
|
307 |
+
$this->parse_init_extensions();
|
308 |
+
|
309 |
+
/**
|
310 |
+
* WordPress submenu no privilege.
|
311 |
+
*
|
312 |
+
* @global string
|
313 |
+
*/
|
314 |
+
global $_wp_submenu_nopriv;
|
315 |
+
|
316 |
+
if ( null === $_wp_submenu_nopriv ) {
|
317 |
+
$_wp_submenu_nopriv = array(); // phpcs:ignore -- Required to fix warnings, pull request solutions appreciated.
|
318 |
+
}
|
319 |
+
|
320 |
+
// execute callable functions here.
|
321 |
+
MainWP_Child_Callable::get_instance()->init_call_functions( $auth );
|
322 |
+
}
|
323 |
+
|
324 |
+
/**
|
325 |
+
* Method init_check_login()
|
326 |
+
*
|
327 |
+
* Initiate the check login process.
|
328 |
+
*
|
329 |
+
* @uses MainWP_Connect::check_login()
|
330 |
+
*/
|
331 |
+
public function init_check_login() {
|
332 |
+
MainWP_Connect::instance()->check_login();
|
333 |
+
}
|
334 |
+
|
335 |
+
/**
|
336 |
+
* Method admin_init()
|
337 |
+
*
|
338 |
+
* If the current user is administrator initiate the admin ajax.
|
339 |
+
*
|
340 |
+
* @uses \MainWP\Child\MainWP_Clone::init_ajax()
|
341 |
+
* @uses \MainWP\Child\MainWP_Helper::is_admin()
|
342 |
+
*/
|
343 |
+
public function admin_init() {
|
344 |
+
if ( MainWP_Helper::is_admin() && is_admin() ) {
|
345 |
+
MainWP_Clone::instance()->init_ajax();
|
346 |
+
}
|
347 |
+
}
|
348 |
+
|
349 |
+
/**
|
350 |
+
* Method parse_init_extensions()
|
351 |
+
*
|
352 |
+
* Parse MainWP Extension initiations.
|
353 |
+
*
|
354 |
+
* @uses \MainWP\Child\MainWP_Child_Branding::branding_init()
|
355 |
+
* @uses \MainWP\Child\MainWP_Client_Report::creport_init()
|
356 |
+
* @uses \MainWP\Child\MainWP_Child_IThemes_Security::ithemes_init()
|
357 |
+
* @uses \MainWP\Child\MainWP_Child_Updraft_Plus_Backups::updraftplus_init()
|
358 |
+
* @uses \MainWP\Child\MainWP_Child_Back_Up_WordPress::init()
|
359 |
+
* @uses \MainWP\Child\MainWP_Child_WP_Rocket::init()
|
360 |
+
* @uses \MainWP\Child\MainWP_Child_Back_WP_Up::init()
|
361 |
+
* @uses \MainWP\Child\MainWP_Child_Back_Up_Buddy::instance()
|
362 |
+
* @uses \MainWP\Child\MainWP_Child_Wordfence::wordfence_init()
|
363 |
+
* @uses \MainWP\Child\MainWP_Child_Timecapsule::init()
|
364 |
+
* @uses \MainWP\Child\MainWP_Child_Staging::init()
|
365 |
+
* @uses \MainWP\Child\MainWP_Child_Pagespeed::init()
|
366 |
+
* @uses \MainWP\Child\MainWP_Child_Links_Checker::init()
|
367 |
+
* @uses \MainWP\Child\MainWP_Child_WPvivid_BackupRestore::init()
|
368 |
+
*/
|
369 |
+
private function parse_init_extensions() {
|
370 |
+
MainWP_Child_Branding::instance()->branding_init();
|
371 |
+
MainWP_Client_Report::instance()->creport_init();
|
372 |
+
MainWP_Child_IThemes_Security::instance()->ithemes_init();
|
373 |
+
MainWP_Child_Updraft_Plus_Backups::instance()->updraftplus_init();
|
374 |
+
MainWP_Child_Back_Up_WordPress::instance()->init();
|
375 |
+
MainWP_Child_WP_Rocket::instance()->init();
|
376 |
+
MainWP_Child_Back_WP_Up::instance()->init();
|
377 |
+
MainWP_Child_Back_Up_Buddy::instance();
|
378 |
+
MainWP_Child_Wordfence::instance()->wordfence_init();
|
379 |
+
MainWP_Child_Timecapsule::instance()->init();
|
380 |
+
MainWP_Child_Staging::instance()->init();
|
381 |
+
MainWP_Child_Pagespeed::instance()->init();
|
382 |
+
MainWP_Child_Links_Checker::instance()->init();
|
383 |
+
MainWP_Child_WPvivid_BackupRestore::instance()->init();
|
384 |
+
}
|
385 |
+
|
386 |
+
/**
|
387 |
+
* Method deactivation()
|
388 |
+
*
|
389 |
+
* Deactivate the MainWP Child plugin and delete unwanted data.
|
390 |
+
*
|
391 |
+
* @param bool $deact Whether or not to deactivate pugin. Default: true.
|
392 |
+
*/
|
393 |
+
public function deactivation( $deact = true ) {
|
394 |
+
|
395 |
+
$mu_plugin_enabled = apply_filters( 'mainwp_child_mu_plugin_enabled', false );
|
396 |
+
if ( $mu_plugin_enabled ) {
|
397 |
+
return;
|
398 |
+
}
|
399 |
+
|
400 |
+
$to_delete = array(
|
401 |
+
'mainwp_child_pubkey',
|
402 |
+
'mainwp_child_nonce',
|
403 |
+
'mainwp_child_nossl',
|
404 |
+
'mainwp_child_nossl_key',
|
405 |
+
'mainwp_security',
|
406 |
+
'mainwp_child_server',
|
407 |
+
);
|
408 |
+
$to_delete[] = 'mainwp_ext_snippets_enabled';
|
409 |
+
$to_delete[] = 'mainwp_ext_code_snippets';
|
410 |
+
|
411 |
+
foreach ( $to_delete as $delete ) {
|
412 |
+
if ( get_option( $delete ) ) {
|
413 |
+
delete_option( $delete );
|
414 |
+
wp_cache_delete( $delete, 'options' );
|
415 |
+
}
|
416 |
+
}
|
417 |
+
|
418 |
+
if ( $deact ) {
|
419 |
+
do_action( 'mainwp_child_deactivation' );
|
420 |
+
}
|
421 |
+
}
|
422 |
+
|
423 |
+
/**
|
424 |
+
* Method activation()
|
425 |
+
*
|
426 |
+
* Activate the MainWP Child plugin and delete unwanted data.
|
427 |
+
*
|
428 |
+
* @uses \MainWP\Child\MainWP_Helper::update_option()
|
429 |
+
*/
|
430 |
+
public function activation() {
|
431 |
+
$mu_plugin_enabled = apply_filters( 'mainwp_child_mu_plugin_enabled', false );
|
432 |
+
if ( $mu_plugin_enabled ) {
|
433 |
+
return;
|
434 |
+
}
|
435 |
+
|
436 |
+
$to_delete = array(
|
437 |
+
'mainwp_child_pubkey',
|
438 |
+
'mainwp_child_nonce',
|
439 |
+
'mainwp_child_nossl',
|
440 |
+
'mainwp_child_nossl_key',
|
441 |
+
);
|
442 |
+
foreach ( $to_delete as $delete ) {
|
443 |
+
if ( get_option( $delete ) ) {
|
444 |
+
delete_option( $delete );
|
445 |
+
}
|
446 |
+
}
|
447 |
+
|
448 |
+
MainWP_Helper::update_option( 'mainwp_child_activated_once', true );
|
449 |
+
|
450 |
+
$to_delete = array( 'mainwp_ext_snippets_enabled', 'mainwp_ext_code_snippets' );
|
451 |
+
foreach ( $to_delete as $delete ) {
|
452 |
+
delete_option( $delete );
|
453 |
+
}
|
454 |
+
}
|
455 |
+
|
456 |
+
}
|
class/class-mainwp-client-report-base.php
CHANGED
@@ -1,1026 +1,1026 @@
|
|
1 |
-
<?php
|
2 |
-
/**
|
3 |
-
* MainWP Client Reports Base
|
4 |
-
*
|
5 |
-
* MainWP Client Reprots Extension handler.
|
6 |
-
* Extension URL: https://mainwp.com/extension/client-reports/
|
7 |
-
*
|
8 |
-
* @package MainWP\Child
|
9 |
-
*/
|
10 |
-
|
11 |
-
namespace MainWP\Child;
|
12 |
-
|
13 |
-
/**
|
14 |
-
* Class MainWP_Client_Report_Base
|
15 |
-
*
|
16 |
-
* MainWP Client Reports extension handler, extened by the MainWP_Client_Report class.
|
17 |
-
*/
|
18 |
-
class MainWP_Client_Report_Base {
|
19 |
-
|
20 |
-
/**
|
21 |
-
* Public static variable to hold the single instance of the class.
|
22 |
-
*
|
23 |
-
* @var mixed Default null
|
24 |
-
*/
|
25 |
-
public static $instance = null;
|
26 |
-
|
27 |
-
/**
|
28 |
-
* Method get_class_name()
|
29 |
-
*
|
30 |
-
* Get class name.
|
31 |
-
*
|
32 |
-
* @return string __CLASS__ Class name.
|
33 |
-
*/
|
34 |
-
public static function get_class_name() {
|
35 |
-
return __CLASS__;
|
36 |
-
}
|
37 |
-
|
38 |
-
/**
|
39 |
-
* Public static variable to hold the single instance of the class.
|
40 |
-
*
|
41 |
-
* @var mixed Default null
|
42 |
-
*/
|
43 |
-
public static function instance() {
|
44 |
-
if ( null === self::$instance ) {
|
45 |
-
self::$instance = new self();
|
46 |
-
}
|
47 |
-
return self::$instance;
|
48 |
-
}
|
49 |
-
|
50 |
-
/**
|
51 |
-
* Convert context name of tokens to context name saved in child reports.
|
52 |
-
*
|
53 |
-
* @param string $context Context name to be converted.
|
54 |
-
*
|
55 |
-
* @return string $context Converted context name.
|
56 |
-
*/
|
57 |
-
public function get_compatible_context( $context ) {
|
58 |
-
// some context are not different.
|
59 |
-
$mapping_contexts = array(
|
60 |
-
'comment' => 'comments', // actual context values: post, page.
|
61 |
-
'plugin' => 'plugins',
|
62 |
-
'users' => 'profiles',
|
63 |
-
'user' => 'profiles',
|
64 |
-
'session' => 'sessions',
|
65 |
-
'setting' => 'settings',
|
66 |
-
'theme' => 'themes',
|
67 |
-
'posts' => 'post',
|
68 |
-
'pages' => 'page',
|
69 |
-
'widgets' => 'widgets',
|
70 |
-
'widget' => 'widgets',
|
71 |
-
'menu' => 'menus',
|
72 |
-
'backups' => 'backups',
|
73 |
-
'backup' => 'backups',
|
74 |
-
'sucuri' => 'sucuri_scan',
|
75 |
-
'maintenance' => 'mainwp_maintenance',
|
76 |
-
'wordfence' => 'wordfence_scan',
|
77 |
-
'backups' => 'backups',
|
78 |
-
'backup' => 'backups',
|
79 |
-
'media' => 'media',
|
80 |
-
);
|
81 |
-
|
82 |
-
$context = isset( $mapping_contexts[ $context ] ) ? $mapping_contexts[ $context ] : $context;
|
83 |
-
|
84 |
-
return strtolower( $context );
|
85 |
-
}
|
86 |
-
|
87 |
-
/**
|
88 |
-
* Get connector by compatible context.
|
89 |
-
*
|
90 |
-
* @param string $context Context name as reference.
|
91 |
-
*
|
92 |
-
* @return string $connector Required connector.
|
93 |
-
*/
|
94 |
-
public function get_connector_by_compatible_context( $context ) {
|
95 |
-
|
96 |
-
$connector = '';
|
97 |
-
|
98 |
-
$mapping_connectors = array(
|
99 |
-
'plugins' => 'installer',
|
100 |
-
'themes' => 'installer',
|
101 |
-
'wordpress' => 'installer', // phpcs:ignore -- wordpress -> WordPress.
|
102 |
-
'profiles' => 'users',
|
103 |
-
'comments' => 'comments',
|
104 |
-
'settings' => 'settings',
|
105 |
-
'post' => 'posts',
|
106 |
-
'page' => 'posts',
|
107 |
-
'widgets' => 'widgets',
|
108 |
-
'menus' => 'menus',
|
109 |
-
'backups' => 'mainwp_backups',
|
110 |
-
'sucuri_scan' => 'mainwp_sucuri',
|
111 |
-
'mainwp_maintenance' => 'mainwp_maintenance',
|
112 |
-
'wordfence_scan' => 'mainwp_wordfence',
|
113 |
-
'media' => 'media',
|
114 |
-
);
|
115 |
-
|
116 |
-
if ( isset( $mapping_connectors[ $context ] ) ) {
|
117 |
-
$connector = $mapping_connectors[ $context ];
|
118 |
-
}
|
119 |
-
|
120 |
-
return $connector;
|
121 |
-
}
|
122 |
-
|
123 |
-
/**
|
124 |
-
* Get compatible action by context.
|
125 |
-
*
|
126 |
-
* @param string $action Action name as reference.
|
127 |
-
* @param string $context Context name as reference.
|
128 |
-
*
|
129 |
-
* @return string $action Compatible action.
|
130 |
-
*/
|
131 |
-
public function get_compatible_action( $action, $context = '' ) {
|
132 |
-
|
133 |
-
$mapping_actions = array(
|
134 |
-
'restored' => 'untrashed',
|
135 |
-
'spam' => 'spammed',
|
136 |
-
);
|
137 |
-
|
138 |
-
if ( isset( $mapping_actions[ $action ] ) ) {
|
139 |
-
return $mapping_actions[ $action ];
|
140 |
-
}
|
141 |
-
|
142 |
-
if ( 'mainwp_maintenance' == $context ) {
|
143 |
-
if ( 'process' == $action ) {
|
144 |
-
$action = 'maintenance';
|
145 |
-
}
|
146 |
-
} elseif ( 'sucuri_scan' == $context ) {
|
147 |
-
if ( 'checks' == $action ) {
|
148 |
-
$action = 'sucuri_scan';
|
149 |
-
}
|
150 |
-
} elseif ( 'wordfence_scan' == $context ) {
|
151 |
-
if ( 'scan' == $action ) {
|
152 |
-
$action = 'wordfence_scan';
|
153 |
-
}
|
154 |
-
}
|
155 |
-
return $action;
|
156 |
-
}
|
157 |
-
|
158 |
-
/**
|
159 |
-
* Get the Stream parameters.
|
160 |
-
*
|
161 |
-
* @param array $other_tokens An array containing other tokens.
|
162 |
-
* @param array $sections An array containing sections.
|
163 |
-
*
|
164 |
-
* @return array Arguments array.
|
165 |
-
*
|
166 |
-
* @uses \MainWP\Child\MainWP_Child_Branding::is_branding()
|
167 |
-
*/
|
168 |
-
public function get_stream_get_params( $other_tokens, $sections ) {
|
169 |
-
|
170 |
-
$allowed_params = array(
|
171 |
-
'connector',
|
172 |
-
'context',
|
173 |
-
'action',
|
174 |
-
'author',
|
175 |
-
'author_role',
|
176 |
-
'object_id',
|
177 |
-
'search',
|
178 |
-
'date',
|
179 |
-
'date_from',
|
180 |
-
'date_to',
|
181 |
-
'record__in',
|
182 |
-
'blog_id',
|
183 |
-
'ip',
|
184 |
-
);
|
185 |
-
|
186 |
-
$args = array();
|
187 |
-
foreach ( $allowed_params as $param ) {
|
188 |
-
$paramval = \wp_mainwp_stream_filter_input( INPUT_POST, $param );
|
189 |
-
if ( $paramval || '0' === $paramval ) {
|
190 |
-
$args[ $param ] = $paramval;
|
191 |
-
}
|
192 |
-
}
|
193 |
-
|
194 |
-
foreach ( $args as $arg => $val ) {
|
195 |
-
if ( ! in_array( $arg, $allowed_params ) ) {
|
196 |
-
unset( $args[ $arg ] );
|
197 |
-
}
|
198 |
-
}
|
199 |
-
|
200 |
-
$exclude_connector_posts = $this->get_stream_get_not_in_params( $sections, $other_tokens );
|
201 |
-
if ( $exclude_connector_posts ) {
|
202 |
-
$args['connector__not_in'] = array( 'posts' );
|
203 |
-
}
|
204 |
-
|
205 |
-
$args['action__not_in'] = array( 'login' );
|
206 |
-
|
207 |
-
$args['with-meta'] = 1;
|
208 |
-
|
209 |
-
if ( isset( $args['date_from'] ) ) {
|
210 |
-
$args['date_from'] = date( 'Y-m-d', $args['date_from'] ); // phpcs:ignore -- required to achieve desired results, pull request solutions appreciated.
|
211 |
-
}
|
212 |
-
|
213 |
-
if ( isset( $args['date_to'] ) ) {
|
214 |
-
$args['date_to'] = date( 'Y-m-d', $args['date_to'] ); // phpcs:ignore -- required to achieve desired results, pull request solutions appreciated.
|
215 |
-
}
|
216 |
-
|
217 |
-
if ( MainWP_Child_Branding::instance()->is_branding() ) {
|
218 |
-
$args['hide_child_reports'] = 1;
|
219 |
-
}
|
220 |
-
|
221 |
-
$args['records_per_page'] = 9999;
|
222 |
-
|
223 |
-
return $args;
|
224 |
-
}
|
225 |
-
|
226 |
-
/**
|
227 |
-
* Get the Stream excluded parameters.
|
228 |
-
*
|
229 |
-
* @param array $sections An array containing sections.
|
230 |
-
* @param array $other_tokens An array containing other tokens.
|
231 |
-
*
|
232 |
-
* @return bool true|false
|
233 |
-
*/
|
234 |
-
private function get_stream_get_not_in_params( $sections, $other_tokens ) {
|
235 |
-
|
236 |
-
$exclude_connector_posts = true;
|
237 |
-
|
238 |
-
$parts = array( 'header', 'body', 'footer' );
|
239 |
-
foreach ( $parts as $part ) {
|
240 |
-
if ( isset( $sections[ $part ] ) && isset( $sections[ $part ]['section_token'] ) && is_array( $sections[ $part ]['section_token'] ) ) {
|
241 |
-
foreach ( $sections[ $part ]['section_token'] as $sec ) {
|
242 |
-
if ( false !== strpos( $sec, '[section.posts' ) || false !== strpos( $sec, '[section.pages' ) ) {
|
243 |
-
$exclude_connector_posts = false;
|
244 |
-
break;
|
245 |
-
}
|
246 |
-
}
|
247 |
-
}
|
248 |
-
if ( ! $exclude_connector_posts ) {
|
249 |
-
break;
|
250 |
-
}
|
251 |
-
}
|
252 |
-
|
253 |
-
if ( $exclude_connector_posts ) {
|
254 |
-
foreach ( $parts as $part ) {
|
255 |
-
if ( isset( $other_tokens[ $part ] ) && is_array( $other_tokens[ $part ] ) ) {
|
256 |
-
foreach ( $other_tokens[ $part ] as $sec ) {
|
257 |
-
if ( false !== strpos( $sec, '[post.' ) || false !== strpos( $sec, '[page.' ) ) {
|
258 |
-
$exclude_connector_posts = false;
|
259 |
-
break;
|
260 |
-
}
|
261 |
-
}
|
262 |
-
}
|
263 |
-
if ( ! $exclude_connector_posts ) {
|
264 |
-
break;
|
265 |
-
}
|
266 |
-
}
|
267 |
-
}
|
268 |
-
return $exclude_connector_posts;
|
269 |
-
}
|
270 |
-
|
271 |
-
/**
|
272 |
-
* Get the Stream other tokens.
|
273 |
-
*
|
274 |
-
* @param array $records An array containg actions records.
|
275 |
-
* @param array $other_tokens An array containing other tokens.
|
276 |
-
* @param array $skip_records An array containing skipped records.
|
277 |
-
*
|
278 |
-
* @return array Other tokens data.
|
279 |
-
*/
|
280 |
-
public function get_stream_others_tokens( $records, $other_tokens, $skip_records ) {
|
281 |
-
$other_tokens_data = array();
|
282 |
-
$parts = array( 'header', 'body', 'footer' );
|
283 |
-
foreach ( $parts as $part ) {
|
284 |
-
if ( isset( $other_tokens[ $part ] ) && is_array( $other_tokens[ $part ] ) ) {
|
285 |
-
$other_tokens_data[ $part ] = $this->get_other_tokens_data( $records, $other_tokens[ $part ], $skip_records );
|
286 |
-
}
|
287 |
-
}
|
288 |
-
return $other_tokens_data;
|
289 |
-
}
|
290 |
-
|
291 |
-
/**
|
292 |
-
* Get the Stream sections data.
|
293 |
-
*
|
294 |
-
* @param array $records An array containg actions records.
|
295 |
-
* @param array $sections An array containing sections.
|
296 |
-
* @param array $skip_records An array containing skipped records.
|
297 |
-
*
|
298 |
-
* @return array Sections data.
|
299 |
-
*/
|
300 |
-
public function get_stream_sections_data( $records, $sections, $skip_records ) {
|
301 |
-
$sections_data = array();
|
302 |
-
$parts = array( 'header', 'body', 'footer' );
|
303 |
-
foreach ( $parts as $part ) {
|
304 |
-
if ( isset( $sections[ $part ] ) && is_array( $sections[ $part ] ) && ! empty( $sections[ $part ] ) ) {
|
305 |
-
foreach ( $sections[ $part ]['section_token'] as $index => $sec ) {
|
306 |
-
$tokens = $sections[ $part ]['section_content_tokens'][ $index ];
|
307 |
-
$sections_data[ $part ][ $index ] = $this->get_section_loop_data( $records, $tokens, $sec, $skip_records );
|
308 |
-
}
|
309 |
-
}
|
310 |
-
}
|
311 |
-
return $sections_data;
|
312 |
-
}
|
313 |
-
|
314 |
-
/**
|
315 |
-
* Fix logging for posts creation action.
|
316 |
-
*
|
317 |
-
* @param array $records An array containg actions records.
|
318 |
-
* @param array $skip_records An array containg records to skip.
|
319 |
-
*/
|
320 |
-
protected function fix_logs_posts_created( &$records, &$skip_records ) {
|
321 |
-
|
322 |
-
$args = array(
|
323 |
-
'post_type' => 'post',
|
324 |
-
'post_status' => 'publish',
|
325 |
-
'date_query' => array(
|
326 |
-
'column' => 'post_date',
|
327 |
-
'after' => $args['date_from'],
|
328 |
-
'before' => $args['date_to'],
|
329 |
-
),
|
330 |
-
);
|
331 |
-
|
332 |
-
$result = new \WP_Query( $args );
|
333 |
-
$records_created_posts = $result->posts;
|
334 |
-
|
335 |
-
if ( $records_created_posts ) {
|
336 |
-
|
337 |
-
$count_records = count( $records );
|
338 |
-
for ( $i = 0; $i < $count_records; $i++ ) {
|
339 |
-
$record = $records[ $i ];
|
340 |
-
if ( 'posts' == $record->connector && 'post' == $record->context && 'created' == $record->action ) {
|
341 |
-
if ( ! in_array( $record->ID, $skip_records ) ) {
|
342 |
-
$skip_records[] = $record->ID;
|
343 |
-
}
|
344 |
-
}
|
345 |
-
}
|
346 |
-
|
347 |
-
$post_authors = array();
|
348 |
-
|
349 |
-
foreach ( $records_created_posts as $_post ) {
|
350 |
-
$au_id = $_post->post_author;
|
351 |
-
if ( ! isset( $post_authors[ $au_id ] ) ) {
|
352 |
-
$au = get_user_by( 'id', $au_id );
|
353 |
-
$post_authors[ $au_id ] = $au->display_name;
|
354 |
-
}
|
355 |
-
$au_name = $post_authors[ $au_id ];
|
356 |
-
|
357 |
-
// simulate logging created posts record.
|
358 |
-
$stdObj = new \stdClass();
|
359 |
-
$stdObj->ID = 0; // simulate ID value.
|
360 |
-
$stdObj->connector = 'posts';
|
361 |
-
$stdObj->context = 'post';
|
362 |
-
$stdObj->action = 'created';
|
363 |
-
$stdObj->created = $_post->post_date;
|
364 |
-
$stdObj->meta = array(
|
365 |
-
'post_title' => array( $_post->post_title ),
|
366 |
-
'user_meta' => array( $au_name ),
|
367 |
-
);
|
368 |
-
|
369 |
-
$records[] = $stdObj;
|
370 |
-
}
|
371 |
-
}
|
372 |
-
}
|
373 |
-
|
374 |
-
/**
|
375 |
-
* Get the other tokens data.
|
376 |
-
*
|
377 |
-
* @param array $records An array containg actions records.
|
378 |
-
* @param array $tokens An array containg the tokens list.
|
379 |
-
* @param array $skip_records An array containg records to skip.
|
380 |
-
*
|
381 |
-
* @return array An array containg the tokens values.
|
382 |
-
*/
|
383 |
-
public function get_other_tokens_data( $records, $tokens, &$skip_records ) {
|
384 |
-
|
385 |
-
$token_values = array();
|
386 |
-
|
387 |
-
if ( ! is_array( $tokens ) ) {
|
388 |
-
$tokens = array();
|
389 |
-
}
|
390 |
-
|
391 |
-
$backups_created_time_to_fix = array();
|
392 |
-
|
393 |
-
foreach ( $tokens as $token ) {
|
394 |
-
if ( isset( $token_values[ $token ] ) ) {
|
395 |
-
continue;
|
396 |
-
}
|
397 |
-
$str_tmp = str_replace( array( '[', ']' ), '', $token );
|
398 |
-
$array_tmp = explode( '.', $str_tmp );
|
399 |
-
if ( is_array( $array_tmp ) ) {
|
400 |
-
$context = '';
|
401 |
-
$action = '';
|
402 |
-
$data = '';
|
403 |
-
if ( 2 === count( $array_tmp ) ) {
|
404 |
-
list( $context, $data ) = $array_tmp;
|
405 |
-
} elseif ( 3 === count( $array_tmp ) ) {
|
406 |
-
list( $context, $action, $data ) = $array_tmp;
|
407 |
-
}
|
408 |
-
$context = $this->get_compatible_context( $context );
|
409 |
-
// to compatible with new version of child report.
|
410 |
-
// to check condition for grabbing report data.
|
411 |
-
$connector = $this->get_connector_by_compatible_context( $context );
|
412 |
-
$action = $this->get_compatible_action( $action, $context );
|
413 |
-
// custom values.
|
414 |
-
if ( 'profiles' == $context ) {
|
415 |
-
if ( 'created' == $action || 'deleted' == $action ) {
|
416 |
-
$context = 'users';
|
417 |
-
}
|
418 |
-
}
|
419 |
-
switch ( $data ) {
|
420 |
-
case 'count':
|
421 |
-
$token_values[ $token ] = $this->get_other_tokens_count( $records, $connector, $context, $action, $skip_records, $backups_created_time_to_fix );
|
422 |
-
break;
|
423 |
-
}
|
424 |
-
}
|
425 |
-
}
|
426 |
-
|
427 |
-
return $token_values;
|
428 |
-
}
|
429 |
-
|
430 |
-
/**
|
431 |
-
* Get the other tokens count.
|
432 |
-
*
|
433 |
-
* @param object $records Object containng reports records.
|
434 |
-
* @param string $connector Record connector.
|
435 |
-
* @param string $context Record context.
|
436 |
-
* @param string $action Record action.
|
437 |
-
* @param array $skip_records Records to skip.
|
438 |
-
* @param array $backups_created_time_to_fix Backups created time.
|
439 |
-
*
|
440 |
-
* @return int The count number.
|
441 |
-
*/
|
442 |
-
private function get_other_tokens_count( $records, $connector, $context, $action, &$skip_records, &$backups_created_time_to_fix ) { // phpcs:ignore -- Current complexity is the only way to achieve desired results, pull request solutions appreciated.
|
443 |
-
$count = 0;
|
444 |
-
|
445 |
-
foreach ( $records as $record ) {
|
446 |
-
// check connector.
|
447 |
-
if ( 'editor' == $record->connector ) {
|
448 |
-
if ( ! in_array( $context, array( 'plugins', 'themes' ) ) || 'updated' !== $action ) {
|
449 |
-
continue;
|
450 |
-
}
|
451 |
-
} elseif ( $connector !== $record->connector ) {
|
452 |
-
continue;
|
453 |
-
}
|
454 |
-
|
455 |
-
$valid_context = false;
|
456 |
-
// check context.
|
457 |
-
if ( 'comments' == $context ) { // multi values.
|
458 |
-
$comment_contexts = array( 'post', 'page' );
|
459 |
-
if ( ! in_array( $record->context, $comment_contexts ) ) {
|
460 |
-
continue;
|
461 |
-
}
|
462 |
-
$valid_context = true;
|
463 |
-
} elseif ( 'post' === $context && 'created' === $action ) {
|
464 |
-
if ( in_array( $record->ID, $skip_records ) ) {
|
465 |
-
continue;
|
466 |
-
}
|
467 |
-
$valid_context = true;
|
468 |
-
} elseif ( 'menus' == $context ) {
|
469 |
-
$valid_context = true; // ok, pass, don't check context.
|
470 |
-
} elseif ( 'editor' == $record->connector ) {
|
471 |
-
$valid_context = true; // ok, pass, checked above.
|
472 |
-
} elseif ( 'media' == $connector && 'media' == $record->connector ) {
|
473 |
-
$valid_context = true; // ok, pass, do not check context.
|
474 |
-
} elseif ( 'widgets' == $connector && 'widgets' == $record->connector ) {
|
475 |
-
$valid_context = true; // ok, pass, don't check context.
|
476 |
-
}
|
477 |
-
|
478 |
-
$valid_context = ( $valid_context || strtolower( $record->context ) == $context ) ? true : false;
|
479 |
-
if ( ! $valid_context ) {
|
480 |
-
continue;
|
481 |
-
}
|
482 |
-
// custom action value.
|
483 |
-
if ( 'widgets' == $connector ) {
|
484 |
-
if ( 'deleted' == $action ) {
|
485 |
-
$action = 'removed'; // action saved in database.
|
486 |
-
}
|
487 |
-
}
|
488 |
-
|
489 |
-
// check action.
|
490 |
-
if ( 'backups' === $context ) {
|
491 |
-
if ( ! $this->is_backup_action( $record->action ) ) {
|
492 |
-
continue;
|
493 |
-
}
|
494 |
-
$created = strtotime( $record->created );
|
495 |
-
if ( in_array( $created, $backups_created_time_to_fix ) ) {
|
496 |
-
if ( ! in_array( $record->ID, $skip_records ) ) {
|
497 |
-
$skip_records[] = $record->ID;
|
498 |
-
}
|
499 |
-
continue;
|
500 |
-
} else {
|
501 |
-
$backups_created_time_to_fix[] = $created;
|
502 |
-
}
|
503 |
-
} else {
|
504 |
-
if ( $action !== $record->action ) {
|
505 |
-
continue;
|
506 |
-
}
|
507 |
-
|
508 |
-
if ( 'updated' === $action && ( 'post' === $context || 'page' === $context ) ) {
|
509 |
-
$new_status = $this->get_stream_meta_data( $record, 'new_status' );
|
510 |
-
if ( 'draft' === $new_status ) {
|
511 |
-
continue;
|
512 |
-
}
|
513 |
-
} elseif ( 'updated' === $action && ( 'themes' === $context || 'plugins' === $context ) ) {
|
514 |
-
$name = $this->get_stream_meta_data( $record, 'name' );
|
515 |
-
if ( empty( $name ) ) {
|
516 |
-
if ( ! in_array( $record->ID, $skip_records ) ) {
|
517 |
-
$skip_records[] = $record->ID;
|
518 |
-
}
|
519 |
-
continue;
|
520 |
-
} else {
|
521 |
-
$old_version = $this->get_stream_meta_data( $record, 'old_version' );
|
522 |
-
$version = $this->get_stream_meta_data( $record, 'version' );
|
523 |
-
if ( version_compare( $version, $old_version, '<=' ) ) {
|
524 |
-
if ( ! in_array( $record->ID, $skip_records ) ) {
|
525 |
-
$skip_records[] = $record->ID;
|
526 |
-
}
|
527 |
-
continue;
|
528 |
-
}
|
529 |
-
}
|
530 |
-
}
|
531 |
-
}
|
532 |
-
$count ++;
|
533 |
-
}
|
534 |
-
return $count;
|
535 |
-
}
|
536 |
-
|
537 |
-
/**
|
538 |
-
* Get the section loop data.
|
539 |
-
*
|
540 |
-
* @param object $records Object containng reports records.
|
541 |
-
* @param array $tokens An array containing report tokens.
|
542 |
-
* @param string $section Section name.
|
543 |
-
* @param array $skip_records Records to skip.
|
544 |
-
*
|
545 |
-
* @return array Section loop records.
|
546 |
-
*/
|
547 |
-
public function get_section_loop_data( $records, $tokens, $section, $skip_records = array() ) {
|
548 |
-
|
549 |
-
$context = '';
|
550 |
-
$action = '';
|
551 |
-
|
552 |
-
$str_tmp = str_replace( array( '[', ']' ), '', $section );
|
553 |
-
$array_tmp = explode( '.', $str_tmp );
|
554 |
-
if ( is_array( $array_tmp ) ) {
|
555 |
-
if ( 2 === count( $array_tmp ) ) {
|
556 |
-
list( $str1, $context ) = $array_tmp;
|
557 |
-
} elseif ( 3 === count( $array_tmp ) ) {
|
558 |
-
list( $str1, $context, $action ) = $array_tmp;
|
559 |
-
}
|
560 |
-
}
|
561 |
-
|
562 |
-
// get db $context value by mapping.
|
563 |
-
$context = $this->get_compatible_context( $context );
|
564 |
-
// to compatible with new version of child report.
|
565 |
-
// to check condition for grabbing report data.
|
566 |
-
$connector = $this->get_connector_by_compatible_context( $context );
|
567 |
-
|
568 |
-
$action = $this->get_compatible_action( $action, $context );
|
569 |
-
|
570 |
-
if ( 'profiles' == $context ) {
|
571 |
-
if ( 'created' == $action || 'deleted' == $action ) {
|
572 |
-
$context = 'users';
|
573 |
-
}
|
574 |
-
}
|
575 |
-
|
576 |
-
return $this->get_section_loop_records( $records, $tokens, $connector, $context, $action, $skip_records );
|
577 |
-
}
|
578 |
-
|
579 |
-
/**
|
580 |
-
* Get the section loop records.
|
581 |
-
*
|
582 |
-
* @param object $records Object containng reports records.
|
583 |
-
* @param array $tokens An array containing report tokens.
|
584 |
-
* @param string $connector Record connector.
|
585 |
-
* @param string $context Record context.
|
586 |
-
* @param string $action Record action.
|
587 |
-
* @param array $skip_records Records to skip.
|
588 |
-
*
|
589 |
-
* @return array Loops.
|
590 |
-
*/
|
591 |
-
public function get_section_loop_records( $records, $tokens, $connector, $context, $action, $skip_records ) { // phpcs:ignore -- Current complexity is the only way to achieve desired results, pull request solutions appreciated.
|
592 |
-
|
593 |
-
$loops = array();
|
594 |
-
$loop_count = 0;
|
595 |
-
|
596 |
-
$max_items_get = ( isset( $_POST['max_items_get'] ) && ! empty( $_POST['max_items_get'] ) ) ? intval( $_POST['max_items_get'] ) : 0;
|
597 |
-
$limit_connectors = ( isset( $_POST['limit_reports'] ) && ! empty( $_POST['limit_reports'] ) ) ? intval( $_POST['limit_reports'] ) : array();
|
598 |
-
|
599 |
-
if ( ! is_array( $limit_connectors ) || empty( $limit_connectors ) ) {
|
600 |
-
$limit_connectors = array( 'mainwp_sucuri', 'mainwp_maintenance', 'mainwp_backups' );
|
601 |
-
}
|
602 |
-
|
603 |
-
foreach ( $records as $record ) {
|
604 |
-
|
605 |
-
if ( in_array( $record->ID, $skip_records ) ) {
|
606 |
-
continue;
|
607 |
-
}
|
608 |
-
|
609 |
-
if ( 'editor' == $record->connector ) {
|
610 |
-
if ( ! in_array( $context, array( 'plugins', 'themes' ) ) || 'updated' !== $action ) {
|
611 |
-
continue;
|
612 |
-
}
|
613 |
-
} elseif ( $connector !== $record->connector ) {
|
614 |
-
continue;
|
615 |
-
}
|
616 |
-
|
617 |
-
$valid_context = false;
|
618 |
-
|
619 |
-
if ( 'comments' == $context ) {
|
620 |
-
$comment_contexts = array( 'post', 'page' );
|
621 |
-
if ( ! in_array( $record->context, $comment_contexts ) ) {
|
622 |
-
continue;
|
623 |
-
}
|
624 |
-
$valid_context = true;
|
625 |
-
} elseif ( 'menus' == $context ) {
|
626 |
-
$valid_context = true; // ok, pass, don't check context.
|
627 |
-
} elseif ( 'editor' == $record->connector ) {
|
628 |
-
$valid_context = true; // ok, pass, checked above.
|
629 |
-
} elseif ( 'media' == $connector && 'media' == $record->connector ) {
|
630 |
-
$valid_context = true; // ok, pass, do not check context.
|
631 |
-
} elseif ( 'widgets' == $connector && 'widgets' == $record->connector ) {
|
632 |
-
$valid_context = true; // ok, pass, don't check context.
|
633 |
-
}
|
634 |
-
|
635 |
-
$valid_context = ( $valid_context || strtolower( $record->context ) == $context ) ? true : false;
|
636 |
-
|
637 |
-
if ( ! $valid_context ) {
|
638 |
-
continue;
|
639 |
-
}
|
640 |
-
|
641 |
-
// custom action value!
|
642 |
-
if ( 'widgets' == $connector ) {
|
643 |
-
if ( 'deleted' == $action ) {
|
644 |
-
$action = 'removed'; // action saved in database!
|
645 |
-
}
|
646 |
-
}
|
647 |
-
|
648 |
-
if ( 'backups' == $context ) {
|
649 |
-
if ( ! $this->is_backup_action( $record->action ) ) {
|
650 |
-
continue;
|
651 |
-
}
|
652 |
-
} elseif ( $action !== $record->action ) {
|
653 |
-
continue;
|
654 |
-
}
|
655 |
-
|
656 |
-
if ( 'updated' === $action && ( 'post' === $context || 'page' === $context ) ) {
|
657 |
-
$new_status = $this->get_stream_meta_data( $record, 'new_status' );
|
658 |
-
if ( 'draft' === $new_status ) { // avoid auto save post!
|
659 |
-
continue;
|
660 |
-
}
|
661 |
-
}
|
662 |
-
$token_values = $this->get_section_loop_token_values( $record, $context, $tokens );
|
663 |
-
if ( ! empty( $token_values ) ) {
|
664 |
-
$loops[ $loop_count ] = $token_values;
|
665 |
-
$loop_count ++;
|
666 |
-
}
|
667 |
-
|
668 |
-
if ( $max_items_get && ( $loop_count >= $max_items_get ) ) {
|
669 |
-
if ( in_array( $connector, $limit_connectors ) ) {
|
670 |
-
break;
|
671 |
-
}
|
672 |
-
}
|
673 |
-
}
|
674 |
-
return $loops;
|
675 |
-
}
|
676 |
-
|
677 |
-
/**
|
678 |
-
* Check if it's backup action.
|
679 |
-
*
|
680 |
-
* @param string $action Record action.
|
681 |
-
*
|
682 |
-
* @return bool If backup action, return trie, if not, false.
|
683 |
-
*/
|
684 |
-
public function is_backup_action( $action ) {
|
685 |
-
if ( in_array( $action, array( 'mainwp_backup', 'backupbuddy_backup', 'backupwordpress_backup', 'backwpup_backup', 'updraftplus_backup', 'wptimecapsule_backup', 'wpvivid_backup' ) ) ) {
|
686 |
-
return true;
|
687 |
-
}
|
688 |
-
return false;
|
689 |
-
}
|
690 |
-
|
691 |
-
/**
|
692 |
-
* Get the section loop token values.
|
693 |
-
*
|
694 |
-
* @param object $record Object containing the record data.
|
695 |
-
* @param string $context Record context.
|
696 |
-
* @param array $tokens An array containg the report tokens.
|
697 |
-
*
|
698 |
-
* @return array Token values.
|
699 |
-
*
|
700 |
-
* @uses \MainWP\Child\MainWP_Helper::log_debug()
|
701 |
-
*/
|
702 |
-
private function get_section_loop_token_values( $record, $context, $tokens ) {
|
703 |
-
|
704 |
-
$token_values = array();
|
705 |
-
foreach ( $tokens as $token ) {
|
706 |
-
$data = '';
|
707 |
-
$token_name = str_replace( array( '[', ']' ), '', $token );
|
708 |
-
$array_tmp = explode( '.', $token_name );
|
709 |
-
|
710 |
-
if ( 'user.name' === $token_name ) {
|
711 |
-
$data = 'display_name';
|
712 |
-
} else {
|
713 |
-
if ( 1 === count( $array_tmp ) ) {
|
714 |
-
list( $data ) = $array_tmp;
|
715 |
-
} elseif ( 2 === count( $array_tmp ) ) {
|
716 |
-
list( $str1, $data ) = $array_tmp;
|
717 |
-
} elseif ( 3 === count( $array_tmp ) ) {
|
718 |
-
list( $str1, $str2, $data ) = $array_tmp;
|
719 |
-
}
|
720 |
-
|
721 |
-
if ( 'version' === $data ) {
|
722 |
-
if ( 'old' === $str2 ) {
|
723 |
-
$data = 'old_version';
|
724 |
-
} elseif ( 'current' === $str2 && 'wordpress' === $str1 ) { // phpcs:ignore -- wordpress -> WordPress.
|
725 |
-
$data = 'new_version';
|
726 |
-
}
|
727 |
-
}
|
728 |
-
}
|
729 |
-
|
730 |
-
if ( 'role' === $data ) {
|
731 |
-
$data = 'roles';
|
732 |
-
}
|
733 |
-
|
734 |
-
$tok_value = $this->get_section_token_value( $record, $data, $context, $token );
|
735 |
-
|
736 |
-
$token_values[ $token ] = $tok_value;
|
737 |
-
|
738 |
-
if ( empty( $tok_value ) ) {
|
739 |
-
$msg = 'MainWP Child Report:: skip empty value :: token :: ' . $token . ' :: record :: ' . print_r( $record, true ); // phpcs:ignore -- required to achieve desired results, pull request solutions appreciated.
|
740 |
-
MainWP_Helper::log_debug( $msg );
|
741 |
-
}
|
742 |
-
}
|
743 |
-
return $token_values;
|
744 |
-
}
|
745 |
-
|
746 |
-
/**
|
747 |
-
* Get the section token value.
|
748 |
-
*
|
749 |
-
* @param object $record Object containing the record data.
|
750 |
-
* @param string $data Data to process.
|
751 |
-
* @param string $context Record context.
|
752 |
-
* @param string $token Requested token.
|
753 |
-
*
|
754 |
-
* @return array Token value.
|
755 |
-
*
|
756 |
-
* @uses \MainWP\Child\MainWP_Helper::format_date()
|
757 |
-
* @uses \MainWP\Child\MainWP_Helper::format_time()
|
758 |
-
*/
|
759 |
-
public function get_section_token_value( $record, $data, $context, $token ) { // phpcs:ignore -- Current complexity is the only way to achieve desired results, pull request solutions appreciated.
|
760 |
-
$tok_value = '';
|
761 |
-
switch ( $data ) {
|
762 |
-
case 'ID':
|
763 |
-
$tok_value = $record->ID;
|
764 |
-
break;
|
765 |
-
case 'date':
|
766 |
-
$tok_value = MainWP_Helper::format_date( MainWP_Helper::get_timestamp( strtotime( $record->created ) ) );
|
767 |
-
break;
|
768 |
-
case 'time':
|
769 |
-
$tok_value = MainWP_Helper::format_time( MainWP_Helper::get_timestamp( strtotime( $record->created ) ) );
|
770 |
-
break;
|
771 |
-
case 'area':
|
772 |
-
$data = 'sidebar_name';
|
773 |
-
$tok_value = $this->get_stream_meta_data( $record, $data );
|
774 |
-
break;
|
775 |
-
case 'name':
|
776 |
-
case 'version':
|
777 |
-
case 'old_version':
|
778 |
-
case 'new_version':
|
779 |
-
case 'display_name':
|
780 |
-
case 'roles':
|
781 |
-
if ( 'name' == $data ) {
|
782 |
-
if ( 'profiles' == $context ) {
|
783 |
-
$data = 'display_name';
|
784 |
-
}
|
785 |
-
}
|
786 |
-
$tok_value = $this->get_stream_meta_data( $record, $data );
|
787 |
-
break;
|
788 |
-
case 'title':
|
789 |
-
if ( 'comments' === $context ) {
|
790 |
-
$tok_value = $record->summary;
|
791 |
-
} else {
|
792 |
-
if ( 'page' === $context || 'post' === $context ) {
|
793 |
-
$data = 'post_title';
|
794 |
-
} elseif ( 'menus' === $record->connector ) {
|
795 |
-
$data = 'name';
|
796 |
-
}
|
797 |
-
$tok_value = $this->get_stream_meta_data( $record, $data );
|
798 |
-
}
|
799 |
-
break;
|
800 |
-
case 'author':
|
801 |
-
$tok_value = $this->get_author_data_token_value( $record, $connector, $context, $data );
|
802 |
-
|
803 |
-
break;
|
804 |
-
case 'status':
|
805 |
-
case 'webtrust':
|
806 |
-
$value = '';
|
807 |
-
if ( 'sucuri_scan' === $context ) {
|
808 |
-
$value = $this->get_sucuri_scan_token_value( $record, $data );
|
809 |
-
}
|
810 |
-
$tok_value = $value;
|
811 |
-
break;
|
812 |
-
case 'details':
|
813 |
-
case 'result':
|
814 |
-
$tok_value = $this->get_result_data_token_value( $record, $context, $data );
|
815 |
-
break;
|
816 |
-
case 'type':
|
817 |
-
if ( 'backups' === $context ) {
|
818 |
-
$tok_value = $this->get_stream_meta_data( $record, $data );
|
819 |
-
} else {
|
820 |
-
$tok_value = $token;
|
821 |
-
}
|
822 |
-
break;
|
823 |
-
default:
|
824 |
-
$tok_value = 'N/A';
|
825 |
-
break;
|
826 |
-
}
|
827 |
-
return $tok_value;
|
828 |
-
}
|
829 |
-
|
830 |
-
/**
|
831 |
-
* Get the Stream meta data for a certain record.
|
832 |
-
*
|
833 |
-
* @param object $record Object containing the record data.
|
834 |
-
* @param string $data Data to process.
|
835 |
-
*
|
836 |
-
* @return string Return the meta data value.
|
837 |
-
*/
|
838 |
-
public function get_stream_meta_data( $record, $data ) {
|
839 |
-
|
840 |
-
if ( empty( $record ) ) {
|
841 |
-
return '';
|
842 |
-
}
|
843 |
-
|
844 |
-
$meta_key = $data;
|
845 |
-
|
846 |
-
$value = '';
|
847 |
-
|
848 |
-
if ( isset( $record->meta ) ) {
|
849 |
-
$meta = $record->meta;
|
850 |
-
|
851 |
-
if ( isset( $meta[ $meta_key ] ) ) {
|
852 |
-
$value = $meta[ $meta_key ];
|
853 |
-
$value = ( 'user_meta' == $meta_key && isset( $value[1] ) ) ? $value[1] : current( $value );
|
854 |
-
|
855 |
-
if ( 'author_meta' === $meta_key ) {
|
856 |
-
$value = maybe_unserialize( $value );
|
857 |
-
if ( is_array( $value ) ) {
|
858 |
-
$value = $value['display_name'];
|
859 |
-
// fix empty author value!
|
860 |
-
if ( empty( $value ) ) {
|
861 |
-
if ( isset( $value['agent'] ) && ! empty( $value['agent'] ) ) {
|
862 |
-
$value = $value['agent'];
|
863 |
-
}
|
864 |
-
}
|
865 |
-
}
|
866 |
-
if ( ! is_string( $value ) ) {
|
867 |
-
$value = '';
|
868 |
-
}
|
869 |
-
}
|
870 |
-
}
|
871 |
-
}
|
872 |
-
|
873 |
-
return $value;
|
874 |
-
}
|
875 |
-
|
876 |
-
/**
|
877 |
-
* Get the author data token value.
|
878 |
-
*
|
879 |
-
* @param object $record Object containing the record data.
|
880 |
-
* @param string $connector Record connector.
|
881 |
-
* @param string $context Record context.
|
882 |
-
* @param string $data Data to process.
|
883 |
-
*
|
884 |
-
* @return string Author data token value.
|
885 |
-
*/
|
886 |
-
private function get_author_data_token_value( $record, $connector, $context, $data ) {
|
887 |
-
if ( 'comment' == $connector ) {
|
888 |
-
$data = 'user_name';
|
889 |
-
} else {
|
890 |
-
$data = 'user_meta';
|
891 |
-
}
|
892 |
-
$value = $this->get_stream_meta_data( $record, $data );
|
893 |
-
|
894 |
-
if ( empty( $value ) && 'comments' === $context ) {
|
895 |
-
$value = __( 'Guest', 'mainwp-child' );
|
896 |
-
}
|
897 |
-
|
898 |
-
// check compatibility with old meta data.
|
899 |
-
if ( empty( $value ) ) {
|
900 |
-
$value = $this->get_stream_meta_data( $record, 'author_meta' );
|
901 |
-
}
|
902 |
-
|
903 |
-
return $value;
|
904 |
-
}
|
905 |
-
|
906 |
-
/**
|
907 |
-
* Get the result data token value.
|
908 |
-
*
|
909 |
-
* @param object $record Object containing the record data.
|
910 |
-
* @param string $context Record context.
|
911 |
-
* @param string $data Data to process.
|
912 |
-
*
|
913 |
-
* @return string Result data token value.
|
914 |
-
*/
|
915 |
-
private function get_result_data_token_value( $record, $context, $data ) {
|
916 |
-
if ( 'mainwp_maintenance' === $context && 'details' == $data ) {
|
917 |
-
$tok_value = $this->get_mainwp_maintenance_token_value( $record, $data );
|
918 |
-
} elseif ( 'wordfence_scan' === $context || 'mainwp_maintenance' === $context ) {
|
919 |
-
$meta_value = $this->get_stream_meta_data( $record, $data );
|
920 |
-
if ( 'wordfence_scan' === $context ) {
|
921 |
-
if ( 'result' == $data ) {
|
922 |
-
$completed_log = __( 'Scan complete. Congratulations, no new problems found.', 'wordfence' );
|
923 |
-
$str_loc1 = MainWP_Child_Wordfence::instance()->get_substr( $completed_log, 2 ); // loc string.
|
924 |
-
$str_loc2 = MainWP_Child_Wordfence::instance()->get_substr( $completed_log, 3 ); // loc string.
|
925 |
-
$congra_str_loc = str_replace( $str_loc1, '', $str_loc2 );
|
926 |
-
$congra_str_loc = trim( $congra_str_loc, ' ,' );
|
927 |
-
|
928 |
-
// SUM_FINAL:Scan complete. You have xxx new issues to fix. See below.
|
929 |
-
// SUM_FINAL:Scan complete. Congratulations, no new problems found.
|
930 |
-
if ( stripos( $meta_value, 'Congratulations' ) || stripos( $meta_value, $congra_str_loc ) ) {
|
931 |
-
$meta_value = 'No issues detected';
|
932 |
-
} elseif ( stripos( $meta_value, 'You have' ) ) {
|
933 |
-
$meta_value = 'Issues Detected';
|
934 |
-
} else {
|
935 |
-
$meta_value = '';
|
936 |
-
}
|
937 |
-
} elseif ( 'details' == $data ) {
|
938 |
-
$meta_value = str_replace( 'SUM_FINAL:', '', $meta_value );
|
939 |
-
}
|
940 |
-
}
|
941 |
-
$tok_value = $meta_value;
|
942 |
-
}
|
943 |
-
return $tok_value;
|
944 |
-
}
|
945 |
-
|
946 |
-
/**
|
947 |
-
* Get the Sucuri scan token value.
|
948 |
-
*
|
949 |
-
* @param object $record Object containing the record data.
|
950 |
-
* @param string $data Data to process.
|
951 |
-
*
|
952 |
-
* @return string Sucuri scan token value.
|
953 |
-
*/
|
954 |
-
private function get_sucuri_scan_token_value( $record, $data ) {
|
955 |
-
$tok_value = '';
|
956 |
-
$scan_data = $this->get_stream_meta_data( $record, 'scan_data' );
|
957 |
-
if ( ! empty( $scan_data ) ) {
|
958 |
-
$scan_data = maybe_unserialize( base64_decode( $scan_data ) ); // phpcs:ignore WordPress.PHP.DiscouragedPHPFunctions -- base64_encode required for backwards compatibility.
|
959 |
-
if ( is_array( $scan_data ) ) {
|
960 |
-
|
961 |
-
$blacklisted = $scan_data['blacklisted'];
|
962 |
-
$malware_exists = $scan_data['malware_exists'];
|
963 |
-
|
964 |
-
$status = array();
|
965 |
-
if ( $blacklisted ) {
|
966 |
-
$status[] = __( 'Site Blacklisted', 'mainwp-child' ); }
|
967 |
-
if ( $malware_exists ) {
|
968 |
-
$status[] = __( 'Site With Warnings', 'mainwp-child' ); }
|
969 |
-
|
970 |
-
if ( 'status' == $data ) {
|
971 |
-
$tok_value = count( $status ) > 0 ? implode( ', ', $status ) : __( 'Verified Clear', 'mainwp-child' );
|
972 |
-
} elseif ( 'webtrust' == $data ) {
|
973 |
-
$tok_value = $blacklisted ? __( 'Site Blacklisted', 'mainwp-child' ) : __( 'Trusted', 'mainwp-child' );
|
974 |
-
}
|
975 |
-
}
|
976 |
-
} else {
|
977 |
-
$tok_value = $this->get_stream_meta_data( $record, $data );
|
978 |
-
}
|
979 |
-
return $tok_value;
|
980 |
-
}
|
981 |
-
|
982 |
-
/**
|
983 |
-
* Get the Maintanence token value.
|
984 |
-
*
|
985 |
-
* @param object $record Object containing the record data.
|
986 |
-
* @param string $data Data to process.
|
987 |
-
*
|
988 |
-
* @return string Maintanence token value.
|
989 |
-
*/
|
990 |
-
private function get_mainwp_maintenance_token_value( $record, $data ) {
|
991 |
-
|
992 |
-
$maintenance_details = array(
|
993 |
-
'revisions' => __( 'Delete all post revisions', 'mainwp-child' ),
|
994 |
-
'revisions_max' => __( 'Delete all post revisions, except for the last:', 'mainwp-child' ),
|
995 |
-
'autodraft' => __( 'Delete all auto draft posts', 'mainwp-child' ),
|
996 |
-
'trashpost' => __( 'Delete trash posts', 'mainwp-child' ),
|
997 |
-
'spam' => __( 'Delete spam comments', 'mainwp-child' ),
|
998 |
-
'pending' => __( 'Delete pending comments', 'mainwp-child' ),
|
999 |
-
'trashcomment' => __( 'Delete trash comments', 'mainwp-child' ),
|
1000 |
-
'tags' => __( 'Delete tags with 0 posts associated', 'mainwp-child' ),
|
1001 |
-
'categories' => __( 'Delete categories with 0 posts associated', 'mainwp-child' ),
|
1002 |
-
'optimize' => __( 'Optimize database tables', 'mainwp-child' ),
|
1003 |
-
);
|
1004 |
-
|
1005 |
-
$meta_value = $this->get_stream_meta_data( $record, $data );
|
1006 |
-
$meta_value = explode( ',', $meta_value );
|
1007 |
-
|
1008 |
-
$details = array();
|
1009 |
-
|
1010 |
-
if ( is_array( $meta_value ) ) {
|
1011 |
-
foreach ( $meta_value as $mt ) {
|
1012 |
-
if ( isset( $maintenance_details[ $mt ] ) ) {
|
1013 |
-
if ( 'revisions_max' == $mt ) {
|
1014 |
-
$max_revisions = $this->get_stream_meta_data( $record, 'revisions' );
|
1015 |
-
$dtl = $maintenance_details['revisions_max'] . ' ' . $max_revisions;
|
1016 |
-
} else {
|
1017 |
-
$dtl = $maintenance_details[ $mt ];
|
1018 |
-
}
|
1019 |
-
$details[] = $dtl;
|
1020 |
-
}
|
1021 |
-
}
|
1022 |
-
}
|
1023 |
-
$tok_value = implode( ', ', $details );
|
1024 |
-
return $tok_value;
|
1025 |
-
}
|
1026 |
-
}
|
1 |
+
<?php
|
2 |
+
/**
|
3 |
+
* MainWP Client Reports Base
|
4 |
+
*
|
5 |
+
* MainWP Client Reprots Extension handler.
|
6 |
+
* Extension URL: https://mainwp.com/extension/client-reports/
|
7 |
+
*
|
8 |
+
* @package MainWP\Child
|
9 |
+
*/
|
10 |
+
|
11 |
+
namespace MainWP\Child;
|
12 |
+
|
13 |
+
/**
|
14 |
+
* Class MainWP_Client_Report_Base
|
15 |
+
*
|
16 |
+
* MainWP Client Reports extension handler, extened by the MainWP_Client_Report class.
|
17 |
+
*/
|
18 |
+
class MainWP_Client_Report_Base {
|
19 |
+
|
20 |
+
/**
|
21 |
+
* Public static variable to hold the single instance of the class.
|
22 |
+
*
|
23 |
+
* @var mixed Default null
|
24 |
+
*/
|
25 |
+
public static $instance = null;
|
26 |
+
|
27 |
+
/**
|
28 |
+
* Method get_class_name()
|
29 |
+
*
|
30 |
+
* Get class name.
|
31 |
+
*
|
32 |
+
* @return string __CLASS__ Class name.
|
33 |
+
*/
|
34 |
+
public static function get_class_name() {
|
35 |
+
return __CLASS__;
|
36 |
+
}
|
37 |
+
|
38 |
+
/**
|
39 |
+
* Public static variable to hold the single instance of the class.
|
40 |
+
*
|
41 |
+
* @var mixed Default null
|
42 |
+
*/
|
43 |
+
public static function instance() {
|
44 |
+
if ( null === self::$instance ) {
|
45 |
+
self::$instance = new self();
|
46 |
+
}
|
47 |
+
return self::$instance;
|
48 |
+
}
|
49 |
+
|
50 |
+
/**
|
51 |
+
* Convert context name of tokens to context name saved in child reports.
|
52 |
+
*
|
53 |
+
* @param string $context Context name to be converted.
|
54 |
+
*
|
55 |
+
* @return string $context Converted context name.
|
56 |
+
*/
|
57 |
+
public function get_compatible_context( $context ) {
|
58 |
+
// some context are not different.
|
59 |
+
$mapping_contexts = array(
|
60 |
+
'comment' => 'comments', // actual context values: post, page.
|
61 |
+
'plugin' => 'plugins',
|
62 |
+
'users' => 'profiles',
|
63 |
+
'user' => 'profiles',
|
64 |
+
'session' => 'sessions',
|
65 |
+
'setting' => 'settings',
|
66 |
+
'theme' => 'themes',
|
67 |
+
'posts' => 'post',
|
68 |
+
'pages' => 'page',
|
69 |
+
'widgets' => 'widgets',
|
70 |
+
'widget' => 'widgets',
|
71 |
+
'menu' => 'menus',
|
72 |
+
'backups' => 'backups',
|
73 |
+
'backup' => 'backups',
|
74 |
+
'sucuri' => 'sucuri_scan',
|
75 |
+
'maintenance' => 'mainwp_maintenance',
|
76 |
+
'wordfence' => 'wordfence_scan',
|
77 |
+
'backups' => 'backups',
|
78 |
+
'backup' => 'backups',
|
79 |
+
'media' => 'media',
|
80 |
+
);
|
81 |
+
|
82 |
+
$context = isset( $mapping_contexts[ $context ] ) ? $mapping_contexts[ $context ] : $context;
|
83 |
+
|
84 |
+
return strtolower( $context );
|
85 |
+
}
|
86 |
+
|
87 |
+
/**
|
88 |
+
* Get connector by compatible context.
|
89 |
+
*
|
90 |
+
* @param string $context Context name as reference.
|
91 |
+
*
|
92 |
+
* @return string $connector Required connector.
|
93 |
+
*/
|
94 |
+
public function get_connector_by_compatible_context( $context ) {
|
95 |
+
|
96 |
+
$connector = '';
|
97 |
+
|
98 |
+
$mapping_connectors = array(
|
99 |
+
'plugins' => 'installer',
|
100 |
+
'themes' => 'installer',
|
101 |
+
'wordpress' => 'installer', // phpcs:ignore -- wordpress -> WordPress.
|
102 |
+
'profiles' => 'users',
|
103 |
+
'comments' => 'comments',
|
104 |
+
'settings' => 'settings',
|
105 |
+
'post' => 'posts',
|
106 |
+
'page' => 'posts',
|
107 |
+
'widgets' => 'widgets',
|
108 |
+
'menus' => 'menus',
|
109 |
+
'backups' => 'mainwp_backups',
|
110 |
+
'sucuri_scan' => 'mainwp_sucuri',
|
111 |
+
'mainwp_maintenance' => 'mainwp_maintenance',
|
112 |
+
'wordfence_scan' => 'mainwp_wordfence',
|
113 |
+
'media' => 'media',
|
114 |
+
);
|
115 |
+
|
116 |
+
if ( isset( $mapping_connectors[ $context ] ) ) {
|
117 |
+
$connector = $mapping_connectors[ $context ];
|
118 |
+
}
|
119 |
+
|
120 |
+
return $connector;
|
121 |
+
}
|
122 |
+
|
123 |
+
/**
|
124 |
+
* Get compatible action by context.
|
125 |
+
*
|
126 |
+
* @param string $action Action name as reference.
|
127 |
+
* @param string $context Context name as reference.
|
128 |
+
*
|
129 |
+
* @return string $action Compatible action.
|
130 |
+
*/
|
131 |
+
public function get_compatible_action( $action, $context = '' ) {
|
132 |
+
|
133 |
+
$mapping_actions = array(
|
134 |
+
'restored' => 'untrashed',
|
135 |
+
'spam' => 'spammed',
|
136 |
+
);
|
137 |
+
|
138 |
+
if ( isset( $mapping_actions[ $action ] ) ) {
|
139 |
+
return $mapping_actions[ $action ];
|
140 |
+
}
|
141 |
+
|
142 |
+
if ( 'mainwp_maintenance' == $context ) {
|
143 |
+
if ( 'process' == $action ) {
|
144 |
+
$action = 'maintenance';
|
145 |
+
}
|
146 |
+
} elseif ( 'sucuri_scan' == $context ) {
|
147 |
+
if ( 'checks' == $action ) {
|
148 |
+
$action = 'sucuri_scan';
|
149 |
+
}
|
150 |
+
} elseif ( 'wordfence_scan' == $context ) {
|
151 |
+
if ( 'scan' == $action ) {
|
152 |
+
$action = 'wordfence_scan';
|
153 |
+
}
|
154 |
+
}
|
155 |
+
return $action;
|
156 |
+
}
|
157 |
+
|
158 |
+
/**
|
159 |
+
* Get the Stream parameters.
|
160 |
+
*
|
161 |
+
* @param array $other_tokens An array containing other tokens.
|
162 |
+
* @param array $sections An array containing sections.
|
163 |
+
*
|
164 |
+
* @return array Arguments array.
|
165 |
+
*
|
166 |
+
* @uses \MainWP\Child\MainWP_Child_Branding::is_branding()
|
167 |
+
*/
|
168 |
+
public function get_stream_get_params( $other_tokens, $sections ) {
|
169 |
+
|
170 |
+
$allowed_params = array(
|
171 |
+
'connector',
|
172 |
+
'context',
|
173 |
+
'action',
|
174 |
+
'author',
|
175 |
+
'author_role',
|
176 |
+
'object_id',
|
177 |
+
'search',
|
178 |
+
'date',
|
179 |
+
'date_from',
|
180 |
+
'date_to',
|
181 |
+
'record__in',
|
182 |
+
'blog_id',
|
183 |
+
'ip',
|
184 |
+
);
|
185 |
+
|
186 |
+
$args = array();
|
187 |
+
foreach ( $allowed_params as $param ) {
|
188 |
+
$paramval = \wp_mainwp_stream_filter_input( INPUT_POST, $param );
|
189 |
+
if ( $paramval || '0' === $paramval ) {
|
190 |
+
$args[ $param ] = $paramval;
|
191 |
+
}
|
192 |
+
}
|
193 |
+
|
194 |
+
foreach ( $args as $arg => $val ) {
|
195 |
+
if ( ! in_array( $arg, $allowed_params ) ) {
|
196 |
+
unset( $args[ $arg ] );
|
197 |
+
}
|
198 |
+
}
|
199 |
+
|
200 |
+
$exclude_connector_posts = $this->get_stream_get_not_in_params( $sections, $other_tokens );
|
201 |
+
if ( $exclude_connector_posts ) {
|
202 |
+
$args['connector__not_in'] = array( 'posts' );
|
203 |
+
}
|
204 |
+
|
205 |
+
$args['action__not_in'] = array( 'login' );
|
206 |
+
|
207 |
+
$args['with-meta'] = 1;
|
208 |
+
|
209 |
+
if ( isset( $args['date_from'] ) ) {
|
210 |
+
$args['date_from'] = date( 'Y-m-d', $args['date_from'] ); // phpcs:ignore -- required to achieve desired results, pull request solutions appreciated.
|
211 |
+
}
|
212 |
+
|
213 |
+
if ( isset( $args['date_to'] ) ) {
|
214 |
+
$args['date_to'] = date( 'Y-m-d', $args['date_to'] ); // phpcs:ignore -- required to achieve desired results, pull request solutions appreciated.
|
215 |
+
}
|
216 |
+
|
217 |
+
if ( MainWP_Child_Branding::instance()->is_branding() ) {
|
218 |
+
$args['hide_child_reports'] = 1;
|
219 |
+
}
|
220 |
+
|
221 |
+
$args['records_per_page'] = 9999;
|
222 |
+
|
223 |
+
return $args;
|
224 |
+
}
|
225 |
+
|
226 |
+
/**
|
227 |
+
* Get the Stream excluded parameters.
|
228 |
+
*
|
229 |
+
* @param array $sections An array containing sections.
|
230 |
+
* @param array $other_tokens An array containing other tokens.
|
231 |
+
*
|
232 |
+
* @return bool true|false
|
233 |
+
*/
|
234 |
+
private function get_stream_get_not_in_params( $sections, $other_tokens ) {
|
235 |
+
|
236 |
+
$exclude_connector_posts = true;
|
237 |
+
|
238 |
+
$parts = array( 'header', 'body', 'footer' );
|
239 |
+
foreach ( $parts as $part ) {
|
240 |
+
if ( isset( $sections[ $part ] ) && isset( $sections[ $part ]['section_token'] ) && is_array( $sections[ $part ]['section_token'] ) ) {
|
241 |
+
foreach ( $sections[ $part ]['section_token'] as $sec ) {
|
242 |
+
if ( false !== strpos( $sec, '[section.posts' ) || false !== strpos( $sec, '[section.pages' ) ) {
|
243 |
+
$exclude_connector_posts = false;
|
244 |
+
break;
|
245 |
+
}
|
246 |
+
}
|
247 |
+
}
|
248 |
+
if ( ! $exclude_connector_posts ) {
|
249 |
+
break;
|
250 |
+
}
|
251 |
+
}
|
252 |
+
|
253 |
+
if ( $exclude_connector_posts ) {
|
254 |
+
foreach ( $parts as $part ) {
|
255 |
+
if ( isset( $other_tokens[ $part ] ) && is_array( $other_tokens[ $part ] ) ) {
|
256 |
+
foreach ( $other_tokens[ $part ] as $sec ) {
|
257 |
+
if ( false !== strpos( $sec, '[post.' ) || false !== strpos( $sec, '[page.' ) ) {
|
258 |
+
$exclude_connector_posts = false;
|
259 |
+
break;
|
260 |
+
}
|
261 |
+
}
|
262 |
+
}
|
263 |
+
if ( ! $exclude_connector_posts ) {
|
264 |
+
break;
|
265 |
+
}
|
266 |
+
}
|
267 |
+
}
|
268 |
+
return $exclude_connector_posts;
|
269 |
+
}
|
270 |
+
|
271 |
+
/**
|
272 |
+
* Get the Stream other tokens.
|
273 |
+
*
|
274 |
+
* @param array $records An array containg actions records.
|
275 |
+
* @param array $other_tokens An array containing other tokens.
|
276 |
+
* @param array $skip_records An array containing skipped records.
|
277 |
+
*
|
278 |
+
* @return array Other tokens data.
|
279 |
+
*/
|
280 |
+
public function get_stream_others_tokens( $records, $other_tokens, $skip_records ) {
|
281 |
+
$other_tokens_data = array();
|
282 |
+
$parts = array( 'header', 'body', 'footer' );
|
283 |
+
foreach ( $parts as $part ) {
|
284 |
+
if ( isset( $other_tokens[ $part ] ) && is_array( $other_tokens[ $part ] ) ) {
|
285 |
+
$other_tokens_data[ $part ] = $this->get_other_tokens_data( $records, $other_tokens[ $part ], $skip_records );
|
286 |
+
}
|
287 |
+
}
|
288 |
+
return $other_tokens_data;
|
289 |
+
}
|
290 |
+
|
291 |
+
/**
|
292 |
+
* Get the Stream sections data.
|
293 |
+
*
|
294 |
+
* @param array $records An array containg actions records.
|
295 |
+
* @param array $sections An array containing sections.
|
296 |
+
* @param array $skip_records An array containing skipped records.
|
297 |
+
*
|
298 |
+
* @return array Sections data.
|
299 |
+
*/
|
300 |
+
public function get_stream_sections_data( $records, $sections, $skip_records ) {
|
301 |
+
$sections_data = array();
|
302 |
+
$parts = array( 'header', 'body', 'footer' );
|
303 |
+
foreach ( $parts as $part ) {
|
304 |
+
if ( isset( $sections[ $part ] ) && is_array( $sections[ $part ] ) && ! empty( $sections[ $part ] ) ) {
|
305 |
+
foreach ( $sections[ $part ]['section_token'] as $index => $sec ) {
|
306 |
+
$tokens = $sections[ $part ]['section_content_tokens'][ $index ];
|
307 |
+
$sections_data[ $part ][ $index ] = $this->get_section_loop_data( $records, $tokens, $sec, $skip_records );
|
308 |
+
}
|
309 |
+
}
|
310 |
+
}
|
311 |
+
return $sections_data;
|
312 |
+
}
|
313 |
+
|
314 |
+
/**
|
315 |
+
* Fix logging for posts creation action.
|
316 |
+
*
|
317 |
+
* @param array $records An array containg actions records.
|
318 |
+
* @param array $skip_records An array containg records to skip.
|
319 |
+
*/
|
320 |
+
protected function fix_logs_posts_created( &$records, &$skip_records ) {
|
321 |
+
|
322 |
+
$args = array(
|
323 |
+
'post_type' => 'post',
|
324 |
+
'post_status' => 'publish',
|
325 |
+
'date_query' => array(
|
326 |
+
'column' => 'post_date',
|
327 |
+
'after' => $args['date_from'],
|
328 |
+
'before' => $args['date_to'],
|
329 |
+
),
|
330 |
+
);
|
331 |
+
|
332 |
+
$result = new \WP_Query( $args );
|
333 |
+
$records_created_posts = $result->posts;
|
334 |
+
|
335 |
+
if ( $records_created_posts ) {
|
336 |
+
|
337 |
+
$count_records = count( $records );
|
338 |
+
for ( $i = 0; $i < $count_records; $i++ ) {
|
339 |
+
$record = $records[ $i ];
|
340 |
+
if ( 'posts' == $record->connector && 'post' == $record->context && 'created' == $record->action ) {
|
341 |
+
if ( ! in_array( $record->ID, $skip_records ) ) {
|
342 |
+
$skip_records[] = $record->ID;
|
343 |
+
}
|
344 |
+
}
|
345 |
+
}
|
346 |
+
|
347 |
+
$post_authors = array();
|
348 |
+
|
349 |
+
foreach ( $records_created_posts as $_post ) {
|
350 |
+
$au_id = $_post->post_author;
|
351 |
+
if ( ! isset( $post_authors[ $au_id ] ) ) {
|
352 |
+
$au = get_user_by( 'id', $au_id );
|
353 |
+
$post_authors[ $au_id ] = $au->display_name;
|
354 |
+
}
|
355 |
+
$au_name = $post_authors[ $au_id ];
|
356 |
+
|
357 |
+
// simulate logging created posts record.
|
358 |
+
$stdObj = new \stdClass();
|
359 |
+
$stdObj->ID = 0; // simulate ID value.
|
360 |
+
$stdObj->connector = 'posts';
|
361 |
+
$stdObj->context = 'post';
|
362 |
+
$stdObj->action = 'created';
|
363 |
+
$stdObj->created = $_post->post_date;
|
364 |
+
$stdObj->meta = array(
|
365 |
+
'post_title' => array( $_post->post_title ),
|
366 |
+
'user_meta' => array( $au_name ),
|
367 |
+
);
|
368 |
+
|
369 |
+
$records[] = $stdObj;
|
370 |
+
}
|
371 |
+
}
|
372 |
+
}
|
373 |
+
|
374 |
+
/**
|
375 |
+
* Get the other tokens data.
|
376 |
+
*
|
377 |
+
* @param array $records An array containg actions records.
|
378 |
+
* @param array $tokens An array containg the tokens list.
|
379 |
+
* @param array $skip_records An array containg records to skip.
|
380 |
+
*
|
381 |
+
* @return array An array containg the tokens values.
|
382 |
+
*/
|
383 |
+
public function get_other_tokens_data( $records, $tokens, &$skip_records ) {
|
384 |
+
|
385 |
+
$token_values = array();
|
386 |
+
|
387 |
+
if ( ! is_array( $tokens ) ) {
|
388 |
+
$tokens = array();
|
389 |
+
}
|
390 |
+
|
391 |
+
$backups_created_time_to_fix = array();
|
392 |
+
|
393 |
+
foreach ( $tokens as $token ) {
|
394 |
+
if ( isset( $token_values[ $token ] ) ) {
|
395 |
+
continue;
|
396 |
+
}
|
397 |
+
$str_tmp = str_replace( array( '[', ']' ), '', $token );
|
398 |
+
$array_tmp = explode( '.', $str_tmp );
|
399 |
+
if ( is_array( $array_tmp ) ) {
|
400 |
+
$context = '';
|
401 |
+
$action = '';
|
402 |
+
$data = '';
|
403 |
+
if ( 2 === count( $array_tmp ) ) {
|
404 |
+
list( $context, $data ) = $array_tmp;
|
405 |
+
} elseif ( 3 === count( $array_tmp ) ) {
|
406 |
+
list( $context, $action, $data ) = $array_tmp;
|
407 |
+
}
|
408 |
+
$context = $this->get_compatible_context( $context );
|
409 |
+
// to compatible with new version of child report.
|
410 |
+
// to check condition for grabbing report data.
|
411 |
+
$connector = $this->get_connector_by_compatible_context( $context );
|
412 |
+
$action = $this->get_compatible_action( $action, $context );
|
413 |
+
// custom values.
|
414 |
+
if ( 'profiles' == $context ) {
|
415 |
+
if ( 'created' == $action || 'deleted' == $action ) {
|
416 |
+
$context = 'users';
|
417 |
+
}
|
418 |
+
}
|
419 |
+
switch ( $data ) {
|
420 |
+
case 'count':
|
421 |
+
$token_values[ $token ] = $this->get_other_tokens_count( $records, $connector, $context, $action, $skip_records, $backups_created_time_to_fix );
|
422 |
+
break;
|
423 |
+
}
|
424 |
+
}
|
425 |
+
}
|
426 |
+
|
427 |
+
return $token_values;
|
428 |
+
}
|
429 |
+
|
430 |
+
/**
|
431 |
+
* Get the other tokens count.
|
432 |
+
*
|
433 |
+
* @param object $records Object containng reports records.
|
434 |
+
* @param string $connector Record connector.
|
435 |
+
* @param string $context Record context.
|
436 |
+
* @param string $action Record action.
|
437 |
+
* @param array $skip_records Records to skip.
|
438 |
+
* @param array $backups_created_time_to_fix Backups created time.
|
439 |
+
*
|
440 |
+
* @return int The count number.
|
441 |
+
*/
|
442 |
+
private function get_other_tokens_count( $records, $connector, $context, $action, &$skip_records, &$backups_created_time_to_fix ) { // phpcs:ignore -- Current complexity is the only way to achieve desired results, pull request solutions appreciated.
|
443 |
+
$count = 0;
|
444 |
+
|
445 |
+
foreach ( $records as $record ) {
|
446 |
+
// check connector.
|
447 |
+
if ( 'editor' == $record->connector ) {
|
448 |
+
if ( ! in_array( $context, array( 'plugins', 'themes' ) ) || 'updated' !== $action ) {
|
449 |
+
continue;
|
450 |
+
}
|
451 |
+
} elseif ( $connector !== $record->connector ) {
|
452 |
+
continue;
|
453 |
+
}
|
454 |
+
|
455 |
+
$valid_context = false;
|
456 |
+
// check context.
|
457 |
+
if ( 'comments' == $context ) { // multi values.
|
458 |
+
$comment_contexts = array( 'post', 'page' );
|
459 |
+
if ( ! in_array( $record->context, $comment_contexts ) ) {
|
460 |
+
continue;
|
461 |
+
}
|
462 |
+
$valid_context = true;
|
463 |
+
} elseif ( 'post' === $context && 'created' === $action ) {
|
464 |
+
if ( in_array( $record->ID, $skip_records ) ) {
|
465 |
+
continue;
|
466 |
+
}
|
467 |
+
$valid_context = true;
|
468 |
+
} elseif ( 'menus' == $context ) {
|
469 |
+
$valid_context = true; // ok, pass, don't check context.
|
470 |
+
} elseif ( 'editor' == $record->connector ) {
|
471 |
+
$valid_context = true; // ok, pass, checked above.
|
472 |
+
} elseif ( 'media' == $connector && 'media' == $record->connector ) {
|
473 |
+
$valid_context = true; // ok, pass, do not check context.
|
474 |
+
} elseif ( 'widgets' == $connector && 'widgets' == $record->connector ) {
|
475 |
+
$valid_context = true; // ok, pass, don't check context.
|
476 |
+
}
|
477 |
+
|
478 |
+
$valid_context = ( $valid_context || strtolower( $record->context ) == $context ) ? true : false;
|
479 |
+
if ( ! $valid_context ) {
|
480 |
+
continue;
|
481 |
+
}
|
482 |
+
// custom action value.
|
483 |
+
if ( 'widgets' == $connector ) {
|
484 |
+
if ( 'deleted' == $action ) {
|
485 |
+
$action = 'removed'; // action saved in database.
|
486 |
+
}
|
487 |
+
}
|
488 |
+
|
489 |
+
// check action.
|
490 |
+
if ( 'backups' === $context ) {
|
491 |
+
if ( ! $this->is_backup_action( $record->action ) ) {
|
492 |
+
continue;
|
493 |
+
}
|
494 |
+
$created = strtotime( $record->created );
|
495 |
+
if ( in_array( $created, $backups_created_time_to_fix ) ) {
|
496 |
+
if ( ! in_array( $record->ID, $skip_records ) ) {
|
497 |
+
$skip_records[] = $record->ID;
|
498 |
+
}
|
499 |
+
continue;
|
500 |
+
} else {
|
501 |
+
$backups_created_time_to_fix[] = $created;
|
502 |
+
}
|
503 |
+
} else {
|
504 |
+
if ( $action !== $record->action ) {
|
505 |
+
continue;
|
506 |
+
}
|
507 |
+
|
508 |
+
if ( 'updated' === $action && ( 'post' === $context || 'page' === $context ) ) {
|
509 |
+
$new_status = $this->get_stream_meta_data( $record, 'new_status' );
|
510 |
+
if ( 'draft' === $new_status ) {
|
511 |
+
continue;
|
512 |
+
}
|
513 |
+
} elseif ( 'updated' === $action && ( 'themes' === $context || 'plugins' === $context ) ) {
|
514 |
+
$name = $this->get_stream_meta_data( $record, 'name' );
|
515 |
+
if ( empty( $name ) ) {
|
516 |
+
if ( ! in_array( $record->ID, $skip_records ) ) {
|
517 |
+
$skip_records[] = $record->ID;
|
518 |
+
}
|
519 |
+
continue;
|
520 |
+
} else {
|
521 |
+
$old_version = $this->get_stream_meta_data( $record, 'old_version' );
|
522 |
+
$version = $this->get_stream_meta_data( $record, 'version' );
|
523 |
+
if ( version_compare( $version, $old_version, '<=' ) ) {
|
524 |
+
if ( ! in_array( $record->ID, $skip_records ) ) {
|
525 |
+
$skip_records[] = $record->ID;
|
526 |
+
}
|
527 |
+
continue;
|
528 |
+
}
|
529 |
+
}
|
530 |
+
}
|
531 |
+
}
|
532 |
+
$count ++;
|
533 |
+
}
|
534 |
+
return $count;
|
535 |
+
}
|
536 |
+
|
537 |
+
/**
|
538 |
+
* Get the section loop data.
|
539 |
+
*
|
540 |
+
* @param object $records Object containng reports records.
|
541 |
+
* @param array $tokens An array containing report tokens.
|
542 |
+
* @param string $section Section name.
|
543 |
+
* @param array $skip_records Records to skip.
|
544 |
+
*
|
545 |
+
* @return array Section loop records.
|
546 |
+
*/
|
547 |
+
public function get_section_loop_data( $records, $tokens, $section, $skip_records = array() ) {
|
548 |
+
|
549 |
+
$context = '';
|
550 |
+
$action = '';
|
551 |
+
|
552 |
+
$str_tmp = str_replace( array( '[', ']' ), '', $section );
|
553 |
+
$array_tmp = explode( '.', $str_tmp );
|
554 |
+
if ( is_array( $array_tmp ) ) {
|
555 |
+
if ( 2 === count( $array_tmp ) ) {
|
556 |
+
list( $str1, $context ) = $array_tmp;
|
557 |
+
} elseif ( 3 === count( $array_tmp ) ) {
|
558 |
+
list( $str1, $context, $action ) = $array_tmp;
|
559 |
+
}
|
560 |
+
}
|
561 |
+
|
562 |
+
// get db $context value by mapping.
|
563 |
+
$context = $this->get_compatible_context( $context );
|
564 |
+
// to compatible with new version of child report.
|
565 |
+
// to check condition for grabbing report data.
|
566 |
+
$connector = $this->get_connector_by_compatible_context( $context );
|
567 |
+
|
568 |
+
$action = $this->get_compatible_action( $action, $context );
|
569 |
+
|
570 |
+
if ( 'profiles' == $context ) {
|
571 |
+
if ( 'created' == $action || 'deleted' == $action ) {
|
572 |
+
$context = 'users';
|
573 |
+
}
|
574 |
+
}
|
575 |
+
|
576 |
+
return $this->get_section_loop_records( $records, $tokens, $connector, $context, $action, $skip_records );
|
577 |
+
}
|
578 |
+
|
579 |
+
/**
|
580 |
+
* Get the section loop records.
|
581 |
+
*
|
582 |
+
* @param object $records Object containng reports records.
|
583 |
+
* @param array $tokens An array containing report tokens.
|
584 |
+
* @param string $connector Record connector.
|
585 |
+
* @param string $context Record context.
|
586 |
+
* @param string $action Record action.
|
587 |
+
* @param array $skip_records Records to skip.
|
588 |
+
*
|
589 |
+
* @return array Loops.
|
590 |
+
*/
|
591 |
+
public function get_section_loop_records( $records, $tokens, $connector, $context, $action, $skip_records ) { // phpcs:ignore -- Current complexity is the only way to achieve desired results, pull request solutions appreciated.
|
592 |
+
|
593 |
+
$loops = array();
|
594 |
+
$loop_count = 0;
|
595 |
+
|
596 |
+
$max_items_get = ( isset( $_POST['max_items_get'] ) && ! empty( $_POST['max_items_get'] ) ) ? intval( $_POST['max_items_get'] ) : 0;
|
597 |
+
$limit_connectors = ( isset( $_POST['limit_reports'] ) && ! empty( $_POST['limit_reports'] ) ) ? intval( $_POST['limit_reports'] ) : array();
|
598 |
+
|
599 |
+
if ( ! is_array( $limit_connectors ) || empty( $limit_connectors ) ) {
|
600 |
+
$limit_connectors = array( 'mainwp_sucuri', 'mainwp_maintenance', 'mainwp_backups' );
|
601 |
+
}
|
602 |
+
|
603 |
+
foreach ( $records as $record ) {
|
604 |
+
|
605 |
+
if ( in_array( $record->ID, $skip_records ) ) {
|
606 |
+
continue;
|
607 |
+
}
|
608 |
+
|
609 |
+
if ( 'editor' == $record->connector ) {
|
610 |
+
if ( ! in_array( $context, array( 'plugins', 'themes' ) ) || 'updated' !== $action ) {
|
611 |
+
continue;
|
612 |
+
}
|
613 |
+
} elseif ( $connector !== $record->connector ) {
|
614 |
+
continue;
|
615 |
+
}
|
616 |
+
|
617 |
+
$valid_context = false;
|
618 |
+
|
619 |
+
if ( 'comments' == $context ) {
|
620 |
+
$comment_contexts = array( 'post', 'page' );
|
621 |
+
if ( ! in_array( $record->context, $comment_contexts ) ) {
|
622 |
+
continue;
|
623 |
+
}
|
624 |
+
$valid_context = true;
|
625 |
+
} elseif ( 'menus' == $context ) {
|
626 |
+
$valid_context = true; // ok, pass, don't check context.
|
627 |
+
} elseif ( 'editor' == $record->connector ) {
|
628 |
+
$valid_context = true; // ok, pass, checked above.
|
629 |
+
} elseif ( 'media' == $connector && 'media' == $record->connector ) {
|
630 |
+
$valid_context = true; // ok, pass, do not check context.
|
631 |
+
} elseif ( 'widgets' == $connector && 'widgets' == $record->connector ) {
|
632 |
+
$valid_context = true; // ok, pass, don't check context.
|
633 |
+
}
|
634 |
+
|
635 |
+
$valid_context = ( $valid_context || strtolower( $record->context ) == $context ) ? true : false;
|
636 |
+
|
637 |
+
if ( ! $valid_context ) {
|
638 |
+
continue;
|
639 |
+
}
|
640 |
+
|
641 |
+
// custom action value!
|
642 |
+
if ( 'widgets' == $connector ) {
|
643 |
+
if ( 'deleted' == $action ) {
|
644 |
+
$action = 'removed'; // action saved in database!
|
645 |
+
}
|
646 |
+
}
|
647 |
+
|
648 |
+
if ( 'backups' == $context ) {
|
649 |
+
if ( ! $this->is_backup_action( $record->action ) ) {
|
650 |
+
continue;
|
651 |
+
}
|
652 |
+
} elseif ( $action !== $record->action ) {
|
653 |
+
continue;
|
654 |
+
}
|
655 |
+
|
656 |
+
if ( 'updated' === $action && ( 'post' === $context || 'page' === $context ) ) {
|
657 |
+
$new_status = $this->get_stream_meta_data( $record, 'new_status' );
|
658 |
+
if ( 'draft' === $new_status ) { // avoid auto save post!
|
659 |
+
continue;
|
660 |
+
}
|
661 |
+
}
|
662 |
+
$token_values = $this->get_section_loop_token_values( $record, $context, $tokens );
|
663 |
+
if ( ! empty( $token_values ) ) {
|
664 |
+
$loops[ $loop_count ] = $token_values;
|
665 |
+
$loop_count ++;
|
666 |
+
}
|
667 |
+
|
668 |
+
if ( $max_items_get && ( $loop_count >= $max_items_get ) ) {
|
669 |
+
if ( in_array( $connector, $limit_connectors ) ) {
|
670 |
+
break;
|
671 |
+
}
|
672 |
+
}
|
673 |
+
}
|
674 |
+
return $loops;
|
675 |
+
}
|
676 |
+
|
677 |
+
/**
|
678 |
+
* Check if it's backup action.
|
679 |
+
*
|
680 |
+
* @param string $action Record action.
|
681 |
+
*
|
682 |
+
* @return bool If backup action, return trie, if not, false.
|
683 |
+
*/
|
684 |
+
public function is_backup_action( $action ) {
|
685 |
+
if ( in_array( $action, array( 'mainwp_backup', 'backupbuddy_backup', 'backupwordpress_backup', 'backwpup_backup', 'updraftplus_backup', 'wptimecapsule_backup', 'wpvivid_backup' ) ) ) {
|
686 |
+
return true;
|
687 |
+
}
|
688 |
+
return false;
|
689 |
+
}
|
690 |
+
|
691 |
+
/**
|
692 |
+
* Get the section loop token values.
|
693 |
+
*
|
694 |
+
* @param object $record Object containing the record data.
|
695 |
+
* @param string $context Record context.
|
696 |
+
* @param array $tokens An array containg the report tokens.
|
697 |
+
*
|
698 |
+
* @return array Token values.
|
699 |
+
*
|
700 |
+
* @uses \MainWP\Child\MainWP_Helper::log_debug()
|
701 |
+
*/
|
702 |
+
private function get_section_loop_token_values( $record, $context, $tokens ) {
|
703 |
+
|
704 |
+
$token_values = array();
|
705 |
+
foreach ( $tokens as $token ) {
|
706 |
+
$data = '';
|
707 |
+
$token_name = str_replace( array( '[', ']' ), '', $token );
|
708 |
+
$array_tmp = explode( '.', $token_name );
|
709 |
+
|
710 |
+
if ( 'user.name' === $token_name ) {
|
711 |
+
$data = 'display_name';
|
712 |
+
} else {
|
713 |
+
if ( 1 === count( $array_tmp ) ) {
|
714 |
+
list( $data ) = $array_tmp;
|
715 |
+
} elseif ( 2 === count( $array_tmp ) ) {
|
716 |
+
list( $str1, $data ) = $array_tmp;
|
717 |
+
} elseif ( 3 === count( $array_tmp ) ) {
|
718 |
+
list( $str1, $str2, $data ) = $array_tmp;
|
719 |
+
}
|
720 |
+
|
721 |
+
if ( 'version' === $data ) {
|
722 |
+
if ( 'old' === $str2 ) {
|
723 |
+
$data = 'old_version';
|
724 |
+
} elseif ( 'current' === $str2 && 'wordpress' === $str1 ) { // phpcs:ignore -- wordpress -> WordPress.
|
725 |
+
$data = 'new_version';
|
726 |
+
}
|
727 |
+
}
|
728 |
+
}
|
729 |
+
|
730 |
+
if ( 'role' === $data ) {
|
731 |
+
$data = 'roles';
|
732 |
+
}
|
733 |
+
|
734 |
+
$tok_value = $this->get_section_token_value( $record, $data, $context, $token );
|
735 |
+
|
736 |
+
$token_values[ $token ] = $tok_value;
|
737 |
+
|
738 |
+
if ( empty( $tok_value ) ) {
|
739 |
+
$msg = 'MainWP Child Report:: skip empty value :: token :: ' . $token . ' :: record :: ' . print_r( $record, true ); // phpcs:ignore -- required to achieve desired results, pull request solutions appreciated.
|
740 |
+
MainWP_Helper::log_debug( $msg );
|
741 |
+
}
|
742 |
+
}
|
743 |
+
return $token_values;
|
744 |
+
}
|
745 |
+
|
746 |
+
/**
|
747 |
+
* Get the section token value.
|
748 |
+
*
|
749 |
+
* @param object $record Object containing the record data.
|
750 |
+
* @param string $data Data to process.
|
751 |
+
* @param string $context Record context.
|
752 |
+
* @param string $token Requested token.
|
753 |
+
*
|
754 |
+
* @return array Token value.
|
755 |
+
*
|
756 |
+
* @uses \MainWP\Child\MainWP_Helper::format_date()
|
757 |
+
* @uses \MainWP\Child\MainWP_Helper::format_time()
|
758 |
+
*/
|
759 |
+
public function get_section_token_value( $record, $data, $context, $token ) { // phpcs:ignore -- Current complexity is the only way to achieve desired results, pull request solutions appreciated.
|
760 |
+
$tok_value = '';
|
761 |
+
switch ( $data ) {
|
762 |
+
case 'ID':
|
763 |
+
$tok_value = $record->ID;
|
764 |
+
break;
|
765 |
+
case 'date':
|
766 |
+
$tok_value = MainWP_Helper::format_date( MainWP_Helper::get_timestamp( strtotime( $record->created ) ) );
|
767 |
+
break;
|
768 |
+
case 'time':
|
769 |
+
$tok_value = MainWP_Helper::format_time( MainWP_Helper::get_timestamp( strtotime( $record->created ) ) );
|
770 |
+
break;
|
771 |
+
case 'area':
|
772 |
+
$data = 'sidebar_name';
|
773 |
+
$tok_value = $this->get_stream_meta_data( $record, $data );
|
774 |
+
break;
|
775 |
+
case 'name':
|
776 |
+
case 'version':
|
777 |
+
case 'old_version':
|
778 |
+
case 'new_version':
|
779 |
+
case 'display_name':
|
780 |
+
case 'roles':
|
781 |
+
if ( 'name' == $data ) {
|
782 |
+
if ( 'profiles' == $context ) {
|
783 |
+
$data = 'display_name';
|
784 |
+
}
|
785 |
+
}
|
786 |
+
$tok_value = $this->get_stream_meta_data( $record, $data );
|
787 |
+
break;
|
788 |
+
case 'title':
|
789 |
+
if ( 'comments' === $context ) {
|
790 |
+
$tok_value = $record->summary;
|
791 |
+
} else {
|
792 |
+
if ( 'page' === $context || 'post' === $context ) {
|
793 |
+
$data = 'post_title';
|
794 |
+
} elseif ( 'menus' === $record->connector ) {
|
795 |
+
$data = 'name';
|
796 |
+
}
|
797 |
+
$tok_value = $this->get_stream_meta_data( $record, $data );
|
798 |
+
}
|
799 |
+
break;
|
800 |
+
case 'author':
|
801 |
+
$tok_value = $this->get_author_data_token_value( $record, $connector, $context, $data );
|
802 |
+
|
803 |
+
break;
|
804 |
+
case 'status':
|
805 |
+
case 'webtrust':
|
806 |
+
$value = '';
|
807 |
+
if ( 'sucuri_scan' === $context ) {
|
808 |
+
$value = $this->get_sucuri_scan_token_value( $record, $data );
|
809 |
+
}
|
810 |
+
$tok_value = $value;
|
811 |
+
break;
|
812 |
+
case 'details':
|
813 |
+
case 'result':
|
814 |
+
$tok_value = $this->get_result_data_token_value( $record, $context, $data );
|
815 |
+
break;
|
816 |
+
case 'type':
|
817 |
+
if ( 'backups' === $context ) {
|
818 |
+
$tok_value = $this->get_stream_meta_data( $record, $data );
|
819 |
+
} else {
|
820 |
+
$tok_value = $token;
|
821 |
+
}
|
822 |
+
break;
|
823 |
+
default:
|
824 |
+
$tok_value = 'N/A';
|
825 |
+
break;
|
826 |
+
}
|
827 |
+
return $tok_value;
|
828 |
+
}
|
829 |
+
|
830 |
+
/**
|
831 |
+
* Get the Stream meta data for a certain record.
|
832 |
+
*
|
833 |
+
* @param object $record Object containing the record data.
|
834 |
+
* @param string $data Data to process.
|
835 |
+
*
|
836 |
+
* @return string Return the meta data value.
|
837 |
+
*/
|
838 |
+
public function get_stream_meta_data( $record, $data ) {
|
839 |
+
|
840 |
+
if ( empty( $record ) ) {
|
841 |
+
return '';
|
842 |
+
}
|
843 |
+
|
844 |
+
$meta_key = $data;
|
845 |
+
|
846 |
+
$value = '';
|
847 |
+
|
848 |
+
if ( isset( $record->meta ) ) {
|
849 |
+
$meta = $record->meta;
|
850 |
+
|
851 |
+
if ( isset( $meta[ $meta_key ] ) ) {
|
852 |
+
$value = $meta[ $meta_key ];
|
853 |
+
$value = ( 'user_meta' == $meta_key && isset( $value[1] ) ) ? $value[1] : current( $value );
|
854 |
+
|
855 |
+
if ( 'author_meta' === $meta_key ) {
|
856 |
+
$value = maybe_unserialize( $value );
|
857 |
+
if ( is_array( $value ) ) {
|
858 |
+
$value = $value['display_name'];
|
859 |
+
// fix empty author value!
|
860 |
+
if ( empty( $value ) ) {
|
861 |
+
if ( isset( $value['agent'] ) && ! empty( $value['agent'] ) ) {
|
862 |
+
$value = $value['agent'];
|
863 |
+
}
|
864 |
+
}
|
865 |
+
}
|
866 |
+
if ( ! is_string( $value ) ) {
|
867 |
+
$value = '';
|
868 |
+
}
|
869 |
+
}
|
870 |
+
}
|
871 |
+
}
|
872 |
+
|
873 |
+
return $value;
|
874 |
+
}
|
875 |
+
|
876 |
+
/**
|
877 |
+
* Get the author data token value.
|
878 |
+
*
|
879 |
+
* @param object $record Object containing the record data.
|
880 |
+
* @param string $connector Record connector.
|
881 |
+
* @param string $context Record context.
|
882 |
+
* @param string $data Data to process.
|
883 |
+
*
|
884 |
+
* @return string Author data token value.
|
885 |
+
*/
|
886 |
+
private function get_author_data_token_value( $record, $connector, $context, $data ) {
|
887 |
+
if ( 'comment' == $connector ) {
|
888 |
+
$data = 'user_name';
|
889 |
+
} else {
|
890 |
+
$data = 'user_meta';
|
891 |
+
}
|
892 |
+
$value = $this->get_stream_meta_data( $record, $data );
|
893 |
+
|
894 |
+
if ( empty( $value ) && 'comments' === $context ) {
|
895 |
+
$value = __( 'Guest', 'mainwp-child' );
|
896 |
+
}
|
897 |
+
|
898 |
+
// check compatibility with old meta data.
|
899 |
+
if ( empty( $value ) ) {
|
900 |
+
$value = $this->get_stream_meta_data( $record, 'author_meta' );
|
901 |
+
}
|
902 |
+
|
903 |
+
return $value;
|
904 |
+
}
|
905 |
+
|
906 |
+
/**
|
907 |
+
* Get the result data token value.
|
908 |
+
*
|
909 |
+
* @param object $record Object containing the record data.
|
910 |
+
* @param string $context Record context.
|
911 |
+
* @param string $data Data to process.
|
912 |
+
*
|
913 |
+
* @return string Result data token value.
|
914 |
+
*/
|
915 |
+
private function get_result_data_token_value( $record, $context, $data ) {
|
916 |
+
if ( 'mainwp_maintenance' === $context && 'details' == $data ) {
|
917 |
+
$tok_value = $this->get_mainwp_maintenance_token_value( $record, $data );
|
918 |
+
} elseif ( 'wordfence_scan' === $context || 'mainwp_maintenance' === $context ) {
|
919 |
+
$meta_value = $this->get_stream_meta_data( $record, $data );
|
920 |
+
if ( 'wordfence_scan' === $context ) {
|
921 |
+
if ( 'result' == $data ) {
|
922 |
+
$completed_log = __( 'Scan complete. Congratulations, no new problems found.', 'wordfence' );
|
923 |
+
$str_loc1 = MainWP_Child_Wordfence::instance()->get_substr( $completed_log, 2 ); // loc string.
|
924 |
+
$str_loc2 = MainWP_Child_Wordfence::instance()->get_substr( $completed_log, 3 ); // loc string.
|
925 |
+
$congra_str_loc = str_replace( $str_loc1, '', $str_loc2 );
|
926 |
+
$congra_str_loc = trim( $congra_str_loc, ' ,' );
|
927 |
+
|
928 |
+
// SUM_FINAL:Scan complete. You have xxx new issues to fix. See below.
|
929 |
+
// SUM_FINAL:Scan complete. Congratulations, no new problems found.
|
930 |
+
if ( stripos( $meta_value, 'Congratulations' ) || stripos( $meta_value, $congra_str_loc ) ) {
|
931 |
+
$meta_value = 'No issues detected';
|
932 |
+
} elseif ( stripos( $meta_value, 'You have' ) ) {
|
933 |
+
$meta_value = 'Issues Detected';
|
934 |
+
} else {
|
935 |
+
$meta_value = '';
|
936 |
+
}
|
937 |
+
} elseif ( 'details' == $data ) {
|
938 |
+
$meta_value = str_replace( 'SUM_FINAL:', '', $meta_value );
|
939 |
+
}
|
940 |
+
}
|
941 |
+
$tok_value = $meta_value;
|
942 |
+
}
|
943 |
+
return $tok_value;
|
944 |
+
}
|
945 |
+
|
946 |
+
/**
|
947 |
+
* Get the Sucuri scan token value.
|
948 |
+
*
|
949 |
+
* @param object $record Object containing the record data.
|
950 |
+
* @param string $data Data to process.
|
951 |
+
*
|
952 |
+
* @return string Sucuri scan token value.
|
953 |
+
*/
|
954 |
+
private function get_sucuri_scan_token_value( $record, $data ) {
|
955 |
+
$tok_value = '';
|
956 |
+
$scan_data = $this->get_stream_meta_data( $record, 'scan_data' );
|
957 |
+
if ( ! empty( $scan_data ) ) {
|
958 |
+
$scan_data = maybe_unserialize( base64_decode( $scan_data ) ); // phpcs:ignore WordPress.PHP.DiscouragedPHPFunctions -- base64_encode required for backwards compatibility.
|
959 |
+
if ( is_array( $scan_data ) ) {
|
960 |
+
|
961 |
+
$blacklisted = $scan_data['blacklisted'];
|
962 |
+
$malware_exists = $scan_data['malware_exists'];
|
963 |
+
|
964 |
+
$status = array();
|
965 |
+
if ( $blacklisted ) {
|
966 |
+
$status[] = __( 'Site Blacklisted', 'mainwp-child' ); }
|
967 |
+
if ( $malware_exists ) {
|
968 |
+
$status[] = __( 'Site With Warnings', 'mainwp-child' ); }
|
969 |
+
|
970 |
+
if ( 'status' == $data ) {
|
971 |
+
$tok_value = count( $status ) > 0 ? implode( ', ', $status ) : __( 'Verified Clear', 'mainwp-child' );
|
972 |
+
} elseif ( 'webtrust' == $data ) {
|
973 |
+
$tok_value = $blacklisted ? __( 'Site Blacklisted', 'mainwp-child' ) : __( 'Trusted', 'mainwp-child' );
|
974 |
+
}
|
975 |
+
}
|
976 |
+
} else {
|
977 |
+
$tok_value = $this->get_stream_meta_data( $record, $data );
|
978 |
+
}
|
979 |
+
return $tok_value;
|
980 |
+
}
|
981 |
+
|
982 |
+
/**
|
983 |
+
* Get the Maintanence token value.
|
984 |
+
*
|
985 |
+
* @param object $record Object containing the record data.
|
986 |
+
* @param string $data Data to process.
|
987 |
+
*
|
988 |
+
* @return string Maintanence token value.
|
989 |
+
*/
|
990 |
+
private function get_mainwp_maintenance_token_value( $record, $data ) {
|
991 |
+
|
992 |
+
$maintenance_details = array(
|
993 |
+
'revisions' => __( 'Delete all post revisions', 'mainwp-child' ),
|
994 |
+
'revisions_max' => __( 'Delete all post revisions, except for the last:', 'mainwp-child' ),
|
995 |
+
'autodraft' => __( 'Delete all auto draft posts', 'mainwp-child' ),
|
996 |
+
'trashpost' => __( 'Delete trash posts', 'mainwp-child' ),
|
997 |
+
'spam' => __( 'Delete spam comments', 'mainwp-child' ),
|
998 |
+
'pending' => __( 'Delete pending comments', 'mainwp-child' ),
|
999 |
+
'trashcomment' => __( 'Delete trash comments', 'mainwp-child' ),
|
1000 |
+
'tags' => __( 'Delete tags with 0 posts associated', 'mainwp-child' ),
|
1001 |
+
'categories' => __( 'Delete categories with 0 posts associated', 'mainwp-child' ),
|
1002 |
+
'optimize' => __( 'Optimize database tables', 'mainwp-child' ),
|
1003 |
+
);
|
1004 |
+
|
1005 |
+
$meta_value = $this->get_stream_meta_data( $record, $data );
|
1006 |
+
$meta_value = explode( ',', $meta_value );
|
1007 |
+
|
1008 |
+
$details = array();
|
1009 |
+
|
1010 |
+
if ( is_array( $meta_value ) ) {
|
1011 |
+
foreach ( $meta_value as $mt ) {
|
1012 |
+
if ( isset( $maintenance_details[ $mt ] ) ) {
|
1013 |
+
if ( 'revisions_max' == $mt ) {
|
1014 |
+
$max_revisions = $this->get_stream_meta_data( $record, 'revisions' );
|
1015 |
+
$dtl = $maintenance_details['revisions_max'] . ' ' . $max_revisions;
|
1016 |
+
} else {
|
1017 |
+
$dtl = $maintenance_details[ $mt ];
|
1018 |
+
}
|
1019 |
+
$details[] = $dtl;
|
1020 |
+
}
|
1021 |
+
}
|
1022 |
+
}
|
1023 |
+
$tok_value = implode( ', ', $details );
|
1024 |
+
return $tok_value;
|
1025 |
+
}
|
1026 |
+
}
|
class/class-mainwp-clone.php
CHANGED
@@ -1,864 +1,864 @@
|
|
1 |
-
<?php
|
2 |
-
/**
|
3 |
-
* MainWP MainWP_Clone
|
4 |
-
*
|
5 |
-
* Manage child site cloning process.
|
6 |
-
*
|
7 |
-
* @package MainWP\Child
|
8 |
-
*/
|
9 |
-
|
10 |
-
namespace MainWP\Child;
|
11 |
-
|
12 |
-
/**
|
13 |
-
* Class MainWP_Clone
|
14 |
-
*
|
15 |
-
* Manage child site cloning process.
|
16 |
-
*/
|
17 |
-
class MainWP_Clone {
|
18 |
-
|
19 |
-
/**
|
20 |
-
* Public static variable to hold the single instance of the class.
|
21 |
-
*
|
22 |
-
* @var mixed Default null
|
23 |
-
*/
|
24 |
-
protected static $instance = null;
|
25 |
-
|
26 |
-
/**
|
27 |
-
* Protected variable to hold security nonces.
|
28 |
-
*
|
29 |
-
* @var array Security nonces.
|
30 |
-
*/
|
31 |
-
protected $security_nonces;
|
32 |
-
|
33 |
-
/**
|
34 |
-
* Method get_class_name()
|
35 |
-
*
|
36 |
-
* Get class name.
|
37 |
-
*
|
38 |
-
* @return string __CLASS__ Class name.
|
39 |
-
*/
|
40 |
-
public static function get_class_name() {
|
41 |
-
return __CLASS__;
|
42 |
-
}
|
43 |
-
|
44 |
-
/**
|
45 |
-
* Method instance()
|
46 |
-
*
|
47 |
-
* Create a public static instance.
|
48 |
-
*
|
49 |
-
* @return mixed Class instance.
|
50 |
-
*/
|
51 |
-
public static function instance() {
|
52 |
-
if ( null === self::$instance ) {
|
53 |
-
self::$instance = new self();
|
54 |
-
}
|
55 |
-
return self::$instance;
|
56 |
-
}
|
57 |
-
|
58 |
-
/**
|
59 |
-
* Method init_ajax()
|
60 |
-
*
|
61 |
-
* Initiate AJAX requests.
|
62 |
-
*/
|
63 |
-
public function init_ajax() {
|
64 |
-
$this->add_action( 'mainwp-child_clone_backupcreate', array( &$this, 'clone_backup_create' ) );
|
65 |
-
$this->add_action( 'mainwp-child_clone_backupcreatepoll', array( &$this, 'clone_backup_create_poll' ) );
|
66 |
-
$this->add_action( 'mainwp-child_clone_backupdownload', array( &$this, 'clone_backup_download' ) );
|
67 |
-
$this->add_action( 'mainwp-child_clone_backupdownloadpoll', array( &$this, 'clone_backup_download_poll' ) );
|
68 |
-
$this->add_action( 'mainwp-child_clone_backupextract', array( &$this, 'clone_backup_extract' ) );
|
69 |
-
}
|
70 |
-
|
71 |
-
/**
|
72 |
-
* Method add_security_nonce()
|
73 |
-
*
|
74 |
-
* Create security nonce for specific actions.
|
75 |
-
*
|
76 |
-
* @param string $action Contains the action that requires security nonce.
|
77 |
-
*/
|
78 |
-
public function add_security_nonce( $action ) {
|
79 |
-
if ( ! is_array( $this->security_nonces ) ) {
|
80 |
-
$this->security_nonces = array();
|
81 |
-
}
|
82 |
-
if ( ! function_exists( 'wp_create_nonce' ) ) {
|
83 |
-
include_once ABSPATH . WPINC . '/pluggable.php';
|
84 |
-
}
|
85 |
-
$this->security_nonces[ $action ] = wp_create_nonce( $action );
|
86 |
-
}
|
87 |
-
|
88 |
-
/**
|
89 |
-
* Method get_security_nonces()
|
90 |
-
*
|
91 |
-
* Get security nonces from the security nonces array.
|
92 |
-
*
|
93 |
-
* @return array Security nonces.
|
94 |
-
*/
|
95 |
-
public function get_security_nonces() {
|
96 |
-
return $this->security_nonces;
|
97 |
-
}
|
98 |
-
|
99 |
-
/**
|
100 |
-
* Method add_action()
|
101 |
-
*
|
102 |
-
* Add actions to the 'wp_ajax_' hook and create security nonce.
|
103 |
-
*
|
104 |
-
* @param string $action Contains action to be added to the 'wp_ajax_' hook.
|
105 |
-
* @param string $callback Contains a callback action.
|
106 |
-
*/
|
107 |
-
public function add_action( $action, $callback ) {
|
108 |
-
add_action( 'wp_ajax_' . $action, $callback );
|
109 |
-
$this->add_security_nonce( $action );
|
110 |
-
}
|
111 |
-
|
112 |
-
/**
|
113 |
-
* Method secure_request()
|
114 |
-
*
|
115 |
-
* Build secure request for the clone process.
|
116 |
-
*
|
117 |
-
* @param string $action Contains the action that is being performed.
|
118 |
-
* @param string $query_arg Contains the query argument.
|
119 |
-
*
|
120 |
-
* @return void
|
121 |
-
*
|
122 |
-
* @uses \MainWP\Child\MainWP_Helper::is_admin()
|
123 |
-
* @uses \MainWP\Child\MainWP_Helper::update_option()
|
124 |
-
*/
|
125 |
-
public function secure_request( $action = '', $query_arg = 'security' ) {
|
126 |
-
if ( ! MainWP_Helper::is_admin() ) {
|
127 |
-
die( 0 );
|
128 |
-
}
|
129 |
-
|
130 |
-
if ( '' == $action ) {
|
131 |
-
return;
|
132 |
-
}
|
133 |
-
|
134 |
-
if ( ! $this->check_security( $action, $query_arg ) ) {
|
135 |
-
die( wp_json_encode( array( 'error' => __( 'Invalid request!', 'mainwp-child' ) ) ) );
|
136 |
-
}
|
137 |
-
|
138 |
-
if ( isset( $_POST['dts'] ) ) {
|
139 |
-
$ajaxPosts = get_option( 'mainwp_ajaxposts' );
|
140 |
-
if ( ! is_array( $ajaxPosts ) ) {
|
141 |
-
$ajaxPosts = array();
|
142 |
-
}
|
143 |
-
|
144 |
-
// If already processed, just quit!
|
145 |
-
if ( isset( $ajaxPosts[ $action ] ) && ( $ajaxPosts[ $action ] == $_POST['dts'] ) ) {
|
146 |
-
die( wp_json_encode( array( 'error' => __( 'Double request!', 'mainwp-child' ) ) ) );
|
147 |
-
}
|
148 |
-
|
149 |
-
$ajaxPosts[ $action ] = isset( $_POST['dts'] ) ? sanitize_text_field( wp_unslash( $_POST['dts'] ) ) : '';
|
150 |
-
MainWP_Helper::update_option( 'mainwp_ajaxposts', $ajaxPosts );
|
151 |
-
}
|
152 |
-
}
|
153 |
-
|
154 |
-
/**
|
155 |
-
* Method check_security()
|
156 |
-
*
|
157 |
-
* Check the clone request security.
|
158 |
-
*
|
159 |
-
* @param string $action Contains the action that is being performed.
|
160 |
-
* @param string $query_arg Contains the query argument.
|
161 |
-
*
|
162 |
-
* @return bool true|false If secure, return true, if not, return false.
|
163 |
-
*/
|
164 |
-
public function check_security( $action = - 1, $query_arg = 'security' ) {
|
165 |
-
if ( - 1 == $action ) {
|
166 |
-
return false;
|
167 |
-
}
|
168 |
-
|
169 |
-
$adminurl = strtolower( admin_url() );
|
170 |
-
$referer = strtolower( wp_get_referer() );
|
171 |
-
$result = isset( $_REQUEST[ $query_arg ] ) ? wp_verify_nonce( sanitize_text_field( wp_unslash( $_REQUEST[ $query_arg ] ) ), $action ) : false;
|
172 |
-
if ( ! $result && ! ( - 1 == $action && 0 === strpos( $referer, $adminurl ) ) ) {
|
173 |
-
return false;
|
174 |
-
}
|
175 |
-
|
176 |
-
return true;
|
177 |
-
}
|
178 |
-
|
179 |
-
/**
|
180 |
-
* Method init()
|
181 |
-
*
|
182 |
-
* Initiate action hooks.
|
183 |
-
*
|
184 |
-
* @uses \MainWP\Child\MainWP_Clone_Page::get_class_name()
|
185 |
-
*/
|
186 |
-
public function init() {
|
187 |
-
add_action( 'check_admin_referer', array( self::get_class_name(), 'permalink_changed' ) );
|
188 |
-
if ( get_option( 'mainwp_child_clone_permalink' ) || get_option( 'mainwp_child_restore_permalink' ) ) {
|
189 |
-
add_action( 'admin_notices', array( MainWP_Clone_Page::get_class_name(), 'permalink_admin_notice' ) );
|
190 |
-
}
|
191 |
-
}
|
192 |
-
|
193 |
-
/**
|
194 |
-
* Method upload_mimes()
|
195 |
-
*
|
196 |
-
* Add allowed mime types and file extensions.
|
197 |
-
*
|
198 |
-
* @param array $mime_types Mime types keyed by the file extension regex corresponding to those types.
|
199 |
-
*
|
200 |
-
* @return array Array containing allowed mime types.
|
201 |
-
*/
|
202 |
-
public static function upload_mimes( $mime_types = array() ) {
|
203 |
-
if ( ! isset( $mime_types['tar.bz2'] ) ) {
|
204 |
-
$mime_types['tar.bz2'] = 'application/x-tar';
|
205 |
-
}
|
206 |
-
|
207 |
-
return $mime_types;
|
208 |
-
}
|
209 |
-
|
210 |
-
/**
|
211 |
-
* Request clone.
|
212 |
-
*
|
213 |
-
* @return bool|void true|void.
|
214 |
-
*
|
215 |
-
* @uses \MainWP\Child\MainWP_Connect::is_valid_auth()
|
216 |
-
* @uses \MainWP\Child\MainWP_Helper::get_mainwp_dir()
|
217 |
-
* @uses \MainWP\Child\MainWP_Helper::write()
|
218 |
-
* @uses \MainWP\Child\MainWP_Utility::upload_file()
|
219 |
-
*/
|
220 |
-
public function request_clone_funct() {
|
221 |
-
|
222 |
-
if ( ! isset( $_REQUEST['key'] ) ) {
|
223 |
-
return;
|
224 |
-
}
|
225 |
-
if ( ! isset( $_REQUEST['f'] ) || ( '' === $_REQUEST['f'] ) ) {
|
226 |
-
return;
|
227 |
-
}
|
228 |
-
if ( ! isset( $_REQUEST['key'] ) || ! MainWP_Connect::instance()->is_valid_auth( wp_unslash( $_REQUEST['key'] ) ) ) {
|
229 |
-
return;
|
230 |
-
}
|
231 |
-
|
232 |
-
$cloneFunc = isset( $_REQUEST['cloneFunc'] ) ? sanitize_text_field( wp_unslash( $_REQUEST['cloneFunc'] ) ) : '';
|
233 |
-
|
234 |
-
if ( 'dl' === $cloneFunc ) {
|
235 |
-
$f = isset( $_REQUEST['f'] ) ? wp_unslash( $_REQUEST['f'] ) : '';
|
236 |
-
if ( ! empty( $f ) ) {
|
237 |
-
MainWP_Utility::instance()->upload_file( wp_unslash( $_REQUEST['f'] ) );
|
238 |
-
}
|
239 |
-
exit;
|
240 |
-
} elseif ( 'deleteCloneBackup' === $cloneFunc ) {
|
241 |
-
$df = isset( $_POST['f'] ) ? sanitize_text_field( wp_unslash( $_POST['f'] ) ) : '';
|
242 |
-
if ( empty( $df ) || stristr( $df, '..' ) ) {
|
243 |
-
return false;
|
244 |
-
}
|
245 |
-
|
246 |
-
$dirs = MainWP_Helper::get_mainwp_dir( 'backup' );
|
247 |
-
$backupdir = $dirs[0];
|
248 |
-
$result = glob( $backupdir . $df );
|
249 |
-
if ( 0 === count( $result ) ) {
|
250 |
-
return;
|
251 |
-
}
|
252 |
-
|
253 |
-
unlink( $result[0] );
|
254 |
-
MainWP_Helper::write( array( 'result' => 'ok' ) );
|
255 |
-
} elseif ( 'createCloneBackupPoll' === $cloneFunc ) {
|
256 |
-
$dirs = MainWP_Helper::get_mainwp_dir( 'backup' );
|
257 |
-
$backupdir = $dirs[0];
|
258 |
-
$f = isset( $_POST['f'] ) ? wp_unslash( $_POST['f'] ) : '';
|
259 |
-
$archiveFile = false;
|
260 |
-
if ( ! empty( $f ) ) {
|
261 |
-
$result = glob( $backupdir . 'backup-' . $f . '-*' );
|
262 |
-
foreach ( $result as $file ) {
|
263 |
-
if ( self::is_archive( $file, 'backup-' . $f . '-' ) ) {
|
264 |
-
$archiveFile = $file;
|
265 |
-
break;
|
266 |
-
}
|
267 |
-
}
|
268 |
-
}
|
269 |
-
if ( false === $archiveFile ) {
|
270 |
-
return;
|
271 |
-
}
|
272 |
-
|
273 |
-
MainWP_Helper::write( array( 'size' => filesize( $archiveFile ) ) );
|
274 |
-
} elseif ( 'createCloneBackup' === $cloneFunc ) {
|
275 |
-
$this->create_clone_backup();
|
276 |
-
}
|
277 |
-
return true;
|
278 |
-
}
|
279 |
-
|
280 |
-
|
281 |
-
/**
|
282 |
-
* Create backup of clone.
|
283 |
-
*
|
284 |
-
* @uses \MainWP\Child\MainWP_Backup::create_full_backup()
|
285 |
-
* @uses \MainWP\Child\MainWP_Helper::end_session()
|
286 |
-
* @uses \MainWP\Child\MainWP_Helper::is_dir_empty()
|
287 |
-
* @uses \MainWP\Child\MainWP_Helper::get_mainwp_dir()
|
288 |
-
* @uses \MainWP\Child\MainWP_Helper::write()
|
289 |
-
*/
|
290 |
-
private function create_clone_backup() { // phpcs:ignore -- Current complexity is the only way to achieve desired results, pull request solutions appreciated.
|
291 |
-
MainWP_Helper::end_session();
|
292 |
-
$files = glob( WP_CONTENT_DIR . '/dbBackup*.sql' );
|
293 |
-
foreach ( $files as $file ) {
|
294 |
-
unlink( $file );
|
295 |
-
}
|
296 |
-
if ( file_exists( ABSPATH . 'clone/config.txt' ) ) {
|
297 |
-
unlink( ABSPATH . 'clone/config.txt' );
|
298 |
-
}
|
299 |
-
if ( MainWP_Helper::is_dir_empty( ABSPATH . 'clone' ) ) {
|
300 |
-
rmdir( ABSPATH . 'clone' );
|
301 |
-
}
|
302 |
-
|
303 |
-
$wpversion = isset( $_POST['wpversion'] ) ? sanitize_text_field( wp_unslash( $_POST['wpversion'] ) ) : '';
|
304 |
-
global $wp_version;
|
305 |
-
$includeCoreFiles = ( $wpversion !== $wp_version );
|
306 |
-
$excludes = ( isset( $_POST['exclude'] ) ? explode( ',', wp_unslash( $_POST['exclude'] ) ) : array() );
|
307 |
-
$excludes[] = str_replace( ABSPATH, '', WP_CONTENT_DIR ) . '/uploads/mainwp';
|
308 |
-
$uploadDir = MainWP_Helper::get_mainwp_dir();
|
309 |
-
$uploadDir = $uploadDir[0];
|
310 |
-
$excludes[] = str_replace( ABSPATH, '', $uploadDir );
|
311 |
-
$excludes[] = str_replace( ABSPATH, '', WP_CONTENT_DIR ) . '/object-cache.php';
|
312 |
-
if ( version_compare( phpversion(), '5.3.0' ) >= 0 || ! ini_get( 'safe_mode' ) ) {
|
313 |
-
set_time_limit( 6000 );
|
314 |
-
}
|
315 |
-
|
316 |
-
$newExcludes = array();
|
317 |
-
foreach ( $excludes as $exclude ) {
|
318 |
-
$newExcludes[] = rtrim( $exclude, '/' );
|
319 |
-
}
|
320 |
-
|
321 |
-
$method = ( ! isset( $_POST['zipmethod'] ) ? 'tar.gz' : wp_unslash( $_POST['zipmethod'] ) );
|
322 |
-
if ( 'tar.gz' === $method && ! function_exists( 'gzopen' ) ) {
|
323 |
-
$method = 'zip';
|
324 |
-
}
|
325 |
-
|
326 |
-
$file = false;
|
327 |
-
if ( isset( $_POST['f'] ) ) {
|
328 |
-
$file = ! empty( $_POST['f'] ) ? wp_unslash( $_POST['f'] ) : false;
|
329 |
-
} elseif ( isset( $_POST['file'] ) ) {
|
330 |
-
$file = ! empty( $_POST['file'] ) ? wp_unslash( $_POST['file'] ) : false;
|
331 |
-
}
|
332 |
-
|
333 |
-
$res = MainWP_Backup::get()->create_full_backup( $newExcludes, $file, true, $includeCoreFiles, 0, false, false, false, false, $method );
|
334 |
-
if ( ! $res ) {
|
335 |
-
$information['backup'] = false;
|
336 |
-
} else {
|
337 |
-
$information['backup'] = $res['file'];
|
338 |
-
$information['size'] = $res['filesize'];
|
339 |
-
}
|
340 |
-
|
341 |
-
$plugins = array();
|
342 |
-
$dir = WP_CONTENT_DIR . '/plugins/';
|
343 |
-
$fh = opendir( $dir );
|
344 |
-
while ( $entry = readdir( $fh ) ) {
|
345 |
-
if ( ! is_dir( $dir . $entry ) ) {
|
346 |
-
continue;
|
347 |
-
}
|
348 |
-
if ( ( '.' === $entry ) || ( '..' === $entry ) ) {
|
349 |
-
continue;
|
350 |
-
}
|
351 |
-
$plugins[] = $entry;
|
352 |
-
}
|
353 |
-
closedir( $fh );
|
354 |
-
$information['plugins'] = $plugins;
|
355 |
-
|
356 |
-
$themes = array();
|
357 |
-
$dir = WP_CONTENT_DIR . '/themes/';
|
358 |
-
$fh = opendir( $dir );
|
359 |
-
while ( $entry = readdir( $fh ) ) {
|
360 |
-
if ( ! is_dir( $dir . $entry ) ) {
|
361 |
-
continue;
|
362 |
-
}
|
363 |
-
if ( ( '.' === $entry ) || ( '..' === $entry ) ) {
|
364 |
-
continue;
|
365 |
-
}
|
366 |
-
$themes[] = $entry;
|
367 |
-
}
|
368 |
-
closedir( $fh );
|
369 |
-
$information['themes'] = $themes;
|
370 |
-
MainWP_Helper::write( $information );
|
371 |
-
}
|
372 |
-
|
373 |
-
/**
|
374 |
-
* Method clone_backup_create()
|
375 |
-
*
|
376 |
-
* Create backup of template site so it can be used to clone it.
|
377 |
-
*
|
378 |
-
* @throws \Exception Error message.
|
379 |
-
*
|
380 |
-
* @uses \MainWP\Child\MainWP_Helper::end_session()
|
381 |
-
* @uses \MainWP\Child\MainWP_Helper::update_option()
|
382 |
-
* @uses \MainWP\Child\MainWP_Utility::fetch_url()
|
383 |
-
*/
|
384 |
-
public function clone_backup_create() {
|
385 |
-
try {
|
386 |
-
$this->secure_request( 'mainwp-child_clone_backupcreate' );
|
387 |
-
|
388 |
-
if ( ! isset( $_POST['siteId'] ) ) {
|
389 |
-
throw new \Exception( __( 'No site given', 'mainwp-child' ) );
|
390 |
-
}
|
391 |
-
|
392 |
-
$siteId = isset( $_POST['siteId'] ) ? intval( wp_unslash( $_POST['siteId'] ) ) : false;
|
393 |
-
|
394 |
-
$rand = isset( $_POST['rand'] ) ? sanitize_text_field( wp_unslash( $_POST['rand'] ) ) : '';
|
395 |
-
$sitesToClone = get_option( 'mainwp_child_clone_sites' );
|
396 |
-
|
397 |
-
if ( ! is_array( $sitesToClone ) || ! isset( $sitesToClone[ $siteId ] ) ) {
|
398 |
-
throw new \Exception( __( 'Site not found', 'mainwp-child' ) );
|
399 |
-
}
|
400 |
-
|
401 |
-
$siteToClone = $sitesToClone[ $siteId ];
|
402 |
-
$url = $siteToClone['url'];
|
403 |
-
$key = $siteToClone['extauth'];
|
404 |
-
$clone_admin = $siteToClone['connect_admin'];
|
405 |
-
|
406 |
-
MainWP_Helper::end_session();
|
407 |
-
|
408 |
-
// Send request to the childsite!
|
409 |
-
|
410 |
-
/**
|
411 |
-
* The installed version of WordPress.
|
412 |
-
*
|
413 |
-
* @global string $wp_version The installed version of WordPress.
|
414 |
-
*/
|
415 |
-
global $wp_version;
|
416 |
-
|
417 |
-
$method = ( function_exists( 'gzopen' ) ? 'tar.gz' : 'zip' );
|
418 |
-
$result = MainWP_Utility::fetch_url(
|
419 |
-
$url,
|
420 |
-
array(
|
421 |
-
'cloneFunc' => 'createCloneBackup',
|
422 |
-
'key' => $key,
|
423 |
-
'f' => $rand,
|
424 |
-
'wpversion' => $wp_version,
|
425 |
-
'zipmethod' => $method,
|
426 |
-
'json_result' => true,
|
427 |
-
)
|
428 |
-
);
|
429 |
-
|
430 |
-
if ( ! $result['backup'] ) {
|
431 |
-
throw new \Exception( __( 'Could not create backupfile on child', 'mainwp-child' ) );
|
432 |
-
}
|
433 |
-
MainWP_Helper::update_option( 'mainwp_temp_clone_plugins', $result['plugins'] );
|
434 |
-
MainWP_Helper::update_option( 'mainwp_temp_clone_themes', $result['themes'] );
|
435 |
-
MainWP_Helper::update_option( 'mainwp_temp_clone_admin', $clone_admin );
|
436 |
-
|
437 |
-
$output = array(
|
438 |
-
'url' => $result['backup'],
|
439 |
-
'size' => round( $result['size'] / 1024, 0 ),
|
440 |
-
);
|
441 |
-
} catch ( \Exception $e ) {
|
442 |
-
$output = array( 'error' => $e->getMessage() );
|
443 |
-
}
|
444 |
-
|
445 |
-
die( wp_json_encode( $output ) );
|
446 |
-
}
|
447 |
-
|
448 |
-
/**
|
449 |
-
* Method clone_backup_create_poll()
|
450 |
-
*
|
451 |
-
* Create backup poll of template site so it can be used to clone it.
|
452 |
-
*
|
453 |
-
* @throws \Exception Error message.
|
454 |
-
*
|
455 |
-
* @uses \MainWP\Child\MainWP_Helper::end_session()
|
456 |
-
* @uses \MainWP\Child\MainWP_Utility::fetch_url()
|
457 |
-
*/
|
458 |
-
public function clone_backup_create_poll() {
|
459 |
-
try {
|
460 |
-
$this->secure_request( 'mainwp-child_clone_backupcreatepoll' );
|
461 |
-
|
462 |
-
if ( ! isset( $_POST['siteId'] ) ) {
|
463 |
-
throw new \Exception( __( 'No site given', 'mainwp-child' ) );
|
464 |
-
}
|
465 |
-
$siteId = isset( $_POST['siteId'] ) ? sanitize_text_field( wp_unslash( $_POST['siteId'] ) ) : '';
|
466 |
-
$rand = isset( $_POST['rand'] ) ? sanitize_text_field( wp_unslash( $_POST['rand'] ) ) : '';
|
467 |
-
|
468 |
-
$sitesToClone = get_option( 'mainwp_child_clone_sites' );
|
469 |
-
if ( ! is_array( $sitesToClone ) || ! isset( $sitesToClone[ $siteId ] ) ) {
|
470 |
-
throw new \Exception( __( 'Site not found', 'mainwp-child' ) );
|
471 |
-
}
|
472 |
-
|
473 |
-
$siteToClone = $sitesToClone[ $siteId ];
|
474 |
-
$url = $siteToClone['url'];
|
475 |
-
|
476 |
-
$key = $siteToClone['extauth'];
|
477 |
-
|
478 |
-
MainWP_Helper::end_session();
|
479 |
-
// Send request to the childsite!
|
480 |
-
$result = MainWP_Utility::fetch_url(
|
481 |
-
$url,
|
482 |
-
array(
|
483 |
-
'cloneFunc' => 'createCloneBackupPoll',
|
484 |
-
'key' => $key,
|
485 |
-
'f' => $rand,
|
486 |
-
'json_result' => true,
|
487 |
-
)
|
488 |
-
);
|
489 |
-
|
490 |
-
if ( ! isset( $result['size'] ) ) {
|
491 |
-
throw new \Exception( __( 'Invalid response', 'mainwp-child' ) );
|
492 |
-
}
|
493 |
-
|
494 |
-
$output = array( 'size' => round( $result['size'] / 1024, 0 ) );
|
495 |
-
} catch ( \Exception $e ) {
|
496 |
-
$output = array( 'error' => $e->getMessage() );
|
497 |
-
}
|
498 |
-
die( wp_json_encode( $output ) );
|
499 |
-
}
|
500 |
-
|
501 |
-
/**
|
502 |
-
* Method clone_backup_download()
|
503 |
-
*
|
504 |
-
* Download backup file of template site so it can be used to clone it.
|
505 |
-
*
|
506 |
-
* @return mixed Response message.
|
507 |
-
* @throws \Exception Error message.
|
508 |
-
*
|
509 |
-
* @uses \MainWP\Child\MainWP_Helper::end_session()
|
510 |
-
* @uses \MainWP\Child\MainWP_Helper::get_mainwp_dir()
|
511 |
-
* @uses \MainWP\Child\MainWP_Utility::fetch_url()
|
512 |
-
*/
|
513 |
-
public function clone_backup_download() {
|
514 |
-
try {
|
515 |
-
$this->secure_request( 'mainwp-child_clone_backupdownload' );
|
516 |
-
|
517 |
-
if ( ! isset( $_POST['file'] ) ) {
|
518 |
-
throw new \Exception( __( 'No download link given', 'mainwp-child' ) );
|
519 |
-
}
|
520 |
-
|
521 |
-
$file = isset( $_POST['file'] ) ? wp_unslash( $_POST['file'] ) : '';
|
522 |
-
if ( isset( $_POST['siteId'] ) ) {
|
523 |
-
$siteId = isset( $_POST['siteId'] ) ? intval( wp_unslash( $_POST['siteId'] ) ) : false;
|
524 |
-
|
525 |
-
$sitesToClone = get_option( 'mainwp_child_clone_sites' );
|
526 |
-
|
527 |
-
if ( ! is_array( $sitesToClone ) || ! isset( $sitesToClone[ $siteId ] ) ) {
|
528 |
-
throw new \Exception( __( 'Site not found', 'mainwp-child' ) );
|
529 |
-
}
|
530 |
-
|
531 |
-
$siteToClone = $sitesToClone[ $siteId ];
|
532 |
-
$url = $siteToClone['url'];
|
533 |
-
$key = $siteToClone['extauth'];
|
534 |
-
|
535 |
-
$url = trailingslashit( $url ) . '?cloneFunc=dl&key=' . rawurlencode( $key ) . '&f=' . $file;
|
536 |
-
} else {
|
537 |
-
$url = $file;
|
538 |
-
}
|
539 |
-
MainWP_Helper::end_session();
|
540 |
-
// Send request to the childsite!
|
541 |
-
$split = explode( '=', $file );
|
542 |
-
$file = urldecode( $split[ count( $split ) - 1 ] );
|
543 |
-
$filename = 'download-' . basename( $file );
|
544 |
-
$dirs = MainWP_Helper::get_mainwp_dir( 'backup', false );
|
545 |
-
$backupdir = $dirs[0];
|
546 |
-
$dh = opendir( $backupdir );
|
547 |
-
if ( $dh ) {
|
548 |
-
$fl = readdir( $dh );
|
549 |
-
while ( false !== $fl ) {
|
550 |
-
if ( '.' !== $fl && '..' !== $fl && self::is_archive( $fl, 'download-' ) ) {
|
551 |
-
unlink( $backupdir . $fl );
|
552 |
-
}
|
553 |
-
$fl = readdir( $dh );
|
554 |
-
}
|
555 |
-
closedir( $dh );
|
556 |
-
}
|
557 |
-
|
558 |
-
$filename = $backupdir . $filename;
|
559 |
-
|
560 |
-
$response = wp_remote_get(
|
561 |
-
$url,
|
562 |
-
array(
|
563 |
-
'timeout' => 300000,
|
564 |
-
'stream' => true,
|
565 |
-
'filename' => $filename,
|
566 |
-
)
|
567 |
-
);
|
568 |
-
|
569 |
-
if ( is_wp_error( $response ) ) {
|
570 |
-
unlink( $filename );
|
571 |
-
|
572 |
-
return $response;
|
573 |
-
}
|
574 |
-
|
575 |
-
if ( 200 !== (int) wp_remote_retrieve_response_code( $response ) ) {
|
576 |
-
unlink( $filename );
|
577 |
-
|
578 |
-
return new \WP_Error( 'http_404', trim( wp_remote_retrieve_response_message( $response ) ) );
|
579 |
-
}
|
580 |
-
|
581 |
-
$output = array( 'done' => $filename );
|
582 |
-
|
583 |
-
// Delete backup on child.
|
584 |
-
try {
|
585 |
-
if ( isset( $_POST['siteId'] ) ) {
|
586 |
-
$siteId = isset( $_POST['siteId'] ) ? intval( wp_unslash( $_POST['siteId'] ) ) : false;
|
587 |
-
|
588 |
-
$sitesToClone = get_option( 'mainwp_child_clone_sites' );
|
589 |
-
if ( is_array( $sitesToClone ) && isset( $sitesToClone[ $siteId ] ) ) {
|
590 |
-
$siteToClone = $sitesToClone[ $siteId ];
|
591 |
-
|
592 |
-
MainWP_Utility::fetch_url(
|
593 |
-
$siteToClone['url'],
|
594 |
-
array(
|
595 |
-
'cloneFunc' => 'deleteCloneBackup',
|
596 |
-
'key' => $siteToClone['extauth'],
|
597 |
-
'f' => $file,
|
598 |
-
'json_result' => true,
|
599 |
-
)
|
600 |
-
);
|
601 |
-
}
|
602 |
-
}
|
603 |
-
} catch ( \Exception $e ) {
|
604 |
-
throw $e;
|
605 |
-
}
|
606 |
-
} catch ( \Exception $e ) {
|
607 |
-
$output = array( 'error' => $e->getMessage() );
|
608 |
-
}
|
609 |
-
|
610 |
-
die( wp_json_encode( $output ) );
|
611 |
-
}
|
612 |
-
|
613 |
-
/**
|
614 |
-
* Method clone_backup_download_poll()
|
615 |
-
*
|
616 |
-
* Download backup file poll of template site so it can be used to clone it.
|
617 |
-
*
|
618 |
-
* @throws \Exception Error message.
|
619 |
-
*
|
620 |
-
* @uses \MainWP\Child\MainWP_Helper::end_session()
|
621 |
-
* @uses \MainWP\Child\MainWP_Helper::get_mainwp_dir()
|
622 |
-
*/
|
623 |
-
public function clone_backup_download_poll() {
|
624 |
-
try {
|
625 |
-
$this->secure_request( 'mainwp-child_clone_backupdownloadpoll' );
|
626 |
-
|
627 |
-
MainWP_Helper::end_session();
|
628 |
-
|
629 |
-
$dirs = MainWP_Helper::get_mainwp_dir( 'backup', false );
|
630 |
-
$backupdir = $dirs[0];
|
631 |
-
$files = glob( $backupdir . 'download-*' );
|
632 |
-
$archiveFile = false;
|
633 |
-
|
634 |
-
foreach ( $files as $file ) {
|
635 |
-
if ( self::is_archive( $file, 'download-' ) ) {
|
636 |
-
$archiveFile = $file;
|
637 |
-
break;
|
638 |
-
}
|
639 |
-
}
|
640 |
-
if ( false === $archiveFile ) {
|
641 |
-
throw new \Exception( __( 'No download file found', 'mainwp-child' ) );
|
642 |
-
}
|
643 |
-
$output = array( 'size' => filesize( $archiveFile ) / 1024 );
|
644 |
-
} catch ( \Exception $e ) {
|
645 |
-
$output = array( 'error' => $e->getMessage() );
|
646 |
-
}
|
647 |
-
die( wp_json_encode( $output ) );
|
648 |
-
}
|
649 |
-
|
650 |
-
/**
|
651 |
-
* Method clone_backup_extract()
|
652 |
-
*
|
653 |
-
* Extract the backup archive to clone the site.
|
654 |
-
*
|
655 |
-
* @uses \MainWP\Child\MainWP_Clone_Install()
|
656 |
-
* @uses \MainWP\Child\MainWP_Helper::end_session()
|
657 |
-
* @uses \MainWP\Child\MainWP_Helper::update_option()
|
658 |
-
* @uses \MainWP\Child\MainWP_Helper::starts_with()
|
659 |
-
*/
|
660 |
-
public function clone_backup_extract() {
|
661 |
-
try {
|
662 |
-
$this->secure_request( 'mainwp-child_clone_backupextract' );
|
663 |
-
|
664 |
-
MainWP_Helper::end_session();
|
665 |
-
|
666 |
-
$file = false;
|
667 |
-
if ( isset( $_POST['f'] ) ) {
|
668 |
-
$file = ! empty( $_POST['f'] ) ? wp_unslash( $_POST['f'] ) : false;
|
669 |
-
} elseif ( isset( $_POST['file'] ) ) {
|
670 |
-
$file = ! empty( $_POST['file'] ) ? wp_unslash( $_POST['file'] ) : false;
|
671 |
-
}
|
672 |
-
|
673 |
-
$testFull = false;
|
674 |
-
$file = $this->clone_backup_get_file( $file, $testFull );
|
675 |
-
$cloneInstall = new MainWP_Clone_Install( $file );
|
676 |
-
$cloneInstall->read_configuration_file();
|
677 |
-
|
678 |
-
$plugins = get_option( 'mainwp_temp_clone_plugins' );
|
679 |
-
$themes = get_option( 'mainwp_temp_clone_themes' );
|
680 |
-
$clone_admin = get_option( 'mainwp_temp_clone_admin' );
|
681 |
-
|
682 |
-
if ( $testFull ) {
|
683 |
-
$cloneInstall->test_download();
|
684 |
-
}
|
685 |
-
$cloneInstall->remove_config_file();
|
686 |
-
$cloneInstall->extract_backup();
|
687 |
-
|
688 |
-
$pubkey = get_option( 'mainwp_child_pubkey' );
|
689 |
-
$uniqueId = MainWP_Helper::get_site_unique_id();
|
690 |
-
$uniqueId = get_option( 'mainwp_child_uniqueId' );
|
691 |
-
$server = get_option( 'mainwp_child_server' );
|
692 |
-
$nonce = get_option( 'mainwp_child_nonce' );
|
693 |
-
$nossl = get_option( 'mainwp_child_nossl' );
|
694 |
-
$nossl_key = get_option( 'mainwp_child_nossl_key' );
|
695 |
-
$sitesToClone = get_option( 'mainwp_child_clone_sites' );
|
696 |
-
|
697 |
-
$cloneInstall->install();
|
698 |
-
|
699 |
-
delete_option( 'mainwp_child_pubkey' );
|
700 |
-
delete_option( 'mainwp_child_uniqueId' );
|
701 |
-
delete_option( 'mainwp_child_server' );
|
702 |
-
delete_option( 'mainwp_child_nonce' );
|
703 |
-
delete_option( 'mainwp_child_nossl' );
|
704 |
-
delete_option( 'mainwp_child_nossl_key' );
|
705 |
-
delete_option( 'mainwp_child_clone_sites' );
|
706 |
-
delete_option( 'mainwp_temp_clone_admin' );
|
707 |
-
|
708 |
-
MainWP_Helper::update_option( 'mainwp_child_pubkey', $pubkey, 'yes' );
|
709 |
-
MainWP_Helper::update_option( 'mainwp_child_uniqueId', $uniqueId );
|
710 |
-
MainWP_Helper::update_option( 'mainwp_child_server', $server );
|
711 |
-
MainWP_Helper::update_option( 'mainwp_child_nonce', $nonce );
|
712 |
-
MainWP_Helper::update_option( 'mainwp_child_nossl', $nossl, 'yes' );
|
713 |
-
MainWP_Helper::update_option( 'mainwp_child_nossl_key', $nossl_key );
|
714 |
-
MainWP_Helper::update_option( 'mainwp_child_clone_sites', $sitesToClone );
|
715 |
-
MainWP_Helper::update_option( 'mainwp_child_just_clone_admin', $clone_admin );
|
716 |
-
|
717 |
-
if ( ! MainWP_Helper::starts_with( basename( $file ), 'download-backup-' ) ) {
|
718 |
-
MainWP_Helper::update_option( 'mainwp_child_restore_permalink', true, 'yes' );
|
719 |
-
} else {
|
720 |
-
MainWP_Helper::update_option( 'mainwp_child_clone_permalink', true, 'yes' );
|
721 |
-
}
|
722 |
-
|
723 |
-
$cloneInstall->update_wp_config();
|
724 |
-
$cloneInstall->clean();
|
725 |
-
$output = $this->clone_backup_delete_files( $plugins, $themes );
|
726 |
-
} catch ( \Exception $e ) {
|
727 |
-
$output = array( 'error' => $e->getMessage() );
|
728 |
-
}
|
729 |
-
|
730 |
-
die( wp_json_encode( $output ) );
|
731 |
-
}
|
732 |
-
|
733 |
-
/**
|
734 |
-
* Method clone_backup_get_file()
|
735 |
-
*
|
736 |
-
* Get the backup file to download and clone.
|
737 |
-
*
|
738 |
-
* @param resource $file Backup file to be downloaded.
|
739 |
-
* @param bool $testFull Return true if the file exists.
|
740 |
-
*
|
741 |
-
* @return resource Return the backup file.
|
742 |
-
* @throws \Exception Error message.
|
743 |
-
*
|
744 |
-
* @uses \MainWP\Child\MainWP_Helper::get_mainwp_dir()
|
745 |
-
*/
|
746 |
-
private function clone_backup_get_file( $file, &$testFull ) {
|
747 |
-
if ( '' == $file ) {
|
748 |
-
$dirs = MainWP_Helper::get_mainwp_dir( 'backup', false );
|
749 |
-
$backupdir = $dirs[0];
|
750 |
-
$files = glob( $backupdir . 'download-*' );
|
751 |
-
$archiveFile = false;
|
752 |
-
foreach ( $files as $file ) {
|
753 |
-
if ( self::is_archive( $file, 'download-' ) ) {
|
754 |
-
$archiveFile = $file;
|
755 |
-
break;
|
756 |
-
}
|
757 |
-
}
|
758 |
-
if ( false === $archiveFile ) {
|
759 |
-
throw new \Exception( __( 'No download file found', 'mainwp-child' ) );
|
760 |
-
}
|
761 |
-
$file = $archiveFile;
|
762 |
-
} elseif ( file_exists( $file ) ) {
|
763 |
-
$testFull = true;
|
764 |
-
} else {
|
765 |
-
$file = ABSPATH . $file;
|
766 |
-
if ( ! file_exists( $file ) ) {
|
767 |
-
throw new \Exception( __( 'Backup file not found', 'mainwp-child' ) );
|
768 |
-
}
|
769 |
-
$testFull = true;
|
770 |
-
}
|
771 |
-
return $file;
|
772 |
-
}
|
773 |
-
|
774 |
-
/**
|
775 |
-
* Method is_archive()
|
776 |
-
*
|
777 |
-
* Check if the file is archive file.
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|