/**
 * Get list of posts for a post_type and output as "chosen-friendly" select list options
 *
 * Each <option> lists post title with ID as value
 *
 * First option is blank
 *
 * @since 2.0.0
 *
 * @param 	int 	$selected 		ID of selected page, if applicable
 * @return 	string 					HTML <optgroup> with <option> for each post type.
 */
function fpw_page_select_list_options($selected = null)
{
    $post_types = fpw_post_types();
    // stop if there are no post types to display
    if (!$post_types) {
        return;
    }
    // setup string to build options on
    // first option is blank i.e. "no page selected"
    $fpw_select_list_options = '<option value=""></option>';
    // loop through each post type
    foreach ($post_types as $type) {
        // prepare list of pages
        $posts = get_posts(array('post_status' => 'publish', 'posts_per_page' => -1, 'post_type' => $type, 'orderby' => 'title', 'order' => 'DESC', 'suppress_filters' => false));
        $post_type_object = get_post_type_object($type);
        $name = $post_type_object->labels->name;
        // open optgroup with post type name
        $fpw_select_list_options .= '<optgroup label="' . esc_attr($name) . '">';
        // loop through each post, output an <option>
        foreach ($posts as $post) {
            $post_id = $post->ID;
            $post_title = $post->post_title;
            // test for excerpt and feature image, set HTML classes if available
            $featured_image = null;
            if (has_post_thumbnail($post_id)) {
                $featured_image = 'featured-image';
            }
            $excerpt = null;
            if (has_excerpt($post_id)) {
                $excerpt = 'excerpt';
            }
            $fpw_select_list_options .= sprintf('<option class="%4$s %5$s" value="%1$s" data-edit-link="%6$s" %3$s>%2$s</option>', $post_id, $post_title, selected($selected, $post_id, false), $featured_image, $excerpt, esc_url(get_edit_post_link($post_id)));
        }
        // close the optgroup, continue
        $fpw_select_list_options .= '</optgroup>';
    }
    // Add special options - Eventually this will make it in
    /*$fpw_select_list_options .= '<optgroup label="Special">';
    	// Most Recent Post
    	$fpw_select_list_options .= sprintf(
    		'<option value="most_recent" %1$s>Most Recent Post</option>',
    		selected( $selected, 'most_recent', false )
    	);
    	$fpw_select_list_options .= '</optgroup>';*/
    return $fpw_select_list_options;
}
function fpw_page_supports()
{
    // Enable core WP features on pages to allow widget to function
    add_theme_support('post-thumbnails');
    // automatically enable excerpt and thumbnails for all supported post types
    $fpw_post_types = fpw_post_types();
    foreach ($fpw_post_types as $type) {
        if (post_type_exists($type)) {
            add_post_type_support($type, 'excerpt');
            add_post_type_support($type, 'thumbnail');
        }
    }
    // Register image sizes
    // For the "Wrapped" layout
    add_image_size('fpw_square', 200, 200, true);
    // For the "Banner" layout
    add_image_size('fpw_banner', 400, 150, true);
    // For the "Big" layout
    add_image_size('fpw_big', 400, 600);
}