PluginProbe
Polylang / 3.1.4
Polylang v3.1.4
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 | include/crud-posts.php +16 -23 3.03.1.4 View file →
@@ -42,9 +42,9 @@
42 42 $this->curlang = &$polylang->curlang;
43 43
44 44 add_action( 'save_post', array( $this, 'save_post' ), 10, 2 );
45 45 add_action( 'set_object_terms', array( $this, 'set_object_terms' ), 10, 4 );
46 - add_filter( 'wp_insert_post_parent', array( $this, 'wp_insert_post_parent' ), 10, 4 );
46 + add_filter( 'wp_insert_post_parent', array( $this, 'wp_insert_post_parent' ), 10, 2 );
47 47 add_action( 'before_delete_post', array( $this, 'delete_post' ) );
48 48
49 49 // Specific for media
50 50 if ( $polylang->options['media_support'] ) {
@@ -186,28 +186,21 @@
186 186 }
187 187 }
188 188
189 189 /**
190 - * Make sure that the post parent is in the correct language when using bulk edit
190 + * Make sure that the post parent is in the correct language.
191 191 *
192 192 * @since 1.8
193 193 *
194 - * @param int $post_parent Post parent ID.
195 - * @param int $post_id Post ID.
196 - * @param array $new_postarr Array of parsed post data.
197 - * @param array $postarr Array of sanitized, but otherwise unmodified post data.
194 + * @param int $post_parent Post parent ID.
195 + * @param int $post_id Post ID.
198 196 * @return int
199 197 */
200 - public function wp_insert_post_parent( $post_parent, $post_id, $new_postarr, $postarr ) {
201 - if ( isset( $postarr['bulk_edit'], $postarr['inline_lang_choice'] ) ) {
202 - check_admin_referer( 'bulk-posts' );
203 - $lang = -1 == $postarr['inline_lang_choice'] ?
204 - $this->model->post->get_language( $post_id ) :
205 - $this->model->get_language( $postarr['inline_lang_choice'] );
206 - // Dont break the hierarchy in case the post has no language
207 - if ( ! empty( $lang ) ) {
208 - $post_parent = $this->model->post->get_translation( $post_parent, $lang );
209 - }
198 + public function wp_insert_post_parent( $post_parent, $post_id ) {
199 + $lang = $this->model->post->get_language( $post_id );
200 + // Dont break the hierarchy in case the post has no language
201 + if ( ! empty( $lang ) ) {
202 + $post_parent = $this->model->post->get_translation( $post_parent, $lang );
210 203 }
211 204 return $post_parent;
212 205 }
213 206
@@ -227,10 +220,9 @@
227 220 }
228 221 }
229 222
230 223 /**
231 - * Prevents WP deleting files when there are still media using them
232 - * Thanks to Bruno "Aesqe" Babic and its plugin file gallery in which I took all the ideas for this function
224 + * Prevents WP deleting files when there are still media using them.
233 225 *
234 226 * @since 0.9
235 227 *
236 228 * @param string $file Path to the file to delete.
@@ -240,21 +232,22 @@
240 232 global $wpdb;
241 233
242 234 $uploadpath = wp_upload_dir();
243 235
236 + // Get the main attached file.
237 + $attached_file = substr_replace( $file, '', 0, strlen( trailingslashit( $uploadpath['basedir'] ) ) );
238 + $attached_file = preg_replace( '#-\d+x\d+\.([a-z]+)$#', '.$1', $attached_file );
239 +
244 240 $ids = $wpdb->get_col(
245 241 $wpdb->prepare(
246 242 "SELECT post_id FROM $wpdb->postmeta
247 243 WHERE meta_key = '_wp_attached_file' AND meta_value = %s",
248 - substr_replace( $file, '', 0, strlen( trailingslashit( $uploadpath['basedir'] ) ) )
244 + $attached_file
249 245 )
250 246 );
251 247
252 248 if ( ! empty( $ids ) ) {
253 - // Regenerate intermediate sizes if it's an image ( since we could not prevent WP deleting them before ).
254 - require_once ABSPATH . 'wp-admin/includes/image.php'; // In case the file is deleted outside admin.
255 - wp_update_attachment_metadata( $ids[0], wp_slash( wp_generate_attachment_metadata( $ids[0], $file ) ) ); // Directly uses update_post_meta, so expects slashed.
256 - return ''; // Prevent deleting the main file.
249 + return ''; // Prevent deleting the file.
257 250 }
258 251
259 252 return $file;
260 253 }