Delete Associated Media Upon Page Deletion

How about this? It adapts an example on the get_posts() function reference page. function delete_post_media( $post_id ) { $attachments = get_posts( array( ‘post_type’ => ‘attachment’, ‘posts_per_page’ => -1, ‘post_status’ => ‘any’, ‘post_parent’ => $post_id ) ); foreach ( $attachments as $attachment ) { if ( false === wp_delete_attachment( $attachment->ID ) ) { // Log failure … Read more

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

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