2

Is there any function to change the image Author(Uploaded By) in WordPress library?

enter image description here

2 Answers 2

0

You can use wp_update_post()

$my_post = array(
'ID' => $post_id,
'post_author' => $user_id,
);
wp_update_post( $my_post );

Or change image's author via a function using GravityForms uploader

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;    

}
4

In the screenshot you provided, click on the Edit more detail. this will redirect you to attachment's page.

Then, click on the Screen's options on the top of screen, and check the Author box. A new box will be added to your page.

Screen's option box in edit attachment page

You can there choose an author for your attachment, and save the page.

If you want to do this programmatically on upload or edit, you can use the add_attachment or edit_attachment filter as shown in this answer.

Otherwise, to change it manually, you can use the wp_update_post() function. A photo is an attachment, therefore a post type, so you can change its author by passing an author to post_author argument of this function.

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

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