PluginProbe
Polylang / 3.6.7
Polylang v3.6.7
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 | admin/admin.php +88 -32 2.83.6.7 View file →
@@ -3,44 +3,71 @@
3 3 * @package Polylang
4 4 */
5 5
6 6 /**
7 - * Admin side controller
8 - * accessible in $polylang global object
7 + * Main Polylang class for admin (except Polylang pages), accessible from @see PLL().
9 8 *
10 - * Properties:
11 - * options => inherited, reference to Polylang options array
12 - * model => inherited, reference to PLL_Model object
13 - * links_model => inherited, reference to PLL_Links_Model object
14 - * links => inherited, reference to PLL_Admin_Links object
15 - * static_pages => inherited, reference to PLL_Admin_Static_Pages object
16 - * filters_links => inherited, reference to PLL_Filters_Links object
17 - * curlang => inherited, optional, current language used to filter the content (language of the post or term being edited, equal to filter_lang otherwise)
18 - * filter_lang => inherited, optional, current status of the admin languages filter (in the admin bar)
19 - * pref_lang => inherited, preferred language used as default when saving posts or terms
20 - * posts => reference to PLL_CRUD_Posts object
21 - * terms => reference to PLL_CRUD_Terms object
22 - * filters => reference to PLL_Admin_Filters object
23 - * filters_columns => reference to PLL_Admin_Filters_Columns object
24 - * filters_post => reference to PLL_Admin_Filters_Post object
25 - * filters_term => reference to PLL_Admin_filters_Term object
26 - * nav_menu => reference to PLL_Admin_Nav_Menu object
27 - * block_editor => reference to PLL_Admin_Block_Editor object
28 - * classic_editor => reference to PLL_Admin_Classic_Editor object
29 - * filters_media => optional, reference to PLL_Admin_Filters_Media object
30 - *
31 9 * @since 1.2
32 10 */
33 11 class PLL_Admin extends PLL_Admin_Base {
34 - public $filters, $filters_columns, $filters_post, $filters_term, $nav_menu, $filters_media;
12 + /**
13 + * @var PLL_Admin_Filters|null
14 + */
15 + public $filters;
35 16
36 17 /**
37 - * Loads the polylang text domain
38 - * Setups filters and action needed on all admin pages and on plugins page
18 + * @var PLL_Admin_Filters_Columns|null
19 + */
20 + public $filters_columns;
21 +
22 + /**
23 + * @var PLL_Admin_Filters_Post|null
24 + */
25 + public $filters_post;
26 +
27 + /**
28 + * @var PLL_Admin_Filters_Term|null
29 + */
30 + public $filters_term;
31 +
32 + /**
33 + * @var PLL_Admin_Filters_Media|null
34 + */
35 + public $filters_media;
36 +
37 + /**
38 + * @since 2.9
39 39 *
40 + * @var PLL_Filters_Sanitization|null
41 + */
42 + public $filters_sanitization;
43 +
44 + /**
45 + * @var PLL_Admin_Block_Editor|null
46 + */
47 + public $block_editor;
48 +
49 + /**
50 + * @var PLL_Admin_Classic_Editor|null
51 + */
52 + public $classic_editor;
53 +
54 + /**
55 + * @var PLL_Admin_Nav_Menu|null
56 + */
57 + public $nav_menu;
58 +
59 + /**
60 + * @var PLL_Admin_Filters_Widgets_Options|null
61 + */
62 + public $filters_widgets_options;
63 +
64 + /**
65 + * Setups filters and action needed on all admin pages and on plugins page.
66 + *
40 67 * @since 1.2
41 68 *
42 - * @param object $links_model
69 + * @param PLL_Links_Model $links_model Reference to the links model.
43 70 */
44 71 public function __construct( &$links_model ) {
45 72 parent::__construct( $links_model );
46 73
@@ -59,20 +86,20 @@
59 86 parent::init();
60 87
61 88 // Setup filters for admin pages
62 89 // Priority 5 to make sure filters are there before customize_register is fired
63 - if ( $this->model->get_languages_list() ) {
90 + if ( $this->model->has_languages() ) {
64 91 add_action( 'wp_loaded', array( $this, 'add_filters' ), 5 );
65 92 }
66 93 }
67 94
68 95 /**
69 - * Adds a 'settings' link in the plugins table
96 + * Adds a 'settings' link for our plugin in the plugins list table.
70 97 *
71 98 * @since 0.1
72 99 *
73 - * @param array $links list of links associated to the plugin
74 - * @return array modified list of links
100 + * @param string[] $links List of links associated to the plugin.
101 + * @return string[] Modified list of links.
75 102 */
76 103 public function plugin_action_links( $links ) {
77 104 array_unshift( $links, '<a href="admin.php?page=mlang">' . __( 'Settings', 'polylang' ) . '</a>' );
78 105 return $links;
@@ -84,11 +111,12 @@
84 111 * @since 1.1.6
85 112 *
86 113 * @param array $plugin_data Not used
87 114 * @param object $r Plugin update data
115 + * @return void
88 116 */
89 117 public function plugin_update_message( $plugin_data, $r ) {
90 - if ( isset( $r->upgrade_notice ) ) {
118 + if ( ! empty( $r->upgrade_notice ) ) {
91 119 printf( '<p style="margin: 3px 0 0 0; border-top: 1px solid #ddd; padding-top: 3px">%s</p>', esc_html( $r->upgrade_notice ) );
92 120 }
93 121 }
94 122
@@ -96,10 +124,14 @@
96 124 * Setup filters for admin pages
97 125 *
98 126 * @since 1.2
99 127 * @since 2.7 instantiate a PLL_Bulk_Translate instance.
128 + * @return void
100 129 */
101 130 public function add_filters() {
131 + $this->filters_sanitization = new PLL_Filters_Sanitization( $this->get_locale_for_sanitization() );
132 + $this->filters_widgets_options = new PLL_Admin_Filters_Widgets_Options( $this );
133 +
102 134 // All these are separated just for convenience and maintainability
103 135 $classes = array( 'Filters', 'Filters_Columns', 'Filters_Post', 'Filters_Term', 'Nav_Menu', 'Classic_Editor', 'Block_Editor' );
104 136
105 137 // Don't load media filters if option is disabled or if user has no right
@@ -119,6 +151,30 @@
119 151 */
120 152 $class = apply_filters( 'pll_' . $obj, 'PLL_Admin_' . $class );
121 153 $this->$obj = new $class( $this );
122 154 }
155 + }
156 +
157 + /**
158 + * Retrieve the locale according to the current language instead of the language
159 + * of the admin interface.
160 + *
161 + * @since 2.0
162 + *
163 + * @return string
164 + */
165 + public function get_locale_for_sanitization() {
166 + $locale = get_locale();
167 +
168 + if ( isset( $_POST['post_lang_choice'] ) && $lang = $this->model->get_language( sanitize_key( $_POST['post_lang_choice'] ) ) ) { // phpcs:ignore WordPress.Security.NonceVerification
169 + $locale = $lang->locale;
170 + } elseif ( isset( $_POST['term_lang_choice'] ) && $lang = $this->model->get_language( sanitize_key( $_POST['term_lang_choice'] ) ) ) { // phpcs:ignore WordPress.Security.NonceVerification
171 + $locale = $lang->locale;
172 + } elseif ( isset( $_POST['inline_lang_choice'] ) && $lang = $this->model->get_language( sanitize_key( $_POST['inline_lang_choice'] ) ) ) { // phpcs:ignore WordPress.Security.NonceVerification
173 + $locale = $lang->locale;
174 + } elseif ( ! empty( $this->curlang ) ) {
175 + $locale = $this->curlang->locale;
176 + }
177 +
178 + return $locale;
123 179 }
124 180 }