Skip to Content
Menu

get_spam_domain_list()

Return an array of spam domains.

PHP April 1, 2021

Usage

This function runs automatically, so it is not called manually. Is this incorrect?

Was this page helpful? Yes No


    A feedback message is required to submit this form.


    Please check that you have entered a valid email address.

    Enter your email address if you would like a response.

    Thank you for your feedback!

    Source File

    Located in /libs/Security.php on line 354.

    1 Hook

    Find these filters and actions in the source code below to hook into them. Use do_action() and add_filter() in your functions file or plugin.

    Filters
    "nebula_spam_domains"
    Need a new filter hook? Request one here.

    Actions
    This function has no action hooks available. Request one?

    PHP
            public function get_spam_domain_list(){
                //First get the latest spam domain list maintained by Matomo or Nebula's cache of the Matomo list
                $spam_domain_public_file = get_template_directory() . '/inc/data/spam_domain_list.txt'; //Eventually change this to "spam_domain_public_list.txt"
                $spam_domain_public_list = nebula()->transient('nebula_spam_domain_public_list', function($data){
                    $response = $this->remote_get('https://raw.githubusercontent.com/matomo-org/referrer-spam-list/master/spammers.txt'); //Watch for this to change from "master" to "main" (if ever)
                    if ( !is_wp_error($response) ){
                        $spam_domain_public_list = $response['body'];
                    }
    
                    //If there was an error or empty response, try my GitHub repo
                    if ( is_wp_error($response) || empty($spam_domain_public_list) ){ //This does not check availability because it is the same hostname as above.
                        $response = $this->remote_get('https://raw.githubusercontent.com/chrisblakley/Nebula/main/inc/data/spam_domain_list.txt'); //Eventually change this to "spam_domain_public_list.txt"
                        if ( !is_wp_error($response) ){
                            $spam_domain_public_list = $response['body'];
                        }
                    }
    
                    //If either of the above remote requests received data, update the local file and store the data in a transient for 36 hours
                    if ( !is_wp_error($response) && !empty($spam_domain_public_list) ){
                        WP_Filesystem();
                        global $wp_filesystem;
                        $wp_filesystem->put_contents($data['spam_domain_public_file'], $spam_domain_public_list);
    
                        return $spam_domain_public_list;
                    }
                }, array('spam_domain_public_file' => $spam_domain_public_file), HOUR_IN_SECONDS*36);
    
                //If neither remote resource worked, get the local file
                if ( empty($spam_domain_public_list) ){
                    WP_Filesystem();
                    global $wp_filesystem;
                    $spam_domain_public_list = $wp_filesystem->get_contents($spam_domain_public_file);
                }
    
                //If one of the above methods worked, parse the data.
                if ( !empty($spam_domain_public_list) ){
                    $spam_domain_array = array();
                    foreach( explode("\n", $spam_domain_public_list) as $line ){
                        if ( !empty($line) ){
                            $spam_domain_array[] = $line;
                        }
                    }
                } else {
                    $this->ga_send_exception('(Security) Public spammers.txt was not available!', false);
                }
    
                //Next get the latest spam domain "manual" list maintained by Nebula or the local cache of the Nebula list
                $spam_domain_private_file = get_template_directory() . '/inc/data/spam_domain_private_list.txt';
                $spam_domain_private_list = nebula()->transient('nebula_spam_domain_private_list', function($data){
                    $response = $this->remote_get('https://raw.githubusercontent.com/chrisblakley/Nebula/main/inc/data/spam_domain_private_list.txt');
                    if ( !is_wp_error($response) ){
                        $spam_domain_private_list = $response['body'];
                    }
    
                    //If the above remote request received data, update the local file and store the data in a transient for 36 hours
                    if ( !is_wp_error($response) && !empty($spam_domain_private_list) ){
                        WP_Filesystem();
                        global $wp_filesystem;
                        $wp_filesystem->put_contents($data['spam_domain_private_file'], $spam_domain_private_list);
    
                        return $spam_domain_private_list;
                    }
                }, array('spam_domain_private_file' => $spam_domain_private_file), HOUR_IN_SECONDS*36);
    
                //If neither remote resource worked, get the local file
                if ( empty($spam_domain_private_list) ){
                    WP_Filesystem();
                    global $wp_filesystem;
                    $spam_domain_private_list = $wp_filesystem->get_contents($spam_domain_private_file);
                }
    
                if ( !empty($spam_domain_private_list) ){
                    $spam_domain_array = array();
                    foreach( explode("\n", $spam_domain_private_list) as $line ){
                        if ( !empty($line) ){
                            $spam_domain_array[] = $line;
                        }
                    }
                } else {
                    $this->ga_send_exception('(Security) Private spam_domain_private_list.txt was not available!', false);
                }
    
                //Add manual and user-added spam domains
                $manual_nebula_spam_domains = array(
                    'bitcoinpile.com',
                    '84lv.com', //2024
                    '16lv.com', //2024
                    '1-88.vip', //2024
                    'top8.co', //2024
                    'tip8.co', //2024
                    '1-88.live', //2024
                );
                $all_spam_domains = apply_filters('nebula_spam_domains', $manual_nebula_spam_domains);
    
                return array_merge($spam_domain_array, $all_spam_domains);
            }
    

    Override

    This function can not be short-circuited with an override filter. Request one?