| @@ -1,8 +1,5 @@ | ||
| 1 | 1 | <?php |
| 2 | -/** | |
| 3 | - * @package Polylang | |
| 4 | - */ | |
| 5 | 2 | |
| 6 | 3 | /** |
| 7 | 4 | * Polylang activation / de-activation class |
| 8 | 5 | * |
| @@ -10,129 +7,89 @@ | ||
| 10 | 7 | */ |
| 11 | 8 | class PLL_Install extends PLL_Install_Base { |
| 12 | 9 | |
| 13 | 10 | /** |
| 14 | - * Checks min PHP and WP version, displays a notice if a requirement is not met. | |
| 11 | + * plugin activation for multisite | |
| 15 | 12 | * |
| 16 | - * @since 2.6.7 | |
| 13 | + * @since 0.1 | |
| 17 | 14 | */ |
| 18 | - public function can_activate() { | |
| 15 | + public function activate( $networkwide ) { | |
| 19 | 16 | global $wp_version; |
| 20 | 17 | |
| 21 | - if ( version_compare( PHP_VERSION, PLL_MIN_PHP_VERSION, '<' ) ) { | |
| 22 | - add_action( 'admin_notices', array( $this, 'php_version_notice' ) ); | |
| 23 | - return false; | |
| 24 | - } | |
| 18 | + Polylang::define_constants(); | |
| 25 | 19 | |
| 26 | - if ( version_compare( $wp_version, PLL_MIN_WP_VERSION, '<' ) ) { | |
| 27 | - add_action( 'admin_notices', array( $this, 'wp_version_notice' ) ); | |
| 28 | - return false; | |
| 20 | + load_plugin_textdomain( 'polylang', false, basename( POLYLANG_DIR ).'/languages' ); // plugin i18n | |
| 21 | + | |
| 22 | + if ( version_compare( $wp_version, PLL_MIN_WP_VERSION , '<' ) ) { | |
| 23 | + die( sprintf( '<p style = "font-family: sans-serif; font-size: 12px; color: #333; margin: -5px">%s</p>', | |
| 24 | + /* translators: %s are WordPress version numbers */ | |
| 25 | + sprintf( esc_html__( 'You are using WordPress %s. Polylang requires at least WordPress %s.', 'polylang' ), | |
| 26 | + esc_html( $wp_version ), | |
| 27 | + PLL_MIN_WP_VERSION | |
| 28 | + ) | |
| 29 | + ) ); | |
| 29 | 30 | } |
| 30 | - | |
| 31 | - return true; | |
| 31 | + $this->do_for_all_blogs( 'activate', $networkwide ); | |
| 32 | 32 | } |
| 33 | 33 | |
| 34 | 34 | /** |
| 35 | - * Displays a notice if PHP min version is not met. | |
| 35 | + * get default Polylang options | |
| 36 | 36 | * |
| 37 | - * @since 2.6.7 | |
| 38 | - */ | |
| 39 | - public function php_version_notice() { | |
| 40 | - load_plugin_textdomain( 'polylang' ); // Plugin i18n. | |
| 41 | - | |
| 42 | - printf( | |
| 43 | - '<div class="error"><p>%s</p></div>', | |
| 44 | - sprintf( | |
| 45 | - /* translators: 1: Plugin name 2: Current PHP version 3: Required PHP version */ | |
| 46 | - 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' ), | |
| 47 | - esc_html( POLYLANG ), | |
| 48 | - PHP_VERSION, | |
| 49 | - esc_html( PLL_MIN_PHP_VERSION ) | |
| 50 | - ) | |
| 51 | - ); | |
| 52 | - } | |
| 53 | - | |
| 54 | - /** | |
| 55 | - * Displays a notice if WP min version is not met. | |
| 56 | - * | |
| 57 | - * @since 2.6.7 | |
| 58 | - */ | |
| 59 | - public function wp_version_notice() { | |
| 60 | - global $wp_version; | |
| 61 | - | |
| 62 | - load_plugin_textdomain( 'polylang' ); // Plugin i18n. | |
| 63 | - | |
| 64 | - printf( | |
| 65 | - '<div class="error"><p>%s</p></div>', | |
| 66 | - sprintf( | |
| 67 | - /* translators: 1: Plugin name 2: Current WordPress version 3: Required WordPress version */ | |
| 68 | - 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' ), | |
| 69 | - esc_html( POLYLANG ), | |
| 70 | - esc_html( $wp_version ), | |
| 71 | - esc_html( PLL_MIN_WP_VERSION ) | |
| 72 | - ) | |
| 73 | - ); | |
| 74 | - } | |
| 75 | - | |
| 76 | - /** | |
| 77 | - * Get default Polylang options | |
| 78 | - * | |
| 79 | 37 | * @since 1.8 |
| 80 | 38 | * |
| 81 | 39 | * return array |
| 82 | 40 | */ |
| 83 | - public static function get_default_options() { | |
| 41 | + static public function get_default_options() { | |
| 84 | 42 | return array( |
| 85 | - 'browser' => 1, // Default language for the front page is set by browser preference | |
| 86 | - 'rewrite' => 1, // Remove /language/ in permalinks ( was the opposite before 0.7.2 ) | |
| 87 | - 'hide_default' => 1, // Remove URL language information for default language ( was the opposite before 2.1.5 ) | |
| 88 | - 'force_lang' => 1, // Add URL language information ( was 0 before 1.7 ) | |
| 89 | - 'redirect_lang' => 0, // Do not redirect the language page to the homepage | |
| 90 | - 'media_support' => 1, // Support languages and translation for media by default | |
| 91 | - 'uninstall' => 0, // Do not remove data when uninstalling Polylang | |
| 92 | - 'sync' => array(), // Synchronisation is disabled by default ( was the opposite before 1.2 ) | |
| 93 | - 'post_types' => array(), | |
| 94 | - 'taxonomies' => array(), | |
| 95 | - 'domains' => array(), | |
| 96 | - 'version' => POLYLANG_VERSION, | |
| 97 | - 'first_activation' => time(), | |
| 43 | + 'browser' => 1, // default language for the front page is set by browser preference | |
| 44 | + 'rewrite' => 1, // remove /language/ in permalinks ( was the opposite before 0.7.2 ) | |
| 45 | + 'hide_default' => 0, // do not remove URL language information for default language | |
| 46 | + 'force_lang' => 1, // add URL language information ( was 0 before 1.7 ) | |
| 47 | + 'redirect_lang' => 0, // do not redirect the language page to the homepage | |
| 48 | + 'media_support' => 1, // support languages and translation for media by default | |
| 49 | + 'uninstall' => 0, // do not remove data when uninstalling Polylang | |
| 50 | + 'sync' => array(), // synchronisation is disabled by default ( was the opposite before 1.2 ) | |
| 51 | + 'post_types' => array(), | |
| 52 | + 'taxonomies' => array(), | |
| 53 | + 'domains' => array(), | |
| 54 | + 'version' => POLYLANG_VERSION, | |
| 98 | 55 | ); |
| 99 | 56 | } |
| 100 | 57 | |
| 101 | 58 | /** |
| 102 | - * Plugin activation | |
| 59 | + * plugin activation | |
| 103 | 60 | * |
| 104 | 61 | * @since 0.5 |
| 105 | 62 | */ |
| 106 | 63 | protected function _activate() { |
| 107 | 64 | if ( $options = get_option( 'polylang' ) ) { |
| 108 | - // Check if we will be able to upgrade | |
| 65 | + // check if we will be able to upgrade | |
| 109 | 66 | if ( version_compare( $options['version'], POLYLANG_VERSION, '<' ) ) { |
| 110 | 67 | $upgrade = new PLL_Upgrade( $options ); |
| 111 | 68 | $upgrade->can_activate(); |
| 112 | 69 | } |
| 113 | 70 | } |
| 114 | - // Defines default values for options in case this is the first installation | |
| 71 | + // defines default values for options in case this is the first installation | |
| 115 | 72 | else { |
| 116 | 73 | update_option( 'polylang', self::get_default_options() ); |
| 117 | 74 | } |
| 118 | 75 | |
| 119 | - // Avoid 1 query on every pages if no wpml strings is registered | |
| 76 | + // avoid 1 query on every pages if no wpml strings is registered | |
| 120 | 77 | if ( ! get_option( 'polylang_wpml_strings' ) ) { |
| 121 | 78 | update_option( 'polylang_wpml_strings', array() ); |
| 122 | 79 | } |
| 123 | 80 | |
| 124 | - // Don't use flush_rewrite_rules at network activation. See #32471 | |
| 125 | - // Thanks to RavanH for the trick. See https://polylang.wordpress.com/2015/06/10/polylang-1-7-6-and-multisite/ | |
| 126 | - // Rewrite rules are created at next page load :) | |
| 81 | + // don't use flush_rewrite_rules at network activation. See #32471 | |
| 82 | + // thanks to RavanH for the trick. See https://polylang.wordpress.com/2015/06/10/polylang-1-7-6-and-multisite/ | |
| 83 | + // rewrite rules are created at next page load :) | |
| 127 | 84 | delete_option( 'rewrite_rules' ); |
| 128 | 85 | } |
| 129 | 86 | |
| 130 | 87 | /** |
| 131 | - * Plugin deactivation | |
| 88 | + * plugin deactivation | |
| 132 | 89 | * |
| 133 | 90 | * @since 0.5 |
| 134 | 91 | */ |
| 135 | 92 | protected function _deactivate() { |
| 136 | - delete_option( 'rewrite_rules' ); // Don't use flush_rewrite_rules at network activation. See #32471 | |
| 93 | + delete_option( 'rewrite_rules' ); // don't use flush_rewrite_rules at network activation. See #32471 | |
| 137 | 94 | } |
| 138 | 95 | } |