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