| 1 |
<?php |
| 2 |
/** |
| 3 |
* @package Polylang |
| 4 |
* |
| 5 |
* /!\ THE CONSTANTS `POLYLANG_BASENAME` AND `POLYLANG_VERSION` MUST BE DEFINED. |
| 6 |
*/ |
| 7 |
|
| 8 |
/** |
| 9 |
* A generic (de)activation class compatible with multisite. |
| 10 |
* |
| 11 |
* @since 3.8 |
| 12 |
*/ |
| 13 |
abstract class PLL_Abstract_Activable { |
| 14 |
/** |
| 15 |
* (De)Activation for all blogs. |
| 16 |
* |
| 17 |
* @since 1.2 |
| 18 |
* @since 3.8 Moved from the class `PLL_Install_Base`. |
| 19 |
* Visibility changed from `protected`. |
| 20 |
* Made it `static`. |
| 21 |
* Removed first parameter `$what`. |
| 22 |
* |
| 23 |
* @param bool $networkwide Whether the plugin is (de)activated for all sites in the network or just the current site. |
| 24 |
* @return void |
| 25 |
*/ |
| 26 |
public static function do_for_all_blogs( $networkwide ): void { |
| 27 |
if ( is_multisite() && $networkwide ) { |
| 28 |
// Network. |
| 29 |
foreach ( get_sites( array( 'fields' => 'ids', 'number' => 0 ) ) as $blog_id ) { |
| 30 |
switch_to_blog( $blog_id ); |
| 31 |
static::process(); |
| 32 |
} |
| 33 |
restore_current_blog(); |
| 34 |
} else { |
| 35 |
// Single blog. |
| 36 |
static::process(); |
| 37 |
} |
| 38 |
} |
| 39 |
|
| 40 |
/** |
| 41 |
* Returns the plugin's basename. |
| 42 |
* |
| 43 |
* @since 3.8 |
| 44 |
* |
| 45 |
* @return string |
| 46 |
*/ |
| 47 |
public static function get_plugin_basename(): string { |
| 48 |
return pll_get_constant( 'POLYLANG_BASENAME', '' ); |
| 49 |
} |
| 50 |
|
| 51 |
/** |
| 52 |
* Returns the plugin's version. |
| 53 |
* |
| 54 |
* @since 3.8 |
| 55 |
* |
| 56 |
* @return string |
| 57 |
*/ |
| 58 |
public static function get_plugin_version(): string { |
| 59 |
return pll_get_constant( 'POLYLANG_VERSION', '' ); |
| 60 |
} |
| 61 |
|
| 62 |
/** |
| 63 |
* The process to run on plugin (de)activation. |
| 64 |
* |
| 65 |
* @since 0.5 |
| 66 |
* @since 3.8 Moved from the class `PLL_Install_Base`. |
| 67 |
* Renamed from `_activate()`/`_deactivate()`. |
| 68 |
* Made it `static` and `abstract`. |
| 69 |
* |
| 70 |
* @return void |
| 71 |
*/ |
| 72 |
abstract protected static function process(): void; |
| 73 |
} |
| 74 |
|