Skip to content

Commit 321109e

Browse files
committed
Switch to using file_get_contents
1 parent 34a448e commit 321109e

File tree

1 file changed

+6
-19
lines changed

1 file changed

+6
-19
lines changed

includes/class-scf-json-schema-validator.php

Lines changed: 6 additions & 19 deletions
Original file line numberDiff line numberDiff line change
@@ -133,21 +133,12 @@ public function validate_data( $data, $schema_name ) {
133133
public function load_schema( $schema_name ) {
134134
$schema_file = $this->schema_path . $schema_name . '.schema.json';
135135

136-
if ( ! file_exists( $schema_file ) ) {
136+
if ( ! file_exists( $schema_file ) || ! is_readable( $schema_file ) ) {
137137
return null;
138138
}
139139

140-
if ( ! function_exists( 'WP_Filesystem' ) ) {
141-
require_once ABSPATH . 'wp-admin/includes/file.php';
142-
}
143-
WP_Filesystem();
144-
global $wp_filesystem;
145-
146-
if ( null === $wp_filesystem ) {
147-
return null;
148-
}
149-
150-
$schema_content = $wp_filesystem->get_contents( $schema_file );
140+
// phpcs:ignore WordPress.WP.AlternativeFunctions.file_get_contents_file_get_contents -- Local plugin file, safe to read directly.
141+
$schema_content = file_get_contents( $schema_file );
151142
if ( false === $schema_content ) {
152143
return null;
153144
}
@@ -275,17 +266,13 @@ public function validate_json( $json_string, $schema_name ) {
275266
public function validate_file( $file_path, $schema_name ) {
276267
$this->clear_validation_errors();
277268

278-
if ( ! file_exists( $file_path ) ) {
269+
if ( ! file_exists( $file_path ) || ! is_readable( $file_path ) ) {
279270
$this->add_validation_error( 'file', 'File does not exist: ' . $file_path );
280271
return false;
281272
}
282273

283-
if ( ! function_exists( 'WP_Filesystem' ) ) {
284-
require_once ABSPATH . 'wp-admin/includes/file.php';
285-
}
286-
WP_Filesystem();
287-
global $wp_filesystem;
288-
$json_content = $wp_filesystem->get_contents( $file_path );
274+
// phpcs:ignore WordPress.WP.AlternativeFunctions.file_get_contents_file_get_contents -- Local plugin file, safe to read directly.
275+
$json_content = file_get_contents( $file_path );
289276

290277
if ( false === $json_content ) {
291278
$this->add_validation_error( 'file', 'Could not read file: ' . $file_path );

0 commit comments

Comments
 (0)