dtbaker / envato-wp-theme-setup-wizard

A step by step setup wizard that runs after a ThemeForest theme has been activated.
GNU General Public License v2.0
202 stars 66 forks source link

Better handling of data #21

Closed thewebsitedev closed 8 years ago

thewebsitedev commented 8 years ago

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.

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?

dtbaker commented 8 years ago

Looks good! :) Welcome to do a pull request.