The most performant way to do this is probably by hooking into map_meta_cap to conditionally disallow the install_plugins capability. There are no database calls involved with that.
Here’s an (untested) example:
add_filter( 'map_meta_cap', 'wpse291964_limit_plugins', 10, 2 );
function wpse291964_limit_plugins( $caps, $cap ) {
if ( 'install_plugins' === $cap ) {
$plugins = get_plugins();
// Only allow 10 plugins to be installed.
if ( count( $plugins ) > 10 ) {
$caps[] = 'do_not_allow';
}
}
return $caps;
}
I recommend you to watch this video by John Blackbourn to learn more about map_meta_cap and friends.
Related Posts:
- Remote upload file to server B
- Replacing Icons in the Dashboard
- Using functions from a plugin in your theme
- Keep one user logged for a year?
- Is the WordPress HTTPS Plugin Still Safe To Use? [closed]
- Post source link plugin – small modification
- How to turn off email you receive when registered?
- Execute a function using ajax
- How do you auto-activate plugins from child themes
- While Using Static Pages, How Can I Get /blog into the URL of Each Post?
- Fatal error: Class not found in
- What’s the point of using WordPress’s built in admin-ajax.php?
- Converting a simple plugin to be placed inside of functions.php
- Using plugin functionality in external php script not working
- greatest() function returns undefined property
- How to get post URL in the_content filter?
- May i Use ShortCode in Template?
- Pass info from functions.php to plugin
- add_query_arg not working
- Inserting HTML tag with ACF into shortcode
- How to stop or remove an action being called inside a function of an extended class
- How to Display a Plugin function (content) on frontpage using index.php
- Theme my Login plugin, how to update fields
- Date calculations from 2 custom fields
- How to debug error message: Cannot modify header information
- How to enable specific plugin only based around shop manager role?
- get current date + 90 days and checking every day
- Adding a new field to the address field type in gravity forms
- How to create an input field, and base the output on spreadsheet data? [closed]
- Nested shortcode functions accessing variable
- Calling an attribute from a plugin shortcode
- Customize permalink wordpress category id
- Admin style for just one plugin in dashboard
- Which file of wordpress manage plugins functionalities?
- How to create an option page for this simple plugin
- What is @Action in WordPress?
- the_tags : can we insert a class
- WordPress checkbox and Illegal string offset
- Undefined index: action plugin problem
- PHP script from functions php is loaded via admin-ajax to div…and the result is 0, not the desired content
- JQuery prepend a function
- Adding class to last list item? Not WP generated
- I changed .live() to .on() but change is not reflected on the server
- wp_enqueue_scripts
- How can I fetch data from another website to my wordpress website with mysql database
- Send email with list of active plugins upon activation/deactivation
- Set up functions to be overridden without using function_exists() by short-circuiting them?
- how to change wp-admin url using function file
- Add action to custom Function
- Help with a function in a widget
- Changing plugin options from theme functions file?
- Expected ‘add_filter’ (T_STRING)
- Could not add ‘LoginLogout’ link using BAW login logout plugin
- My widget won’t update its values when save is clicked
- Adding a pagenavi to function for displaying bookmarks
- How do I create pages within a WordPress post?
- What is the most efficient way of adding additional functionaliy for admin only
- Error Metabox Warning: call_user_func() expects parameter 1 to be a valid callback
- Replace the_content with ACF Flexible Content via function
- Create category for each user
- Alternative Hook to the_content for Changing Background Color
- Unpublished Pages Failing To Appear On Custom Path
- Post source link plugin – small modification
- Is there any way to sync Facebook Comments and with comments on WordPress website?
- Cannot pass value variable to WP AJAX functions
- Sharing varible between two add_actions
- Easiest way to load/fire a handful of functions, IF checkbox is checked?
- Block plugin update possibilities (but not by hiding notifications)
- Execute function activate/deactivate plugin in specific pages
- Plugin function in child theme
- post id or permalink auto-incrementing number and reset everyday
- Override filter variable not working
- Soflyy WP All Import Custom File Download Issue
- Get a Taxonomy values in an array
- Shows warning when enable “wp_gallery_custom_links” plugin with Themify Builder
- WordPress environment not loading properly
- Place content inside the Post Loop
- How to replace native comment_count with Comments Evolved aggregate count
- Follow author on muti-user WordPress site
- Hook into install email
- wordpress Shortocode running twice?
- Is there any wordpress function to update a random post every 10 minutes?
- Calling an custom field from theme option at the frontend
- pluggable function in theme, to be overridden by plugin
- How to add submenu to WordPress plugin in the same Directory of main Plugin?
- Calling a function from a link in WordPress
- Saving an array to get_options
- Contact Form 7: custom validation [closed]
- Showing author box on post detail page
- add query string to all pages after user logged in
- Simple WordPress function / plugin to redirect a site
- Remove base from the custom post type URL [duplicate]
- is_plugin_active() not defined on active plugin, in the thumbnails.php file
- How to declare this function correctly?
- Requires PHP version 5.3.0
- Make plugin admin page visible to other roles
- Show WooCommerce products based on query parameters on redirect
- Secure way to add JS Script to WordPress filesystem
- How to get next day date of a specific day
- How to access a function declared in child theme’s functions file in a plugin file?