| @@ -9,8 +9,13 @@ | ||
| 9 | 9 | */ |
| 10 | 10 | |
| 11 | 11 | namespace MainWP\Dashboard; |
| 12 | 12 | |
| 13 | +// Exit if accessed directly. | |
| 14 | +if ( ! defined( 'ABSPATH' ) ) { | |
| 15 | + exit; | |
| 16 | +} | |
| 17 | + | |
| 13 | 18 | /** |
| 14 | 19 | * Class MainWP_Settings |
| 15 | 20 | * |
| 16 | 21 | * @package MainWP\Dashboard |
| @@ -55,9 +60,9 @@ | ||
| 55 | 60 | if ( is_array( $added_demo ) && ! empty( $added_demo['sites_ids'] ) ) { |
| 56 | 61 | static::$demo_website_ids = $added_demo['sites_ids']; |
| 57 | 62 | } |
| 58 | 63 | |
| 59 | - if ( empty( static::$demo_website_ids ) || ! array( static::$demo_website_ids ) ) { | |
| 64 | + if ( empty( static::$demo_website_ids ) || ! is_array( static::$demo_website_ids ) ) { | |
| 60 | 65 | static::$demo_website_ids = array( -1 ); // for single assign. |
| 61 | 66 | } |
| 62 | 67 | } |
| 63 | 68 | return static::$instance; |
| @@ -288,15 +293,15 @@ | ||
| 288 | 293 | $params['userid'] = $userid; |
| 289 | 294 | $params['client_id'] = 0; // set: 0. |
| 290 | 295 | |
| 291 | 296 | $syncValues = array( |
| 292 | - 'dtsSync' => 0, | |
| 293 | - 'dtsSyncStart' => 0, | |
| 294 | - 'dtsAutomaticSync' => 0, | |
| 295 | - 'dtsAutomaticSyncStart' => 0, | |
| 296 | - 'totalsize' => 0, | |
| 297 | - 'extauth' => '', | |
| 298 | - 'sync_errors' => '', | |
| 297 | + 'dtsSync' => 0, | |
| 298 | + 'dtsSyncStart' => 0, | |
| 299 | + 'dtsAutomaticSync' => 0, | |
| 300 | + 'dtsAutomaticSyncStart' => 0, | |
| 301 | + 'totalsize' => 0, | |
| 302 | + 'extauth' => '', | |
| 303 | + 'sync_errors' => '', | |
| 299 | 304 | ); |
| 300 | 305 | |
| 301 | 306 | if ( $wpdb->insert( MainWP_DB::instance()->get_table_name( 'wp' ), $params ) ) { |
| 302 | 307 | $websiteid = $wpdb->insert_id; |
| @@ -365,18 +370,8 @@ | ||
| 365 | 370 | * @param index $websiteid website id. |
| 366 | 371 | */ |
| 367 | 372 | private function add_demo_none_mainwp_action( $data_rows, $index, $websiteid ) { |
| 368 | 373 | global $wpdb; |
| 369 | - if ( ! is_array( $data_rows ) || empty( $websiteid ) ) { | |
| 370 | - return; | |
| 371 | - } | |
| 372 | - foreach ( $data_rows as $row ) { | |
| 373 | - if ( isset( $row['action_id'] ) && isset( $row['wpid'] ) && (int) $index === (int) $row['wpid'] ) { | |
| 374 | - unset( $row['action_id'] ); | |
| 375 | - $row['wpid'] = $websiteid; | |
| 376 | - $wpdb->insert( MainWP_DB::instance()->get_table_name( 'wp_actions' ), $row ); | |
| 377 | - } | |
| 378 | - } | |
| 379 | 374 | } |
| 380 | 375 | |
| 381 | 376 | /** |
| 382 | 377 | * Method delete_data_demo() |
| @@ -413,14 +408,26 @@ | ||
| 413 | 408 | * Handle delete demo data . |
| 414 | 409 | */ |
| 415 | 410 | public function is_new_instance() { |
| 416 | 411 | global $wpdb; |
| 417 | - $count = $wpdb->get_var( 'SELECT count(id) FROM ' . MainWP_DB::instance()->get_table_name( 'wp' ) ); //phpcs:ignore WordPress.DB.PreparedSQL -- ok. | |
| 412 | + $cache_key = 'mainwp_is_new_instance'; | |
| 413 | + $cached = wp_cache_get( $cache_key ); | |
| 414 | + | |
| 415 | + if ( false !== $cached ) { | |
| 416 | + return $cached; | |
| 417 | + } | |
| 418 | + | |
| 419 | + $table_wp = esc_sql( MainWP_DB::instance()->get_table_name( 'wp' ) ); | |
| 420 | + $count = $wpdb->get_var( "SELECT count(id) FROM {$table_wp}" ); // phpcs:ignore WordPress.DB.PreparedSQL.NotPrepared -- Table name cannot be parameterized. | |
| 418 | 421 | if ( $count ) { |
| 422 | + wp_cache_set( $cache_key, false ); | |
| 419 | 423 | return false; |
| 420 | 424 | } |
| 421 | - $count = $wpdb->get_var( 'SELECT count(client_id) FROM ' . MainWP_DB::instance()->get_table_name( 'wp_clients' ) ); //phpcs:ignore WordPress.DB.PreparedSQL -- ok. | |
| 425 | + | |
| 426 | + $table_clients = esc_sql( MainWP_DB::instance()->get_table_name( 'wp_clients' ) ); | |
| 427 | + $count = $wpdb->get_var( "SELECT count(client_id) FROM {$table_clients}" ); // phpcs:ignore WordPress.DB.PreparedSQL.NotPrepared -- Table name cannot be parameterized. | |
| 422 | 428 | if ( $count ) { |
| 429 | + wp_cache_set( $cache_key, false ); | |
| 423 | 430 | return false; |
| 424 | 431 | } |
| 425 | 432 | |
| 426 | 433 | $extensions_disabled = MainWP_Extensions_Handler::get_extensions_disabled(); |
| @@ -425,11 +432,13 @@ | ||
| 425 | 432 | |
| 426 | 433 | $extensions_disabled = MainWP_Extensions_Handler::get_extensions_disabled(); |
| 427 | 434 | $extensions = MainWP_Extensions_Handler::get_extensions(); |
| 428 | 435 | if ( ! empty( $extensions ) && $extensions !== $extensions_disabled ) { |
| 436 | + wp_cache_set( $cache_key, false ); | |
| 429 | 437 | return false; |
| 430 | 438 | } |
| 431 | 439 | |
| 440 | + wp_cache_set( $cache_key, true ); | |
| 432 | 441 | return true; |
| 433 | 442 | } |
| 434 | 443 | |
| 435 | 444 | /** |