| 1 |
<?php |
| 2 |
|
| 3 |
/** |
| 4 |
* Polylang activation / de-activation class |
| 5 |
* |
| 6 |
* @since 1.7 |
| 7 |
*/ |
| 8 |
class PLL_Install extends PLL_Install_Base { |
| 9 |
|
| 10 |
/** |
| 11 |
* Plugin activation for multisite |
| 12 |
* |
| 13 |
* @since 0.1 |
| 14 |
* |
| 15 |
* @param bool $networkwide |
| 16 |
*/ |
| 17 |
public function activate( $networkwide ) { |
| 18 |
global $wp_version; |
| 19 |
|
| 20 |
Polylang::define_constants(); |
| 21 |
|
| 22 |
load_plugin_textdomain( 'polylang', false, basename( POLYLANG_DIR ) . '/languages' ); // plugin i18n |
| 23 |
|
| 24 |
if ( version_compare( $wp_version, PLL_MIN_WP_VERSION, '<' ) ) { |
| 25 |
die( sprintf( '<p style = "font-family: sans-serif; font-size: 12px; color: #333; margin: -5px">%s</p>', |
| 26 |
/* translators: %1$s and %2$s are WordPress version numbers */ |
| 27 |
sprintf( esc_html__( 'You are using WordPress %1$s. Polylang requires at least WordPress %2$s.', 'polylang' ), |
| 28 |
esc_html( $wp_version ), |
| 29 |
PLL_MIN_WP_VERSION |
| 30 |
) |
| 31 |
) ); |
| 32 |
} |
| 33 |
$this->do_for_all_blogs( 'activate', $networkwide ); |
| 34 |
} |
| 35 |
|
| 36 |
/** |
| 37 |
* Get default Polylang options |
| 38 |
* |
| 39 |
* @since 1.8 |
| 40 |
* |
| 41 |
* return array |
| 42 |
*/ |
| 43 |
static public function get_default_options() { |
| 44 |
return array( |
| 45 |
'browser' => 1, // Default language for the front page is set by browser preference |
| 46 |
'rewrite' => 1, // Remove /language/ in permalinks ( was the opposite before 0.7.2 ) |
| 47 |
'hide_default' => 1, // Remove URL language information for default language ( was the opposite before 2.1.5 ) |
| 48 |
'force_lang' => 1, // Add URL language information ( was 0 before 1.7 ) |
| 49 |
'redirect_lang' => 0, // Do not redirect the language page to the homepage |
| 50 |
'media_support' => 1, // Support languages and translation for media by default |
| 51 |
'uninstall' => 0, // Do not remove data when uninstalling Polylang |
| 52 |
'sync' => array(), // Synchronisation is disabled by default ( was the opposite before 1.2 ) |
| 53 |
'post_types' => array(), |
| 54 |
'taxonomies' => array(), |
| 55 |
'domains' => array(), |
| 56 |
'version' => POLYLANG_VERSION, |
| 57 |
'first_activation' => time(), |
| 58 |
); |
| 59 |
} |
| 60 |
|
| 61 |
/** |
| 62 |
* Plugin activation |
| 63 |
* |
| 64 |
* @since 0.5 |
| 65 |
*/ |
| 66 |
protected function _activate() { |
| 67 |
if ( $options = get_option( 'polylang' ) ) { |
| 68 |
// Check if we will be able to upgrade |
| 69 |
if ( version_compare( $options['version'], POLYLANG_VERSION, '<' ) ) { |
| 70 |
$upgrade = new PLL_Upgrade( $options ); |
| 71 |
$upgrade->can_activate(); |
| 72 |
} |
| 73 |
} |
| 74 |
// Defines default values for options in case this is the first installation |
| 75 |
else { |
| 76 |
update_option( 'polylang', self::get_default_options() ); |
| 77 |
} |
| 78 |
|
| 79 |
// Avoid 1 query on every pages if no wpml strings is registered |
| 80 |
if ( ! get_option( 'polylang_wpml_strings' ) ) { |
| 81 |
update_option( 'polylang_wpml_strings', array() ); |
| 82 |
} |
| 83 |
|
| 84 |
// Don't use flush_rewrite_rules at network activation. See #32471 |
| 85 |
// Thanks to RavanH for the trick. See https://polylang.wordpress.com/2015/06/10/polylang-1-7-6-and-multisite/ |
| 86 |
// Rewrite rules are created at next page load :) |
| 87 |
delete_option( 'rewrite_rules' ); |
| 88 |
} |
| 89 |
|
| 90 |
/** |
| 91 |
* Plugin deactivation |
| 92 |
* |
| 93 |
* @since 0.5 |
| 94 |
*/ |
| 95 |
protected function _deactivate() { |
| 96 |
delete_option( 'rewrite_rules' ); // Don't use flush_rewrite_rules at network activation. See #32471 |
| 97 |
} |
| 98 |
} |
| 99 |
|