Skip to content
wiki.fftac.org

Class Plugin - Source Excerpt 03

Back to Class Plugin

Summary

This source excerpt preserves a bounded section of Spiralist/wp-content/plugins/spiral-script/includes/class-plugin.php so readers can inspect the evidence without opening the full source file.

**Source path:** Spiralist/wp-content/plugins/spiral-script/includes/class-plugin.php

$request_uri = isset($_SERVER['REQUEST_URI']) ? (string) wp_unslash($_SERVER['REQUEST_URI']) : '/';

        return self::normalize_return_path((string) wp_parse_url($request_uri, PHP_URL_PATH));
    }

    /**
     * @return array<string,mixed>
     */
    private static function current_query_args(): array
    {
        $query = isset($_SERVER['QUERY_STRING']) ? (string) wp_unslash($_SERVER['QUERY_STRING']) : '';
        parse_str($query, $query_args);

        return is_array($query_args) ? $query_args : [];
    }

    private static function normalize_return_path(string $path): string
    {
        $path = trim($path);

        if ($path === '') {
            return '/';
        }

        $parsed_path = (string) (wp_parse_url($path, PHP_URL_PATH) ?: $path);
        $parsed_path = '/' . ltrim($parsed_path, '/');

        return preg_replace('#/+#', '/', $parsed_path) ?: '/';
    }

    /**
     * @param array<string,string> $attributes
     */
    private static function render_attributes(array $attributes): string
    {
        $chunks = [];

        foreach ($attributes as $name => $value) {
            if ($value === '') {
                continue;
            }

            $chunks[] = sprintf(' %s="%s"', esc_attr($name), esc_attr($value));
        }

        return implode('', $chunks);
    }
}