/**
  * Activate the plugin
  */
 public static function activate()
 {
     global $Chronosly_Extend;
     //TODO MIRAR LA FUNCION add_role PARA AÑADIR ROLES DE USUARIOS NUEVOS
     // Capabilities for the chronosly custom post type
     $WP_Roles = new WP_Roles();
     foreach (array('chronosly_author', 'edit_' . CHRONOSLY_CAPABILITY_TYPE, 'read_' . CHRONOSLY_CAPABILITY_TYPE, 'delete_' . CHRONOSLY_CAPABILITY_TYPE, 'delete_' . CHRONOSLY_CAPABILITY_TYPE . 's', 'edit_' . CHRONOSLY_CAPABILITY_TYPE . 's', 'edit_others_' . CHRONOSLY_CAPABILITY_TYPE . 's', 'edit_published_' . CHRONOSLY_CAPABILITY_TYPE . 's', 'delete_published_' . CHRONOSLY_CAPABILITY_TYPE . 's', 'delete_private_' . CHRONOSLY_CAPABILITY_TYPE . 's', 'delete_others_' . CHRONOSLY_CAPABILITY_TYPE . 's', 'publish_' . CHRONOSLY_CAPABILITY_TYPE . 's', 'read_private_' . CHRONOSLY_CAPABILITY_TYPE . 's', 'chronosly_options', 'chronosly_license') as $cap) {
         $WP_Roles->add_cap(CHRONOSLY_ADMIN_ROLE, $cap);
     }
     $ext = new Chronosly_Extend();
     //the new code will set CHRONOSLY_VERSION code to the latest
     //update templates and addons
     $ext->update_addons();
     $ext->update_templates();
     $ext->rebuild_template_addons("default");
     Chronosly_Cache::clear_cache();
     wp_schedule_event(time(), "daily", 'chronosly_update_addons');
     wp_schedule_event(time(), "daily", 'chronosly_update_templates');
 }
 public function template_edit_page()
 {
     global $Post_Type_Chronosly;
     if (!current_user_can('manage_options')) {
         wp_die(__('You do not have sufficient permissions to access this page.'));
     }
     if (isset($_POST['chronosly_nonce'])) {
         //uploading templates
         if (wp_verify_nonce($_POST['chronosly_nonce'], "chronosly_addons_upload")) {
             if (!empty($_FILES['chronosly_addon']['name'])) {
                 Chronosly_Cache::clear_cache();
                 //print_r($_FILES['chronosly_addon']);
                 // Setup the array of supported file types. In this case, it's just PDF.
                 $supported_types = array('application/zip');
                 // Get the file type of the upload
                 $arr_file_type = wp_check_filetype(basename($_FILES['chronosly_addon']['name']));
                 $uploaded_type = $arr_file_type['type'];
                 // Check if the type is supported. If not, throw an error.
                 if (in_array($uploaded_type, $supported_types)) {
                     // Use the WordPress API to upload the file
                     $upload = wp_upload_bits($_FILES['chronosly_addon']['name'], null, file_get_contents($_FILES['chronosly_addon']['tmp_name']));
                     if (isset($upload['error']) && $upload['error'] != 0) {
                         echo '<div class="bubbleerror">' . __(sprintf('There was an error uploading your file. The error is: %s', "chronosly"), $upload['error']) . "</div>";
                     } else {
                         WP_Filesystem();
                         $destination_path = CHRONOSLY_TEMPLATES_PATH;
                         $upload['file'] = str_replace(array("/", "\\"), DIRECTORY_SEPARATOR, $upload['file']);
                         $unzipfile = unzip_file($upload['file'], $destination_path);
                         unlink($upload['file']);
                         if ($unzipfile === true) {
                             $names = explode(DIRECTORY_SEPARATOR, $upload['file']);
                             $name = str_replace(".zip", "", $names[count($names) - 1]);
                             //volvemos a construir los addons
                             Chronosly_Extend::rebuild_template_addons($name);
                             echo "<div class='bubblegreen'>{$name} " . __("template installed", "chronosly") . "</div>";
                             wp_redirect("admin.php?page=chronosly_edit_templates&installed={$name}");
                         } else {
                             echo '<div class="bubbleerror">' . __("There was an error installing this template", "chronosly") . '</div>';
                         }
                     }
                 } else {
                     echo '<div class="bubbleerror">' . __("The file type that you've uploaded is not a Chronosly Template ZIP.", "chronosly") . "</div>";
                 }
                 // end if/else
             }
             // end if
         }
     }
     $Post_Type_Chronosly->inicia_scripts();
     include CHRONOSLY_PATH . DIRECTORY_SEPARATOR . "metaboxes" . DIRECTORY_SEPARATOR . "settings" . DIRECTORY_SEPARATOR . "template-editor.php";
 }