| 1 |
<?php |
| 2 |
/** |
| 3 |
* @package Polylang |
| 4 |
* |
| 5 |
* /!\ THE CONSTANTS `POLYLANG_BASENAME` AND `POLYLANG_VERSION` MUST BE DEFINED. |
| 6 |
*/ |
| 7 |
|
| 8 |
use WP_Syntex\Polylang\Options\Options; |
| 9 |
use WP_Syntex\Polylang\Options\Registry as Options_Registry; |
| 10 |
|
| 11 |
/** |
| 12 |
* Activation class compatible with multisite. |
| 13 |
* |
| 14 |
* @since 3.8 |
| 15 |
*/ |
| 16 |
class PLL_Activate extends PLL_Abstract_Activate { |
| 17 |
/** |
| 18 |
* Adds the required hooks. |
| 19 |
* |
| 20 |
* @since 3.8 |
| 21 |
* |
| 22 |
* @return void |
| 23 |
*/ |
| 24 |
public static function add_hooks(): void { |
| 25 |
register_activation_hook( static::get_plugin_basename(), array( PLL_Wizard::class, 'start_wizard' ) ); |
| 26 |
|
| 27 |
parent::add_hooks(); |
| 28 |
} |
| 29 |
|
| 30 |
/** |
| 31 |
* The process to run on plugin activation. |
| 32 |
* |
| 33 |
* @since 0.5 |
| 34 |
* @since 3.8 Moved from the class `PLL_Install`. |
| 35 |
* Renamed from `_activate()`. |
| 36 |
* Made it `static`. |
| 37 |
* |
| 38 |
* @return void |
| 39 |
*/ |
| 40 |
protected static function process(): void { |
| 41 |
add_action( 'pll_init_options_for_blog', array( Options_Registry::class, 'register' ) ); |
| 42 |
$options = new Options(); |
| 43 |
|
| 44 |
if ( ! empty( $options['version'] ) ) { |
| 45 |
// Check if we will be able to upgrade. |
| 46 |
if ( version_compare( $options['version'], static::get_plugin_version(), '<' ) ) { |
| 47 |
( new PLL_Upgrade( $options ) )->can_activate(); |
| 48 |
} |
| 49 |
} else { |
| 50 |
$options['version'] = static::get_plugin_version(); |
| 51 |
} |
| 52 |
|
| 53 |
$options->save(); // Force save here to prevent any conflicts with another instance of `Options`. |
| 54 |
|
| 55 |
add_option( |
| 56 |
'pll_language_from_content_available', |
| 57 |
0 === $options['force_lang'] ? 'yes' : 'no' |
| 58 |
); |
| 59 |
|
| 60 |
// Avoid 1 query on every pages if no wpml strings is registered. |
| 61 |
add_option( 'polylang_wpml_strings', array() ); |
| 62 |
|
| 63 |
add_option( 'pll_language_taxonomies', array() ); |
| 64 |
|
| 65 |
/* |
| 66 |
* Don't use flush_rewrite_rules at network activation. See #32471. |
| 67 |
* Thanks to RavanH for the trick. See https://polylang.wordpress.com/2015/06/10/polylang-1-7-6-and-multisite/. |
| 68 |
* Rewrite rules are created at next page load. |
| 69 |
*/ |
| 70 |
delete_option( 'rewrite_rules' ); |
| 71 |
} |
| 72 |
} |
| 73 |
|