Uploading media with the REST API

This is not possible via the API; you need to fetch the image yourself, and send the data to the API yourself. Blockquote – This quotes Ryan on the GitHub–issue mentioned in @Dan (deleted) answer. How to side load images Note that the media_sideload_image() return value can be an instance of \WP_Error as well. You … Read more

How to change upload directory in wp_handle_upload

Here’s a complete example for how we do it in Easy Digital Downloads: /** * Set Upload Directory * * Sets the upload dir to edd. This function is called from * edd_change_downloads_upload_dir() * * @since 1.0 * @return array Upload directory information */ function edd_set_upload_dir( $upload ) { $upload[‘subdir’] = ‘/edd’ . $upload[‘subdir’]; $upload[‘path’] … Read more

What is in media-template.php, and how does it work?

Those are javascript templates that get compiled into HTML by a javascript library. I think WP uses underscore.js. Let’s say you write a jQuery plugin, and you have to append HTML code to the document. Using such templates you can avoid stuffing that HTML code inside huge concatenated strings within your javascript code, and put … Read more

What’s the best way to use the Featured Image for responsive web design?

Step 1: Define two custom image sizes, e.g.: <?php add_image_size( ‘normal-thumbnail’, 400, 300, false ); // Default image size add_image_size( ‘mobile-device-thumbnail’, 200, 150, false ); // Mobile-device image size ?> Step 2: Implement your chosen means to determine client. There are several ways, and which method you use is outside the scope of this question. … Read more

How to stop form resubmission on page refresh

Instead of … } else { echo “<p>Your file has been uploaded.</p>”; } … redirect to another address on success: } else { $new_url = add_query_arg( ‘success’, 1, get_permalink() ); wp_redirect( $new_url, 303 ); exit; } Status code 303 triggers a GET request: This method exists primarily to allow the output of a POST-activated script … Read more

WP-CLI – Selecting PHP version

Got the same problem! Just switch the php version. On my server PHP5.6 was default for apache, while CLI was configured with PHP7.1. After installing WP-CLI, with wp –info I got this result: PHP binary: /usr/bin/php7.1 PHP version: 7.1.5-1+deb.sury.org~xenial+1 php.ini used: /etc/php/7.1/cli/php.ini WP-CLI root dir: phar://wp-cli.phar And when i used the wp core install command … Read more