/**
  * Save the metaboxes for this custom post type
  */
 public function save_post($post_id)
 {
     // verify if this is an auto save routine.
     // If it is our form has not been submitted, so we dont want to do anything
     if (defined('DOING_AUTOSAVE') && DOING_AUTOSAVE) {
         return;
     }
     // handle the case when the custom post is quick edited
     // otherwise all custom meta fields are cleared out
     if (wp_verify_nonce($_POST['_inline_edit'], 'inlineeditnonce')) {
         return;
     }
     if (isset($_POST['post_type']) && $_POST['post_type'] == self::POST_TYPE && current_user_can('edit_post', $post_id)) {
         Chronosly_Cache::delete_item($post_id);
         foreach ($this->_meta as $field_name) {
             // Update the post's meta field
             update_post_meta($post_id, $field_name, $_POST[$field_name]);
         }
     } else {
         return;
     }
     // if($_POST['post_type'] == self::POST_TYPE && current_user_can('edit_post', $post_id))
 }
 public function print_template($id, $vista, $draganddropels = "", $template = "", $style = "back", $args = array(), $html2 = 0)
 {
     $vars = $this->settings;
     $data = "";
     $this->vars->pid = $id;
     $this->vars->vista = $vista;
     $this->vars->args = $args;
     $itid = $id;
     if (isset($args["start"]) and isset($args["end"])) {
         $itid .= "_{$args["start"]}_{$args["end"]}";
     }
     if ($args["h"] and $args["m"]) {
         $itid .= "_{$args["h"]}_{$args["m"]}";
     }
     //si lo tenemos en la cache lo pintamos, si no lo generamos y lo guardamos
     $path = CHRONOSLY_TEMPLATES_PATH . DIRECTORY_SEPARATOR;
     if (isset($vars['chronosly_template_default_active']) and $vars['chronosly_template_default_active'] and stripos($_SERVER['HTTP_REFERER'], "chronosly_edit_templates") === FALSE) {
         $template = $vars['chronosly_template_default'];
     }
     if (isset($_REQUEST["force_template"])) {
         $template = $_REQUEST["force_template"];
     }
     if (!$template) {
         $template = $this->get_tipo_template($id, $vista);
     }
     if (!$template) {
         $template = $vars['chronosly_template_default'];
     }
     if ($style == "front" and !$html2 and file_exists($path . $vista . DIRECTORY_SEPARATOR . $template . ".html")) {
         // echo "html";
         return $this->print_template_html($id, $vista, $draganddropels, $template, $style, $args, $html2);
     }
     if ($style == "front" and $id != 1 and $html = Chronosly_Cache::load_item($itid, $vista)) {
         echo $html;
     } else {
         ob_start();
         if (!$template) {
             //si no hay template en la bd estamos cargando el default
             $this->render_template($vars['chronosly_template_default'], $style, $vista, "", $draganddropels, $html2);
         } else {
             if ($template == "chbd") {
                 //se trata de un template editado, cargamos los datos del template
                 $data = str_replace(array('\\"', "\\'"), array('"', "'"), $this->get_template($id, $vista));
             }
             $this->render_template($template, $style, $vista, json_decode($data), $draganddropels, $html2);
         }
         $cont = str_replace("{{notprev}}", "", ob_get_clean());
         echo $cont;
         if ($style == "front") {
             Chronosly_Cache::save_item($itid, $vista, $cont);
         }
     }
 }
 /**
  * Save the metaboxes for this custom post type
  */
 public function save_post($post_id)
 {
     // verify if this is an auto save routine.
     // If it is our form has not been submitted, so we dont want to do anything
     if (defined('DOING_AUTOSAVE') && DOING_AUTOSAVE) {
         return;
     }
     // handle the case when the custom post is quick edited
     // otherwise all custom meta fields are cleared out
     if (wp_verify_nonce($_POST['_inline_edit'], 'inlineeditnonce')) {
         Chronosly_Cache::delete_item($post_id);
         if (!class_exists("Chronosly_Tickets_and_Repeats_Extended")) {
             $req = array("ev-to", "ev-to-h", "ev-to-m", "ev-from", "ev-from-h", "ev-from-m", "ev-repeat-every", "ev-repeat", "ev-repeat-option", "ev-until", "ev-end_count", "organizer", "places", "featured", "order");
         } else {
             $req = array("organizer", "places", "featured", "order");
         }
         foreach ($this->_meta as $field_name) {
             // Update the post's meta field
             // if($field_name == "tickets"){
             //     $tick_send = $_POST[$field_name];
             //     $tickets = @get_post_meta($post_id, 'tickets', true);
             //     $tickets= json_decode($tickets[0]);
             //     if(isset($tickets->tickets)){
             //         for($i = 1; $i < count($tickets->tickets);++$i){
             //             $ticket = $tickets->tickets[$i];
             //             foreach($ticket as $t){
             //                 $tick[$t->name] = $t->value;
             //                 if(($t->name == "price" or $t->name == "soldout") and $tick_send[$i][$t->name]) $t->value = $tick_send[$i][$t->name];
             //                 $tickets->tickets[$i][] = array("name" => $t->name, "value" => $t->value);
             //             }
             //         }
             //         update_post_meta($post_id, $field_name, json_encode($tickets));
             //     }
             // }
             // else
             if (in_array($field_name, $req)) {
                 update_post_meta($post_id, $field_name, $_POST[$field_name]);
             }
         }
     }
     if (isset($_POST['post_type']) && $_POST['post_type'] == self::POST_TYPE && current_user_can('edit_post', $post_id)) {
         Chronosly_Cache::delete_item($post_id);
         foreach ($this->_meta as $field_name) {
             // Update the post's meta field
             update_post_meta($post_id, $field_name, $_POST[$field_name]);
         }
     } else {
         return;
     }
     // if($_POST['post_type'] == self::POST_TYPE && current_user_can('edit_post', $post_id))
 }
 public function save_taxonomy_custom_fields($term_id)
 {
     $t_id = $term_id;
     Chronosly_Cache::delete_item($term_id);
     $metas = array("featured" => $_POST["featured"], "order" => $_POST["order"], "cat-color" => $_POST["cat-color"]);
     update_option('chronosly-taxonomy_' . $t_id, serialize($metas));
 }
 /**
  * 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');
 }
<div class="wrapch addons">

    <?php 
global $Post_Type_Chronosly;
if (isset($_POST['chronosly_nonce'])) {
    //uploading file
    if (!current_user_can('manage_options')) {
        wp_die(__('You do not have sufficient permissions to access this page.'));
    }
    if (wp_verify_nonce($_POST['chronosly_nonce'], "chronosly_addons_upload")) {
        if (!empty($_FILES['chronosly_addon']['name'])) {
            Chronosly_Cache::clear_cache();
            // 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) {
                    wp_die('There was an error uploading your file. The error is: ' . $upload['error']);
                } else {
                    WP_Filesystem();
                    $destination_path = CHRONOSLY_ADDONS_PATH;
                    // if(stripos($upload['file'], "organizers_and_places") !== FALSE or stripos($upload['file'], "extended_marketplace") !== FALSE) $destination_path = CHRONOSLY_PATH;
                    $upload['file'] = str_replace(array("/", "\\"), DIRECTORY_SEPARATOR, $upload['file']);
                    $unzipfile = unzip_file($upload['file'], $destination_path);
                    if ($unzipfile === true) {
                        if (stripos($upload['file'], "organizers_and_places") !== FALSE) {
 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";
 }