function pp_update_project($project_data) { if (!($project_category_id = pp_get_category_id('projects'))) { return false; // This shouldn't happen from the edit screen. } if (isset($project_data['project_parent']) && (!$project_data['project_parent'] || -1 == $project_data['project_parent'])) { $project_data['project_parent'] = $project_category_id; } $category_data = array('cat_ID' => $project_data['project_ID'], 'cat_name' => $project_data['project_name'], 'category_description' => $project_data['project_description'], 'category_nicename' => $project_data['project_nicename'], 'category_parent' => $project_data['project_parent']); if (!($category_id = wp_update_category($category_data, false))) { return false; } $project_meta = array(); $project_meta['logo'] = $project_data['project_logo']; $project_meta['website'] = $project_data['project_website']; $project_meta['blog'] = $project_data['project_blog']; $project_meta['svn'] = $project_data['project_svn']; $project_meta['trac'] = $project_data['project_trac']; $project_meta['intertrac'] = $project_data['project_intertrac']; $project_meta['activity'] = $project_data['project_activity']; $project_meta['overheard'] = $project_data['project_overheard']; if ($project_meta['activity']) { $project_meta['activity'] = str_replace("\r", '', $project_meta['activity']); $project_meta['activity'] = explode("\n", $project_meta['activity']); array_walk($project_meta['activity'], create_function('&$a', '$a = trim($a);')); $project_meta['activity'] = array_filter($project_meta['activity']); } if ($project_meta['overheard']) { $project_meta['overheard'] = str_replace("\r", '', $project_meta['overheard']); $project_meta['overheard'] = explode("\n", $project_meta['overheard']); array_walk($project_meta['overheard'], create_function('&$a', '$a = trim($a);')); $project_meta['overheard'] = array_filter($project_meta['overheard']); } if ($current_project_meta = get_option('pp_project_meta_' . $category_id)) { $project_meta = array_merge($current_project_meta, $project_meta); } update_option('pp_project_meta_' . $category_id, $project_meta); return $category_id; }
_e('Edit category'); ?> »" /></p> </form> <p><a href="categories.php"><?php _e('« Return to category list'); ?> </a></p> </div> <?php break; case 'editedcat': if (!current_user_can('manage_categories')) { die(__('Cheatin’ uh?')); } wp_update_category($_POST); header('Location: categories.php?message=3'); break; default: require_once 'admin-header.php'; $messages[1] = __('Category added.'); $messages[2] = __('Category deleted.'); $messages[3] = __('Category updated.'); ?> <?php if (isset($_GET['message'])) { ?> <div id="message" class="updated fade"><p><?php echo $messages[$_GET['message']]; ?>
$category = get_category_to_edit($cat_ID); include 'edit-category-form.php'; break; case 'editedcat': $cat_ID = (int) $_POST['cat_ID']; check_admin_referer('update-category_' . $cat_ID); if (!current_user_can('manage_categories')) { wp_die(__('Cheatin’ uh?')); } $location = 'categories.php'; if ($referer = wp_get_original_referer()) { if (false !== strpos($referer, 'categories.php')) { $location = $referer; } } if (wp_update_category($_POST)) { $location = add_query_arg('message', 3, $location); } else { $location = add_query_arg('message', 5, $location); } wp_redirect($location); exit; break; default: if (isset($_GET['_wp_http_referer']) && !empty($_GET['_wp_http_referer'])) { wp_redirect(remove_query_arg(array('_wp_http_referer', '_wpnonce'), stripslashes($_SERVER['REQUEST_URI']))); exit; } wp_enqueue_script('admin-categories'); if (current_user_can('manage_categories')) { wp_enqueue_script('inline-edit-tax');
} if (!isset($_POST['tax_ID']) || !($id = (int) $_POST['tax_ID'])) { die(-1); } switch ($_POST['tax_type']) { case 'cat': $data = array(); $data['cat_ID'] = $id; $data['cat_name'] = $_POST['name']; $data['category_nicename'] = $_POST['slug']; if (isset($_POST['parent']) && (int) $_POST['parent'] > 0) { $data['category_parent'] = $_POST['parent']; } $cat = get_category($id, ARRAY_A); $data['category_description'] = $cat['category_description']; $updated = wp_update_category($data); if ($updated && !is_wp_error($updated)) { echo _cat_row($updated, 0); } else { die(__('Category not updated.')); } break; case 'link-cat': $updated = wp_update_term($id, 'link_category', $_POST); if ($updated && !is_wp_error($updated)) { echo link_cat_row($updated['term_id']); } else { die(__('Category not updated.')); } break; case 'tag':
function cpm_action_build_storyline_schema() { global $cpm_config; update_option('comicpress-enable-storyline-support', isset($_POST['enable-storyline-support']) ? 1 : 0); update_option('comicpress-storyline-show-top-category', isset($_POST['show-top-category']) ? 1 : 0); if (isset($_POST['enable-storyline-support'])) { $cpm_config->is_cpm_modifying_categories = true; $categories_to_create = array(); $categories_to_rename = array(); $category_ids_to_clean = array(); extract(cpm_get_all_comic_categories()); $comic_posts = cpm_query_posts(); $comic_posts_by_category_id = array(); foreach ($comic_posts as $post) { foreach (wp_get_post_categories($post->ID) as $category) { if (!isset($comic_posts_by_category_id[$category])) { $comic_posts_by_category_id[$category] = array(); } $comic_posts_by_category_id[$category][] = $post->ID; } } foreach ($_POST as $field => $value) { $value = stripslashes($value); $parts = explode("/", $field); if ($parts[0] == "0" && count($parts) > 1) { $category_id = end($parts); $category = get_category($category_id); if (!empty($category)) { $category = (array) $category; if ($category['cat_name'] != $value) { $cpm_config->messages[] = sprintf(__('Category <strong>%1$s</strong> renamed to <strong>%2$s</strong>.', 'comicpress-manager'), $category['cat_name'], $value); $category['cat_name'] = $value; wp_update_category($category); $category_ids_to_clean[] = $category_id; } } else { $categories_to_create[$field] = $value; } if (($index = array_search($field, $category_tree)) !== false) { array_splice($category_tree, $index, 1); } } } if (isset($_POST['original-categories'])) { foreach (explode(",", $_POST['original-categories']) as $node) { if (!isset($_POST[$node])) { $category_id = end(explode("/", $node)); $category = get_category($category_id); $original_cat_name = $category->cat_name; // ensure that we're not deleting a ComicPress category $ok = true; foreach (array('comiccat', 'blogcat') as $type) { if ($category_id == $cpm_config->properties[$type]) { $ok = false; } } // ensure that the category truly is a child of the comic category if ($ok) { $category = get_category($category_id); $ok = false; if (!is_wp_error($category)) { while ($category->parent != 0 && $category->parent != $cpm_config->properties['comiccat']) { $category = get_category($category->parent); } if ($category->parent == $cpm_config->properties['comiccat']) { $ok = true; } } } if ($ok) { wp_delete_category($category_id); $category_ids_to_clean[] = $category_id; $cpm_config->messages[] = sprintf(__('Category <strong>%s</strong> deleted.', 'comicpress-manager'), $original_cat_name); } } } } uksort($categories_to_create, 'cpm_sort_category_keys_by_length'); $changed_field_ids = array(); $removed_field_ids = array(); $target_category_ids = array(); foreach ($categories_to_create as $field => $value) { $original_field = $field; foreach ($changed_field_ids as $changed_field => $new_field) { if (strpos($field, $changed_field) === 0 && strlen($field) > strlen($changed_field)) { $field = str_replace($changed_field, $new_field, $field); break; } } $parts = explode("/", $field); $target_id = array_pop($parts); $parent_id = array_pop($parts); if (!category_exists($value)) { $category_id = wp_create_category($value, $parent_id); $category_ids_to_clean[] = $category_id; array_push($parts, $parent_id); array_push($parts, $category_id); $changed_field_ids[$original_field] = implode("/", $parts); $cpm_config->messages[] = sprintf(__('Category <strong>%s</strong> created.', 'comicpress-manager'), $value); } else { $cpm_config->warnings[] = sprintf(__("The category %s already exists. Please enter a new name.", 'comicpress-manager'), $value); $removed_field_ids[] = $field; } } $order = array_diff(explode(",", $_POST['order']), $removed_field_ids); for ($i = 0; $i < count($order); ++$i) { if (isset($changed_field_ids[$order[$i]])) { $order[$i] = $changed_field_ids[$order[$i]]; } } // ensure we're writing sane data $new_order = array(); $valid_comic_categories = array(); foreach ($order as $node) { $parts = explode("/", $node); if ($parts[0] == "0" && count($parts) > 1) { $new_order[] = $node; $valid_comic_categories[] = end($parts); } } $comic_categories_preserved = array(); foreach ($comic_posts as $post) { $categories = wp_get_post_categories($post->ID); if (count(array_intersect($valid_comic_categories, $categories)) == 0) { $all_parent_categories = array(); foreach ($comic_posts_by_category_id as $category => $post_ids) { if (in_array($post->ID, $post_ids)) { foreach ($new_order as $node) { $parts = explode("/", $node); if ($category == end($parts)) { $parts = explode("/", $node); array_pop($parts); if (count($parts) > 1) { $all_parent_categories[] = implode("/", $parts); } } } } } if (count($all_parent_categories) > 0) { foreach ($all_parent_categories as $category_node) { if (in_array($category_node, $new_order)) { $categories[] = end(explode("/", $category_node)); } } } else { $categories[] = $cpm_config->properties['comiccat']; } wp_set_post_categories($post->ID, $categories); $comic_categories_preserved[] = $post->ID; } } if (count($comic_categories_preserved) > 0) { $cpm_config->messages[] = sprintf(__("The following orphaned comic posts were placed into their original category's parent: <strong>%s</strong>"), implode(", ", $comic_categories_preserved)); } $cpm_config->messages[] = __('Storyline structure saved.', 'comicpress-manager'); update_option("comicpress-storyline-category-order", implode(",", $new_order)); clean_term_cache($category_ids_to_clean, 'category'); wp_cache_flush(); } }
/** * Set options for a new blog created when a new * campaign is created. * * @param int $blogId * @return null */ protected function setBlogOptions($blogId) { // allow search engine robots to index the campaign site update_blog_option($blogId, 'blog_public', 1); // set defaut campaign theme update_blog_option($blogId, 'current_theme', 'Blog 01'); update_blog_option($blogId, 'stylesheet', 'blog-01'); update_blog_option($blogId, 'template', 'blog-01'); // set upload limit $capabilities = Capability::getByPlanId($this->plan_id); update_blog_option($blogId, 'blog_upload_space', $capabilities->upload_limit->value); // enable contact page update_blog_option($blogId, 'projeto_contact_enabled', 'on'); // enable "mobilize" menu entry option if ($capabilities->mobilize->value) { update_blog_option($blogId, 'mobilize', array('general' => array('menuItem' => true))); } // rename category "sem-categoria" to "noticias" wp_update_category(array('cat_ID' => 1, 'cat_name' => 'NotÃcias', 'category_nicename' => 'noticias')); }
/** * Set options for a new blog created when a new * campaign is created. * * @param int $blogId * @return null */ protected function setBlogOptions($blogId) { // allow search engine robots to index the campaign site update_blog_option($blogId, 'blog_public', 1); // allow change of blog model $model = get_user_meta(get_current_user_id(), 'blogmodel', true); if (empty($model)) { // set defaut campaign theme update_blog_option($blogId, 'current_theme', 'Blog 01'); update_blog_option($blogId, 'stylesheet', 'blog-01'); update_blog_option($blogId, 'template', 'blog-01'); } elseif (file_exists(WPMU_PLUGIN_DIR . "/campaign_base/models/" . basename($model) . ".php")) { include WPMU_PLUGIN_DIR . "/campaign_base/models/" . basename($model) . ".php"; } // set upload limit $capabilities = Capability::getByPlanId($this->plan_id); update_blog_option($blogId, 'blog_upload_space', $capabilities->upload_limit->value); // enable contact page update_blog_option($blogId, 'projeto_contact_enabled', 'on'); // enable "mobilize" menu entry option if ($capabilities->mobilize->value) { update_blog_option($blogId, 'mobilize', array('general' => array('menuItem' => true))); } // rename category "sem-categoria" to "noticias" wp_update_category(array('cat_ID' => 1, 'cat_name' => 'NotÃcias', 'category_nicename' => 'noticias')); }