Esempio n. 1
0
 /**
  * Get list of all blocks
  * @param $importer: Boolean to check if data is being imported or not
  */
 function circleflip_get_blocks($template_id, $saved_blocks, $importer = false)
 {
     global $aq_page_builder;
     $aqpb_config = circleflip_page_builder_config();
     $aq_page_builder = new AQ_Page_Builder($aqpb_config);
     $blocks = $aq_page_builder->retrieve_blocks($template_id, $saved_blocks, $importer);
     return $blocks;
 }
 function post_content_builder_mb_save()
 {
     global $post;
     $template_id = isset($_POST['post_ID']) ? $_POST['post_ID'] : '';
     /*Security Check*/
     if (!isset($_POST['rojo_mb_nonce-page_builder']) || !wp_verify_nonce($_POST['rojo_mb_nonce-page_builder'], 'rojo_mb_nonce-page_builder')) {
         return $template_id;
     }
     //now let's save our blocks & prepare haystack
     $blocks = AQ_Page_Builder::get_blocks($template_id);
     $haystack = array();
     $template_transient_data = array();
     $i = 1;
     foreach ($blocks as $new_instance) {
         global $aq_registered_blocks;
         global $post;
         $old_key = isset($new_instance['number']) ? 'aq_block_' . $new_instance['number'] : 'aq_block_0';
         $new_key = isset($new_instance['number']) ? 'aq_block_' . $i : 'aq_block_0';
         $old_instance = get_post_meta($template_id, $old_key, true);
         extract($new_instance);
         if (class_exists($id_base)) {
             //get the block object
             $block = $aq_registered_blocks[$id_base];
             //insert template_id into $instance
             $new_instance['template_id'] = $template_id;
             //sanitize instance with AQ_Block::update()
             $new_instance = $block->update($new_instance, $old_instance);
         }
         //update block
         update_post_meta($template_id, $new_key, $new_instance);
         //store instance into $template_transient_data
         $template_transient_data[$new_key] = $new_instance;
         //prepare haystack
         $haystack[] = $new_key;
         $i++;
     }
     //update transient
     $template_transient = 'aq_template_' . $template_id;
     update_post_meta($template_id, $template_transient, $template_transient_data);
     //use haystack to check for deleted blocks
     $curr_blocks = AQ_Page_Builder::retrieve_blocks($template_id);
     //$curr_blocks = $this->get_blocks($template_id);
     $curr_blocks = is_array($curr_blocks) ? $curr_blocks : array();
     foreach ($curr_blocks as $key => $block) {
         if (!in_array($key, $haystack)) {
             delete_post_meta($template_id, $key);
         }
     }
     $activate_builder = $_POST['rojo']['page_builder'];
     $old = get_post_meta($template_id, 'page_builder', $activate_builder, true);
     $new = $activate_builder;
     if ($new && $new != $old) {
         update_post_meta($template_id, 'page_builder', $new);
     } elseif ('' == $new && $old) {
         delete_post_meta($template_id, 'page_builder', $old);
     }
     return $template_id;
 }