Nk_list_all_wp

Home

Description

This function, nk_list_all_wp(), lists all the domains on the server that have a WordPress installation by checking if a wp-config.php file exists in their document root directory.

Here’s how the function works:

It calls the nk_list_all_domains() function to get a list of all the domains on the server. For each domain, it gets the document root path by calling the nk_docroot() function with the domain as an argument and assigns the result to the docroot variable. It checks if a wp-config.php file exists inside the docroot path by using the -f file test. If the file exists, it prints the domain name using echo. If the file doesn’t exist, it does nothing and moves on to the next domain in the loop. The output of this function will be a list of all the domains on the server that have a wp-config.php file in their document root directory, indicating the presence of a WordPress installation.

Example

[root@cloudvpsserver public_html]# nk_list_all_wp
nkern.net

Code

nk_list_all_wp() {
# For every domain on the server. Found via nk_list_all_domains
for domain in $(nk_list_all_domains); do
docroot="$(nk_docroot "$domain")"

# If wp-config.php exists inside of docroot
if [ -f "$docroot"/wp-config.php ]; then
    # Then print out the domain name.
    echo "$domain"
fi
# Otherwise do nothing.
done
}

Author: Nichole Kernreicht

Created: 2023-04-09 Sun 21:27