PluginProbe
Polylang / 3.1.4
Polylang v3.1.4
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
← All changes | include/base.php +34 -59 2.93.1.4 View file →
@@ -16,10 +16,8 @@
16 16 */
17 17 public $options;
18 18
19 19 /**
20 - * Instance of PLL_Model.
21 - *
22 20 * @var PLL_Model
23 21 */
24 22 public $model;
25 23
@@ -44,13 +42,13 @@
44 42 */
45 43 public $terms;
46 44
47 45 /**
48 - * Constructor
46 + * Constructor.
49 47 *
50 48 * @since 1.2
51 49 *
52 - * @param object $links_model
50 + * @param PLL_Links_Model $links_model Links Model.
53 51 */
54 52 public function __construct( &$links_model ) {
55 53 $this->links_model = &$links_model;
56 54 $this->model = &$links_model->model;
@@ -62,8 +60,9 @@
62 60
63 61 // User defined strings translations
64 62 add_action( 'pll_language_defined', array( $this, 'load_strings_translations' ), 5 );
65 63 add_action( 'change_locale', array( $this, 'load_strings_translations' ) ); // Since WP 4.7
64 + add_action( 'personal_options_update', array( $this, 'load_strings_translations' ), 1, 0 ); // Before WP, for confirmation request when changing the user email.
66 65
67 66 // Switch_to_blog
68 67 add_action( 'switch_blog', array( $this, 'switch_blog' ), 10, 2 );
69 68 }
@@ -72,8 +71,10 @@
72 71 * Instantiates classes reacting to CRUD operations on posts and terms,
73 72 * only when at least one language is defined.
74 73 *
75 74 * @since 2.6
75 + *
76 + * @return void
76 77 */
77 78 public function init() {
78 79 if ( $this->model->get_languages_list() ) {
79 80 $this->posts = new PLL_CRUD_Posts( $this );
@@ -79,12 +80,12 @@
79 80 $this->posts = new PLL_CRUD_Posts( $this );
80 81 $this->terms = new PLL_CRUD_Terms( $this );
81 82
82 83 // WordPress options.
83 - new PLL_Translate_Option( 'blogname', array(), array( 'context' => 'WorPress' ) );
84 - new PLL_Translate_Option( 'blogdescription', array(), array( 'context' => 'WorPress' ) );
85 - new PLL_Translate_Option( 'date_format', array(), array( 'context' => 'WorPress' ) );
86 - new PLL_Translate_Option( 'time_format', array(), array( 'context' => 'WorPress' ) );
84 + new PLL_Translate_Option( 'blogname', array(), array( 'context' => 'WordPress' ) );
85 + new PLL_Translate_Option( 'blogdescription', array(), array( 'context' => 'WordPress' ) );
86 + new PLL_Translate_Option( 'date_format', array(), array( 'context' => 'WordPress' ) );
87 + new PLL_Translate_Option( 'time_format', array(), array( 'context' => 'WordPress' ) );
87 88 }
88 89 }
89 90
90 91 /**
@@ -90,8 +91,10 @@
90 91 /**
91 92 * Registers our widgets
92 93 *
93 94 * @since 0.1
95 + *
96 + * @return void
94 97 */
95 98 public function widgets_init() {
96 99 register_widget( 'PLL_Widget_Languages' );
97 100
@@ -108,12 +111,13 @@
108 111 * @since 1.2
109 112 * @since 2.1.3 $locale parameter added.
110 113 *
111 114 * @param string $locale Locale. Defaults to current locale.
115 + * @return void
112 116 */
113 117 public function load_strings_translations( $locale = '' ) {
114 118 if ( empty( $locale ) ) {
115 - $locale = get_locale();
119 + $locale = ( is_admin() && ! Polylang::is_ajax_on_front() ) ? get_user_locale() : get_locale();
116 120 }
117 121
118 122 $language = $this->model->get_language( $locale );
119 123
@@ -126,70 +130,41 @@
126 130 }
127 131 }
128 132
129 133 /**
130 - * Resets some variables when switching blog
131 - * Applies only if Polylang is active on the new blog
134 + * Resets some variables when the blog is switched.
135 + * Applied only if Polylang is active on the new blog.
132 136 *
133 137 * @since 1.5.1
134 138 *
135 - * @param int $new_blog
136 - * @param int $old_blog
137 - * @return bool not used by WP but by child class
139 + * @param int $new_blog_id New blog ID.
140 + * @param int $prev_blog_id Previous blog ID.
141 + * @return void
138 142 */
139 - public function switch_blog( $new_blog, $old_blog ) {
140 - $plugins = ( $sitewide_plugins = get_site_option( 'active_sitewide_plugins' ) ) && is_array( $sitewide_plugins ) ? array_keys( $sitewide_plugins ) : array();
141 - $plugins = array_merge( $plugins, get_option( 'active_plugins', array() ) );
142 -
143 - // 2nd test needed when Polylang is not networked activated
144 - // 3rd test needed when Polylang is networked activated and a new site is created
145 - if ( $new_blog != $old_blog && in_array( POLYLANG_BASENAME, $plugins ) && get_option( 'polylang' ) ) {
146 - $this->options = get_option( 'polylang' ); // Needed for menus
143 + public function switch_blog( $new_blog_id, $prev_blog_id ) {
144 + if ( $this->is_active_on_new_blog( $new_blog_id, $prev_blog_id ) ) {
145 + $this->options = get_option( 'polylang' ); // Needed for menus.
147 146 remove_action( 'pre_option_rewrite_rules', array( $this->links_model, 'prepare_rewrite_rules' ) );
148 147 $this->links_model = $this->model->get_links_model();
149 - return true;
150 148 }
151 - return false;
152 149 }
153 150
154 151 /**
155 - * Some backward compatibility with Polylang < 1.2
156 - * Allows for example to call $polylang->get_languages_list() instead of $polylang->model->get_languages_list()
157 - * This works but should be slower than the direct call, thus an error is triggered in debug mode
152 + * Checks if Polylang is active on the new blog when the blog is switched.
158 153 *
159 - * @since 1.2
154 + * @since 3.0
160 155 *
161 - * @param string $func function name
162 - * @param array $args function arguments
156 + * @param int $new_blog_id New blog ID.
157 + * @param int $prev_blog_id Previous blog ID.
158 + * @return bool
163 159 */
164 - public function __call( $func, $args ) {
165 - foreach ( $this as $prop => &$obj ) {
166 - if ( is_object( $obj ) && method_exists( $obj, $func ) ) {
167 - if ( WP_DEBUG ) {
168 - $debug = debug_backtrace( DEBUG_BACKTRACE_IGNORE_ARGS ); // phpcs:ignore WordPress.PHP.DevelopmentFunctions
169 - $i = 1 + empty( $debug[1]['line'] ); // The file and line are in $debug[2] if the function was called using call_user_func
170 - trigger_error( // phpcs:ignore WordPress.PHP.DevelopmentFunctions
171 - sprintf(
172 - '%1$s was called incorrectly in %3$s on line %4$s: the call to $polylang->%1$s() has been deprecated in Polylang 1.2, use PLL()->%2$s->%1$s() instead.' . "\nError handler",
173 - esc_html( $func ),
174 - esc_html( $prop ),
175 - esc_html( $debug[ $i ]['file'] ),
176 - absint( $debug[ $i ]['line'] )
177 - )
178 - );
179 - }
180 - return call_user_func_array( array( $obj, $func ), $args );
181 - }
182 - }
160 + protected function is_active_on_new_blog( $new_blog_id, $prev_blog_id ) {
161 + $plugins = ( $sitewide_plugins = get_site_option( 'active_sitewide_plugins' ) ) && is_array( $sitewide_plugins ) ? array_keys( $sitewide_plugins ) : array();
162 + $plugins = array_merge( $plugins, get_option( 'active_plugins', array() ) );
183 163
184 - $debug = debug_backtrace( DEBUG_BACKTRACE_IGNORE_ARGS ); // phpcs:ignore WordPress.PHP.DevelopmentFunctions
185 - trigger_error( // phpcs:ignore WordPress.PHP.DevelopmentFunctions
186 - sprintf(
187 - 'Call to undefined function PLL()->%1$s() in %2$s on line %3$s' . "\nError handler",
188 - esc_html( $func ),
189 - esc_html( $debug[0]['file'] ),
190 - absint( $debug[0]['line'] )
191 - ),
192 - E_USER_ERROR
193 - );
164 + /*
165 + * The 2nd test is needed when Polylang is not networked activated.
166 + * The 3rd test is needed when Polylang is networked activated and a new site is created.
167 + */
168 + return $new_blog_id !== $prev_blog_id && in_array( POLYLANG_BASENAME, $plugins ) && get_option( 'polylang' );
194 169 }
195 170 }