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;
}
Related Posts:
- How do I call wp_get_current_user() in a plugin when plugins are loaded before pluggable.php?
- Plugin update error message
- How to Loop Plugin Option Field Set?
- Can we completely remove the WordPress Sitemaps (WordPress 5.5)?
- Set a User as Author of all ‘New Posts’ posted
- Post source link plugin – small modification
- Change destination author link
- HELP: Integrating WP with raw PHP code once published button is hit
- How to redirect Old Post URL to new Post and keep Old post Comments?
- Modifying Footnote Plugin for Descriptive Title Attributes
- I would like to use create a function in my custom plugin to tell WP to use a different header
- New Plugin: Post update pushes a copy as a revision
- How to get images from EDD post?
- How to Replace Words with Hypertext Link But Ignore Previously Existed Links?
- bulk change of image setting “link to” to “link to: image url “
- Display a text message if the field is not found and not if found
- Scope for PHP Variables Assigned in functions.php or a plugin
- Add a plugin before main container
- Executing my function once on a specific time
- How to stop or remove an action being called inside a function of an extended class
- wordpress plugin is not activating from widget
- Date calculations from 2 custom fields
- How to enable specific plugin only based around shop manager role?
- Override Plugin Script Fucnction in WordPress
- Adding a new field to the address field type in gravity forms
- Nested shortcode functions accessing variable
- How to call WordPress function other files
- Conditional attributes and logic per product category
- WP Query. Is there a maximum size?
- Redirect to another page using contact form 7? [closed]
- What is @Action in WordPress?
- Check if variable is set in filter
- Checking the count within a foreach loop
- execute function after one completed
- Need to replace Currency Shortforms
- wp_enqueue_scripts
- How to get specific string/value from an array? php [closed]
- WordPress Stock Update Programatically
- How can I fetch data from another website to my wordpress website with mysql database
- Getting a ressource ID, from a WC_Order_Item_Product/Order
- How to translate wordpress error message
- Api external with wordpress
- All custom widgets are not showing in widget area at the same time
- same user role or copy the user role to be same as the other role
- Adding a Tag Parameter / Filter to My Shortcode
- More gentle way to hook WordPress custom url
- How to add custom function to pluggable.php
- Checkbox show / hide output result
- Custom Logo Link WordPress
- How to convert Currency from USD to other IP Based currency in Php function
- implement custom roles in custom plugin
- How to get current cart values using WC_Shortcodes?
- Attempting to list all product categories and the price range of all products within them
- Cookie value changes back to previous value after changing
- Creating an array from form inputs before it is posted to the options database
- Is there any way to sync Facebook Comments and with comments on WordPress website?
- Custom Plugin: How to Include Install Buttons of other 3rd Party Plugins?
- adding dynamic/multiple slug values in ‘option_none_value’
- How to create algorithm for ordering posts in WordPress?
- How to assign a specific service to a specific provider based on location
- front end editor creation for Restropress plug in – displaying information from a WP admin area, on a different URL
- Easiest way to load/fire a handful of functions, IF checkbox is checked?
- post id or permalink auto-incrementing number and reset everyday
- Is admin section completely customizable in terms of styling?
- How to make the first letter of a post title uppercase, in a plugin?
- Compare Ajax Data Results
- How can I make the search bar in my wordpress site search all of the pages rather than just the blog posts?
- Update (a function) post’s featured image as soon as $image_url changes
- Migrating custom php we wrote from functions.php into a site-specific plugin
- Nested DIV’s across functions in PHP, do not seem to work
- WordPress environment not loading properly
- Every time I use wp_get_current_user() my plugin breaks
- How to replace native comment_count with Comments Evolved aggregate count
- Cannot access variables within a widget
- Is there any wordpress function to update a random post every 10 minutes?
- Calling an custom field from theme option at the frontend
- Posting code inside the post instead of in the template file using shortcode
- WordPress function to add text
- Saving an array to get_options
- Saving plugin data returns “You do not have sufficient permissions to access this page.”
- Metabox Data not saving
- How to add a handler for a button in plugin?
- Can anyone tell me why I can’t edit a plugin when it is installed without having to re-install?
- Doing action based on input from options menu
- Including a PHP file via a function that is part of a plugin?
- Building custom pages with a video player
- Showing author box on post detail page
- How use Dynamic hyperlink on each wordpress post?
- Move related products after product summary? [closed]
- How to tweak a plugin without preventing it from updating
- is_plugin_active() not defined on active plugin, in the thumbnails.php file
- Adminimize Plugin — Is there an alternative to limiting Editor to ‘Appearance > Widgets’ only?
- Integrate Razorpay quick payments plugin with contact form7 plugin
- Woocommerce disable checkout on specific day
- Requires PHP version 5.3.0
- How can I save the selected page in the dropdown after anyone clicks on Save Changes?
- Option value not getting updated until page refresh in WordPress
- Make plugin admin page visible to other roles
- Sort posts by Date (DESC) and by ACF: active_inactive (ASC)
- WordPress Custom Page Blog Template Pagination Problem (Pagination Not Displaying)