Last active
December 11, 2019 13:08
-
-
Save scottopolis/066965aa7d0fd9d77ac4a68545c5880d to your computer and use it in GitHub Desktop.
Add an image for the AppPresser media player
This file contains 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
<?php | |
/* | |
Plugin Name: AppPresser Media Images | |
Plugin URI: https://apppresser.com | |
Description: Automatically add media images on when a post is saved for posts that have a media url. | |
Version: 1.0 | |
Author: AppPresser Team | |
Author URI: http://apppresser.com | |
License: GPLv2 | |
*/ | |
add_action('save_post', 'apppresser_add_media_image', 10, 3 ); | |
function apppresser_add_media_image( $post_id, $post, $update ) { | |
if( !class_exists('AppPresser') ) return; | |
// Only set for posts that use the media feature | |
$arr = appp_get_setting( 'media_post_types' ); | |
if( false === array_search( $post->post_type, $arr ) ) { | |
return; | |
} | |
// (optional) you could also check for only posts that have the media url set | |
if( get_post_meta( $post_id, 'appp_media_url', 1 ) === '' ) { | |
return; | |
} | |
$featured_url = wp_get_attachment_url( get_post_thumbnail_id( $post_id ) ); | |
update_post_meta( $post_id, 'appp_media_image', $featured_url ); | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment