-
Notifications
You must be signed in to change notification settings - Fork 5
/
Copy pathstubs.php
151 lines (117 loc) · 3.84 KB
/
stubs.php
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
<?php declare(strict_types = 1);
use RemoteDataBlocks\Tests\Mocks\MockWordPressFunctions;
function add_action(): void {}
function add_filter(): void {}
function do_action( string $action, mixed ...$args ): void {
MockWordPressFunctions::do_action( $action, ...$args );
}
function apply_filters( string $filter, mixed $thing, mixed ...$args ): mixed {
return MockWordPressFunctions::apply_filters( $filter, $thing, ...$args );
}
function esc_html( string $text ): string {
return $text;
}
function esc_html__( string $text ): string {
return apply_filters( 'esc_html__', $text );
}
function register_block_pattern( string $_name, array $_options ): void {
// Do nothing
}
function is_multisite(): void {
// Do nothing
}
function plugins_url( string $path ): string {
return sprintf( 'https://example.com/%s/', $path );
}
function sanitize_title( string $title ): string {
return str_replace( ' ', '-', strtolower( $title ) );
}
function sanitize_title_with_dashes( string $title ): string {
return preg_replace( '/[^a-z0-9-]/', '-', sanitize_title( $title ) );
}
function sanitize_text_field( string $text ): string {
// phpcs:ignore WordPressVIPMinimum.Functions.StripTags.StripTagsOneParameter
$text = strip_tags( $text );
$text = trim( $text );
$text = stripslashes( $text );
return htmlspecialchars( $text, ENT_QUOTES, 'UTF-8' );
}
function sanitize_email( string $email ): string {
$email = trim( $email );
$email = strtolower( $email );
return filter_var( $email, FILTER_SANITIZE_EMAIL );
}
function sanitize_url( string $url ): string {
$url = trim( $url );
$url = filter_var( $url, FILTER_SANITIZE_URL );
return preg_replace( '/[^-a-zA-Z0-9:_.\/@?&=#%]/', '', $url );
}
function __( string $text ): string {
return $text;
}
function wp_strip_all_tags( string $string ): string {
return $string;
}
function is_wp_error( mixed $thing ): bool {
return $thing instanceof \WP_Error;
}
function wp_parse_url( string $url ): array|false {
// phpcs:ignore WordPress.WP.AlternativeFunctions.parse_url_parse_url
return parse_url( $url );
}
function wp_json_encode( mixed $data ): string {
// phpcs:ignore WordPress.WP.AlternativeFunctions.json_encode_json_encode
$string = json_encode( $data );
return $string ?: '';
}
function wp_cache_get(): bool {
return false;
}
function wp_cache_set(): bool {
return true;
}
function update_option( string $option, mixed $value ): bool {
MockWordPressFunctions::set_mock_option( $option, $value );
return true;
}
function get_option( string $option, mixed $default = false ): mixed {
return MockWordPressFunctions::get_option( $option, $default );
}
function get_page_by_path( string $path ): string {
return $path ?? 'fake WP_Post';
}
function get_query_var( string $var_name, mixed $default_value = null ): ?string {
return MockWordPressFunctions::get_query_var( $var_name, $default_value );
}
function wp_generate_uuid4(): string {
return '00000000-0000-4000-8000-000000000000';
}
function is_email( mixed $email ): bool {
return filter_var( $email, FILTER_VALIDATE_EMAIL ) !== false;
}
function wp_is_uuid( mixed $uuid, ?int $version = null ): bool {
if ( ! is_string( $uuid ) ) {
return false;
}
if ( is_numeric( $version ) ) {
if ( 4 !== (int) $version ) {
throw new Exception( esc_html( 'Only UUID V4 is supported at this time.' ) );
}
$regex = '/^[0-9a-f]{8}-[0-9a-f]{4}-4[0-9a-f]{3}-[89ab][0-9a-f]{3}-[0-9a-f]{12}$/';
} else {
$regex = '/^[0-9a-f]{8}-[0-9a-f]{4}-[0-9a-f]{4}-[0-9a-f]{4}-[0-9a-f]{12}$/';
}
return (bool) preg_match( $regex, $uuid );
}
class WP_Error {
public function __construct( private string $code = '', private string $message = '', private mixed $data = null ) {}
public function get_error_code(): string {
return $this->code;
}
public function get_error_data(): mixed {
return $this->data;
}
public function get_error_message(): string {
return $this->message;
}
}