| 1 |
<?php |
| 2 |
|
| 3 |
// Do not allow the file to be called directly. |
| 4 |
if ( ! defined( 'ABSPATH' ) ) { |
| 5 |
exit; |
| 6 |
} |
| 7 |
|
| 8 |
/** |
| 9 |
* This class is used to handle anything multisite related. |
| 10 |
*/ |
| 11 |
class P_Multisite extends P_Core { |
| 12 |
/** |
| 13 |
* Add the actions required for the multisite functionality. |
| 14 |
* |
| 15 |
* @param Patchstack $core |
| 16 |
* @return void |
| 17 |
*/ |
| 18 |
public function __construct( $core ) { |
| 19 |
parent::__construct( $core ); |
| 20 |
if ( ! is_super_admin() ) { |
| 21 |
return; |
| 22 |
} |
| 23 |
|
| 24 |
// When we need to re-run the migration of a specific site. |
| 25 |
if ( isset( $_GET['site'], $_GET['PatchstackNonce'] ) && wp_verify_nonce( $_GET['PatchstackNonce'], 'patchstack-migration' ) ) { |
| 26 |
$this->run_migration(); |
| 27 |
} |
| 28 |
} |
| 29 |
|
| 30 |
/** |
| 31 |
* This will be called when the network admin clicks on the "Sites" button. |
| 32 |
* It will show all sites. |
| 33 |
* |
| 34 |
* @return void |
| 35 |
*/ |
| 36 |
public function sites_section_callback() { |
| 37 |
require_once dirname( __FILE__ ) . '/views/pages/multisite-table.php'; |
| 38 |
} |
| 39 |
|
| 40 |
/** |
| 41 |
* Re-run the migration for a specific multisite site. |
| 42 |
* |
| 43 |
* @return void |
| 44 |
*/ |
| 45 |
private function run_migration( ) { |
| 46 |
// Must be a number. |
| 47 |
if ( ! isset( $_GET['site'] ) || ! is_scalar( $_GET['site'] ) || ! ctype_digit( (string) $_GET['site'] ) ) { |
| 48 |
exit; |
| 49 |
} |
| 50 |
|
| 51 |
// Site must be valid and exists. |
| 52 |
$site = function_exists( 'get_site' ) ? get_site( $_GET['site'] ) : null; |
| 53 |
if ( is_null( $site ) ) { |
| 54 |
exit; |
| 55 |
} |
| 56 |
|
| 57 |
// Perform base migration. |
| 58 |
$this->plugin->activation->migrate( null, $site->id ); |
| 59 |
|
| 60 |
// Perform specific version migrations. |
| 61 |
$versions = array('3.0.1', '3.0.2'); |
| 62 |
foreach ( $versions as $version ) { |
| 63 |
$this->plugin->activation->migrate( $version, $site->id ); |
| 64 |
} |
| 65 |
|
| 66 |
wp_safe_redirect( add_query_arg( [ 'success' => '1', 'site' => $site->id ], remove_query_arg( [ 'PatchstackNonce', 'site' ] ) ) ); |
| 67 |
exit; |
| 68 |
} |
| 69 |
} |
| 70 |
|