/** * Undo demo setup and reverts back to state before importing the sample contents. * Does not remove post/pages that have been modified by the user. * * @since 1.7.6 */ function themify_undo_import_sample_content() { do_action('themify_before_demo_erase'); themify_import_sample_content_setup(); $import = new Themify_Import(); $data = $import->parse(themify_get_sample_content_file()); foreach ($data['categories'] as $cat) { $term_id = term_exists($cat['category_nicename'], 'category'); if ($term_id) { if (is_array($term_id)) { $term_id = $term_id['term_id']; } if (isset($cat['term_id'])) { wp_delete_category($term_id); } } } foreach ($data['tags'] as $tag) { $term_id = term_exists($tag['tag_slug'], 'post_tag'); if ($term_id) { if (is_array($term_id)) { $term_id = $term_id['term_id']; } if (isset($tag['term_id'])) { wp_delete_term($term_id, 'post_tag'); } } } foreach ($data['terms'] as $term) { $term_id = term_exists($term['slug'], $term['term_taxonomy']); if ($term_id) { if (is_array($term_id)) { $term_id = $term_id['term_id']; } if (isset($term['term_id'])) { wp_delete_term($term_id, $term['term_taxonomy']); } } } foreach ($data['posts'] as $post) { $post_exists = post_exists($post['post_title'], '', $post['post_date']); if ($post_exists && get_post_type($post_exists) == $post['post_type']) { /* check if the post has not been modified since it was created */ if ($post['post_date'] == get_post_field('post_modified', $post_exists)) { wp_delete_post($post_exists, true); // true: bypass trash } } } do_action('themify_after_demo_erase'); }