Skip to content

Instantly share code, notes, and snippets.

@jeremyfelt
Created April 14, 2012 19:20
Show Gist options
  • Save jeremyfelt/2387195 to your computer and use it in GitHub Desktop.
Save jeremyfelt/2387195 to your computer and use it in GitHub Desktop.
Filters enabled in Automatic Featured Image Posts
<?php
/* A brief overview of filters that are now available in Automatic Featured Image Posts.
*
* These allow easy overriding of the default post title, categories, and content before
* the new post is created, while still maintaining the core priority of the plugin,
* which is to add a new post with a featured image assigned to it */
add_filter( 'afip_new_post_title', 'myprefix_change_afip_post_title', 10, 2 );
/* Adds 'Magic Photo: ' to the front of every auto generated post tile from
* Automatic Featured Image Posts */
function myprefix_change_afip_post_title( $post_title, $attachment_id ) {
return 'Magic Photo: ' . $post_title;
}
add_filter( 'afip_new_post_category', 'myprefix_change_afip_post_category', 10, 2 );
/* Adds every auto generated post to the category with the slug 'photos' */
function myprefix_change_afip_post_category( $post_category, $attachment_id ) {
$my_photo_category = get_category_by_slug( 'photos' );
if ( is_object( $my_photo_category ) )
$post_category[] = $my_photo_category->term_id;
return $post_category;
}
add_filter( 'afip_new_post_content', 'myprefix_change_afip_post_content', 10, 2 );
/* Grabs the image source for the newly created image and inserts it
* into the new post content along with a one line paragraph. */
function myprefix_change_afip_post_content( $post_content, $attachment_id ) {
$my_uploaded_image = wp_get_attachment_image_src( $attachment_id );
$post_content = '<p>This is my new uploaded image....</p>';
$post_content .= '<img src="' . $my_uploaded_image[0] . '">';
return $post_content;
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment