| @@ -1,6 +1,12 @@ | ||
| 1 | 1 | <?php |
| 2 | +/** | |
| 3 | + * @package Polylang | |
| 4 | + */ | |
| 2 | 5 | |
| 6 | +use WP_Syntex\Polylang\Options\Options; | |
| 7 | +use WP_Syntex\Polylang\Options\Registry as Options_Registry; | |
| 8 | + | |
| 3 | 9 | /** |
| 4 | 10 | * Polylang activation / de-activation class |
| 5 | 11 | * |
| 6 | 12 | * @since 1.7 |
| @@ -10,8 +16,10 @@ | ||
| 10 | 16 | /** |
| 11 | 17 | * Checks min PHP and WP version, displays a notice if a requirement is not met. |
| 12 | 18 | * |
| 13 | 19 | * @since 2.6.7 |
| 20 | + * | |
| 21 | + * @return bool | |
| 14 | 22 | */ |
| 15 | 23 | public function can_activate() { |
| 16 | 24 | global $wp_version; |
| 17 | 25 | |
| @@ -31,11 +39,13 @@ | ||
| 31 | 39 | /** |
| 32 | 40 | * Displays a notice if PHP min version is not met. |
| 33 | 41 | * |
| 34 | 42 | * @since 2.6.7 |
| 43 | + * | |
| 44 | + * @return void | |
| 35 | 45 | */ |
| 36 | 46 | public function php_version_notice() { |
| 37 | - load_plugin_textdomain( 'polylang', false, basename( POLYLANG_DIR ) . '/languages' ); // Plugin i18n. | |
| 47 | + load_plugin_textdomain( 'polylang' ); // Plugin i18n. | |
| 38 | 48 | |
| 39 | 49 | printf( |
| 40 | 50 | '<div class="error"><p>%s</p></div>', |
| 41 | 51 | sprintf( |
| @@ -51,13 +61,15 @@ | ||
| 51 | 61 | /** |
| 52 | 62 | * Displays a notice if WP min version is not met. |
| 53 | 63 | * |
| 54 | 64 | * @since 2.6.7 |
| 65 | + * | |
| 66 | + * @return void | |
| 55 | 67 | */ |
| 56 | 68 | public function wp_version_notice() { |
| 57 | 69 | global $wp_version; |
| 58 | 70 | |
| 59 | - load_plugin_textdomain( 'polylang', false, basename( POLYLANG_DIR ) . '/languages' ); // Plugin i18n. | |
| 71 | + load_plugin_textdomain( 'polylang' ); // Plugin i18n. | |
| 60 | 72 | |
| 61 | 73 | printf( |
| 62 | 74 | '<div class="error"><p>%s</p></div>', |
| 63 | 75 | sprintf( |
| @@ -70,48 +82,34 @@ | ||
| 70 | 82 | ); |
| 71 | 83 | } |
| 72 | 84 | |
| 73 | 85 | /** |
| 74 | - * Get default Polylang options | |
| 75 | - * | |
| 76 | - * @since 1.8 | |
| 77 | - * | |
| 78 | - * return array | |
| 79 | - */ | |
| 80 | - public static function get_default_options() { | |
| 81 | - return array( | |
| 82 | - 'browser' => 1, // Default language for the front page is set by browser preference | |
| 83 | - 'rewrite' => 1, // Remove /language/ in permalinks ( was the opposite before 0.7.2 ) | |
| 84 | - 'hide_default' => 1, // Remove URL language information for default language ( was the opposite before 2.1.5 ) | |
| 85 | - 'force_lang' => 1, // Add URL language information ( was 0 before 1.7 ) | |
| 86 | - 'redirect_lang' => 0, // Do not redirect the language page to the homepage | |
| 87 | - 'media_support' => 1, // Support languages and translation for media by default | |
| 88 | - 'uninstall' => 0, // Do not remove data when uninstalling Polylang | |
| 89 | - 'sync' => array(), // Synchronisation is disabled by default ( was the opposite before 1.2 ) | |
| 90 | - 'post_types' => array(), | |
| 91 | - 'taxonomies' => array(), | |
| 92 | - 'domains' => array(), | |
| 93 | - 'version' => POLYLANG_VERSION, | |
| 94 | - 'first_activation' => time(), | |
| 95 | - ); | |
| 96 | - } | |
| 97 | - | |
| 98 | - /** | |
| 99 | 86 | * Plugin activation |
| 100 | 87 | * |
| 101 | 88 | * @since 0.5 |
| 89 | + * | |
| 90 | + * @return void | |
| 102 | 91 | */ |
| 103 | 92 | protected function _activate() { |
| 104 | - if ( $options = get_option( 'polylang' ) ) { | |
| 105 | - // Check if we will be able to upgrade | |
| 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. | |
| 106 | 98 | if ( version_compare( $options['version'], POLYLANG_VERSION, '<' ) ) { |
| 107 | - $upgrade = new PLL_Upgrade( $options ); | |
| 108 | - $upgrade->can_activate(); | |
| 99 | + ( new PLL_Upgrade( $options ) )->can_activate(); | |
| 109 | 100 | } |
| 101 | + } else { | |
| 102 | + $options['version'] = POLYLANG_VERSION; | |
| 110 | 103 | } |
| 111 | - // Defines default values for options in case this is the first installation | |
| 112 | - else { | |
| 113 | - update_option( 'polylang', self::get_default_options() ); | |
| 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 | + ); | |
| 114 | 112 | } |
| 115 | 113 | |
| 116 | 114 | // Avoid 1 query on every pages if no wpml strings is registered |
| 117 | 115 | if ( ! get_option( 'polylang_wpml_strings' ) ) { |
| @@ -127,8 +125,10 @@ | ||
| 127 | 125 | /** |
| 128 | 126 | * Plugin deactivation |
| 129 | 127 | * |
| 130 | 128 | * @since 0.5 |
| 129 | + * | |
| 130 | + * @return void | |
| 131 | 131 | */ |
| 132 | 132 | protected function _deactivate() { |
| 133 | 133 | delete_option( 'rewrite_rules' ); // Don't use flush_rewrite_rules at network activation. See #32471 |
| 134 | 134 | } |