Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- function save_url_link( $post_id, $post ){
- // only works if the post is an audio post format
- if ( has_post_format('audio', $post_id)) {
- // look for either http or https mp3, m4a, ogg, wav or wma files
- $pattern = "/(http|https)://.*/(.*).(mp3|m4a|ogg|wav|wma)/";
- // php the removes all except the mp3 link
- preg_match_all($pattern,$post->post_content,$matches);
- // saves the mp3 link to a string
- $audio_raw = $matches[0][0];
- // check if meta field is empty
- if (get_post_meta( $post_id, 'audio_url', true ) == '') {
- // update the meta field
- update_post_meta( $post_id, 'audio_url', $audio_raw );
- // removes the save action
- remove_action('save_post', 'save_url_link', 10, 2);
- // update the content without the mp3 link
- wp_update_post(array('ID' => $post_id,'post_excerpt'=>$audio_raw,'post_content' => preg_replace('/(http|https)://.*/(.*).(mp3|m4a|ogg|wav|wma)/', "", $post->post_content)));
- // close and save
- };}}
- add_action( 'save_post', 'save_url_link', 10, 2 );
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement