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'); } } }
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; }
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; } }
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(); }
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; } } }
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"; } } }
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; }
/** * 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; }
/** * 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; }
function process_post($post) { global $wpdb; $post_ID = (int) $this->get_tag($post, 'wp:post_id'); if ($post_ID && !empty($this->post_ids_processed[$post_ID])) { // Processed already return 0; } set_time_limit(60); // There are only ever one of these $post_title = $this->get_tag($post, 'title'); $post_date = $this->get_tag($post, 'wp:post_date'); $post_date_gmt = $this->get_tag($post, 'wp:post_date_gmt'); $comment_status = $this->get_tag($post, 'wp:comment_status'); $ping_status = $this->get_tag($post, 'wp:ping_status'); $post_status = $this->get_tag($post, 'wp:status'); $post_name = $this->get_tag($post, 'wp:post_name'); $post_parent = $this->get_tag($post, 'wp:post_parent'); $menu_order = $this->get_tag($post, 'wp:menu_order'); $post_type = $this->get_tag($post, 'wp:post_type'); $post_password = $this->get_tag($post, 'wp:post_password'); $is_sticky = $this->get_tag($post, 'wp:is_sticky'); $guid = $this->get_tag($post, 'guid'); $post_author = $this->get_tag($post, 'dc:creator'); $post_excerpt = $this->get_tag($post, 'excerpt:encoded'); $post_excerpt = preg_replace_callback('|<(/?[A-Z]+)|', array(&$this, '_normalize_tag'), $post_excerpt); $post_excerpt = str_replace('<br>', '<br />', $post_excerpt); $post_excerpt = str_replace('<hr>', '<hr />', $post_excerpt); $post_content = $this->get_tag($post, 'content:encoded'); $post_content = preg_replace_callback('|<(/?[A-Z]+)|', array(&$this, '_normalize_tag'), $post_content); $post_content = str_replace('<br>', '<br />', $post_content); $post_content = str_replace('<hr>', '<hr />', $post_content); preg_match_all('|<category domain="tag">(.*?)</category>|is', $post, $tags); $tags = $tags[1]; $tag_index = 0; foreach ($tags as $tag) { $tags[$tag_index] = $wpdb->escape(html_entity_decode(str_replace(array('<![CDATA[', ']]>'), '', $tag))); $tag_index++; } preg_match_all('|<category>(.*?)</category>|is', $post, $categories); $categories = $categories[1]; $cat_index = 0; foreach ($categories as $category) { $categories[$cat_index] = $wpdb->escape(html_entity_decode(str_replace(array('<![CDATA[', ']]>'), '', $category))); $cat_index++; } $post_exists = $wpdb->get_row("SELECT ID FROM wp_posts WHERE post_title = '" . $post_title . "' && post_status = 'publish'", 'ARRAY_N'); if ($post_exists) { echo '<li>'; printf(__('Post <em>%s</em> already exists.', 'wordpress-importer'), stripslashes($post_title)); $comment_post_ID = $post_id = $post_exists; } else { // If it has parent, process parent first. $post_parent = (int) $post_parent; if ($post_parent) { // if we already know the parent, map it to the local ID if (isset($this->post_ids_processed[$post_parent])) { $post_parent = $this->post_ids_processed[$post_parent]; // new ID of the parent } else { // record the parent for later $this->orphans[intval($post_ID)] = $post_parent; } } echo '<li>'; $post_author = $this->checkauthor($post_author); //just so that if a post already exists, new users are not created by checkauthor $postdata = compact('post_author', 'post_date', 'post_date_gmt', 'post_content', 'post_excerpt', 'post_title', 'post_status', 'post_name', 'comment_status', 'ping_status', 'guid', 'post_parent', 'menu_order', 'post_type', 'post_password'); $postdata['import_id'] = $post_ID; if ($post_type == 'attachment') { $remote_url = $this->get_tag($post, 'wp:attachment_url'); if (!$remote_url) { $remote_url = $guid; } $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); } } // Now for comments preg_match_all('|<wp:comment>(.*?)</wp:comment>|is', $post, $comments); $comments = $comments[1]; $num_comments = 0; $inserted_comments = array(); if ($comments) { foreach ($comments as $comment) { $comment_id = $this->get_tag($comment, 'wp:comment_id'); $newcomments[$comment_id]['comment_post_ID'] = $comment_post_ID; $newcomments[$comment_id]['comment_author'] = $this->get_tag($comment, 'wp:comment_author'); $newcomments[$comment_id]['comment_author_email'] = $this->get_tag($comment, 'wp:comment_author_email'); $newcomments[$comment_id]['comment_author_IP'] = $this->get_tag($comment, 'wp:comment_author_IP'); $newcomments[$comment_id]['comment_author_url'] = $this->get_tag($comment, 'wp:comment_author_url'); $newcomments[$comment_id]['comment_date'] = $this->get_tag($comment, 'wp:comment_date'); $newcomments[$comment_id]['comment_date_gmt'] = $this->get_tag($comment, 'wp:comment_date_gmt'); $newcomments[$comment_id]['comment_content'] = $this->get_tag($comment, 'wp:comment_content'); $newcomments[$comment_id]['comment_approved'] = $this->get_tag($comment, 'wp:comment_approved'); $newcomments[$comment_id]['comment_type'] = $this->get_tag($comment, 'wp:comment_type'); $newcomments[$comment_id]['comment_parent'] = $this->get_tag($comment, 'wp:comment_parent'); } // Sort by comment ID, to make sure comment parents exist (if there at all) ksort($newcomments); foreach ($newcomments as $key => $comment) { // if this is a new post we can skip the comment_exists() check if (!$post_exists || !comment_exists($comment['comment_author'], $comment['comment_date'])) { if (isset($inserted_comments[$comment['comment_parent']])) { $comment['comment_parent'] = $inserted_comments[$comment['comment_parent']]; } $comment = wp_filter_comment($comment); $inserted_comments[$key] = wp_insert_comment($comment); $num_comments++; } } } if ($num_comments) { printf(' ' . _n('(%s comment)', '(%s comments)', $num_comments, 'wordpress-importer'), $num_comments); } // Now for post meta preg_match_all('|<wp:postmeta>(.*?)</wp:postmeta>|is', $post, $postmeta); $postmeta = $postmeta[1]; if ($postmeta) { foreach ($postmeta as $p) { $key = $this->get_tag($p, 'wp:meta_key'); $value = $this->get_tag($p, 'wp:meta_value'); $this->process_post_meta($post_id, $key, $value); } } do_action('import_post_added', $post_id); print "</li>\n"; }
/** * 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); }
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; }
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'; }
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'); }
/** * 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); }
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)); }
function wp_create_category($cat_name) { $cat_array = compact('cat_name'); return wp_insert_category($cat_array); }
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>'); } $global_post = $wpdb->get_row($wpdb->prepare("SELECT * FROM {$wpdb->posts} WHERE guid IN (%s,%s)", $post->guid, esc_url($post->guid))); if ('publish' != $post->post_status && is_object($global_post) && isset($global_post->ID)) { wp_delete_post($global_post->ID); } else { if (isset($global_post->ID) && $global_post->ID != '') { $post->ID = $global_post->ID; // editing an old post foreach (array_keys($this->meta_to_sync) as $key) { delete_post_meta($global_post->ID, $key); } } else { unset($post->ID); // new post } } if ('publish' == $post->post_status) { $post->ping_status = 'closed'; $post->comment_status = 'closed'; // Use the category IDs in the post $post->post_category = $category_ids; $this->doing_save_post = true; $post_id = wp_insert_post($post, true); if (!is_wp_error($post_id)) { // do meta sync action do_action('wds_multisite_aggregate_post_sync', $post_id, $post, $this->meta_to_sync); $this->imported[] = $post; } } restore_current_blog(); }
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; }
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++; }
/** * Create new category. * * @since 2.2.0 * * @param array $args Method parameters. * @return int Category ID. */ function wp_newCategory($args) { $this->escape($args); $blog_id = (int) $args[0]; $username = $args[1]; $password = $args[2]; $category = $args[3]; if (!($user = $this->login($username, $password))) { return $this->error; } 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.')); } do_action('xmlrpc_call_success_wp_newCategory', $cat_id, $args); return $cat_id; }
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 link_library_process_user_submission($my_link_library_plugin) { check_admin_referer('LL_ADDLINK_FORM'); require_once ABSPATH . '/wp-admin/includes/taxonomy.php'; load_plugin_textdomain('link-library', false, dirname(plugin_basename(__FILE__)) . '/languages'); global $wpdb; $settings = isset($_POST['settingsid']) ? $_POST['settingsid'] : 1; $settingsname = 'LinkLibraryPP' . $settings; $options = get_option($settingsname); $options = wp_parse_args($options, ll_reset_options(1, 'list', 'return')); $genoptions = get_option('LinkLibraryGeneral'); $genoptions = wp_parse_args($genoptions, ll_reset_gen_settings('return')); $valid = true; $requiredcheck = true; $message = ""; $captureddata = array(); $captureddata['link_category'] = isset($_POST['link_category']) ? $_POST['link_category'] : ''; $captureddata['link_user_category'] = isset($_POST['link_user_category']) ? $_POST['link_user_category'] : ''; $captureddata['link_description'] = isset($_POST['link_description']) ? $_POST['link_description'] : ''; $captureddata['link_textfield'] = isset($_POST['link_textfield']) ? $_POST['link_textfield'] : ''; $captureddata['link_name'] = isset($_POST['link_name']) ? $_POST['link_name'] : ''; $captureddata['link_url'] = isset($_POST['link_url']) ? $_POST['link_url'] : ''; $captureddata['link_rss'] = isset($_POST['link_rss']) ? $_POST['link_rss'] : ''; $captureddata['link_notes'] = isset($_POST['link_notes']) ? $_POST['link_notes'] : ''; $captureddata['ll_secondwebaddr'] = isset($_POST['ll_secondwebaddr']) ? $_POST['ll_secondwebaddr'] : ''; $captureddata['ll_telephone'] = isset($_POST['ll_telephone']) ? $_POST['ll_telephone'] : ''; $captureddata['ll_email'] = isset($_POST['ll_email']) ? $_POST['ll_email'] : ''; $captureddata['ll_reciprocal'] = isset($_POST['ll_reciprocal']) ? $_POST['ll_reciprocal'] : ''; $captureddata['ll_submittername'] = isset($_POST['ll_submittername']) ? $_POST['ll_submittername'] : ''; $captureddata['ll_submitteremail'] = isset($_POST['ll_submitteremail']) ? $_POST['ll_submitteremail'] : ''; $captureddata['ll_submittercomment'] = isset($_POST['ll_submittercomment']) ? $_POST['ll_submittercomment'] : ''; $captureddata['ll_customcaptchaanswer'] = isset($_POST['ll_customcaptchaanswer']) ? $_POST['ll_customcaptchaanswer'] : ''; if ('required' == $options['showaddlinkrss'] && empty($captureddata['link_rss'])) { $requiredcheck = false; $message = 11; } else { if ('required' == $options['showaddlinkdesc'] && empty($captureddata['link_description'])) { $requiredcheck = false; $message = 12; } else { if ('required' == $options['showaddlinknotes'] && empty($captureddata['link_notes'])) { $requiredcheck = false; $message = 13; } else { if ('required' == $options['showaddlinkreciprocal'] && empty($captureddata['ll_reciprocal'])) { $requiredcheck = false; $message = 14; } else { if ('required' == $options['showaddlinksecondurl'] && empty($captureddata['ll_secondwebaddr'])) { $requiredcheck = false; $message = 15; } else { if ('required' == $options['showaddlinktelephone'] && empty($captureddata['ll_telephone'])) { $requiredcheck = false; $message = 16; } else { if ('required' == $options['showaddlinkemail'] && empty($captureddata['ll_email'])) { $requiredcheck = false; $message = 17; } else { if ('required' == $options['showlinksubmittername'] && empty($captureddata['ll_submittername'])) { $requiredcheck = false; $message = 18; } else { if ('required' == $options['showaddlinksubmitteremail'] && empty($captureddata['ll_submitteremail'])) { $requiredcheck = false; $message = 19; } else { if ('required' == $options['showlinksubmittercomment'] && empty($captureddata['ll_submittercomment'])) { $requiredcheck = false; $message = 20; } else { if ('required' == $options['showuserlargedescription'] && empty($captureddata['link_textfield'])) { $requiredcheck = false; $message = 21; } } } } } } } } } } } if ($captureddata['link_name'] != '' && $requiredcheck) { if (($options['addlinkakismet'] || $genoptions['addlinkakismet']) && ll_akismet_is_available()) { $c = array(); $c['comment_author'] = $captureddata['ll_submittername']; $c['comment_author_email'] = $captureddata['ll_submitteremail']; $c['comment_author_url'] = $captureddata['link_url']; if ('required' == $options['showaddlinkdesc'] || 'show' == $options['showaddlinkdesc']) { $c['comment_content'] = $captureddata['link_description']; } elseif ('required' == $options['showaddlinknotes'] || 'show' == $options['showaddlinknotes']) { $c['comment_content'] = $captureddata['link_notes']; } elseif ('required' == $options['showuserlargedescription'] || 'show' == $options['showuserlargedescription']) { $c['comment_content'] = $captureddata['link_textfield']; } $c['blog'] = get_option('home'); $c['blog_lang'] = get_locale(); $c['blog_charset'] = get_option('blog_charset'); $c['user_ip'] = $_SERVER['REMOTE_ADDR']; $c['user_agent'] = $_SERVER['HTTP_USER_AGENT']; $c['referrer'] = $_SERVER['HTTP_REFERER']; $c['comment_type'] = 'link-library'; $ignore = array('HTTP_COOKIE', 'HTTP_COOKIE2', 'PHP_AUTH_PW'); foreach ($_SERVER as $key => $value) { if (!in_array($key, (array) $ignore)) { $c["{$key}"] = $value; } } if (ll_akismet_comment_check($c)) { $valid = false; $message = 22; } else { $valid = true; } } elseif (($options['addlinkakismet'] || $genoptions['addlinkakismet']) && !ll_akismet_is_available()) { echo 'Akismet has been selected but is not available'; die; } if ($options['showcaptcha'] && $valid) { $message = apply_filters('link_library_verify_captcha', ''); if ($message > 0) { $valid = false; } else { $valid = true; } } if ($options['showcustomcaptcha'] == 'show' && $valid) { if ($captureddata['ll_customcaptchaanswer'] == '') { $valid = false; $message = 5; } else { if (strtolower($captureddata['ll_customcaptchaanswer']) == strtolower($options['customcaptchaanswer'])) { $valid = true; } else { $valid = false; $message = 6; } } } if ($valid || $options['showcaptcha'] == false && $options['showcustomcaptcha'] == 'hide' && $options['addlinkakismet'] == false) { $existinglinkquery = "SELECT * from " . $my_link_library_plugin->db_prefix() . "links l where l.link_name = '" . $captureddata['link_name'] . "' "; if ($options['addlinknoaddress'] == false || $options['addlinknoaddress'] == true && $captureddata['link_url'] != "") { $existinglinkquery .= " or l.link_url = 'http://" . $captureddata['link_url'] . "'"; } $existinglink = $wpdb->get_var($existinglinkquery); if ($existinglink == "" && ($options['addlinknoaddress'] == false && $captureddata['link_url'] != "" || $options['addlinknoaddress'] == true)) { if ($captureddata['link_category'] == 'new' && $captureddata['link_user_category'] != '') { $existingcatquery = "SELECT t.term_id FROM " . $my_link_library_plugin->db_prefix() . "terms t, " . $my_link_library_plugin->db_prefix() . "term_taxonomy tt "; $existingcatquery .= "WHERE t.name = '" . $captureddata['link_user_category'] . "' AND t.term_id = tt.term_id AND tt.taxonomy = 'link_category'"; $existingcat = $wpdb->get_var($existingcatquery); if (!$existingcat) { $newlinkcatdata = array("cat_name" => $captureddata['link_user_category'], "category_description" => "", "category_nicename" => sanitize_text_field($captureddata['link_user_category'])); $newlinkcat = wp_insert_category($newlinkcatdata); $newcatarray = array("term_id" => $newlinkcat); $newcattype = array("taxonomy" => 'link_category'); $wpdb->update($my_link_library_plugin->db_prefix() . 'term_taxonomy', $newcattype, $newcatarray); $newlinkcat = array($newlinkcat); } else { $newlinkcat = array($existingcat); } $message = 8; $validcat = true; } elseif ($captureddata['link_category'] == 'new' && $captureddata['link_user_category'] == '') { $message = 7; $validcat = false; } else { $newlinkcat = array($captureddata['link_category']); $message = 8; $validcat = true; } if ($validcat == true) { if ($options['showuserlinks'] == false) { if ($options['showifreciprocalvalid']) { $reciprocal_return = $my_link_library_plugin->CheckReciprocalLink($genoptions['recipcheckaddress'], $captureddata['ll_reciprocal']); if ($reciprocal_return == 'exists_found') { $newlinkdesc = $captureddata['link_description']; $newlinkvisibility = 'Y'; unset($message); } else { $newlinkdesc = '(LinkLibrary:AwaitingModeration:RemoveTextToApprove)' . $captureddata['link_description']; $newlinkvisibility = 'N'; } } else { $newlinkdesc = '(LinkLibrary:AwaitingModeration:RemoveTextToApprove)' . $captureddata['link_description']; $newlinkvisibility = 'N'; } } else { $newlinkdesc = $captureddata['link_description']; $newlinkvisibility = 'Y'; unset($message); } $username = ''; if ($options['storelinksubmitter'] == true) { global $current_user; get_currentuserinfo(); if ($current_user) { $username = $current_user->user_login; } } $newlink = array("link_name" => esc_html(stripslashes($captureddata['link_name'])), "link_url" => esc_html(stripslashes($captureddata['link_url'])), "link_rss" => esc_html(stripslashes($captureddata['link_rss'])), "link_description" => esc_html(stripslashes($newlinkdesc)), "link_notes" => esc_html(stripslashes($captureddata['link_notes'])), "link_category" => $newlinkcat, "link_visible" => $newlinkvisibility, 'link_target' => $options['linktarget'], 'link_updated' => date("Y-m-d H:i", current_time('timestamp'))); $newlinkid = $my_link_library_plugin->link_library_insert_link($newlink, false, $options['addlinknoaddress']); $extradatatable = $my_link_library_plugin->db_prefix() . "links_extrainfo"; $wpdb->insert($extradatatable, array('link_id' => $newlinkid, 'link_second_url' => $captureddata['ll_secondwebaddr'], 'link_telephone' => $captureddata['ll_telephone'], 'link_email' => $captureddata['ll_email'], 'link_reciprocal' => $captureddata['ll_reciprocal'], 'link_submitter' => isset($username) ? $username : null, 'link_submitter_name' => $captureddata['ll_submittername'], 'link_submitter_email' => $captureddata['ll_submitteremail'], 'link_textfield' => $captureddata['link_textfield'], 'link_no_follow' => '', 'link_featured' => '', 'link_manual_updated' => '')); if ($options['emailnewlink']) { if ($genoptions['moderatoremail'] != '') { $adminmail = $genoptions['moderatoremail']; } else { $adminmail = get_option('admin_email'); } $link_category_name = ''; if ($captureddata['link_category'] == 'new' && $captureddata['link_user_category'] != '') { $link_category_name = $captureddata['link_user_category']; } else { if (!empty($captureddata['link_category'])) { $find_cat_name_query = "SELECT t.name FROM " . $my_link_library_plugin->db_prefix() . "terms t, " . $my_link_library_plugin->db_prefix() . "term_taxonomy tt "; $find_cat_name_query .= "WHERE t.term_id = '" . $captureddata['link_category'] . "' AND t.term_id = tt.term_id AND tt.taxonomy = 'link_category'"; $link_category_name = $wpdb->get_var($find_cat_name_query); } } $headers = "MIME-Version: 1.0\r\n"; $headers .= "Content-type: text/html; charset=iso-8859-1\r\n"; $emailmessage = __('A user submitted a new link to your Wordpress Link database.', 'link-library') . "<br /><br />"; $emailmessage .= __('Link Name', 'link-library') . ": " . esc_html(stripslashes($captureddata['link_name'])) . "<br />"; $emailmessage .= __('Link Address', 'link-library') . ": <a href='" . esc_html(stripslashes($captureddata['link_url'])) . "'>" . esc_html(stripslashes($captureddata['link_url'])) . "</a><br />"; if ('show' == $options['showaddlinkrss'] || 'required' == $options['showaddlinkrss']) { $emailmessage .= __('Link RSS', 'link-library') . ": " . esc_html(stripslashes($captureddata['link_rss'])) . "<br />"; } if ('show' == $options['showaddlinkdesc'] || 'required' == $options['showaddlinkdesc']) { $emailmessage .= __('Link Description', 'link-library') . ": " . esc_html(stripslashes($captureddata['link_description'])) . "<br />"; } if ('show' == $options['showuserlargedescription'] || 'required' == $options['showuserlargedescription']) { $emailmessage .= __('Link Large Description', 'link-library') . ": " . esc_html(stripslashes($captureddata['link_textfield'])) . "<br />"; } if ('show' == $options['showaddlinknotes'] || 'required' == $options['showaddlinknotes']) { $emailmessage .= __('Link Notes', 'link-library') . ": " . esc_html(stripslashes($captureddata['link_notes'])) . "<br />"; } $emailmessage .= __('Link Category', 'link-library') . ": " . $link_category_name . " ( " . $captureddata['link_category'] . " )<br /><br />"; if ('show' == $options['showaddlinkreciprocal'] || 'required' == $options['showaddlinkreciprocal']) { $emailmessage .= __('Reciprocal Link', 'link-library') . ": " . $captureddata['ll_reciprocal'] . "<br /><br />"; } if ('show' == $options['showaddlinksecondurl'] || 'required' == $options['showaddlinksecondurl']) { $emailmessage .= __('Link Secondary Address', 'link-library') . ": " . $captureddata['ll_secondwebaddr'] . "<br /><br />"; } if ('show' == $options['showaddlinktelephone'] || 'required' == $options['showaddlinktelephone']) { $emailmessage .= __('Link Telephone', 'link-library') . ": " . $captureddata['ll_telephone'] . "<br /><br />"; } if ('show' == $options['showaddlinkemail'] || 'required' == $options['showaddlinkemail']) { $emailmessage .= __('Link E-mail', 'link-library') . ": " . $captureddata['ll_email'] . "<br /><br />"; } if ('show' == $options['showlinksubmittername'] || 'required' == $options['showlinksubmittername']) { $emailmessage .= __('Link Submitter Name', 'link-library') . ": " . $captureddata['ll_submittername'] . "<br /><br />"; } if ('show' == $options['showaddlinksubmitteremail'] || 'required' == $options['showaddlinksubmitteremail']) { $emailmessage .= __('Link Submitter E-mail', 'link-library') . ": " . $captureddata['ll_submitteremail'] . "<br /><br />"; } if ('show' == $options['showlinksubmittercomment'] || 'required' == $options['showlinksubmittercomment']) { $emailmessage .= __('Link Comment', 'link-library') . ": " . $captureddata['ll_submittercomment'] . "<br /><br />"; } if ($options['showuserlinks'] == false) { $emailmessage .= '<a href="' . esc_url(add_query_arg('s', 'LinkLibrary%3AAwaitingModeration%3ARemoveTextToApprove', admin_url('link-manager.php'))) . '">Moderate new links</a>'; } elseif ($options['showuserlinks'] == true) { $emailmessage .= '<a href="' . admin_url('link-manager.php') . '">View links</a>'; } $emailmessage .= "<br /><br />" . __('Message generated by', 'link-library') . " <a href='http://ylefebvre.ca/wordpress-plugins/link-library/'>Link Library</a> for Wordpress"; if (!isset($emailtitle) || $emailtitle == '') { $emailtitle = stripslashes($genoptions['moderationnotificationtitle']); $emailtitle = str_replace('%linkname%', esc_html(stripslashes($captureddata['link_name'])), $emailtitle); } else { $emailtitle = htmlspecialchars_decode(get_option('blogname'), ENT_QUOTES) . " - " . __('New link added', 'link-library') . ": " . htmlspecialchars($captureddata['link_name']); } wp_mail($adminmail, $emailtitle, $emailmessage, $headers); } if ($options['emailsubmitter'] && !empty($captureddata['ll_submitteremail']) && is_email($captureddata['ll_submitteremail'])) { $submitteremailheaders = "MIME-Version: 1.0\r\n"; $submitteremailheaders .= "Content-type: text/html; charset=iso-8859-1\r\n"; $submitteremailtitle = __('Link Submission Confirmation', 'link-library'); $submitteremailmessage = '<p>' . __('Thank you for your link submission on ', 'link-library'); $submitteremailmessage .= esc_html(get_bloginfo('name')) . '</p>'; if ($options['showuserlinks'] == false) { $submitteremailmessage .= '<p>' . __('Your link will appear once approved by the site administrator.', 'link-library') . '</p>'; } elseif ($options['showuserlinks'] == true) { $submitteremailmessage .= '<p>' . __('Your link will immediately be added to the site.', 'link-library') . '</p>'; } $submitteremailmessage .= __('Link Name', 'link-library') . ": " . esc_html(stripslashes($captureddata['link_name'])) . "<br />"; $submitteremailmessage .= __('Link Address', 'link-library') . ": <a href='" . esc_html(stripslashes($captureddata['link_url'])) . "'>" . esc_html(stripslashes($captureddata['link_url'])) . "</a><br />"; if ('show' == $options['showaddlinkrss'] || 'required' == $options['showaddlinkrss']) { $submitteremailmessage .= __('Link RSS', 'link-library') . ": " . esc_html(stripslashes($captureddata['link_rss'])) . "<br />"; } if ('show' == $options['showaddlinkdesc'] || 'required' == $options['showaddlinkdesc']) { $submitteremailmessage .= __('Link Description', 'link-library') . ": " . esc_html(stripslashes($captureddata['link_description'])) . "<br />"; } if ('show' == $options['showuserlargedescription'] || 'required' == $options['showuserlargedescription']) { $submitteremailmessage .= __('Link Large Description', 'link-library') . ": " . esc_html(stripslashes($captureddata['link_textfield'])) . "<br />"; } if ('show' == $options['showaddlinknotes'] || 'required' == $options['showaddlinknotes']) { $submitteremailmessage .= __('Link Notes', 'link-library') . ": " . esc_html(stripslashes($captureddata['link_notes'])) . "<br />"; } $submitteremailmessage .= __('Link Category', 'link-library') . ": " . $link_category_name . " ( " . $captureddata['link_category'] . " )<br /><br />"; if ('show' == $options['showaddlinkreciprocal'] || 'required' == $options['showaddlinkreciprocal']) { $submitteremailmessage .= __('Reciprocal Link', 'link-library') . ": " . $captureddata['ll_reciprocal'] . "<br /><br />"; } if ('show' == $options['showaddlinksecondurl'] || 'required' == $options['showaddlinksecondurl']) { $submitteremailmessage .= __('Link Secondary Address', 'link-library') . ": " . $captureddata['ll_secondwebaddr'] . "<br /><br />"; } if ('show' == $options['showaddlinktelephone'] || 'required' == $options['showaddlinktelephone']) { $submitteremailmessage .= __('Link Telephone', 'link-library') . ": " . $captureddata['ll_telephone'] . "<br /><br />"; } if ('show' == $options['showaddlinkemail'] || 'required' == $options['showaddlinkemail']) { $submitteremailmessage .= __('Link E-mail', 'link-library') . ": " . $captureddata['ll_email'] . "<br /><br />"; } if ('show' == $options['showaddlinksubmittername'] || 'required' == $options['showaddlinksubmittername']) { $submitteremailmessage .= __('Link Submitter Name', 'link-library') . ": " . $captureddata['ll_submittername'] . "<br /><br />"; } if ('show' == $options['showaddlinksubmitteremail'] || 'required' == $options['showaddlinksubmitteremail']) { $submitteremailmessage .= __('Link Submitter E-mail', 'link-library') . ": " . $captureddata['ll_submitteremail'] . "<br /><br />"; } if ('show' == $options['showlinksubmittercomment'] || 'required' == $options['showlinksubmittercomment']) { $submitteremailmessage .= __('Link Comment', 'link-library') . ": " . $captureddata['ll_submittercomment'] . "<br /><br />"; } wp_mail($captureddata['ll_submitteremail'], $submitteremailtitle, $submitteremailmessage, $submitteremailheaders); } } } elseif ($existinglink == "" && ($options['addlinknoaddress'] == false && $captureddata['link_url'] == "")) { $message = 9; } else { $message = 10; } } } $redirectaddress = ''; if (isset($_POST['thankyouurl']) && $_POST['thankyouurl'] != '' && $requiredcheck && $valid) { $redirectaddress = $_POST['thankyouurl']; } else { if (isset($_POST['pageid']) && is_numeric($_POST['pageid'])) { $redirectaddress = get_permalink($_POST['pageid']); } } $redirectaddress = esc_url_raw(add_query_arg('addlinkmessage', $message, $redirectaddress)); if ($valid == false && ($options['showcaptcha'] == true || $options['showcustomcaptcha'] == 'show')) { if (isset($_POST['link_name']) && $_POST['link_name'] != '') { $redirectaddress = add_query_arg('addlinkname', rawurlencode($captureddata['link_name']), $redirectaddress); } if (isset($_POST['link_url']) && $_POST['link_url'] != '') { $redirectaddress = add_query_arg('addlinkurl', rawurlencode($captureddata['link_url']), $redirectaddress); } if (isset($_POST['link_category']) && $_POST['link_category'] != '') { $redirectaddress = add_query_arg('addlinkcat', rawurlencode($captureddata['link_category']), $redirectaddress); } if (isset($_POST['link_user_category']) && $_POST['link_user_category'] != '') { $redirectaddress = add_query_arg('addlinkusercat', rawurlencode($captureddata['link_user_category']), $redirectaddress); } if (isset($_POST['link_description']) && $_POST['link_description'] != '') { $redirectaddress = add_query_arg('addlinkdesc', rawurlencode($captureddata['link_description']), $redirectaddress); } if (isset($_POST['link_textfield']) && $_POST['link_textfield'] != '') { $redirectaddress = add_query_arg('addlinktextfield', rawurlencode($captureddata['link_textfield']), $redirectaddress); } if (isset($_POST['link_rss']) && $_POST['link_rss'] != '') { $redirectaddress = add_query_arg('addlinkrss', rawurlencode($captureddata['link_rss']), $redirectaddress); } if (isset($_POST['link_notes']) && $_POST['link_notes'] != '') { $redirectaddress = add_query_arg('addlinknotes', rawurlencode($captureddata['link_notes']), $redirectaddress); } if (isset($_POST['ll_secondwebaddr']) && $_POST['ll_secondwebaddr'] != '') { $redirectaddress = add_query_arg('addlinksecondurl', rawurlencode($captureddata['ll_secondwebaddr']), $redirectaddress); } if (isset($_POST['ll_telephone']) && $_POST['ll_telephone'] != '') { $redirectaddress = add_query_arg('addlinktelephone', rawurlencode($captureddata['ll_telephone']), $redirectaddress); } if (isset($_POST['ll_email']) && $_POST['ll_email'] != '') { $redirectaddress = add_query_arg('addlinkemail', rawurlencode($captureddata['ll_email']), $redirectaddress); } if (isset($_POST['ll_reciprocal']) && $_POST['ll_reciprocal'] != '') { $redirectaddress = add_query_arg('addlinkreciprocal', rawurlencode($captureddata['ll_reciprocal']), $redirectaddress); } if (isset($_POST['ll_submittername']) && $_POST['ll_submittername'] != '') { $redirectaddress = add_query_arg('addlinksubmitname', rawurlencode($captureddata['ll_submittername']), $redirectaddress); } if (isset($_POST['ll_submitteremail']) && $_POST['ll_submitteremail'] != '') { $redirectaddress = add_query_arg('addlinksubmitemail', rawurlencode($captureddata['ll_submitteremail']), $redirectaddress); } if (isset($_POST['ll_submittercomment']) && $_POST['ll_submittercomment'] != '') { $redirectaddress = add_query_arg('addlinksubmitcomment', rawurlencode($captureddata['ll_submittercomment']), $redirectaddress); } if (isset($_POST['ll_customcaptchaanswer']) && $_POST['ll_customcaptchaanswer'] != '') { $redirectaddress = add_query_arg('addlinkcustomcaptcha', rawurlencode($captureddata['ll_customcaptchaanswer']), $redirectaddress); } $redirectaddress = esc_url_raw($redirectaddress); } wp_redirect($redirectaddress); exit; }
function cat2wp($categories = '') { // General Housekeeping global $wpdb; $count = 0; $s9ycat2wpcat = 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 $title = $wpdb->escape($category_name); $slug = $categoryid . '-' . sanitize_title($title); $name = $wpdb->escape($title); $parent = $s9ycat2wpcat[$parentid]; $args = array('category_nicename' => $slug, 'cat_name' => $name); if (!empty($parentid)) { $args['category_parent'] = $parent; } $ret_id = wp_insert_category($args); $s9ycat2wpcat[$categoryid] = $ret_id; } // Store category translation for future use add_option('s9ycat2wpcat', $s9ycat2wpcat); echo '<p>' . sprintf(__('Done! <strong>%1$s</strong> categories imported.'), $count) . '<br /><br /></p>'; return true; } echo __('No Categories to Import!'); return false; }
if (empty($_GET["{$wpvar}"])) { ${$wpvar} = ''; } else { ${$wpvar} = $_GET["{$wpvar}"]; } } else { ${$wpvar} = $_POST["{$wpvar}"]; } } } switch ($action) { case 'addcat': if (!current_user_can('manage_categories')) { die(__('Cheatin’ uh?')); } wp_insert_category($_POST); header('Location: categories.php?message=1#addcat'); break; case 'delete': check_admin_referer(); if (!current_user_can('manage_categories')) { die(__('Cheatin’ uh?')); } $cat_ID = (int) $_GET['cat_ID']; $cat_name = get_catname($cat_ID); if (1 == $cat_ID) { die(sprintf(__("Can't delete the <strong>%s</strong> category: this is the default one"), $cat_name)); } wp_delete_category($cat_ID); header('Location: categories.php?message=2'); break;
/** * @dataProvider providerTestCreatePosts */ function testCreatePosts($posts, $expected_post_ids, $expected_additional_info = false) { global $wp_test_expectations; update_option('default_category', 1); wp_insert_category(array('slug' => 'test')); $this->assertEquals($expected_post_ids, $this->pf->create_posts($posts, array('test' => 1, 'test2' => 2, 'test2/test3' => 3))); if (is_array($expected_additional_info)) { extract($expected_additional_info); if (isset($categories)) { if (is_array($categories)) { foreach ($categories as $post_id => $cats) { $this->assertEquals($cats, wp_get_post_categories($post_id)); } } } if (isset($metadata)) { if (is_array($metadata)) { foreach ($metadata as $post_id => $metadata_info) { foreach ($metadata_info as $key => $value) { $this->assertEquals($value, get_post_meta($post_id, $key, true)); } } } } if (isset($tags)) { if (is_array($tags)) { foreach ($tags as $post_id => $expected_tags) { $post_tags = wp_get_post_tags($post_id); foreach ($post_tags as &$tag) { $tag = $tag->slug; } $this->assertEquals($post_tags, $expected_tags); } } } } }
/** * 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); }
/** * Cleans everything for the given id, then redoes everything * * @param integer $id The id to edit */ function adminProcessEdit($id) { global $wpdb; // If we need to execute a tool action we stop here if ($this->adminProcessTools()) { return; } // Delete all to recreate $wpdb->query("DELETE FROM {$this->db['campaign_word']} WHERE campaign_id = {$id}"); $wpdb->query("DELETE FROM {$this->db['campaign_category']} WHERE campaign_id = {$id}"); // Process categories # New if (isset($this->campaign_data['categories']['new'])) { foreach ($this->campaign_data['categories']['new'] as $category) { $this->campaign_data['categories'][] = wp_insert_category(array('cat_name' => $category)); } unset($this->campaign_data['categories']['new']); } # All foreach ($this->campaign_data['categories'] as $category) { // Insert $wpdb->query(WPOTools::insertQuery($this->db['campaign_category'], array('category_id' => $category, 'campaign_id' => $id))); } // Process feeds # New if (isset($this->campaign_data['feeds']['new'])) { foreach ($this->campaign_data['feeds']['new'] as $feed) { $this->addCampaignFeed($id, $feed); } } if (isset($this->campaign_data['feeds']['move'])) { # For each of these we need to set the feed to the new campaign id foreach ($this->campaign_data['feeds']['move'] as $fid => $cid) { $wpdb->update($this->db['campaign_feed'], array('campaign_id' => $cid), array('id' => $fid), array('%d'), array('%d')); } } //echo "Queries:<pre>"; //print_r( $wpdb->queries ); //echo "</pre>"; # Delete if (isset($this->campaign_data['feeds']['delete'])) { foreach ($this->campaign_data['feeds']['delete'] as $feed) { $wpdb->query("DELETE FROM {$this->db['campaign_feed']} WHERE id = {$feed} "); } } // Process words foreach ($this->campaign_data['rewrites'] as $rewrite) { $wpdb->query(WPOTools::insertQuery($this->db['campaign_word'], array('word' => $rewrite['origin']['search'], 'regex' => $rewrite['origin']['regex'], 'rewrite' => isset($rewrite['rewrite']), 'rewrite_to' => isset($rewrite['rewrite']) ? $rewrite['rewrite'] : '', 'relink' => isset($rewrite['relink']) ? $rewrite['relink'] : null, 'campaign_id' => $id))); } // Main $main = $this->campaign_data['main']; // Fetch author id $author = get_userdatabylogin($this->campaign_data['main']['author']); $main['authorid'] = $author->ID; unset($main['author']); // Query $query = WPOTools::updateQuery($this->db['campaign'], $main, 'id = ' . intval($id)); $wpdb->query($query); }
/** * Test a category_name query * * @since 1.5 */ public function testCategoryNameQuery() { $cat_one = wp_insert_category(array('cat_name' => 'one')); $cat_two = wp_insert_category(array('cat_name' => 'two')); $cat_three = wp_insert_category(array('cat_name' => 'three')); ep_create_and_sync_post(array('post_content' => 'findme test 1', 'post_category' => array($cat_one, $cat_two))); ep_create_and_sync_post(array('post_content' => 'findme test 2')); ep_create_and_sync_post(array('post_content' => 'findme test 3', 'post_category' => array($cat_one, $cat_three))); ep_refresh_index(); $args = array('s' => 'findme', 'category_name' => 'one'); $query = new WP_Query($args); $this->assertEquals(2, $query->post_count); $this->assertEquals(2, $query->found_posts); }
/** * 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); }