function update_theme()
 {
     if (isset($_REQUEST['page'])) {
         // Sanitize page being requested.
         $_page = esc_attr($_REQUEST['page']);
         if ('spyropress-update' == $_page) {
             //Setup Filesystem
             $method = get_filesystem_method();
             if (isset($_POST['spyropress_ftp_cred'])) {
                 $cred = spyropress_decode($_POST['spyropress_ftp_cred']);
                 $filesystem = WP_Filesystem($cred);
             } else {
                 $filesystem = WP_Filesystem();
             }
             if (false == $filesystem && 'Proceed' != $_POST['upgrade']) {
                 add_error_message(sprintf(__('Failed: Filesystem preventing downloads. (%s)', 'spyropress'), $method));
                 return;
             }
             if (isset($_REQUEST['spyropress_updater'])) {
                 // Sanitize action being requested.
                 $_action = esc_attr($_REQUEST['spyropress_updater']);
                 if ('framework' == $_action) {
                     locate_template('framework/utilities/envato/class-envato-wordpress-theme-upgrader.php', true);
                     $envato_api_key = get_option('_spyropress_envato_api_key_' . get_internal_name());
                     $envato_username = get_option('_spyropress_envato_username_' . get_internal_name());
                     $upgrader = new Envato_WordPress_Theme_Upgrader($envato_username, $envato_api_key);
                     $result = $upgrader->upgrade_theme();
                     // Successfully Updated
                     if ($result->success) {
                         $message = __('New version successfully downloaded, extracted and updated.', 'spyropress');
                         $message .= '<script type="text/javascript">
                             //<![CDATA[
                                 window.location.replace("' . admin_url('admin.php?page=spyropress-update') . '");
                             //]]>
                         </script>';
                         add_success_message($message);
                     } else {
                         add_error_message($result->errors[0]);
                     }
                 }
             }
         }
         // END UPDATE HERE
     }
 }
/**
 * Install Dummy Data
 */
function spyropress_install_dummy_data()
{
    if (!current_user_can('manage_options')) {
        return;
    }
    if (isset($_GET['import-done']) && $_GET['import-done']) {
        add_success_message('Sucessfully imported demo data!');
        return;
    }
    if (!isset($_POST['import-dummy'])) {
        return;
    }
    if (!isset($_POST['security'])) {
        return;
    }
    if (!wp_verify_nonce($_POST['security'], 'spyropress-update-options')) {
        return;
    }
    // Generate Option Key
    $key = 'spyropress_' . $_POST['setting_panel_name'];
    // Check for define
    if (!isset($GLOBALS[$key])) {
        _e('false', 'spyropress');
        return;
    }
    // Doing import
    $importer = new SpyropressImporter($key);
    // Allow developer to perform actions
    do_action('spyropress_import_' . $_POST['setting_panel_name']);
    wp_safe_redirect(admin_url('admin.php?page=spyropress-theme&import-done=1'));
}