Rendering the uploaded file in a wp.media object

I presume you’ve fixed this already but (in a blatant attempt to snaffle the bounty and) as mentioned in the comments there’s a simple fix, in your myplugin_meta_box_callback() function change the line $mime_types = array( ‘application/pdf’ ); to $mime_types=”application/pdf”; The library.type option to wp.media expects a string (which can be comma-separated with additional types) not … Read more

Media library to list images only user uploaded

This works for me in order to list the items uploaded by a user on the media library. function users_my_media_only( $wp_query ) { if ( false !== strpos( $_SERVER[ ‘REQUEST_URI’ ], ‘/wp-admin/upload.php’ ) ) { $current_user = wp_get_current_user(); $current_user = $current_user->ID; if ( ! current_user_can( ‘manage_options’ ) ) { global $current_user; $wp_query->set( ‘author’, $current_user->id ); … Read more

Custom post type with a forced fixed aspect ratio image crop

Don, You will have to add support for thumbnails in your functions.php/plugin-file.php //Add Support for Thumbs if ( function_exists( ‘add_theme_support’ ) ) { add_theme_support( ‘post-thumbnails’ ); set_post_thumbnail_size( 960, 276, true ); // default Post Thumbnail dimensions } //Add Thumbnail sizes if ( function_exists( ‘add_image_size’ ) ) { add_image_size( ‘large-thumb’, 960, 276, true ); //960 pixels … Read more

How can you set maximum width for original images?

I was able to solve it using the following code: function my_handle_upload ( $params ) { $filePath = $params[‘file’]; if ( (!is_wp_error($params)) && file_exists($filePath) && in_array($params[‘type’], array(‘image/png’,’image/gif’,’image/jpeg’))) { $quality = 90; list($largeWidth, $largeHeight) = array( get_option( ‘large_size_w’ ), get_option( ‘large_size_h’ ) ); list($oldWidth, $oldHeight) = getimagesize( $filePath ); list($newWidth, $newHeight) = wp_constrain_dimensions( $oldWidth, $oldHeight, $largeWidth, … Read more

Add media with WP-Rest-API v2

SO! This is fun. Keep in mind the WP-API is still very, very much a work-in-progress. Content-Disposition I found an issue reported on the WP-API issue queue about Content-Disposition. This is a required header for posting new media content and there are some very, very strict requirements when it comes to providing this in the … Read more

Update media library files after upload via FTP

Avoid direct upload WordPress doesn’t scan upload directory for new files, instead use WordPress media uploader to add files WordPress automatically creates folder and store them accordingly. But you can use this plugin to import those uploaded files into WordPress, it should help you https://wordpress.org/plugins/add-from-server/