Restrict Imagify settings to a specific user

Contents

Build your own WordPress Support Plan

Expert, yet affordable WordPress support & maintenance plans.
View our pricing

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.

Written By
Adam
Founder of WP Helper.
You will also like these articles

Relax Knowing Your WordPress Site Is Secure & Running Smoothly 24/7

Let us manage your WordPress site, everything from security to updates will be taken care of. Support plans also come with dedicated support so we can do anything from adding content to customising your site for you.

Same Day Professional WordPress Support

Get WordPress Support Today

Need help with a single WordPress problem, today? We can help with anything from adding analytics tracking code to site hack recovery. Full money back guarantee on all jobs.

1. Submit a Support Request

Use our support ticket form below to send details of your problem to our developers.

2. Get a Quote

We will review your request and provide a quote within 24 hours (but usually within a few hours).

3. We fix your WordPress problem

Our team will begin fixing your WordPress problem the same day.

4. 100% Money Back Guarantee

If we can’t fix the problem for the amount quoted we will refund you 100%.

  • Do you have a screenshot of the issue or have a copy of the theme or plugin that is at fault? If you want to upload php, html or css please zip first.
    Drop files here or
    Accepted file types: jpg, jpeg, png, pdf, zip, gzip, rar, doc, txt, Max. file size: 15 MB, Max. files: 10.