I bumped into an issue where the default.json file was returning NULL. As far my understanding it was due to some kind of permission issue. So what I did to solve this is to make proper use of WP_Filesystem.
Here is my code. I think it can further be improved.
private function _get_json( $file ) {
WP_Filesystem();
$creds = request_filesystem_credentials(site_url() . '/wp-admin/', '', false, false, array());
if ( ! WP_Filesystem($creds) ) {
return false;
}
global $wp_filesystem;
// change path with path to your content dir
$dir = $wp_filesystem->find_folder(WP_CONTENT_DIR . "/themes/offshore/envato_setup/content");
$file = trailingslashit($dir) . $file;
if ( $wp_filesystem->exists( $file ) ) {
return json_decode( $wp_filesystem->get_contents( $file ), true );
} else {
return array();
}
}
Same approach can be used for _get_sql function. Thoughts?
Hello,
I bumped into an issue where the default.json file was returning NULL. As far my understanding it was due to some kind of permission issue. So what I did to solve this is to make proper use of WP_Filesystem.
Here is my code. I think it can further be improved.
Same approach can be used for
_get_sql
function. Thoughts?