WordPress.org

Plugin Directory

Changeset 528722


Ignore:
Timestamp:
04/08/12 01:47:21 (2 years ago)
Author:
jeremyfelt
Message:

Update trunk with new version 0.5

Supporting post formats, sporting cleaner code and better messaging.

Location:
automatic-featured-image-posts/trunk
Files:
3 edited

Legend:

Unmodified
Added
Removed
  • automatic-featured-image-posts/trunk/automatic-featured-image-posts.php

    r516189 r528722  
    44Plugin URI: http://www.jeremyfelt.com/wordpress/plugins/automatic-featured-image-posts/ 
    55Description: Automatically creates a new post with an assigned featured image from every image upload. 
    6 Version: 0.4 
     6Version: 0.5 
    77Author: Jeremy Felt 
    88Author URI: http://www.jeremyfelt.com 
     
    2626*/ 
    2727 
    28 /* Upon activation, we'll want to check for existing plugin options and make sure that 
    29  * defaults are assigned if this is the first time. */ 
    30 register_activation_hook( __FILE__, 'afip_activate' ); 
    31 function afip_activate() { 
    32     $current_afip_options = get_option( 'afip_options' ); 
    33     $afip_options[ 'default_post_status' ] = isset( $current_afip_options[ 'default_post_status' ] ) ? $current_afip_options[ 'default_post_status' ] : 'publish'; 
    34     $afip_options[ 'default_post_type' ] = isset( $current_afip_options[ 'default_post_type' ] ) ? $current_afip_options[ 'default_post_type' ] : 'post'; 
    35     update_option( 'afip_options', $afip_options ); 
    36  
    37     if ( '0.4' != get_option( 'afip_upgrade_check' ) ) 
    38         update_option( 'afip_upgrade_check', '0.4' ); 
     28class Automatic_Featured_Image_Posts_Foghlaim { 
     29 
     30    public function __construct() { 
     31        register_activation_hook( __FILE__, array( $this, 'activate' ) ); 
     32        add_action( 'admin_init', array( $this, 'upgrade_check' ) ); 
     33        add_action( 'admin_init', array( $this, 'add_languages' ) ); 
     34        add_action( 'admin_menu', array( $this, 'add_settings' ) ); 
     35        add_action( 'admin_init', array( $this, 'register_settings' ) ); 
     36        add_filter( 'plugin_action_links', array( $this, 'add_plugin_action_links' ), 10, 2 ); 
     37        add_action( 'add_attachment', array( $this, 'create_post_from_image' ), 20 ); 
     38    } 
     39 
     40    /** 
     41     * Upon activation, we'll want to check for existing plugin options and make sure that 
     42     * defaults are assigned if this is the first time. 
     43     */ 
     44    public function activate() { 
     45        $current_afip_options = get_option( 'afip_options' ); 
     46        $afip_options = array(); 
     47 
     48        if ( empty( $current_afip_options[ 'default_post_status' ] ) ) 
     49            $afip_options[ 'default_post_status' ] = 'publish'; 
     50        else 
     51            $afip_options[ 'default_post_status' ] = $current_afip_options[ 'default_post_status' ]; 
     52 
     53        if ( empty( $current_afip_options[ 'default_post_type' ] ) ) 
     54            $afip_options[ 'default_post_type' ] = 'post'; 
     55        else 
     56            $afip_options[ 'default_post_type' ] = $current_afip_options[ 'default_post_type' ]; 
     57 
     58        if ( empty( $current_afip_options[ 'default_post_format' ] ) ) 
     59            $afip_options[ 'default_post_format' ] = 'standard'; 
     60        else 
     61            $afip_options[ 'default_post_format' ] = $current_afip_options[ 'default_post_format' ]; 
     62 
     63        update_option( 'afip_options', $afip_options ); 
     64 
     65        if ( '0.5' != get_option( 'afip_upgrade_check' ) ) 
     66            update_option( 'afip_upgrade_check', '0.5' ); 
     67    } 
     68 
     69    /** 
     70     * Make sure that we're on the current set of options by checking the version flag and then 
     71     * running through activation accordingly. 
     72     */ 
     73    public function upgrade_check() { 
     74        if ( '0.5' != get_option( 'afip_upgrade_check' ) ) 
     75            $this->activate(); 
     76    } 
     77 
     78    /** 
     79     * Add the text domain for plugin translation 
     80     */ 
     81    public function add_languages() { 
     82        load_plugin_textdomain( 'automated-featured-image-posts', false, basename( dirname( __FILE__ ) ) . '/lang' ); 
     83    } 
     84 
     85    /** 
     86     * Add our settings to the admin menu. 
     87     * 
     88     * Add the sub-menu item under the Settings top-level menu. Of course, since I have to pick 
     89     * such a long plugin name, we'll shorten this to Auto Image Posts instead. 
     90     */ 
     91    public function add_settings() { 
     92        add_options_page( __('Auto Image Posts', 'automatic-featured-image-posts' ), __('Auto Image Posts', 'automatic-featured-image-posts'), 'manage_options', 'automatic-featured-image-posts-settings', array( $this, 'view_settings' ) ); 
     93    } 
     94 
     95    /** 
     96     * Callback function to display main settings view for Automatic Featured Image Posts 
     97     * 
     98     * Additional checks are now implemented for post-formats and post-thumbnails. If a user's theme 
     99     * does not support post thumbnails (featured images), we output a warning so that they are aware 
     100     * of the possible incompatibility. If a user's theme supports post formats, we give an extra option 
     101     * allowing them to choose which format to publish under. 
     102     */ 
     103    public function view_settings() { 
     104        ?> 
     105        <div class="wrap"> 
     106            <div class="icon32" id="icon-options-general"></div> 
     107            <h2><?php _e( 'Automatic Featured Image Posts', 'automatic-featured-image-posts' ); ?></h2> 
     108            <h3><?php _e( 'Overview', 'automatic-featured-image-posts' ); ?></h3> 
     109            <p style="margin-left: 12px;max-width: 640px;"><?php _e('The default <strong>post status</strong> is set to <strong>publish</strong> by default. This means that as soon as you upload a new image through any interface in WordPress, a new post will appear with that image assigned as the featured image.', 'automatic-featured-image-posts' ); ?></p> 
     110            <p style="margin-left: 12px;max-width: 640px;"><?php _e('The default <strong>post type</strong> is set to the most familiar WordPress post type, <strong>Post</strong>. Other custom post types registered by your theme and installed plugins have been automatically detected and will also appear in the drop down menu as options. Note that these custom post types should have support for featured images, or they may not appear as you would like.', 'automatic-featured-image-posts' ); ?></p> 
     111            <?php if ( current_theme_supports( 'post-formats' ) ) : ?><p style="margin-left: 12px;max-width: 640px;"><?php _e( 'Your theme supports <strong>post formats</strong>, so an extra option is available to set which format an automatically created post will be set to. The default is <strong>Standard</strong>. Note that the final display will depend on what is provided by your theme.', 'automatic-featured-image-posts' ); ?></p><?php endif; ?> 
     112            <?php if ( ! current_theme_supports( 'post-thumbnails' ) ) : ?><div class="error" style="margin-left: 12px;max-width: 640px;"><?php _e( '<strong>PLEASE NOTE:</strong> Your current theme does <strong>NOT</strong> support featured images and thus this plugin will be severely limited. Images will be attached to posts after upload, but it may be impossible to see this until featured image support is added to your theme.', 'automatic-featured-image-posts' ); ?></div><?php endif; ?> 
     113            <form method="POST" action="options.php"> 
     114        <?php 
     115            settings_fields( 'afip_options' ); 
     116            do_settings_sections( 'afip' ); 
     117        ?> 
     118            <p class="submit"><input type="submit" class="button-primary" value="<?php _e( 'Save Changes', 'automatic-featured-image-posts' ); ?>"></p> 
     119            </form> 
     120        </div> 
     121        <?php 
     122    } 
     123 
     124    /** 
     125     * Register our settings and add the settings sections and fields. 
     126     */ 
     127    public function register_settings() { 
     128        register_setting( 'afip_options', 'afip_options', array( $this, 'validate_options' ) ); 
     129        add_settings_section( 'afip_section_main', '', array( $this, 'output_section_text' ), 'afip' ); 
     130        add_settings_field( 'afip_default_post_status', __( 'Default Post Status:', 'automatic-featured-image-posts' ) , array( $this, 'output_default_post_status_text' ), 'afip', 'afip_section_main' ); 
     131        add_settings_field( 'afip_default_post_type', __( 'Default Post Type:', 'automatic-featured-image-posts' ), array( $this, 'output_default_post_type_text' ), 'afip', 'afip_section_main' ); 
     132        if ( current_theme_supports( 'post-formats' ) ) 
     133            add_settings_field( 'afip_default_post_format', __( 'Default Post Format:', 'automatic-featured-image-posts' ), array( $this, 'output_default_post_format_text' ), 'afip', 'afip_section_main' ); 
     134    } 
     135 
     136    /** 
     137     * Placeholder for settings section. Would be overkill methinks. 
     138     */ 
     139    public function output_section_text() { } 
     140 
     141    /** 
     142     * Output the text related to selecting the post type to be assigned when a featured 
     143     * image is automatically added. 
     144     */ 
     145    public function output_default_post_type_text() { 
     146        $afip_options = get_option( 'afip_options' ); 
     147        $all_post_types = get_post_types( array( '_builtin' => false ) ); 
     148 
     149        if ( ! isset( $afip_options[ 'default_post_type' ] ) ) 
     150            $afip_options[ 'default_post_type' ] = 'post'; 
     151        ?> 
     152        <select id="afip-default-post-type" name="afip_options[default_post_type]"> 
     153            <option value="post" <?php selected( $afip_options[ 'default_post_type' ], 'post' ); ?>>Post</option> 
     154        <?php foreach( $all_post_types as $p ) : ?><option value="<?php echo esc_attr( $p ); ?>" <?php selected( $afip_options[ 'default_post_type' ], esc_attr( $p ) ); ?>><?php echo esc_html( $p ); ?></option><?php endforeach; ?> 
     155        </select> 
     156        <?php 
     157    } 
     158 
     159    /** 
     160     * Output the text related to selecting the post status to be assigned when a featured 
     161     * image is automatically added. 
     162     */ 
     163    public function output_default_post_status_text() { 
     164        $afip_options = get_option( 'afip_options' ); 
     165 
     166        if ( ! isset( $afip_options[ 'default_post_status' ] ) ) 
     167            $afip_options[ 'default_post_status' ] = 'draft'; 
     168        ?> 
     169        <select id="afip_default_post_status" name="afip_options[default_post_status]"> 
     170            <option value="draft" <?php selected( $afip_options[ 'default_post_status' ], 'draft' ); ?>>Draft</option> 
     171            <option value="publish" <?php selected( $afip_options[ 'default_post_status' ], 'publish' ); ?>>Publish</option> 
     172            <option value="private" <?php selected( $afip_options[ 'default_post_status' ], 'private' ); ?>>Private</option> 
     173        </select> 
     174        <?php 
     175    } 
     176 
     177    public function output_default_post_format_text() { 
     178        global $_wp_theme_features; 
     179        $afip_options = get_option( 'afip_options' ); 
     180 
     181        if ( ! isset( $afip_options[ 'default_post_format' ] ) ) 
     182            $afip_options[ 'default_post_format' ] = 'standard'; 
     183 
     184        ?> 
     185        <select id="afip_default_post_format" name="afip_options[default_post_format]"> 
     186            <option value="standard" <?php selected( $afip_options[ 'default_post_format' ], 'standard' ); ?>>Standard</option> 
     187            <?php 
     188                if ( isset( $_wp_theme_features[ 'post-formats' ] ) ) { 
     189                    foreach ( $_wp_theme_features[ 'post-formats' ] as $post_format_array ){ 
     190                        foreach ( $post_format_array as $post_format ) { 
     191            ?> 
     192                        <option value="<?php echo esc_attr( $post_format ); ?>" <?php selected( $afip_options[ 'default_post_format' ], esc_attr( $post_format ) ); ?>><?php echo esc_html( ucwords( $post_format ) ); ?></option> 
     193            <?php 
     194                        } 
     195                    } 
     196                } 
     197        ?> 
     198        </select> 
     199        <?php 
     200    } 
     201 
     202    /** 
     203     * Validation of a drop down. Hmm. Well, if it isn't on our list, we'll force it onto our list. 
     204     * 
     205     * @param $input array of options that we are attempting to store to the database 
     206     * @return array of validated options that we've confirmed for storing 
     207     */ 
     208    public function validate_options( $input ) { 
     209        global $_wp_theme_features; 
     210        $valid_post_status_options = array( 'draft', 'publish', 'private' ); 
     211        $valid_post_type_options = get_post_types( array( '_builtin' => false ) ); 
     212        $valid_post_type_options[] = 'post'; 
     213        $valid_post_format_options = array( 'standard' ); 
     214 
     215        if ( isset( $_wp_theme_features[ 'post-formats' ] ) ) { 
     216            foreach ( $_wp_theme_features[ 'post-formats' ] as $post_format_array ) { 
     217                foreach ( $post_format_array as $post_format ) { 
     218                    $valid_post_format_options[] = $post_format; 
     219                } 
     220            } 
     221        } 
     222 
     223        if ( ! in_array( $input[ 'default_post_status' ], $valid_post_status_options ) ) 
     224            $input[ 'default_post_status' ] = 'draft'; 
     225 
     226        if ( ! in_array( $input[ 'default_post_type' ], $valid_post_type_options ) ) 
     227            $input[ 'default_post_type' ] = 'post'; 
     228 
     229        if ( ! in_array( $input[ 'default_post_format' ], $valid_post_format_options ) ) 
     230            $input[ 'default_post_format' ] = 'standard'; 
     231 
     232        return $input; 
     233    } 
     234 
     235    /** 
     236     * Make a pretty link for settings under the plugin information in the admin screen 
     237     * 
     238     * Function gratefully taken (and barely modified) from Pippin Williamson's 
     239     * WPMods article: http://www.wpmods.com/adding-plugin-action-links/ 
     240     * 
     241     * @param $links array of links to be shown with the plugin 
     242     * @param $file string of the filename we're working with at the moment 
     243     * @return array Updated links to be shown with the plugin 
     244     */ 
     245    public function add_plugin_action_links( $links, $file ) { 
     246        static $this_plugin; 
     247 
     248        if ( ! $this_plugin ) 
     249            $this_plugin = plugin_basename( __FILE__ ); 
     250 
     251        if ( $file == $this_plugin ) { 
     252            $settings_link = '<a href="' . site_url( '/wp-admin/options-general.php?page=automatic-featured-image-posts-settings' ) . '">' . __( 'Settings', 'automatic-featured-image-posts' ) . '</a>'; 
     253            array_unshift( $links, $settings_link ); 
     254        } 
     255        return $links; 
     256    } 
     257 
     258    /** 
     259     * Hook into the add_attachment action, as this should occur after the image has uploaded and after meta data 
     260     * about the image has been saved. We previously tried using the filter wp_update_attachment_metadata instead, 
     261     * but that just doesn't seem like the right choice. 
     262     * 
     263     * Pulling out extra EXIF areas now, as we weren't really doing anything extra with that, just relying on the 
     264     * data that WordPress already uses. May be fun to revisit sometime though to allow for more data from Lightroom, etc. 
     265     * 
     266     * @param $post_id int The post ID of the attachment that was just added from an image uplad. 
     267     * @return mixed Only used when breaking from the script 
     268     */ 
     269    public function create_post_from_image( $post_id ) { 
     270 
     271        if( ! wp_attachment_is_image( $post_id ) ) 
     272            return; 
     273 
     274        $new_post_category = array(); 
     275 
     276        /* If this image is being added through an existing post, we want to make sure it inherits 
     277         * the category setting from its parent. */ 
     278        if ( $parent_post_id = get_post( $post_id )->post_parent ) { 
     279            if ( $parent_post_categories = get_the_category( $parent_post_id ) ) { 
     280                foreach( $parent_post_categories as $post_cat ) 
     281                    $new_post_category[] = $post_cat->cat_ID; 
     282            } 
     283        } 
     284 
     285        $afip_options = get_option( 'afip_options' ); 
     286        $new_post_date = date( 'Y-m-d H:i:s' ); 
     287        $current_user = wp_get_current_user(); 
     288 
     289        $new_post_content = ''; 
     290 
     291        $new_post_id = wp_insert_post( array( 
     292            'post_title' => get_the_title( $post_id ), 
     293            'post_content' => $new_post_content, 
     294            'post_status' => $afip_options[ 'default_post_status' ], 
     295            'post_author' => $current_user->ID, 
     296            'post_date' => $new_post_date, 
     297            'post_category' => $new_post_category, 
     298            'post_type' => $afip_options[ 'default_post_type' ], 
     299        )); 
     300 
     301        if ( isset( $afip_options[ 'default_post_format' ] ) && 'standard' != $afip_options[ 'default_post_format' ] ) 
     302            set_post_format( $new_post_id, $afip_options[ 'default_post_format' ] ); 
     303 
     304        update_post_meta( $new_post_id, '_thumbnail_id', $post_id ); 
     305        wp_update_post( array( 'ID' => $post_id, 'post_parent' => $new_post_id, 'post_status' => 'inherit' ) ); 
     306    } 
    39307} 
    40  
    41 /* Make sure that we're on the current set of options by checking the version flag 
    42  * and then running through activation accordingly. */ 
    43 add_action( 'admin_init', 'afip_check_and_upgrade' ); 
    44 function afip_check_and_upgrade() { 
    45     if ( '0.4' != get_option( 'afip_upgrade_check' ) ) 
    46         afip_activate(); 
    47 } 
    48  
    49 /* Add language data for the plugin. */ 
    50 add_action( 'admin_init', 'afip_add_languages' ); 
    51 function afip_add_languages() { 
    52     load_plugin_textdomain( 'automated-featured-image-posts', false, basename( dirname( __FILE__ ) ) . '/lang' ); 
    53 } 
    54  
    55 /* Add our settings to the admin menu. 
    56  * 
    57  * Add the sub-menu item under the Settings top-level menu. Of course, since I have to pick 
    58  * such a long plugin name, we'll shorten this to Auto Image Posts instead. */ 
    59 add_action( 'admin_menu', 'afip_add_settings' ); 
    60 function afip_add_settings() { 
    61     add_options_page( __('Auto Image Posts', 'automatic-featured-image-posts' ), __('Auto Image Posts', 'automatic-featured-image-posts'), 'manage_options', 'automatic-featured-image-posts-settings', 'afip_view_settings' ); 
    62 } 
    63  
    64 /* Callback function to display main settings view for Automatic Featred Image Posts */ 
    65 function afip_view_settings() { 
    66 ?> 
    67     <div class="wrap"> 
    68         <div class="icon32" id="icon-options-general"></div> 
    69         <h2><?php _e( 'Automatic Featured Image Posts', 'automatic-featured-image-posts' ); ?></h2> 
    70         <h3><?php _e( 'Overview', 'automatic-featured-image-posts' ); ?></h3> 
    71         <p style="margin-left: 12px;max-width: 640px;"><?php _e( 'Two options are available to you with Automatic Featured Image Posts.', 'automatic-featured-image-posts' ); ?></p> 
    72         <p style="margin-left: 12px;max-width: 640px;"><?php _e('Default Post Status is set to publish by default, which means that as soon as you upload a new image through   any interface in the WordPress admin pages, a new post will appear with that image assigned as the featured image.', 'automatic-featured-image-posts' ); ?></p> 
    73         <p style="margin-left: 12px;max-width: 640px;"><?php _e('The Default Post Type is set to the most familiar WordPress post type, post. The other custom post types installed on your site have been automatically detected and will appear in the drop down menu as options. Note that these custom post types should have support for featured images, or they may not appear as you would like.', 'automatic-featured-image-posts' ); ?></p> 
    74         <form method="POST" action="options.php"> 
    75 <?php 
    76         settings_fields( 'afip_options' ); 
    77         do_settings_sections( 'afip' ); 
    78 ?> 
    79             <p class="submit"><input type="submit" class="button-primary" value="<?php _e( 'Save Changes', 'automatic-featured-image-posts' ); ?>"></p> 
    80         </form></div> 
    81 <?php 
    82 } 
    83  
    84 /*  Register our settings and add the settings sections and fields. */ 
    85 add_action( 'admin_init', 'afip_register_settings' ); 
    86 function afip_register_settings() { 
    87     register_setting( 'afip_options', 'afip_options', 'afip_options_validate' ); 
    88     add_settings_section( 'afip_section_main', '', 'afip_section_text', 'afip' ); 
    89     add_settings_field( 'afip_default_post_status', __( 'Default Post Status:', 'automatic-featured-image-posts' ) , 'afip_default_post_status_text', 'afip', 'afip_section_main' ); 
    90     add_settings_field( 'afip_default_post_type', __( 'Default Post Type:', 'automatic-featured-image-posts' ), 'afip_default_post_type_text', 'afip', 'afip_section_main' ); 
    91 } 
    92  
    93 function afip_section_text() { 
    94     /*  Placeholder for settings section. Would be overkill methinks. */ 
    95 } 
    96  
    97 function afip_default_post_type_text() { 
    98     $afip_options = get_option( 'afip_options' ); 
    99     $all_post_types = get_post_types( array( '_builtin' => false ) ); 
    100  
    101     if ( ! isset( $afip_options[ 'default_post_type' ] ) ) 
    102         $afip_options[ 'default_post_type' ] = array( 'post' ); 
    103 ?> 
    104     <select id="afip-default-post-type" name="afip_options[default_post_type]"> 
    105         <option value="post" <?php selected( $afip_options[ 'default_post_type' ], 'post' ); ?>>Post</option> 
    106         <?php foreach( $all_post_types as $p ) : ?><option value="<?php echo esc_attr( $p ); ?>" <?php selected( $afip_options[ 'default_post_type' ], esc_attr( $p ) ); ?>><?php echo esc_html( $p ); ?></option><?php endforeach; ?> 
    107     </select> 
    108 <?php 
    109 } 
    110  
    111 function afip_default_post_status_text() { 
    112     $afip_options = get_option( 'afip_options' ); 
    113 ?> 
    114     <select id="afip_default_post_status" name="afip_options[default_post_status]"> 
    115         <option value="draft" <?php selected( $afip_options[ 'default_post_status' ], 'draft' ); ?>>draft</option> 
    116         <option value="publish" <?php selected( $afip_options[ 'default_post_status' ], 'publish' ); ?>>publish</option> 
    117         <option value="private" <?php selected( $afip_options[ 'default_post_status' ], 'private' ); ?>>private</option> 
    118     </select> 
    119 <?php 
    120 } 
    121  
    122 /*  Validation of a drop down. Hmm. Well, if it isn't on our list, we'll force it onto our list. */ 
    123 function afip_options_validate( $input ) { 
    124     $valid_post_status_options = array( 'draft', 'publish', 'private' ); 
    125     $valid_post_type_options = get_post_types( array( '_builtin' => false ) ); 
    126     $valid_post_type_options[] = 'post'; 
    127  
    128     if( ! in_array( $input[ 'default_post_status' ], $valid_post_status_options ) ) 
    129         $input[ 'default_post_status' ] = 'draft'; 
    130  
    131     if( ! in_array( $input[ 'default_post_type' ], $valid_post_type_options ) ) 
    132         $input[ 'default_post_type' ] = 'post'; 
    133  
    134     return $input; 
    135 } 
    136  
    137 /*  Make a pretty link for settings under the plugin information. */ 
    138 add_filter( 'plugin_action_links', 'afip_plugin_action_links', 10, 2 ); 
    139 function afip_plugin_action_links( $links, $file ) { 
    140     /*  Function gratefully taken (and barely modified) from Pippin Williamson's 
    141         WPMods article: http://www.wpmods.com/adding-plugin-action-links/ */ 
    142     static $this_plugin; 
    143  
    144     if ( ! $this_plugin ) 
    145         $this_plugin = plugin_basename( __FILE__ ); 
    146  
    147     if ( $file == $this_plugin ) { 
    148         $settings_path = '/wp-admin/options-general.php?page=automatic-featured-image-posts-settings'; 
    149         $settings_link = '<a href="' . get_bloginfo( 'wpurl' ) . $settings_path . '">' . __( 'Settings', 'automatic-featured-image-posts' ) . '</a>'; 
    150         array_unshift( $links, $settings_link );  // add the link to the list 
    151     } 
    152     return $links; 
    153 } 
    154  
    155 /* Hook into the add_attachment action, as this should occur after the image has uploaded 
    156  * and after meta data about the image has been saved. We previously tried using the filter 
    157  * wp_update_attachment_metadata instead, but that just doesn't seem like the right choice. 
    158  * 
    159  * Pulling out extra EXIF areas now, as we weren't really doing anything extra with that, just 
    160  * relying on the data that WordPress already uses. May be fun to revisit sometime though to 
    161  * allow for more data from Lightroom, etc. 
    162 */ 
    163 add_action( 'add_attachment', 'afip_create_post_from_image', 20 ); 
    164 function afip_create_post_from_image( $post_id ) { 
    165  
    166     if( ! wp_attachment_is_image( $post_id ) ) 
    167         return; 
    168  
    169     $new_post_category = array(); 
    170  
    171     /* If this image is being added through an existing post, we want to make sure it inherits 
    172      * the category setting from its parent. */ 
    173     if ( $parent_post_id = get_post( $post_id )->post_parent ) { 
    174         if ( $parent_post_categories = get_the_category( $parent_post_id ) ) { 
    175             foreach( $parent_post_categories as $post_cat ) 
    176                 $new_post_category[] = $post_cat->cat_ID; 
    177         } 
    178     } 
    179  
    180     $afip_options = get_option( 'afip_options' ); 
    181     $new_post_date = date( 'Y-m-d H:i:s' ); 
    182     $current_user = wp_get_current_user(); 
    183  
    184     $new_post_id = wp_insert_post( array( 
    185         'post_title' => get_the_title( $post_id ), 
    186         'post_content' => '', 
    187         'post_status' => $afip_options[ 'default_post_status' ], 
    188         'post_author' => $current_user->ID, 
    189         'post_date' => $new_post_date, 
    190         'post_category' => $new_post_category, 
    191         'post_type' => $afip_options[ 'default_post_type' ], 
    192     )); 
    193     /*  Assign the featured image */ 
    194     update_post_meta( $new_post_id, '_thumbnail_id', $post_id ); 
    195 } 
     308new Automatic_Featured_Image_Posts_Foghlaim(); 
  • automatic-featured-image-posts/trunk/readme.txt

    r516189 r528722  
    33Contributors: jeremyfelt 
    44Donate link: http://www.jeremyfelt.com/wordpress/plugins/automatic-featured-image-posts/ 
    5 Tags: featured image, media, photo, pictures, posts, photoblog, upload, automatic, custom post type, thumbnail 
     5Tags: featured image, media, photo, pictures, posts, photoblog, upload, automatic, custom post type, thumbnail, post thumbnails, post formats 
    66Requires at least: 3.2.1 
    7 Tested up to: 3.3.1 
    8 Stable tag: 0.4 
     7Tested up to: 3.4 
     8Stable tag: 0.5 
    99 
    1010Automatic Featured Image Posts creates a new post with a Featured Image every time an image is uploaded. 
     
    1212== Description == 
    1313 
    14 Automatic Featured Image Posts creates a new post with a Featured Image every time an image is uploaded. Through the plugin settings page, you can set the image to publish and assign itself to one of your other existing custom post types. 
     14Automatic Featured Image Posts creates a new post with a Featured Image every time an image is uploaded. Through the plugin settings page, you can set the image to publish and assign itself to one of your other existing custom post types and/or post formats. 
    1515 
    1616The imagined use case is to make managing a large number of photos through WordPress a little more interesting and a little more fun. 
     
    2424    *  Default is the WordPress post. 
    2525    *  Can choose any custom post type registered in your WordPress installation. 
     26*  Default Post Format 
     27    *  Default is 'standard', which equates to none. 
     28    *  Other options are provided if registered by your theme 
    2629 
    2730== Installation == 
    2831 
    29 1. Upload 'automatic-featured-image-posts' to your plugin directory, usually 'wp-content/plugins/', or install automatically via your WordPress admin page. 
    30 1. Activate Automatic Featured Image Posts in your plugin menu. 
    31 1. If you'd like to change the default post status or post type, configure the plugin using the Auto Image Posts menu under Settings in your admin page. (*See Screenshot*) 
     321.  Upload 'automatic-featured-image-posts' to your plugin directory, usually 'wp-content/plugins/', or install automatically via your WordPress admin page. 
     331.  Activate Automatic Featured Image Posts in your plugin menu. 
     341.  If you'd like to change the default post status or post type, configure the plugin using the Auto Image Posts menu under Settings in your admin page. (*See Screenshot*) 
    3235 
    3336That's it! 
     
    3538== Frequently Asked Questions == 
    3639 
    37 = Why aren't there any FAQs? = 
     40= Why don't I see any of my images? The posts were created. = 
    3841 
    39 *  Because nobody has asked a question yet. 
     42*  More than likely the installed theme does not support featured images (post thumbnails). If this is the case, images are assigned to posts in the background, but there is no interface to display or edit them. 
     43*  A warning will appear on your Automatic Featured Image Posts settings screen if it is detected that featured images are not enabled. 
    4044 
    41 = What's next? = 
     45= Can you put the images in post content instead of setting them as a featured image? = 
    4246 
    43 I solved my use case, so I'm looking for ideas from you. What options do you want to configure? 
     47At this time, no. I spent quite a bit of time exploring a good way to do this, and I'm definitely open to it in the future, but it doesn't appear to be realistic right now. There are so many options for placing an image in your content, I'd hate to think I'd pick the perfect default. 
    4448 
    4549== Screenshots == 
     
    4852 
    4953== Changelog == 
     54 
     55= 0.5 = 
     56*  Add support for Post Formats. If your theme supports it, you can now select to publish as an image, aside, etc... 
     57*  Make sure the attachment is also adhering to core parent/inherit standards after media is uploaded. 
     58*  Add a warning for themes that do not support featured images. 
     59*  Code cleanup, specifically moving everything into its own class to be a good global namespace citizen. 
     60 
    5061= 0.4 = 
    51  
    52 * Switched to use add_attachment action hook, possible avoidance of issues that I couldn't confirm, but could exist, in using wp_update_attachment_metadata 
    53 * Code cleanup, formatting, standards 
     62*  Switched to use add_attachment action hook, possible avoidance of issues that I couldn't confirm, but could exist, in using wp_update_attachment_metadata 
     63*  Code cleanup, formatting, standards 
    5464 
    5565= 0.3 = 
    56  
    57 * An option to assign the posts created through Automatic Featured Image Posts to any of your existing custom post types has been added. 
    58 * General code cleanup & refactoring. 
    59 * Language file update to match new settings. 
     66*  An option to assign the posts created through Automatic Featured Image Posts to any of your existing custom post types has been added. 
     67*  General code cleanup & refactoring. 
     68*  Language file update to match new settings. 
    6069 
    6170= 0.2 = 
    62  
    63 * Images uploaded through the 'edit post' screen are now assigned the categories of that post. Requested by jackthalad. Will be a configurable option in next release. 
     71*  Images uploaded through the 'edit post' screen are now assigned the categories of that post. Requested by jackthalad. Will be a configurable option in next release. 
    6472 
    6573= 0.1 = 
     74*  In which a plugin begins its life. 
    6675 
    67 * In which a plugin begins its life. 
    6876 
    69 == Upgrade Notice === 
     77== Upgrade Notice == 
     78 
     79= 0.5 = 
     80*  NEW - Option to assign automatically created posts to registered post formats. 
     81 
    7082= 0.4 = 
    71  
    72 * Upgrade not required, but things are handled a little differently behind the scenes. 
     83*  Upgrade not required, but things are handled a little differently behind the scenes. 
    7384 
    7485= 0.3 = 
    75  
    76 * NEW - Option to assign posts created through Automatic Featured Image Posts to any of your existing custom post types. 
     86*  NEW - Option to assign posts created through Automatic Featured Image Posts to any of your existing custom post types. 
    7787 
    7888= 0.2 = 
    79  
    80 * Posts created by images uploaded through 'edit post' inherit the category of that existing post. 
     89*  Posts created by images uploaded through 'edit post' inherit the category of that existing post. 
    8190 
    8291= 0.1 = 
    83  
    84 * Initial installation. 
     92*  Initial installation. 
Note: See TracChangeset for help on using the changeset viewer.