2009-11-22 20:35:39 +00:00
|
|
|
<?php
|
2009-11-22 20:50:16 +00:00
|
|
|
|
|
|
|
class PostFixtures {
|
|
|
|
function parse_json($input) {
|
|
|
|
if (($data = json_decode($input)) !== false) {
|
|
|
|
if (is_array($data) || is_object($data)) {
|
2009-11-22 20:56:00 +00:00
|
|
|
return array_values((array)$data);
|
2009-11-22 20:50:16 +00:00
|
|
|
}
|
|
|
|
}
|
|
|
|
return false;
|
|
|
|
}
|
2009-11-22 22:34:57 +00:00
|
|
|
|
|
|
|
function remove_all_posts() {
|
|
|
|
if (is_array($posts = get_posts('nopaging=1'))) {
|
|
|
|
foreach ($posts as $post) { wp_delete_post($post->ID); }
|
|
|
|
}
|
|
|
|
}
|
2009-11-22 22:58:34 +00:00
|
|
|
|
|
|
|
function remove_all_categories() {
|
|
|
|
foreach (get_all_category_ids() as $id) {
|
|
|
|
wp_delete_category($id);
|
|
|
|
}
|
|
|
|
}
|
2009-11-22 23:11:59 +00:00
|
|
|
|
|
|
|
function process_data($data) {
|
|
|
|
$posts = $data;
|
|
|
|
$categories = array();
|
|
|
|
foreach ($data as $post) {
|
|
|
|
if (isset($post['categories'])) {
|
|
|
|
$categories = array_merge($categories, $post['categories']);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
return compact('posts', 'categories');
|
|
|
|
}
|
2009-11-22 23:32:52 +00:00
|
|
|
|
|
|
|
function create_categories($categories) {
|
|
|
|
$category_ids_by_slug = array();
|
|
|
|
if (is_array($categories)) {
|
|
|
|
foreach ($categories as $category) {
|
|
|
|
$category_ids_by_slug[$category] = wp_insert_category(array('slug' => $category));
|
|
|
|
}
|
|
|
|
}
|
|
|
|
return $category_ids_by_slug;
|
|
|
|
}
|
2009-11-22 20:50:16 +00:00
|
|
|
}
|