| @@ -40,9 +40,9 @@ | ||
| 40 | 40 | * @static |
| 41 | 41 | * @return MainWP_System |
| 42 | 42 | */ |
| 43 | 43 | public static function instance() { |
| 44 | - if ( null === self::$instance ) { | |
| 44 | + if ( null == self::$instance ) { | |
| 45 | 45 | self::$instance = new self(); |
| 46 | 46 | } |
| 47 | 47 | |
| 48 | 48 | return self::$instance; |
| @@ -51,10 +51,8 @@ | ||
| 51 | 51 | /** |
| 52 | 52 | * MainWP_System_Handler constructor. |
| 53 | 53 | * |
| 54 | 54 | * Run each time the class is called. |
| 55 | - * | |
| 56 | - * @uses \MainWP\Dashboard\MainWP_Extensions_Handler::get_class_name() | |
| 57 | 55 | */ |
| 58 | 56 | public function __construct() { |
| 59 | 57 | add_filter( 'mainwp-extension-enabled-check', array( MainWP_Extensions_Handler::get_class_name(), 'is_extension_enabled' ) ); // @deprecated Use 'mainwp_extension_enabled_check' instead. |
| 60 | 58 | add_filter( 'mainwp_extension_enabled_check', array( MainWP_Extensions_Handler::get_class_name(), 'is_extension_enabled' ) ); |
| @@ -70,9 +68,8 @@ | ||
| 70 | 68 | add_filter( 'mainwp-getdbsites', array( MainWP_Extensions_Handler::get_class_name(), 'hook_get_db_sites' ), 10, 5 ); // @deprecated Use 'mainwp_getdbsites' instead. |
| 71 | 69 | |
| 72 | 70 | add_filter( 'mainwp_getsites', array( MainWP_Extensions_Handler::get_class_name(), 'hook_get_sites' ), 10, 5 ); |
| 73 | 71 | add_filter( 'mainwp_getdbsites', array( MainWP_Extensions_Handler::get_class_name(), 'hook_get_db_sites' ), 10, 5 ); |
| 74 | - add_filter( 'mainwp_get_db_websites', array( MainWP_Extensions_Handler::get_class_name(), 'hook_get_db_websites' ), 10, 5 ); | |
| 75 | 72 | |
| 76 | 73 | /** |
| 77 | 74 | * This hook allows you to get a information about groups via the 'mainwp-getgroups' filter. |
| 78 | 75 | * |
| @@ -83,11 +80,8 @@ | ||
| 83 | 80 | add_filter( 'mainwp-getgroups', array( MainWP_Extensions_Handler::get_class_name(), 'hook_get_groups' ), 10, 4 ); // @deprecated Use 'mainwp_getgroups' instead. |
| 84 | 81 | add_filter( 'mainwp_getgroups', array( MainWP_Extensions_Handler::get_class_name(), 'hook_get_groups' ), 10, 4 ); |
| 85 | 82 | add_action( 'mainwp_fetchurlsauthed', array( &$this, 'filter_fetch_urls_authed' ), 10, 7 ); |
| 86 | 83 | add_filter( 'mainwp_fetchurlauthed', array( &$this, 'filter_fetch_url_authed' ), 10, 6 ); |
| 87 | - add_filter( 'mainwp_getsqlwebsites_for_current_user', array( self::class, 'hook_get_sql_websites_for_current_user' ), 10, 4 ); | |
| 88 | - add_filter( 'mainwp_fetchurlverifyaction', array( &$this, 'hook_fetch_url_verify_action' ), 10, 4 ); | |
| 89 | - | |
| 90 | 84 | add_filter( |
| 91 | 85 | 'mainwp_getdashboardsites', |
| 92 | 86 | array( |
| 93 | 87 | MainWP_Extensions_Handler::get_class_name(), |
| @@ -113,11 +107,9 @@ | ||
| 113 | 107 | 'hook_get_all_extensions', |
| 114 | 108 | ) |
| 115 | 109 | ); |
| 116 | 110 | |
| 117 | - add_action( 'admin_init', array( &$this, 'admin_init' ) ); | |
| 118 | - | |
| 119 | - if ( false !== get_option( 'mainwp_upgradeVersionInfo' ) && '' !== get_option( 'mainwp_upgradeVersionInfo' ) ) { | |
| 111 | + if ( '' != get_option( 'mainwp_upgradeVersionInfo' ) ) { | |
| 120 | 112 | $this->upgradeVersionInfo = get_option( 'mainwp_upgradeVersionInfo' ); |
| 121 | 113 | if ( ! is_object( $this->upgradeVersionInfo ) ) { |
| 122 | 114 | $this->upgradeVersionInfo = new \stdClass(); |
| 123 | 115 | } |
| @@ -137,13 +129,11 @@ | ||
| 137 | 129 | * @param mixed $handle Function handle. |
| 138 | 130 | * @param mixed $output Function output. |
| 139 | 131 | * |
| 140 | 132 | * @return mixed MainWP_Extensions_Handler::hook_fetch_urls_authed() Hook fetch authorized URLs. |
| 141 | - * | |
| 142 | - * @uses \MainWP\Dashboard\MainWP_Extensions_Handler::hook_fetch_urls_authed() | |
| 143 | 133 | */ |
| 144 | 134 | public function filter_fetch_urls_authed( $pluginFile, $key, $dbwebsites, $what, $params, $handle, $output ) { |
| 145 | - return MainWP_Extensions_Handler::hook_fetch_urls_authed( $pluginFile, $key, $dbwebsites, $what, $params, $handle, $output ); | |
| 135 | + return MainWP_Extensions_Handler::hook_fetch_urls_authed( $pluginFile, $key, $dbwebsites, $what, $params, $handle, $output, $is_external_hook = true ); | |
| 146 | 136 | } |
| 147 | 137 | |
| 148 | 138 | /** |
| 149 | 139 | * Method filter_fetch_url_authed() |
| @@ -157,10 +147,8 @@ | ||
| 157 | 147 | * @param array $params Function paramerters. |
| 158 | 148 | * @param null $raw_response Raw response. |
| 159 | 149 | * |
| 160 | 150 | * @return mixed MainWP_Extensions_Handler::hook_fetch_url_authed() Hook fetch authorized URL. |
| 161 | - * | |
| 162 | - * @uses \MainWP\Dashboard\MainWP_Extensions_Handler::hook_fetch_url_authed() | |
| 163 | 151 | */ |
| 164 | 152 | public function filter_fetch_url_authed( $pluginFile, $key, $websiteId, $what, $params, $raw_response = null ) { |
| 165 | 153 | return MainWP_Extensions_Handler::hook_fetch_url_authed( $pluginFile, $key, $websiteId, $what, $params, $raw_response ); |
| 166 | 154 | } |
| @@ -165,28 +153,8 @@ | ||
| 165 | 153 | return MainWP_Extensions_Handler::hook_fetch_url_authed( $pluginFile, $key, $websiteId, $what, $params, $raw_response ); |
| 166 | 154 | } |
| 167 | 155 | |
| 168 | 156 | /** |
| 169 | - * Method hook_fetch_url_verify_action() | |
| 170 | - * | |
| 171 | - * Filter fetch Authorized URL. | |
| 172 | - * | |
| 173 | - * @param mixed $pluginFile MainWP extention. | |
| 174 | - * @param string $childKey Extension child key. | |
| 175 | - * @param int $websiteId Website ID. | |
| 176 | - * @param array $params Function paramerters. | |
| 177 | - * | |
| 178 | - * @return mixed MainWP_Extensions_Handler::hook_fetch_url_authed() Hook fetch authorized URL. | |
| 179 | - */ | |
| 180 | - public function hook_fetch_url_verify_action( $pluginFile, $childKey, $websiteId, $params ) { | |
| 181 | - if ( ! is_array( $params ) || ! isset( $params['actionnonce'] ) ) { | |
| 182 | - return false; | |
| 183 | - } | |
| 184 | - $what = 'verify_action'; | |
| 185 | - return MainWP_Extensions_Handler::hook_fetch_url_authed( $pluginFile, $childKey, $websiteId, $what, $params ); | |
| 186 | - } | |
| 187 | - | |
| 188 | - /** | |
| 189 | 157 | * Method apply_filter() |
| 190 | 158 | * |
| 191 | 159 | * Apply filter |
| 192 | 160 | * |
| @@ -193,10 +161,8 @@ | ||
| 193 | 161 | * @param string $filter The filter. |
| 194 | 162 | * @param array $value Input value. |
| 195 | 163 | * |
| 196 | 164 | * @return array $output Output array. |
| 197 | - * | |
| 198 | - * @uses \MainWP\Dashboard\MainWP_Extensions_Handler::hook_verify() | |
| 199 | 165 | */ |
| 200 | 166 | public function apply_filters( $filter, $value = array() ) { |
| 201 | 167 | |
| 202 | 168 | if ( 'mainwp-getmetaboxes' === $filter ) { |
| @@ -208,15 +174,17 @@ | ||
| 208 | 174 | if ( ! is_array( $output ) ) { |
| 209 | 175 | return array(); |
| 210 | 176 | } |
| 211 | 177 | $count = count( $output ); |
| 212 | - for ( $i = 0; $i < $count; $i++ ) { | |
| 178 | + for ( $i = 0; $i < $count; $i ++ ) { | |
| 179 | + if ( ! isset( $output[ $i ]['plugin'] ) || ! isset( $output[ $i ]['key'] ) ) { | |
| 180 | + unset( $output[ $i ] ); | |
| 181 | + continue; | |
| 182 | + } | |
| 213 | 183 | |
| 214 | - if ( 'mainwp_getmetaboxes' === $filter ) { | |
| 215 | - // pass custom widget. | |
| 216 | - if ( isset( $output[ $i ]['custom'] ) && $output[ $i ]['custom'] && isset( $output[ $i ]['plugin'] ) ) { | |
| 217 | - continue; | |
| 218 | - } | |
| 184 | + if ( ! MainWP_Extensions_Handler::hook_verify( $output[ $i ]['plugin'], $output[ $i ]['key'] ) ) { | |
| 185 | + unset( $output[ $i ] ); | |
| 186 | + continue; | |
| 219 | 187 | } |
| 220 | 188 | } |
| 221 | 189 | |
| 222 | 190 | return $output; |
| @@ -222,321 +190,68 @@ | ||
| 222 | 190 | return $output; |
| 223 | 191 | } |
| 224 | 192 | |
| 225 | 193 | /** |
| 226 | - * Method admin_init() | |
| 227 | - * | |
| 228 | - * Do nothing if current user is not an Admin. | |
| 229 | - */ | |
| 230 | - public function admin_init() { // phpcs:ignore -- complex function. | |
| 231 | - if ( ! MainWP_System_Utility::is_admin() ) { | |
| 232 | - return; | |
| 233 | - } | |
| 234 | - | |
| 235 | - global $pagenow; | |
| 236 | - | |
| 237 | - if ( 'plugins.php' === $pagenow && isset( $_GET['do'] ) && 'checkUpgrade' === $_GET['do'] && ( ( time() - $this->upgradeVersionInfo->updated ) > 30 ) ) { // phpcs:ignore WordPress.Security.NonceVerification,WordPress.Security.ValidatedSanitizedInput.InputNotSanitized | |
| 238 | - $this->check_upgrade(); | |
| 239 | - delete_site_transient( 'update_plugins' ); // to forced refresh 'update_plugins' transient. | |
| 240 | - wp_safe_redirect( admin_url( 'plugins.php' ) ); | |
| 241 | - exit; | |
| 242 | - } | |
| 243 | - } | |
| 244 | - | |
| 245 | - | |
| 246 | - | |
| 247 | - /** | |
| 248 | - * Method hook_get_sql_websites_for_current_user() | |
| 249 | - * | |
| 250 | - * Get sql websites for current user. | |
| 251 | - * | |
| 252 | - * @param mixed $input_value First input filter value. | |
| 253 | - * @param string $pluginFile Extension plugin file to verify. | |
| 254 | - * @param string $key The child-key. | |
| 255 | - * @param mixed $params Input params data. | |
| 256 | - * | |
| 257 | - * @return string sql. | |
| 258 | - */ | |
| 259 | - public static function hook_get_sql_websites_for_current_user( $input_value, $pluginFile, $key, $params ) { | |
| 260 | - if ( ! MainWP_Extensions_Handler::hook_verify( $pluginFile, $key ) ) { | |
| 261 | - return false; | |
| 262 | - } | |
| 263 | - return MainWP_DB::instance()->get_sql_wp_for_current_user( $params ); | |
| 264 | - } | |
| 265 | - /** | |
| 266 | 194 | * Method handle_manage_sites_screen_settings() |
| 267 | 195 | * |
| 268 | 196 | * Handle manage sites screen settings |
| 269 | 197 | */ |
| 270 | - public function handle_manage_sites_screen_settings() { // phpcs:ignore -- required to achieve desired results, pull request solutions appreciated. | |
| 271 | - if ( isset( $_POST['wp_nonce'] ) && wp_verify_nonce( sanitize_key( $_POST['wp_nonce'] ), 'ManageSitesScrOptions' ) ) { | |
| 272 | - $show_cols = array(); | |
| 198 | + public function handle_manage_sites_screen_settings() { | |
| 199 | + if ( isset( $_POST['submit'] ) && isset( $_POST['wp_nonce'] ) && wp_verify_nonce( sanitize_key( $_POST['wp_nonce'] ), 'ManageSitesScrOptions' ) ) { | |
| 200 | + $hide_cols = array(); | |
| 273 | 201 | foreach ( array_map( 'sanitize_text_field', wp_unslash( $_POST ) ) as $key => $val ) { |
| 274 | - if ( false !== strpos( $key, 'mainwp_show_column_' ) ) { | |
| 275 | - $col = str_replace( 'mainwp_show_column_', '', $key ); | |
| 276 | - $show_cols[ $col ] = 1; | |
| 202 | + if ( false !== strpos( $key, 'mainwp_hide_column_' ) ) { | |
| 203 | + $col = str_replace( 'mainwp_hide_column_', '', $key ); | |
| 204 | + $hide_cols[] = $col; | |
| 277 | 205 | } |
| 278 | 206 | } |
| 279 | - if ( isset( $_POST['show_columns_name'] ) ) { | |
| 280 | - foreach ( array_map( 'sanitize_text_field', wp_unslash( $_POST['show_columns_name'] ) ) as $col ) { | |
| 281 | - if ( ! isset( $show_cols[ $col ] ) ) { | |
| 282 | - $show_cols[ $col ] = 0; // uncheck, hide columns. | |
| 283 | - } | |
| 284 | - } | |
| 285 | - } | |
| 286 | - MainWP_Utility::update_option( 'mainwp_use_favicon', 1 ); | |
| 287 | - MainWP_Utility::update_option( 'mainwp_optimize', ( ! isset( $_POST['mainwp_optimize'] ) ? 0 : 1 ) ); | |
| 288 | 207 | $user = wp_get_current_user(); |
| 289 | 208 | if ( $user ) { |
| 290 | - $val = ( isset( $_POST['mainwp_sitesviewmode'] ) ? sanitize_text_field( wp_unslash( $_POST['mainwp_sitesviewmode'] ) ) : 'grid' ); | |
| 291 | - if ( 'grid' !== $val && 'table' !== $val ) { | |
| 292 | - $val = 'grid'; | |
| 293 | - } | |
| 294 | - update_user_option( $user->ID, 'mainwp_sitesviewmode', $val, true ); | |
| 295 | - update_user_option( $user->ID, 'mainwp_settings_show_manage_sites_columns', $show_cols, true ); | |
| 209 | + update_user_option( $user->ID, 'mainwp_settings_hide_manage_sites_columns', $hide_cols, true ); | |
| 296 | 210 | update_option( 'mainwp_default_sites_per_page', ( isset( $_POST['mainwp_default_sites_per_page'] ) ? intval( $_POST['mainwp_default_sites_per_page'] ) : 25 ) ); |
| 297 | 211 | } |
| 298 | - } elseif ( isset( $_POST['wp_nonce'] ) && wp_verify_nonce( sanitize_key( $_POST['wp_nonce'] ), 'SreenshotsSitesScrOptions' ) ) { | |
| 299 | - $user = wp_get_current_user(); | |
| 300 | - if ( $user ) { | |
| 301 | - $val = ( isset( $_POST['mainwp_sitesviewmode'] ) ? sanitize_text_field( wp_unslash( $_POST['mainwp_sitesviewmode'] ) ) : 'grid' ); | |
| 302 | - if ( 'grid' !== $val && 'table' !== $val ) { | |
| 303 | - $val = 'grid'; | |
| 304 | - } | |
| 305 | - update_user_option( $user->ID, 'mainwp_sitesviewmode', $val, true ); | |
| 306 | - } | |
| 307 | 212 | } |
| 308 | 213 | } |
| 309 | 214 | |
| 310 | 215 | /** |
| 311 | - * Method handle_monitoring_sites_screen_settings() | |
| 312 | - * | |
| 313 | - * Handle monitoring sites screen settings | |
| 314 | - */ | |
| 315 | - public function handle_monitoring_sites_screen_settings() { | |
| 316 | - if ( isset( $_POST['wp_nonce'] ) && wp_verify_nonce( sanitize_key( $_POST['wp_nonce'] ), 'MonitoringSitesScrOptions' ) ) { | |
| 317 | - $show_cols = array(); | |
| 318 | - foreach ( array_map( 'sanitize_text_field', wp_unslash( $_POST ) ) as $key => $val ) { | |
| 319 | - if ( false !== strpos( $key, 'mainwp_show_column_' ) ) { | |
| 320 | - $col = str_replace( 'mainwp_show_column_', '', $key ); | |
| 321 | - $show_cols[ $col ] = 1; | |
| 322 | - } | |
| 323 | - } | |
| 324 | - if ( isset( $_POST['show_columns_name'] ) ) { | |
| 325 | - foreach ( array_map( 'sanitize_text_field', wp_unslash( $_POST['show_columns_name'] ) ) as $col ) { | |
| 326 | - if ( ! isset( $show_cols[ $col ] ) ) { | |
| 327 | - $show_cols[ $col ] = 0; // uncheck, hide columns. | |
| 328 | - } | |
| 329 | - } | |
| 330 | - } | |
| 331 | - | |
| 332 | - $user = wp_get_current_user(); | |
| 333 | - if ( $user ) { | |
| 334 | - update_user_option( $user->ID, 'mainwp_settings_show_monitoring_sites_columns', $show_cols, true ); | |
| 335 | - update_option( 'mainwp_default_monitoring_sites_per_page', ( isset( $_POST['mainwp_default_monitoring_sites_per_page'] ) ? intval( $_POST['mainwp_default_monitoring_sites_per_page'] ) : 25 ) ); | |
| 336 | - } | |
| 337 | - | |
| 338 | - update_option( 'mainwp_disableSitesChecking', ( ! isset( $_POST['mainwp_disableSitesChecking'] ) ? 1 : 0 ) ); | |
| 339 | - | |
| 340 | - $val = isset( $_POST['mainwp_frequency_sitesChecking'] ) ? intval( $_POST['mainwp_frequency_sitesChecking'] ) : 1440; | |
| 341 | - update_option( 'mainwp_frequencySitesChecking', $val ); | |
| 342 | - | |
| 343 | - update_option( 'mainwp_disableSitesHealthMonitoring', ( ! isset( $_POST['mainwp_disable_sitesHealthMonitoring'] ) ? 1 : 0 ) ); | |
| 344 | - | |
| 345 | - $val = isset( $_POST['mainwp_site_healthThreshold'] ) ? intval( $_POST['mainwp_site_healthThreshold'] ) : 80; | |
| 346 | - update_option( 'mainwp_sitehealthThreshold', $val ); | |
| 347 | - } | |
| 348 | - } | |
| 349 | - | |
| 350 | - /** | |
| 351 | - * Method handle_clients_screen_settings() | |
| 352 | - * | |
| 353 | - * Handle manage clients screen settings | |
| 354 | - */ | |
| 355 | - public function handle_clients_screen_settings() { | |
| 356 | - if ( isset( $_POST['wp_nonce'] ) && wp_verify_nonce( sanitize_key( $_POST['wp_nonce'] ), 'ManageClientsScrOptions' ) ) { | |
| 357 | - $show_cols = array(); | |
| 358 | - foreach ( array_map( 'sanitize_text_field', wp_unslash( $_POST ) ) as $key => $val ) { | |
| 359 | - if ( false !== strpos( $key, 'mainwp_show_column_' ) ) { | |
| 360 | - $col = str_replace( 'mainwp_show_column_', '', $key ); | |
| 361 | - $show_cols[ $col ] = 1; | |
| 362 | - } | |
| 363 | - } | |
| 364 | - if ( isset( $_POST['show_columns_name'] ) ) { | |
| 365 | - foreach ( array_map( 'sanitize_text_field', wp_unslash( $_POST['show_columns_name'] ) ) as $col ) { | |
| 366 | - if ( ! isset( $show_cols[ $col ] ) ) { | |
| 367 | - $show_cols[ $col ] = 0; // uncheck, hide columns. | |
| 368 | - } | |
| 369 | - } | |
| 370 | - } | |
| 371 | - | |
| 372 | - $user = wp_get_current_user(); | |
| 373 | - if ( $user ) { | |
| 374 | - update_user_option( $user->ID, 'mainwp_settings_show_manage_clients_columns', $show_cols, true ); | |
| 375 | - update_option( 'mainwp_default_manage_clients_per_page', ( isset( $_POST['mainwp_default_manage_clients_per_page'] ) ? intval( $_POST['mainwp_default_manage_clients_per_page'] ) : 25 ) ); | |
| 376 | - } | |
| 377 | - } | |
| 378 | - } | |
| 379 | - | |
| 380 | - /** | |
| 381 | - * Method handle_clients_screen_settings() | |
| 382 | - * | |
| 383 | - * Handle manage clients screen settings | |
| 384 | - */ | |
| 385 | - public function handle_updates_screen_settings() { | |
| 386 | - if ( isset( $_POST['wp_nonce'] ) && wp_verify_nonce( sanitize_key( $_POST['wp_nonce'] ), 'UpdatesScrOptions' ) ) { | |
| 387 | - $val = ( ! isset( $_POST['mainwp_pluginAutomaticDailyUpdate'] ) ? 0 : intval( $_POST['mainwp_pluginAutomaticDailyUpdate'] ) ); | |
| 388 | - MainWP_Utility::update_option( 'mainwp_pluginAutomaticDailyUpdate', $val ); | |
| 389 | - $val = ( ! isset( $_POST['mainwp_themeAutomaticDailyUpdate'] ) ? 0 : intval( $_POST['mainwp_themeAutomaticDailyUpdate'] ) ); | |
| 390 | - MainWP_Utility::update_option( 'mainwp_themeAutomaticDailyUpdate', $val ); | |
| 391 | - $val = ( ! isset( $_POST['mainwp_automaticDailyUpdate'] ) ? 0 : intval( $_POST['mainwp_automaticDailyUpdate'] ) ); | |
| 392 | - MainWP_Utility::update_option( 'mainwp_automaticDailyUpdate', $val ); | |
| 393 | - $val = ( isset( $_POST['mainwp_delay_autoupdate'] ) ? intval( $_POST['mainwp_delay_autoupdate'] ) : 1 ); | |
| 394 | - MainWP_Utility::update_option( 'mainwp_delay_autoupdate', $val ); | |
| 395 | - $val = ( ! isset( $_POST['mainwp_show_language_updates'] ) ? 0 : 1 ); | |
| 396 | - MainWP_Utility::update_option( 'mainwp_show_language_updates', $val ); | |
| 397 | - $val = ( ! isset( $_POST['mainwp_disable_update_confirmations'] ) ? 0 : intval( $_POST['mainwp_disable_update_confirmations'] ) ); | |
| 398 | - MainWP_Utility::update_option( 'mainwp_disable_update_confirmations', $val ); | |
| 399 | - } | |
| 400 | - } | |
| 401 | - | |
| 402 | - | |
| 403 | - /** | |
| 404 | 216 | * Method handle_mainwp_tools_settings() |
| 405 | 217 | * |
| 406 | - * Handle mainwp tools settings. | |
| 407 | - * | |
| 408 | - * @uses \MainWP\Dashboard\MainWP_Twitter::clear_all_twitter_messages() | |
| 409 | - * @uses \MainWP\Dashboard\MainWP_Utility::update_option() | |
| 218 | + * Handle mainwp tools settings | |
| 410 | 219 | */ |
| 411 | - public function handle_mainwp_tools_settings() { // phpcs:ignore -- Current complexity is the only way to achieve desired results, pull request solutions appreciated. | |
| 220 | + public function handle_mainwp_tools_settings() { | |
| 221 | + $update_screen_options = false; | |
| 222 | + if ( isset( $_POST['submit'] ) && isset( $_GET['page'] ) && 'MainWPTools' === $_GET['page'] ) { | |
| 223 | + if ( isset( $_POST['submit'] ) && isset( $_POST['wp_nonce'] ) && wp_verify_nonce( sanitize_key( $_POST['wp_nonce'] ), 'MainWPTools' ) ) { | |
| 224 | + $update_screen_options = true; | |
| 225 | + MainWP_Utility::update_option( 'mainwp_enable_managed_cr_for_wc', ( ! isset( $_POST['enable_managed_cr_for_wc'] ) ? 0 : 1 ) ); | |
| 226 | + MainWP_Utility::update_option( 'mainwp_use_favicon', ( ! isset( $_POST['mainwp_use_favicon'] ) ? 0 : 1 ) ); | |
| 412 | 227 | |
| 413 | - $user = wp_get_current_user(); | |
| 414 | - | |
| 415 | - $update_selected_mainwp_themes = false; | |
| 416 | - | |
| 417 | - if ( isset( $_GET['page'] ) && 'MainWPTools' === $_GET['page'] ) { | |
| 418 | - if ( isset( $_POST['wp_nonce'] ) && wp_verify_nonce( sanitize_key( $_POST['wp_nonce'] ), 'MainWPTools' ) ) { | |
| 419 | - if ( isset( $_POST['mainwp_restore_info_messages'] ) && ! empty( $_POST['mainwp_restore_info_messages'] ) ) { | |
| 420 | - delete_user_option( $user->ID, 'mainwp_notice_saved_status' ); | |
| 228 | + $enabled_twit = ! isset( $_POST['mainwp_hide_twitters_message'] ) ? 0 : 1; | |
| 229 | + MainWP_Utility::update_option( 'mainwp_hide_twitters_message', $enabled_twit ); | |
| 230 | + if ( ! $enabled_twit ) { | |
| 231 | + MainWP_Twitter::clear_all_twitter_messages(); | |
| 421 | 232 | } |
| 422 | - $enabled_tours = ! isset( $_POST['mainwp-guided-tours-option'] ) ? 0 : 1; | |
| 423 | - MainWP_Utility::update_option( 'mainwp_enable_guided_tours', $enabled_tours ); | |
| 424 | - | |
| 425 | - if ( isset( $_POST['mainwp_settings_custom_theme'] ) ) { | |
| 426 | - $update_selected_mainwp_themes = true; | |
| 427 | - } | |
| 428 | 233 | } |
| 429 | - } | |
| 430 | - | |
| 431 | - if ( isset( $_POST['wp_scr_options_nonce'] ) && wp_verify_nonce( sanitize_key( $_POST['wp_scr_options_nonce'] ), 'MainWPSelectThemes' ) ) { | |
| 432 | - $update_selected_mainwp_themes = true; | |
| 433 | - } | |
| 434 | - | |
| 435 | - if ( $update_selected_mainwp_themes ) { | |
| 436 | - if ( isset( $_POST['mainwp_settings_custom_theme'] ) ) { | |
| 437 | - $custom_theme = sanitize_text_field( wp_unslash( $_POST['mainwp_settings_custom_theme'] ) ); | |
| 438 | - update_user_option( $user->ID, 'mainwp_selected_theme', $custom_theme ); | |
| 234 | + } elseif ( ( isset( $_GET['page'] ) && 'mainwp_tab' === $_GET['page'] ) || isset( $_GET['dashboard'] ) ) { | |
| 235 | + if ( isset( $_POST['submit'] ) && isset( $_POST['wp_nonce'] ) && wp_verify_nonce( sanitize_key( $_POST['wp_nonce'] ), 'MainWPScrOptions' ) ) { | |
| 236 | + $update_screen_options = true; | |
| 439 | 237 | } |
| 440 | 238 | } |
| 441 | 239 | |
| 442 | - $update_screen_options = false; | |
| 443 | - if ( isset( $_POST['wp_nonce'] ) && ( wp_verify_nonce( sanitize_key( $_POST['wp_nonce'] ), 'Settings' ) || wp_verify_nonce( sanitize_key( $_POST['wp_nonce'] ), 'MainWPScrOptions' ) ) ) { | |
| 444 | - $update_screen_options = true; | |
| 445 | - } | |
| 446 | - | |
| 447 | 240 | if ( $update_screen_options ) { |
| 448 | - $show_wids = array(); | |
| 449 | - if ( isset( $_POST['mainwp_show_widgets'] ) && is_array( $_POST['mainwp_show_widgets'] ) ) { | |
| 450 | - $selected_wids = array_map( 'sanitize_text_field', wp_unslash( $_POST['mainwp_show_widgets'] ) ); | |
| 451 | - foreach ( $selected_wids as $name ) { | |
| 452 | - $show_wids[ $name ] = 1; | |
| 453 | - } | |
| 241 | + $hide_wids = array(); | |
| 242 | + if ( isset( $_POST['mainwp_hide_widgets'] ) && is_array( $_POST['mainwp_hide_widgets'] ) ) { | |
| 243 | + $hide_wids = array_map( 'sanitize_text_field', wp_unslash( $_POST['mainwp_hide_widgets'] ) ); | |
| 454 | 244 | } |
| 455 | - | |
| 456 | - if ( isset( $_POST['mainwp_widgets_name'] ) && is_array( $_POST['mainwp_widgets_name'] ) ) { | |
| 457 | - $name_wids = array_map( 'sanitize_text_field', wp_unslash( $_POST['mainwp_widgets_name'] ) ); | |
| 458 | - foreach ( $name_wids as $name ) { | |
| 459 | - if ( ! isset( $show_wids[ $name ] ) ) { | |
| 460 | - $show_wids[ $name ] = 0; | |
| 461 | - } | |
| 462 | - } | |
| 463 | - } | |
| 464 | - | |
| 465 | - $show_cols = array(); | |
| 466 | - if ( isset( $_POST['mainwp_show_columns'] ) && is_array( $_POST['mainwp_show_columns'] ) ) { | |
| 467 | - $selected_cols = array_map( 'sanitize_text_field', wp_unslash( $_POST['mainwp_show_columns'] ) ); | |
| 468 | - foreach ( $selected_cols as $name ) { | |
| 469 | - $show_cols[ $name ] = 1; | |
| 470 | - } | |
| 471 | - } | |
| 472 | - | |
| 473 | - if ( isset( $_POST['mainwp_columns_name'] ) && is_array( $_POST['mainwp_columns_name'] ) ) { | |
| 474 | - $name_cols = array_map( 'sanitize_text_field', wp_unslash( $_POST['mainwp_columns_name'] ) ); | |
| 475 | - foreach ( $name_cols as $name ) { | |
| 476 | - if ( ! isset( $show_cols[ $name ] ) ) { | |
| 477 | - $show_cols[ $name ] = 0; | |
| 478 | - } | |
| 479 | - } | |
| 480 | - } | |
| 481 | - | |
| 482 | - $val = ( isset( $_POST['mainwp_sidebarPosition'] ) ? intval( $_POST['mainwp_sidebarPosition'] ) : 1 ); | |
| 245 | + $user = wp_get_current_user(); | |
| 483 | 246 | if ( $user ) { |
| 484 | - update_user_option( $user->ID, 'mainwp_settings_show_widgets', $show_wids, true ); | |
| 485 | - update_user_option( $user->ID, 'mainwp_sidebarPosition', $val, true ); | |
| 486 | - | |
| 487 | - if ( isset( $_POST['mainwp_manageposts_show_columns_settings'] ) ) { | |
| 488 | - update_user_option( $user->ID, 'mainwp_manageposts_show_columns', $show_cols, true ); | |
| 489 | - } | |
| 490 | - | |
| 491 | - if ( isset( $_POST['mainwp_managepages_show_columns_settings'] ) ) { | |
| 492 | - update_user_option( $user->ID, 'mainwp_managepages_show_columns', $show_cols, true ); | |
| 493 | - } | |
| 494 | - | |
| 495 | - if ( isset( $_POST['mainwp_manageusers_show_columns_settings'] ) ) { | |
| 496 | - update_user_option( $user->ID, 'mainwp_manageusers_show_columns', $show_cols, true ); | |
| 497 | - } | |
| 247 | + update_user_option( $user->ID, 'mainwp_settings_hide_widgets', $hide_wids, true ); | |
| 498 | 248 | } |
| 499 | 249 | |
| 500 | 250 | MainWP_Utility::update_option( 'mainwp_hide_update_everything', ( ! isset( $_POST['hide_update_everything'] ) ? 0 : 1 ) ); |
| 501 | - | |
| 502 | - if ( isset( $_POST['reset_overview_settings'] ) && ! empty( $_POST['reset_overview_settings'] ) && isset( $_POST['reset_overview_which_settings'] ) && 'overview_settings' === $_POST['reset_overview_which_settings'] ) { | |
| 503 | - update_user_option( $user->ID, 'mainwp_widgets_sorted_toplevel_page_mainwp_tab', false, true ); | |
| 504 | - update_user_option( $user->ID, 'mainwp_widgets_sorted_mainwp_page_managesites', false, true ); | |
| 505 | - } | |
| 251 | + MainWP_Utility::update_option( 'mainwp_show_usersnap', ( ! isset( $_POST['mainwp_show_usersnap'] ) ? 0 : time() ) ); | |
| 252 | + MainWP_Utility::update_option( 'mainwp_number_overview_columns', ( isset( $_POST['number_overview_columns'] ) ? intval( $_POST['number_overview_columns'] ) : 2 ) ); | |
| 506 | 253 | } |
| 507 | - | |
| 508 | - $update_clients_screen_options = false; | |
| 509 | - if ( isset( $_POST['wp_scr_options_nonce'] ) && wp_verify_nonce( sanitize_key( $_POST['wp_scr_options_nonce'] ), 'MainWPClientsScrOptions' ) ) { | |
| 510 | - $update_clients_screen_options = true; | |
| 511 | - } | |
| 512 | - if ( $update_clients_screen_options ) { | |
| 513 | - | |
| 514 | - $show_wids = array(); | |
| 515 | - if ( isset( $_POST['mainwp_show_widgets'] ) && is_array( $_POST['mainwp_show_widgets'] ) ) { | |
| 516 | - $selected_wids = array_map( 'sanitize_text_field', wp_unslash( $_POST['mainwp_show_widgets'] ) ); | |
| 517 | - foreach ( $selected_wids as $name ) { | |
| 518 | - $show_wids[ $name ] = 1; | |
| 519 | - } | |
| 520 | - } | |
| 521 | - | |
| 522 | - if ( isset( $_POST['mainwp_widgets_name'] ) && is_array( $_POST['mainwp_widgets_name'] ) ) { | |
| 523 | - $name_wids = array_map( 'sanitize_text_field', wp_unslash( $_POST['mainwp_widgets_name'] ) ); | |
| 524 | - foreach ( $name_wids as $name ) { | |
| 525 | - if ( ! isset( $show_wids[ $name ] ) ) { | |
| 526 | - $show_wids[ $name ] = 0; | |
| 527 | - } | |
| 528 | - } | |
| 529 | - } | |
| 530 | - | |
| 531 | - if ( $user ) { | |
| 532 | - update_user_option( $user->ID, 'mainwp_clients_show_widgets', $show_wids, true ); | |
| 533 | - } | |
| 534 | - | |
| 535 | - if ( isset( $_POST['reset_client_overview_settings'] ) && ! empty( $_POST['reset_client_overview_settings'] ) ) { | |
| 536 | - update_user_option( $user->ID, 'mainwp_widgets_sorted_mainwp_page_manageclients', false, true ); | |
| 537 | - } | |
| 538 | - } | |
| 539 | 254 | } |
| 540 | 255 | |
| 541 | 256 | /** |
| 542 | 257 | * Method handle_settings_post() |
| @@ -541,50 +256,26 @@ | ||
| 541 | 256 | /** |
| 542 | 257 | * Method handle_settings_post() |
| 543 | 258 | * |
| 544 | 259 | * Handle saving settings page. |
| 545 | - * | |
| 546 | - * @uses \MainWP\Dashboard\MainWP_Backup_Handler::handle_settings_post() | |
| 547 | - * @uses \MainWP\Dashboard\MainWP_DB_Common::get_user_extension() | |
| 548 | - * @uses \MainWP\Dashboard\MainWP_DB_Common::update_user_extension() | |
| 549 | - * @uses \MainWP\Dashboard\MainWP_Monitoring_Handler::handle_settings_post() | |
| 550 | - * @uses \MainWP\Dashboard\MainWP_Settings::handle_settings_post() | |
| 551 | 260 | */ |
| 552 | - public function handle_settings_post() { // phpcs:ignore -- complex method. | |
| 261 | + public function handle_settings_post() { | |
| 262 | + if ( ! function_exists( 'wp_create_nonce' ) ) { | |
| 263 | + include_once ABSPATH . WPINC . '/pluggable.php'; | |
| 264 | + } | |
| 553 | 265 | |
| 554 | - if ( isset( $_GET['page'] ) && ( isset( $_POST['wp_nonce'] ) || isset( $_POST['wp_scr_options_nonce'] ) ) ) { | |
| 555 | - $this->include_pluggable(); | |
| 266 | + if ( isset( $_GET['page'] ) && isset( $_POST['wp_nonce'] ) ) { | |
| 556 | 267 | $this->handle_mainwp_tools_settings(); |
| 557 | 268 | $this->handle_manage_sites_screen_settings(); |
| 558 | - $this->handle_monitoring_sites_screen_settings(); | |
| 559 | - $this->handle_clients_screen_settings(); | |
| 560 | - $this->handle_updates_screen_settings(); | |
| 561 | 269 | } |
| 562 | 270 | |
| 563 | - if ( isset( $_POST['select_mainwp_options_siteview'] ) ) { | |
| 564 | - $this->include_pluggable(); | |
| 565 | - if ( check_admin_referer( 'mainwp-admin-nonce' ) ) { | |
| 566 | - $userExtension = MainWP_DB_Common::instance()->get_user_extension(); | |
| 567 | - $userExtension->site_view = ( empty( $_POST['select_mainwp_options_siteview'] ) ? MAINWP_VIEW_PER_PLUGIN_THEME : intval( $_POST['select_mainwp_options_siteview'] ) ); | |
| 568 | - MainWP_DB_Common::instance()->update_user_extension( $userExtension ); | |
| 569 | - } | |
| 271 | + if ( isset( $_POST['select_mainwp_options_siteview'] ) && check_admin_referer( 'mainwp-admin-nonce' ) ) { | |
| 272 | + $userExtension = MainWP_DB_Common::instance()->get_user_extension(); | |
| 273 | + $userExtension->site_view = ( empty( $_POST['select_mainwp_options_siteview'] ) ? MAINWP_VIEW_PER_PLUGIN_THEME : intval( $_POST['select_mainwp_options_siteview'] ) ); | |
| 274 | + MainWP_DB_Common::instance()->update_user_extension( $userExtension ); | |
| 570 | 275 | } |
| 571 | 276 | |
| 572 | - if ( isset( $_POST['select_mainwp_options_plugintheme_view'] ) ) { | |
| 573 | - $this->include_pluggable(); | |
| 574 | - if ( check_admin_referer( 'mainwp-admin-nonce' ) ) { | |
| 575 | - $view_per = ( empty( $_POST['select_mainwp_options_plugintheme_view'] ) ? MAINWP_VIEW_PER_PLUGIN_THEME : intval( $_POST['select_mainwp_options_plugintheme_view'] ) ); | |
| 576 | - $which = isset( $_POST['whichview'] ) ? sanitize_text_field( wp_unslash( $_POST['whichview'] ) ) : ''; | |
| 577 | - if ( 'plugin' === $which ) { | |
| 578 | - MainWP_Utility::update_user_option( 'mainwp_manage_plugin_view', $view_per ); | |
| 579 | - } else { | |
| 580 | - MainWP_Utility::update_user_option( 'mainwp_manage_theme_view', $view_per ); | |
| 581 | - } | |
| 582 | - } | |
| 583 | - } | |
| 584 | - | |
| 585 | 277 | if ( isset( $_POST['submit'] ) && isset( $_POST['wp_nonce'] ) ) { |
| 586 | - $this->include_pluggable(); | |
| 587 | 278 | if ( wp_verify_nonce( sanitize_key( $_POST['wp_nonce'] ), 'Settings' ) ) { |
| 588 | 279 | $updated = MainWP_Settings::handle_settings_post(); |
| 589 | 280 | $updated |= MainWP_Backup_Handler::handle_settings_post(); |
| 590 | 281 | $updated |= MainWP_Monitoring_Handler::handle_settings_post(); |
| @@ -595,75 +286,34 @@ | ||
| 595 | 286 | wp_safe_redirect( admin_url( 'admin.php?page=Settings' . $msg ) ); |
| 596 | 287 | exit(); |
| 597 | 288 | } |
| 598 | 289 | } |
| 599 | - | |
| 600 | - if ( isset( $_POST['mainwp_sidebar_position'] ) && isset( $_POST['wp_nonce'] ) && wp_verify_nonce( sanitize_key( $_POST['wp_nonce'] ), 'onchange_sidebarposition' ) ) { | |
| 601 | - $val = isset( $_POST['mainwp_sidebar_position'] ) && ! empty( $_POST['mainwp_sidebar_position'] ) ? 1 : 0; | |
| 602 | - $user = wp_get_current_user(); | |
| 603 | - if ( $user ) { | |
| 604 | - update_user_option( $user->ID, 'mainwp_sidebarPosition', $val, true ); | |
| 605 | - } | |
| 606 | - return true; | |
| 607 | - } | |
| 608 | - | |
| 609 | - if ( isset( $_GET['viewmode'] ) && isset( $_GET['modenonce'] ) ) { | |
| 610 | - $viewmode = sanitize_text_field( wp_unslash( $_GET['viewmode'] ) ); | |
| 611 | - $nonce = sanitize_key( $_GET['modenonce'] ); | |
| 612 | - if ( ( 'table' === $viewmode || 'grid' === $viewmode ) && wp_verify_nonce( sanitize_key( $nonce ), 'viewmode' ) ) { | |
| 613 | - $user = wp_get_current_user(); | |
| 614 | - if ( $user ) { | |
| 615 | - update_user_option( $user->ID, 'mainwp_sitesviewmode', $viewmode, true ); | |
| 616 | - wp_safe_redirect( admin_url( 'admin.php?page=managesites' ) ); | |
| 617 | - exit; | |
| 618 | - } | |
| 619 | - } | |
| 620 | - } | |
| 621 | 290 | } |
| 622 | 291 | |
| 623 | 292 | /** |
| 624 | - * Method include_pluggable() | |
| 293 | + * Method plugins_api_info() | |
| 625 | 294 | * |
| 626 | - * Include pluggable functions. | |
| 627 | - */ | |
| 628 | - public function include_pluggable() { | |
| 629 | - // may causing of conflict with Post S m t p plugin. | |
| 630 | - if ( ! function_exists( 'wp_create_nonce' ) ) { | |
| 631 | - include_once ABSPATH . WPINC . '/pluggable.php'; | |
| 632 | - } | |
| 633 | - } | |
| 634 | - | |
| 635 | - /** | |
| 636 | - * Method plugins_api_extension_info() | |
| 637 | - * | |
| 638 | 295 | * Get MainWP Extension api information. |
| 639 | 296 | * |
| 640 | - * @param mixed $input_value Return value. | |
| 297 | + * @param mixed $false Return value. | |
| 641 | 298 | * @param mixed $action Action being performed. |
| 642 | 299 | * @param mixed $arg Action arguments. Should be the plugin slug. |
| 643 | 300 | * |
| 644 | - * @return mixed $info|$input_value | |
| 301 | + * @return mixed $info|$false | |
| 645 | 302 | * |
| 646 | - * @uses \MainWP\Dashboard\MainWP_API_Handler::get_update_information() | |
| 647 | - * @uses \MainWP\Dashboard\MainWP_Extensions_View::get_available_extensions() | |
| 648 | - * @uses \MainWP\Dashboard\MainWP_System::get_plugin_slug() | |
| 649 | - * @uses \MainWP\Dashboard\MainWP_Extensions_Handler::get_slugs() | |
| 303 | + * @uses \MainWP\Dashboard\MainWP_API_Handler::get_plugin_information() | |
| 650 | 304 | */ |
| 651 | - public function plugins_api_extension_info( $input_value, $action, $arg ) { | |
| 305 | + public function plugins_api_info( $false, $action, $arg ) { | |
| 652 | 306 | if ( 'plugin_information' !== $action ) { |
| 653 | - return $input_value; | |
| 307 | + return $false; | |
| 654 | 308 | } |
| 655 | 309 | |
| 656 | - if ( is_array( $arg ) ) { | |
| 657 | - $arg = (object) $arg; | |
| 658 | - } | |
| 659 | - | |
| 660 | 310 | if ( ! isset( $arg->slug ) || ( '' === $arg->slug ) ) { |
| 661 | - return $input_value; | |
| 311 | + return $false; | |
| 662 | 312 | } |
| 663 | 313 | |
| 664 | 314 | if ( dirname( MainWP_System::instance()->get_plugin_slug() ) === $arg->slug ) { |
| 665 | - return $input_value; | |
| 315 | + return $false; | |
| 666 | 316 | } |
| 667 | 317 | |
| 668 | 318 | $result = MainWP_Extensions_Handler::get_slugs(); |
| 669 | 319 | $am_slugs = $result['am_slugs']; |
| @@ -669,15 +319,10 @@ | ||
| 669 | 319 | $am_slugs = $result['am_slugs']; |
| 670 | 320 | |
| 671 | 321 | if ( '' !== $am_slugs ) { |
| 672 | 322 | $am_slugs = explode( ',', $am_slugs ); |
| 673 | - if ( false !== strpos( $arg->slug, '/' ) ) { // to fix. | |
| 674 | - $dir_slug = dirname( $arg->slug ); | |
| 675 | - } else { | |
| 676 | - $dir_slug = $arg->slug; | |
| 677 | - } | |
| 678 | - if ( in_array( $dir_slug, $am_slugs ) ) { | |
| 679 | - $info = MainWP_API_Handler::get_update_information( $dir_slug ); | |
| 323 | + if ( in_array( $arg->slug, $am_slugs ) ) { | |
| 324 | + $info = MainWP_API_Handler::get_plugin_information( $arg->slug ); | |
| 680 | 325 | if ( is_object( $info ) && property_exists( $info, 'sections' ) ) { |
| 681 | 326 | if ( ! is_array( $info->sections ) || ! isset( $info->sections['changelog'] ) || empty( $info->sections['changelog'] ) ) { |
| 682 | 327 | $exts_data = MainWP_Extensions_View::get_available_extensions(); |
| 683 | 328 | if ( isset( $exts_data[ $arg->slug ] ) ) { |
| @@ -691,97 +336,15 @@ | ||
| 691 | 336 | return $info; |
| 692 | 337 | } |
| 693 | 338 | } |
| 694 | 339 | |
| 695 | - return $input_value; | |
| 340 | + return $false; | |
| 696 | 341 | } |
| 697 | 342 | |
| 698 | 343 | /** |
| 699 | - * Method plugins_api_wp_plugins_api_result() | |
| 700 | - * | |
| 701 | - * Hook after get plugins api information. | |
| 702 | - * | |
| 703 | - * @param mixed $res api information value. | |
| 704 | - * @param mixed $action Action being performed. | |
| 705 | - * @param mixed $arg Action arguments. Should be the plugin slug. | |
| 706 | - * | |
| 707 | - * @return mixed $res | |
| 708 | - */ | |
| 709 | - public function plugins_api_wp_plugins_api_result( $res, $action, $arg ) { | |
| 710 | - | |
| 711 | - if ( 'plugin_information' !== $action ) { | |
| 712 | - return $res; | |
| 713 | - } | |
| 714 | - | |
| 715 | - if ( is_object( $res ) && property_exists( $res, 'slug' ) && property_exists( $res, 'sections' ) ) { | |
| 716 | - return $res; | |
| 717 | - } | |
| 718 | - | |
| 719 | - if ( ! isset( $_GET['wpplugin'] ) || ! is_numeric( $_GET['wpplugin'] ) || empty( $_GET['wpplugin'] ) ) { // phpcs:ignore WordPress.Security.NonceVerification,WordPress.Security.ValidatedSanitizedInput.InputNotSanitized | |
| 720 | - return $res; | |
| 721 | - } | |
| 722 | - | |
| 723 | - if ( is_array( $arg ) ) { | |
| 724 | - $arg = (object) $arg; | |
| 725 | - } | |
| 726 | - | |
| 727 | - if ( ! isset( $arg->slug ) || ( '' === $arg->slug ) ) { | |
| 728 | - return $res; | |
| 729 | - } | |
| 730 | - | |
| 731 | - $site_id = intval( $_GET['wpplugin'] ); // phpcs:ignore WordPress.Security.NonceVerification,WordPress.Security.ValidatedSanitizedInput.InputNotSanitized | |
| 732 | - | |
| 733 | - if ( $site_id ) { | |
| 734 | - $website = MainWP_DB::instance()->get_website_by_id( $site_id ); | |
| 735 | - if ( $website && ! empty( $website->plugin_upgrades ) ) { | |
| 736 | - $plugin_upgrades = json_decode( $website->plugin_upgrades, true ); | |
| 737 | - | |
| 738 | - if ( is_array( $plugin_upgrades ) ) { | |
| 739 | - $found_update = false; | |
| 740 | - $empty_sections = false; | |
| 741 | - foreach ( $plugin_upgrades as $plugin_slug => $info ) { | |
| 742 | - if ( false !== strpos( $plugin_slug, $arg->slug ) && isset( $info['update'] ) ) { | |
| 743 | - $found_update = true; | |
| 744 | - if ( isset( $info['update']['slug'] ) && $arg->slug === $info['update']['slug'] && isset( $info['update']['new_version'] ) && ! empty( $info['update']['new_version'] ) && isset( $info['update']['sections'] ) && ! empty( $info['update']['sections'] ) ) { | |
| 745 | - $info_update = (object) $info['update']; | |
| 746 | - $info_update->external = false; | |
| 747 | - return $info_update; | |
| 748 | - } | |
| 749 | - $empty_sections = true; | |
| 750 | - break; | |
| 751 | - } | |
| 752 | - } | |
| 753 | - | |
| 754 | - if ( $found_update && $empty_sections ) { | |
| 755 | - try { | |
| 756 | - $info = MainWP_Connect::fetch_url_authed( | |
| 757 | - $website, | |
| 758 | - 'plugin_action', | |
| 759 | - array( | |
| 760 | - 'action' => 'changelog_info', // try to get changelog from the child site. | |
| 761 | - 'slug' => $arg->slug, | |
| 762 | - ) | |
| 763 | - ); | |
| 764 | - if ( is_array( $info ) && isset( $info['update'] ) && ! empty( $info['update']['sections'] ) ) { | |
| 765 | - $info_update = (object) $info['update']; | |
| 766 | - $info_update->external = true; | |
| 767 | - return $info_update; | |
| 768 | - } | |
| 769 | - } catch ( \Exception $e ) { | |
| 770 | - // error happen. | |
| 771 | - } | |
| 772 | - } | |
| 773 | - } | |
| 774 | - } | |
| 775 | - } | |
| 776 | - | |
| 777 | - return $res; | |
| 778 | - } | |
| 779 | - | |
| 780 | - /** | |
| 781 | 344 | * Method check_update_custom() |
| 782 | 345 | * |
| 783 | - * Check MainWP Extensions for updates. | |
| 346 | + * Check MainWP Exensions for updates. | |
| 784 | 347 | * |
| 785 | 348 | * @param object $transient Transient information. |
| 786 | 349 | * |
| 787 | 350 | * @return object $transient Transient information. |
| @@ -786,28 +349,15 @@ | ||
| 786 | 349 | * |
| 787 | 350 | * @return object $transient Transient information. |
| 788 | 351 | * |
| 789 | 352 | * @uses \MainWP\Dashboard\MainWP_API_Handler::get_upgrade_information() |
| 790 | - * @uses \MainWP\Dashboard\MainWP_Extensions_Handler::get_indexed_extensions_infor() | |
| 791 | - * @uses \MainWP\Dashboard\MainWP_Extensions_Handler::get_extension_slug() | |
| 792 | - * @uses \MainWP\Dashboard\MainWP_Utility::update_option() | |
| 793 | 353 | */ |
| 794 | 354 | public function check_update_custom( $transient ) { // phpcs:ignore -- Current complexity is the only way to achieve desired results, pull request solutions appreciated. |
| 795 | - if ( isset( $_POST['action'] ) && ( ( 'update-plugin' === $_POST['action'] ) || ( 'update-selected' === $_POST['action'] ) ) && is_object( $transient ) && property_exists( $transient, 'response' ) ) { // phpcs:ignore WordPress.Security.NonceVerification,WordPress.Security.ValidatedSanitizedInput.InputNotSanitized | |
| 355 | + if ( isset( $_POST['action'] ) && ( ( 'update-plugin' === $_POST['action'] ) || ( 'update-selected' === $_POST['action'] ) ) ) { | |
| 796 | 356 | $extensions = MainWP_Extensions_Handler::get_indexed_extensions_infor( array( 'activated' => true ) ); |
| 797 | - if ( defined( 'DOING_AJAX' ) && isset( $_POST['plugin'] ) && 'update-plugin' === $_POST['action'] ) { // phpcs:ignore WordPress.Security.NonceVerification,WordPress.Security.ValidatedSanitizedInput.InputNotSanitized | |
| 798 | - | |
| 799 | - if ( empty( $transient->response ) ) { | |
| 800 | - $transient->response = array(); | |
| 801 | - } | |
| 802 | - | |
| 803 | - $plugin_slug = sanitize_text_field( wp_unslash( $_POST['plugin'] ) ); // phpcs:ignore WordPress.Security.NonceVerification,WordPress.Security.ValidatedSanitizedInput.InputNotSanitized | |
| 357 | + if ( defined( 'DOING_AJAX' ) && isset( $_POST['plugin'] ) && 'update-plugin' == $_POST['action'] ) { | |
| 358 | + $plugin_slug = sanitize_text_field( wp_unslash( $_POST['plugin'] ) ); | |
| 804 | 359 | if ( isset( $extensions[ $plugin_slug ] ) ) { |
| 805 | - | |
| 806 | - if ( ! isset( $transient->response[ $plugin_slug ] ) || ! is_object( $transient->response[ $plugin_slug ] ) || ! property_exists( $transient->response[ $plugin_slug ], 'new_version' ) ) { | |
| 807 | - return $transient; | |
| 808 | - } | |
| 809 | - | |
| 810 | 360 | if ( isset( $transient->response[ $plugin_slug ] ) && version_compare( $transient->response[ $plugin_slug ]->new_version, $extensions[ $plugin_slug ]['version'], '=' ) ) { |
| 811 | 361 | return $transient; |
| 812 | 362 | } |
| 813 | 363 | |
| @@ -813,34 +363,25 @@ | ||
| 813 | 363 | |
| 814 | 364 | $api_slug = dirname( $plugin_slug ); |
| 815 | 365 | $rslt = MainWP_API_Handler::get_upgrade_information( $api_slug ); |
| 816 | 366 | |
| 817 | - if ( ! empty( $rslt ) && is_object( $rslt ) && property_exists( $rslt, 'new_version' ) && ! empty( $rslt->new_version ) && version_compare( $rslt->new_version, $extensions[ $plugin_slug ]['version'], '>' ) ) { | |
| 367 | + if ( ! empty( $rslt ) && isset( $rslt->latest_version ) && version_compare( $rslt->latest_version, $extensions[ $plugin_slug ]['version'], '>' ) ) { | |
| 818 | 368 | $transient->response[ $plugin_slug ] = self::map_rslt_obj( $rslt ); |
| 819 | 369 | } |
| 820 | 370 | |
| 821 | 371 | return $transient; |
| 822 | 372 | } |
| 823 | - } elseif ( 'update-selected' === $_POST['action'] && isset( $_POST['checked'] ) && is_array( $_POST['checked'] ) ) { // phpcs:ignore WordPress.Security.NonceVerification,WordPress.Security.ValidatedSanitizedInput.InputNotSanitized | |
| 824 | - | |
| 825 | - if ( empty( $transient->response ) ) { | |
| 826 | - $transient->response = array(); | |
| 827 | - } | |
| 828 | - | |
| 373 | + } elseif ( 'update-selected' === $_POST['action'] && isset( $_POST['checked'] ) && is_array( $_POST['checked'] ) ) { | |
| 829 | 374 | $updated = false; |
| 830 | - foreach ( wp_unslash( $_POST['checked'] ) as $plugin_slug ) { // phpcs:ignore WordPress.Security.NonceVerification,WordPress.Security.ValidatedSanitizedInput.InputNotSanitized | |
| 375 | + foreach ( wp_unslash( $_POST['checked'] ) as $plugin_slug ) { | |
| 831 | 376 | if ( isset( $extensions[ $plugin_slug ] ) ) { |
| 832 | - | |
| 833 | - if ( ! isset( $transient->response[ $plugin_slug ] ) ) { | |
| 834 | - $transient->response[ $plugin_slug ] = new \stdClass(); | |
| 835 | - } | |
| 836 | - | |
| 837 | 377 | if ( isset( $transient->response[ $plugin_slug ] ) && version_compare( $transient->response[ $plugin_slug ]->new_version, $extensions[ $plugin_slug ]['version'], '=' ) ) { |
| 838 | 378 | continue; |
| 839 | 379 | } |
| 840 | 380 | $api_slug = dirname( $plugin_slug ); |
| 841 | 381 | $rslt = MainWP_API_Handler::get_upgrade_information( $api_slug ); |
| 842 | - if ( ! empty( $rslt ) && is_object( $rslt ) && property_exists( $rslt, 'new_version' ) && ! empty( $rslt->new_version ) && version_compare( $rslt->new_version, $extensions[ $plugin_slug ]['version'], '>' ) ) { | |
| 382 | + if ( ! empty( $rslt ) && isset( $rslt->latest_version ) && version_compare( $rslt->latest_version, $extensions[ $plugin_slug ]['version'], '>' ) ) { | |
| 383 | + | |
| 843 | 384 | $this->upgradeVersionInfo->result[ $api_slug ] = $rslt; |
| 844 | 385 | $transient->response[ $plugin_slug ] = self::map_rslt_obj( $rslt ); |
| 845 | 386 | $updated = true; |
| 846 | 387 | } |
| @@ -857,9 +398,13 @@ | ||
| 857 | 398 | if ( empty( $transient->checked ) ) { |
| 858 | 399 | return $transient; |
| 859 | 400 | } |
| 860 | 401 | |
| 861 | - if ( ! empty( $this->upgradeVersionInfo ) && property_exists( $this->upgradeVersionInfo, 'result' ) && is_array( $this->upgradeVersionInfo->result ) ) { | |
| 402 | + if ( isset( $_GET['do'] ) && 'checkUpgrade' === $_GET['do'] && ( ( time() - $this->upgradeVersionInfo->updated ) > 30 ) ) { | |
| 403 | + $this->check_upgrade(); | |
| 404 | + } | |
| 405 | + | |
| 406 | + if ( null != $this->upgradeVersionInfo && property_exists( $this->upgradeVersionInfo, 'result' ) && is_array( $this->upgradeVersionInfo->result ) ) { | |
| 862 | 407 | foreach ( $this->upgradeVersionInfo->result as $rslt ) { |
| 863 | 408 | if ( ! isset( $rslt->slug ) ) { |
| 864 | 409 | continue; |
| 865 | 410 | } |
| @@ -864,9 +409,9 @@ | ||
| 864 | 409 | continue; |
| 865 | 410 | } |
| 866 | 411 | |
| 867 | 412 | $plugin_slug = MainWP_Extensions_Handler::get_extension_slug( $rslt->slug ); |
| 868 | - if ( isset( $transient->checked[ $plugin_slug ] ) && property_exists( $rslt, 'new_version' ) && ! empty( $rslt->new_version ) && version_compare( $rslt->new_version, $transient->checked[ $plugin_slug ], '>' ) ) { | |
| 413 | + if ( isset( $transient->checked[ $plugin_slug ] ) && version_compare( $rslt->latest_version, $transient->checked[ $plugin_slug ], '>' ) ) { | |
| 869 | 414 | $transient->response[ $plugin_slug ] = self::map_rslt_obj( $rslt ); |
| 870 | 415 | } |
| 871 | 416 | } |
| 872 | 417 | } |
| @@ -886,11 +431,11 @@ | ||
| 886 | 431 | */ |
| 887 | 432 | public static function map_rslt_obj( $result ) { |
| 888 | 433 | $obj = new \stdClass(); |
| 889 | 434 | $obj->slug = $result->slug; |
| 890 | - $obj->new_version = $result->new_version; | |
| 435 | + $obj->new_version = $result->latest_version; | |
| 891 | 436 | $obj->url = 'https://mainwp.com/'; |
| 892 | - $obj->package = $result->package; | |
| 437 | + $obj->package = $result->download_url; | |
| 893 | 438 | |
| 894 | 439 | return $obj; |
| 895 | 440 | } |
| 896 | 441 | |
| @@ -899,13 +444,12 @@ | ||
| 899 | 444 | * |
| 900 | 445 | * Check if Extension has an update. |
| 901 | 446 | * |
| 902 | 447 | * @uses \MainWP\Dashboard\MainWP_API_Handler::check_exts_upgrade() |
| 903 | - * @uses \MainWP\Dashboard\MainWP_Utility::update_option() | |
| 904 | 448 | */ |
| 905 | 449 | private function check_upgrade() { |
| 906 | 450 | $result = MainWP_API_Handler::check_exts_upgrade(); |
| 907 | - if ( null === $this->upgradeVersionInfo ) { | |
| 451 | + if ( null == $this->upgradeVersionInfo ) { | |
| 908 | 452 | $this->upgradeVersionInfo = new \stdClass(); |
| 909 | 453 | } |
| 910 | 454 | $this->upgradeVersionInfo->updated = time(); |
| 911 | 455 | if ( ! empty( $result ) ) { |
| @@ -921,11 +465,8 @@ | ||
| 921 | 465 | * |
| 922 | 466 | * @param object $transient Transient information. |
| 923 | 467 | * |
| 924 | 468 | * @return object $transient Transient information. |
| 925 | - * | |
| 926 | - * @uses \MainWP\Dashboard\MainWP_Extensions_Handler::get_indexed_extensions_infor() | |
| 927 | - * @uses \MainWP\Dashboard\MainWP_Extensions_Handler::get_extension_slug() | |
| 928 | 469 | */ |
| 929 | 470 | public function pre_check_update_custom( $transient ) { |
| 930 | 471 | if ( ! isset( $transient->checked ) ) { |
| 931 | 472 | return $transient; |
| @@ -930,21 +471,17 @@ | ||
| 930 | 471 | if ( ! isset( $transient->checked ) ) { |
| 931 | 472 | return $transient; |
| 932 | 473 | } |
| 933 | 474 | |
| 934 | - if ( ( null === $this->upgradeVersionInfo ) || ! property_exists( $this->upgradeVersionInfo, 'updated' ) || ( ( time() - $this->upgradeVersionInfo->updated ) > 60 ) ) { | |
| 475 | + if ( ( null == $this->upgradeVersionInfo ) || ! property_exists( $this->upgradeVersionInfo, 'updated' ) || ( ( time() - $this->upgradeVersionInfo->updated ) > 60 ) ) { | |
| 935 | 476 | $this->check_upgrade(); |
| 936 | 477 | } |
| 937 | 478 | |
| 938 | - if ( empty( $transient->response ) ) { | |
| 939 | - $transient->response = array(); | |
| 940 | - } | |
| 941 | - | |
| 942 | - if ( ! empty( $this->upgradeVersionInfo ) && property_exists( $this->upgradeVersionInfo, 'result' ) && is_array( $this->upgradeVersionInfo->result ) ) { | |
| 479 | + if ( null != $this->upgradeVersionInfo && property_exists( $this->upgradeVersionInfo, 'result' ) && is_array( $this->upgradeVersionInfo->result ) ) { | |
| 943 | 480 | $extensions = MainWP_Extensions_Handler::get_indexed_extensions_infor( array( 'activated' => true ) ); |
| 944 | 481 | foreach ( $this->upgradeVersionInfo->result as $rslt ) { |
| 945 | 482 | $plugin_slug = MainWP_Extensions_Handler::get_extension_slug( $rslt->slug ); |
| 946 | - if ( isset( $extensions[ $plugin_slug ] ) && property_exists( $rslt, 'new_version' ) && ! empty( $rslt->new_version ) && version_compare( $rslt->new_version, $extensions[ $plugin_slug ]['version'], '>' ) ) { | |
| 483 | + if ( isset( $extensions[ $plugin_slug ] ) && version_compare( $rslt->latest_version, $extensions[ $plugin_slug ]['version'], '>' ) ) { | |
| 947 | 484 | $transient->response[ $plugin_slug ] = self::map_rslt_obj( $rslt ); |
| 948 | 485 | } |
| 949 | 486 | } |
| 950 | 487 | } |
| @@ -959,10 +496,8 @@ | ||
| 959 | 496 | * |
| 960 | 497 | * @param mixed $file File to upload. |
| 961 | 498 | * |
| 962 | 499 | * @return void |
| 963 | - * | |
| 964 | - * @uses \MainWP\Dashboard\MainWP_Utility::ends_with() | |
| 965 | 500 | */ |
| 966 | 501 | public function upload_file( $file ) { |
| 967 | 502 | header( 'Content-Description: File Transfer' ); |
| 968 | 503 | if ( MainWP_Utility::ends_with( $file, '.tar.gz' ) ) { |
| @@ -1000,13 +535,11 @@ | ||
| 1000 | 535 | } |
| 1001 | 536 | |
| 1002 | 537 | while ( ! feof( $handle ) ) { |
| 1003 | 538 | $buffer = fread( $handle, $chunksize ); |
| 1004 | - echo $buffer; // phpcs:ignore WordPress.Security.EscapeOutput.OutputNotEscaped | |
| 1005 | - if ( ob_get_length() ) { | |
| 1006 | - ob_flush(); | |
| 1007 | - flush(); | |
| 1008 | - } | |
| 539 | + echo $buffer; | |
| 540 | + ob_flush(); | |
| 541 | + flush(); | |
| 1009 | 542 | $buffer = null; |
| 1010 | 543 | } |
| 1011 | 544 | |
| 1012 | 545 | return fclose( $handle ); |
| @@ -1032,11 +565,8 @@ | ||
| 1032 | 565 | * Activate MainWP Extension. |
| 1033 | 566 | * |
| 1034 | 567 | * @param mixed $ext_key Extension API Key. |
| 1035 | 568 | * @param array $info Extension Info. |
| 1036 | - * | |
| 1037 | - * @uses \MainWP\Dashboard\MainWP_Api_Manager::set_activation_info() | |
| 1038 | - * @uses \MainWP\Dashboard\MainWP_Api_Manager_Password_Management::generate_password() | |
| 1039 | 569 | */ |
| 1040 | 570 | public function activate_extension( $ext_key, $info = array() ) { |
| 1041 | 571 | |
| 1042 | 572 | add_filter( 'wp_redirect', array( $this, 'activate_redirect' ) ); |
| @@ -1057,18 +587,10 @@ | ||
| 1057 | 587 | * |
| 1058 | 588 | * Deactivate MaiNWP Extension. |
| 1059 | 589 | * |
| 1060 | 590 | * @param mixed $ext_key Exnension API Key. |
| 1061 | - * @param bool $dashboard_only Deactive API Key on dashboard only. | |
| 1062 | - * | |
| 1063 | - * @uses \MainWP\Dashboard\MainWP_Api_Manager::set_activation_info() | |
| 1064 | 591 | */ |
| 1065 | - public function deactivate_extension( $ext_key, $dashboard_only = false ) { | |
| 1066 | - // try to deactivate license. | |
| 1067 | - if ( ! $dashboard_only ) { | |
| 1068 | - $mainwp_api_key = MainWP_Api_Manager_Key::instance()->get_decrypt_master_api_key(); | |
| 1069 | - $result = MainWP_Api_Manager::instance()->license_key_deactivation( $ext_key, $mainwp_api_key ); | |
| 1070 | - } | |
| 592 | + public function deactivate_extension( $ext_key ) { | |
| 593 | + MainWP_Api_Manager::instance()->set_activation_info( $ext_key, '' ); | |
| 594 | + } | |
| 1071 | 595 | |
| 1072 | - MainWP_Api_Manager::instance()->remove_activation_info( $ext_key ); | |
| 1073 | - } | |
| 1074 | 596 | } |