Create a new post using rest api and save featured image using an external image url

Instead of using wp_ajax_ (i.e. admin-ajax.php), how about adding a custom REST API field and then using its update_callback, download the remote image and set it as the post featured image? Working Example add_action( ‘rest_api_init’, ‘wpse_381217’ ); function wpse_381217() { register_rest_field( ‘post’, ‘featured_image_url’, array( // If you don’t want to expose the field in the … Read more

Issue with querying

As I said, your code seems ok, but I think you dont get the current user beforehand. Something like this works: $user = wp_get_current_user(); // get current user, to get the ID $posts = get_posts(array( ‘numberposts’ => -1, ‘post_type’ => ‘shipments’, ‘meta_key’ => ‘customer_user_id’, ‘meta_value’ => $user->ID )); if( $posts ){ echo ‘<ul class=”shipment-posts-list”>’; foreach( … Read more

How to get plugin activate URL to use URL vars?

It turns out getting the URL on activation is not likely through the standard $_GET so WP has hooks for that. Plugin Activation I need to check for back up files stored in wp-content root, if they were created previously during de-activation or update, and copy to the plugin’s folder. register_activation_hook(__FILE__, function() { add_option(‘move_blocks_activated’,’move-blocks’); if( … Read more