Add control in image detail panel

You can use this code function your_slug_edit_media_custom_checkbox( $form_fields, $post ) { $form_fields[‘custom_field’] = array( ‘label’ => ‘Custom Field’, ‘input’ => ‘text’, ‘value’ => get_post_meta( $post->ID, ‘_custom_field’, true ) ); return $form_fields; } function your_slug_save_media_custom_field( $post, $attachment ) { update_post_meta( $post[‘ID’], ‘_custom_field’, $attachment[‘custom_field’] ); return $post; } add_filter( ‘attachment_fields_to_edit’, ‘edit_media_custom_checkbox’, 11, 2 ); add_filter( ‘attachment_fields_to_save’, ‘save_media_custom_checkbox’, … Read more

Allowing for multiple template views on the Gallery Settings page when using the Visual Editor

It appears that the templates live in script form <script type=”text/html” id=”tmpl-my-custom-gallery-setting”> To render the above template would require wp.media.template(‘my-custom-gallery-setting’)(view) Since we’re replacing the template: logic then all we need to do is store a list of template IDs. if (!wp.media.gallery.templates) wp.media.gallery.templates = [‘gallery-settings’]; wp.media.gallery.templates.push(‘my-custom-gallery-setting’); Then loop through all available views wp.media.view.Settings.Gallery = wp.media.view.Settings.Gallery.extend({ template: … Read more

Different upload directory based on post type in a theme

If i understand your question right you want a function within your theme that adds directories for the current post_type? like: uploads/post_type_name. if so here is a function for that: function wpse_16722_type_upload_dir( $args ) { // Get the current post_id $id = ( isset( $_REQUEST[‘post_id’] ) ? $_REQUEST[‘post_id’] : ” ); if( $id ) { … Read more

Best approach when modifying the Media Manager

This is my go to snippet for things like this. <?php add_action(‘print_media_templates’, function(){ // define your backbone template; // the “tmpl-” prefix is required, // and your input field should have a data-setting attribute // matching the shortcode name ?> <script type=”text/html” id=”tmpl-my-custom-gallery-setting”> <label class=”setting”> <span><?php _e(‘My setting’); ?></span> <select data-setting=”my_custom_attr”> <option value=”foo”> Foo </option> … Read more

How can I change Max Embed Size in WordPress 3.5?

See the function wp_embed_defaults() in wp-includes/media.php: function wp_embed_defaults() { if ( ! empty( $GLOBALS[‘content_width’] ) ) $width = (int) $GLOBALS[‘content_width’]; if ( empty( $width ) ) $width = 500; $height = min( ceil( $width * 1.5 ), 1000 ); return apply_filters( ’embed_defaults’, compact( ‘width’, ‘height’ ) ); } To change these values filter embed_defaults: add_filter( … Read more

How to delete resized (cropped) image uploads and prevent future resizing?

A majority of the answers covered how to stop creating future default image sizes but this doesnt account for creating any custom sizes in your theme but here is another solution to add to functions.php: function wpse_240765_unset_images( $sizes ){ unset( $sizes[ ‘thumbnail’ ]); unset( $sizes[ ‘medium’ ]); unset( $sizes[ ‘medium_large’ ] ); unset( $sizes[ ‘large’ … Read more