Changeset 43392
- Timestamp:
- 07/05/2018 02:31:24 PM (6 years ago)
- Location:
- trunk/src/wp-includes
- Files:
-
- 2 edited
Legend:
- Unmodified
- Added
- Removed
-
trunk/src/wp-includes/functions.php
r43389 r43392 5849 5849 5850 5850 /** 5851 * Deletes a file if its path is within the given directory. 5852 * 5853 * @since 4.9.7 5854 * 5855 * @param string $file Absolute path to the file to delete. 5856 * @param string $directory Absolute path to a directory. 5857 * @return bool True on success, false on failure. 5858 */ 5859 function wp_delete_file_from_directory( $file, $directory ) { 5860 $real_file = realpath( wp_normalize_path( $file ) ); 5861 $real_directory = realpath( wp_normalize_path( $directory ) ); 5862 5863 if ( false === $real_file || false === $real_directory || strpos( wp_normalize_path( $real_file ), trailingslashit( wp_normalize_path( $real_directory ) ) ) !== 0 ) { 5864 return false; 5865 } 5866 5867 wp_delete_file( $file ); 5868 5869 return true; 5870 } 5871 5872 /** 5851 5873 * Outputs a small JS snippet on preview tabs/windows to remove `window.name` on unload. 5852 5874 * -
trunk/src/wp-includes/post.php
r43378 r43392 5312 5312 do_action( 'deleted_post', $post_id ); 5313 5313 5314 wp_delete_attachment_files( $post_id, $meta, $backup_sizes, $file ); 5315 5316 clean_post_cache( $post ); 5317 5318 return $post; 5319 } 5320 5321 /** 5322 * Deletes all files that belong to the given attachment. 5323 * 5324 * @since 4.9.7 5325 * 5326 * @param int $post_id Attachment ID. 5327 * @param array $meta The attachment's meta data. 5328 * @param array $backup_sizes The meta data for the attachment's backup images. 5329 * @param string $file Absolute path to the attachment's file. 5330 * @return bool True on success, false on failure. 5331 */ 5332 function wp_delete_attachment_files( $post_id, $meta, $backup_sizes, $file ) { 5333 global $wpdb; 5334 5314 5335 $uploadpath = wp_get_upload_dir(); 5336 $deleted = true; 5315 5337 5316 5338 if ( ! empty( $meta['thumb'] ) ) { … … 5318 5340 if ( ! $wpdb->get_row( $wpdb->prepare( "SELECT meta_id FROM $wpdb->postmeta WHERE meta_key = '_wp_attachment_metadata' AND meta_value LIKE %s AND post_id <> %d", '%' . $wpdb->esc_like( $meta['thumb'] ) . '%', $post_id ) ) ) { 5319 5341 $thumbfile = str_replace( basename( $file ), $meta['thumb'], $file ); 5320 /** This filter is documented in wp-includes/functions.php */ 5321 $thumbfile = apply_filters( 'wp_delete_file', $thumbfile ); 5322 @ unlink( path_join( $uploadpath['basedir'], $thumbfile ) ); 5342 if ( ! empty( $thumbfile ) ) { 5343 $thumbfile = path_join( $uploadpath['basedir'], $thumbfile ); 5344 $thumbdir = path_join( $uploadpath['basedir'], dirname( $file ) ); 5345 5346 if ( ! wp_delete_file_from_directory( $thumbfile, $thumbdir ) ) { 5347 $deleted = false; 5348 } 5349 } 5323 5350 } 5324 5351 } … … 5326 5353 // Remove intermediate and backup images if there are any. 5327 5354 if ( isset( $meta['sizes'] ) && is_array( $meta['sizes'] ) ) { 5355 $intermediate_dir = path_join( $uploadpath['basedir'], dirname( $file ) ); 5328 5356 foreach ( $meta['sizes'] as $size => $sizeinfo ) { 5329 5357 $intermediate_file = str_replace( basename( $file ), $sizeinfo['file'], $file ); 5330 /** This filter is documented in wp-includes/functions.php */ 5331 $intermediate_file = apply_filters( 'wp_delete_file', $intermediate_file ); 5332 @ unlink( path_join( $uploadpath['basedir'], $intermediate_file ) ); 5358 if ( ! empty( $intermediate_file ) ) { 5359 $intermediate_file = path_join( $uploadpath['basedir'], $intermediate_file ); 5360 5361 if ( ! wp_delete_file_from_directory( $intermediate_file, $intermediate_dir ) ) { 5362 $deleted = false; 5363 } 5364 } 5333 5365 } 5334 5366 } 5335 5367 5336 5368 if ( is_array( $backup_sizes ) ) { 5369 $del_dir = path_join( $uploadpath['basedir'], dirname( $meta['file'] ) ); 5337 5370 foreach ( $backup_sizes as $size ) { 5338 5371 $del_file = path_join( dirname( $meta['file'] ), $size['file'] ); 5339 /** This filter is documented in wp-includes/functions.php */ 5340 $del_file = apply_filters( 'wp_delete_file', $del_file ); 5341 @ unlink( path_join( $uploadpath['basedir'], $del_file ) ); 5342 } 5343 } 5344 5345 wp_delete_file( $file ); 5346 5347 clean_post_cache( $post ); 5348 5349 return $post; 5372 if ( ! empty( $del_file ) ) { 5373 $del_file = path_join( $uploadpath['basedir'], $del_file ); 5374 5375 if ( ! wp_delete_file_from_directory( $del_file, $del_dir ) ) { 5376 $deleted = false; 5377 } 5378 } 5379 } 5380 } 5381 5382 if ( ! wp_delete_file_from_directory( $file, $uploadpath['basedir'] ) ) { 5383 $deleted = false; 5384 } 5385 5386 return $deleted; 5350 5387 } 5351 5388
Note: See TracChangeset
for help on using the changeset viewer.