Title: Accessing is_multisite() via a Bash script.
Last modified: June 20, 2024

---

# Accessing is_multisite() via a Bash script.

 *  [phoenix26](https://wordpress.org/support/users/phoenix26/)
 * (@phoenix26)
 * [1 year, 11 months ago](https://wordpress.org/support/topic/accessing-is_multisite-via-a-bash-script/)
 * Hi,
 * I need to determine via a Bash script, which WordPress folders are multisites.
   I found this page:
 * [https://developer.wordpress.org/reference/functions/is_multisite/](https://developer.wordpress.org/reference/functions/is_multisite/)
 * but I don’t know how to incorporate it into a simple Bash script. I appreciate
   any advice.
 * I tried adding require_once(“wp-load.php”) in my Bash script, but it didn’t like
   the syntax. If this worked I was then planning to use the is_multisite() function.
 * Thanks,
 * P26

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

 *  Moderator [bcworkz](https://wordpress.org/support/users/bcworkz/)
 * (@bcworkz)
 * [1 year, 11 months ago](https://wordpress.org/support/topic/accessing-is_multisite-via-a-bash-script/#post-17839767)
 * Bash script running on the same machine as the WP installation? AFAIK, to execute
   WP functions from a Bash script [you need WP-CLI (command line interface)](https://wp-cli.org/).
   I don’t know if it’ll return that particular function’s result. Look through 
   its docs to see what’s possible. If all else fails I’d expect it could be extended
   in some way to get the answer you seek.
 *  Thread Starter [phoenix26](https://wordpress.org/support/users/phoenix26/)
 * (@phoenix26)
 * [1 year, 11 months ago](https://wordpress.org/support/topic/accessing-is_multisite-via-a-bash-script/#post-17840422)
 * Thanks [bcworkz](https://wordpress.org/support/users/bcworkz/)
 * Yes, the Bash script runs on the same Linux server as the WP Installation. I 
   can use other WP functions from the WP-CLI – such as wp core update – but there
   seems to be something missing when I try and access is_multisite(). I appreciate
   any further thoughts. Is it because this function is in PHP and I need something
   in the Bash Script to interpret this? Thanks.
 *  Moderator [bcworkz](https://wordpress.org/support/users/bcworkz/)
 * (@bcworkz)
 * [1 year, 11 months ago](https://wordpress.org/support/topic/accessing-is_multisite-via-a-bash-script/#post-17842721)
 * I do not use CLI, but it’s my understanding that it gives you command line access
   to WP functionality. That access however is limited to what the CLI developers
   intended, you don’t get full access to everything. I don’t know if is_multisite()
   is exposed through CLI or not.
 * Even if it were not exposed by default, I’d expect there to be a way to extend
   CLI so that you could get the correct result through CLI. If you desire more 
   information about what’s feasible with CLI, I recommend you start a new topic
   with your WP-CLI specific questions. Tag the topic with “wp-cli” so it’ll attract
   the attention of those who really know WP-CLI.
 * If your PHP installation includes its command line tool, you could create a custom.
   php file that includes wp-load.php, after which your file can call is_multisite()
   directly. Your Bash could in turn execute this .php file via the `php` command
   prompt command.
 * It’s also possible to make a HTTP GET request to /wp-admin/admin-post.php with
   a custom “action” query string. You can add a callback to the action hook named
   after your query string value which calls is_multisite() and returns the appropriate
   result.
 *  Moderator [threadi](https://wordpress.org/support/users/threadi/)
 * (@threadi)
 * [1 year, 11 months ago](https://wordpress.org/support/topic/accessing-is_multisite-via-a-bash-script/#post-17844363)
 * This works for me:
 *     ```wp-block-code
       <?phprequire_once 'wp-load.php';var_dump(is_multisite());
       ```
   
 * Executed via `php test.php` at the console. No WP CLI necessary.
 *  Moderator [Jose Castaneda](https://wordpress.org/support/users/jcastaneda/)
 * (@jcastaneda)
 * THEME COFFEE MONKEY
 * [1 year, 11 months ago](https://wordpress.org/support/topic/accessing-is_multisite-via-a-bash-script/#post-17849373)
 * > but there seems to be something missing when I try and access is_multisite()
 * What is missing? What exactly are you looking/trying to do?
 *  Thread Starter [phoenix26](https://wordpress.org/support/users/phoenix26/)
 * (@phoenix26)
 * [1 year, 11 months ago](https://wordpress.org/support/topic/accessing-is_multisite-via-a-bash-script/#post-17866187)
 * I have a simple bash script that sits on a redhat server and needs to check if
   particular WordPress (6.5.4) folders on the same server are multi-sites or not.
   We have mutliple WordPress sites – some are single sites, some multi-sites. I
   spotted this in the docs:
 * [https://developer.wordpress.org/reference/functions/is_multisite/](https://developer.wordpress.org/reference/functions/is_multisite/)
 * I’ve added my basic code below, but my script doesn’t like the syntax. I’m new
   to bash and PHP and wondered if I can achieve this via extending WP-CLI access
   or if I need my Bash script to call into a PHP function? Any tips/examples of
   the best way to achieve this are most appreciated.
 * vim multisitecheck.sh
 * require_once(“wp-load.php”);
 * if ( is_multisite() )
   thenecho multisite presentfiecho check complete
    -  This reply was modified 1 year, 11 months ago by [phoenix26](https://wordpress.org/support/users/phoenix26/).
 *  Moderator [bcworkz](https://wordpress.org/support/users/bcworkz/)
 * (@bcworkz)
 * [1 year, 11 months ago](https://wordpress.org/support/topic/accessing-is_multisite-via-a-bash-script/#post-17869546)
 * You appear to be mixing PHP and Bash syntax? That won’t work well 😉
    I setup
   a quick test in my WP installation directory. The bash file (test.sh):
 *     ```
       #!/bin/bash
       php ckmulti.php
       ```
   
 * The PHP file (ckmulti.sh):
 *     ```
       <?php
       require_once 'wp-load.php';
       if ( is_multisite() ) echo "multisite present/n";
       else echo "not multisite\n";
       exit();
       ```
   
 * Then at the terminal’s command prompt do `bash test.sh`
    I don’t actually have
   multisite here, but no errors were thrown and the correct message appears in 
   the terminal. Presumably the other message would appear with multisite.
 * If everything is not in the same folder, be sure all paths are correct. Also 
   be sure the files are marked as executable. If you need your Bash script to conditionally
   do something based on what PHP determines, the exit() function should be passed
   an appropriate integer value (`1` abnormal completion or `0` normal completion).
   Then the Bash script might be more like:
 *     ```
       #!/bin/bash
       if php ckmulti.php ; then
           echo "is multisite"
       else
           echo "not multisite"
       fi
       ```
   
 * And the PHP:
 *     ```
       <?php
       require_once 'wp-load.php';
       if ( is_multisite() ) $status = 0;
       else $status = 1;
       exit( $status );
       ```
   
 *  Thread Starter [phoenix26](https://wordpress.org/support/users/phoenix26/)
 * (@phoenix26)
 * [1 year, 11 months ago](https://wordpress.org/support/topic/accessing-is_multisite-via-a-bash-script/#post-17877597)
 * Brilliant – thanks [bcworkz](https://wordpress.org/support/users/bcworkz/). That
   really helps my understanding of PHP and Bash working together.
 * I also found this cmd that will do it via the WP CLI: wp core is-installed –network
 * Thanks again.

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

The topic ‘Accessing is_multisite() via a Bash script.’ is closed to new replies.

 * In: [Developing with WordPress](https://wordpress.org/support/forum/wp-advanced/)
 * 8 replies
 * 4 participants
 * Last reply from: [phoenix26](https://wordpress.org/support/users/phoenix26/)
 * Last activity: [1 year, 11 months ago](https://wordpress.org/support/topic/accessing-is_multisite-via-a-bash-script/#post-17877597)
 * Status: not resolved

## Topics

### Topics with no replies

### Non-support topics

### Resolved topics

### Unresolved topics

### All topics
