Imagify is a great image compression service by the guys who made WP Rocket, as you will probably know you pay for usage with Imagify so you may not want your users all triggering bulk updates and consuming all your API usage. Luckily there is a simple function you can use to restrict access to the Imagify bulk optimizing to a single user or users.
1. What is Imagify?
Imagify is the most advanced image optimization plugin to help you resize and compress images. You can now use its power directly in WordPress to optimize images and reduce the weight of the photos you want to add to your site – all in just one click and without sacrificing their quality.
Imagify is the best WordPress image optimizer. The plugin lets you optimize images in one go with its asynchronous bulk optimization option. You can resize your images on the fly – they will be automatically optimized at the best compression level. If needed, you can always restore your images to their original versions.
On top of optimizing images, you’ll choose the best WebP plugin for WordPress. Imagify also converts your images to WebP, a next-gen format for lighter images that will speed up your WordPress site, improve user experience, and even SEO. Convert WebP will make a difference in image optimization, you’ll see that from yourself.
Lastly, it’s easy to use the best image compression plugin for better site performance. Speed up your WordPress site and improve Core Web Vitals thanks to Imagify’s state-of-the-art image optimization process.
2. Problem
How to restrict Imagify plugin access to a single user (by id).
3. Solution
We will use a simple function to restrict Imagify access to a single user, in this case, the user will have the ID of 1. You will need to have a basic understanding of PHP to use this function and you will also need to know the ID of the user you want to grant access to.
The Function
/** * Filter the user capacity used to operate Imagify. * * @since 1.0 * @author Grégory Viguier * * @param string $capacity The user capacity. * @param string $describer Capacity describer. Possible values are 'manage', 'bulk-optimize', 'manual-optimize', and 'auto-optimize'. * @return string */ add_filter( 'imagify_capacity', 'private_imagify', 10, 2 ); function private_imagify( $capacity, $describer ) { if ( 'manage' !== $describer || 'bulk-optimize' !== $describer ) { return $capacity; } $user_id = get_current_user_id(); if ( 1 !== $user_id ) { // Put your user ID here. return 'nope'; } return $capacity; }
Simply place this function in your theme functions, create a plugin, or use Code Snippets.
Conclusion
With the help of this plugin, we can restrict users to use a plugin from the admin area.
For more information on restricting Imagify settings to a specific user, let us help you accordingly, from start to finish, with one-Time fixes, custom plans, or monthly routines for your WordPress website.