PluginProbe
Polylang / 2.6.3
Polylang v2.6.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 | admin/admin-classic-editor.php +63 -114 3.02.6.3 View file →
@@ -1,8 +1,5 @@
1 1 <?php
2 -/**
3 - * @package Polylang
4 - */
5 2
6 3 /**
7 4 * Manages filters and actions related to the classic editor
8 5 *
@@ -8,33 +5,11 @@
8 5 *
9 6 * @since 2.4
10 7 */
11 8 class PLL_Admin_Classic_Editor {
12 - /**
13 - * @var PLL_Model
14 - */
15 - public $model;
9 + public $model, $links, $curlang, $pref_lang;
16 10
17 11 /**
18 - * @var PLL_Admin_Links
19 - */
20 - public $links;
21 -
22 - /**
23 - * Current language (used to filter the content).
24 - *
25 - * @var PLL_Language
26 - */
27 - public $curlang;
28 -
29 - /**
30 - * Preferred language to assign to new contents.
31 - *
32 - * @var PLL_Language
33 - */
34 - public $pref_lang;
35 -
36 - /**
37 12 * Constructor: setups filters and actions
38 13 *
39 14 * @since 2.4
40 15 *
@@ -46,9 +21,9 @@
46 21 $this->curlang = &$polylang->curlang;
47 22 $this->pref_lang = &$polylang->pref_lang;
48 23
49 24 // Adds the Languages box in the 'Edit Post' and 'Edit Page' panels
50 - add_action( 'add_meta_boxes', array( $this, 'add_meta_boxes' ) );
25 + add_action( 'add_meta_boxes', array( $this, 'add_meta_boxes' ), 10, 2 );
51 26
52 27 // Ajax response for changing the language in the post metabox
53 28 add_action( 'wp_ajax_post_lang_choice', array( $this, 'post_lang_choice' ) );
54 29 add_action( 'wp_ajax_pll_posts_not_translated', array( $this, 'ajax_posts_not_translated' ) );
@@ -65,11 +40,11 @@
65 40 *
66 41 * @since 0.1
67 42 *
68 43 * @param string $post_type Current post type
69 - * @return void
44 + * @param object $post Current post
70 45 */
71 - public function add_meta_boxes( $post_type ) {
46 + public function add_meta_boxes( $post_type, $post ) {
72 47 if ( $this->model->is_translated_post_type( $post_type ) ) {
73 48 add_meta_box(
74 49 'ml_box',
75 50 __( 'Languages', 'polylang' ),
@@ -87,17 +62,15 @@
87 62 /**
88 63 * Displays the Languages metabox in the 'Edit Post' and 'Edit Page' panels
89 64 *
90 65 * @since 0.1
91 - *
92 - * @return void
93 66 */
94 67 public function post_language() {
95 68 global $post_ID;
69 + $post_id = $post_ID;
96 70 $post_type = get_post_type( $post_ID );
97 71
98 - // phpcs:ignore WordPress.Security.NonceVerification, VariableAnalysis.CodeAnalysis.VariableAnalysis.UnusedVariable
99 - $from_post_id = isset( $_GET['from_post'] ) ? (int) $_GET['from_post'] : 0;
72 + $from_post_id = isset( $_GET['from_post'] ) ? (int) $_GET['from_post'] : 0; // phpcs:ignore WordPress.Security.NonceVerification
100 73
101 74 $lang = ( $lg = $this->model->post->get_language( $post_ID ) ) ? $lg :
102 75 ( isset( $_GET['new_lang'] ) ? $this->model->get_language( sanitize_key( $_GET['new_lang'] ) ) : // phpcs:ignore WordPress.Security.NonceVerification
103 76 $this->pref_lang );
@@ -107,9 +80,8 @@
107 80 $id = ( 'attachment' === $post_type ) ? sprintf( 'attachments[%d][language]', (int) $post_ID ) : 'post_lang_choice';
108 81
109 82 $dropdown_html = $dropdown->walk(
110 83 $this->model->get_languages_list(),
111 - -1,
112 84 array(
113 85 'name' => $id,
114 86 'class' => 'post_lang_choice tags-input',
115 87 'selected' => $lang ? $lang->slug : '',
@@ -138,13 +110,9 @@
138 110 do_action( 'pll_before_post_translations', $post_type );
139 111
140 112 echo '<div id="post-translations" class="translations">';
141 113 if ( $lang ) {
142 - if ( 'attachment' === $post_type ) {
143 - include __DIR__ . '/view-translations-media.php';
144 - } else {
145 - include __DIR__ . '/view-translations-post.php';
146 - }
114 + include PLL_ADMIN_INC . '/view-translations-' . ( 'attachment' == $post_type ? 'media' : 'post' ) . '.php';
147 115 }
148 116 echo '</div>' . "\n";
149 117 }
150 118
@@ -151,10 +119,8 @@
151 119 /**
152 120 * Ajax response for changing the language in the post metabox
153 121 *
154 122 * @since 0.2
155 - *
156 - * @return void
157 123 */
158 124 public function post_lang_choice() {
159 125 check_ajax_referer( 'pll_language', '_pll_nonce' );
160 126
@@ -162,22 +128,18 @@
162 128 wp_die( 0 );
163 129 }
164 130
165 131 global $post_ID; // Obliged to use the global variable for wp_popular_terms_checklist
166 - $post_ID = (int) $_POST['post_id'];
167 - $lang = $this->model->get_language( sanitize_key( $_POST['lang'] ) );
132 + $post_id = $post_ID = (int) $_POST['post_id'];
133 + $lang = $this->model->get_language( sanitize_key( $_POST['lang'] ) );
134 +
168 135 $post_type = sanitize_key( $_POST['post_type'] );
169 136
170 - if ( empty( $lang ) || ! post_type_exists( $post_type ) ) {
137 + if ( ! post_type_exists( $post_type ) ) {
171 138 wp_die( 0 );
172 139 }
173 140
174 141 $post_type_object = get_post_type_object( $post_type );
175 -
176 - if ( empty( $post_type_object ) ) {
177 - wp_die( 0 );
178 - }
179 -
180 142 if ( ! current_user_can( $post_type_object->cap->edit_post, $post_ID ) ) {
181 143 wp_die( -1 );
182 144 }
183 145
@@ -188,49 +150,44 @@
188 150 $translations = array_diff( $translations, array( $post_ID ) );
189 151 $this->model->post->save_translations( $post_ID, $translations );
190 152
191 153 ob_start();
192 - if ( 'attachment' === $post_type ) {
193 - include __DIR__ . '/view-translations-media.php';
194 - } else {
195 - include __DIR__ . '/view-translations-post.php';
154 + if ( $lang ) {
155 + include PLL_ADMIN_INC . '/view-translations-' . ( 'attachment' == $post_type ? 'media' : 'post' ) . '.php';
196 156 }
197 157 $x = new WP_Ajax_Response( array( 'what' => 'translations', 'data' => ob_get_contents() ) );
198 158 ob_end_clean();
199 159
200 160 // Categories
201 - if ( isset( $_POST['taxonomies'] ) ) { // Not set for pages
202 - $supplemental = array();
203 -
161 + if ( isset( $_POST['taxonomies'] ) ) {
162 + // Not set for pages
204 163 foreach ( array_map( 'sanitize_key', $_POST['taxonomies'] ) as $taxname ) {
205 164 $taxonomy = get_taxonomy( $taxname );
206 165
207 - if ( ! empty( $taxonomy ) ) {
208 - ob_start();
209 - $popular_ids = wp_popular_terms_checklist( $taxonomy->name );
210 - $supplemental['populars'] = ob_get_contents();
211 - ob_end_clean();
166 + ob_start();
167 + $popular_ids = wp_popular_terms_checklist( $taxonomy->name );
168 + $supplemental['populars'] = ob_get_contents();
169 + ob_end_clean();
212 170
213 - ob_start();
214 - // Use $post_ID to remember checked terms in case we come back to the original language
215 - wp_terms_checklist( $post_ID, array( 'taxonomy' => $taxonomy->name, 'popular_cats' => $popular_ids ) );
216 - $supplemental['all'] = ob_get_contents();
217 - ob_end_clean();
171 + ob_start();
172 + // Use $post_ID to remember checked terms in case we come back to the original language
173 + wp_terms_checklist( $post_ID, array( 'taxonomy' => $taxonomy->name, 'popular_cats' => $popular_ids ) );
174 + $supplemental['all'] = ob_get_contents();
175 + ob_end_clean();
218 176
219 - $supplemental['dropdown'] = wp_dropdown_categories(
220 - array(
221 - 'taxonomy' => $taxonomy->name,
222 - 'hide_empty' => 0,
223 - 'name' => 'new' . $taxonomy->name . '_parent',
224 - 'orderby' => 'name',
225 - 'hierarchical' => 1,
226 - 'show_option_none' => '&mdash; ' . $taxonomy->labels->parent_item . ' &mdash;',
227 - 'echo' => 0,
228 - )
229 - );
177 + $supplemental['dropdown'] = wp_dropdown_categories(
178 + array(
179 + 'taxonomy' => $taxonomy->name,
180 + 'hide_empty' => 0,
181 + 'name' => 'new' . $taxonomy->name . '_parent',
182 + 'orderby' => 'name',
183 + 'hierarchical' => 1,
184 + 'show_option_none' => '&mdash; ' . $taxonomy->labels->parent_item . ' &mdash;',
185 + 'echo' => 0,
186 + )
187 + );
230 188
231 - $x->Add( array( 'what' => 'taxonomy', 'data' => $taxonomy->name, 'supplemental' => $supplemental ) );
232 - }
189 + $x->Add( array( 'what' => 'taxonomy', 'data' => $taxonomy->name, 'supplemental' => $supplemental ) );
233 190 }
234 191 }
235 192
236 193 // Parent dropdown list ( only for hierarchical post types )
@@ -236,25 +193,23 @@
236 193 // Parent dropdown list ( only for hierarchical post types )
237 194 if ( in_array( $post_type, get_post_types( array( 'hierarchical' => true ) ) ) ) {
238 195 $post = get_post( $post_ID );
239 196
240 - if ( ! empty( $post ) ) {
241 - // Args and filter from 'page_attributes_meta_box' in wp-admin/includes/meta-boxes.php of WP 4.2.1
242 - $dropdown_args = array(
243 - 'post_type' => $post->post_type,
244 - 'exclude_tree' => $post->ID,
245 - 'selected' => $post->post_parent,
246 - 'name' => 'parent_id',
247 - 'show_option_none' => __( '(no parent)', 'polylang' ),
248 - 'sort_column' => 'menu_order, post_title',
249 - 'echo' => 0,
250 - );
197 + // Args and filter from 'page_attributes_meta_box' in wp-admin/includes/meta-boxes.php of WP 4.2.1
198 + $dropdown_args = array(
199 + 'post_type' => $post->post_type,
200 + 'exclude_tree' => $post->ID,
201 + 'selected' => $post->post_parent,
202 + 'name' => 'parent_id',
203 + 'show_option_none' => __( '(no parent)', 'polylang' ),
204 + 'sort_column' => 'menu_order, post_title',
205 + 'echo' => 0,
206 + );
251 207
252 - /** This filter is documented in wp-admin/includes/meta-boxes.php */
253 - $dropdown_args = apply_filters( 'page_attributes_dropdown_pages_args', $dropdown_args, $post ); // Since WP 3.3
208 + /** This filter is documented in wp-admin/includes/meta-boxes.php */
209 + $dropdown_args = apply_filters( 'page_attributes_dropdown_pages_args', $dropdown_args, $post ); // Since WP 3.3
254 210
255 - $x->Add( array( 'what' => 'pages', 'data' => wp_dropdown_pages( $dropdown_args ) ) ); // phpcs:ignore WordPress.Security.EscapeOutput
256 - }
211 + $x->Add( array( 'what' => 'pages', 'data' => wp_dropdown_pages( $dropdown_args ) ) ); // phpcs:ignore WordPress.Security.EscapeOutput
257 212 }
258 213
259 214 // Flag
260 215 $x->Add( array( 'what' => 'flag', 'data' => empty( $lang->flag ) ? esc_html( $lang->slug ) : $lang->flag ) );
@@ -268,10 +223,8 @@
268 223 /**
269 224 * Ajax response for input in translation autocomplete input box
270 225 *
271 226 * @since 1.5
272 - *
273 - * @return void
274 227 */
275 228 public function ajax_posts_not_translated() {
276 229 check_ajax_referer( 'pll_language', '_pll_nonce' );
277 230
@@ -305,19 +258,16 @@
305 258
306 259 // Add current translation in list
307 260 if ( $post_id = $this->model->post->get_translation( (int) $_GET['pll_post_id'], $translation_language ) ) {
308 261 $post = get_post( $post_id );
309 -
310 - if ( ! empty( $post ) ) {
311 - array_unshift(
312 - $return,
313 - array(
314 - 'id' => $post_id,
315 - 'value' => $post->post_title,
316 - 'link' => $this->links->edit_post_translation_link( $post_id ),
317 - )
318 - );
319 - }
262 + array_unshift(
263 + $return,
264 + array(
265 + 'id' => $post_id,
266 + 'value' => $post->post_title,
267 + 'link' => $this->links->edit_post_translation_link( $post_id ),
268 + )
269 + );
320 270 }
321 271
322 272 wp_die( wp_json_encode( $return ) );
323 273 }
@@ -322,15 +272,15 @@
322 272 wp_die( wp_json_encode( $return ) );
323 273 }
324 274
325 275 /**
326 - * Filters the pages by language in the parent dropdown list in the page attributes metabox.
276 + * Filters the pages by language in the parent dropdown list in the page attributes metabox
327 277 *
328 278 * @since 0.6
329 279 *
330 - * @param array $dropdown_args Arguments passed to wp_dropdown_pages().
331 - * @param WP_Post $post The page being edited.
332 - * @return array Modified arguments.
280 + * @param array $dropdown_args Arguments passed to wp_dropdown_pages
281 + * @param object $post
282 + * @return array Modified arguments
333 283 */
334 284 public function page_attributes_dropdown_pages_args( $dropdown_args, $post ) {
335 285 $dropdown_args['lang'] = isset( $_POST['lang'] ) ? $this->model->get_language( sanitize_key( $_POST['lang'] ) ) : $this->model->post->get_language( $post->ID ); // phpcs:ignore WordPress.Security.NonceVerification
336 286 if ( ! $dropdown_args['lang'] ) {
@@ -340,14 +290,13 @@
340 290 return $dropdown_args;
341 291 }
342 292
343 293 /**
344 - * Displays a notice if the user has not sufficient rights to overwrite synchronized taxonomies and metas.
294 + * Displays a notice if the user has not sufficient rights to overwrite synchronized taxonomies and metas
345 295 *
346 296 * @since 2.6
347 297 *
348 - * @param WP_Post $post the post currently being edited.
349 - * @return void
298 + * @param object $post Post currently being edited
350 299 */
351 300 public function edit_form_top( $post ) {
352 301 if ( ! $this->model->post->current_user_can_synchronize( $post->ID ) ) {
353 302 ?>