public static function isFrontendAjax()
    {
        if (self::isAjax()) {
            $referer = '';
            $filename = isset($_SERVER['SCRIPT_FILENAME']) ? $_SERVER['SCRIPT_FILENAME'] : '';

            if (!empty($_REQUEST['_wp_http_referer'])) {
                $referer = wp_unslash($_REQUEST['_wp_http_referer']);
            } elseif (!empty($_SERVER['HTTP_REFERER'])) {
                $referer = wp_unslash($_SERVER['HTTP_REFERER']);
            }

            return strpos($referer, admin_url()) === false && basename($filename) === 'admin-ajax.php';
        }

        return false;
    }
public static function isFrontendAjax()
    {
        if (self::isAjax()) {
            $referer = '';
            $filename = isset($_SERVER['SCRIPT_FILENAME']) ? $_SERVER['SCRIPT_FILENAME'] : '';

            if (!empty($_REQUEST['_wp_http_referer'])) {
                $referer = wp_unslash($_REQUEST['_wp_http_referer']);
            } elseif (!empty($_SERVER['HTTP_REFERER'])) {
                $referer = wp_unslash($_SERVER['HTTP_REFERER']);
            }

            return strpos($referer, admin_url()) === false && basename($filename) === 'admin-ajax.php';
        }

        return false;
    }
public static function isFrontendAjax ( ) { if ( self :: isAjax ( ) ) { $ referer = '' ; $ filename = isset ( $ _SERVER [ 'SCRIPT_FILENAME' ] ) ? $ _SERVER [ 'SCRIPT_FILENAME' ] : '' ; if ( ! empty ( $ _REQUEST [ '_wp_http_referer' ] ) ) { $ referer = wp_unslash ( $ _REQUEST [ '_wp_http_referer' ] ) ; } elseif ( ! empty ( $ _SERVER [ 'HTTP_REFERER' ] ) ) { $ referer = wp_unslash ( $ _SERVER [ 'HTTP_REFERER' ] ) ; } return strpos ( $ referer , admin_url ( ) ) === false && basename ( $ filename ) === 'admin-ajax.php' ; } return false ; }
Attempts to decide if the current Ajax request is happening on the frontend
instead of the backend.
@return boolean
@link https://snippets.khromov.se/determine-if-wordpress-ajax-request-is-a-backend-of-frontend-request/
Attempts to decide if the current Ajax request is happening on the frontend instead of the backend .