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