PluginProbe
Polylang / 2.0.3
Polylang v2.0.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
← All changes | include/base.php +42 -108 2.8.32.0.3 View file →
@@ -1,53 +1,17 @@
1 1 <?php
2 -/**
3 - * @package Polylang
4 - */
5 2
6 3 /**
7 - * Base class for both admin and frontend
4 + * base class for both admin and frontend
8 5 *
9 6 * @since 1.2
10 7 */
11 8 abstract class PLL_Base {
12 - /**
13 - * Stores the plugin options.
14 - *
15 - * @var array
16 - */
17 - public $options;
9 + public $links_model, $model, $options;
18 10
19 11 /**
20 - * Instance of PLL_Model.
12 + * constructor
21 13 *
22 - * @var PLL_Model
23 - */
24 - public $model;
25 -
26 - /**
27 - * Instance of a child class of PLL_Links_Model.
28 - *
29 - * @var PLL_Links_Model
30 - */
31 - public $links_model;
32 -
33 - /**
34 - * Registers hooks on insert / update post related actions and filters.
35 - *
36 - * @var PLL_CRUD_Posts
37 - */
38 - public $posts;
39 -
40 - /**
41 - * Registers hooks on insert / update term related action and filters.
42 - *
43 - * @var PLL_CRUD_Terms
44 - */
45 - public $terms;
46 -
47 - /**
48 - * Constructor
49 - *
50 14 * @since 1.2
51 15 *
52 16 * @param object $links_model
53 17 */
@@ -55,80 +19,64 @@
55 19 $this->links_model = &$links_model;
56 20 $this->model = &$links_model->model;
57 21 $this->options = &$this->model->options;
58 22
59 - $GLOBALS['l10n_unloaded']['pll_string'] = true; // Short-circuit _load_textdomain_just_in_time() for 'pll_string' domain in WP 4.6+
60 -
61 23 add_action( 'widgets_init', array( $this, 'widgets_init' ) );
62 24
63 - // User defined strings translations
25 + // user defined strings translations
64 26 add_action( 'pll_language_defined', array( $this, 'load_strings_translations' ), 5 );
65 - add_action( 'change_locale', array( $this, 'load_strings_translations' ) ); // Since WP 4.7
66 27
67 - // Switch_to_blog
28 + // switch_to_blog
68 29 add_action( 'switch_blog', array( $this, 'switch_blog' ), 10, 2 );
69 30 }
70 31
71 32 /**
72 - * Instantiates classes reacting to CRUD operations on posts and terms,
73 - * only when at least one language is defined.
33 + * registers our widgets
74 34 *
75 - * @since 2.6
76 - */
77 - public function init() {
78 - if ( $this->model->get_languages_list() ) {
79 - $this->posts = new PLL_CRUD_Posts( $this );
80 - $this->terms = new PLL_CRUD_Terms( $this );
81 - }
82 - }
83 -
84 - /**
85 - * Registers our widgets
86 - *
87 35 * @since 0.1
88 36 */
89 37 public function widgets_init() {
90 38 register_widget( 'PLL_Widget_Languages' );
91 39
92 - // Overwrites the calendar widget to filter posts by language
40 + // overwrites the calendar widget to filter posts by language
93 41 if ( ! defined( 'PLL_WIDGET_CALENDAR' ) || PLL_WIDGET_CALENDAR ) {
94 42 unregister_widget( 'WP_Widget_Calendar' );
95 43 register_widget( 'PLL_Widget_Calendar' );
96 44 }
45 +
46 + // backward compatibility with WP < 4.4
47 + // overwrites the recent posts and recent comments widget to use a language dependant cache key
48 + // useful only if using a cache plugin
49 + if ( version_compare( $GLOBALS['wp_version'], '4.4', '<' ) && defined( 'WP_CACHE' ) && WP_CACHE ) {
50 + if ( ! defined( 'PLL_WIDGET_RECENT_POSTS' ) || PLL_WIDGET_RECENT_POSTS ) {
51 + unregister_widget( 'WP_Widget_Recent_Posts' );
52 + register_widget( 'PLL_Widget_Recent_Posts' );
53 + }
54 +
55 + if ( ! defined( 'PLL_WIDGET_RECENT_COMMENTS' ) || PLL_WIDGET_RECENT_COMMENTS ) {
56 + unregister_widget( 'WP_Widget_Recent_Comments' );
57 + register_widget( 'PLL_Widget_Recent_Comments' );
58 + }
59 + }
97 60 }
98 61
99 62 /**
100 - * Loads user defined strings translations
63 + * loads user defined strings translations
101 64 *
102 65 * @since 1.2
103 - * @since 2.1.3 $locale parameter added.
104 - *
105 - * @param string $locale Locale. Defaults to current locale.
106 66 */
107 - public function load_strings_translations( $locale = '' ) {
108 - if ( empty( $locale ) ) {
109 - $locale = get_locale();
110 - }
111 -
112 - $language = $this->model->get_language( $locale );
113 -
114 - if ( ! empty( $language ) ) {
115 - $mo = new PLL_MO();
116 - $mo->import_from_db( $language );
117 - $GLOBALS['l10n']['pll_string'] = &$mo;
118 - } else {
119 - unset( $GLOBALS['l10n']['pll_string'] );
120 - }
67 + public function load_strings_translations() {
68 + $mo = new PLL_MO();
69 + $mo->import_from_db( $this->model->get_language( get_locale() ) );
70 + $GLOBALS['l10n']['pll_string'] = &$mo;
121 71 }
122 72
123 73 /**
124 - * Resets some variables when switching blog
125 - * Applies only if Polylang is active on the new blog
74 + * resets some variables when switching blog
75 + * applies only if Polylang is active on the new blog
126 76 *
127 77 * @since 1.5.1
128 78 *
129 - * @param int $new_blog
130 - * @param int $old_blog
131 79 * @return bool not used by WP but by child class
132 80 */
133 81 public function switch_blog( $new_blog, $old_blog ) {
134 82 $plugins = ( $sitewide_plugins = get_site_option( 'active_sitewide_plugins' ) ) && is_array( $sitewide_plugins ) ? array_keys( $sitewide_plugins ) : array();
@@ -136,10 +84,9 @@
136 84
137 85 // 2nd test needed when Polylang is not networked activated
138 86 // 3rd test needed when Polylang is networked activated and a new site is created
139 87 if ( $new_blog != $old_blog && in_array( POLYLANG_BASENAME, $plugins ) && get_option( 'polylang' ) ) {
140 - $this->options = get_option( 'polylang' ); // Needed for menus
141 - remove_action( 'pre_option_rewrite_rules', array( $this->links_model, 'prepare_rewrite_rules' ) );
88 + $this->options = get_option( 'polylang' ); // needed for menus
142 89 $this->links_model = $this->model->get_links_model();
143 90 return true;
144 91 }
145 92 return false;
@@ -145,45 +92,32 @@
145 92 return false;
146 93 }
147 94
148 95 /**
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
96 + * some backward compatibility with Polylang < 1.2
97 + * allows for example to call $polylang->get_languages_list() instead of $polylang->model->get_languages_list()
98 + * this works but should be slower than the direct call, thus an error is triggered in debug mode
152 99 *
153 100 * @since 1.2
154 101 *
155 102 * @param string $func function name
156 - * @param array $args function arguments
103 + * @param array $args function arguments
157 104 */
158 105 public function __call( $func, $args ) {
159 106 foreach ( $this as $prop => &$obj ) {
160 107 if ( is_object( $obj ) && method_exists( $obj, $func ) ) {
161 108 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 - );
109 + $debug = debug_backtrace();
110 + $i = 1 + empty( $debug[1]['line'] ); // the file and line are in $debug[2] if the function was called using call_user_func
111 + trigger_error( sprintf(
112 + '%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",
113 + $func, $prop, $debug[ $i ]['file'], $debug[ $i ]['line']
114 + ) );
173 115 }
174 116 return call_user_func_array( array( $obj, $func ), $args );
175 117 }
176 118 }
177 119
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 - );
120 + $debug = debug_backtrace();
121 + trigger_error( sprintf( 'Call to undefined function PLL()->%1$s() in %2$s on line %3$s' . "\nError handler", $func, $debug[0]['file'], $debug[0]['line'] ), E_USER_ERROR );
188 122 }
189 123 }