Changeset 43396
- Timestamp:
- 07/05/2018 02:52:09 PM (7 years ago)
- Location:
- branches/4.6/src/wp-includes
- Files:
-
- 2 edited
-
functions.php (modified) (3 diffs)
-
post.php (modified) (2 diffs)
Legend:
- Unmodified
- Added
- Removed
-
branches/4.6/src/wp-includes/functions.php
r42279 r43396 1703 1703 * @since 4.4.0 Ensures upper-case drive letters on Windows systems. 1704 1704 * @since 4.5.0 Allows for Windows network shares. 1705 * @since 4.9.7 Allows for PHP file wrappers. 1705 1706 * 1706 1707 * @param string $path Path to normalize. … … 1708 1709 */ 1709 1710 function wp_normalize_path( $path ) { 1711 $wrapper = ''; 1712 if ( wp_is_stream( $path ) ) { 1713 list( $wrapper, $path ) = explode( '://', $path, 2 ); 1714 $wrapper .= '://'; 1715 } 1716 1717 // Standardise all paths to use / 1710 1718 $path = str_replace( '\\', '/', $path ); 1719 1720 // Replace multiple slashes down to a singular, allowing for network shares having two slashes. 1711 1721 $path = preg_replace( '|(?<=.)/+|', '/', $path ); 1722 1723 // Windows paths should uppercase the drive letter 1712 1724 if ( ':' === substr( $path, 1, 1 ) ) { 1713 1725 $path = ucfirst( $path ); 1714 1726 } 1715 return $path; 1727 1728 return $wrapper . $path; 1716 1729 } 1717 1730 … … 5354 5367 5355 5368 /** 5369 * Deletes a file if its path is within the given directory. 5370 * 5371 * @since 4.9.7 5372 * 5373 * @param string $file Absolute path to the file to delete. 5374 * @param string $directory Absolute path to a directory. 5375 * @return bool True on success, false on failure. 5376 */ 5377 function wp_delete_file_from_directory( $file, $directory ) { 5378 $real_file = realpath( wp_normalize_path( $file ) ); 5379 $real_directory = realpath( wp_normalize_path( $directory ) ); 5380 5381 if ( false === $real_file || false === $real_directory || strpos( wp_normalize_path( $real_file ), trailingslashit( wp_normalize_path( $real_directory ) ) ) !== 0 ) { 5382 return false; 5383 } 5384 5385 wp_delete_file( $file ); 5386 5387 return true; 5388 } 5389 5390 /** 5356 5391 * Outputs a small JS snippet on preview tabs/windows to remove `window.name` on unload. 5357 5392 * -
branches/4.6/src/wp-includes/post.php
r42059 r43396 4798 4798 do_action( 'deleted_post', $post_id ); 4799 4799 4800 wp_delete_attachment_files( $post_id, $meta, $backup_sizes, $file ); 4801 4802 clean_post_cache( $post ); 4803 4804 return $post; 4805 } 4806 4807 /** 4808 * Deletes all files that belong to the given attachment. 4809 * 4810 * @since 4.9.7 4811 * 4812 * @param int $post_id Attachment ID. 4813 * @param array $meta The attachment's meta data. 4814 * @param array $backup_sizes The meta data for the attachment's backup images. 4815 * @param string $file Absolute path to the attachment's file. 4816 * @return bool True on success, false on failure. 4817 */ 4818 function wp_delete_attachment_files( $post_id, $meta, $backup_sizes, $file ) { 4819 global $wpdb; 4820 4800 4821 $uploadpath = wp_get_upload_dir(); 4801 4802 if ( ! empty($meta['thumb']) ) { 4822 $deleted = true; 4823 4824 if ( ! empty( $meta['thumb'] ) ) { 4803 4825 // Don't delete the thumb if another attachment uses it. 4804 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)) ) { 4805 $thumbfile = str_replace(basename($file), $meta['thumb'], $file); 4806 /** This filter is documented in wp-includes/functions.php */ 4807 $thumbfile = apply_filters( 'wp_delete_file', $thumbfile ); 4808 @ unlink( path_join($uploadpath['basedir'], $thumbfile) ); 4826 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 ) ) ) { 4827 $thumbfile = str_replace( basename( $file ), $meta['thumb'], $file ); 4828 if ( ! empty( $thumbfile ) ) { 4829 $thumbfile = path_join( $uploadpath['basedir'], $thumbfile ); 4830 $thumbdir = path_join( $uploadpath['basedir'], dirname( $file ) ); 4831 4832 if ( ! wp_delete_file_from_directory( $thumbfile, $thumbdir ) ) { 4833 $deleted = false; 4834 } 4835 } 4809 4836 } 4810 4837 } … … 4812 4839 // Remove intermediate and backup images if there are any. 4813 4840 if ( isset( $meta['sizes'] ) && is_array( $meta['sizes'] ) ) { 4841 $intermediate_dir = path_join( $uploadpath['basedir'], dirname( $file ) ); 4814 4842 foreach ( $meta['sizes'] as $size => $sizeinfo ) { 4815 4843 $intermediate_file = str_replace( basename( $file ), $sizeinfo['file'], $file ); 4816 /** This filter is documented in wp-includes/functions.php */ 4817 $intermediate_file = apply_filters( 'wp_delete_file', $intermediate_file ); 4818 @ unlink( path_join( $uploadpath['basedir'], $intermediate_file ) ); 4819 } 4820 } 4821 4822 if ( is_array($backup_sizes) ) { 4844 if ( ! empty( $intermediate_file ) ) { 4845 $intermediate_file = path_join( $uploadpath['basedir'], $intermediate_file ); 4846 4847 if ( ! wp_delete_file_from_directory( $intermediate_file, $intermediate_dir ) ) { 4848 $deleted = false; 4849 } 4850 } 4851 } 4852 } 4853 4854 if ( is_array( $backup_sizes ) ) { 4855 $del_dir = path_join( $uploadpath['basedir'], dirname( $meta['file'] ) ); 4823 4856 foreach ( $backup_sizes as $size ) { 4824 $del_file = path_join( dirname($meta['file']), $size['file'] ); 4825 /** This filter is documented in wp-includes/functions.php */ 4826 $del_file = apply_filters( 'wp_delete_file', $del_file ); 4827 @ unlink( path_join($uploadpath['basedir'], $del_file) ); 4828 } 4829 } 4830 4831 wp_delete_file( $file ); 4832 4833 clean_post_cache( $post ); 4834 4835 return $post; 4857 $del_file = path_join( dirname( $meta['file'] ), $size['file'] ); 4858 if ( ! empty( $del_file ) ) { 4859 $del_file = path_join( $uploadpath['basedir'], $del_file ); 4860 4861 if ( ! wp_delete_file_from_directory( $del_file, $del_dir ) ) { 4862 $deleted = false; 4863 } 4864 } 4865 } 4866 } 4867 4868 if ( ! wp_delete_file_from_directory( $file, $uploadpath['basedir'] ) ) { 4869 $deleted = false; 4870 } 4871 4872 return $deleted; 4836 4873 } 4837 4874
Note: See TracChangeset
for help on using the changeset viewer.