Take the 2-minute tour ×
WordPress Development Stack Exchange is a question and answer site for WordPress developers and administrators. It's 100% free, no registration required.

I am wondering if there is a way to manually change the author of images.

I am using Gravity Forms which sets the post author to the current user but does not set them as the author of the images they upload.

I figure there might be a way to add a function which finds the current user and then sets the author of the images they upload to that user.

share|improve this question

closed as off-topic by birgire, ialocin, mrwweb, Pieter Goosen, G. M. Aug 31 at 6:01

This question appears to be off-topic. The users who voted to close gave this specific reason:

If this question can be reworded to fit the rules in the help center, please edit the question.

    
OR is there a way to show only images media gallery linked to a certain post? –  tyler Oct 30 '12 at 18:55

1 Answer 1

up vote 1 down vote accepted
add_action("gform_user_registered", "image_author", 10, 4);
function image_author($user_id, $config, $entry, $user_pass) 
{
$post_id = $entry["post_id"];

$args = array(
'post_parent' => $post_id,
'post_type' => 'attachment',
'post_mime_type' => 'image'
);

$attachments = get_posts($args);
if($attachments) :
    foreach ($attachments as $attachment) : setup_postdata($attachment);
       $the_post = array();
       $the_post['ID'] = $attachment->ID;
       $the_post['post_author'] = $user_id;

       wp_update_post( $the_post );

   endforeach;
endif;    

}
share|improve this answer
    
This finds the user ID after the user has registered and then sets them as the author of the files they uploaded while creating a post via gravity forms. –  tyler Oct 31 '12 at 15:11
    
Tyler, if this solves your Question, please mark it as the correct Answer, so it doesn't hangs on the "Unanswered" category, thanks! –  brasofilo Nov 17 '12 at 16:33

Not the answer you're looking for? Browse other questions tagged or ask your own question.