Is there any function to change the image Author(Uploaded By) in WordPress library?
2 Answers
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;
}