Forked from blainerobison/gist:fecf1bba78527712fd6e
Last active
January 31, 2017 10:17
-
-
Save mszkb/89b6978327e5315c11ec6ad9f5ee82ba to your computer and use it in GitHub Desktop.
Wordpress Metadata - Update Metadata after Upload
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
/** | |
* Add attachment metadata | |
* | |
* By default, WordPress only adds '_wp_attachment_metadata' metadata to images, audio and video files. | |
* This hooks into 'wp_update_attachment_metadata' and sets 'file' to the value of '_wp_attached_file'. | |
*/ | |
function prefix_update_attachment_metadata( $data, $post_id ) { | |
// only set 'file' if needed | |
if ( isset( $data['file'] ) ) { | |
return $data; | |
} | |
// get file path e.g. pdf/filename.pdf | |
if ( $file = get_post_meta( $post_id, '_wp_attached_file', true ) ) { | |
// TODO Do your Metadata stuff here | |
$data['file']=$filename."/preview.jpg"; | |
$data['thumb']=$filename."/preview.jpg"; | |
$data['mime-type']='image/jpeg'; | |
} | |
return $data; | |
} | |
add_filter( 'wp_update_attachment_metadata', 'prefix_update_attachment_metadata', 10, 2 ); |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment