User permissions to upload images

Only logged in user can upload media from front end. Below code will allow users to see only their media files and not others. Put this in your theme’s functions.php file. I hope this helps. add_action( ‘pre_get_posts’, ‘users_own_attachments’); function users_own_attachments( $wp_query_obj ) { global $current_user, $pagenow; if ( $pagenow == ‘upload.php’ || ( $pagenow == … Read more

Resize existing library images

Doing this on your own is actually quite a lot of work. For the sole purpose of regenerating your custom image sizes I would recommend using this plugin: AJAX Thumbnail Rebuild It allows you to loop through your Image Library and regenerate the different image sizes that you selected.

Easing the download of a regularly uploaded pdf

I would use ACF (Advanced Custom Fields) to give the option to add the file to the homepage. Then once a week when he needs to update it he can just go in and replace the existing file by uploading the new one. If the description or anything has to change then you can just … Read more

Create featured image from a remote url when creating a post

The code worked for me; but I defined the function like this: function generate_featured( $post_id ), then I commented out the global $post;; and finally (although this is not mandatory..), in the $file_array, I set name like this: ‘name’ => basename( $image_url ), So: (Note that I intentionally didn’t include the whole code) function generate_featured( … Read more

Why does get_dirsize return the same size?

Under the hood, get_dirsize() uses recurse_dirsize() which uses a transient called dirsize_cache. Try clearing that transient and check again. To do so, you can use one of the following methods: call delete_transient(‘dirsize_cache’); use WP CLI’s wp transient delete use a plugin Looking further through the source code, I think it should be possible to use … Read more

How to load attachment in media library for current user?

If you want to filter the attachments only at the moment they are being loaded via AJAX, for example when you are setting the post featured image, you can make use of: function filter_get_the_user_attachments( $query ) { $current_user = wp_get_current_user(); if ( !$current_user ) { return; } $current_user_id = $current_user->ID; $query[‘author__in’] = array( $current_user_id ); … Read more

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