WordPress.org

Ready to get started?Download WordPress

Forums

Featured Image Column
[resolved] filter for post types (5 posts)

  1. Bill Erickson
    Member
    Posted 2 years ago #

    Great plugin!

    Right now it looks like it adds the column to any post type that supports featured images, and adds featured image support to post and page.

    I recommend creating a filtered array, $post_types, so developers can specify exactly where it shows up.

    $post_types = array();
    if( post_type_supports( 'post', 'thumbnail' ) $post_types[] = 'post';
    if( post_type_supports( 'page', 'thumbnail' ) $post_types[] = 'page';
    $post_types = apply_filters( 'featured_image_column_post_types', $post_types );

    That way, if I want to limit it to just my "rotator" post type, I can drop this in the functions.php file:

    function be_featured_image_columns( $post_types ) {
    	return 'rotator';
    }
    add_filter( 'featured_image_column_post_types', 'be_featured_image_columns' );

    http://wordpress.org/extend/plugins/featured-image-column/

  2. Austin Passy
    Member
    Plugin Author

    Posted 2 years ago #

    Great idea. Which function would I drop that into?

  3. Bill Erickson
    Member
    Posted 2 years ago #

    I'd recommend creating a separate function in the class:

    function included_post_types( $post_type ) {
    	$post_types = array();
    	if( post_type_supports( 'post', 'thumbnail' ) $post_types[] = 'post';
    	if( post_type_supports( 'page', 'thumbnail' ) $post_types[] = 'page';
    	$post_types = apply_filters( 'featured_image_column_post_types', $post_types );
    	if( in_array( $post_type, $post_types )
    		return true;
    	else
    		return false;
    }

    Then, everywhere you're checking to see if the current post type supports thumbnails, replace it with this function. For example, at the top of columns(), change this:

    if ( !post_type_supports( $post_type, 'thumbnail' ) )
    	return;

    To this:

    if( !self::included_post_types( $post_type ) )
    	return;

    This is all untested though

  4. Austin Passy
    Member
    Plugin Author

    Posted 2 years ago #

    I'll play around with this.

  5. Adam W. Warner
    Member
    Posted 2 years ago #

    The power of community:) I just learned of your plugin and I'm agreed...GREAT idea!

Topic Closed

This topic has been closed to new replies.

About this Plugin

About this Topic