How to make a image-size selected by default in Media upload – WP v3.5

Try this out. Your add_filter()’s second argument is a function, that will affect the current option via a return: function theme_default_image_size() { return ‘custom-image-size-2’; } add_filter( ‘pre_option_image_default_size’, ‘theme_default_image_size’ ); You could also look into the pre_update_option_{$option} filter, and update the value once, so you don’t need to run this filter every time (may save 0.01s, … Read more

How to trigger a refresh in the media modal

You can checkout this link https://codex.wordpress.org/Javascript_Reference/wp.media jQuery(function($){ // Set all variables to be used in scope var frame, metaBox = $(‘#meta-box-id.postbox’), // Your meta box id here addImgLink = metaBox.find(‘.upload-custom-img’), delImgLink = metaBox.find( ‘.delete-custom-img’), imgContainer = metaBox.find( ‘.custom-img-container’), imgIdInput = metaBox.find( ‘.custom-img-id’ ); // ADD IMAGE LINK addImgLink.on( ‘click’, function( event ){ event.preventDefault(); // If … Read more

Reject upload of wrong-sized images using the Media Uploader

In your handler, if you set ‘error’, the error message will be displayed and will cancel the upload add_filter( ‘wp_handle_upload_prefilter’, ‘custom_upload_filter’ ); function custom_upload_filter( $file ) { $image_info = getimagesize( $file[‘tmp_name’] ); $image_width = $image_info[0]; $image_height = $image_info[1]; if ( $image_with !== 800 || $image_height !== 600 ) { $file[‘error’] = __( ‘Images must be … Read more

“Add Media” button in custom plugin

If you want to add a add media button to your admin panels: You need to use wp_enqueue_media(); add_action ( ‘admin_enqueue_scripts’, function () { if (is_admin ()) wp_enqueue_media (); } ); Then use this js: jQuery(document).ready(function() { var $ = jQuery; if ($(‘.set_custom_images’).length > 0) { if ( typeof wp !== ‘undefined’ && wp.media && … 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/

tech