function wp_insert_category($catarr) { global $wpdb; extract($catarr, EXTR_SKIP); if (trim($cat_name) == '') { return 0; } $cat_ID = (int) $cat_ID; // Are we updating or creating? if (!empty($cat_ID)) { $update = true; } else { $update = false; } $name = $cat_name; $description = $category_description; $slug = $category_nicename; $parent = $category_parent; $parent = (int) $parent; if (empty($parent) || !category_exists($parent) || $cat_ID && cat_is_ancestor_of($cat_ID, $parent)) { $parent = 0; } $args = compact('name', 'slug', 'parent', 'description'); if ($update) { $cat_ID = wp_update_term($cat_ID, 'category', $args); } else { $cat_ID = wp_insert_term($cat_name, 'category', $args); } if (is_wp_error($cat_ID)) { return 0; } return $cat_ID['term_id']; }
/** * @ticket 30975 */ public function test_category_exists_should_respect_nonempty_parent() { $c1 = $this->factory->category->create(); $c2 = $this->factory->category->create(array('name' => 'Foo', 'parent' => $c1)); $c3 = $this->factory->category->create(array('name' => 'Foo')); $found = category_exists('Foo', $c1); $this->assertEquals($found, $c2); }
function _category_exists($cat_id) { global $wpdb; $cat_id = (int) $cat_id; $maybe_exists = category_exists($cat_id); if ($maybe_exists) { return true; } else { return false; } }
function ConvertSubject() { global $wpdb; $subjects = $wpdb->get_results("SELECT * FROM subject", 'ARRAY_A'); /* foreach ($subjects as $subject) { $tag_id = ''; $tag_id = term_exists($subject['name']); if ($tag_id == 0){ $tag_id = wp_create_term($subject['name'],'post_tag' ); $tag_id = $wpdb->get_var("SELECT MAX(`term_id`) FROM $wpdb->terms"); $wpdb->insert( 'subject_to_tag', array( 'subject_id' => $subject['id'], 'tag_id' => $tag_id ), array( '%d', '%d' ) ); } } */ foreach ($subjects as $category) { if ($term_id = category_exists($category['name'])) { $wpdb->insert('category_to_terms', array('category_id' => $category['id'], 'term_id' => $term_id), array('%d', '%d')); } else { $parent = $wpdb->get_var("SELECT `term_id` FROM `category_to_terms` WHERE `category_id` = '" . $category['parent'] . "'"); if ($term_id = wp_create_category($category['name'], $parent)) { $wpdb->insert('category_to_terms', array('category_id' => $category['id'], 'term_id' => $term_id), array('%d', '%d')); } } } $count = $wpdb->get_var("SELECT COUNT(*) FROM `subject_to_tag`"); ?> <html> <head> <meta charset='UTF-8' /> </head> <body> <?php echo $count; ?> </body> </html> <!-- end HTML part --> <?php SelestAction(); }
/** * Create categories for the given post. * * @since 2.0.0 * * @param array $categories List of categories to create. * @param int $post_id Optional. The post ID. Default empty. * @return List of categories to create for the given post. */ function wp_create_categories($categories, $post_id = '') { $cat_ids = array(); foreach ($categories as $category) { if ($id = category_exists($category)) { $cat_ids[] = $id; } elseif ($id = wp_create_category($category)) { $cat_ids[] = $id; } } if ($post_id) { wp_set_post_categories($post_id, $cat_ids); } return $cat_ids; }
function wp_insert_category($catarr, $wp_error = false) { $cat_defaults = array('cat_ID' => 0, 'cat_name' => '', 'category_description' => '', 'category_nicename' => '', 'category_parent' => ''); $cat_arr = wp_parse_args($cat_arr, $cat_defaults); extract($catarr, EXTR_SKIP); if ( trim( $cat_name ) == '' ) { if ( ! $wp_error ) return 0; else return new WP_Error( 'cat_name', __('You did not enter a category name.') ); } $cat_ID = (int) $cat_ID; // Are we updating or creating? if ( !empty ($cat_ID) ) $update = true; else $update = false; $name = $cat_name; $description = $category_description; $slug = $category_nicename; $parent = $category_parent; $parent = (int) $parent; if ( $parent < 0 ) $parent = 0; if ( empty($parent) || !category_exists( $parent ) || ($cat_ID && cat_is_ancestor_of($cat_ID, $parent) ) ) $parent = 0; $args = compact('name', 'slug', 'parent', 'description'); if ( $update ) $cat_ID = wp_update_term($cat_ID, 'category', $args); else $cat_ID = wp_insert_term($cat_name, 'category', $args); if ( is_wp_error($cat_ID) ) { if ( $wp_error ) return $cat_ID; else return 0; } return $cat_ID['term_id']; }
function wpinstaroll_getInstagramGeneratedDraftPosts() { $category_for_post = get_option(WP_ROLL_INSTAGRAM_PLUGIN_PREFIX . '_instagram_post_category'); if (empty($category_for_post)) { $category_for_post = 'Uncategorized'; update_option(WP_ROLL_INSTAGRAM_PLUGIN_PREFIX . '_instagram_post_category', $category_for_post); } $cat_id = category_exists($category_for_post); if ($cat_id) { $category = get_category($cat_id); $category_slug = $category->slug; return get_bloginfo('wpurl') . '/wp-admin/edit.php?post_status=draft&post_type=post&category_name=' . $category_slug; } else { return get_bloginfo('wpurl') . '/wp-admin/edit.php?post_status=draft&post_type=post'; } }
function process_categories() { global $wpdb; $cat_names = (array) $wpdb->get_col("SELECT cat_name FROM {$wpdb->categories}"); while ($c = array_shift($this->categories)) { $cat_name = trim(str_replace(array('<![CDATA[', ']]>'), '', $this->get_tag($c, 'wp:cat_name'))); // If the category exists we leave it alone if (in_array($cat_name, $cat_names)) { continue; } $category_nicename = $this->get_tag($c, 'wp:category_nicename'); $posts_private = (int) $this->get_tag($c, 'wp:posts_private'); $links_private = (int) $this->get_tag($c, 'wp:links_private'); $parent = $this->get_tag($c, 'wp:category_parent'); if (empty($parent)) { $category_parent = '0'; } else { $category_parent = category_exists($parent); } $catarr = compact('category_nicename', 'category_parent', 'posts_private', 'links_private', 'posts_private', 'cat_name'); $cat_ID = wp_insert_category($catarr); } }
function process_categories() { global $wpdb; $cat_names = (array) get_terms('category', 'fields=names'); while ($c = array_shift($this->categories)) { $cat_name = trim($this->get_tag($c, 'wp:cat_name')); // If the category exists we leave it alone if (in_array($cat_name, $cat_names)) { continue; } $category_nicename = $this->get_tag($c, 'wp:category_nicename'); $category_description = $this->get_tag($c, 'wp:category_description'); $posts_private = (int) $this->get_tag($c, 'wp:posts_private'); $links_private = (int) $this->get_tag($c, 'wp:links_private'); $parent = $this->get_tag($c, 'wp:category_parent'); if (empty($parent)) { $category_parent = '0'; } else { $category_parent = category_exists($parent); } $catarr = compact('category_nicename', 'category_parent', 'posts_private', 'links_private', 'posts_private', 'cat_name', 'category_description'); $cat_ID = wp_insert_category($catarr); } }
function test_wp_insert_delete_category() { $term = rand_str(); $this->assertNull( category_exists( $term ) ); $initial_count = wp_count_terms( 'category' ); $t = wp_insert_category( array( 'cat_name' => $term ) ); $this->assertTrue( is_numeric($t) ); $this->assertFalse( is_wp_error($t) ); $this->assertTrue( $t > 0 ); $this->assertEquals( $initial_count + 1, wp_count_terms( 'category' ) ); // make sure the term exists $this->assertTrue( term_exists($term) > 0 ); $this->assertTrue( term_exists($t) > 0 ); // now delete it $this->assertTrue( wp_delete_category($t) ); $this->assertNull( term_exists($term) ); $this->assertNull( term_exists($t) ); $this->assertEquals( $initial_count, wp_count_terms('category') ); }
function test_query_cat() { $cat = category_exists('cat-b'); $posts = $this->q->query("cat={$cat}"); // there are 4 posts with Cat B $this->assertCount(4, $posts); $this->assertEquals('cat-b', $posts[0]->post_name); $this->assertEquals('cats-b-and-c', $posts[1]->post_name); $this->assertEquals('cats-a-and-b', $posts[2]->post_name); $this->assertEquals('cats-a-b-c', $posts[3]->post_name); }
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; }
$cat_name = wp_specialchars(stripslashes($cat_name)); $x->add(array('what' => 'link-category', 'id' => $cat_id, 'data' => "<li id='link-category-{$cat_id}'><label for='in-link-category-{$cat_id}' class='selectit'><input value='{$cat_id}' type='checkbox' checked='checked' name='link_category[]' id='in-link-category-{$cat_id}'/> {$cat_name}</label></li>", 'position' => -1)); } $x->send(); 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']))) { $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) {
function process_categories() { global $wpdb; $cat_names = (array) get_terms('category', array('fields' => 'names')); while ($c = array_shift($this->categories)) { $cat_name = trim($this->get_tag($c, 'wp:cat_name')); // If the category exists we leave it alone if (in_array($cat_name, $cat_names)) { continue; } $category_nicename = $this->get_tag($c, 'wp:category_nicename'); $category_description = $this->get_tag($c, 'wp:category_description'); $posts_private = (int) $this->get_tag($c, 'wp:posts_private'); $links_private = (int) $this->get_tag($c, 'wp:links_private'); $parent = $this->get_tag($c, 'wp:category_parent'); if (empty($parent)) { $category_parent = '0'; } else { $category_parent = category_exists($parent); } $catarr = compact('category_nicename', 'category_parent', 'posts_private', 'links_private', 'posts_private', 'cat_name', 'category_description'); print '<em>' . sprintf(__('Importing category <em>%s</em>…', 'wordpress-importer'), esc_html($cat_name)) . '</em><br />' . "\n"; $cat_ID = wp_insert_term($cat_name, 'category', $catarr); } }
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'; }
public function process_mailbox($p_mailbox) { $this->_mailbox = $p_mailbox + ERP_get_default_mailbox(); if ($this->_functionality_enabled) { if ($this->_mailbox['enabled']) { // Check whether EmailReporting supports the mailbox type. The check is based on available default ports if (isset($this->_default_ports[$this->_mailbox['mailbox_type']])) { if (project_exists($this->_mailbox['project_id'])) { if (category_exists($this->_mailbox['global_category_id'])) { $t_upload_folder_passed = TRUE; if ($this->_allow_file_upload && $this->_file_upload_method == DISK) { $t_upload_folder_passed = FALSE; $t_file_path = project_get_field($this->_mailbox['project_id'], 'file_path'); if ($t_file_path == '') { $t_file_path = config_get('absolute_path_default_upload_folder'); } $t_file_path = ERP_prepare_directory_string($t_file_path, TRUE); $t_real_file_path = ERP_prepare_directory_string($t_file_path); if (!file_exists($t_file_path) || !is_dir($t_file_path) || !is_writable($t_file_path) || !is_readable($t_file_path)) { $this->custom_error('Upload folder is not writable: ' . $t_file_path . "\n"); } elseif (strcasecmp($t_real_file_path, $t_file_path) !== 0) { $this->custom_error('Upload folder is not an absolute path' . "\n" . 'Upload folder: ' . $t_file_path . "\n" . 'Absolute path: ' . $t_real_file_path . "\n"); } else { $t_upload_folder_passed = TRUE; } } if ($t_upload_folder_passed) { $this->prepare_mailbox_hostname(); if (!$this->_test_only && $this->_mail_debug) { var_dump($this->_mailbox); } $this->show_memory_usage('Start process mailbox'); $t_process_mailbox_function = 'process_' . strtolower($this->_mailbox['mailbox_type']) . '_mailbox'; $this->{$t_process_mailbox_function}(); $this->show_memory_usage('Finished process mailbox'); } } else { $this->custom_error('Category does not exist'); } } else { $this->custom_error('Project does not exist'); } } else { $this->custom_error('Unknown mailbox type'); } } else { $this->custom_error('Mailbox disabled'); } } return $this->_result; }
<?php session_start(); require_once $_SERVER['DOCUMENT_ROOT'] . "/exam-simulator/private/functions/sql_functions.php"; require_once $_SERVER['DOCUMENT_ROOT'] . "/exam-simulator/private/functions/session_functions.php"; require_once $_SERVER['DOCUMENT_ROOT'] . "/exam-simulator/private/functions/input.php"; require_once $_SERVER['DOCUMENT_ROOT'] . "/exam-simulator/private/functions/templates.php"; if (logged_in() && isset($_GET['examName']) && isset($_GET['examID']) && isset($_GET['examCat'])) { $examCat = fix_string($_GET['examCat']); $examID = fix_string($_GET['examID']); $examName = fix_string($_GET['examName']); if (!exam_exists($examID, $examName) || !category_exists($examCat)) { // checks if user has selected a real exam and category go_home(); } $get_script = "\$.getScript('javascript/single_exam_edit.js');"; $content = get_exam_content($examID, $examName, $examCat); get_main_template($content, $get_script); } else { go_home(); }
/** * Check whether the category exists in the project * Trigger an error if it does not * @param int $p_category_id category id * @access public */ function category_ensure_exists( $p_category_id ) { if( !category_exists( $p_category_id ) ) { trigger_error( ERROR_CATEGORY_NOT_FOUND, ERROR ); } }
/** * Create new categories based on import information * * Doesn't create a new category if its slug already exists */ function process_categories() { $this->categories = apply_filters('wp_import_categories', $this->categories); if (empty($this->categories)) { return; } foreach ($this->categories 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'])) { $this->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'])) { $this->processed_terms[intval($cat['term_id'])] = $id; } } else { // printf( theme_locals('import_category'), esc_html($cat['category_nicename']) ); // echo '<br />';| $this->log($id->get_error_message()); $this->log('Failed to import category ' . esc_html($cat["category_nicename"])); continue; } } unset($this->categories); }
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(); } }
/** * Create new categories based on import information * * Doesn't create a new category if its slug already exists */ function process_categories() { $this->categories = apply_filters('wp_import_categories', $this->categories); if (empty($this->categories)) { return; } foreach ($this->categories 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'])) { $this->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'])) { $this->processed_terms[intval($cat['term_id'])] = $id; } } else { if (defined('WP_DEBUG') && WP_DEBUG === TRUE) { printf(__('Failed to import category %s', 'wordpress-importer'), esc_html($cat['category_nicename'])); if (defined('IMPORT_DEBUG') && IMPORT_DEBUG) { echo ': ' . $id->get_error_message(); } echo '<br />'; } //Roll back the import do_action('pcst_rollback_import', 'failed to import: ', 'Category', esc_html($cat['category_nicename'])); continue; } } unset($this->categories); }
/** * Imports options and fields from the XML file given. * @param $xmlFilename the file to import from. * @return boolean true on success, false on failure */ function importFromXML($xmlFilename) { //parse the xml file $xmlParser = new PhotoQXMLParser($xmlFilename); $xmlParser->parse(); //store the parsed options if they validate if ($xmlParser->validate()) { $optionArray = $xmlParser->getParsedOptions(); $fieldArray = $xmlParser->getParsedFields(); $catsArray = $xmlParser->getParsedCats(); //right now we only support one default category $defaultCat = null; if (!empty($catsArray)) { $defaultCat = $catsArray[0]; } //delete views that are no longer used in the new settings $this->_deleteObsoleteViews($this->getViewNames(), $xmlParser->getViewNames()); //delete image sizes that are no longer used in the new settings $this->_deleteObsoleteImageSizes($this->getImageSizeNames(), $xmlParser->getImageSizeNames()); //add custom fields required by views setting of xml file, //conflicts with fields will not happen as this is already tested in validation. foreach ($xmlParser->getViewNames(true) as $view) { $this->addViewCallback($view, true); } //it may happen that some fields are already there. Do not show an error in this case $this->_errStack->pushCallback(array('PhotoQErrorHandler', 'mutePHOTOQ_FIELD_EXISTS')); //create fields required by the xml file foreach ($fieldArray as $fieldname) { $this->_db->insertField($fieldname, true); } //add default tags to all photoq posts if (isset($optionArray['qPostDefaultTags']['qPostDefaultTags']) && !empty($optionArray['qPostDefaultTags']['qPostDefaultTags'])) { $newTags = preg_split("/[\\s]*,[\\s]*/", $optionArray['qPostDefaultTags']['qPostDefaultTags']); $postIDs = $this->_db->getAllPublishedPhotoIDs(); foreach ($postIDs as $id) { //update the tags in the database wp_set_post_tags($id, add_magic_quotes($newTags), true); } //update all posts in the queue $qEntries = $this->_db->getQueueIDTagPairs(); foreach ($qEntries as $entry) { $oldTags = preg_split("/[\\s]*,[\\s]*/", $entry->q_tags); $tagString = implode(',', array_unique(array_merge($newTags, $oldTags))); $this->_db->updateTags($entry->q_img_id, $tagString); } } //same for default category if ($defaultCat) { //create it if it does not exist if (!category_exists($defaultCat)) { $catID = wp_insert_category(array('cat_name' => $defaultCat)); if (is_wp_error($catID)) { $defaultCat = NULL; } } else { $catID = get_cat_id($defaultCat); } //get all posts and add default category to list of cats $postIDs = $this->_db->getAllPublishedPhotoIDs(); foreach ($postIDs as $id) { //update the tags in the database wp_set_object_terms($id, $defaultCat, 'category', true); } //update all posts in the queue if (!is_wp_error($catID)) { $qIds = $this->_db->getAllQueuedPhotoIDs(); foreach ($qIds as $id) { if (!in_array($catID, $this->_db->getCategoriesByImgId($id))) { $this->_db->insertCategory($id, $catID); } } } } //store the imported options to the database $storedOptions = get_option($this->_optionsDBName); foreach ($optionArray as $key => $val) { if (array_key_exists($key, $storedOptions)) { $storedOptions[$key] = PhotoQHelper::arrayHtmlEntities($val); } } update_option($this->_optionsDBName, $storedOptions); //reload to make the changes active $this->load(); return true; } return false; }
private function check_category($category) { if (is_null($category)) { return true; } $term = category_exists($category); if (empty($term) || is_wp_error($term)) { WP_CLI::warning(sprintf('Could not find a category matching %s', $category)); return false; } $this->export_args['category'] = $category; return true; }
$cat_name = esc_html(stripslashes($cat_name)); $x->add(array('what' => 'link-category', 'id' => $cat_id, 'data' => "<li id='link-category-{$cat_id}'><label for='in-link-category-{$cat_id}' class='selectit'><input value='" . esc_attr($cat_id) . "' type='checkbox' checked='checked' name='link_category[]' id='in-link-category-{$cat_id}'/> {$cat_name}</label></li>", 'position' => -1)); } $x->send(); 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) {
# No need to call email_generic(), bugnote_add() does it } else { email_bug_updated($t_bug_id); } helper_call_custom_function('issue_update_notify', array($t_bug_id)); } else { $t_failed_ids[$t_bug_id] = lang_get('bug_actiongroup_status'); } } else { $t_failed_ids[$t_bug_id] = lang_get('bug_actiongroup_access'); } break; case 'UP_CATEGORY': $f_category_id = gpc_get_int('category'); if (access_has_bug_level(config_get('update_bug_threshold'), $t_bug_id)) { if (category_exists($f_category_id)) { # @todo we need to issue a helper_call_custom_function( 'issue_update_validate', array( $t_bug_id, $t_bug_data, $f_bugnote_text ) ); bug_set_field($t_bug_id, 'category_id', $f_category_id); email_bug_updated($t_bug_id); helper_call_custom_function('issue_update_notify', array($t_bug_id)); } else { $t_failed_ids[$t_bug_id] = lang_get('bug_actiongroup_category'); } } else { $t_failed_ids[$t_bug_id] = lang_get('bug_actiongroup_access'); } break; case 'UP_PRODUCT_VERSION': $f_product_version = gpc_get_string('product_version'); if (access_has_bug_level(config_get('update_bug_threshold'), $t_bug_id)) { if ($f_product_version === '' || version_get_id($f_product_version, $t_bug->project_id) !== false) {
function pre_save_category() { // allow adding categories with the same name in different languages global $wpdb; if (isset($_POST['action']) && $_POST['action'] == 'add-cat') { if (category_exists($_POST['cat_name']) && isset($_POST['icl_category_language']) && $_POST['icl_category_language'] != $this->get_default_language()) { $_POST['cat_name'] .= ' @' . $_POST['icl_category_language']; } } }
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'); }
} else { if ( wp_set_comment_status( $comment->comment_ID, 'hold' ) ) die('1'); } die('0'); break; case 'add-category' : // On the Fly if ( !current_user_can( 'manage_categories' ) ) die('-1'); $names = explode(',', $_POST['newcat']); $x = new WP_Ajax_Response(); foreach ( $names as $cat_name ) { $cat_name = trim($cat_name); if ( !$category_nicename = sanitize_title($cat_name) ) die('0'); if ( !$cat_id = category_exists( $cat_name ) ) $cat_id = wp_create_category( $cat_name ); $cat_name = wp_specialchars(stripslashes($cat_name)); $x->add( array( 'what' => 'category', 'id' => $cat_id, 'data' => "<li id='category-$cat_id'><label for='in-category-$cat_id' class='selectit'><input value='$cat_id' type='checkbox' checked='checked' name='post_category[]' id='in-category-$cat_id'/> $cat_name</label></li>" ) ); } $x->send(); break; case 'add-cat' : // From Manage->Categories if ( !current_user_can( 'manage_categories' ) ) die('-1'); if ( !$cat = wp_insert_category( $_POST ) ) die('0');
/** * Create new categories based on import information * * Doesn't create a new category if its slug already exists */ function process_categories() { if (empty($this->categories)) { return; } foreach ($this->categories 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'])) { $this->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'])) { $this->processed_terms[intval($cat['term_id'])] = $id; } } else { printf(__('Failed to import category %s', 'radium'), esc_html($cat['category_nicename'])); if (defined('IMPORT_DEBUG') && IMPORT_DEBUG) { echo ': ' . $id->get_error_message(); } echo '<br />'; continue; } } unset($this->categories); }
$t_project = bug_get_field($t_bug_id, 'project_id'); if (access_has_bug_level(access_get_status_threshold($f_status, $t_project), $t_bug_id)) { if (TRUE == bug_check_workflow($t_status, $f_status)) { bug_set_field($t_bug_id, 'status', $f_status); } else { $t_failed_ids[$t_bug_id] = lang_get('bug_actiongroup_status'); } } else { $t_failed_ids[$t_bug_id] = lang_get('bug_actiongroup_access'); } break; case 'UP_CATEGORY': $f_category = gpc_get_string('category'); $t_project = bug_get_field($t_bug_id, 'project_id'); if (access_has_bug_level(config_get('update_bug_threshold'), $t_bug_id)) { if (category_exists($t_project, $f_category)) { bug_set_field($t_bug_id, 'category', $f_category); } else { $t_failed_ids[$t_bug_id] = lang_get('bug_actiongroup_category'); } } else { $t_failed_ids[$t_bug_id] = lang_get('bug_actiongroup_access'); } break; case 'VIEW_STATUS': if (access_has_bug_level(config_get('change_view_status_threshold'), $t_bug_id)) { $f_view_status = gpc_get_int('view_status'); bug_set_field($t_bug_id, 'view_state', $f_view_status); } else { $t_failed_ids[$t_bug_id] = lang_get('bug_actiongroup_access'); }