PluginProbe
Polylang / 1.5
Polylang v1.5
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 / include / base.php

base.php in Polylang 1.5, at include/base.php

96 lines 2.8 KB
No matching file
Up and down to move Enter to open Esc to close
Raw Download Zip
1 <?php
2
3 /*
4 * base class for both admin and frontend
5 *
6 * @since 1.2
7 */
8 abstract class PLL_Base {
9 public $links_model, $model, $options;
10
11 /*
12 * constructor
13 *
14 * @since 1.2
15 *
16 * @param object $links_model
17 */
18 public function __construct(&$links_model) {
19 $this->links_model = &$links_model;
20 $this->model = &$links_model->model;
21 $this->options = &$this->model->options;
22
23 add_action('widgets_init', array(&$this, 'widgets_init'));
24
25 // user defined strings translations
26 add_action('pll_language_defined', array(&$this, 'load_strings_translations'), 5);
27 }
28
29 /*
30 * registers our widgets
31 *
32 * @since 0.1
33 */
34 public function widgets_init() {
35 register_widget('PLL_Widget_Languages');
36
37 // overwrites the calendar widget to filter posts by language
38 if (!defined('PLL_WIDGET_CALENDAR') || PLL_WIDGET_CALENDAR) {
39 unregister_widget('WP_Widget_Calendar');
40 register_widget('PLL_Widget_Calendar');
41 }
42
43 // overwrites the recent posts and recent comments widget to use a language dependant cache key
44 // useful only if using a cache plugin
45 if (defined('WP_CACHE') && WP_CACHE) {
46 if (!defined('PLL_WIDGET_RECENT_POSTS') || PLL_WIDGET_RECENT_POSTS) {
47 unregister_widget('WP_Widget_Recent_Posts');
48 register_widget('PLL_Widget_Recent_Posts');
49 }
50
51 if (!defined('PLL_WIDGET_RECENT_COMMENTS') || PLL_WIDGET_RECENT_COMMENTS) {
52 unregister_widget('WP_Widget_Recent_Comments');
53 register_widget('PLL_Widget_Recent_Comments');
54 }
55 }
56 }
57
58 /*
59 * loads user defined strings translations
60 *
61 * @since 1.2
62 */
63 public function load_strings_translations() {
64 $mo = new PLL_MO();
65 $mo->import_from_db($this->model->get_language(get_locale()));
66 $GLOBALS['l10n']['pll_string'] = &$mo;
67 }
68
69 /*
70 * some backward compatibility with Polylang < 1.2
71 * allows for example to call $polylang->get_languages_list() instead of $polylang->model->get_languages_list()
72 * this works but should be slower than the direct call, thus an error is triggered in debug mode
73 *
74 * @since 1.2
75 *
76 * @param string $func function name
77 * @param array $args function arguments
78 */
79 public function __call($func, $args) {
80 foreach ($this as $prop => &$obj)
81 if (is_object($obj) && method_exists($obj, $func)) {
82 if (WP_DEBUG) {
83 $debug = debug_backtrace();
84 trigger_error(sprintf(
85 '%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",
86 $func, $prop, $debug[1]['file'], $debug[1]['line']
87 ));
88 }
89 return call_user_func_array(array($obj, $func), $args);
90 }
91
92 $debug = debug_backtrace();
93 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);
94 }
95 }
96