| @@ -6,8 +6,13 @@ | ||
| 6 | 6 | */ |
| 7 | 7 | |
| 8 | 8 | namespace MainWP\Dashboard; |
| 9 | 9 | |
| 10 | +// Exit if accessed directly. | |
| 11 | +if ( ! defined( 'ABSPATH' ) ) { | |
| 12 | + exit; | |
| 13 | +} | |
| 14 | + | |
| 10 | 15 | /** |
| 11 | 16 | * Class MainWP_Post_Site_Handler |
| 12 | 17 | * |
| 13 | 18 | * @package MainWP\Dashboard |
| @@ -13,459 +18,485 @@ | ||
| 13 | 18 | * @package MainWP\Dashboard |
| 14 | 19 | * |
| 15 | 20 | * @uses \MainWP\Dashboard\MainWP_Post_Base_Handler |
| 16 | 21 | */ |
| 17 | -class MainWP_Post_Site_Handler extends MainWP_Post_Base_Handler { | |
| 22 | +class MainWP_Post_Site_Handler extends MainWP_Post_Base_Handler { // phpcs:ignore Generic.Classes.OpeningBraceSameLine.ContentAfterBrace -- NOSONAR. | |
| 18 | 23 | |
| 19 | - /** | |
| 20 | - * Private static variable to hold the single instance of the class. | |
| 21 | - * | |
| 22 | - * @static | |
| 23 | - * | |
| 24 | - * @var mixed Default null | |
| 25 | - */ | |
| 26 | - private static $instance = null; | |
| 24 | + /** | |
| 25 | + * Private static variable to hold the single instance of the class. | |
| 26 | + * | |
| 27 | + * @static | |
| 28 | + * | |
| 29 | + * @var mixed Default null | |
| 30 | + */ | |
| 31 | + private static $instance = null; | |
| 27 | 32 | |
| 28 | - /** | |
| 29 | - * Method instance() | |
| 30 | - * | |
| 31 | - * Create MainWP Post Site Handler instance. | |
| 32 | - * | |
| 33 | - * @static | |
| 34 | - * @return self $instance MainWP_Post_Site_Handler. | |
| 35 | - */ | |
| 36 | - public static function instance() { | |
| 37 | - if ( null === self::$instance ) { | |
| 38 | - self::$instance = new self(); | |
| 39 | - } | |
| 40 | - return self::$instance; | |
| 41 | - } | |
| 33 | + /** | |
| 34 | + * Method instance() | |
| 35 | + * | |
| 36 | + * Create MainWP Post Site Handler instance. | |
| 37 | + * | |
| 38 | + * @static | |
| 39 | + * @return self $instance MainWP_Post_Site_Handler. | |
| 40 | + */ | |
| 41 | + public static function instance() { | |
| 42 | + if ( null === static::$instance ) { | |
| 43 | + static::$instance = new self(); | |
| 44 | + } | |
| 45 | + return static::$instance; | |
| 46 | + } | |
| 42 | 47 | |
| 43 | - /** | |
| 44 | - * Init site actions | |
| 45 | - */ | |
| 46 | - public function init() { | |
| 47 | - // Page: ManageSites. | |
| 48 | - $this->add_action( 'mainwp_checkwp', array( &$this, 'mainwp_checkwp' ) ); | |
| 49 | - $this->add_action( 'mainwp_addwp', array( &$this, 'mainwp_addwp' ) ); | |
| 50 | - $this->add_action( 'mainwp_get_site_icon', array( &$this, 'get_site_icon' ) ); | |
| 51 | - $this->add_action( 'mainwp_check_abandoned', array( &$this, 'check_abandoned' ) ); | |
| 48 | + /** | |
| 49 | + * Init site actions | |
| 50 | + */ | |
| 51 | + public function init() { | |
| 52 | + // Page: ManageSites. | |
| 53 | + $this->add_action( 'mainwp_checkwp', array( &$this, 'mainwp_checkwp' ) ); | |
| 54 | + $this->add_action( 'mainwp_addwp', array( &$this, 'mainwp_addwp' ) ); | |
| 55 | + $this->add_action( 'mainwp_get_site_icon', array( &$this, 'get_site_icon' ) ); | |
| 56 | + $this->add_action( 'mainwp_check_abandoned', array( &$this, 'check_abandoned' ) ); | |
| 52 | 57 | |
| 53 | - if ( mainwp_current_user_have_right( 'dashboard', 'test_connection' ) ) { | |
| 54 | - $this->add_action( 'mainwp_testwp', array( &$this, 'mainwp_testwp' ) ); | |
| 55 | - } | |
| 58 | + if ( \mainwp_current_user_can( 'dashboard', 'test_connection' ) ) { | |
| 59 | + $this->add_action( 'mainwp_testwp', array( &$this, 'mainwp_testwp' ) ); | |
| 60 | + } | |
| 56 | 61 | |
| 57 | - $this->add_action( 'mainwp_removesite', array( &$this, 'mainwp_removesite' ) ); | |
| 58 | - $this->add_action( 'mainwp_reconnectwp', array( &$this, 'mainwp_reconnectwp' ) ); | |
| 59 | - $this->add_action( 'mainwp_updatechildsite_value', array( &$this, 'mainwp_updatechildsite_value' ) ); | |
| 62 | + $this->add_action( 'mainwp_removesite', array( &$this, 'mainwp_removesite' ) ); | |
| 63 | + $this->add_action( 'mainwp_reconnectwp', array( &$this, 'mainwp_reconnectwp' ) ); | |
| 64 | + $this->add_action( 'mainwp_updatechildsite_value', array( &$this, 'mainwp_updatechildsite_value' ) ); | |
| 60 | 65 | |
| 61 | - // Page: ManageGroups. | |
| 62 | - $this->add_action( 'mainwp_group_rename', array( &$this, 'mainwp_group_rename' ) ); | |
| 63 | - $this->add_action( 'mainwp_group_delete', array( &$this, 'mainwp_group_delete' ) ); | |
| 64 | - $this->add_action( 'mainwp_group_add', array( &$this, 'mainwp_group_add' ) ); | |
| 66 | + // Page: ManageGroups. | |
| 67 | + $this->add_action( 'mainwp_group_rename', array( &$this, 'mainwp_group_rename' ) ); | |
| 68 | + $this->add_action( 'mainwp_group_delete', array( &$this, 'mainwp_group_delete' ) ); | |
| 69 | + $this->add_action( 'mainwp_group_add', array( &$this, 'mainwp_group_add' ) ); | |
| 65 | 70 | |
| 66 | - $this->add_action( 'mainwp_group_getsites', array( &$this, 'mainwp_group_getsites' ) ); | |
| 67 | - $this->add_action( 'mainwp_group_updategroup', array( &$this, 'mainwp_group_updategroup' ) ); | |
| 71 | + $this->add_action( 'mainwp_group_getsites', array( &$this, 'mainwp_group_getsites' ) ); | |
| 72 | + $this->add_action( 'mainwp_group_updategroup', array( &$this, 'mainwp_group_updategroup' ) ); | |
| 68 | 73 | |
| 69 | - // Widget: RightNow. | |
| 70 | - $this->add_action( 'mainwp_syncsites', array( &$this, 'mainwp_syncsites' ) ); | |
| 74 | + // Widget: RightNow. | |
| 75 | + $this->add_action( 'mainwp_syncsites', array( &$this, 'mainwp_syncsites' ) ); | |
| 71 | 76 | |
| 72 | - $this->add_action( 'mainwp_checksites', array( &$this, 'mainwp_checksites' ) ); | |
| 73 | - $this->add_action( 'mainwp_manage_sites_suspend_site', array( &$this, 'manage_suspend_site' ) ); | |
| 74 | - $this->add_action( 'mainwp_group_sites_add', array( &$this, 'ajax_group_sites_add' ) ); | |
| 75 | - } | |
| 77 | + $this->add_action( 'mainwp_checksites', array( &$this, 'ajax_checksites' ) ); | |
| 78 | + $this->add_action( 'mainwp_manage_sites_suspend_site', array( &$this, 'manage_suspend_site' ) ); | |
| 79 | + $this->add_action( 'mainwp_group_sites_add', array( &$this, 'ajax_group_sites_add' ) ); | |
| 80 | + } | |
| 76 | 81 | |
| 77 | - /** | |
| 78 | - * Method mainwp_group_rename() | |
| 79 | - * | |
| 80 | - * Rename Group. | |
| 81 | - * | |
| 82 | - * @uses \MainWP\Dashboard\MainWP_Manage_Groups::rename_group() | |
| 83 | - */ | |
| 84 | - public function mainwp_group_rename() { | |
| 85 | - $this->secure_request( 'mainwp_group_rename' ); | |
| 82 | + /** | |
| 83 | + * Method mainwp_group_rename() | |
| 84 | + * | |
| 85 | + * Rename Group. | |
| 86 | + * | |
| 87 | + * @uses \MainWP\Dashboard\MainWP_Manage_Groups::rename_group() | |
| 88 | + */ | |
| 89 | + public function mainwp_group_rename() { | |
| 90 | + $this->secure_request( 'mainwp_group_rename' ); | |
| 86 | 91 | |
| 87 | - MainWP_Manage_Groups::rename_group(); | |
| 88 | - } | |
| 92 | + MainWP_Manage_Groups::rename_group(); | |
| 93 | + } | |
| 89 | 94 | |
| 90 | - /** | |
| 91 | - * Method mainwp_group_delete() | |
| 92 | - * | |
| 93 | - * Delete Group. | |
| 94 | - * | |
| 95 | - * @uses \MainWP\Dashboard\MainWP_Manage_Groups::delete_group() | |
| 96 | - */ | |
| 97 | - public function mainwp_group_delete() { | |
| 98 | - $this->secure_request( 'mainwp_group_delete' ); | |
| 95 | + /** | |
| 96 | + * Method mainwp_group_delete() | |
| 97 | + * | |
| 98 | + * Delete Group. | |
| 99 | + * | |
| 100 | + * @uses \MainWP\Dashboard\MainWP_Manage_Groups::delete_group() | |
| 101 | + */ | |
| 102 | + public function mainwp_group_delete() { | |
| 103 | + $this->secure_request( 'mainwp_group_delete' ); | |
| 99 | 104 | |
| 100 | - MainWP_Manage_Groups::delete_group(); | |
| 101 | - } | |
| 105 | + MainWP_Manage_Groups::delete_group(); | |
| 106 | + } | |
| 102 | 107 | |
| 103 | - /** | |
| 104 | - * Method mainwp_group_add() | |
| 105 | - * | |
| 106 | - * Add Group. | |
| 107 | - * | |
| 108 | - * @uses \MainWP\Dashboard\MainWP_Manage_Groups::add_group() | |
| 109 | - */ | |
| 110 | - public function mainwp_group_add() { | |
| 111 | - $this->secure_request( 'mainwp_group_add' ); | |
| 112 | - MainWP_Manage_Groups::add_group(); | |
| 113 | - } | |
| 108 | + /** | |
| 109 | + * Method mainwp_group_add() | |
| 110 | + * | |
| 111 | + * Add Group. | |
| 112 | + * | |
| 113 | + * @uses \MainWP\Dashboard\MainWP_Manage_Groups::add_group() | |
| 114 | + */ | |
| 115 | + public function mainwp_group_add() { | |
| 116 | + $this->secure_request( 'mainwp_group_add' ); | |
| 117 | + MainWP_Manage_Groups::add_group(); | |
| 118 | + } | |
| 114 | 119 | |
| 115 | - /** | |
| 116 | - * Method ajax_group_sites_add() | |
| 117 | - * | |
| 118 | - * Add Group in modal. | |
| 119 | - */ | |
| 120 | - public function ajax_group_sites_add() { | |
| 121 | - $this->secure_request( 'mainwp_group_sites_add' ); | |
| 122 | - // phpcs:disable WordPress.Security.NonceVerification,WordPress.Security.ValidatedSanitizedInput.InputNotSanitized | |
| 123 | - $newName = isset( $_POST['newName'] ) ? sanitize_text_field( wp_unslash( $_POST['newName'] ) ) : ''; | |
| 124 | - $newColor = isset( $_POST['newColor'] ) ? sanitize_hex_color( wp_unslash( $_POST['newColor'] ) ) : ''; | |
| 125 | - if ( empty( $newColor ) && ! empty( $tmp_color ) ) { | |
| 126 | - $newColor = '#cce2ff'; // default. | |
| 127 | - } | |
| 128 | - $selected_sites = isset( $_POST['selected_sites'] ) && is_array( $_POST['selected_sites'] ) ? array_map( 'intval', wp_unslash( $_POST['selected_sites'] ) ) : array(); | |
| 129 | - $selected_sites = array_filter( $selected_sites ); | |
| 130 | - // phpcs:enable | |
| 131 | - $success = false; | |
| 132 | - if ( ! empty( $newName ) ) { | |
| 133 | - $success = MainWP_Manage_Groups::add_group_sites( $newName, $selected_sites, $newColor ); | |
| 134 | - } | |
| 135 | - if ( ! $success ) { | |
| 136 | - wp_die( wp_json_encode( array( 'error' => esc_html__( 'Unexpected error occurred. Please try again.', 'mainwp' ) ) ) ); | |
| 137 | - } else { | |
| 138 | - wp_die( wp_json_encode( array( 'success' => 1 ) ) ); | |
| 139 | - } | |
| 140 | - } | |
| 120 | + /** | |
| 121 | + * Method ajax_group_sites_add() | |
| 122 | + * | |
| 123 | + * Add Group in modal. | |
| 124 | + */ | |
| 125 | + public function ajax_group_sites_add() { | |
| 126 | + $this->secure_request( 'mainwp_group_sites_add' ); | |
| 127 | + // phpcs:disable WordPress.Security.NonceVerification,WordPress.Security.ValidatedSanitizedInput.InputNotSanitized | |
| 128 | + $newName = isset( $_POST['newName'] ) ? sanitize_text_field( wp_unslash( $_POST['newName'] ) ) : ''; | |
| 129 | + $newColor = isset( $_POST['newColor'] ) ? sanitize_hex_color( wp_unslash( $_POST['newColor'] ) ) : ''; | |
| 130 | + if ( empty( $newColor ) ) { | |
| 131 | + $newColor = '#cce2ff'; // default. | |
| 132 | + } | |
| 133 | + $selected_sites = isset( $_POST['selected_sites'] ) && is_array( $_POST['selected_sites'] ) ? array_map( 'intval', wp_unslash( $_POST['selected_sites'] ) ) : array(); | |
| 134 | + $selected_sites = array_filter( $selected_sites ); | |
| 135 | + // phpcs:enable | |
| 136 | + $success = false; | |
| 137 | + if ( ! empty( $newName ) ) { | |
| 138 | + $success = MainWP_Manage_Groups::add_group_sites( $newName, $selected_sites, $newColor ); | |
| 139 | + } | |
| 140 | + if ( ! $success ) { | |
| 141 | + wp_die( wp_json_encode( array( 'error' => esc_html__( 'Unexpected error occurred. Please try again.', 'mainwp' ) ) ) ); | |
| 142 | + } else { | |
| 143 | + wp_die( wp_json_encode( array( 'success' => $success ) ) ); | |
| 144 | + } | |
| 145 | + } | |
| 141 | 146 | |
| 142 | 147 | |
| 143 | - /** | |
| 144 | - * Method mainwp_group_getsites() | |
| 145 | - * | |
| 146 | - * Get Child Sites in group. | |
| 147 | - */ | |
| 148 | - public function mainwp_group_getsites() { | |
| 148 | + /** | |
| 149 | + * Method mainwp_group_getsites() | |
| 150 | + * | |
| 151 | + * Get Child Sites in group. | |
| 152 | + */ | |
| 153 | + public function mainwp_group_getsites() { | |
| 149 | 154 | |
| 150 | - $this->secure_request( 'mainwp_group_getsites' ); | |
| 151 | - //phpcs:disable WordPress.Security.NonceVerification.Missing | |
| 152 | - $groupid = isset( $_POST['groupId'] ) && ! empty( $_POST['groupId'] ) ? intval( $_POST['groupId'] ) : false; // phpcs:ignore WordPress.Security.NonceVerification.Missing,WordPress.Security.ValidatedSanitizedInput.InputNotSanitized | |
| 153 | - //phpcs:enable | |
| 155 | + $this->secure_request( 'mainwp_group_getsites' ); | |
| 156 | + //phpcs:disable WordPress.Security.NonceVerification.Missing | |
| 157 | + $groupid = isset( $_POST['groupId'] ) && ! empty( $_POST['groupId'] ) ? intval( $_POST['groupId'] ) : false; // phpcs:ignore WordPress.Security.NonceVerification.Missing,WordPress.Security.ValidatedSanitizedInput.InputNotSanitized | |
| 158 | + //phpcs:enable | |
| 154 | 159 | |
| 155 | - if ( $groupid ) { | |
| 156 | - $group = MainWP_DB_Common::instance()->get_group_by_id( $groupid ); | |
| 157 | - if ( ! empty( $group ) ) { | |
| 158 | - $websites = MainWP_DB::instance()->get_websites_by_group_id( $group->id ); | |
| 159 | - $websiteIds = array(); | |
| 160 | - if ( ! empty( $websites ) ) { | |
| 161 | - foreach ( $websites as $website ) { | |
| 162 | - $websiteIds[] = $website->id; | |
| 163 | - } | |
| 164 | - } | |
| 160 | + if ( $groupid ) { | |
| 161 | + $group = MainWP_DB_Common::instance()->get_group_by_id( $groupid ); | |
| 162 | + if ( ! empty( $group ) ) { | |
| 163 | + $websites = MainWP_DB::instance()->get_websites_by_group_id( $group->id ); | |
| 164 | + $websiteIds = array(); | |
| 165 | + if ( ! empty( $websites ) ) { | |
| 166 | + foreach ( $websites as $website ) { | |
| 167 | + $websiteIds[] = $website->id; | |
| 168 | + } | |
| 169 | + } | |
| 165 | 170 | |
| 166 | - die( wp_json_encode( $websiteIds ) ); // phpcs:ignore WordPress.Security.EscapeOutput | |
| 167 | - } | |
| 168 | - } | |
| 169 | - die( 'ERROR' ); | |
| 170 | - } | |
| 171 | + die( wp_json_encode( $websiteIds ) ); // phpcs:ignore WordPress.Security.EscapeOutput | |
| 172 | + } | |
| 173 | + } | |
| 174 | + die( 'ERROR' ); | |
| 175 | + } | |
| 171 | 176 | |
| 172 | - /** | |
| 173 | - * Method mainwp_group_updategroup() | |
| 174 | - * | |
| 175 | - * Update Group. | |
| 176 | - * | |
| 177 | - * @uses \MainWP\Dashboard\MainWP_Manage_Groups::update_group() | |
| 178 | - */ | |
| 179 | - public function mainwp_group_updategroup() { | |
| 180 | - $this->secure_request( 'mainwp_group_updategroup' ); | |
| 177 | + /** | |
| 178 | + * Method mainwp_group_updategroup() | |
| 179 | + * | |
| 180 | + * Update Group. | |
| 181 | + * | |
| 182 | + * @uses \MainWP\Dashboard\MainWP_Manage_Groups::update_group() | |
| 183 | + */ | |
| 184 | + public function mainwp_group_updategroup() { | |
| 185 | + $this->secure_request( 'mainwp_group_updategroup' ); | |
| 181 | 186 | |
| 182 | - MainWP_Manage_Groups::update_group(); | |
| 183 | - } | |
| 187 | + MainWP_Manage_Groups::update_group(); | |
| 188 | + } | |
| 184 | 189 | |
| 185 | - /** | |
| 186 | - * Method mainwp_checkwp() | |
| 187 | - * | |
| 188 | - * Check if WP can be added. | |
| 189 | - * | |
| 190 | - * @uses \MainWP\Dashboard\MainWP_Manage_Sites_Handler::check_site() | |
| 191 | - */ | |
| 192 | - public function mainwp_checkwp() { | |
| 193 | - $this->check_security( 'mainwp_checkwp', 'security' ); | |
| 194 | - MainWP_Manage_Sites_Handler::check_site(); | |
| 195 | - } | |
| 190 | + /** | |
| 191 | + * Method mainwp_checkwp() | |
| 192 | + * | |
| 193 | + * Check if WP can be added. | |
| 194 | + * | |
| 195 | + * @uses \MainWP\Dashboard\MainWP_Manage_Sites_Handler::check_site() | |
| 196 | + */ | |
| 197 | + public function mainwp_checkwp() { | |
| 198 | + $this->check_security( 'mainwp_checkwp', 'security' ); | |
| 199 | + MainWP_Manage_Sites_Handler::check_site(); | |
| 200 | + } | |
| 196 | 201 | |
| 197 | - /** | |
| 198 | - * Method mainwp_addwp() | |
| 199 | - * | |
| 200 | - * Add WP to the database. | |
| 201 | - * | |
| 202 | - * @uses \MainWP\Dashboard\MainWP_Manage_Sites_Handler::add_site() | |
| 203 | - */ | |
| 204 | - public function mainwp_addwp() { | |
| 205 | - $this->check_security( 'mainwp_addwp', 'security' ); | |
| 206 | - MainWP_Manage_Sites_Handler::add_site(); | |
| 207 | - } | |
| 202 | + /** | |
| 203 | + * Method mainwp_addwp() | |
| 204 | + * | |
| 205 | + * Add WP to the database. | |
| 206 | + * | |
| 207 | + * @uses \MainWP\Dashboard\MainWP_Manage_Sites_Handler::add_site() | |
| 208 | + */ | |
| 209 | + public function mainwp_addwp() { | |
| 210 | + $this->check_security( 'mainwp_addwp', 'security' ); | |
| 211 | + MainWP_Manage_Sites_Handler::add_site(); | |
| 212 | + } | |
| 208 | 213 | |
| 209 | - /** | |
| 210 | - * Method get_site_icon() | |
| 211 | - * | |
| 212 | - * Get Child Site Favicon. | |
| 213 | - * | |
| 214 | - * @uses \MainWP\Dashboard\MainWP_Sync::get_wp_icon() | |
| 215 | - */ | |
| 216 | - public function get_site_icon() { | |
| 217 | - $this->check_security( 'mainwp_get_site_icon', 'security' ); | |
| 218 | - $siteId = isset( $_POST['siteId'] ) ? intval( $_POST['siteId'] ) : null; // phpcs:ignore WordPress.Security.NonceVerification,WordPress.Security.ValidatedSanitizedInput.InputNotSanitized | |
| 219 | - $result = MainWP_Sync::get_wp_icon( $siteId ); | |
| 220 | - wp_send_json( $result ); | |
| 221 | - } | |
| 214 | + /** | |
| 215 | + * Method get_site_icon() | |
| 216 | + * | |
| 217 | + * Get Child Site Favicon. | |
| 218 | + * | |
| 219 | + * @uses \MainWP\Dashboard\MainWP_Sync::get_wp_icon() | |
| 220 | + */ | |
| 221 | + public function get_site_icon() { | |
| 222 | + $this->check_security( 'mainwp_get_site_icon', 'security' ); | |
| 223 | + $siteId = isset( $_POST['siteId'] ) ? intval( $_POST['siteId'] ) : null; // phpcs:ignore WordPress.Security.NonceVerification,WordPress.Security.ValidatedSanitizedInput.InputNotSanitized | |
| 224 | + $result = MainWP_Sync::get_wp_icon( $siteId ); | |
| 225 | + wp_send_json( $result ); | |
| 226 | + } | |
| 222 | 227 | |
| 223 | - /** | |
| 224 | - * Method check_abandoned() | |
| 225 | - * | |
| 226 | - * Check abandoned plugins or themes. | |
| 227 | - */ | |
| 228 | - public function check_abandoned() { | |
| 229 | - $this->check_security( 'mainwp_check_abandoned', 'security' ); | |
| 230 | - $siteId = isset( $_POST['siteId'] ) ? intval( $_POST['siteId'] ) : null; // phpcs:ignore WordPress.Security.NonceVerification,WordPress.Security.ValidatedSanitizedInput.InputNotSanitized | |
| 231 | - $which = isset( $_POST['which'] ) ? sanitize_text_field( wp_unslash( $_POST['which'] ) ) : ''; // phpcs:ignore WordPress.Security.NonceVerification,WordPress.Security.ValidatedSanitizedInput.InputNotSanitized | |
| 232 | - $result = MainWP_Utility::check_abandoned( $siteId, $which ); | |
| 233 | - wp_send_json( $result ); | |
| 234 | - } | |
| 228 | + /** | |
| 229 | + * Method check_abandoned() | |
| 230 | + * | |
| 231 | + * Check abandoned plugins or themes. | |
| 232 | + */ | |
| 233 | + public function check_abandoned() { | |
| 234 | + $this->check_security( 'mainwp_check_abandoned', 'security' ); | |
| 235 | + $siteId = isset( $_POST['siteId'] ) ? intval( $_POST['siteId'] ) : null; // phpcs:ignore WordPress.Security.NonceVerification,WordPress.Security.ValidatedSanitizedInput.InputNotSanitized | |
| 236 | + $which = isset( $_POST['which'] ) ? sanitize_text_field( wp_unslash( $_POST['which'] ) ) : ''; // phpcs:ignore WordPress.Security.NonceVerification,WordPress.Security.ValidatedSanitizedInput.InputNotSanitized | |
| 237 | + $result = MainWP_Utility::check_abandoned( $siteId, $which ); | |
| 238 | + wp_send_json( $result ); | |
| 239 | + } | |
| 235 | 240 | |
| 236 | - /** | |
| 237 | - * Method mainwp_testwp() | |
| 238 | - * | |
| 239 | - * Test if Child Site can be reached. | |
| 240 | - * | |
| 241 | - * @uses \MainWP\Dashboard\MainWP_Connect::try_visit() | |
| 242 | - * @uses \MainWP\Dashboard\MainWP_DB::get_website_by_id() | |
| 243 | - * @uses \MainWP\Dashboard\MainWP_Utility::remove_http_prefix() | |
| 244 | - */ | |
| 245 | - public function mainwp_testwp() { // phpcs:ignore -- complex function. Current complexity is the only way to achieve desired results, pull request solutions appreciated. | |
| 246 | - $this->secure_request( 'mainwp_testwp' ); | |
| 241 | + /** | |
| 242 | + * Method mainwp_testwp() | |
| 243 | + * | |
| 244 | + * Test if Child Site can be reached. | |
| 245 | + * | |
| 246 | + * @uses \MainWP\Dashboard\MainWP_Connect::try_visit() | |
| 247 | + * @uses \MainWP\Dashboard\MainWP_DB::get_website_by_id() | |
| 248 | + * @uses \MainWP\Dashboard\MainWP_Utility::remove_http_prefix() | |
| 249 | + */ | |
| 250 | + public function mainwp_testwp() { // phpcs:ignore -- NOSONAR - complex function. Current complexity is the only way to achieve desired results, pull request solutions appreciated. | |
| 251 | + $this->secure_request( 'mainwp_testwp' ); | |
| 247 | 252 | |
| 248 | - $url = null; | |
| 249 | - $name = null; | |
| 250 | - $http_user = null; | |
| 251 | - $http_pass = null; | |
| 252 | - $verifyCertificate = 1; | |
| 253 | - $sslVersion = 0; | |
| 253 | + $url = null; | |
| 254 | + $name = null; | |
| 255 | + $http_user = null; | |
| 256 | + $http_pass = null; | |
| 257 | + $verifyCertificate = 1; | |
| 258 | + $sslVersion = 0; | |
| 254 | 259 | |
| 255 | - // phpcs:disable WordPress.Security.NonceVerification,WordPress.Security.ValidatedSanitizedInput.InputNotSanitized | |
| 256 | - if ( isset( $_POST['url'] ) ) { | |
| 257 | - $url = sanitize_text_field( wp_unslash( $_POST['url'] ) ); | |
| 258 | - $url = urldecode( $url ); | |
| 260 | + // phpcs:disable WordPress.Security.NonceVerification,WordPress.Security.ValidatedSanitizedInput.InputNotSanitized | |
| 261 | + if ( isset( $_POST['url'] ) ) { | |
| 262 | + $url = sanitize_text_field( wp_unslash( $_POST['url'] ) ); | |
| 263 | + $url = urldecode( $url ); | |
| 259 | 264 | |
| 260 | - $invalid = false; | |
| 261 | - $info = wp_parse_url( $url ); | |
| 265 | + $invalid = false; | |
| 266 | + $info = wp_parse_url( $url ); | |
| 262 | 267 | |
| 263 | - $def_not_allow = array( 21, 22 ); // not allow ports 21, 22. | |
| 264 | - $not_allow_ports = apply_filters( 'mainwp_connect_sites_not_allow_ports', $def_not_allow, $url ); | |
| 268 | + $def_not_allow = array( 21, 22 ); // not allow ports 21, 22. | |
| 269 | + $not_allow_ports = apply_filters( 'mainwp_connect_sites_not_allow_ports', $def_not_allow, $url ); | |
| 265 | 270 | |
| 266 | - if ( ! is_array( $not_allow_ports ) ) { | |
| 267 | - $not_allow_ports = $def_not_allow; | |
| 268 | - } | |
| 271 | + if ( ! is_array( $not_allow_ports ) ) { | |
| 272 | + $not_allow_ports = $def_not_allow; | |
| 273 | + } | |
| 269 | 274 | |
| 270 | - if ( is_array( $info ) && ! empty( $info['port'] ) && ( in_array( intval( $info['port'] ), $not_allow_ports, true ) ) ) { | |
| 271 | - $invalid = true; | |
| 272 | - } | |
| 275 | + if ( is_array( $info ) && ! empty( $info['port'] ) && ( in_array( intval( $info['port'] ), $not_allow_ports, true ) ) ) { | |
| 276 | + $invalid = true; | |
| 277 | + } | |
| 273 | 278 | |
| 274 | - $temp_url = MainWP_Utility::remove_http_prefix( $url, true ); | |
| 279 | + $temp_url = MainWP_Utility::remove_http_prefix( $url, true ); | |
| 275 | 280 | |
| 276 | - if ( $invalid || false !== strpos( $url, '?=' ) ) { | |
| 277 | - die( wp_json_encode( array( 'error' => esc_html__( 'Invalid URL.', 'mainwp' ) ) ) ); | |
| 278 | - } | |
| 281 | + if ( $invalid || false !== strpos( $url, '?=' ) ) { | |
| 282 | + die( wp_json_encode( array( 'error' => esc_html__( 'Invalid URL.', 'mainwp' ) ) ) ); | |
| 283 | + } | |
| 279 | 284 | |
| 280 | - if ( strpos( $temp_url, ':' ) ) { | |
| 281 | - $invalid = true; | |
| 282 | - $allow_ports = apply_filters( 'mainwp_connect_sites_allow_ports', array(), $url ); | |
| 283 | - if ( ! empty( $allow_ports ) && is_array( $allow_ports ) ) { | |
| 284 | - if ( is_array( $info ) && ! empty( $info['port'] ) && ( in_array( intval( $info['port'] ), $allow_ports, true ) ) ) { | |
| 285 | - $invalid = false; | |
| 286 | - } | |
| 287 | - } | |
| 288 | - if ( $invalid ) { | |
| 289 | - die( wp_json_encode( array( 'error' => esc_html__( 'Invalid URL.', 'mainwp' ) ) ) ); | |
| 290 | - } | |
| 291 | - } | |
| 285 | + if ( strpos( $temp_url, ':' ) ) { | |
| 286 | + $invalid = true; | |
| 287 | + $allow_ports = apply_filters( 'mainwp_connect_sites_allow_ports', array(), $url ); | |
| 288 | + if ( ! empty( $allow_ports ) && is_array( $allow_ports ) && is_array( $info ) && ! empty( $info['port'] ) && ( in_array( intval( $info['port'] ), $allow_ports, true ) ) ) { | |
| 289 | + $invalid = false; | |
| 290 | + } | |
| 291 | + if ( $invalid ) { | |
| 292 | + die( wp_json_encode( array( 'error' => esc_html__( 'Invalid URL.', 'mainwp' ) ) ) ); | |
| 293 | + } | |
| 294 | + } | |
| 292 | 295 | |
| 293 | - $verifyCertificate = isset( $_POST['test_verify_cert'] ) ? intval( $_POST['test_verify_cert'] ) : 1; | |
| 294 | - $forceUseIPv4 = apply_filters( 'mainwp_manage_sites_force_use_ipv4', false, $url ); | |
| 295 | - $sslVersion = isset( $_POST['ssl_version'] ) ? intval( $_POST['ssl_version'] ) : 0; | |
| 296 | - $http_user = isset( $_POST['http_user'] ) ? sanitize_text_field( wp_unslash( $_POST['http_user'] ) ) : ''; | |
| 297 | - $http_pass = isset( $_POST['http_pass'] ) ? wp_unslash( $_POST['http_pass'] ) : ''; | |
| 296 | + $verifyCertificate = isset( $_POST['test_verify_cert'] ) ? intval( $_POST['test_verify_cert'] ) : 1; | |
| 297 | + $forceUseIPv4 = apply_filters( 'mainwp_manage_sites_force_use_ipv4', false, $url ); | |
| 298 | + $sslVersion = isset( $_POST['ssl_version'] ) ? intval( $_POST['ssl_version'] ) : 0; | |
| 299 | + $http_user = isset( $_POST['http_user'] ) ? sanitize_text_field( wp_unslash( $_POST['http_user'] ) ) : ''; | |
| 300 | + $http_pass = isset( $_POST['http_pass'] ) ? wp_unslash( $_POST['http_pass'] ) : ''; | |
| 298 | 301 | |
| 299 | - } elseif ( isset( $_POST['siteid'] ) ) { | |
| 300 | - $website = MainWP_DB::instance()->get_website_by_id( intval( $_POST['siteid'] ) ); | |
| 301 | - if ( $website ) { | |
| 302 | - $url = $website->url; | |
| 303 | - $name = $website->name; | |
| 304 | - $verifyCertificate = (int) $website->verify_certificate; | |
| 305 | - $forceUseIPv4 = $website->force_use_ipv4; | |
| 306 | - $sslVersion = $website->ssl_version; | |
| 307 | - $http_user = $website->http_user; | |
| 308 | - $http_pass = $website->http_pass; | |
| 309 | - } | |
| 310 | - } | |
| 311 | - // phpcs:enable | |
| 302 | + } elseif ( isset( $_POST['siteid'] ) ) { | |
| 303 | + $website = MainWP_DB::instance()->get_website_by_id( intval( $_POST['siteid'] ) ); | |
| 304 | + if ( $website ) { | |
| 305 | + $url = $website->url; | |
| 306 | + $name = $website->name; | |
| 307 | + $verifyCertificate = (int) $website->verify_certificate; | |
| 308 | + $forceUseIPv4 = $website->force_use_ipv4; | |
| 309 | + $sslVersion = $website->ssl_version; | |
| 310 | + // MWP-1548: decrypt at the boundary so the reconnect / | |
| 311 | + // try_visit call below uses plaintext credentials. | |
| 312 | + $http_user = MainWP_Credential_Storage::decrypt_credential( $website->http_user ); | |
| 313 | + $http_pass = MainWP_Credential_Storage::decrypt_credential( $website->http_pass ); | |
| 314 | + } | |
| 315 | + } | |
| 316 | + // phpcs:enable | |
| 312 | 317 | |
| 313 | - $ssl_verifyhost = false; | |
| 318 | + $ssl_verifyhost = false; | |
| 314 | 319 | |
| 315 | - if ( 1 === $verifyCertificate ) { | |
| 316 | - $ssl_verifyhost = true; | |
| 317 | - } elseif ( 2 === $verifyCertificate ) { | |
| 318 | - if ( ( ( false === get_option( 'mainwp_sslVerifyCertificate' ) ) || ( 1 === (int) get_option( 'mainwp_sslVerifyCertificate' ) ) ) ) { | |
| 319 | - $ssl_verifyhost = true; | |
| 320 | - } | |
| 321 | - } | |
| 320 | + if ( 1 === $verifyCertificate ) { | |
| 321 | + $ssl_verifyhost = true; | |
| 322 | + } elseif ( 2 === $verifyCertificate ) { | |
| 323 | + if ( ( false === get_option( 'mainwp_sslVerifyCertificate' ) ) || ( 1 === (int) get_option( 'mainwp_sslVerifyCertificate' ) ) ) { | |
| 324 | + $ssl_verifyhost = true; | |
| 325 | + } | |
| 326 | + } | |
| 322 | 327 | |
| 323 | - $rslt = MainWP_Connect::try_visit( $url, $ssl_verifyhost, $http_user, $http_pass, $sslVersion, $forceUseIPv4 ); | |
| 328 | + $rslt = MainWP_Connect::try_visit( $url, $ssl_verifyhost, $http_user, $http_pass, $sslVersion, $forceUseIPv4 ); | |
| 324 | 329 | |
| 325 | - if ( isset( $rslt['error'] ) && ( '' !== $rslt['error'] ) && ( 'wp-admin/' !== substr( $url, - 9 ) ) ) { | |
| 326 | - if ( substr( $url, - 1 ) !== '/' ) { | |
| 327 | - $url .= '/'; | |
| 328 | - } | |
| 329 | - $url .= 'wp-admin/'; | |
| 330 | - $newrslt = MainWP_Connect::try_visit( $url, $ssl_verifyhost, $http_user, $http_pass, $sslVersion, $forceUseIPv4 ); | |
| 331 | - if ( isset( $newrslt['error'] ) && ( '' !== $rslt['error'] ) ) { | |
| 332 | - $rslt = $newrslt; | |
| 333 | - } | |
| 334 | - } | |
| 330 | + if ( isset( $rslt['error'] ) && ( '' !== $rslt['error'] ) && ( 'wp-admin/' !== substr( $url, - 9 ) ) ) { | |
| 331 | + if ( substr( $url, - 1 ) !== '/' ) { | |
| 332 | + $url .= '/'; | |
| 333 | + } | |
| 334 | + $url .= 'wp-admin/'; | |
| 335 | + $newrslt = MainWP_Connect::try_visit( $url, $ssl_verifyhost, $http_user, $http_pass, $sslVersion, $forceUseIPv4 ); | |
| 336 | + if ( isset( $newrslt['error'] ) && ( '' !== $rslt['error'] ) ) { | |
| 337 | + $rslt = $newrslt; | |
| 338 | + } | |
| 339 | + } | |
| 335 | 340 | |
| 336 | - if ( null !== $name ) { | |
| 337 | - $rslt['sitename'] = esc_html( $name ); | |
| 338 | - } | |
| 341 | + if ( null !== $name ) { | |
| 342 | + $rslt['sitename'] = esc_html( $name ); | |
| 343 | + } | |
| 339 | 344 | |
| 340 | - wp_send_json( $rslt ); | |
| 341 | - } | |
| 345 | + wp_send_json( $rslt ); | |
| 346 | + } | |
| 342 | 347 | |
| 343 | - /** | |
| 344 | - * Method mainwp_removesite() | |
| 345 | - * | |
| 346 | - * Remove a website from MainWP. | |
| 347 | - * | |
| 348 | - * @uses \MainWP\Dashboard\MainWP_Manage_Sites_Handler::remove_site() | |
| 349 | - */ | |
| 350 | - public function mainwp_removesite() { | |
| 351 | - if ( ! mainwp_current_user_have_right( 'dashboard', 'delete_sites' ) ) { | |
| 352 | - die( wp_json_encode( array( 'error' => mainwp_do_not_have_permissions( esc_html__( 'delete sites', 'mainwp' ), false ) ) ) ); | |
| 353 | - } | |
| 348 | + /** | |
| 349 | + * Method mainwp_removesite() | |
| 350 | + * | |
| 351 | + * Remove a website from MainWP. | |
| 352 | + * | |
| 353 | + * @uses \MainWP\Dashboard\MainWP_Manage_Sites_Handler::remove_site() | |
| 354 | + */ | |
| 355 | + public function mainwp_removesite() { | |
| 356 | + if ( ! \mainwp_current_user_can( 'dashboard', 'delete_sites' ) ) { | |
| 357 | + die( wp_json_encode( array( 'error' => \mainwp_do_not_have_permissions( esc_html__( 'delete sites', 'mainwp' ), false ) ) ) ); | |
| 358 | + } | |
| 354 | 359 | |
| 355 | - $this->secure_request( 'mainwp_removesite' ); | |
| 360 | + $this->secure_request( 'mainwp_removesite' ); | |
| 356 | 361 | |
| 357 | - MainWP_Manage_Sites_Handler::remove_site(); | |
| 358 | - } | |
| 362 | + static::invalidate_warm_cache(); | |
| 359 | 363 | |
| 360 | - /** | |
| 361 | - * Method mainwp_reconnectwp() | |
| 362 | - * | |
| 363 | - * Reconnect to Child Site. | |
| 364 | - * | |
| 365 | - * @uses \MainWP\Dashboard\MainWP_Manage_Sites_Handler::reconnect_site() | |
| 366 | - */ | |
| 367 | - public function mainwp_reconnectwp() { | |
| 368 | - $this->secure_request( 'mainwp_reconnectwp' ); | |
| 364 | + MainWP_Manage_Sites_Handler::remove_site(); | |
| 365 | + } | |
| 369 | 366 | |
| 370 | - MainWP_Manage_Sites_Handler::reconnect_site(); | |
| 371 | - } | |
| 372 | 367 | |
| 373 | - /** | |
| 374 | - * Method mainwp_updatechildsite_value() | |
| 375 | - * | |
| 376 | - * Update Child Site value. | |
| 377 | - * | |
| 378 | - * @uses \MainWP\Dashboard\MainWP_Manage_Sites_Handler::update_child_site_value() | |
| 379 | - */ | |
| 380 | - public function mainwp_updatechildsite_value() { | |
| 381 | - $this->secure_request( 'mainwp_updatechildsite_value' ); | |
| 368 | + /** | |
| 369 | + * Method invalidate_warm_cache() | |
| 370 | + */ | |
| 371 | + public static function invalidate_warm_cache() { | |
| 372 | + MainWP_Cache_Warm_Helper::invalidate_manage_pages( array( 'managesites', 'mainwp_tab' ) ); | |
| 373 | + } | |
| 382 | 374 | |
| 383 | - MainWP_Manage_Sites_Handler::update_child_site_value(); | |
| 384 | - } | |
| 375 | + /** | |
| 376 | + * Method mainwp_reconnectwp() | |
| 377 | + * | |
| 378 | + * Reconnect to Child Site. | |
| 379 | + * | |
| 380 | + * @uses \MainWP\Dashboard\MainWP_Manage_Sites_Handler::reconnect_site() | |
| 381 | + */ | |
| 382 | + public function mainwp_reconnectwp() { | |
| 383 | + $this->secure_request( 'mainwp_reconnectwp' ); | |
| 385 | 384 | |
| 386 | - /** | |
| 387 | - * Method mainwp_syncsites() | |
| 388 | - * | |
| 389 | - * Sync Child Sites. | |
| 390 | - * | |
| 391 | - * @uses \MainWP\Dashboard\MainWP_Updates_Overview::dismiss_sync_errors() | |
| 392 | - */ | |
| 393 | - public function mainwp_syncsites() { | |
| 394 | - $this->secure_request( 'mainwp_syncsites' ); | |
| 395 | - MainWP_Updates_Overview::dismiss_sync_errors( false ); | |
| 385 | + MainWP_Manage_Sites_Handler::reconnect_site(); | |
| 386 | + } | |
| 396 | 387 | |
| 397 | - $website = null; | |
| 398 | - $wp_id = isset( $_POST['wp_id'] ) ? intval( $_POST['wp_id'] ) : false; // phpcs:ignore WordPress.Security.NonceVerification,WordPress.Security.ValidatedSanitizedInput.InputNotSanitized | |
| 399 | - if ( $wp_id ) { | |
| 400 | - $website = MainWP_DB::instance()->get_website_by_id( $wp_id ); | |
| 401 | - } | |
| 388 | + /** | |
| 389 | + * Method mainwp_updatechildsite_value() | |
| 390 | + * | |
| 391 | + * Update Child Site value. | |
| 392 | + * | |
| 393 | + * @uses \MainWP\Dashboard\MainWP_Manage_Sites_Handler::update_child_site_value() | |
| 394 | + */ | |
| 395 | + public function mainwp_updatechildsite_value() { | |
| 396 | + $this->secure_request( 'mainwp_updatechildsite_value' ); | |
| 402 | 397 | |
| 403 | - if ( null === $website ) { | |
| 404 | - die( wp_json_encode( array( 'error' => esc_html__( 'Site ID not found. Please reload the page and try again.', 'mainwp' ) ) ) ); | |
| 405 | - } | |
| 398 | + MainWP_Manage_Sites_Handler::update_child_site_value(); | |
| 399 | + } | |
| 406 | 400 | |
| 407 | - if ( MainWP_Sync::sync_website( $website ) ) { | |
| 408 | - $website = MainWP_DB::instance()->get_website_by_id( $website->id ); // reload. | |
| 409 | - /** | |
| 410 | - * Fires immediately after website synced successfully. | |
| 411 | - * | |
| 412 | - * @since 4.6 | |
| 413 | - * | |
| 414 | - * @param object $website website data. | |
| 415 | - */ | |
| 416 | - do_action( 'mainwp_after_sync_site_success', $website ); | |
| 417 | - die( wp_json_encode( array( 'result' => 'SUCCESS' ) ) ); | |
| 418 | - } | |
| 401 | + /** | |
| 402 | + * Method mainwp_syncsites() | |
| 403 | + * | |
| 404 | + * Sync Child Sites. | |
| 405 | + * | |
| 406 | + * @uses \MainWP\Dashboard\MainWP_Updates_Overview::dismiss_sync_errors() | |
| 407 | + */ | |
| 408 | + public function mainwp_syncsites() { | |
| 409 | + $this->secure_request( 'mainwp_syncsites' ); | |
| 410 | + MainWP_Updates_Overview::dismiss_sync_errors( false ); | |
| 419 | 411 | |
| 420 | - $website = MainWP_DB::instance()->get_website_by_id( $website->id ); | |
| 412 | + $website = null; | |
| 413 | + $wp_id = isset( $_POST['wp_id'] ) ? intval( $_POST['wp_id'] ) : false; // phpcs:ignore WordPress.Security.NonceVerification,WordPress.Security.ValidatedSanitizedInput.InputNotSanitized | |
| 414 | + if ( $wp_id ) { | |
| 415 | + $website = MainWP_DB::instance()->get_website_by_id( $wp_id ); | |
| 416 | + } | |
| 421 | 417 | |
| 422 | - die( wp_json_encode( array( 'error' => esc_html( wp_strip_all_tags( $website->sync_errors ) ) ) ) ); | |
| 423 | - } | |
| 418 | + if ( null === $website ) { | |
| 419 | + die( wp_json_encode( array( 'error' => esc_html__( 'Site ID not found. Please reload the page and try again.', 'mainwp' ) ) ) ); | |
| 420 | + } | |
| 424 | 421 | |
| 425 | - /** | |
| 426 | - * Method mainwp_checksites() | |
| 427 | - * | |
| 428 | - * Check Child Sites. | |
| 429 | - * | |
| 430 | - * @uses \MainWP\Dashboard\MainWP_Monitoring_Handler::ajax_check_status_site() | |
| 431 | - */ | |
| 432 | - public function mainwp_checksites() { | |
| 433 | - $this->secure_request( 'mainwp_checksites' ); | |
| 434 | - MainWP_Monitoring_Handler::ajax_check_status_site(); | |
| 435 | - } | |
| 422 | + if ( MainWP_Sync::sync_website( $website ) ) { | |
| 423 | + $website = MainWP_DB::instance()->get_website_by_id( $website->id ); // reload. | |
| 424 | + /** | |
| 425 | + * Fires immediately after website synced successfully. | |
| 426 | + * | |
| 427 | + * @since 4.6 | |
| 428 | + * | |
| 429 | + * @param object $website website data. | |
| 430 | + */ | |
| 431 | + do_action( 'mainwp_after_sync_site_success', $website ); | |
| 432 | + die( wp_json_encode( array( 'result' => 'SUCCESS' ) ) ); | |
| 433 | + } | |
| 436 | 434 | |
| 437 | - /** | |
| 438 | - * Method mainwp_manage_sites_suspend_site() | |
| 439 | - * | |
| 440 | - * Check Child Sites. | |
| 441 | - * | |
| 442 | - * @uses \MainWP\Dashboard\MainWP_Sync::get_wp_icon() | |
| 443 | - */ | |
| 444 | - public function manage_suspend_site() { | |
| 445 | - $this->secure_request( 'mainwp_manage_sites_suspend_site' ); | |
| 446 | - $siteId = isset( $_POST['siteid'] ) ? intval( $_POST['siteid'] ) : null; // phpcs:ignore WordPress.Security.NonceVerification,WordPress.Security.ValidatedSanitizedInput.InputNotSanitized | |
| 447 | - $suspended = isset( $_POST['suspended'] ) && '1' === $_POST['suspended'] ? 1 : 0; // phpcs:ignore WordPress.Security.NonceVerification,WordPress.Security.ValidatedSanitizedInput.InputNotSanitized | |
| 448 | - $newValues = array( | |
| 449 | - 'suspended' => $suspended, | |
| 450 | - ); | |
| 435 | + $website = MainWP_DB::instance()->get_website_by_id( $website->id ); | |
| 451 | 436 | |
| 452 | - if ( $siteId ) { | |
| 453 | - $website = MainWP_DB::instance()->get_website_by_id( $siteId ); | |
| 454 | - if ( $website && $website->suspended != $suspended ) { //phpcs:ignore -- to valid. | |
| 455 | - MainWP_DB::instance()->update_website_values( $siteId, $newValues ); | |
| 456 | - /** | |
| 457 | - * Fires immediately after website suspended/unsuspend. | |
| 458 | - * | |
| 459 | - * @since 4.5.1.1 | |
| 460 | - * | |
| 461 | - * @param object $website website data. | |
| 462 | - * @param int $suspended The new suspended value. | |
| 463 | - */ | |
| 464 | - do_action( 'mainwp_site_suspended', $website, $suspended ); | |
| 465 | - } | |
| 466 | - wp_send_json( array( 'result' => 'success' ) ); | |
| 467 | - } else { | |
| 468 | - wp_send_json( array( 'error' => 'Error: site id empty' ) ); | |
| 469 | - } | |
| 470 | - } | |
| 437 | + die( wp_json_encode( array( 'error' => esc_html( wp_strip_all_tags( $website->sync_errors ) ) ) ) ); | |
| 438 | + } | |
| 439 | + | |
| 440 | + /** | |
| 441 | + * Method ajax_checksites() | |
| 442 | + * | |
| 443 | + * Check Child Sites. | |
| 444 | + */ | |
| 445 | + public function ajax_checksites() { | |
| 446 | + $this->secure_request( 'mainwp_checksites' ); | |
| 447 | + | |
| 448 | + $website = null; | |
| 449 | + if ( isset( $_POST['wp_id'] ) ) { // phpcs:ignore WordPress.Security.NonceVerification,WordPress.Security.ValidatedSanitizedInput.InputNotSanitized | |
| 450 | + $website = MainWP_DB::instance()->get_website_by_id( intval( $_POST['wp_id'] ) ); // phpcs:ignore WordPress.Security.NonceVerification,WordPress.Security.ValidatedSanitizedInput.InputNotSanitized | |
| 451 | + } | |
| 452 | + | |
| 453 | + if ( null === $website ) { | |
| 454 | + die( wp_json_encode( array( 'error' => esc_html__( 'Site ID not found. Please reload the page and try again.', 'mainwp' ) ) ) ); | |
| 455 | + } | |
| 456 | + | |
| 457 | + MainWP_Utility::end_session(); | |
| 458 | + $result = MainWP_Monitoring_Handler::handle_check_website( $website ); | |
| 459 | + MainWP_Utility::end_session(); | |
| 460 | + | |
| 461 | + if ( is_array( $result ) ) { | |
| 462 | + die( wp_json_encode( array( 'result' => 'success' ) ) ); | |
| 463 | + } else { | |
| 464 | + die( wp_json_encode( array( 'error' => esc_html__( 'Request failed. Please, try again.', 'mainwp' ) ) ) ); | |
| 465 | + } | |
| 466 | + } | |
| 467 | + | |
| 468 | + /** | |
| 469 | + * Method mainwp_manage_sites_suspend_site() | |
| 470 | + * | |
| 471 | + * Check Child Sites. | |
| 472 | + * | |
| 473 | + * @uses \MainWP\Dashboard\MainWP_Sync::get_wp_icon() | |
| 474 | + */ | |
| 475 | + public function manage_suspend_site() { | |
| 476 | + $this->secure_request( 'mainwp_manage_sites_suspend_site' ); | |
| 477 | + $siteId = isset( $_POST['siteid'] ) ? intval( $_POST['siteid'] ) : null; // phpcs:ignore WordPress.Security.NonceVerification,WordPress.Security.ValidatedSanitizedInput.InputNotSanitized | |
| 478 | + $suspended = isset( $_POST['suspended'] ) && '1' === $_POST['suspended'] ? 1 : 0; // phpcs:ignore WordPress.Security.NonceVerification,WordPress.Security.ValidatedSanitizedInput.InputNotSanitized | |
| 479 | + $newValues = array( | |
| 480 | + 'suspended' => $suspended, | |
| 481 | + ); | |
| 482 | + | |
| 483 | + if ( $siteId ) { | |
| 484 | + $website = MainWP_DB::instance()->get_website_by_id( $siteId ); | |
| 485 | + if ( $website && $website->suspended != $suspended ) { //phpcs:ignore -- to valid. | |
| 486 | + MainWP_DB::instance()->update_website_values( $siteId, $newValues ); | |
| 487 | + /** | |
| 488 | + * Fires immediately after website suspended/unsuspend. | |
| 489 | + * | |
| 490 | + * @since 4.5.1.1 | |
| 491 | + * | |
| 492 | + * @param object $website website data. | |
| 493 | + * @param int $suspended The new suspended value. | |
| 494 | + */ | |
| 495 | + do_action( 'mainwp_site_suspended', $website, $suspended ); | |
| 496 | + } | |
| 497 | + wp_send_json( array( 'result' => 'success' ) ); | |
| 498 | + } else { | |
| 499 | + wp_send_json( array( 'error' => 'Error: site id empty' ) ); | |
| 500 | + } | |
| 501 | + } | |
| 471 | 502 | } |