public function getVar(string $specific_ep = '', $default = null)
    {
        if (!did_action('wp')) {
            throw new Exception('`wp` action not done yet.');
        }
        $WP       = $GLOBALS['wp']; // WP class instance.
        $WP_Query = $GLOBALS['wp_the_query']; // Main.

        if (!get_option('permalink_structure')) {
            return $default; // Impossible.
        } elseif (empty($WP->request) || empty($WP_Query->query_vars)) {
            return $default; // Impossible.
        } elseif (!($request_components = explode('/', $WP->request))) {
            return $default; // Impossible.
        }
        foreach ($request_components as $_maybe_ep) {
            if (!$_maybe_ep) {
                continue; // It's empty, bypass.
            } elseif ($specific_ep && $_maybe_ep !== $specific_ep) {
                continue; // Not what we're looking for.
            } elseif (!isset($WP_Query->query_vars[$_maybe_ep])) {
                continue; // It's not an endpoint; query var not set.
            } else {
                return get_query_var($_maybe_ep, $default);
            }
        } // unset($_maybe_ep); // Housekeeping.

        return $default;
    }
public function getVar(string $specific_ep = '', $default = null)
    {
        if (!did_action('wp')) {
            throw new Exception('`wp` action not done yet.');
        }
        $WP       = $GLOBALS['wp']; // WP class instance.
        $WP_Query = $GLOBALS['wp_the_query']; // Main.

        if (!get_option('permalink_structure')) {
            return $default; // Impossible.
        } elseif (empty($WP->request) || empty($WP_Query->query_vars)) {
            return $default; // Impossible.
        } elseif (!($request_components = explode('/', $WP->request))) {
            return $default; // Impossible.
        }
        foreach ($request_components as $_maybe_ep) {
            if (!$_maybe_ep) {
                continue; // It's empty, bypass.
            } elseif ($specific_ep && $_maybe_ep !== $specific_ep) {
                continue; // Not what we're looking for.
            } elseif (!isset($WP_Query->query_vars[$_maybe_ep])) {
                continue; // It's not an endpoint; query var not set.
            } else {
                return get_query_var($_maybe_ep, $default);
            }
        } // unset($_maybe_ep); // Housekeeping.

        return $default;
    }
public function getVar ( string $ specific_ep = '' , $ default = null ) { if ( ! did_action ( 'wp' ) ) { throw new Exception ( '`wp` action not done yet.' ) ; } $ WP = $ GLOBALS [ 'wp' ] ; // WP class instance. $ WP_Query = $ GLOBALS [ 'wp_the_query' ] ; // Main. if ( ! get_option ( 'permalink_structure' ) ) { return $ default ; // Impossible. } elseif ( empty ( $ WP -> request ) || empty ( $ WP_Query -> query_vars ) ) { return $ default ; // Impossible. } elseif ( ! ( $ request_components = explode ( '/' , $ WP -> request ) ) ) { return $ default ; // Impossible. } foreach ( $ request_components as $ _maybe_ep ) { if ( ! $ _maybe_ep ) { continue ; // It's empty, bypass. } elseif ( $ specific_ep && $ _maybe_ep !== $ specific_ep ) { continue ; // Not what we're looking for. } elseif ( ! isset ( $ WP_Query -> query_vars [ $ _maybe_ep ] ) ) { continue ; // It's not an endpoint; query var not set. } else { return get_query_var ( $ _maybe_ep , $ default ) ; } } // unset($_maybe_ep); // Housekeeping. return $ default ; }
Get endpoint query var.

@since 17xxxx Endpoint utils.

@param string $specific_ep Specific endpoint?
@note If empty, returns QV for first endpoint detected.

@param mixed $default Default return value, passed to `get_query_var()`.

@return mixed|null Response from `get_query_var()`, else `$default`.
Get endpoint query var .