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