PluginProbe
Polylang / 3.3
Polylang v3.3
3.8.9 3.8.8 3.8.7 3.8.6 3.8.5 3.8.4 3.8.3 2.7 2.7.0.1 2.7.1 2.7.2 2.7.3 2.7.4 2.8 2.8.1 2.8.2 2.8.3 2.8.4 2.9 2.9.1 2.9.2 3.0 3.0.1 3.0.2 3.0.3 All 233 releases
polylang / install / install.php

install.php in Polylang 3.3, at install/install.php

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