WordPress.org

Ready to get started?Download WordPress

Forums

Frontend Uploader
[ patch ] Uploaded Image as featured, and CT posts (3 posts)

  1. guy.kastenbaum
    Member
    Posted 10 months ago #

    I had the same problems as some of you and managed to make it work with little change

    A/ to have my own custom post types updated in the form :

    add_action( 'fu_after_create_post', 'fu_add_meta_post' );
    function fu_add_meta_post( $post_id )
    {   global $scpt_known_custom_fields;//I use super-cpt extension
        foreach($scpt_known_custom_fields["mycpt"] as $cptkey=>$cpttype)
         add_post_meta( $post_id, $cptkey,
           sanitize_text_field($_POST[$cptkey]) ); //todo sanitize better
    ...
    maybe it was already in the doc. anyway, it should.

    B/ "make my image attachment automatically as featured image"

    almost the same :

    [ function fu_add_meta_post( $post_id ) ... continued ... ]
      $attached_image = get_children( "post_parent=$post_id&post_type=attachment&post_mime_type=image&numberposts=1" );
      if ($attached_image)
        foreach ($attached_image as $attachment_id => $attachment) {
          set_post_thumbnail($post_id, $attachment_id));
          break;
         }
    return $post_id;
    }
    // things about themes thumbnails
    add_theme_support( 'post-thumbnails' );
    set_post_thumbnail_size( 75, 50, true);//W,H,crop
    add_image_size( 'single-post-thumbnail', 300, 200 );

    * "get_children" syntax is ugly, any nicer replacement?

    * still wrong as "websta" noticed it,
    the hook fu_after_create_post is done too early.
    HEY! why not hook at a better timing ? :

    My changes in plugins/frontend-uploader/frontend-uploader.php : 
    
    line 321, in _upload_post,  comment hook
       //GK do_action( 'fu_after_create_post', $post_id );
    
    line 419 in _handle_result, hook here
    // Account for successful uploads
      if ( isset( $result['success'] ) && $result['success'] ) {
      // If it's a post
        if ( isset( $result['post_id'] ) ){
          $query_args['response'] = 'fu-post-sent';
          do_action( 'fu_after_create_post', $result['post_id'] );//GK
        }

    I am a bit new to WP, and to forum and github,
    so maybe I need to be fixed too.

    Thanks Rinat Khaziev for this plugin, and for viewing my propositions
    to improve the plugin.

    Guy

    http://wordpress.org/plugins/frontend-uploader/

  2. Lampe
    Member
    Posted 10 months ago #

    Thanks to Rinat for this Plugin!
    And thx also to you, Guy! Moving "do_action( 'fu_after_create_post', $post_id )" into _handle_result worked for me, too (from line 325 to 424 in v 0.5.9.2)

    This code in functions.php just makes the first uploaded image the post thumbnail:

    add_action( 'fu_after_create_post', 'fu_attach_thumbnail' );
    function fu_attach_thumbnail( $post_id ) {
    	$args = array(
    	'post_type' => 'attachment',
    	'post_mime_type' => 'image',
    	'post_parent' => $post_id
    	);
    	$images = get_posts( $args );
    	if($images) {
    		$image=array_shift($images);
    		set_post_thumbnail( $post_id, $image->ID );
    	}
    	foreach($images as $image):
    	 // do something with the other attached images...
    	endforeach;
    }

    The other uploaded images could become a gallery or so...?

  3. Rinat Khaziev
    Member
    Plugin Author

    Posted 10 months ago #

    Hey,

    Thanks for the patch. I'm swamped at my job right now, so can't promise when I'll be able to incorporate it into the next release.

Reply

You must log in to post.

About this Plugin

About this Topic