Images are displaying as blank images

You should generate the attachment metadata such as width and height — and file path, and also thumbnails, after you created the attachment: Using wp_generate_attachment_metadata(): $attach_id = wp_insert_attachment( $attachment, $filename ); if ( $attach_id ) { require_once ABSPATH . ‘wp-admin/includes/image.php’; $metadata = wp_generate_attachment_metadata( $attach_id, $filename ); wp_update_attachment_metadata( $attach_id, $metadata ); } Using wp_maybe_generate_attachment_metadata(): $attach_id = … Read more

How to disable Media Library?

I did a googles of the issue (using ‘wordpress restrict media access’) and got this link on the first page https://www.wpbeginner.com/plugins/how-to-restrict-media-library-access-to-users-own-uploads-in-wordpress/ Which has this code // Limit media library access add_filter( ‘ajax_query_attachments_args’, ‘wpb_show_current_user_attachments’ ); function wpb_show_current_user_attachments( $query ) { $user_id = get_current_user_id(); if ( $user_id && !current_user_can(‘activate_plugins’) && !current_user_can(‘edit_others_posts ‘) ) { $query[‘author’] = $user_id; … Read more

Correctly using the root directory for media uploads?

The WordPress uploads directory’s path and URL are determined by the wp_upload_dir() function which applies a filter named upload_dir which you can use to fix the double slashes in the attachment URL. So if you turned off the “Organize my uploads into month- and year-based folders” setting, try the following: add_filter( ‘upload_dir’, function ( $data … Read more

Change Image folder Locations

The GUID is not the image’s URL. It typically does end up (coincidentally) being the original URL of the image, because it needs to be a unique identifier – but that’s all WordPress uses it for, as a unique identifier. Your code should successfully update the URLs of the featured images of posts, but only … Read more

wp_enqueue_media is not loading styles

There are some wp-admin styles you need to load. Since I cannot find any way to let wp_enqueue_style() accept url parameters, so I load styles by wp_head hook function here. add_action( ‘wp_head’, ‘load_admin_media_styles’, 10); function load_admin_media_styles(){ // list all style libs the post page of wp-admin loaded, but we may only need to load 2 … Read more

Set different max upload size limits based on file type/extension

This should work: function max_video_size( $file ) { $size = $file[‘size’]; $size = $size / 1024; $type = $file[‘type’]; $is_image = strpos( $type, ‘video’ ) !== false; $limit = 750; $limit_output=”750kb”; if ( $is_image && $size > $limit ) { $file[‘error’] = ‘Video files must be smaller than ‘ . $limit_output; } return $file; } … Read more

WordPress media upload issue could not insert attachment into the database

Try the following solutins: First of all check your WP database size and check whether the size is full according to your hosting provider’s requirement/rule. Second option, add this line into your wp-config.php: define(‘WP_MEMORY_LIMIT’, ‘256M’); Also if you have access to php.ini (or php[version number].ini) file on your server, try to add this line: memory_limit … Read more

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