PluginProbe
Polylang / 2.0.5
Polylang v2.0.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 2.0.5, at include/base.php

126 lines 4.2 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 $GLOBALS['l10n_unloaded']['pll_string'] = true; // Short-circuit _load_textdomain_just_in_time() for 'pll_string' domain in WP 4.6+
24
25 add_action( 'widgets_init', array( $this, 'widgets_init' ) );
26
27 // User defined strings translations
28 add_action( 'pll_language_defined', array( $this, 'load_strings_translations' ), 5 );
29
30 // Switch_to_blog
31 add_action( 'switch_blog', array( $this, 'switch_blog' ), 10, 2 );
32 }
33
34 /**
35 * Registers our widgets
36 *
37 * @since 0.1
38 */
39 public function widgets_init() {
40 register_widget( 'PLL_Widget_Languages' );
41
42 // Overwrites the calendar widget to filter posts by language
43 if ( ! defined( 'PLL_WIDGET_CALENDAR' ) || PLL_WIDGET_CALENDAR ) {
44 unregister_widget( 'WP_Widget_Calendar' );
45 register_widget( 'PLL_Widget_Calendar' );
46 }
47
48 // Backward compatibility with WP < 4.4
49 // Overwrites the recent posts and recent comments widget to use a language dependant cache key
50 // Useful only if using a cache plugin
51 if ( version_compare( $GLOBALS['wp_version'], '4.4', '<' ) && defined( 'WP_CACHE' ) && WP_CACHE ) {
52 if ( ! defined( 'PLL_WIDGET_RECENT_POSTS' ) || PLL_WIDGET_RECENT_POSTS ) {
53 unregister_widget( 'WP_Widget_Recent_Posts' );
54 register_widget( 'PLL_Widget_Recent_Posts' );
55 }
56
57 if ( ! defined( 'PLL_WIDGET_RECENT_COMMENTS' ) || PLL_WIDGET_RECENT_COMMENTS ) {
58 unregister_widget( 'WP_Widget_Recent_Comments' );
59 register_widget( 'PLL_Widget_Recent_Comments' );
60 }
61 }
62 }
63
64 /**
65 * Loads user defined strings translations
66 *
67 * @since 1.2
68 */
69 public function load_strings_translations() {
70 $mo = new PLL_MO();
71 $mo->import_from_db( $this->model->get_language( get_locale() ) );
72 $GLOBALS['l10n']['pll_string'] = &$mo;
73 }
74
75 /**
76 * Resets some variables when switching blog
77 * Applies only if Polylang is active on the new blog
78 *
79 * @since 1.5.1
80 *
81 * @return bool not used by WP but by child class
82 */
83 public function switch_blog( $new_blog, $old_blog ) {
84 $plugins = ( $sitewide_plugins = get_site_option( 'active_sitewide_plugins' ) ) && is_array( $sitewide_plugins ) ? array_keys( $sitewide_plugins ) : array();
85 $plugins = array_merge( $plugins, get_option( 'active_plugins', array() ) );
86
87 // 2nd test needed when Polylang is not networked activated
88 // 3rd test needed when Polylang is networked activated and a new site is created
89 if ( $new_blog != $old_blog && in_array( POLYLANG_BASENAME, $plugins ) && get_option( 'polylang' ) ) {
90 $this->options = get_option( 'polylang' ); // Needed for menus
91 $this->links_model = $this->model->get_links_model();
92 return true;
93 }
94 return false;
95 }
96
97 /**
98 * Some backward compatibility with Polylang < 1.2
99 * Allows for example to call $polylang->get_languages_list() instead of $polylang->model->get_languages_list()
100 * This works but should be slower than the direct call, thus an error is triggered in debug mode
101 *
102 * @since 1.2
103 *
104 * @param string $func function name
105 * @param array $args function arguments
106 */
107 public function __call( $func, $args ) {
108 foreach ( $this as $prop => &$obj ) {
109 if ( is_object( $obj ) && method_exists( $obj, $func ) ) {
110 if ( WP_DEBUG ) {
111 $debug = debug_backtrace();
112 $i = 1 + empty( $debug[1]['line'] ); // The file and line are in $debug[2] if the function was called using call_user_func
113 trigger_error( sprintf(
114 '%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",
115 $func, $prop, $debug[ $i ]['file'], $debug[ $i ]['line']
116 ) );
117 }
118 return call_user_func_array( array( $obj, $func ), $args );
119 }
120 }
121
122 $debug = debug_backtrace();
123 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 );
124 }
125 }
126