Skip to content

Instantly share code, notes, and snippets.

@scottopolis
Last active December 11, 2019 13:08
Show Gist options
  • Save scottopolis/066965aa7d0fd9d77ac4a68545c5880d to your computer and use it in GitHub Desktop.
Save scottopolis/066965aa7d0fd9d77ac4a68545c5880d to your computer and use it in GitHub Desktop.
Add an image for the AppPresser media player
<?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