Add metabox with media uploader in a custom post type [duplicate]

I am working on something similar. This is for a podcast upload meta-box. Returns the url to the file. Here is what I have so far: //Add Metabox add_action(‘add_meta_boxes’, ‘add_upload_file_metaboxes’); function add_upload_file_metaboxes() { add_meta_box(‘swp_file_upload’, ‘File Upload’, ‘swp_file_upload’, ‘podcasts’, ‘normal’, ‘default’); } function swp_file_upload() { global $post; // Noncename needed to verify where the data originated … Read more

Extend WP Customizer to make multiple image selection possible

What I eventually did was extending the WP_Customize_Control class as follows: <?php if (!class_exists(‘WP_Customize_Image_Control’)) { return null; } class Multi_Image_Custom_Control extends WP_Customize_Control { public function enqueue() { wp_enqueue_style(‘multi-image-style’, get_template_directory_uri().’/css/multi-image.css’); wp_enqueue_script(‘multi-image-script’, get_template_directory_uri().’/js/multi-image.js’, array( ‘jquery’ ), rand(), true); } public function render_content() { ?> <label> <span class=”customize-control-title”>Image</span> </label> <div> <ul class=”images”></ul> </div> <div class=”actions”> <a class=”button-secondary upload”>Add</a> … Read more

Append button to WordPress Image Details modal

Here’s an alternative technique to manipulating the template. I adapted the solution below from this post. In the approach below, the print_media_templates hook, which is triggered at the bottom of wp-includes/media-template.php, is used to output some JavaScript that removes the default image details underscores template (<script type=”text/html” id=”tmpl-image-details”>) and replaces it with a duplicated version … Read more

Impose a Maximum Limit on Image height and width upload size

Basically you just retrieve the info via getimagesize(), a basic PHP function, a then handle your errors with notes. The plugin A basic plugin as a starting point: <?php /** Plugin Name: (#67107) »kaiser« Restrict file upload via image dimensions */ function wpse67107_restrict_upload( $file ) { $file_data = getimagesize( $file ); // Handle cases where … Read more

Trigger JS when featured image upload window is opened in admin

After some digging I discovered that wp.media.featuredImage.frame() was what I was looking for: wp.media.featuredImage.frame().on(‘open’,function() { // Clever JS here }); I then discovered that the select event fires once you’ve clicked on the ‘Set featured image’ button, not when you’ve clicked on thumbnail, which was what I was after. So I bound my events to … Read more

Disable resizing of gif when uploaded

image_make_intermediate_size was not the hook I was looking for, but intermediate_image_sizes_advanced. Here is a working code: function disable_upload_sizes( $sizes, $metadata ) { // Get filetype data. $filetype = wp_check_filetype($metadata[‘file’]); // Check if is gif. if($filetype[‘type’] == ‘image/gif’) { // Unset sizes if file is gif. $sizes = array(); } // Return sizes you want to … Read more