PluginProbe
Polylang / 3.1
Polylang v3.1
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 +102 -66 2.93.1 View file →
@@ -8,11 +8,33 @@
8 8 *
9 9 * @since 2.4
10 10 */
11 11 class PLL_Admin_Classic_Editor {
12 - public $model, $links, $curlang, $pref_lang;
12 + /**
13 + * @var PLL_Model
14 + */
15 + public $model;
13 16
14 17 /**
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 + /**
15 37 * Constructor: setups filters and actions
16 38 *
17 39 * @since 2.4
18 40 *
@@ -43,8 +65,9 @@
43 65 *
44 66 * @since 0.1
45 67 *
46 68 * @param string $post_type Current post type
69 + * @return void
47 70 */
48 71 public function add_meta_boxes( $post_type ) {
49 72 if ( $this->model->is_translated_post_type( $post_type ) ) {
50 73 add_meta_box(
@@ -64,8 +87,10 @@
64 87 /**
65 88 * Displays the Languages metabox in the 'Edit Post' and 'Edit Page' panels
66 89 *
67 90 * @since 0.1
91 + *
92 + * @return void
68 93 */
69 94 public function post_language() {
70 95 global $post_ID;
71 96 $post_type = get_post_type( $post_ID );
@@ -126,44 +151,45 @@
126 151 /**
127 152 * Ajax response for changing the language in the post metabox
128 153 *
129 154 * @since 0.2
155 + *
156 + * @return void
130 157 */
131 158 public function post_lang_choice() {
132 159 check_ajax_referer( 'pll_language', '_pll_nonce' );
133 160
134 161 if ( ! isset( $_POST['post_id'], $_POST['lang'], $_POST['post_type'] ) ) {
135 - wp_die( 0 );
162 + wp_die( 'The request is missing the parameter "post_type", "lang" and/or "post_id".' );
136 163 }
137 164
138 165 global $post_ID; // Obliged to use the global variable for wp_popular_terms_checklist
139 166 $post_ID = (int) $_POST['post_id'];
140 - $lang = $this->model->get_language( sanitize_key( $_POST['lang'] ) );
167 + $lang_slug = sanitize_key( $_POST['lang'] );
168 + $lang = $this->model->get_language( $lang_slug );
141 169 $post_type = sanitize_key( $_POST['post_type'] );
142 170
143 - if ( ! post_type_exists( $post_type ) ) {
144 - wp_die( 0 );
171 + if ( empty( $lang ) ) {
172 + wp_die( esc_html( "{$lang_slug} is not a valid language code." ) );
145 173 }
146 174
147 175 $post_type_object = get_post_type_object( $post_type );
176 +
177 + if ( empty( $post_type_object ) ) {
178 + wp_die( esc_html( "{$post_type} is not a valid post type." ) );
179 + }
180 +
148 181 if ( ! current_user_can( $post_type_object->cap->edit_post, $post_ID ) ) {
149 - wp_die( -1 );
182 + wp_die( 'You are not allowed to edit this post.' );
150 183 }
151 184
152 - $this->model->post->set_language( $post_ID, $lang ); // Save language, useful to set the language when uploading media from post
185 + $this->model->post->update_language( $post_ID, $lang );
153 186
154 - // We also need to save the translations to match the language change
155 - $translations = $this->model->post->get_translations( $post_ID );
156 - $translations = array_diff( $translations, array( $post_ID ) );
157 - $this->model->post->save_translations( $post_ID, $translations );
158 -
159 187 ob_start();
160 - if ( $lang ) {
161 - if ( 'attachment' === $post_type ) {
162 - include __DIR__ . '/view-translations-media.php';
163 - } else {
164 - include __DIR__ . '/view-translations-post.php';
165 - }
188 + if ( 'attachment' === $post_type ) {
189 + include __DIR__ . '/view-translations-media.php';
190 + } else {
191 + include __DIR__ . '/view-translations-post.php';
166 192 }
167 193 $x = new WP_Ajax_Response( array( 'what' => 'translations', 'data' => ob_get_contents() ) );
168 194 ob_end_clean();
169 195
@@ -173,32 +199,34 @@
173 199
174 200 foreach ( array_map( 'sanitize_key', $_POST['taxonomies'] ) as $taxname ) {
175 201 $taxonomy = get_taxonomy( $taxname );
176 202
177 - ob_start();
178 - $popular_ids = wp_popular_terms_checklist( $taxonomy->name );
179 - $supplemental['populars'] = ob_get_contents();
180 - ob_end_clean();
203 + if ( ! empty( $taxonomy ) ) {
204 + ob_start();
205 + $popular_ids = wp_popular_terms_checklist( $taxonomy->name );
206 + $supplemental['populars'] = ob_get_contents();
207 + ob_end_clean();
181 208
182 - ob_start();
183 - // Use $post_ID to remember checked terms in case we come back to the original language
184 - wp_terms_checklist( $post_ID, array( 'taxonomy' => $taxonomy->name, 'popular_cats' => $popular_ids ) );
185 - $supplemental['all'] = ob_get_contents();
186 - ob_end_clean();
209 + ob_start();
210 + // Use $post_ID to remember checked terms in case we come back to the original language
211 + wp_terms_checklist( $post_ID, array( 'taxonomy' => $taxonomy->name, 'popular_cats' => $popular_ids ) );
212 + $supplemental['all'] = ob_get_contents();
213 + ob_end_clean();
187 214
188 - $supplemental['dropdown'] = wp_dropdown_categories(
189 - array(
190 - 'taxonomy' => $taxonomy->name,
191 - 'hide_empty' => 0,
192 - 'name' => 'new' . $taxonomy->name . '_parent',
193 - 'orderby' => 'name',
194 - 'hierarchical' => 1,
195 - 'show_option_none' => '— ' . $taxonomy->labels->parent_item . ' —',
196 - 'echo' => 0,
197 - )
198 - );
215 + $supplemental['dropdown'] = wp_dropdown_categories(
216 + array(
217 + 'taxonomy' => $taxonomy->name,
218 + 'hide_empty' => 0,
219 + 'name' => 'new' . $taxonomy->name . '_parent',
220 + 'orderby' => 'name',
221 + 'hierarchical' => 1,
222 + 'show_option_none' => '— ' . $taxonomy->labels->parent_item . ' —',
223 + 'echo' => 0,
224 + )
225 + );
199 226
200 - $x->Add( array( 'what' => 'taxonomy', 'data' => $taxonomy->name, 'supplemental' => $supplemental ) );
227 + $x->Add( array( 'what' => 'taxonomy', 'data' => $taxonomy->name, 'supplemental' => $supplemental ) );
228 + }
201 229 }
202 230 }
203 231
204 232 // Parent dropdown list ( only for hierarchical post types )
@@ -204,23 +232,25 @@
204 232 // Parent dropdown list ( only for hierarchical post types )
205 233 if ( in_array( $post_type, get_post_types( array( 'hierarchical' => true ) ) ) ) {
206 234 $post = get_post( $post_ID );
207 235
208 - // Args and filter from 'page_attributes_meta_box' in wp-admin/includes/meta-boxes.php of WP 4.2.1
209 - $dropdown_args = array(
210 - 'post_type' => $post->post_type,
211 - 'exclude_tree' => $post->ID,
212 - 'selected' => $post->post_parent,
213 - 'name' => 'parent_id',
214 - 'show_option_none' => __( '(no parent)', 'polylang' ),
215 - 'sort_column' => 'menu_order, post_title',
216 - 'echo' => 0,
217 - );
236 + if ( ! empty( $post ) ) {
237 + // Args and filter from 'page_attributes_meta_box' in wp-admin/includes/meta-boxes.php of WP 4.2.1
238 + $dropdown_args = array(
239 + 'post_type' => $post->post_type,
240 + 'exclude_tree' => $post->ID,
241 + 'selected' => $post->post_parent,
242 + 'name' => 'parent_id',
243 + 'show_option_none' => __( '(no parent)', 'polylang' ),
244 + 'sort_column' => 'menu_order, post_title',
245 + 'echo' => 0,
246 + );
218 247
219 - /** This filter is documented in wp-admin/includes/meta-boxes.php */
220 - $dropdown_args = apply_filters( 'page_attributes_dropdown_pages_args', $dropdown_args, $post ); // Since WP 3.3
248 + /** This filter is documented in wp-admin/includes/meta-boxes.php */
249 + $dropdown_args = apply_filters( 'page_attributes_dropdown_pages_args', $dropdown_args, $post ); // Since WP 3.3
221 250
222 - $x->Add( array( 'what' => 'pages', 'data' => wp_dropdown_pages( $dropdown_args ) ) ); // phpcs:ignore WordPress.Security.EscapeOutput
251 + $x->Add( array( 'what' => 'pages', 'data' => wp_dropdown_pages( $dropdown_args ) ) ); // phpcs:ignore WordPress.Security.EscapeOutput
252 + }
223 253 }
224 254
225 255 // Flag
226 256 $x->Add( array( 'what' => 'flag', 'data' => empty( $lang->flag ) ? esc_html( $lang->slug ) : $lang->flag ) );
@@ -234,8 +264,10 @@
234 264 /**
235 265 * Ajax response for input in translation autocomplete input box
236 266 *
237 267 * @since 1.5
268 + *
269 + * @return void
238 270 */
239 271 public function ajax_posts_not_translated() {
240 272 check_ajax_referer( 'pll_language', '_pll_nonce' );
241 273
@@ -269,16 +301,19 @@
269 301
270 302 // Add current translation in list
271 303 if ( $post_id = $this->model->post->get_translation( (int) $_GET['pll_post_id'], $translation_language ) ) {
272 304 $post = get_post( $post_id );
273 - array_unshift(
274 - $return,
275 - array(
276 - 'id' => $post_id,
277 - 'value' => $post->post_title,
278 - 'link' => $this->links->edit_post_translation_link( $post_id ),
279 - )
280 - );
305 +
306 + if ( ! empty( $post ) ) {
307 + array_unshift(
308 + $return,
309 + array(
310 + 'id' => $post_id,
311 + 'value' => $post->post_title,
312 + 'link' => $this->links->edit_post_translation_link( $post_id ),
313 + )
314 + );
315 + }
281 316 }
282 317
283 318 wp_die( wp_json_encode( $return ) );
284 319 }
@@ -283,15 +318,15 @@
283 318 wp_die( wp_json_encode( $return ) );
284 319 }
285 320
286 321 /**
287 - * Filters the pages by language in the parent dropdown list in the page attributes metabox
322 + * Filters the pages by language in the parent dropdown list in the page attributes metabox.
288 323 *
289 324 * @since 0.6
290 325 *
291 - * @param array $dropdown_args Arguments passed to wp_dropdown_pages
292 - * @param object $post
293 - * @return array Modified arguments
326 + * @param array $dropdown_args Arguments passed to wp_dropdown_pages().
327 + * @param WP_Post $post The page being edited.
328 + * @return array Modified arguments.
294 329 */
295 330 public function page_attributes_dropdown_pages_args( $dropdown_args, $post ) {
296 331 $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
297 332 if ( ! $dropdown_args['lang'] ) {
@@ -301,13 +336,14 @@
301 336 return $dropdown_args;
302 337 }
303 338
304 339 /**
305 - * Displays a notice if the user has not sufficient rights to overwrite synchronized taxonomies and metas
340 + * Displays a notice if the user has not sufficient rights to overwrite synchronized taxonomies and metas.
306 341 *
307 342 * @since 2.6
308 343 *
309 - * @param object $post Post currently being edited
344 + * @param WP_Post $post the post currently being edited.
345 + * @return void
310 346 */
311 347 public function edit_form_top( $post ) {
312 348 if ( ! $this->model->post->current_user_can_synchronize( $post->ID ) ) {
313 349 ?>