| 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 |
public function activate( $networkwide ) { |
| 16 |
global $wp_version; |
| 17 |
|
| 18 |
Polylang::define_constants(); |
| 19 |
|
| 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 |
) ); |
| 30 |
} |
| 31 |
$this->do_for_all_blogs( 'activate', $networkwide ); |
| 32 |
} |
| 33 |
|
| 34 |
/** |
| 35 |
* get default Polylang options |
| 36 |
* |
| 37 |
* @since 1.8 |
| 38 |
* |
| 39 |
* return array |
| 40 |
*/ |
| 41 |
static public function get_default_options() { |
| 42 |
return array( |
| 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' => 1, // Remove URL language information for default language ( was the opposite before 2.1.5 ) |
| 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, |
| 55 |
); |
| 56 |
} |
| 57 |
|
| 58 |
/** |
| 59 |
* plugin activation |
| 60 |
* |
| 61 |
* @since 0.5 |
| 62 |
*/ |
| 63 |
protected function _activate() { |
| 64 |
if ( $options = get_option( 'polylang' ) ) { |
| 65 |
// check if we will be able to upgrade |
| 66 |
if ( version_compare( $options['version'], POLYLANG_VERSION, '<' ) ) { |
| 67 |
$upgrade = new PLL_Upgrade( $options ); |
| 68 |
$upgrade->can_activate(); |
| 69 |
} |
| 70 |
} |
| 71 |
// defines default values for options in case this is the first installation |
| 72 |
else { |
| 73 |
update_option( 'polylang', self::get_default_options() ); |
| 74 |
} |
| 75 |
|
| 76 |
// avoid 1 query on every pages if no wpml strings is registered |
| 77 |
if ( ! get_option( 'polylang_wpml_strings' ) ) { |
| 78 |
update_option( 'polylang_wpml_strings', array() ); |
| 79 |
} |
| 80 |
|
| 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 :) |
| 84 |
delete_option( 'rewrite_rules' ); |
| 85 |
} |
| 86 |
|
| 87 |
/** |
| 88 |
* plugin deactivation |
| 89 |
* |
| 90 |
* @since 0.5 |
| 91 |
*/ |
| 92 |
protected function _deactivate() { |
| 93 |
delete_option( 'rewrite_rules' ); // don't use flush_rewrite_rules at network activation. See #32471 |
| 94 |
} |
| 95 |
} |
| 96 |
|