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 +8 -12 3.03.1 View file →
@@ -158,36 +158,32 @@
158 158 public function post_lang_choice() {
159 159 check_ajax_referer( 'pll_language', '_pll_nonce' );
160 160
161 161 if ( ! isset( $_POST['post_id'], $_POST['lang'], $_POST['post_type'] ) ) {
162 - wp_die( 0 );
162 + wp_die( 'The request is missing the parameter "post_type", "lang" and/or "post_id".' );
163 163 }
164 164
165 165 global $post_ID; // Obliged to use the global variable for wp_popular_terms_checklist
166 166 $post_ID = (int) $_POST['post_id'];
167 - $lang = $this->model->get_language( sanitize_key( $_POST['lang'] ) );
167 + $lang_slug = sanitize_key( $_POST['lang'] );
168 + $lang = $this->model->get_language( $lang_slug );
168 169 $post_type = sanitize_key( $_POST['post_type'] );
169 170
170 - if ( empty( $lang ) || ! post_type_exists( $post_type ) ) {
171 - wp_die( 0 );
171 + if ( empty( $lang ) ) {
172 + wp_die( esc_html( "{$lang_slug} is not a valid language code." ) );
172 173 }
173 174
174 175 $post_type_object = get_post_type_object( $post_type );
175 176
176 177 if ( empty( $post_type_object ) ) {
177 - wp_die( 0 );
178 + wp_die( esc_html( "{$post_type} is not a valid post type." ) );
178 179 }
179 180
180 181 if ( ! current_user_can( $post_type_object->cap->edit_post, $post_ID ) ) {
181 - wp_die( -1 );
182 + wp_die( 'You are not allowed to edit this post.' );
182 183 }
183 184
184 - $this->model->post->set_language( $post_ID, $lang ); // Save language, useful to set the language when uploading media from post
185 -
186 - // We also need to save the translations to match the language change
187 - $translations = $this->model->post->get_translations( $post_ID );
188 - $translations = array_diff( $translations, array( $post_ID ) );
189 - $this->model->post->save_translations( $post_ID, $translations );
185 + $this->model->post->update_language( $post_ID, $lang );
190 186
191 187 ob_start();
192 188 if ( 'attachment' === $post_type ) {
193 189 include __DIR__ . '/view-translations-media.php';