Remove Featured Image & All Media Uploaded to the Post

You can try using the function get_attached_media() like this: add_action( ‘before_delete_post’, ‘wps_remove_attachment_with_post’, 10 ); function wps_remove_attachment_with_post( $post_id ) { /** @var WP_Post[] $images */ $images = get_attached_media( ‘image’, $post_id ); foreach ( $images as $image ) { wp_delete_attachment( $image->ID, true ); } } Note that this will permanently delete all the image files related to … Read more

Remove delete-attachment button for every media

Rather than focusing on the button itself, focus on what you want users to do. If you don’t want your users to be able to delete media, and you are also comfortable with them not being able to delete other post types (Posts, Pages, etc.), you can create a custom role for these users. <?php … Read more

In the media Rest API, what is “missing_image_sizes”?

Basically, it corresponds to missing thumbnails or custom-sized images in your media library. And it’s (by default) a private field in the REST API and the value is one or more image sizes as returned by wp_get_registered_image_subsizes(). And the function which is used with that field is wp_get_missing_image_subsizes() which returns: (array) An array of the … Read more

Upload media only to DB

Yes, out of the box WordPress stores images and other uploads only as files. Although it could be, theoretically, possible to change this behavior by tapping inton wp_handle_upload() or _wp_handle_upload() and related functions, I think it would be too complex and unreliable. Besides,I think it wouldn’t be a good idea for performance reasons in case … Read more

Returning data instead of echoing/printing

The problem with your code, as you mentioned, is that you are outputting the images via your print_r function, and you need to instead build a string to return, which is displayed in place of the shortcode. Give this a try: function get_media () { $attachments = get_posts([ ‘post_type’ => ‘attachment’, ‘numberposts’ => -1, ‘post_status’ … Read more

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