WebDevStudios / Automatic-Featured-Images-from-Videos

If a YouTube or Vimeo video exists in the first few paragraphs of a post, automatically set the post's featured image to that vidoe's thumbnail.
33 stars 24 forks source link

Add post ID to wds_featured_images_from_video_filter_content filter #25

Closed tw2113 closed 8 years ago

tw2113 commented 8 years ago

Make it easier for users to filter and not hunt down the ID being acted on

binarygary commented 8 years ago

I'm not sure I'm seeing this clearly...can you explain further? We apply the filter inside a function that has the $post->ID.

Maybe you could provide some pseudocode for a situation where the user wouldn't already have the id?

tw2113 commented 8 years ago

In regards to any callback that the user adds to https://github.com/WebDevStudios/Automatic-Featured-Images-from-Videos/blob/master/automatic-featured-images-from-videos.php#L63, they'd receive a chunk of text from the start of their visual editor. However, if they want to instead return content from a meta field, they would need to grab the $_GET parameter version, assuming it's even present at that moment, and grab the post ID there to fetch their custom field. Passing the post ID into the filter, saves them hassle

binarygary commented 8 years ago

I'm not certain on this still. To know what they want to filter, wouldn't they already be in an area of execution that they have access to the id and thus meta, etc...?

I think my thought process is impacted by how I used this. I'm having a hard time understanding how they'd pass in the ID. Would it be accompanied with something else?

tw2113 commented 8 years ago
// New version
$content = apply_filters( 'wds_featured_images_from_video_filter_content', $content, $post_id );
// User-provided content blob, function added to functions.php
function my_function( $original_content, $post_id ) {
    $my_data = get_post_meta( $post_id, 'my_meta_field_unknown_to_plugin', true );
    if ( ! empty( $my_data ) {
        return $my_data;
    }
    return $original_content;
}
add_filter( 'wds_featured_images_from_video_filter_content', 'my_function', 10, 2 );
tw2113 commented 8 years ago

Fixed in 933e919