do_reports_log( $ext ); break; case 'backupwordpress': MainWP_Child_Back_Up_WordPress::instance()->do_reports_log( $ext ); break; case 'backwpup': MainWP_Child_Back_WP_Up::instance()->do_reports_log( $ext ); break; case 'wordfence': MainWP_Child_Wordfence::instance()->do_reports_log( $ext ); break; case 'wptimecapsule': MainWP_Child_Timecapsule::instance()->do_reports_log( $ext ); break; default: break; } } /** * Actions: save_sucuri_stream, save_backup_stream, get_stream, set_showhide. * * @uses \MainWP\Child\MainWP_Helper::write() */ public function action() { $information = array(); if ( ! function_exists( '\wp_mainwp_stream_get_instance' ) ) { $information['error'] = esc_html__( 'No MainWP Child Reports plugin installed.', 'mainwp-child' ); MainWP_Helper::write( $information ); } try { $mwp_action = MainWP_System::instance()->validate_params( 'mwp_action' ); if ( ! empty( $mwp_action ) ) { switch ( $mwp_action ) { case 'save_sucuri_stream': $information = $this->save_sucuri_stream(); break; case 'save_backup_stream': $information = $this->save_backup_stream(); break; case 'get_stream': $information = $this->get_stream(); break; case 'set_showhide': $information = $this->set_showhide(); break; default: break; } } } catch ( MainWP_Exception $e ) { $information['error'] = $e->getMessage(); } MainWP_Helper::write( $information ); } /** * Save sucuri stream. * * @return bool true|false. */ public function save_sucuri_stream() { // phpcs:disable WordPress.Security.NonceVerification $scan_data = isset( $_POST['scan_data'] ) ? wp_unslash( $_POST['scan_data'] ) : ''; //phpcs:ignore WordPress.Security.ValidatedSanitizedInput.InputNotSanitized $scan_time = isset( $_POST['scan_time'] ) ? sanitize_text_field( wp_unslash( $_POST['scan_time'] ) ) : 0; $scan_status = isset( $_POST['scan_status'] ) ? sanitize_text_field( wp_unslash( $_POST['scan_status'] ) ) : ''; $result = isset( $_POST['result'] ) ? wp_unslash( $_POST['result'] ) : ''; //phpcs:ignore WordPress.Security.ValidatedSanitizedInput.InputNotSanitized // phpcs:enable do_action( 'mainwp_reports_sucuri_scan', $result, $scan_status, $scan_data, $scan_time ); return true; } /** * Save backup stream. * * @return bool true|false. */ public function save_backup_stream() { // phpcs:disable WordPress.Security.NonceVerification $destination = isset( $_POST['destination'] ) ? wp_unslash( $_POST['destination'] ) : ''; //phpcs:ignore WordPress.Security.ValidatedSanitizedInput.InputNotSanitized $message = isset( $_POST['message'] ) ? wp_unslash( $_POST['message'] ) : ''; //phpcs:ignore WordPress.Security.ValidatedSanitizedInput.InputNotSanitized $size = isset( $_POST['size'] ) ? wp_unslash( $_POST['size'] ) : ''; //phpcs:ignore WordPress.Security.ValidatedSanitizedInput.InputNotSanitized $status = isset( $_POST['status'] ) ? sanitize_text_field( wp_unslash( $_POST['status'] ) ) : ''; $type = isset( $_POST['type'] ) ? sanitize_text_field( wp_unslash( $_POST['type'] ) ) : ''; // phpcs:enable do_action( 'mainwp_backup', $destination, $message, $size, $status, $type ); return true; } /** * Get stream. * * @return array $information Stream array. */ public function get_stream() { // phpcs:disable WordPress.Security.NonceVerification $sections = isset( $_POST['sections'] ) ? json_decode( base64_decode( wp_unslash( $_POST['sections'] ) ), true ) : array(); // phpcs:ignore WordPress.Security.ValidatedSanitizedInput.InputNotSanitized,WordPress.PHP.DiscouragedPHPFunctions -- base64_encode function is used for http encode compatible.. if ( ! is_array( $sections ) ) { $sections = array(); } $other_tokens = isset( $_POST['other_tokens'] ) ? json_decode( base64_decode( wp_unslash( $_POST['other_tokens'] ) ), true ) : array(); // phpcs:ignore WordPress.Security.ValidatedSanitizedInput.InputNotSanitized,WordPress.PHP.DiscouragedPHPFunctions -- base64_encode function is used for http encode compatible.. if ( ! is_array( $other_tokens ) ) { $other_tokens = array(); } unset( $_POST['sections'] ); unset( $_POST['other_tokens'] ); // phpcs:enable $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(); $other_tokens_data = $this->get_stream_others_tokens( $records, $other_tokens, $skip_records ); $sections_data = $this->get_stream_sections_data( $records, $sections, $skip_records ); return apply_filters( 'mainwp_child_prepared_reports_data', array( 'other_tokens_data' => $other_tokens_data, 'sections_data' => $sections_data, ), $sections, $other_tokens, $args ); } /** * Set Branding Show/Hide. * * @return array $information Results array. * * @uses \MainWP\Child\MainWP_Child_Branding::save_branding_options() */ public function set_showhide() { $hide = MainWP_System::instance()->validate_params( 'showhide' ); MainWP_Child_Branding::instance()->save_branding_options( 'hide_child_reports', $hide ); $information['result'] = 'SUCCESS'; return $information; } /** * Initiate Client Reports. * * @uses \MainWP\Child\MainWP_Child_Branding::get_branding_options() * @uses \MainWP\Child\MainWP_Child_Branding::is_branding() */ public function creport_init() { $branding_opts = MainWP_Child_Branding::instance()->get_branding_options(); $hide_nag = false; if ( isset( $branding_opts['hide_child_reports'] ) && 'hide' === $branding_opts['hide_child_reports'] ) { add_filter( 'all_plugins', array( $this, 'creport_branding_plugin' ) ); add_action( 'admin_menu', array( $this, 'creport_remove_menu' ) ); $hide_nag = true; } if ( ! $hide_nag && MainWP_Child_Branding::instance()->is_branding() ) { $hide_nag = true; } if ( $hide_nag ) { add_filter( 'site_transient_update_plugins', array( &$this, 'remove_update_nag' ) ); add_filter( 'mainwp_child_hide_update_notice', array( &$this, 'hide_update_notice' ) ); } } /** * Hide the MainWP Child Reports plugin update notice. * * @param array $slugs An array containing slugs to hide. * * @return array Updated array containing slugs to hide. */ public function hide_update_notice( $slugs ) { $slugs[] = 'mainwp-child-reports/mainwp-child-reports.php'; return $slugs; } /** * Remove update nag. * * @param string $value Value to remove. * * @return string Response. * * @uses \MainWP\Child\MainWP_Helper::is_updates_screen() */ public function remove_update_nag( $value ) { if ( MainWP_Helper::is_dashboard_request() ) { return $value; } if ( ! MainWP_Helper::is_updates_screen() ) { return $value; } if ( isset( $value->response['mainwp-child-reports/mainwp-child-reports.php'] ) ) { unset( $value->response['mainwp-child-reports/mainwp-child-reports.php'] ); } return $value; } /** * Client Reports Branding plugin. * * @param array $plugins Plugins array. * @return array Plugins array. */ public function creport_branding_plugin( $plugins ) { foreach ( $plugins as $key => $value ) { $plugin_slug = basename( $key, '.php' ); if ( 'mainwp-child-reports' === $plugin_slug ) { unset( $plugins[ $key ] ); } } return $plugins; } /** * Client Remove Menu. */ public function creport_remove_menu() { remove_menu_page( 'mainwp_wp_stream' ); } }