• As the network administrator (super admin) of a multisite WordPress installation, I have need to push out information from time to time to all the /child site admins, information that I would not necessarily share with all /child site subscribers.

    This might include things like “we are decommissioning this plugin” or “we are having issues with x form; we will get back to you when it has been resolved”, “we have installed new software, which can be found here, and here is a tutorial…”, etc.

    However, my Mother site only maintains a list of subscribers for all the /child sites and does not bother to label any of these users as site admins or in any other way identify them in the overall database.

    This means that there is no option for me to contact all the /child site admins at one time. My alternatives are 1) sending out one email per /child site directed to that /child site’s admins, or 2) maintaining and updating a separate list as I add and remove /child site admins.

    Ugh and ugh.

    There MUST be someone else out there who has experienced this and solved this issue. I am not much of a programmer, just a user of the dashboard, and can fiddle with code at best with extremely explicit directions.

    To anyone who can assist, thank you!

    Best,
    Emily Smith

    The page I need help with: [log in to see the link]

Viewing 3 replies - 1 through 3 (of 3 total)
  • Moderator bcworkz

    (@bcworkz)

    Unless someone comes along with a ready made solution, you may be faced with the need to custom code a solution. All users are managed in one table, regardless of the number of sites. It’s feasible to directly query the DB table for all users assigned the administrator role (not necessarily the same as site administrator). Except it’s a little awkward to work backwards into which sites the users so found are able to administer.

    It is possible to use WP_User_Query to get users assigned administrator role, but such a query will only pertain to the current site. It’s also possible for code to switch to any other site prior to making a query, so one could loop through all the sites, making a user query for each, and doing something for each user so found.

    All users in one table is probably why you are having difficulty with newsletter plugins in your other recent topic. A plugin would need to be multisite aware to work properly. I know custom coding something yourself is beyond your ability, but if you decide to hire a coder to implement the above suggestions, it wouldn’t be much more work to also possibly query for other users and send an email to each. The content of the email could simply be the latest post in a certain category, or the email-certain-users script could be triggered from the post you want to email out.

    Post content intended to be sent via email needs to be carefully composed. A nice looking post in WP can get seriously corrupted when sent via email and rendered by a mail client.

    Thread Starter EmilySmith

    (@emilysmith)

    Thank you for your response. I took a wild stab at building a WordPress plugin that would: 1) get the subsites, then identify the administrators on each subsite, then tag each of those administrators with something (cs-admin), create a dashboard, populate the tagged users into a sortable table in the dashboard that you can download to CSV, and to undo any changes the plugin made if you uninstall it. Could you take a look at this for me? Here is the code:

        <?php
        /* 
            Plugin Name: Multisite User Tagging 
            Description: A plugin to tag users in a WordPress multisite network 
            Author: ChatGPT
            Version: 1.0.0  
        */
    
        // Get all sites in the multisite network using wp_get_sites() function
    
        $siteList = wp_get_sites();
    
        foreach($siteList as $site){
    
        // Query for administrators of each site using get_users() function and add cs-admin user meta tag with add_user_meta() function
    
        foreach($siteList as $site){
    		$args = array('role' => 'administrator');
        	$admins = get_users($args);
        	foreach($admins as $admin){
        		add_user_meta( $admin->ID, 'cs-admin', true ); 
            }  
        }
    
        // Create dashboard page and add it to the admin menu 
    
        function mstagdashboard(){ ?>
    
            <div class="wrap">  
                <h2><?php _e('Tagged Users') ?></h2>  
    
                <
        // Query for tagged users using get_users() function 
    
        $args = array(
            'meta_key' => 'cs-admin',
            'meta_value' => true,
        );
    
        $taggedUsers = get_users($args); ?>  
    
    	<table class="wp-list-table widefat fixed striped posts">  
        	<thead>  
            	<tr>  
                	<th><?php _e('Name') ?></th>  <th><?php _e('Email') ?></th>  <th><?
    
        <?php 
        // Create CSV file with tagged users 
    
        if(isset($_POST['exportCSV'])){  
        	$filename = 'tagged-users.csv';  
            $fp = fopen($filename, 'w');  
    
            $headerRowArray=array();  
            $headerRowArray[]='Name';  
            $headerRowArray[]='Email'; 
        	$headerRowArray[]='Site';
    
        	// Write header row to csv file 
    
        	fputcsv($fp,$headerRowArray);     	      	     	        
    
        // Display tagged users in a table on dashboard page 
    
        <table class="wp-list-table widefat fixed striped posts">  
            <thead>  
                <tr>  
                    <th><?php _e('Name') ?></th>  <th><?php _e('Email') ?></th>  <th><?php _e('Site') ?></th>  
                </tr>  
            </thead>    
    
            <tbody id="the-list">
    
            // Loop through each user and write to csv file 
    
            foreach($taggedUsers as $user){  
                $row=array();  
                $row[]=$user->first_name.' '.$user->last_name; 
    			$row[]=$user->user_email;   
                $row[]=get_bloginfo('url');   
    
                fputcsv($fp,$row);  
            }  
    
            fclose($fp);        
    
            // Download CSV file with tagged users 
    
        	header("Content-type: text/csv");  
        	header("Cache-Control: no-store, no-cache"); 
     
       // Create uninstall hook 
        register_uninstall_hook(__FILE__, 'mstag_uninstall');
    
        // Uninstall function 
        function mstag_uninstall(){
            delete_user_meta('cs-admin');
        }    
    Thread Starter EmilySmith

    (@emilysmith)

    And by took a stab … I mean I had a “conversation” with ChatGPT about this! I’m leery to try it out, unless you think it looks solid.

Viewing 3 replies - 1 through 3 (of 3 total)

The topic ‘Contact Child Site Admins’ is closed to new replies.