mirror of
https://github.com/mainwp/mainwp-child.git
synced 2025-09-06 11:10:43 +08:00
Refactoring
This commit is contained in:
parent
3a126a6e29
commit
737db8daa2
6 changed files with 245 additions and 224 deletions
|
@ -146,9 +146,9 @@ class MainWP_Child_Branding {
|
||||||
'authoruri' => $settings['child_plugin_author_uri'],
|
'authoruri' => $settings['child_plugin_author_uri'],
|
||||||
'pluginuri' => isset( $settings['child_plugin_uri'] ) ? $settings['child_plugin_uri'] : '',
|
'pluginuri' => isset( $settings['child_plugin_uri'] ) ? $settings['child_plugin_uri'] : '',
|
||||||
);
|
);
|
||||||
|
|
||||||
$current_settings['preserve_branding'] = $settings['child_preserve_branding'];
|
|
||||||
$current_settings['branding_header'] = $header;
|
$current_settings['branding_header'] = $header;
|
||||||
|
|
||||||
|
$current_settings['preserve_branding'] = $settings['child_preserve_branding'];
|
||||||
$current_settings['support_email'] = $settings['child_support_email'];
|
$current_settings['support_email'] = $settings['child_support_email'];
|
||||||
$current_settings['support_message'] = $settings['child_support_message'];
|
$current_settings['support_message'] = $settings['child_support_message'];
|
||||||
$current_settings['remove_restore'] = $settings['child_remove_restore'];
|
$current_settings['remove_restore'] = $settings['child_remove_restore'];
|
||||||
|
@ -162,11 +162,23 @@ class MainWP_Child_Branding {
|
||||||
$current_settings['email_message'] = $settings['child_send_email_message'];
|
$current_settings['email_message'] = $settings['child_send_email_message'];
|
||||||
$current_settings['return_sender'] = $settings['child_message_return_sender'];
|
$current_settings['return_sender'] = $settings['child_message_return_sender'];
|
||||||
$current_settings['submit_button_title'] = $settings['child_submit_button_title'];
|
$current_settings['submit_button_title'] = $settings['child_submit_button_title'];
|
||||||
|
$current_settings['hide'] = $settings['child_plugin_hide'] ? 'T' : '';
|
||||||
|
$current_settings['show_support'] = ( $settings['child_show_support_button'] && ! empty( $settings['child_support_email'] ) ) ? 'T' : '';
|
||||||
|
$current_settings['disable_change'] = $settings['child_disable_change'] ? 'T' : '';
|
||||||
|
$current_settings['disable_switching_theme'] = $settings['child_disable_switching_theme'] ? 'T' : '';
|
||||||
if ( isset( $settings['child_disable_wp_branding'] ) && ( 'Y' === $settings['child_disable_wp_branding'] || 'N' === $settings['child_disable_wp_branding'] ) ) {
|
if ( isset( $settings['child_disable_wp_branding'] ) && ( 'Y' === $settings['child_disable_wp_branding'] || 'N' === $settings['child_disable_wp_branding'] ) ) {
|
||||||
$current_settings['disable_wp_branding'] = $settings['child_disable_wp_branding'];
|
$current_settings['disable_wp_branding'] = $settings['child_disable_wp_branding'];
|
||||||
}
|
}
|
||||||
|
$current_settings['extra_settings'] = self::get_extra_settings( $current_extra_setting, $settings, $information );
|
||||||
|
MainWP_Helper::update_option( 'mainwp_child_branding_settings', $current_settings );
|
||||||
|
|
||||||
|
$information['result'] = 'SUCCESS';
|
||||||
|
|
||||||
|
return $information;
|
||||||
|
}
|
||||||
|
|
||||||
|
public static function get_extra_settings( $current_extra_setting, $settings, &$information ){
|
||||||
|
|
||||||
$extra_setting = array(
|
$extra_setting = array(
|
||||||
'show_button_in' => $settings['child_show_support_button_in'],
|
'show_button_in' => $settings['child_show_support_button_in'],
|
||||||
'global_footer' => $settings['child_global_footer'],
|
'global_footer' => $settings['child_global_footer'],
|
||||||
|
@ -255,21 +267,9 @@ class MainWP_Child_Branding {
|
||||||
} elseif ( isset( $current_extra_setting['favico_image'] ) ) {
|
} elseif ( isset( $current_extra_setting['favico_image'] ) ) {
|
||||||
$extra_setting['favico_image'] = $current_extra_setting['favico_image'];
|
$extra_setting['favico_image'] = $current_extra_setting['favico_image'];
|
||||||
}
|
}
|
||||||
|
return $extra_setting;
|
||||||
$current_settings['extra_settings'] = $extra_setting;
|
|
||||||
|
|
||||||
$current_settings['hide'] = $settings['child_plugin_hide'] ? 'T' : '';
|
|
||||||
$current_settings['show_support'] = ( $settings['child_show_support_button'] && ! empty( $settings['child_support_email'] ) ) ? 'T' : '';
|
|
||||||
$current_settings['disable_change'] = $settings['child_disable_change'] ? 'T' : '';
|
|
||||||
$current_settings['disable_switching_theme'] = $settings['child_disable_switching_theme'] ? 'T' : '';
|
|
||||||
|
|
||||||
MainWP_Helper::update_option( 'mainwp_child_branding_settings', $current_settings );
|
|
||||||
|
|
||||||
$information['result'] = 'SUCCESS';
|
|
||||||
|
|
||||||
return $information;
|
|
||||||
}
|
}
|
||||||
|
|
||||||
public static function branding_upload_image( $img_url ) {
|
public static function branding_upload_image( $img_url ) {
|
||||||
include_once ABSPATH . 'wp-admin/includes/file.php';
|
include_once ABSPATH . 'wp-admin/includes/file.php';
|
||||||
|
|
||||||
|
|
|
@ -13,7 +13,7 @@
|
||||||
* Extension URL: https://mainwp.com/extension/ithemes-security/
|
* Extension URL: https://mainwp.com/extension/ithemes-security/
|
||||||
*/
|
*/
|
||||||
|
|
||||||
// phpcs:disable PSR1.Classes.ClassDeclaration, WordPress.WP.AlternativeFunctions -- root namespace to use external code.
|
// phpcs:disable -- third party credit code.
|
||||||
|
|
||||||
class MainWP_Child_IThemes_Security {
|
class MainWP_Child_IThemes_Security {
|
||||||
public static $instance = null;
|
public static $instance = null;
|
||||||
|
@ -1000,8 +1000,13 @@ class MainWP_Child_IThemes_Security {
|
||||||
$active = '';
|
$active = '';
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
||||||
$results = $wpdb->get_results( 'SELECT * FROM `' . $wpdb->base_prefix . 'itsec_lockouts`' . $where . $type_statement . $active . ';', ARRAY_A ); // phpcs:ignore -- safe query. $output = array();
|
$results = $wpdb->get_results( 'SELECT * FROM `' . $wpdb->base_prefix . 'itsec_lockouts`' . $where . $type_statement . $active . ';', ARRAY_A ); // phpcs:ignore -- safe query. $output = array();
|
||||||
|
|
||||||
|
return $this->get_lockouts_int( $results, $type );
|
||||||
|
}
|
||||||
|
|
||||||
|
private function get_lockouts_int( $results, $type ){
|
||||||
|
|
||||||
if ( is_array( $results ) && count( $results ) > 0 ) {
|
if ( is_array( $results ) && count( $results ) > 0 ) {
|
||||||
switch ( $type ) {
|
switch ( $type ) {
|
||||||
case 'host':
|
case 'host':
|
||||||
|
@ -1035,10 +1040,11 @@ class MainWP_Child_IThemes_Security {
|
||||||
break;
|
break;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
return $output;
|
return $output;
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
||||||
public function release_lockout() {
|
public function release_lockout() {
|
||||||
global $wpdb;
|
global $wpdb;
|
||||||
|
|
||||||
|
|
|
@ -428,10 +428,9 @@ class MainWP_Child_Server_Information {
|
||||||
<?php
|
<?php
|
||||||
}
|
}
|
||||||
|
|
||||||
public static function render_page() {
|
public static function render_page(){
|
||||||
self::render_page_js();
|
self::render_page_js();
|
||||||
?>
|
?>
|
||||||
|
|
||||||
<style type="text/css">
|
<style type="text/css">
|
||||||
#mwp-server-information {
|
#mwp-server-information {
|
||||||
display: none;
|
display: none;
|
||||||
|
|
|
@ -200,6 +200,47 @@ class MainWP_Client_Report {
|
||||||
|
|
||||||
public function get_stream() {
|
public function get_stream() {
|
||||||
|
|
||||||
|
$sections = isset( $_POST['sections'] ) ? maybe_unserialize( base64_decode( $_POST['sections'] ) ) : array(); // phpcs:ignore WordPress.PHP.DiscouragedPHPFunctions -- base64_encode function is used for begin reasons.
|
||||||
|
if ( ! is_array( $sections ) ) {
|
||||||
|
$sections = array();
|
||||||
|
}
|
||||||
|
|
||||||
|
$other_tokens = isset( $_POST['other_tokens'] ) ? maybe_unserialize( base64_decode( $_POST['other_tokens'] ) ) : array(); // phpcs:ignore WordPress.PHP.DiscouragedPHPFunctions -- base64_encode function is used for begin reasons.
|
||||||
|
if ( ! is_array( $other_tokens ) ) {
|
||||||
|
$other_tokens = array();
|
||||||
|
}
|
||||||
|
|
||||||
|
unset( $_POST['sections'] );
|
||||||
|
unset( $_POST['other_tokens'] );
|
||||||
|
|
||||||
|
$args = $this->get_stream_get_params( $other_tokens, $sections );
|
||||||
|
$records = wp_mainwp_stream_get_instance()->db->query( $args );
|
||||||
|
|
||||||
|
if ( ! is_array( $records ) ) {
|
||||||
|
$records = array();
|
||||||
|
}
|
||||||
|
|
||||||
|
// fix invalid data, or skip records!
|
||||||
|
$skip_records = array();
|
||||||
|
|
||||||
|
// fix for incorrect posts created logs!
|
||||||
|
// query created posts from WP posts data to simulate records logging for created posts.
|
||||||
|
if ( isset( $_POST['direct_posts'] ) && ! empty( $_POST['direct_posts'] ) ) {
|
||||||
|
$this->fix_logs_posts_created( $records, $skip_records );
|
||||||
|
}
|
||||||
|
|
||||||
|
$other_tokens_data = $this->get_stream_others_tokens( $records, $other_tokens, $skip_records );
|
||||||
|
$sections_data = $this->get_stream_sections_data( $records, $sections, $skip_records );
|
||||||
|
|
||||||
|
$information = array(
|
||||||
|
'other_tokens_data' => $other_tokens_data,
|
||||||
|
'sections_data' => $sections_data,
|
||||||
|
);
|
||||||
|
return $information;
|
||||||
|
}
|
||||||
|
|
||||||
|
private function get_stream_get_params( $other_tokens, $sections ){
|
||||||
|
|
||||||
$allowed_params = array(
|
$allowed_params = array(
|
||||||
'connector',
|
'connector',
|
||||||
'context',
|
'context',
|
||||||
|
@ -215,20 +256,7 @@ class MainWP_Client_Report {
|
||||||
'blog_id',
|
'blog_id',
|
||||||
'ip',
|
'ip',
|
||||||
);
|
);
|
||||||
|
|
||||||
$sections = isset( $_POST['sections'] ) ? maybe_unserialize( base64_decode( $_POST['sections'] ) ) : array(); // phpcs:ignore WordPress.PHP.DiscouragedPHPFunctions -- base64_encode function is used for begin reasons.
|
|
||||||
if ( ! is_array( $sections ) ) {
|
|
||||||
$sections = array();
|
|
||||||
}
|
|
||||||
|
|
||||||
$other_tokens = isset( $_POST['other_tokens'] ) ? maybe_unserialize( base64_decode( $_POST['other_tokens'] ) ) : array(); // phpcs:ignore WordPress.PHP.DiscouragedPHPFunctions -- base64_encode function is used for begin reasons.
|
|
||||||
if ( ! is_array( $other_tokens ) ) {
|
|
||||||
$other_tokens = array();
|
|
||||||
}
|
|
||||||
|
|
||||||
unset( $_POST['sections'] );
|
|
||||||
unset( $_POST['other_tokens'] );
|
|
||||||
|
|
||||||
$args = array();
|
$args = array();
|
||||||
foreach ( $allowed_params as $param ) {
|
foreach ( $allowed_params as $param ) {
|
||||||
$paramval = wp_mainwp_stream_filter_input( INPUT_POST, $param );
|
$paramval = wp_mainwp_stream_filter_input( INPUT_POST, $param );
|
||||||
|
@ -323,113 +351,89 @@ class MainWP_Client_Report {
|
||||||
}
|
}
|
||||||
|
|
||||||
$args['records_per_page'] = 9999;
|
$args['records_per_page'] = 9999;
|
||||||
|
|
||||||
$records = wp_mainwp_stream_get_instance()->db->query( $args );
|
return $args;
|
||||||
|
}
|
||||||
if ( ! is_array( $records ) ) {
|
|
||||||
$records = array();
|
private function get_stream_others_tokens( $records, $other_tokens, $skip_records ){
|
||||||
|
$other_tokens_data = array();
|
||||||
|
$parts = array( 'header', 'body', 'footer' );
|
||||||
|
foreach( $parts as $part ) {
|
||||||
|
if ( isset( $other_tokens[ $part ] ) && is_array( $other_tokens[ $part ] ) ) {
|
||||||
|
$other_tokens_data[ $part ] = $this->get_other_tokens_data( $records, $other_tokens[ $part ], $skip_records );
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
return $other_tokens_data;
|
||||||
// fix invalid data, or skip records!
|
}
|
||||||
$skip_records = array();
|
|
||||||
|
private function get_stream_sections_data( $records, $sections, $skip_records ){
|
||||||
// fix for incorrect posts created logs!
|
|
||||||
// query created posts from WP posts data to simulate records logging for created posts.
|
|
||||||
if ( isset( $_POST['direct_posts'] ) && ! empty( $_POST['direct_posts'] ) ) {
|
|
||||||
|
|
||||||
$args = array(
|
|
||||||
'post_type' => 'post',
|
|
||||||
'post_status' => 'publish',
|
|
||||||
'date_query' => array(
|
|
||||||
'column' => 'post_date',
|
|
||||||
'after' => $args['date_from'],
|
|
||||||
'before' => $args['date_to'],
|
|
||||||
),
|
|
||||||
);
|
|
||||||
|
|
||||||
$result = new \WP_Query( $args );
|
|
||||||
$records_created_posts = $result->posts;
|
|
||||||
|
|
||||||
if ( $records_created_posts ) {
|
|
||||||
|
|
||||||
$count_records = count( $records );
|
|
||||||
for ( $i = 0; $i < $count_records; $i++ ) {
|
|
||||||
$record = $records[ $i ];
|
|
||||||
if ( 'posts' == $record->connector && 'post' == $record->context && 'created' == $record->action ) {
|
|
||||||
if ( ! in_array( $record->ID, $skip_records ) ) {
|
|
||||||
$skip_records[] = $record->ID; // so avoid this created logging, will use logging query from posts data.
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
$post_authors = array();
|
|
||||||
|
|
||||||
foreach ( $records_created_posts as $_post ) {
|
|
||||||
$au_id = $_post->post_author;
|
|
||||||
if ( ! isset( $post_authors[ $au_id ] ) ) {
|
|
||||||
$au = get_user_by( 'id', $au_id );
|
|
||||||
$post_authors[ $au_id ] = $au->display_name;
|
|
||||||
}
|
|
||||||
$au_name = $post_authors[ $au_id ];
|
|
||||||
|
|
||||||
// simulate logging created posts record.
|
|
||||||
$stdObj = new \stdClass();
|
|
||||||
$stdObj->ID = 0; // simulate ID value.
|
|
||||||
$stdObj->connector = 'posts';
|
|
||||||
$stdObj->context = 'post';
|
|
||||||
$stdObj->action = 'created';
|
|
||||||
$stdObj->created = $_post->post_date;
|
|
||||||
$stdObj->meta = array(
|
|
||||||
'post_title' => array( $_post->post_title ),
|
|
||||||
'user_meta' => array( $au_name ),
|
|
||||||
);
|
|
||||||
|
|
||||||
$records[] = $stdObj;
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
if ( isset( $other_tokens['header'] ) && is_array( $other_tokens['header'] ) ) {
|
|
||||||
$other_tokens_data['header'] = $this->get_other_tokens_data( $records, $other_tokens['header'], $skip_records );
|
|
||||||
}
|
|
||||||
|
|
||||||
if ( isset( $other_tokens['body'] ) && is_array( $other_tokens['body'] ) ) {
|
|
||||||
$other_tokens_data['body'] = $this->get_other_tokens_data( $records, $other_tokens['body'], $skip_records );
|
|
||||||
}
|
|
||||||
|
|
||||||
if ( isset( $other_tokens['footer'] ) && is_array( $other_tokens['footer'] ) ) {
|
|
||||||
$other_tokens_data['footer'] = $this->get_other_tokens_data( $records, $other_tokens['footer'], $skip_records );
|
|
||||||
}
|
|
||||||
|
|
||||||
$sections_data = array();
|
$sections_data = array();
|
||||||
|
$parts = array( 'header', 'body', 'footer' );
|
||||||
if ( isset( $sections['header'] ) && is_array( $sections['header'] ) && ! empty( $sections['header'] ) ) {
|
foreach( $parts as $part ) {
|
||||||
foreach ( $sections['header']['section_token'] as $index => $sec ) {
|
if ( isset( $sections[ $part ] ) && is_array( $sections[ $part ] ) && ! empty( $sections[ $part ] ) ) {
|
||||||
$tokens = $sections['header']['section_content_tokens'][ $index ];
|
foreach ( $sections[ $part ]['section_token'] as $index => $sec ) {
|
||||||
$sections_data['header'][ $index ] = $this->get_section_loop_data( $records, $tokens, $sec, $skip_records );
|
$tokens = $sections[ $part ]['section_content_tokens'][ $index ];
|
||||||
|
$sections_data[ $part ][ $index ] = $this->get_section_loop_data( $records, $tokens, $sec, $skip_records );
|
||||||
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
if ( isset( $sections['body'] ) && is_array( $sections['body'] ) && ! empty( $sections['body'] ) ) {
|
return $sections_data;
|
||||||
foreach ( $sections['body']['section_token'] as $index => $sec ) {
|
|
||||||
$tokens = $sections['body']['section_content_tokens'][ $index ];
|
|
||||||
$sections_data['body'][ $index ] = $this->get_section_loop_data( $records, $tokens, $sec, $skip_records );
|
|
||||||
}
|
|
||||||
}
|
|
||||||
if ( isset( $sections['footer'] ) && is_array( $sections['footer'] ) && ! empty( $sections['footer'] ) ) {
|
|
||||||
foreach ( $sections['footer']['section_token'] as $index => $sec ) {
|
|
||||||
$tokens = $sections['footer']['section_content_tokens'][ $index ];
|
|
||||||
$sections_data['footer'][ $index ] = $this->get_section_loop_data( $records, $tokens, $sec, $skip_records );
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
$information = array(
|
|
||||||
'other_tokens_data' => $other_tokens_data,
|
|
||||||
'sections_data' => $sections_data,
|
|
||||||
);
|
|
||||||
|
|
||||||
return $information;
|
|
||||||
}
|
}
|
||||||
|
|
||||||
|
private function fix_logs_posts_created( &$records, &$skip_records ){
|
||||||
|
|
||||||
|
$args = array(
|
||||||
|
'post_type' => 'post',
|
||||||
|
'post_status' => 'publish',
|
||||||
|
'date_query' => array(
|
||||||
|
'column' => 'post_date',
|
||||||
|
'after' => $args['date_from'],
|
||||||
|
'before' => $args['date_to'],
|
||||||
|
),
|
||||||
|
);
|
||||||
|
|
||||||
|
$result = new \WP_Query( $args );
|
||||||
|
$records_created_posts = $result->posts;
|
||||||
|
|
||||||
|
if ( $records_created_posts ) {
|
||||||
|
|
||||||
|
$count_records = count( $records );
|
||||||
|
for ( $i = 0; $i < $count_records; $i++ ) {
|
||||||
|
$record = $records[ $i ];
|
||||||
|
if ( 'posts' == $record->connector && 'post' == $record->context && 'created' == $record->action ) {
|
||||||
|
if ( ! in_array( $record->ID, $skip_records ) ) {
|
||||||
|
$skip_records[] = $record->ID; // so avoid this created logging, will use logging query from posts data.
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
$post_authors = array();
|
||||||
|
|
||||||
|
foreach ( $records_created_posts as $_post ) {
|
||||||
|
$au_id = $_post->post_author;
|
||||||
|
if ( ! isset( $post_authors[ $au_id ] ) ) {
|
||||||
|
$au = get_user_by( 'id', $au_id );
|
||||||
|
$post_authors[ $au_id ] = $au->display_name;
|
||||||
|
}
|
||||||
|
$au_name = $post_authors[ $au_id ];
|
||||||
|
|
||||||
|
// simulate logging created posts record.
|
||||||
|
$stdObj = new \stdClass();
|
||||||
|
$stdObj->ID = 0; // simulate ID value.
|
||||||
|
$stdObj->connector = 'posts';
|
||||||
|
$stdObj->context = 'post';
|
||||||
|
$stdObj->action = 'created';
|
||||||
|
$stdObj->created = $_post->post_date;
|
||||||
|
$stdObj->meta = array(
|
||||||
|
'post_title' => array( $_post->post_title ),
|
||||||
|
'user_meta' => array( $au_name ),
|
||||||
|
);
|
||||||
|
|
||||||
|
$records[] = $stdObj;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
public function get_other_tokens_data( $records, $tokens, &$skip_records ) {
|
public function get_other_tokens_data( $records, $tokens, &$skip_records ) {
|
||||||
|
|
||||||
$token_values = array();
|
$token_values = array();
|
||||||
|
@ -609,19 +613,6 @@ class MainWP_Client_Report {
|
||||||
|
|
||||||
public function get_section_loop_records( $records, $tokens, $connector, $context, $action, $skip_records ) {
|
public function get_section_loop_records( $records, $tokens, $connector, $context, $action, $skip_records ) {
|
||||||
|
|
||||||
$maintenance_details = array(
|
|
||||||
'revisions' => __( 'Delete all post revisions', 'mainwp-child' ),
|
|
||||||
'revisions_max' => __( 'Delete all post revisions, except for the last:', 'mainwp-child' ),
|
|
||||||
'autodraft' => __( 'Delete all auto draft posts', 'mainwp-child' ),
|
|
||||||
'trashpost' => __( 'Delete trash posts', 'mainwp-child' ),
|
|
||||||
'spam' => __( 'Delete spam comments', 'mainwp-child' ),
|
|
||||||
'pending' => __( 'Delete pending comments', 'mainwp-child' ),
|
|
||||||
'trashcomment' => __( 'Delete trash comments', 'mainwp-child' ),
|
|
||||||
'tags' => __( 'Delete tags with 0 posts associated', 'mainwp-child' ),
|
|
||||||
'categories' => __( 'Delete categories with 0 posts associated', 'mainwp-child' ),
|
|
||||||
'optimize' => __( 'Optimize database tables', 'mainwp-child' ),
|
|
||||||
);
|
|
||||||
|
|
||||||
$loops = array();
|
$loops = array();
|
||||||
$loop_count = 0;
|
$loop_count = 0;
|
||||||
foreach ( $records as $record ) {
|
foreach ( $records as $record ) {
|
||||||
|
@ -904,7 +895,20 @@ class MainWP_Client_Report {
|
||||||
}
|
}
|
||||||
|
|
||||||
private function get_mainwp_maintenance_token_value( $record, $data ) {
|
private function get_mainwp_maintenance_token_value( $record, $data ) {
|
||||||
|
|
||||||
|
$maintenance_details = array(
|
||||||
|
'revisions' => __( 'Delete all post revisions', 'mainwp-child' ),
|
||||||
|
'revisions_max' => __( 'Delete all post revisions, except for the last:', 'mainwp-child' ),
|
||||||
|
'autodraft' => __( 'Delete all auto draft posts', 'mainwp-child' ),
|
||||||
|
'trashpost' => __( 'Delete trash posts', 'mainwp-child' ),
|
||||||
|
'spam' => __( 'Delete spam comments', 'mainwp-child' ),
|
||||||
|
'pending' => __( 'Delete pending comments', 'mainwp-child' ),
|
||||||
|
'trashcomment' => __( 'Delete trash comments', 'mainwp-child' ),
|
||||||
|
'tags' => __( 'Delete tags with 0 posts associated', 'mainwp-child' ),
|
||||||
|
'categories' => __( 'Delete categories with 0 posts associated', 'mainwp-child' ),
|
||||||
|
'optimize' => __( 'Optimize database tables', 'mainwp-child' ),
|
||||||
|
);
|
||||||
|
|
||||||
$meta_value = $this->get_stream_meta_data( $record, $data );
|
$meta_value = $this->get_stream_meta_data( $record, $data );
|
||||||
$meta_value = explode( ',', $meta_value );
|
$meta_value = explode( ',', $meta_value );
|
||||||
|
|
||||||
|
|
|
@ -1374,32 +1374,8 @@ class MainWP_Clone {
|
||||||
MainWP_Helper::end_session();
|
MainWP_Helper::end_session();
|
||||||
|
|
||||||
$file = ( isset( $_POST['f'] ) ? $_POST['f'] : $_POST['file'] );
|
$file = ( isset( $_POST['f'] ) ? $_POST['f'] : $_POST['file'] );
|
||||||
$testFull = false;
|
$testFull = false;
|
||||||
|
$file = $this->clone_backup_get_file( $file, $testFull );
|
||||||
if ( '' === $file ) {
|
|
||||||
$dirs = MainWP_Helper::get_mainwp_dir( 'backup', false );
|
|
||||||
$backupdir = $dirs[0];
|
|
||||||
$files = glob( $backupdir . 'download-*' );
|
|
||||||
$archiveFile = false;
|
|
||||||
foreach ( $files as $file ) {
|
|
||||||
if ( MainWP_Helper::is_archive( $file, 'download-' ) ) {
|
|
||||||
$archiveFile = $file;
|
|
||||||
break;
|
|
||||||
}
|
|
||||||
}
|
|
||||||
if ( false === $archiveFile ) {
|
|
||||||
throw new \Exception( __( 'No download file found', 'mainwp-child' ) );
|
|
||||||
}
|
|
||||||
$file = $archiveFile;
|
|
||||||
} elseif ( file_exists( $file ) ) {
|
|
||||||
$testFull = true;
|
|
||||||
} else {
|
|
||||||
$file = ABSPATH . $file;
|
|
||||||
if ( ! file_exists( $file ) ) {
|
|
||||||
throw new \Exception( __( 'Backup file not found', 'mainwp-child' ) );
|
|
||||||
}
|
|
||||||
$testFull = true;
|
|
||||||
}
|
|
||||||
$cloneInstall = new MainWP_Clone_Install( $file );
|
$cloneInstall = new MainWP_Clone_Install( $file );
|
||||||
$cloneInstall->read_configuration_file();
|
$cloneInstall->read_configuration_file();
|
||||||
|
|
||||||
|
@ -1445,57 +1421,90 @@ class MainWP_Clone {
|
||||||
|
|
||||||
$cloneInstall->update_wp_config();
|
$cloneInstall->update_wp_config();
|
||||||
$cloneInstall->clean();
|
$cloneInstall->clean();
|
||||||
|
$output = $this->clone_backup_delete_files( $plugins, $themes );
|
||||||
if ( false !== $plugins ) {
|
|
||||||
$out = array();
|
|
||||||
if ( is_array( $plugins ) ) {
|
|
||||||
$dir = WP_CONTENT_DIR . '/plugins/';
|
|
||||||
$fh = opendir( $dir );
|
|
||||||
while ( $entry = readdir( $fh ) ) {
|
|
||||||
if ( ! is_dir( $dir . $entry ) ) {
|
|
||||||
continue;
|
|
||||||
}
|
|
||||||
if ( ( '.' === $entry ) || ( '..' === $entry ) ) {
|
|
||||||
continue;
|
|
||||||
}
|
|
||||||
if ( ! in_array( $entry, $plugins ) ) {
|
|
||||||
MainWP_Helper::delete_dir( $dir . $entry );
|
|
||||||
}
|
|
||||||
}
|
|
||||||
closedir( $fh );
|
|
||||||
}
|
|
||||||
|
|
||||||
delete_option( 'mainwp_temp_clone_plugins' );
|
|
||||||
}
|
|
||||||
if ( false !== $themes ) {
|
|
||||||
$out = array();
|
|
||||||
if ( is_array( $themes ) ) {
|
|
||||||
$dir = WP_CONTENT_DIR . '/themes/';
|
|
||||||
$fh = opendir( $dir );
|
|
||||||
while ( $entry = readdir( $fh ) ) {
|
|
||||||
if ( ! is_dir( $dir . $entry ) ) {
|
|
||||||
continue;
|
|
||||||
}
|
|
||||||
if ( ( '.' === $entry ) || ( '..' === $entry ) ) {
|
|
||||||
continue;
|
|
||||||
}
|
|
||||||
if ( ! in_array( $entry, $themes ) ) {
|
|
||||||
MainWP_Helper::delete_dir( $dir . $entry );
|
|
||||||
}
|
|
||||||
}
|
|
||||||
closedir( $fh );
|
|
||||||
}
|
|
||||||
delete_option( 'mainwp_temp_clone_themes' );
|
|
||||||
}
|
|
||||||
$output = array( 'result' => 'ok' );
|
|
||||||
wp_logout();
|
|
||||||
wp_set_current_user( 0 );
|
|
||||||
} catch ( \Exception $e ) {
|
} catch ( \Exception $e ) {
|
||||||
$output = array( 'error' => $e->getMessage() );
|
$output = array( 'error' => $e->getMessage() );
|
||||||
}
|
}
|
||||||
|
|
||||||
die( wp_json_encode( $output ) );
|
die( wp_json_encode( $output ) );
|
||||||
}
|
}
|
||||||
|
|
||||||
|
private function clone_backup_get_file( $file, &$testFull ){
|
||||||
|
if ( '' === $file ) {
|
||||||
|
$dirs = MainWP_Helper::get_mainwp_dir( 'backup', false );
|
||||||
|
$backupdir = $dirs[0];
|
||||||
|
$files = glob( $backupdir . 'download-*' );
|
||||||
|
$archiveFile = false;
|
||||||
|
foreach ( $files as $file ) {
|
||||||
|
if ( MainWP_Helper::is_archive( $file, 'download-' ) ) {
|
||||||
|
$archiveFile = $file;
|
||||||
|
break;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
if ( false === $archiveFile ) {
|
||||||
|
throw new \Exception( __( 'No download file found', 'mainwp-child' ) );
|
||||||
|
}
|
||||||
|
$file = $archiveFile;
|
||||||
|
} elseif ( file_exists( $file ) ) {
|
||||||
|
$testFull = true;
|
||||||
|
} else {
|
||||||
|
$file = ABSPATH . $file;
|
||||||
|
if ( ! file_exists( $file ) ) {
|
||||||
|
throw new \Exception( __( 'Backup file not found', 'mainwp-child' ) );
|
||||||
|
}
|
||||||
|
$testFull = true;
|
||||||
|
}
|
||||||
|
return $file;
|
||||||
|
}
|
||||||
|
|
||||||
|
private function clone_backup_delete_files( $plugins, $themes ){
|
||||||
|
if ( false !== $plugins ) {
|
||||||
|
$out = array();
|
||||||
|
if ( is_array( $plugins ) ) {
|
||||||
|
$dir = WP_CONTENT_DIR . '/plugins/';
|
||||||
|
$fh = opendir( $dir );
|
||||||
|
while ( $entry = readdir( $fh ) ) {
|
||||||
|
if ( ! is_dir( $dir . $entry ) ) {
|
||||||
|
continue;
|
||||||
|
}
|
||||||
|
if ( ( '.' === $entry ) || ( '..' === $entry ) ) {
|
||||||
|
continue;
|
||||||
|
}
|
||||||
|
if ( ! in_array( $entry, $plugins ) ) {
|
||||||
|
MainWP_Helper::delete_dir( $dir . $entry );
|
||||||
|
}
|
||||||
|
}
|
||||||
|
closedir( $fh );
|
||||||
|
}
|
||||||
|
|
||||||
|
delete_option( 'mainwp_temp_clone_plugins' );
|
||||||
|
}
|
||||||
|
if ( false !== $themes ) {
|
||||||
|
$out = array();
|
||||||
|
if ( is_array( $themes ) ) {
|
||||||
|
$dir = WP_CONTENT_DIR . '/themes/';
|
||||||
|
$fh = opendir( $dir );
|
||||||
|
while ( $entry = readdir( $fh ) ) {
|
||||||
|
if ( ! is_dir( $dir . $entry ) ) {
|
||||||
|
continue;
|
||||||
|
}
|
||||||
|
if ( ( '.' === $entry ) || ( '..' === $entry ) ) {
|
||||||
|
continue;
|
||||||
|
}
|
||||||
|
if ( ! in_array( $entry, $themes ) ) {
|
||||||
|
MainWP_Helper::delete_dir( $dir . $entry );
|
||||||
|
}
|
||||||
|
}
|
||||||
|
closedir( $fh );
|
||||||
|
}
|
||||||
|
delete_option( 'mainwp_temp_clone_themes' );
|
||||||
|
}
|
||||||
|
$output = array( 'result' => 'ok' );
|
||||||
|
wp_logout();
|
||||||
|
wp_set_current_user( 0 );
|
||||||
|
return $output;
|
||||||
|
}
|
||||||
|
|
||||||
public static function permalink_changed( $action ) {
|
public static function permalink_changed( $action ) {
|
||||||
if ( 'update-permalink' === $action ) {
|
if ( 'update-permalink' === $action ) {
|
||||||
if ( isset( $_POST['permalink_structure'] ) || isset( $_POST['category_base'] ) || isset( $_POST['tag_base'] ) ) {
|
if ( isset( $_POST['permalink_structure'] ) || isset( $_POST['category_base'] ) || isset( $_POST['tag_base'] ) ) {
|
||||||
|
|
|
@ -100,7 +100,10 @@ class MainWP_Helper {
|
||||||
// Split by parenthesis, ignoring those inside content-quotes.
|
// Split by parenthesis, ignoring those inside content-quotes.
|
||||||
$ordered[ $ordered_key ] = preg_split( '/([^\'"\{\}]*?[\'"].*?(?<!\\\)[\'"][^\'"\{\}]*?)[\{\}]|([^\'"\{\}]*?)[\{\}]/', trim( $ordered_value, " \r\n\t" ), -1, PREG_SPLIT_NO_EMPTY | PREG_SPLIT_DELIM_CAPTURE );
|
$ordered[ $ordered_key ] = preg_split( '/([^\'"\{\}]*?[\'"].*?(?<!\\\)[\'"][^\'"\{\}]*?)[\{\}]|([^\'"\{\}]*?)[\{\}]/', trim( $ordered_value, " \r\n\t" ), -1, PREG_SPLIT_NO_EMPTY | PREG_SPLIT_DELIM_CAPTURE );
|
||||||
}
|
}
|
||||||
|
return self::parse_css_rebuild( $ordered );
|
||||||
|
}
|
||||||
|
|
||||||
|
public static function parse_css_rebuild( $ordered ) {
|
||||||
// Beginning to rebuild new slim CSS-Array.
|
// Beginning to rebuild new slim CSS-Array.
|
||||||
foreach ( $ordered as $key => $val ) {
|
foreach ( $ordered as $key => $val ) {
|
||||||
$new = array();
|
$new = array();
|
||||||
|
|
Loading…
Add table
Add a link
Reference in a new issue