Skip to content

Commit 43aa84d

Browse files
committed
Prefix WordPress core functions with backslash
All WordPress core functions and classes are now called with a leading backslash to ensure global namespace resolution and avoid conflicts with custom functions. Site Health checks initialization was moved to an admin-only hook for better separation of concerns.
1 parent f696505 commit 43aa84d

10 files changed

Lines changed: 201 additions & 202 deletions

includes/class-health-check.php

Lines changed: 52 additions & 52 deletions
Original file line numberDiff line numberDiff line change
@@ -48,38 +48,38 @@ public static function register_tests( $tests ) {
4848
*/
4949
public static function test_wellknown_endpoint() {
5050
$result = array(
51-
'label' => __( 'NodeInfo discovery is working', 'nodeinfo' ),
51+
'label' => \__( 'NodeInfo discovery is working', 'nodeinfo' ),
5252
'status' => 'good',
5353
'badge' => array(
54-
'label' => __( 'Fediverse', 'nodeinfo' ),
54+
'label' => \__( 'Fediverse', 'nodeinfo' ),
5555
'color' => 'green',
5656
),
57-
'description' => sprintf(
57+
'description' => \sprintf(
5858
'<p>%s</p>',
59-
__( 'The NodeInfo discovery endpoint is accessible and other Fediverse servers can find information about your site.', 'nodeinfo' )
59+
\__( 'The NodeInfo discovery endpoint is accessible and other Fediverse servers can find information about your site.', 'nodeinfo' )
6060
),
6161
'actions' => '',
6262
'test' => 'nodeinfo_wellknown',
6363
);
6464

65-
$url = home_url( '/.well-known/nodeinfo' );
66-
$response = wp_remote_get(
65+
$url = \home_url( '/.well-known/nodeinfo' );
66+
$response = \wp_remote_get(
6767
$url,
6868
array(
6969
'timeout' => 10,
7070
'sslverify' => false,
7171
)
7272
);
7373

74-
if ( is_wp_error( $response ) ) {
74+
if ( \is_wp_error( $response ) ) {
7575
$result['status'] = 'critical';
76-
$result['label'] = __( 'NodeInfo discovery endpoint is not accessible', 'nodeinfo' );
77-
$result['description'] = sprintf(
76+
$result['label'] = \__( 'NodeInfo discovery endpoint is not accessible', 'nodeinfo' );
77+
$result['description'] = \sprintf(
7878
'<p>%s</p><p>%s</p>',
79-
__( 'The NodeInfo discovery endpoint could not be reached. Other Fediverse servers may not be able to discover your site.', 'nodeinfo' ),
80-
sprintf(
79+
\__( 'The NodeInfo discovery endpoint could not be reached. Other Fediverse servers may not be able to discover your site.', 'nodeinfo' ),
80+
\sprintf(
8181
/* translators: %s: Error message */
82-
__( 'Error: %s', 'nodeinfo' ),
82+
\__( 'Error: %s', 'nodeinfo' ),
8383
$response->get_error_message()
8484
)
8585
);
@@ -88,17 +88,17 @@ public static function test_wellknown_endpoint() {
8888
return $result;
8989
}
9090

91-
$status_code = wp_remote_retrieve_response_code( $response );
91+
$status_code = \wp_remote_retrieve_response_code( $response );
9292

9393
if ( 200 !== $status_code ) {
9494
$result['status'] = 'critical';
95-
$result['label'] = __( 'NodeInfo discovery endpoint returned an error', 'nodeinfo' );
96-
$result['description'] = sprintf(
95+
$result['label'] = \__( 'NodeInfo discovery endpoint returned an error', 'nodeinfo' );
96+
$result['description'] = \sprintf(
9797
'<p>%s</p><p>%s</p>',
98-
__( 'The NodeInfo discovery endpoint returned an unexpected status code. This may indicate a server configuration issue.', 'nodeinfo' ),
99-
sprintf(
98+
\__( 'The NodeInfo discovery endpoint returned an unexpected status code. This may indicate a server configuration issue.', 'nodeinfo' ),
99+
\sprintf(
100100
/* translators: %d: HTTP status code */
101-
__( 'HTTP Status: %d', 'nodeinfo' ),
101+
\__( 'HTTP Status: %d', 'nodeinfo' ),
102102
$status_code
103103
)
104104
);
@@ -107,25 +107,25 @@ public static function test_wellknown_endpoint() {
107107
return $result;
108108
}
109109

110-
$body = wp_remote_retrieve_body( $response );
111-
$data = json_decode( $body, true );
110+
$body = \wp_remote_retrieve_body( $response );
111+
$data = \json_decode( $body, true );
112112

113113
if ( empty( $data['links'] ) ) {
114114
$result['status'] = 'recommended';
115-
$result['label'] = __( 'NodeInfo discovery returns incomplete data', 'nodeinfo' );
116-
$result['description'] = sprintf(
115+
$result['label'] = \__( 'NodeInfo discovery returns incomplete data', 'nodeinfo' );
116+
$result['description'] = \sprintf(
117117
'<p>%s</p>',
118-
__( 'The NodeInfo discovery endpoint is accessible but does not contain the expected links. This may indicate a plugin conflict or configuration issue.', 'nodeinfo' )
118+
\__( 'The NodeInfo discovery endpoint is accessible but does not contain the expected links. This may indicate a plugin conflict or configuration issue.', 'nodeinfo' )
119119
);
120120
$result['badge']['color'] = 'orange';
121121

122122
return $result;
123123
}
124124

125-
$result['actions'] = sprintf(
125+
$result['actions'] = \sprintf(
126126
'<p><a href="%s" target="_blank">%s</a></p>',
127-
esc_url( $url ),
128-
__( 'View NodeInfo discovery document', 'nodeinfo' )
127+
\esc_url( $url ),
128+
\__( 'View NodeInfo discovery document', 'nodeinfo' )
129129
);
130130

131131
return $result;
@@ -138,39 +138,39 @@ public static function test_wellknown_endpoint() {
138138
*/
139139
public static function test_nodeinfo_endpoint() {
140140
$result = array(
141-
'label' => __( 'NodeInfo endpoint is working', 'nodeinfo' ),
141+
'label' => \__( 'NodeInfo endpoint is working', 'nodeinfo' ),
142142
'status' => 'good',
143143
'badge' => array(
144-
'label' => __( 'Fediverse', 'nodeinfo' ),
144+
'label' => \__( 'Fediverse', 'nodeinfo' ),
145145
'color' => 'green',
146146
),
147-
'description' => sprintf(
147+
'description' => \sprintf(
148148
'<p>%s</p>',
149-
__( 'The NodeInfo REST endpoint returns valid data about your site.', 'nodeinfo' )
149+
\__( 'The NodeInfo REST endpoint returns valid data about your site.', 'nodeinfo' )
150150
),
151151
'actions' => '',
152152
'test' => 'nodeinfo_endpoint',
153153
);
154154

155155
// Test the latest version (2.2).
156-
$url = get_rest_url( null, '/nodeinfo/2.2' );
157-
$response = wp_remote_get(
156+
$url = \get_rest_url( null, '/nodeinfo/2.2' );
157+
$response = \wp_remote_get(
158158
$url,
159159
array(
160160
'timeout' => 10,
161161
'sslverify' => false,
162162
)
163163
);
164164

165-
if ( is_wp_error( $response ) ) {
165+
if ( \is_wp_error( $response ) ) {
166166
$result['status'] = 'critical';
167-
$result['label'] = __( 'NodeInfo REST endpoint is not accessible', 'nodeinfo' );
168-
$result['description'] = sprintf(
167+
$result['label'] = \__( 'NodeInfo REST endpoint is not accessible', 'nodeinfo' );
168+
$result['description'] = \sprintf(
169169
'<p>%s</p><p>%s</p>',
170-
__( 'The NodeInfo REST endpoint could not be reached. This may indicate that the REST API is disabled or blocked.', 'nodeinfo' ),
171-
sprintf(
170+
\__( 'The NodeInfo REST endpoint could not be reached. This may indicate that the REST API is disabled or blocked.', 'nodeinfo' ),
171+
\sprintf(
172172
/* translators: %s: Error message */
173-
__( 'Error: %s', 'nodeinfo' ),
173+
\__( 'Error: %s', 'nodeinfo' ),
174174
$response->get_error_message()
175175
)
176176
);
@@ -179,17 +179,17 @@ public static function test_nodeinfo_endpoint() {
179179
return $result;
180180
}
181181

182-
$status_code = wp_remote_retrieve_response_code( $response );
182+
$status_code = \wp_remote_retrieve_response_code( $response );
183183

184184
if ( 200 !== $status_code ) {
185185
$result['status'] = 'critical';
186-
$result['label'] = __( 'NodeInfo REST endpoint returned an error', 'nodeinfo' );
187-
$result['description'] = sprintf(
186+
$result['label'] = \__( 'NodeInfo REST endpoint returned an error', 'nodeinfo' );
187+
$result['description'] = \sprintf(
188188
'<p>%s</p><p>%s</p>',
189-
__( 'The NodeInfo REST endpoint returned an unexpected status code.', 'nodeinfo' ),
190-
sprintf(
189+
\__( 'The NodeInfo REST endpoint returned an unexpected status code.', 'nodeinfo' ),
190+
\sprintf(
191191
/* translators: %d: HTTP status code */
192-
__( 'HTTP Status: %d', 'nodeinfo' ),
192+
\__( 'HTTP Status: %d', 'nodeinfo' ),
193193
$status_code
194194
)
195195
);
@@ -198,25 +198,25 @@ public static function test_nodeinfo_endpoint() {
198198
return $result;
199199
}
200200

201-
$body = wp_remote_retrieve_body( $response );
202-
$data = json_decode( $body, true );
201+
$body = \wp_remote_retrieve_body( $response );
202+
$data = \json_decode( $body, true );
203203

204204
if ( empty( $data['software']['name'] ) || empty( $data['version'] ) ) {
205205
$result['status'] = 'recommended';
206-
$result['label'] = __( 'NodeInfo endpoint returns incomplete data', 'nodeinfo' );
207-
$result['description'] = sprintf(
206+
$result['label'] = \__( 'NodeInfo endpoint returns incomplete data', 'nodeinfo' );
207+
$result['description'] = \sprintf(
208208
'<p>%s</p>',
209-
__( 'The NodeInfo endpoint is accessible but does not contain all expected fields.', 'nodeinfo' )
209+
\__( 'The NodeInfo endpoint is accessible but does not contain all expected fields.', 'nodeinfo' )
210210
);
211211
$result['badge']['color'] = 'orange';
212212

213213
return $result;
214214
}
215215

216-
$result['actions'] = sprintf(
216+
$result['actions'] = \sprintf(
217217
'<p><a href="%s" target="_blank">%s</a></p>',
218-
esc_url( $url ),
219-
__( 'View NodeInfo 2.2 endpoint', 'nodeinfo' )
218+
\esc_url( $url ),
219+
\__( 'View NodeInfo 2.2 endpoint', 'nodeinfo' )
220220
);
221221

222222
return $result;

includes/controller/class-nodeinfo.php

Lines changed: 20 additions & 24 deletions
Original file line numberDiff line numberDiff line change
@@ -7,17 +7,13 @@
77

88
namespace Nodeinfo\Controller;
99

10-
use WP_REST_Controller;
11-
use WP_REST_Server;
12-
use WP_REST_Response;
13-
1410
/**
1511
* NodeInfo REST Controller class.
1612
*
1713
* Handles NodeInfo discovery and versioned endpoints.
1814
* Versions are registered dynamically via filters.
1915
*/
20-
class Nodeinfo extends WP_REST_Controller {
16+
class Nodeinfo extends \WP_REST_Controller {
2117

2218
/**
2319
* The namespace.
@@ -30,12 +26,12 @@ class Nodeinfo extends WP_REST_Controller {
3026
* Register the routes.
3127
*/
3228
public function register_routes() {
33-
register_rest_route(
29+
\register_rest_route(
3430
$this->namespace,
3531
'/discovery',
3632
array(
3733
array(
38-
'methods' => WP_REST_Server::READABLE,
34+
'methods' => \WP_REST_Server::READABLE,
3935
'callback' => array( $this, 'get_discovery' ),
4036
'permission_callback' => '__return_true',
4137
),
@@ -48,7 +44,7 @@ public function register_routes() {
4844
return;
4945
}
5046

51-
register_rest_route(
47+
\register_rest_route(
5248
$this->namespace,
5349
'/(?P<version>\d\.\d)',
5450
array(
@@ -61,7 +57,7 @@ public function register_routes() {
6157
),
6258
),
6359
array(
64-
'methods' => WP_REST_Server::READABLE,
60+
'methods' => \WP_REST_Server::READABLE,
6561
'callback' => array( $this, 'get_item' ),
6662
'permission_callback' => '__return_true',
6763
),
@@ -81,7 +77,7 @@ protected function get_versions() {
8177
*
8278
* @param array $versions List of version strings (e.g., '2.0', '2.1').
8379
*/
84-
return apply_filters( 'nodeinfo_versions', array() );
80+
return \apply_filters( 'nodeinfo_versions', array() );
8581
}
8682

8783
/**
@@ -97,7 +93,7 @@ public function get_discovery() {
9793
*
9894
* @param array $links The discovery links.
9995
*/
100-
$links = apply_filters( 'nodeinfo_discovery_links', $links );
96+
$links = \apply_filters( 'nodeinfo_discovery_links', $links );
10197

10298
$discovery = array( 'links' => $links );
10399

@@ -106,9 +102,9 @@ public function get_discovery() {
106102
*
107103
* @param array $discovery The discovery document.
108104
*/
109-
$discovery = apply_filters( 'nodeinfo_discovery', $discovery );
105+
$discovery = \apply_filters( 'nodeinfo_discovery', $discovery );
110106

111-
$response = new WP_REST_Response( $discovery );
107+
$response = new \WP_REST_Response( $discovery );
112108
$response->header( 'Content-Type', 'application/json; profile=http://nodeinfo.diaspora.software' );
113109

114110
return $response;
@@ -125,19 +121,19 @@ public function get_item( $request ) {
125121

126122
$nodeinfo = array(
127123
'version' => $version,
128-
'software' => apply_filters( 'nodeinfo_data_software', array(), $version ),
129-
'protocols' => apply_filters( 'nodeinfo_data_protocols', array(), $version ),
130-
'services' => apply_filters(
124+
'software' => \apply_filters( 'nodeinfo_data_software', array(), $version ),
125+
'protocols' => \apply_filters( 'nodeinfo_data_protocols', array(), $version ),
126+
'services' => \apply_filters(
131127
'nodeinfo_data_services',
132128
array(
133129
'inbound' => array(),
134130
'outbound' => array(),
135131
),
136132
$version
137133
),
138-
'openRegistrations' => (bool) get_option( 'users_can_register', false ),
139-
'usage' => apply_filters( 'nodeinfo_data_usage', array(), $version ),
140-
'metadata' => apply_filters( 'nodeinfo_data_metadata', array(), $version ),
134+
'openRegistrations' => (bool) \get_option( 'users_can_register', false ),
135+
'usage' => \apply_filters( 'nodeinfo_data_usage', array(), $version ),
136+
'metadata' => \apply_filters( 'nodeinfo_data_metadata', array(), $version ),
141137
);
142138

143139
/**
@@ -146,9 +142,9 @@ public function get_item( $request ) {
146142
* @param array $nodeinfo The NodeInfo data.
147143
* @param string $version The NodeInfo version.
148144
*/
149-
$nodeinfo = apply_filters( 'nodeinfo_data', $nodeinfo, $version );
145+
$nodeinfo = \apply_filters( 'nodeinfo_data', $nodeinfo, $version );
150146

151-
return new WP_REST_Response( $nodeinfo );
147+
return new \WP_REST_Response( $nodeinfo );
152148
}
153149

154150
/**
@@ -169,7 +165,7 @@ public function get_item_schema() {
169165
*
170166
* @param array $schema The schema data.
171167
*/
172-
return apply_filters( 'nodeinfo_schema', $schema );
168+
return \apply_filters( 'nodeinfo_schema', $schema );
173169
}
174170

175171
/**
@@ -191,9 +187,9 @@ public static function jrd( $jrd ) {
191187
*
192188
* @param array $links The discovery links.
193189
*/
194-
$links = apply_filters( 'nodeinfo_discovery_links', array() );
190+
$links = \apply_filters( 'nodeinfo_discovery_links', array() );
195191

196-
$jrd['links'] = array_merge( $jrd['links'], $links );
192+
$jrd['links'] = \array_merge( $jrd['links'], $links );
197193

198194
return $jrd;
199195
}

0 commit comments

Comments
 (0)