Checking if a file is already in the Media Library

global $wpdb; $image_src = wp_upload_dir()[‘baseurl’] . “https://wordpress.stackexchange.com/” . _wp_relative_upload_path( $filename ); $query = “SELECT COUNT(*) FROM {$wpdb->posts} WHERE guid=’$image_src'”; $count = intval($wpdb->get_var($query)); You can use this at the top of your code. Then check the value of $count. If it’s 0, then you can continue adding the attachment

How to show all available images in WP’s media library when using the Polylang plugin?

From this post at wordpress.org/support, the user Chrystl points out: If don’t need to translate your media titles, uncheck this option: In Languages > Settings tab > Media: “Activate languages and translations for media”. And you will access to your entire library by clicking on “Add media” and “Set featured image”. And that indeed did … 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

WordPress Media Uploader events

I don’t think there is. You will have to use some local (browser-based) Javascript code to attach a function to the on-click event of the button. (Not a Javascript expert, but perhaps this will point you in a direction of investigation.)

Each custom image size in custom upload directory?

Philipp, anything is possible if you set your mind to it. You can solve your issue by extending the WordPress image editor class. Note I’m using WordPress 3.7 – I haven’t checked any of the below code in earlier versions and in the latest 3.8 release. Image Editor basics WordPress has two built in classes … 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

How to disable generation of default image sizes for some custom post types?

I think the only solution you have at the moment is to disable all intermediate image sizes: add_filter( ‘intermediate_image_sizes’, ‘__return_empty_array’, 99 ); And then manually generate them, depending on the post type, by hooking into ‘wp_generate_attachment_metadata’, where you do have access to the attachment id (and therefore to it’s parent post): function do_your_stuff( $data, $attachment_id … Read more

Hata!: SQLSTATE[HY000] [1045] Access denied for user 'divattrend_liink'@'localhost' (using password: YES)