Make WordPress Core


Ignore:
Timestamp:
11/11/2009 11:24:01 AM (16 years ago)
Author:
azaozz
Message:

Fix image meta after editing image, disable the Save button when no changes, fixes #11115

File:
1 edited

Legend:

Unmodified
Added
Removed
  • trunk/wp-includes/post.php

    r12158 r12163  
    6969
    7070    $file = apply_filters( 'update_attached_file', $file, $attachment_id );
    71 
    72     // Make the file path relative to the upload dir
    73     if ( ($uploads = wp_upload_dir()) && false === $uploads['error'] ) { // Get upload directory
    74         if ( 0 === strpos($file, $uploads['basedir']) ) {// Check that the upload base exists in the file path
    75                 $file = str_replace($uploads['basedir'], '', $file); // Remove upload dir from the file path
    76                 $file = ltrim($file, '/');
    77         }
    78     }
     71    $file = _wp_relative_upload_path($file);
    7972
    8073    return update_post_meta( $attachment_id, '_wp_attached_file', $file );
     74}
     75
     76/**
     77 * Return relative path to an uploaded file.
     78 *
     79 * The path is relative to the current upload dir.
     80 *
     81 * @since 2.9
     82 * @uses apply_filters() Calls '_wp_relative_upload_path' on file path.
     83 *
     84 * @param string $path Full path to the file
     85 * @return string relative path on success, unchanged path on failure.
     86 */
     87function _wp_relative_upload_path( $path ) {
     88    $new_path = $path;
     89
     90    if ( ($uploads = wp_upload_dir()) && false === $uploads['error'] ) {
     91        if ( 0 === strpos($new_path, $uploads['basedir']) ) {
     92                $new_path = str_replace($uploads['basedir'], '', $new_path);
     93                $new_path = ltrim($new_path, '/');
     94        }
     95    }
     96
     97    return apply_filters( '_wp_relative_upload_path', $new_path, $path );
    8198}
    8299
Note: See TracChangeset for help on using the changeset viewer.