Пример #1
0
 public static function delete_post($postid)
 {
     $post = get_post($postid);
     $post_type = get_post_type_object($post->post_type);
     /* If the post type is a revision then don't do anything. */
     if ($post->post_type == 'revision') {
         return false;
     }
     /* Figure out the layout ID */
     //If it has no parents, just stop.
     if ($post->post_parent === 0) {
         $layout_id = 'single-' . $post_type->name . '-' . $post->ID;
         //Otherwise, figure out parents and grandparents
     } else {
         //Set up variables
         $posts = array($post->ID);
         $parents_str = '';
         //Get to business
         while ($post->post_parent != 0) {
             $posts[] = $post->post_parent;
             $post = get_post($post->post_parent);
         }
         foreach (array_reverse($posts) as $post_id) {
             $layout_id = 'single-' . $post_type->name . '-' . $parents_str . $post_id;
             $parents_str .= $post_id . '-';
         }
     }
     //Delete the blocks for the page/post
     HeadwayBlocksData::delete_by_layout($layout_id);
 }
Пример #2
0
 public static function secure_method_delete_template()
 {
     //Retreive templates
     $templates = HeadwayOption::get('list', 'templates', array());
     //Unset the deleted ID
     $id = headway_post('template_to_delete');
     //Delete template if it exists and send array back to DB
     if (isset($templates[$id])) {
         unset($templates[$id]);
         //Delete the blocks from the template
         HeadwayBlocksData::delete_by_layout('template-' . $id);
         //Delete all options from the template
         HeadwayLayoutOption::delete_all_from_layout('template-' . $id);
         //Delete template from templates list
         HeadwayOption::set('list', $templates, 'templates');
         do_action('headway_visual_editor_delete_template');
         echo 'success';
     } else {
         echo 'failure';
     }
 }