Skip to content

Commit

Permalink
Use WP_Filesystem
Browse files Browse the repository at this point in the history
  • Loading branch information
atanas-dev committed Nov 16, 2019
1 parent d29b6d8 commit e62c114
Showing 1 changed file with 9 additions and 2 deletions.
11 changes: 9 additions & 2 deletions src/Concerns/ReadsJsonTrait.php
Original file line number Diff line number Diff line change
Expand Up @@ -34,11 +34,18 @@ abstract protected function getJsonPath();
* @return array
*/
protected function load( $file ) {
if ( ! file_exists( $file ) ) {
/** @var \WP_Filesystem_Base $wp_filesystem */
global $wp_filesystem;

require_once ABSPATH . '/wp-admin/includes/file.php';

WP_Filesystem();

if ( ! $wp_filesystem->exists( $file ) ) {
throw new JsonFileNotFoundException( 'The required ' . basename( $file ) . ' file is missing.' );
}

$contents = file_get_contents( $file );
$contents = $wp_filesystem->get_contents( $file );
$json = json_decode( $contents, true );
$json_error = json_last_error();

Expand Down

0 comments on commit e62c114

Please sign in to comment.