本文整理汇总了PHP中wp_insert_category函数的典型用法代码示例。如果您正苦于以下问题:PHP wp_insert_category函数的具体用法?PHP wp_insert_category怎么用?PHP wp_insert_category使用的例子?那么恭喜您, 这里精选的函数代码示例或许可以为您提供帮助。
在下文中一共展示了wp_insert_category函数的20个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于我们的系统推荐出更棒的PHP代码示例。
示例1: plugin_activate_example_activate
function plugin_activate_example_activate()
{
// Activation code here...
// let's create some categories upon activation
//http://codex.wordpress.org/Function_Reference/wp_insert_category
for ($i = 0; $i < 5; $i++) {
$catarr = array('cat_name' => 'My Category' . $i, 'category_description' => 'A Cool Category' . $i, 'category_nicename' => 'category-slug' . $i, 'category_parent' => '');
wp_insert_category($catarr);
}
// should be root path of the wp install
$wordpress_path = get_home_path();
require_once $wordpress_path . '/wp-load.php';
//not sure if this line is needed
//activate_plugin() is here:
require_once $wordpress_path . '/wp-admin/includes/plugin.php';
// we're going to activate our plugins that are dependencies
$plugins = array("filters-example", "js-example", "shortcode-example");
// see
//http://wordpress.stackexchange.com/questions/62967/why-activate-plugin-is-not-working-in-register-activation-hook
foreach ($plugins as $plugin) {
$plugin_path = $wordpress_path . 'wp-content/plugins/' . $plugin . '/' . $plugin . '.php';
if (file_exists($plugin_path) && is_plugin_inactive($plugin . '/' . $plugin . '.php')) {
// just double check that the plugin exists and unactivated
add_action('update_option_active_plugins', 'plugin_activation_dependencies');
}
}
}
开发者ID:aamirs332,项目名称:wordpress-demos,代码行数:27,代码来源:plugin-activation-example.php
示例2: frs_add_slidetype
function frs_add_slidetype()
{
$cat_name = htmlspecialchars($_POST['name']);
$catarr = array('cat_name' => $cat_name, 'taxonomy' => 'slide_type');
$new_cat_id = wp_insert_category($catarr);
$new_cat = get_term_by('id', $new_cat_id, 'slide_type');
$return = array('success' => true, 'slug' => $new_cat->slug);
echo json_encode($return);
die;
}
开发者ID:mystified7545,项目名称:MyBlog,代码行数:10,代码来源:ajax.php
示例3: startedev_get_categoria
function startedev_get_categoria($categoria)
{
$categoria_woocomerce = array('cat_name' => $categoria, 'taxonomy' => 'product_cat');
$cat_woocommerce = wp_insert_category($categoria_woocomerce, true);
if (is_wp_error($cat_woocommerce)) {
return $cat_woocommerce->get_error_data('term_exists');
} else {
return $cat_woocommerce;
}
}
开发者ID:admigmarcelo,项目名称:startedev-plugin-distribuidora,代码行数:10,代码来源:startedev-plugin-distribuidora.php
示例4: setUp
function setUp()
{
parent::setUp();
$author = wp_insert_user(array("user_login" => "testuser", "user_pass" => "testing", "display_name" => "Tester"));
$category_id = wp_insert_category(array('cat_name' => 'Testing'));
wp_insert_post(array("post_name" => "test-post", "post_title" => "Test Post", "post_content" => "This is a test <strong>post</strong>.", "post_status" => "publish", "post_author" => $author, "post_category" => array($category_id), "tags_input" => array("tag1", "tag2"), "post_date" => "2014-01-01"));
wp_insert_post(array("post_name" => "test-page", "post_title" => "Test Page", "post_content" => "This is a test <strong>page</strong>.", "post_status" => "publish", "post_type" => "page", "post_author" => $author));
global $jekyll_export;
$jekyll_export->init_temp_dir();
}
开发者ID:schnommus,项目名称:sebholzapfel.com,代码行数:10,代码来源:test-wordpress-to-jekyll-exporter.php
示例5: part_categories
function part_categories($categories, &$existing_cat, $start_pos)
{
$start_time = time();
for ($i = $start_pos; $i < count($categories); $i++) {
if (!term_exists($categories[$i]->ID, 'product_cat')) {
//если категория не добавлена в базу
if ($categories[$i]->ID == 'Order') {
$parent_id = 0;
}
$parent_id = cat_exists($categories[$i]->ID_PARENT, $existing_cat, 'product_cat');
wp_insert_category(array('cat_name' => $categories[$i]->Description, 'category_nicename' => $categories[$i]->ID, 'category_parent' => $parent_id, 'taxonomy' => 'product_cat'));
}
if (time() - $start_time > 20) {
restart_load_categories($categories, $existing_cat, ++$i);
break;
}
}
}
开发者ID:systemo-biz,项目名称:merlion,代码行数:18,代码来源:merlion_db.php
示例6: csv_import_options_page
function csv_import_options_page()
{
if (empty($_FILES)) {
?>
<div>
<h2>Upload a csv file here to import categories</h2>
<form action="" method="post" enctype="multipart/form-data">
<?php
wp_nonce_field('csv-import');
?>
<label for="file">Filename:</label>
<input type="file" name="file" id="file"><br>
<input type="submit" name="save" value="save">
</form>
</div>
<?php
} else {
if (!function_exists('wp_handle_upload')) {
require_once ABSPATH . 'wp-admin/includes/file.php';
}
$uploadedfile = $_FILES['file'];
$upload_overrides = array('test_form' => false);
$movefile = wp_handle_upload($uploadedfile, $upload_overrides);
if ($movefile) {
echo "File is valid, and was successfully uploaded.\n";
$csv = array_map('str_getcsv', file($movefile['file']));
// the file should be a csv of categories.
$cnt = 0;
foreach ($csv as $row) {
$my_cat = array('cat_name' => $row[0], 'category_description' => $row[1], 'category_nicename' => $row[2], 'category_parent' => '');
// Create the category
$my_cat_id = wp_insert_category($my_cat);
if ($my_cat_id > 0) {
$cnt++;
}
}
echo "{$cnt} categories added";
// here you can do some stuff with this
} else {
echo "Possible file upload attack!\n";
}
}
}
开发者ID:aamirs332,项目名称:wordpress-demos,代码行数:44,代码来源:csv-import.php
示例7: pp_insert_project
function pp_insert_project($project_data, $wp_error = false)
{
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'])) {
unset($project_data['project_parent']);
}
$project_defaults = array('project_ID' => 0, 'project_name' => '', 'project_description' => '', 'project_nicename' => '', 'project_parent' => $project_category_id, 'project_website' => '', 'project_blog' => '', 'project_svn' => '', 'project_trac' => '', 'project_intertrac' => '', 'project_activity' => '', 'project_overheard' => '');
$project_data = wp_parse_args($project_data, $project_defaults);
$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']);
$category_id = wp_insert_category($category_data, $wp_error);
if (!$wp_error && !$category_id) {
return false;
}
if ($wp_error && is_wp_error($category_id)) {
return $cat_ID;
}
$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']);
}
update_option('pp_project_meta_' . $category_id, $project_meta);
return true;
}
开发者ID:rmccue,项目名称:wordpress-unit-tests,代码行数:43,代码来源:functions-admin.php
示例8: wp_newCategory
/**
* WordPress XML-RPC API
* wp_newCategory
*/
function wp_newCategory($args)
{
$this->escape($args);
$blog_id = (int) $args[0];
$username = $args[1];
$password = $args[2];
$category = $args[3];
if (!$this->login_pass_ok($username, $password)) {
return $this->error;
}
// Set the user context and make sure they are
// allowed to add a category.
set_current_user(0, $username);
if (!current_user_can("manage_categories")) {
return new IXR_Error(401, __("Sorry, you do not have the right to add a category."));
}
// If no slug was provided make it empty so that
// WordPress will generate one.
if (empty($category["slug"])) {
$category["slug"] = "";
}
// If no parent_id was provided make it empty
// so that it will be a top level page (no parent).
if (!isset($category["parent_id"])) {
$category["parent_id"] = "";
}
// If no description was provided make it empty.
if (empty($category["description"])) {
$category["description"] = "";
}
$new_category = array("cat_name" => $category["name"], "category_nicename" => $category["slug"], "category_parent" => $category["parent_id"], "category_description" => $category["description"]);
$cat_id = wp_insert_category($new_category);
if (!$cat_id) {
return new IXR_Error(500, __("Sorry, the new category failed."));
}
return $cat_id;
}
开发者ID:helmonaut,项目名称:owb-mirror,代码行数:41,代码来源:xmlrpc.php
示例9: wp_newCategory
/**
* Create new category.
*
* @since 2.2.0
*
* @param array $args Method parameters.
* @return int|IXR_Error Category ID.
*/
public function wp_newCategory($args)
{
$this->escape($args);
$username = $args[1];
$password = $args[2];
$category = $args[3];
if (!($user = $this->login($username, $password))) {
return $this->error;
}
/** This action is documented in wp-includes/class-wp-xmlrpc-server.php */
do_action('xmlrpc_call', 'wp.newCategory');
// Make sure the user is allowed to add a category.
if (!current_user_can('manage_categories')) {
return new IXR_Error(401, __('Sorry, you do not have the right to add a category.'));
}
// If no slug was provided make it empty so that
// WordPress will generate one.
if (empty($category['slug'])) {
$category['slug'] = '';
}
// If no parent_id was provided make it empty
// so that it will be a top level page (no parent).
if (!isset($category['parent_id'])) {
$category['parent_id'] = '';
}
// If no description was provided make it empty.
if (empty($category["description"])) {
$category["description"] = "";
}
$new_category = array('cat_name' => $category['name'], 'category_nicename' => $category['slug'], 'category_parent' => $category['parent_id'], 'category_description' => $category['description']);
$cat_id = wp_insert_category($new_category, true);
if (is_wp_error($cat_id)) {
if ('term_exists' == $cat_id->get_error_code()) {
return (int) $cat_id->get_error_data();
} else {
return new IXR_Error(500, __('Sorry, the new category failed.'));
}
} elseif (!$cat_id) {
return new IXR_Error(500, __('Sorry, the new category failed.'));
}
/**
* Fires after a new category has been successfully created via XML-RPC.
*
* @since 3.4.0
*
* @param int $cat_id ID of the new category.
* @param array $args An array of new category arguments.
*/
do_action('xmlrpc_call_success_wp_newCategory', $cat_id, $args);
return $cat_id;
}
开发者ID:sb-xs,项目名称:que-pour-elle,代码行数:59,代码来源:class-wp-xmlrpc-server.php
示例10: process_post
//.........这里部分代码省略.........
$comment_post_ID = $post_id = $this->process_attachment($postdata, $remote_url);
if (!$post_id or is_wp_error($post_id)) {
return $post_id;
}
} else {
printf(__('Importing post <em>%s</em>...', 'wordpress-importer') . "\n", stripslashes($post_title));
$comment_post_ID = $post_id = wp_insert_post($postdata);
if ($post_id && $is_sticky == 1) {
stick_post($post_id);
}
}
if (is_wp_error($post_id)) {
return $post_id;
}
// Memorize old and new ID.
if ($post_id && $post_ID) {
$this->post_ids_processed[intval($post_ID)] = intval($post_id);
}
// Add categories.
if (count($categories) > 0) {
$post_cats = array();
foreach ($categories as $category) {
if ('' == $category) {
continue;
}
$slug = sanitize_term_field('slug', $category, 0, 'category', 'db');
$cat = get_term_by('slug', $slug, 'category');
$cat_ID = 0;
if (!empty($cat)) {
$cat_ID = $cat->term_id;
}
if ($cat_ID == 0) {
$category = $wpdb->escape($category);
$cat_ID = wp_insert_category(array('cat_name' => $category));
if (is_wp_error($cat_ID)) {
continue;
}
}
$post_cats[] = $cat_ID;
}
wp_set_post_categories($post_id, $post_cats);
}
// Add tags.
if (count($tags) > 0) {
$post_tags = array();
foreach ($tags as $tag) {
if ('' == $tag) {
continue;
}
$slug = sanitize_term_field('slug', $tag, 0, 'post_tag', 'db');
$tag_obj = get_term_by('slug', $slug, 'post_tag');
$tag_id = 0;
if (!empty($tag_obj)) {
$tag_id = $tag_obj->term_id;
}
if ($tag_id == 0) {
$tag = $wpdb->escape($tag);
$tag_id = wp_insert_term($tag, 'post_tag');
if (is_wp_error($tag_id)) {
continue;
}
$tag_id = $tag_id['term_id'];
}
$post_tags[] = intval($tag_id);
}
wp_set_post_tags($post_id, $post_tags);
开发者ID:nishant368,项目名称:newlifeoffice-new,代码行数:67,代码来源:class.wordpress_importer.php
示例11: wp_update_category
/**
* Aliases wp_insert_category() with minimal args.
*
* If you want to update only some fields of an existing category, call this
* function with only the new values set inside $catarr.
*
* @since 2.0.0
*
* @param array $catarr The 'cat_ID' value is required. All other keys are optional.
* @return int|bool The ID number of the new or updated Category on success. Zero or FALSE on failure.
*/
function wp_update_category($catarr)
{
$cat_ID = (int) $catarr['cat_ID'];
if (isset($catarr['category_parent']) && $cat_ID == $catarr['category_parent']) {
return false;
}
// First, get all of the original fields
$category = get_term($cat_ID, 'category', ARRAY_A);
_make_cat_compat($category);
// Escape data pulled from DB.
$category = wp_slash($category);
// Merge old and new fields with new fields overwriting old ones.
$catarr = array_merge($category, $catarr);
return wp_insert_category($catarr);
}
开发者ID:nstungxd,项目名称:F2CA5,代码行数:26,代码来源:taxonomy.php
示例12: import
function import($file)
{
// Parse file
$dalil_items = self::parse($file);
foreach ($dalil_items as $dalil_item) {
$term = term_exists((string) $dalil_item['categorie'], 'w_dalil_category');
if (!$term) {
$catarr = array('cat_name' => (string) $dalil_item['categorie'], 'taxonomy' => 'w_dalil_category');
wp_insert_category($catarr, $wp_error);
if ($wp_error) {
exit;
}
}
$term = term_exists((string) $dalil_item['city'], 'w_dalil_city');
if (!$term) {
$catarr = array('cat_name' => (string) $dalil_item['city'], 'taxonomy' => 'w_dalil_city');
wp_insert_category($catarr, $wp_error);
if ($wp_error) {
exit;
}
}
}
// Initialises a variable storing the number of logs successfully imported.
$imported = 0;
set_time_limit(600);
foreach ($dalil_items as $dalil_item) {
// global $wpdb;
// $query = $wpdb->get_results('SELECT ID FROM ' . $wpdb->posts . ' WHERE post_title = "'. $dalil_item['title'].'"');
// if ( $query ) {
// wp_publish_post( $query[0]->ID );
// continue;
// }
$my_post = array('post_title' => $dalil_item['title'], 'post_type' => 'w_dalil_posttype', 'post_status' => 'publish');
$post_id = wp_insert_post($my_post, $wp_error);
if (null !== (string) $dalil_item['categorie']) {
$item_set_taxonomy = wp_set_object_terms($post_id, (string) $dalil_item['categorie'], 'w_dalil_category');
}
if (null !== (string) $dalil_item['city']) {
$item_set_taxonomy = wp_set_object_terms($post_id, (string) $dalil_item['city'], 'w_dalil_city');
}
if (!$wp_error) {
if (isset($dalil_item['address'])) {
$dalil_data['dalil-address'] = (string) $dalil_item['address'];
}
if (isset($dalil_item['phone'])) {
$dalil_data['dalil-phone'] = (string) $dalil_item['phone'];
}
if (isset($dalil_item['email'])) {
$dalil_data['dalil-email'] = (string) $dalil_item['email'];
}
if (isset($dalil_item['website'])) {
$dalil_data['dalil-website'] = (string) $dalil_item['website'];
}
update_post_meta($post_id, 'dalil_information', $dalil_data);
$imported++;
}
}
return $imported;
}
开发者ID:iyass09,项目名称:w-dalil,代码行数:59,代码来源:w-dalil-functions.php
示例13: new_post
function new_post()
{
global $user_ID;
if (empty($_POST['action']) || $_POST['action'] != 'new_post') {
die('-1');
}
if (!is_user_logged_in()) {
die('<p>' . __('Error: not logged in.', 'p2') . '</p>');
}
if (!(current_user_can('publish_posts') || get_option('p2_allow_users_publish') && $user_ID)) {
die('<p>' . __('Error: not allowed to post.', 'p2') . '</p>');
}
check_ajax_referer('ajaxnonce', '_ajax_post');
$user = wp_get_current_user();
$user_id = $user->ID;
$post_content = $_POST['posttext'];
$tags = trim($_POST['tags']);
$title = $_POST['post_title'];
$post_type = isset($_POST['post_type']) ? $_POST['post_type'] : 'post';
// Strip placeholder text for tags
if (__('Tag it', 'p2') == $tags) {
$tags = '';
}
if (empty($title) || __('Post Title', 'p2') == $title) {
// For empty or placeholder text, create a nice title based on content
$post_title = p2_title_from_content($post_content);
} else {
$post_title = $title;
}
require_once ABSPATH . '/wp-admin/includes/taxonomy.php';
require_once ABSPATH . WPINC . '/category.php';
$accepted_post_cats = apply_filters('p2_accepted_post_cats', array('post', 'quote', 'status', 'link'));
$post_cat = in_array($_POST['post_cat'], $accepted_post_cats) ? $_POST['post_cat'] : 'status';
if (!category_exists($post_cat)) {
wp_insert_category(array('cat_name' => $post_cat));
}
$post_cat = get_category_by_slug($post_cat);
/* Add the quote citation to the content if it exists */
if (!empty($_POST['post_citation']) && 'quote' == $post_cat->slug) {
$post_content = '<p>' . $post_content . '</p><cite>' . $_POST['post_citation'] . '</cite>';
}
$post_content = p2_list_creator($post_content);
$post_id = wp_insert_post(array('post_author' => $user_id, 'post_title' => $post_title, 'post_content' => $post_content, 'post_type' => $post_type, 'post_category' => array($post_cat->cat_ID), 'tags_input' => $tags, 'post_status' => 'publish'));
echo $post_id ? $post_id : '0';
}
开发者ID:rajbot,项目名称:tikirobot_p2,代码行数:45,代码来源:ajax.php
示例14: cherry_plugin_import_categories
function cherry_plugin_import_categories()
{
$nonce = $_POST['nonce'];
if (!wp_verify_nonce($nonce, 'import_ajax-nonce')) {
exit('instal_error');
}
if (session_id() != "import_xml") {
session_name("import_xml");
session_start();
}
do_action('cherry_plugin_import_categories');
$categories_array = $_SESSION['categories'];
$categories_array = apply_filters('wp_import_categories', $categories_array);
if (empty($categories_array)) {
exit('import_tags');
}
foreach ($categories_array as $cat) {
// if the category already exists leave it alone
$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'])) {
$_SESSION['processed_terms'][intval($cat['term_id'])] = (int) $term_id;
}
continue;
}
$category_parent = empty($cat['category_parent']) ? 0 : category_exists($cat['category_parent']);
$category_description = isset($cat['category_description']) ? $cat['category_description'] : '';
$catarr = array('category_nicename' => $cat['category_nicename'], 'category_parent' => $category_parent, 'cat_name' => $cat['cat_name'], 'category_description' => $category_description);
$id = wp_insert_category($catarr);
if (!is_wp_error($id)) {
if (isset($cat['term_id'])) {
$_SESSION['processed_terms'][intval($cat['term_id'])] = $id;
}
} else {
continue;
}
}
unset($_SESSION['categories']);
exit('import_tags');
}
开发者ID:drupalninja,项目名称:schome_org,代码行数:43,代码来源:import-functions.php
示例15: add_categorie
/**
* Adds the categorie to the relevant site
*
* @param $categorie
*
* @return int
*/
public function add_categorie($categorie)
{
$categorie_args = array('cat_name' => $categorie->name, 'category_description' => $categorie->description, 'category_nicename' => $categorie->slug, 'category_parent' => $categorie->parent);
return wp_insert_category($categorie_args);
}
开发者ID:JonZiemlich,项目名称:wpml2mlp,代码行数:12,代码来源:Wpml2mlp_Categorie_Creator.php
示例16: test_insert_category_force_error_no_handle
function test_insert_category_force_error_no_handle()
{
$cat = array('cat_ID' => 0, 'taxonomy' => 'force_error', 'cat_name' => 'Error');
$this->assertEquals(0, wp_insert_category($cat, false));
}
开发者ID:Benrajalu,项目名称:philRaj,代码行数:5,代码来源:taxonomy.php
示例17: wp_create_category
function wp_create_category($cat_name)
{
$cat_array = compact('cat_name');
return wp_insert_category($cat_array);
}
开发者ID:staylor,项目名称:develop.svn.wordpress.org,代码行数:5,代码来源:admin-db.php
示例18: do_post_sync
function do_post_sync($post_id, $post)
{
$this->post_id = $post_id;
$this->post = $post;
if ($this->doing_save_post) {
$this->doing_save_post = false;
return;
}
if ($error = $this->check_for_site_problems()) {
return $this->error_if_wpcli($error);
}
// wp_insert_category()
include_once ABSPATH . 'wp-admin/includes/admin.php';
$allowed_post_types = apply_filters('sitewide_tags_allowed_post_types', array('post' => true));
if (!isset($allowed_post_types[$post->post_type]) || !$allowed_post_types[$post->post_type]) {
return;
}
$post_categories = wp_get_object_terms($post_id, 'category');
if ($post_categories && !is_wp_error($post_categories) && is_array($post_categories)) {
$post->post_category = wp_list_pluck($post_categories, 'term_id');
} else {
$post->post_category = wp_get_post_categories($post_id);
}
$post->tags_input = implode(', ', wp_get_post_tags($post_id, array('fields' => 'names')));
global $wpdb;
$post_blog_id = $wpdb->blogid;
$post->guid = "{$post_blog_id}.{$post_id}";
$this->meta_to_sync = array();
$meta_keys = apply_filters('sitewide_tags_meta_keys', $this->options->get('tags_blog_postmeta', array()));
if (is_array($meta_keys) && !empty($meta_keys)) {
foreach ($meta_keys as $key) {
$this->meta_to_sync[$key] = get_post_meta($post->ID, $key, true);
}
}
unset($meta_keys);
$this->meta_to_sync['permalink'] = get_permalink($post_id);
$this->meta_to_sync['blogid'] = $post_blog_id;
// org_blog_id
if ($this->options->get('tags_blog_thumbs') && ($thumb_id = get_post_thumbnail_id($post->ID))) {
$thumb_sizes = apply_filters('sitewide_tags_thumb_size', array('thumbnail'));
// back-compat
if (is_string($thumb_sizes)) {
$this->meta_to_sync['thumbnail_html'] = wp_get_attachment_image($thumb_id, $thumb_sizes);
} else {
// back-compat
$this->meta_to_sync['thumbnail_html'] = wp_get_attachment_image($thumb_id, 'thumbnail');
}
// new hawtness
foreach ((array) $thumb_sizes as $thumb_size) {
$this->meta_to_sync["thumbnail_html_{$thumb_size}"] = wp_get_attachment_image($thumb_id, $thumb_size);
}
}
// custom taxonomies
$taxonomies = apply_filters('sitewide_tags_custom_taxonomies', array());
if (!empty($taxonomies) && 'publish' == $post->post_status) {
$registered_tax = array_diff(get_taxonomies(), array('post_tag', 'category', 'link_category', 'nav_menu'));
$custom_tax = array_intersect($taxonomies, $registered_tax);
$tax_input = array();
foreach ($custom_tax as $tax) {
$terms = wp_get_object_terms($post_id, $tax, array('fields' => 'names'));
if (empty($terms)) {
continue;
}
if (is_taxonomy_hierarchical($tax)) {
$tax_input[$tax] = $terms;
} else {
$tax_input[$tax] = implode(',', $terms);
}
}
if (!empty($tax_input)) {
$post->tax_input = $tax_input;
}
}
$tags_blog_id = $this->options->get('tags_blog_id');
switch_to_blog($tags_blog_id);
$category_ids = array();
if (is_array($post_categories) && !empty($post_categories) && 'publish' == $post->post_status) {
foreach ($post_categories as $t => $category) {
$term = get_term_by('slug', $category->slug, 'category');
$term = apply_filters('sitewide_tags_get_term', $term, $category, $this);
if ($this->debug) {
echo '<xmp>$category_to_migrate: ' . print_r($category, true) . '</xmp>';
echo '<xmp>$term_on_aggregate: ' . print_r($term, true) . '</xmp>';
}
if ($term && 0 == $term->parent) {
$category_ids[] = $term->term_id;
continue;
}
// Here is where we insert the category if necessary
$category_id = wp_insert_category(array('cat_name' => $category->name, 'category_description' => $category->name, 'category_nicename' => $category->slug, 'category_parent' => ''), true);
if (is_wp_error($category_id) && false !== stripos($category_id->get_error_message(), 'already exists') && is_numeric($category_id->get_error_data())) {
$category_ids[] = $category_id->get_error_data();
} elseif (is_numeric($category_id)) {
$category_ids[] = $category_id;
}
}
}
if ($this->debug) {
wp_die('<xmp>$category_ids_to_add_to_post: ' . print_r($category_ids, true) . '</xmp>');
}
//.........这里部分代码省略.........
开发者ID:clovepod,项目名称:WDS-Multisite-Aggregate,代码行数:101,代码来源:wds-multisite-aggregate.php
示例19: cat2wp
function cat2wp($categories = '')
{
// General Housekeeping
global $wpdb;
$count = 0;
$dccat2wpcat = array();
// Do the Magic
if (is_array($categories)) {
echo '<p>' . __('Importing Categories...') . '<br /><br /></p>';
foreach ($categories as $category) {
$count++;
extract($category);
// Make Nice Variables
$name = $wpdb->escape($cat_libelle_url);
$title = $wpdb->escape(csc($cat_libelle));
$desc = $wpdb->escape(csc($cat_desc));
if ($cinfo = category_exists($name)) {
$ret_id = wp_insert_category(array('cat_ID' => $cinfo, 'category_nicename' => $name, 'cat_name' => $title, 'category_description' => $desc));
} else {
$ret_id = wp_insert_category(array('category_nicename' => $name, 'cat_name' => $title, 'category_description' => $desc));
}
$dccat2wpcat[$id] = $ret_id;
}
// Store category translation for future use
add_option('dccat2wpcat', $dccat2wpcat);
echo '<p>' . sprintf(__('Done! <strong>%1$s</strong> categories imported.'), $count) . '<br /><br /></p>';
return true;
}
echo __('No Categories to Import!');
return false;
}
开发者ID:helmonaut,项目名称:owb-mirror,代码行数:31,代码来源:dotclear.php
示例20: check_ajax_referer
break;
case 'add-cat':
// From Manage->Categories
check_ajax_referer('add-category');
if (!current_user_can('manage_categories')) {
die('-1');
}
if ('' === trim($_POST['cat_name'])) {
$x = new WP_Ajax_Response(array('what' => 'cat', 'id' => new WP_Error('cat_name', __('You did not enter a category name.'))));
$x->send();
}
if (category_exists(trim($_POST['cat_name']), $_POST['category_parent'])) {
$x = new WP_Ajax_Response(array('what' => 'cat', 'id' => new WP_Error('cat_exists', __('The category you are trying to create already exists.'), array('form-field' => 'cat_name'))));
$x->send();
}
$cat = wp_insert_category($_POST, true);
if (is_wp_error($cat)) {
$x = new WP_Ajax_Response(array('what' => 'cat', 'id' => $cat));
$x->send();
}
if (!$cat || !($cat = get_category($cat))) {
die('0');
}
$level = 0;
$cat_full_name = $cat->name;
$_cat = $cat;
while ($_cat->parent) {
$_cat = get_category($_cat->parent);
$cat_full_name = $_cat->name . ' — ' . $cat_full_name;
$level++;
}
开发者ID:nagyist,项目名称:laura-wordpress,代码行数:31,代码来源:admin-ajax.php
注:本文中的wp_insert_category函数示例整理自Github/MSDocs等源码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。 |
请发表评论