| 1 |
<?php |
| 2 |
/** |
| 3 |
* @package Polylang |
| 4 |
*/ |
| 5 |
|
| 6 |
use WP_Syntex\Polylang\Options\Options; |
| 7 |
use WP_Syntex\Polylang\Options\Registry as Options_Registry; |
| 8 |
|
| 9 |
/** |
| 10 |
* Polylang activation / de-activation class |
| 11 |
* |
| 12 |
* @since 1.7 |
| 13 |
*/ |
| 14 |
class PLL_Install extends PLL_Install_Base { |
| 15 |
|
| 16 |
/** |
| 17 |
* Checks min PHP and WP version, displays a notice if a requirement is not met. |
| 18 |
* |
| 19 |
* @since 2.6.7 |
| 20 |
* |
| 21 |
* @return bool |
| 22 |
*/ |
| 23 |
public function can_activate() { |
| 24 |
global $wp_version; |
| 25 |
|
| 26 |
if ( version_compare( PHP_VERSION, PLL_MIN_PHP_VERSION, '<' ) ) { |
| 27 |
add_action( 'admin_notices', array( $this, 'php_version_notice' ) ); |
| 28 |
return false; |
| 29 |
} |
| 30 |
|
| 31 |
if ( version_compare( $wp_version, PLL_MIN_WP_VERSION, '<' ) ) { |
| 32 |
add_action( 'admin_notices', array( $this, 'wp_version_notice' ) ); |
| 33 |
return false; |
| 34 |
} |
| 35 |
|
| 36 |
return true; |
| 37 |
} |
| 38 |
|
| 39 |
/** |
| 40 |
* Displays a notice if PHP min version is not met. |
| 41 |
* |
| 42 |
* @since 2.6.7 |
| 43 |
* |
| 44 |
* @return void |
| 45 |
*/ |
| 46 |
public function php_version_notice() { |
| 47 |
load_plugin_textdomain( 'polylang' ); // Plugin i18n. |
| 48 |
|
| 49 |
printf( |
| 50 |
'<div class="error"><p>%s</p></div>', |
| 51 |
sprintf( |
| 52 |
/* translators: 1: Plugin name 2: Current PHP version 3: Required PHP version */ |
| 53 |
esc_html__( '%1$s has deactivated itself because you are using an old version of PHP. You are using using PHP %2$s. %1$s requires PHP %3$s.', 'polylang' ), |
| 54 |
esc_html( POLYLANG ), |
| 55 |
PHP_VERSION, |
| 56 |
esc_html( PLL_MIN_PHP_VERSION ) |
| 57 |
) |
| 58 |
); |
| 59 |
} |
| 60 |
|
| 61 |
/** |
| 62 |
* Displays a notice if WP min version is not met. |
| 63 |
* |
| 64 |
* @since 2.6.7 |
| 65 |
* |
| 66 |
* @return void |
| 67 |
*/ |
| 68 |
public function wp_version_notice() { |
| 69 |
global $wp_version; |
| 70 |
|
| 71 |
load_plugin_textdomain( 'polylang' ); // Plugin i18n. |
| 72 |
|
| 73 |
printf( |
| 74 |
'<div class="error"><p>%s</p></div>', |
| 75 |
sprintf( |
| 76 |
/* translators: 1: Plugin name 2: Current WordPress version 3: Required WordPress version */ |
| 77 |
esc_html__( '%1$s has deactivated itself because you are using an old version of WordPress. You are using using WordPress %2$s. %1$s requires at least WordPress %3$s.', 'polylang' ), |
| 78 |
esc_html( POLYLANG ), |
| 79 |
esc_html( $wp_version ), |
| 80 |
esc_html( PLL_MIN_WP_VERSION ) |
| 81 |
) |
| 82 |
); |
| 83 |
} |
| 84 |
|
| 85 |
/** |
| 86 |
* Plugin activation |
| 87 |
* |
| 88 |
* @since 0.5 |
| 89 |
* |
| 90 |
* @return void |
| 91 |
*/ |
| 92 |
protected function _activate() { |
| 93 |
add_action( 'pll_init_options_for_blog', array( Options_Registry::class, 'register' ) ); |
| 94 |
$options = new Options(); |
| 95 |
|
| 96 |
if ( ! empty( $options['version'] ) ) { |
| 97 |
// Check if we will be able to upgrade. |
| 98 |
if ( version_compare( $options['version'], POLYLANG_VERSION, '<' ) ) { |
| 99 |
( new PLL_Upgrade( $options ) )->can_activate(); |
| 100 |
} |
| 101 |
} else { |
| 102 |
$options['version'] = POLYLANG_VERSION; |
| 103 |
} |
| 104 |
|
| 105 |
$options->save(); // Force save here to prevent any conflicts with another instance of `Options`. |
| 106 |
|
| 107 |
if ( false === get_option( 'pll_language_from_content_available' ) ) { |
| 108 |
update_option( |
| 109 |
'pll_language_from_content_available', |
| 110 |
0 === $options['force_lang'] ? 'yes' : 'no' |
| 111 |
); |
| 112 |
} |
| 113 |
|
| 114 |
// Avoid 1 query on every pages if no wpml strings is registered |
| 115 |
if ( ! get_option( 'polylang_wpml_strings' ) ) { |
| 116 |
update_option( 'polylang_wpml_strings', array() ); |
| 117 |
} |
| 118 |
|
| 119 |
// Don't use flush_rewrite_rules at network activation. See #32471 |
| 120 |
// Thanks to RavanH for the trick. See https://polylang.wordpress.com/2015/06/10/polylang-1-7-6-and-multisite/ |
| 121 |
// Rewrite rules are created at next page load :) |
| 122 |
delete_option( 'rewrite_rules' ); |
| 123 |
} |
| 124 |
|
| 125 |
/** |
| 126 |
* Plugin deactivation |
| 127 |
* |
| 128 |
* @since 0.5 |
| 129 |
* |
| 130 |
* @return void |
| 131 |
*/ |
| 132 |
protected function _deactivate() { |
| 133 |
delete_option( 'rewrite_rules' ); // Don't use flush_rewrite_rules at network activation. See #32471 |
| 134 |
} |
| 135 |
} |
| 136 |
|