A
A
Alexander Grach2021-10-02 08:23:08
WordPress
Alexander Grach, 2021-10-02 08:23:08

How to limit the number of sites on WordPress multisite?

Good afternoon.
The question is. There is a grid of sites on WordPress Multisites. I would like to know how you can limit the number of sites created in this grid?

Answer the question

In order to leave comments, you need to log in

1 answer(s)
V
Vladimir Brumer, 2021-10-03
@V_A_B

Good day.
If you open the wp-admin\network\site-new.php file, you can see how the processing is going:
Developers directly check the action and data transfer without any hooks

if ( isset( $_REQUEST['action'] ) && 'add-site' === $_REQUEST['action'] ) {

after the condition is checked check_admin_referer
i.e. we can connect to this check and disable the creation
Examples

// 1
add_action('check_admin_referer',function($action){
  $blog_count=get_blog_count();
  if(is_network_admin()&&isset($_REQUEST['action'])&&'add-site'===$_REQUEST['action']&&$blog_count==2){
    wp_die(__('Достигнут лимит','VAB'));
  }});

// 2
$blog_count=get_blog_count();
if(is_network_admin()&&isset($_REQUEST['action'])&&'add-site'===$_REQUEST['action']&&$blog_count==2){
    add_action('check_admin_referer',function($action){
        // if('add-blog'!==$action){return;}
        wp_die(__('Достигнут лимит','VAB'));
    });}

// ... другие аналоги


The options are so-so:
In addition, at the end of the file, there are do_action( 'network_site_new_form' );buttons for creating in the markup before output, and then styles and scripts are connected. Can take advantage add_action('network_site_new_form'and stop everything after
Example

копки для создания не будет, а так же не подключится футер
require_once ABSPATH . 'wp-admin/admin-footer.php';

сам вариант собственно:
add_action('network_site_new_form','action_function_name_6729');
function action_function_name_6729(){
  $blog_count=get_blog_count();
  if($blog_count==2){exit();}
}


well, as an option, we can completely mute the page through admin_print_scripts-site-new.php
, though an action was created to connect scripts
Example

add_action("admin_print_scripts-site-new.php",'my_admin_scripts');
function my_admin_scripts(){
  $blog_count=get_blog_count();
  if($blog_count==2){
    exit('<center><strong style="font-size:33px;">'.__('Достигнут лимит создания поддоменов','VAB').'</strong></center>');}}


maybe someone else can add options...

Didn't find what you were looking for?

Ask your question

Ask a Question

731 491 924 answers to any question