function elaplugin_activate() { $terms_to_add = array("European Language Portfolio"); //create those categories if they don't already exist foreach ($terms_to_add as $trm) { if (term_exists($trm) == 0) { wp_create_category($trm); } } }
public function create_category() { require_once ABSPATH . 'wp-admin/includes/taxonomy.php'; if (isset($_POST['addcat'])) { $newcat = $_POST['newcat']; if (wp_create_category($newcat)) { $this->alert = 'New Category Created'; } } }
function property_detail_content($content) { if (get_post_meta(get_the_ID(), 'property_id', true) != '' && get_post_meta(get_the_ID(), 'bapi_last_update', true) < time() - 3600 * 60 * 24) { remove_filter('save_post', 'update_post_bapi'); wp_update_post(mod_post_builder($propid, get_the_ID())); update_post_meta(get_the_ID(), 'bapi_last_update', time()); wp_set_post_terms(get_the_ID(), wp_create_category(get_option('property_category_name')), 'category'); add_filter('save_post', 'update_post_bapi'); } bapi_search_page_body($content); return $content; }
private function create_categories($post) { $course_category = get_post_meta($post->ID, "course_category_id", true); if ($course_category == "") { $course_category = wp_create_category($post->post_title); add_post_meta($post->ID, "course_category_id", $course_category, true); } $discussion_category = get_post_meta($post->ID, "course_discussion", true); if ($discussion_category == "") { $discussion_category = wp_create_category(__("discussions"), $course_category); add_post_meta($post->ID, "course_discussion", $discussion_category, true); } return array($course_category, $discussion_category); }
/** * 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 create_my_cat() { if (file_exists(ABSPATH . '/wp-admin/includes/taxonomy.php')) { require_once ABSPATH . '/wp-admin/includes/taxonomy.php'; $loop = new WP_Query(array('post_type' => 'project', 'posts_per_page' => -1)); while ($loop->have_posts()) { $loop->the_post(); global $post; $post_slug = $post->post_name; if (!get_cat_ID($post_slug)) { wp_create_category($post_slug); } } wp_reset_query(); } }
private function create_categories($post) { $categories = array(); $course_category = get_post_meta($post->ID, "course_category_id", true); if ($course_category == "") { $course_category = wp_create_category($post->post_title); add_post_meta($post->ID, "course_category_id", $course_category, true); } array_push($categories, $course_category); $assignment_category = get_post_meta($post->ID, "course_module_assignments", true); if ($module_category == "") { $assignment_category = wp_create_category("Assignments", $course_category); add_post_meta($post->ID, "course_module_assignments", $assignment_category, true); } array_push($categories, $assignment_category); return $categories; }
private function create_categories($post) { $categories = array(); $course_category = get_post_meta($post->ID, "course_category_id", true); if ($course_category == "") { $course_category = wp_create_category($post->post_title); add_post_meta($post->ID, "course_category_id", $course_category, true); } array_push($categories, $course_category); $student_category = get_post_meta($post->ID, "course_students", true); if ($quiz_category == "") { $student_category = wp_create_category("Students", $course_category); add_post_meta($post->ID, "course_students", $student_category, true); } array_push($categories, $student_category); return $categories; }
/** * Create the new Genealogy Update category. * Schedule an update of the TNG RSS feed. * * @author Nate Jacobs * @date 9/11/14 * @since 1.0 */ public function activation() { wp_create_category($this->tng_rss_category); /** * Filter the scheduled recurrence event time. * * @author Nate Jacobs * @date 11/1/14 * @since 1.6 * * @param string The cron interval. */ $schedule = apply_filters('tng_wp_rss_post_schedule', 'daily'); if (!wp_next_scheduled('tng_wp_rss_update')) { wp_schedule_event(time(), $schedule, 'tng_wp_rss_update'); } }
private function create_categories($post) { $categories = array(); $course_category = get_post_meta($post->ID, "course_category_id", true); if ($course_category == "") { $course_category = wp_create_category($post->post_title); add_post_meta($post->ID, "course_category_id", $course_category, true); } array_push($categories, $course_category); if (isset($_POST['module'])) { $module_category = get_post_meta($post->ID, "course_module_" . $_POST['module'], true); if ($module_category == "") { $module_category = wp_create_category(stripslashes($_POST['module_name']), $course_category); add_post_meta($post->ID, "course_module_" . $_POST['module'], $module_category, true); } array_push($categories, $module_category); } return $categories; }
function make_category($slug, $parent = null) { //既存カテゴリをすべて取得 $categories = get_categories($args); //print_r($categories); $flag = 0; foreach ($categories as $cat) { if ($slug == $cat->name) { $flag = 1; $cat_id = $cat->cat_ID; break; } } if ($flag != 1) { //重複無ければ return wp_create_category($slug, $parent); } else { return $cat_id; } }
function wpse_set_defaults($blog_id) { global $json_api; switch_to_blog($blog_id); $id = 'json_api_controllers'; $required_controllers = explode(",", "categories,posts,user,projects,attachments"); $available_controllers = $json_api->get_controllers(); $active_controllers = explode(',', get_option($id, 'core')); $action = "activate"; foreach ($required_controllers as $controller) { if (in_array($controller, $available_controllers)) { if ($action == 'activate' && !in_array($controller, $active_controllers)) { $active_controllers[] = $controller; } else { if ($action == 'deactivate') { $index = array_search($controller, $active_controllers); if ($index !== false) { unset($active_controllers[$index]); } } } } } $value = implode(',', $active_controllers); $option_exists = get_option($id, null) !== null; if ($option_exists) { update_option($id, $value); } else { add_option($id, $value); } // Remove the default post & page wp_delete_post(1, true); wp_delete_post(2, true); // Remove the first comment wp_delete_comment(1, true); // add default categories wp_create_category("Project"); wp_create_category("Document"); restore_current_blog(); }
$mycats = explode(",", $a[0]["mycats"]); echo "{$appear_pk} <br>"; $tags = ""; if ($a[0]["show_nm2"]) { $tags .= "," . $a[0]["show_nm2"]; } if ($a[0]["show_nm3"]) { $tags .= "," . $a[0]["show_nm3"]; } /* // add show to categories if not a category yet $showcat = wp_create_category($shownm, 161); if ($showcat) $mycats[] = $showcat; */ // add PERSON to categories if not a category yet $personcat = wp_create_category($peoplenm, $peoplecat); if ($personcat) { $mycats[] = $personcat; } $title = $peoplenm . " on " . $shownm . " on " . $dt2; // 'ID' => $postfk, // Create post object $my_post = array('post_type' => "appearance", 'post_title' => $title, 'post_content' => "", 'post_status' => 'publish', 'post_author' => 1, 'post_category' => $mycats, 'tags_input' => $shownm . "," . $peoplenm . $tags, 'post_date' => $dt); print_r($my_post); $postid = wp_insert_post($my_post); update_post_meta($postid, '_wp_page_template', 'single-appear.php'); $q = "UPDATE appearances SET appear_post = {$postid} WHERE appear_pk = {$appear_pk}"; $conn->query($q); echo $q; echo "<hr>"; // break;
die('-1'); } $names = explode(',', $_POST['newcat']); if (0 > ($parent = (int) $_POST['newcat_parent'])) { $parent = 0; } $post_category = isset($_POST['post_category']) ? (array) $_POST['post_category'] : array(); $checked_categories = array_map('absint', (array) $post_category); $popular_ids = wp_popular_terms_checklist('category', 0, 10, false); foreach ($names as $cat_name) { $cat_name = trim($cat_name); $category_nicename = sanitize_title($cat_name); if ('' === $category_nicename) { continue; } $cat_id = wp_create_category($cat_name, $parent); $checked_categories[] = $cat_id; if ($parent) { // Do these all at once in a second continue; } $category = get_category($cat_id); ob_start(); wp_category_checklist(0, $cat_id, $checked_categories, $popular_ids); $data = ob_get_contents(); ob_end_clean(); $add = array('what' => 'category', 'id' => $cat_id, 'data' => str_replace(array("\n", "\t"), '', $data), 'position' => -1); } if ($parent) { // Foncy - replace the parent and all its children $parent = get_category($parent);
function test_terms_search() { $this->make_user_by_role('editor'); $name = rand_str(30); $name_id = wp_create_category($name); // search by full name $filter = array('search' => $name); $results = $this->myxmlrpcserver->wp_getTerms(array(1, 'editor', 'editor', 'category', $filter)); $this->assertNotInstanceOf('IXR_Error', $results); $this->assertEquals(1, count($results)); $this->assertEquals($name, $results[0]['name']); $this->assertEquals($name_id, $results[0]['term_id']); // search by partial name $filter = array('search' => substr($name, 0, 10)); $results2 = $this->myxmlrpcserver->wp_getTerms(array(1, 'editor', 'editor', 'category', $filter)); $this->assertNotInstanceOf('IXR_Error', $results2); $this->assertEquals(1, count($results2)); $this->assertEquals($name, $results2[0]['name']); $this->assertEquals($name_id, $results2[0]['term_id']); }
function ConvertCategory($start = false) { global $wpdb; if (!$start) { $start = 0; } $end = 200; $count_category = $wpdb->get_var("SELECT COUNT(*) FROM `categories` WHERE status > 0"); $categories = $wpdb->get_results("SELECT * FROM `categories` WHERE `status` > 0 ORDER BY `parent` ASC LIMIT {$start} , {$end}", 'ARRAY_A'); foreach ($categories 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_added_category = $wpdb->get_var("SELECT COUNT(*) FROM `category_to_terms`"); ?> <div class="cc_title"><h2>Category</h2></div> <script> var a1 = <?php echo $count_category; ?> ; var a2 = <?php echo $start; ?> ; jQuery(function(){ if (a2 <= a1) { url = "?page=CC&action=category&start=<?php echo $start + $end; ?> "; jQuery(location).attr("href", url); } else { url = "?page=CC&action=post"; jQuery(location).attr("href", url); } }); </script> <div class="cc_content"> <?php echo '<div>Total categories: ' . ($count_category - 1) . '</div>'; echo '<div><a href="?page=CC&action=category&start=' . ($start + $end) . '">Next categories >>></a></div>'; ?> </div> <?php SelestAction(); }
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(); } }
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'); if ( !$cat = get_category( $cat ) )
function process_feed($feed_id, $ablog) { // Load simple pie if required if (!function_exists('fetch_feed') && file_exists(ABSPATH . WPINC . '/feed.php')) { require_once ABSPATH . WPINC . '/feed.php'; } // Check again to make sure it is loaded if (!function_exists('fetch_feed')) { $this->msgs[] = __('<strong>Error:</strong> Can not locate the feed reading file.', 'autoblogtext'); } if (empty($ablog['url'])) { $this->msgs[] = __('<strong>Error:</strong> There is no URL setup for this feed - ', 'autoblogtext') . $ablog['title']; return false; } if (!empty($ablog['forcessl']) && $ablog['forcessl'] == 'no') { // Add a filter to remove the force sll check add_filter('http_request_args', array(&$this, 'switch_off_verifyssl'), 10, 2); } $feed = fetch_feed($ablog['url']); remove_filter('http_request_args', array(&$this, 'switch_off_verifyssl'), 10, 2); if (!is_wp_error($feed)) { if (isset($ablog['poststoimport']) && (int) $ablog['poststoimport'] != 0) { $max = (int) $ablog['poststoimport']; } else { $max = $feed->get_item_quantity(); if ($max == 0) { // feed error $this->msgs[] = __('<strong>Notice:</strong> I can not find any entries in your feed - ', 'autoblogtext') . $ablog['url']; } } } else { $max = 0; // feed error $this->msgs[] = __('<strong>Error:</strong> ', 'autoblogtext') . $feed->get_error_message(); } if (!empty($ablog['startfrom']) && $ablog['startfrom'] > time()) { // We aren't processing this feed yet // feed error $this->msgs[] = __('<strong>Notice:</strong> We are not within the date period for processing this feed yet - ', 'autoblogtext') . $ablog['url']; } if (!empty($ablog['endon']) && $ablog['endon'] < time()) { // We aren't processing this feed yet // feed error $this->msgs[] = __('<strong>Notice:</strong> We are not within the date period for processing this feed anymore - ', 'autoblogtext') . $ablog['url']; } $processed_count = 0; for ($x = 0; $x < $max; $x++) { $item = $feed->get_item($x); if (!is_object($item)) { // Smomething has gone wrong with this post item so we'll ignore it and try the next one instead continue; } // Switch to the correct blog if (!empty($ablog['blog']) && function_exists('switch_to_blog')) { switch_to_blog((int) $ablog['blog']); $bid = (int) $ablog['blog']; } // We are going to store the permalink for imported posts in a meta field so we don't import duplicates $results = $this->db->get_row($this->db->prepare("SELECT post_id FROM {$this->db->postmeta} WHERE meta_key = %s AND meta_value = %s", 'original_source', $item->get_permalink())); if (count($results) > 0) { // This post already exists so we shall stop here if ($processed_count == 0) { // first item already exists for this feed $this->msgs[] = __('<strong>Notice:</strong> There are no new entries in the feed - ', 'autoblogtext') . $ablog['url']; } else { $this->msgs[] = __('<strong>Notice:</strong> Reached an already imported entry so stopped processing the feed - ', 'autoblogtext') . $ablog['url']; } break; } $post_title = trim($item->get_title()); $post_content = trim($item->get_content()); if (!$this->check_feed_item($ablog, $item)) { continue; } // Still here so lets process some stuff if ($ablog['useexcerpt'] != '1') { // Create an excerpt $post_content = strip_tags($item->get_content()); switch ($ablog['excerptnumberof']) { case 'words': $find = ' '; break; case 'sentences': $find = '.'; break; case 'paragraphs': $find = "\n\n"; break; } $splitcontent = explode($find, $post_content); $post_content = ''; for ($n = 0; $n < (int) $ablog['excerptnumber']; $n++) { if (isset($splitcontent[$n])) { $post_content .= $splitcontent[$n] . $find; } } } // Set up the author if ($ablog['author'] == '0') { // Try the original author $author = $item->get_author(); if ($author) { $author = $author->get_name(); } if (function_exists('get_user_by') && !empty($author)) { $author = get_user_by('login', $author); } else { $author = false; } if (!$author) { $author = $ablog['altauthor']; } } else { // Use a different author $author = $ablog['author']; } // Set up the category if ((int) $ablog['category'] >= 0) { // Grab the first main category $cats = array((int) $ablog['category']); } else { $cats = array(); } $post_category = $cats; // Set up the tags $tags = array(); if (!empty($ablog['tag'])) { $tags = array_map('trim', explode(',', $ablog['tag'])); } switch ($ablog['feedcatsare']) { case 'categories': //$term = get_term_by('name', $cat_name, 'category'); $thecats = array(); $thecats = $item->get_categories(); if (!empty($thecats)) { foreach ($thecats as $category) { $cat_name = trim($category->get_label()); $term_id = $this->category_exists($cat_name); if (!empty($term_id)) { $post_category[] = $term_id; } else { // need to check and add cat if required if ($ablog['originalcategories'] == '1') { // yes so add $term_id = wp_create_category($cat_name); if (!empty($term_id)) { $post_category[] = $term_id; } } } } } break; case 'tags': // carry on as default as well // carry on as default as well default: $thecats = array(); if (isset($ablog['originalcategories']) && $ablog['originalcategories'] == '1') { $thecats = $item->get_categories(); if (!empty($thecats)) { foreach ($thecats as $category) { $tags[] = trim($category->get_label()); } } } break; } $tax_input = array("post_tag" => $tags); $post_status = $ablog['poststatus']; $post_type = $ablog['posttype']; if ($ablog['postdate'] != 'existing') { $post_date = current_time('mysql'); $post_date_gmt = current_time('mysql', 1); } else { $thedate = $item->get_date(); $post_date = date('Y-m-d H:i:s', strtotime($thedate)); $post_date_gmt = date('Y-m-d H:i:s', strtotime($thedate) + get_option('gmt_offset') * 3600); } // Check the post dates - just in case, we only want posts within our window $thedate = $item->get_date(); $thepostdate = strtotime($thedate); if (!empty($ablog['startfrom']) && $ablog['startfrom'] > $thepostdate) { // We aren't processing this feed yet continue; } if (!empty($ablog['endon']) && $ablog['endon'] < $thepostdate) { // We aren't processing this feed yet continue; } // Move internal variables to correctly labelled ones $post_author = $author; $blog_ID = $bid; $post_data = compact('blog_ID', 'post_author', 'post_date', 'post_date_gmt', 'post_content', 'post_title', 'post_category', 'post_status', 'post_type', 'tax_input'); $post_data = apply_filters('autoblog_pre_post_insert', $post_data, $ablog, $item); $post_ID = wp_insert_post($post_data); if (!is_wp_error($post_ID)) { $processed_count++; update_post_meta($post_ID, 'original_source', trim($item->get_permalink())); update_post_meta($post_ID, 'original_feed', trim($ablog['url'])); update_post_meta($post_ID, 'original_feed_title', trim($ablog['title'])); update_post_meta($post_ID, 'original_imported_time', time()); update_post_meta($post_ID, 'original_feed_id', $feed_id); if (!empty($ablog['source'])) { // Add the original source to the bottom of the post $sourcecontent = "<a href='" . trim($item->get_permalink()) . "'"; if (!empty($ablog['nofollow']) && addslashes($ablog['nofollow']) == '1') { $sourcecontent .= " rel='nofollow'"; } $thesource = stripslashes($ablog['source']); $thesource = str_replace('%POSTURL%', trim($item->get_permalink()), $thesource); $thesource = str_replace('%FEEDURL%', trim($ablog['url']), $thesource); $sourcecontent .= ">" . $thesource . "</a>"; $sourcecontent = apply_filters('autoblog_source_link', $sourcecontent, $ablog); update_post_meta($post_ID, 'original_source_link_html', $sourcecontent); } // Handle fake tags importing if (defined('AUTOBLOG_HANDLE_FAKE_TAGS') && AUTOBLOG_HANDLE_FAKE_TAGS == true) { if (!empty($tags)) { foreach ($tags as $tag) { // Add tags one at a time - more processor and db intensive but, hey, what can you do? wp_set_post_tags($post_ID, $tag, true); } } } do_action('autoblog_post_post_insert', $post_ID, $ablog, $item); } else { // error writing post $this->msgs[] = __('<strong>Error:</strong> ', 'autoblogtext') . $post_ID->get_error_message(); } } // Update the next feed read date $update = array(); $update['lastupdated'] = current_time('timestamp'); $update['nextcheck'] = current_time('timestamp') + intval($ablog['processfeed']) * 60; $this->db->update($this->autoblog, $update, array("feed_id" => $feed_id)); // switch us back to the previous blog if (!empty($ablog['blog']) && function_exists('restore_current_blog')) { restore_current_blog(); } $this->msgs[] = __('<strong>Processed:</strong> I have processed ', 'autoblogtext') . $processed_count . __(' of the ', 'autoblogtext') . $max . __(' posts in the feed - ', 'autoblogtext') . $ablog['url']; return $processed_count; }
function add_category($param_new_category) { $new_categ_name = $parent_of = $categ_slug = ''; $new_categ_name = trim($param_new_category[0]); $parent_of = intval($param_new_category[1]); if (!empty($new_categ_name)) { wp_create_category($new_categ_name, $parent_of); } //create slag from category name, $category_slug = str_replace(' ', '-', strtolower($new_categ_name)); //get category id //alse can be used get_cat_ID( $cat_name ) $this->category_array[] = get_category_by_slug($category_slug)->cat_ID; $this->log("create_category({$param_new_category['0']})", ''); }
<?php $access = new AccessData(); $user = new StudyPressUserWP(); $tableCat = StudyPressDB::getPrefix() . 'studi_category'; $tableCourse = StudyPressDB::getPrefix() . 'studi_course'; $tableSlides = StudyPressDB::getPrefix() . 'studi_slides'; $tableCategCourse = StudyPressDB::getPrefix() . 'studi_categ_cours'; if ($access->getVar("SHOW TABLES LIKE '{$tableCat}'") == $tableCat) { if ($access->getVar("SHOW TABLES LIKE '{$tableCourse}'") == $tableCourse) { $catWPId = wp_create_category('Temporary Category'); $managerCourse = new CourseManager(); $course = new Course(array('name' => 'Temporary Course', 'description' => '', 'authors' => array($user->id()), 'categories' => array($catWPId !== 0 ? $catWPId : 1))); $courseId = $managerCourse->add($course); $resultLesson = $access->getResults("SELECT * FROM {$tableCourse}"); $authors = array(); foreach ($resultLesson as $lesson) { $managerLesson = new LessonManager(); if ($a = get_user_by('login', $lesson['author'])) { $authors[] = $a->ID; } $lessonId = $managerLesson->add(new Lesson(array('name' => $lesson['nom'] != "" ? $lesson['nom'] : "Course", 'author' => $a ? $a->display_name : $user->displayName(), 'authorId' => $a ? $a->ID : $user->id(), 'description' => $lesson['cours_des'], 'duration' => $lesson['duration'], 'courseId' => $courseId))); if (!in_array($user->id(), $authors)) { $authors[] = $user->id(); } if ($access->getVar("SHOW TABLES LIKE '{$tableSlides}'") == $tableSlides) { $slidesResult = $access->getResults("SELECT * FROM {$tableSlides} WHERE course_id = '" . $lesson['course_id'] . "'"); $managerSlide = new SlideManager(); foreach ($slidesResult as $slide) { $managerSlide->add(new Slide(array('courseId' => $lessonId, 'name' => $slide['slides_name'] != "" ? $slide['slides_name'] : "Slide", 'content' => $slide['slides_content'], 'order' => $slide['slides_order']))); }
function get_news($uid = null) { if (is_null($uid)) { $uid = $this->news_uid; } $query = "\n\t\t\tSELECT n.uid itemid,\n\t\t\t\tCASE\n\t\t\t\t\tWHEN n.hidden = 1 THEN 'draft'\n\t\t\t\t\tWHEN n.datetime > UNIX_TIMESTAMP() THEN 'future'\n\t\t\t\t\tELSE 'publish'\n\t\t\t\t\tEND status,\n\t\t\t\tFROM_UNIXTIME(n.datetime) datetime,\n\t\t\t\tn.title,\n\t\t\t\tn.bodytext,\n\t\t\t\tn.keywords,\n\t\t\t\tn.short excerpt,\n\t\t\t\t'open' comments,\n\t\t\t\tn.author,\n\t\t\t\tn.author_email,\n\t\t\t\tn.category,\n\t\t\t\tn.image,\n\t\t\t\tn.imagecaption,\n\t\t\t\tn.news_files,\n\t\t\t\tn.links\n\t\t\tFROM tt_news n\n\t\t\tWHERE 1 = 1\n\t\t\t\tAND n.uid = {$uid}\n\t\t"; $row = $this->t3db->get_row($query, ARRAY_A); if (is_null($row)) { return $row; } $row['props']['datetime'] = $row['datetime']; $row['props']['keywords'] = $row['keywords']; unset($row['keywords']); $row['props']['comments'] = $row['comments']; unset($row['comments']); $row['props']['excerpt'] = $row['excerpt']; unset($row['excerpt']); $row['props']['author'] = $row['author']; unset($row['author']); $row['props']['author_email'] = $row['author_email']; unset($row['author_email']); $row['props']['image'] = $row['image']; unset($row['image']); $row['props']['imagecaption'] = $row['imagecaption']; unset($row['imagecaption']); $row['props']['news_files'] = $row['news_files']; unset($row['news_files']); $row['props']['links'] = $row['links']; unset($row['links']); $row['props']['slug'] = $this->_typo3_api_news_slug($row['itemid']); // Link each category to this post $catids = $this->_typo3_api_news_categories($row['itemid']); $category_arr = array(); foreach ($catids as $cat_name) { // typo3 tt_news_cat => wp category taxomony $category_arr[] = wp_create_category($cat_name); } $row['category'] = $category_arr; return $row; }
function insert_category($category_array) { for ($i = 0; $i < count($category_array); $i++) { $parent_catid = 0; if (is_array($category_array[$i])) { $cat_name_arr = $category_array[$i]; for ($j = 0; $j < count($cat_name_arr); $j++) { $catname = $cat_name_arr[$j]; $last_catid = wp_create_category($catname, $parent_catid); if ($j == 0) { $parent_catid = $last_catid; } } } else { $catname = $category_array[$i]; wp_create_category($catname, $parent_catid); } } }
function wpr_create_campaign() { global $wpdb, $wpr_table_campaigns, $wpr_table_templates,$wpr_loadedmodules; $options = unserialize(get_option("wpr_options")); if($options['wpr_simple']=='Yes') { $totalchance = 0; foreach($wpr_loadedmodules as $lmodule) { if($_POST[$lmodule."chance"] > 0) { $totalchance = $totalchance + $_POST[$lmodule."chance"]; } } if($_POST["mixchance"] > 0) { $totalchance = $totalchance + $_POST["mixchance"]; } } else { for ($i = 1; $i <= $_POST['tnum']; $i++) { if($_POST["chance$i"] > 0) { $totalchance = $totalchance + $_POST["chance$i"]; } } } if($_POST['keywords'] == "" && $_POST['type'] == "keyword") { echo '<div class="updated"><p>'.__("Please enter at least one keyword!", "wprobot").'</p></div>'; } elseif($_POST['feeds'] == "" && $_POST['type'] == "rss") { echo '<div class="updated"><p>'.__("Please enter at least one RSS feed!", "wprobot").'</p></div>'; } elseif($_POST['nodes'] == "" && $_POST['type'] == "nodes") { echo '<div class="updated"><p>'.__("Please enter at least one Amazon BrowseNode!", "wprobot").'</p></div>'; } elseif($_POST['categories'] == "") { echo '<div class="updated"><p>'.__("Please enter at least one category!", "wprobot").'</p></div>'; } elseif($_POST['interval'] == "") { echo '<div class="updated"><p>'.__("Please enter a post interval!", "wprobot").'</p></div>'; } elseif($_POST['name'] == "") { echo '<div class="updated"><p>'.__("Please enter a name for your campaign!", "wprobot").'</p></div>'; } elseif($_POST['title1'] == "" && $options['wpr_simple']!='Yes' || $_POST['content1'] == "" && $options['wpr_simple']!='Yes' || $_POST['chance1'] == "" && $options['wpr_simple']!='Yes') { echo '<div class="updated"><p>'.__("Please enter at least one template for your campaign!", "wprobot").'</p></div>'; } elseif($_POST['amazon_department'] == "All" && $_POST['type'] == "nodes") { echo '<div class="updated"><p>'.__("Amazon Department can not be 'All' in a BrowseNodes campaign! You have to select the correct Department your Nodes belong to (Amazon API requirement).", "wprobot").'</p></div>'; } elseif($totalchance != 100 && $options['wpr_simple']=='Yes' && $_POST['type'] == "keyword") { echo '<div class="updated"><p>'.__("Error: The sum of percentages for all Modules together has to be 100!", "wprobot").'</p></div>'; } elseif($totalchance != 100 && $options['wpr_simple']!='Yes') { echo '<div class="updated"><p>'.__("Error: The sum of the 'Chance of being used' fields for all post templates has to be 100! (Currently: ", "wprobot").$totalchance.')</p></div>'; } elseif($_POST["mixchance"] > 0 && $options['wpr_simple']=='Yes' && empty($_POST["mixcontent"]) && $_POST['type'] == "keyword") { echo '<div class="updated"><p>'.__("Error: Template for Mixed Posts can not be empty if percentage for it is positive!", "wprobot").'</p></div>'; } else { $type = $_POST['type']; // Keywords $_POST['keywords'] = stripslashes($_POST['keywords']); $keywordsinput = str_replace("\r", "", $_POST['keywords']); $keywordsinput = explode("\n", $keywordsinput); $i=0; $keywords = array(); if($_POST["edit"]) {// GET OLD KEYWORDS FOR NUMs $oldcamp->postspan $edit = 1; $oldcamp = $wpdb->get_row( "SELECT keywords,postspan FROM $wpr_table_campaigns WHERE id = '" . $_POST["edit"] . "'" ); $oldkeywords = unserialize($oldcamp->keywords); } if($type == "keyword") { foreach( $keywordsinput as $keyword) { if($keyword != "") { $keyword = explode("|", $keyword); $keywords[$i] = array($keyword[0]); if($edit == 1) { $kwnums = false; foreach($oldkeywords as $key => $oldkeyword) { if($oldkeyword[0] == $keyword[0]) {$kwnums = $oldkeyword[1];} } } if($kwnums != false) { $keywords[$i][] = $kwnums; } else { $keywords[$i][] = array("total" => 0); } $keywords[$i]["skipped"] = 0; // Add alternative keywords for ($y = 1; $y <= 5; $y++) { if(!empty($keyword[$y])) { $keywords[$i]["alternative"][$y] = $keyword[$y]; } } } $i++; } } elseif($type == "rss") { $rssinput = str_replace("\r", "", $_POST['feeds']); $rssinput = explode("\n", $rssinput); foreach( $rssinput as $rss) { if($rss != "") { $keywords[$i] = array($keywordsinput[$i]); if($edit == 1) { $kwnums = false; foreach($oldkeywords as $key => $oldkeyword) { if($oldkeyword[0] == $keywordsinput[$i]) {$kwnums = $oldkeyword[1];} } } if($kwnums != false) { $keywords[$i][] = $kwnums; } else { $keywords[$i][] = array("total" => 0); } $keywords[$i]["skipped"] = 0; $keywords[$i]["feed"] = $rss; } $i++; } } elseif($type == "nodes") { $nodesinput = str_replace("\r", "", $_POST['nodes']); $nodesinput = explode("\n", $nodesinput); $failcount = 0; foreach( $nodesinput as $node) { $nodename = wpr_aws_getnodename($node); if($node != "" && $nodename != false && !is_array($nodename)) { $keywords[$i] = array($keywordsinput[$i]); if($edit == 1) { $kwnums = false; foreach($oldkeywords as $key => $oldkeyword) { if($oldkeyword[0] == $keywordsinput[$i]) {$kwnums = $oldkeyword[1];} } } if($kwnums != false) { $keywords[$i][] = $kwnums; } else { $keywords[$i][] = array("total" => 0); } $keywords[$i]["skipped"] = 0; $keywords[$i]["bnn"] = "$nodename"; $keywords[$i]["node"] = $node; } else { $failcount++; } $i++; } if($failcount > 0) { echo '<div class="updated"><p>'.__("<b>Error</b>: ","wprobot").$failcount.__(" Browsenodes could not be added to your campaign! Make sure to select the correct Amazon Department and the Amazon Site matching your Node ID. This is a requirement of the Amazon API.", "wprobot"); //if(is_array($nodename)) { // echo __("<br/><br/>The last error Amazon returned was:<br/><i>","wprobot").$nodename["message"]."</i>"; //} echo '</p></div>'; } } $keywords = $wpdb->escape(serialize($keywords)); // Categories if($_POST['multisingle'] == "single") { $categorysave = array(); $categorysave[0][0]["id"] = $_POST['categories']; $categorysave[0][0]["name"] = get_cat_name( $_POST['categories'] ); } else { $categorysave = array(); $_POST['categories'] = stripslashes($_POST['categories']); $categoriesinput = str_replace("\r", "", $_POST['categories']); $categoriesinput = explode("\n", $categoriesinput); $i = 0; foreach($categoriesinput as $categories) { $categories = explode(",",$categories); $k = 0; foreach($categories as $category) { if($category != "") { // if category starts with "-" get previous parent ID and set variable if($category[0] == '-') { $category = substr($category, 1); $parent = $parentid; $saveparent = 0; } else { $parent = ""; $saveparent = 1; } $category = str_replace("&", "&", $category); $catname = ucwords($category); $category_ID = get_cat_ID( $category ); if(!$category_ID && $_POST['createcats'] == "yes") { if(is_numeric($parent)) {$parent = (int)$parent;} else {$parent = 0;} if(function_exists("wp_create_category")) { $category_ID = wp_create_category( $catname, $parent ); } elseif(function_exists("wp_insert_category")) { $category_ID = wp_insert_category( array( 'cat_ID' => 0, 'cat_name' => $catname, 'category_description' => "", 'category_nicename' => "", 'category_parent' => $parent, 'taxonomy' => 'category' ) ); } } elseif(!$category_ID && $_POST['createcats'] != "yes") { $category_ID = 1; $catname = get_cat_name( $category_ID ); } elseif(isset($category_ID) && $_POST['createcats'] != "yes") { $catname = get_cat_name( $category_ID ); } $categorysave[$i][$k]["name"] = $catname; $categorysave[$i][$k]["id"] = $category_ID; if($saveparent == 1) {$parentid = $category_ID;} } $k++; } $i++; } /*if(count($categories) == 1) { $categories["type"] = "single"; } else { $categories["type"] = "multi"; } */ }//print_r($categorysave); $categorysave = $wpdb->escape(serialize($categorysave)); // Templates $templates = array(); if($options['wpr_simple']=='Yes' && $type == "keyword") { $i = 1; foreach($wpr_loadedmodules as $lmodule) { if($_POST[$lmodule."chance"] > 0) { $templates[$i]["title"] = "{".$lmodule."title}"; $templates[$i]["content"] = "{".$lmodule."}"; if($lmodule == "ebay" || $lmodule == "yahoonews") {$templates[$i]["content"] .= "\n{".$lmodule."}\n{".$lmodule."}";} $templates[$i]["chance"] = $_POST[$lmodule."chance"]; if($lmodule == "amazon") {$templates[$i]["comments"]["amazon"] = 1;} else {$templates[$i]["comments"]["amazon"] = 0;} if($lmodule == "flickr") {$templates[$i]["comments"]["flickr"] = 1;} else {$templates[$i]["comments"]["flickr"] = 0;} if($lmodule == "yahooanswers") {$templates[$i]["comments"]["yahooanswers"] = 1;} else {$templates[$i]["comments"]["yahooanswers"] = 0;} if($lmodule == "youtube") {$templates[$i]["comments"]["youtube"] = 1;} else {$templates[$i]["comments"]["youtube"] = 0;} $i++; } } if($_POST["mixchance"] > 0) { $templates[$i]["title"] = "{title}"; $templates[$i]["content"] = stripslashes($_POST["mixcontent"]); $templates[$i]["chance"] = $_POST["mixchance"]; $templates[$i]["comments"]["amazon"] = 1; $templates[$i]["comments"]["flickr"] = 1; $templates[$i]["comments"]["yahooanswers"] = 1; $templates[$i]["comments"]["youtube"] = 1; } } else { for ($i = 1; $i <= $_POST['tnum']; $i++) { if($_POST["chance$i"] > 0) { $templates[$i]["title"] = stripslashes($_POST["title$i"]); $templates[$i]["content"] = stripslashes($_POST["content$i"]); $templates[$i]["chance"] = $_POST["chance$i"]; $templates[$i]["comments"]["amazon"] = $_POST["comments_amazon$i"]; $templates[$i]["comments"]["flickr"] = $_POST["comments_flickr$i"]; $templates[$i]["comments"]["yahooanswers"] = $_POST["comments_yahoo$i"]; $templates[$i]["comments"]["youtube"] = $_POST["comments_youtube$i"]; } } } //$templates = array_values($templates); -- MAKES FIRST TEMPLATE "0" $templates = $wpdb->escape(serialize($templates)); // Optional settings $amadept = $_POST['amazon_department']; $yahoocat = array(); $yahoocat["ps"] = $_POST['wpr_poststatus']; $yahoocat["rw"] = $_POST['wpr_rewriter']; $yahoocat["a"] = $_POST['wpr_author']; $yahoocat["t"] = $_POST['wpr_postthumbs']; $yahoocat["pt"] = $_POST['wpr_posttype']; $yahoocat = $wpdb->escape(serialize($yahoocat)); $ebaycat = $_POST['ebay_category']; $_POST['replace'] = stripslashes($_POST['replace']); $replaceinput = str_replace("\r", "", $_POST['replace']); $replaceinput = explode("\n", $replaceinput); $i=0; $replaces = array(); foreach( $replaceinput as $replace) { if($replace != "") { $replace = explode("|", $replace); $replaces[$i]["from"] = $replace[0]; $replaces[$i]["to"] = str_replace('\"', "", $replace[1]); $replaces[$i]["chance"] = $replace[2]; $replaces[$i]["code"] = $replace[3]; } $i++; } $replaces = $wpdb->escape(serialize($replaces)); $_POST['exclude'] = stripslashes($_POST['exclude']); $exclude = str_replace("\r", "", $_POST['exclude']); $exclude = explode("\n", $exclude); foreach($exclude as $key => $value) { if($value == "") { unset($array[$key]); } } $exclude = array_values($exclude); $exclude = $wpdb->escape(serialize($exclude)); $name = $_POST['name']; $postevery = $_POST['interval']; $cr_period = $_POST['period']; $postspan = "WPR_" . $postevery . "_" . $cr_period; $customfield = array(); for ($i = 1; $i <= $_POST['cfnum']; $i++) { if(!empty($_POST["cf_value$i"]) && !empty($_POST["cf_name$i"])) { $customfield[$i]["name"] = $_POST["cf_name$i"]; $customfield[$i]["value"] = $_POST["cf_value$i"]; } } $customfield = $wpdb->escape(serialize($customfield)); $translation = array(); $translation["chance"] = $_POST['transchance']; $translation["from"] = $_POST['trans1']; $translation["to1"] = $_POST['trans2']; $translation["to2"] = $_POST['trans3']; $translation["to3"] = $_POST['trans4']; $translation["comments"] = $_POST['trans_comments']; $translation = $wpdb->escape(serialize($translation)); if($_POST['autopost'] == "yes") { $pause = 0; } else { $pause = 1; } if($_POST["edit"]) { $uid = $_POST["edit"]; $update = "UPDATE " . $wpr_table_campaigns . " SET name = '$name', ctype = '$type', keywords = '$keywords' , categories = '$categorysave', templates = '$templates', cinterval = '$postevery', period = '$cr_period', postspan = '$postspan' , replacekws = '$replaces', excludekws = '$exclude', amazon_department = '$amadept', ebay_cat = '$ebaycat', yahoo_cat = '$yahoocat' , translation = '$translation', customfield = '$customfield', pause = '$pause' WHERE id = $uid"; //echo $update . "<br>"; $results = $wpdb->query($update); if ($results) { if($postspan != $oldcamp->postspan) { $timestamp = wp_next_scheduled( 'wprobothook', array($uid) ); wp_unschedule_event($timestamp, 'wprobothook', array($uid) ); $lag = $_POST['delaystart'] * 3600; wpr_set_schedule($postevery, $cr_period); wp_schedule_event( time()+rand(1,500)+$lag, $postspan, "wprobothook" , array($uid) ); //wp_reschedule_event( $oldcamp->postspan, $postspan, "wprobothook", array($uid) ); // wp_reschedule_event( time(), $postspan, "wprobothook", array($uid) ); wpr_delete_schedule($oldcamp->cinterval, $oldcamp->period); } echo '<div class="updated"><p>'.__('Campaign has been updated! Go to the <a href="?page=wpr-single&id='.$uid.'">control panel</a> to view details.', "wprobot").'</p></div>'; } else { echo '<div class="updated"><p>'.__("Campaign could not be updated!", "wprobot").'</p></div>'; } } else { $insert = "INSERT INTO " . $wpr_table_campaigns . " SET name = '$name', ctype = '$type', keywords = '$keywords' , categories = '$categorysave', templates = '$templates', cinterval = '$postevery', period = '$cr_period', postspan = '$postspan' , replacekws = '$replaces', excludekws = '$exclude', amazon_department = '$amadept', ebay_cat = '$ebaycat', yahoo_cat = '$yahoocat' , translation = '$translation', customfield = '$customfield', pause = '$pause'"; $result = $wpdb->query($insert); $insid = mysql_insert_id(); if ($result) { $sql = "SELECT LAST_INSERT_ID() FROM " . $wpr_table_campaigns; $id = $wpdb->get_var($sql); $linkid = $id; if($linkid != $insid) {$linkid = $insid;} wpr_set_schedule($postevery, $cr_period); $lag = $_POST['delaystart'] * 3600; if($lag == "" || !is_numeric($lag) || $lag < 0) {$lag = 200;} wp_schedule_event( time()+$lag, $postspan, "wprobothook" , array($id) ); $next = wp_next_scheduled( "wprobothook", array($id) ); if($next == 0 || $next == "0" || $next == null || $next == "") { wp_schedule_event( time()+$lag, $postspan, "wprobothook" , array($id) ); } echo '<div class="updated"><p>'; printf(__('Campaign "%1$s" has been added! Go to the <a href="?page=wpr-single&id=%2$s">control panel</a> to view details.', 'wprobot'), $name, $linkid); echo '</p></div>'; } } } }
static function add_category($params_array) { $new_cat_id = wp_create_category($params_array['category_name'], $params_array['parent_id']); //update category descriptions if (!empty($params_array['description'])) { wp_update_term($new_cat_id, 'category', array('description' => $params_array['description'])); } // update the category top post style if (!empty($params_array['top_posts_style'])) { td_global::$td_options['category_options'][$new_cat_id]['tdc_category_top_posts_style'] = $params_array['top_posts_style']; } // update the category top post grid style if (!empty($params_array['tdc_category_td_grid_style'])) { td_global::$td_options['category_options'][$new_cat_id]['tdc_category_td_grid_style'] = $params_array['tdc_category_td_grid_style']; } if (!empty($params_array['tdc_color'])) { td_global::$td_options['category_options'][$new_cat_id]['tdc_color'] = $params_array['tdc_color']; } // update the category template if (!empty($params_array['category_template'])) { td_global::$td_options['category_options'][$new_cat_id]['tdc_category_template'] = $params_array['category_template']; } // update the background if needed if (!empty($params_array['background_td_pic_id'])) { td_global::$td_options['category_options'][$new_cat_id]['tdc_image'] = td_demo_media::get_image_url_by_td_id($params_array['background_td_pic_id']); td_global::$td_options['category_options'][$new_cat_id]['tdc_bg_repeat'] = 'stretch'; } // update the sidebar if needed if (!empty($params_array['sidebar_id'])) { td_global::$td_options['category_options'][$new_cat_id]['tdc_sidebar_name'] = $params_array['sidebar_id']; } // moduel id to sue 123456 (NO MODULE JUST THE NUMBER) if (!empty($params_array['tdc_layout'])) { td_global::$td_options['category_options'][$new_cat_id]['tdc_layout'] = $params_array['tdc_layout']; } // update the sidebar position // sidebar_left, sidebar_right, no_sidebar if (!empty($params_array['tdc_sidebar_pos'])) { td_global::$td_options['category_options'][$new_cat_id]['tdc_sidebar_pos'] = $params_array['tdc_sidebar_pos']; } //update once the category options update_option(TD_THEME_OPTIONS_NAME, td_global::$td_options); // keep a list of installed category ids so we can delete them later if needed // ths is NOT IN WP_011, it's a WordPress option $td_stacks_demo_categories_id = get_option('td_demo_categories_id'); $td_stacks_demo_categories_id[] = $new_cat_id; update_option('td_demo_categories_id', $td_stacks_demo_categories_id); return $new_cat_id; }
function sp_external_videos_init() { $plugin_dir = basename(dirname(__FILE__)); load_plugin_textdomain('external-videos', false, $plugin_dir . '/localization/'); // create a "video" category to store posts against wp_create_category(__('External Videos', 'external-videos')); // create "external videos" post type register_post_type('external-videos', array('label' => __('External Videos', 'external-videos'), 'singular_label' => __('External Video', 'external-videos'), 'description' => __('pulls in videos from external hosting sites', 'external-videos'), 'public' => true, 'publicly_queryable' => true, 'show_ui' => true, 'capability_type' => 'post', 'hierarchical' => false, 'query_var' => false, 'supports' => array('title', 'editor', 'author', 'thumbnail', 'excerpts', 'custom-fields', 'comments', 'revisions', 'excerpt'), 'taxonomies' => array('post_tag', 'category'))); // Oembed support for dotsub wp_oembed_add_provider('#http://(www\\.)?dotsub\\.com/view/.*#i', 'http://api.embed.ly/v1/api/oembed', true); // enable thickbox use for gallery wp_enqueue_style('thickbox'); wp_enqueue_script('thickbox'); }
/** * @param string $session_id session_id to authenticate user * @param array $post Data to insert * @param array $user Data to insert * @param int $blogId Data to insert * @param string $category Data to insert * @return int Id of Post or 0 on error */ public function insertPost($session_id, $post, $user, $blogId, $category, $postId) { if ($this->_isSessionValid($session_id) and $this->_isUserAllowed($session_id, CS_ROLE_USER, $blogId)) { try { if ($blogId == 0) { throw new Exception('Invalid Blog ID!'); } switch_to_blog($blogId); $catId = get_cat_ID($category); if ($catId == 0) { include_once 'wp-admin/includes/taxonomy.php'; $catId = wp_create_category($category); } $post['post_category'] = array($catId); $post['post_author'] = cs_update_user($user); if (!$this->_isUserOfBlog($user['login'], $blogId)) { $success = add_user_to_blog($blogId, $post['post_author'], get_option('default_role')); } if ($postId != '') { $post['ID'] = $postId; wp_update_post($post); } else { $postId = wp_insert_post($post); } restore_current_blog(); } catch (Exception $e) { throw new SoapFault('insertpost', 'Insert Post failed: ' . $e->getMessage()); } } else { if (!$this->_isSessionValid($session_id)) { throw new SoapFault('insertPost', 'insert post failed: Session-ID (' . $session_id . ') is not valid'); } else { throw new SoapFault('insertPost', 'insert post failed: User (' . $this->_sessionid_to_userid_array[$session_id] . ') is not allowed to add post to this blog (' . $blogId . ').'); } } return $postId; }
function process_site_post_form() { if (isset($_POST)) { $djd_options = get_option('djd_site_post_settings'); if (!empty($_POST["djd-our-id"])) { $djd_post_id = $_POST["djd-our-id"]; } // Create post object with defaults $my_post = array('ID' => $djd_post_id, 'post_title' => '', 'post_status' => 'publish', 'post_author' => '', 'post_category' => '', 'comment_status' => 'open', 'ping_status' => 'open', 'post_content' => '', 'post_excerpt' => '', 'post_type' => 'post', 'tags_input' => '', 'to_ping' => ''); //Fill our $my_post array $my_post['post_title'] = wp_strip_all_tags($_POST['djd_site_post_title']); if (array_key_exists('djdsitepostcontent', $_POST)) { $my_post['post_content'] = $_POST['djdsitepostcontent']; } if (array_key_exists('djd_site_post_excerpt', $_POST)) { $my_post['post_excerpt'] = wp_strip_all_tags($_POST['djd_site_post_excerpt']); } if (array_key_exists('djd_site_post_select_category', $_POST)) { $ourCategory = array($_POST['djd_site_post_select_category']); } if (array_key_exists('djd_site_post_checklist_category', $_POST)) { $ourCategory = $_POST['djd_site_post_checklist_category']; } if (array_key_exists('djd_site_post_new_category', $_POST)) { if (!empty($_POST['djd_site_post_new_category'])) { require_once WP_PLUGIN_DIR . '/../../wp-admin/includes/taxonomy.php'; if ($newCatId = wp_create_category(wp_strip_all_tags($_POST['djd_site_post_new_category']))) { $ourCategory = array($newCatId); } else { throw new Exception(__('Unable to create new category. Please try again or select an existing category.', 'djd-site-post')); } } } if (!is_user_logged_in() && !$djd_options['djd-guest-cat-select']) { $ourCategory = array($djd_options['djd-guest-cat']); } $my_post['post_category'] = $ourCategory; if (!empty($_POST["djd-our-author"])) { $my_post['post_author'] = $_POST["djd-our-author"]; } else { $my_post['post_author'] = $user_verified['djd_user_id']; } if (array_key_exists('djd_site_post_tags', $_POST)) { $my_post['tags_input'] = wp_strip_all_tags($_POST['djd_site_post_tags']); } if ($djd_options['djd-publish-status']) { $my_post['post_status'] = $djd_options['djd-publish-status']; } if (array_key_exists('djd-priv-publish-status', $_POST)) { $my_post['post_status'] = wp_strip_all_tags($_POST['djd-priv-publish-status']); } // Insert the post into the database $post_success = wp_update_post($my_post); if ($post_success === false) { $result = "error"; } else { $result = "success"; //if ( 'publish' == $my_post['post_status'] ) do_action('publish_post'); if (isset($_POST['djd-post-format'])) { set_post_format($post_success, wp_strip_all_tags($_POST['djd-post-format'])); } else { set_post_format($post_success, wp_strip_all_tags($djd_options['djd-post-format-default'])); } } if (array_key_exists('djd_site_post_guest_name', $_POST)) { add_post_meta($post_success, 'guest_name', wp_strip_all_tags($_POST['djd_site_post_guest_name']), true) || update_post_meta($post_success, 'guest_name', wp_strip_all_tags($_POST['djd_site_post_guest_name'])); } if (array_key_exists('djd_site_post_guest_email', $_POST)) { add_post_meta($post_success, 'guest_email', wp_strip_all_tags($_POST['djd_site_post_guest_email']), true) || update_post_meta($post_success, 'guest_name', wp_strip_all_tags($_POST['djd_site_post_guest_name'])); } if (apply_filters('form_abort_on_failure', true, $form_name)) { $success = $post_success; } if ($success) { if ($djd_options['djd-mail']) { $this->djd_sendmail($post_success, wp_strip_all_tags($_POST['djd_site_post_title'])); } if (!empty($_SERVER['HTTP_X_REQUESTED_WITH']) && strtolower($_SERVER['HTTP_X_REQUESTED_WITH']) == 'xmlhttprequest') { echo $result; } else { setcookie('form_ok', 1, time() + 10, '/'); header("Location: " . $_SERVER["HTTP_REFERER"]); die; } } else { throw new Exception($djd_options['djd-post-fail'] ? $djd_options['djd-post-fail'] : __('We were unable to accept your post at this time. Please try again. If the problem persists tell the site owner.', 'djd-site-post')); } } // isset($_POST) die; }
/** * Test post category orderby query asc * * @since 1.8 */ public function testSearchTaxNameOrderbyQueryAsc() { $cat1 = wp_create_category('Category 1'); $cat2 = wp_create_category('Another category two'); $cat3 = wp_create_category('basic category'); $cat4 = wp_create_category('Category 0'); ep_create_and_sync_post(array('post_title' => 'ordertest 333', 'post_category' => array($cat4))); ep_create_and_sync_post(array('post_title' => 'ordertest 444', 'post_category' => array($cat1))); ep_create_and_sync_post(array('post_title' => 'Ordertest 222', 'post_category' => array($cat3))); ep_create_and_sync_post(array('post_title' => 'ordertest 111', 'post_category' => array($cat2))); ep_refresh_index(); $args = array('s' => 'ordertest', 'orderby' => 'terms.category.name.sortable', 'order' => 'ASC'); $query = new WP_Query($args); $this->assertEquals(4, $query->post_count); $this->assertEquals(4, $query->found_posts); $this->assertEquals('ordertest 111', $query->posts[0]->post_title); $this->assertEquals('Ordertest 222', $query->posts[1]->post_title); $this->assertEquals('ordertest 333', $query->posts[2]->post_title); $this->assertEquals('ordertest 444', $query->posts[3]->post_title); }
/** * Reads the child node along with the settings specified in the index the adds it to the tree. * * @param \DOMNode $node * @param WebPage $parentPage */ private function readInChildNode(\DOMNode $node, WebPage $parentPage = null) { $webPage = $parentPage; $settings = new WebPageSettings(); if (strcmp($node->nodeName, 'document') == 0) { $attributes = $node->attributes; $title = null; $src = null; $tag = array(); $order = null; $category = array(); if (isset($attributes)) { for ($i = 0; $i < $attributes->length; $i++) { $attribute = $attributes->item($i)->nodeName; switch ($attribute) { case 'title': $title = $attributes->item($i)->nodeValue; break; case 'src': $src = $attributes->item($i)->nodeValue; if ($src[0] != '/') { $src = basename($this->retriever->getFullFilePath($src)); } break; case 'category': // if category is set in XML, then overrides the web settings // TODO: should have a setting for if to use xml or web settings $category = explode(',', $attributes->item($i)->nodeValue); break; // case 'tag': // $tag = explode( ',', $attributes->item( $i )->nodeValue ); // break; // case 'tag': // $tag = explode( ',', $attributes->item( $i )->nodeValue ); // break; case 'order': $order = $attributes->item($i)->nodeValue; break; // /* future cases // case 'overwrite-existing': // break; // */ // /* future cases // case 'overwrite-existing': // break; // */ default: break; } } } if (!is_null($category) && is_array($category)) { foreach ($category as $index => $cat) { $cat_id = wp_create_category(trim($cat)); $settings->addCategory(intval($cat_id)); } } /* if ( !is_null( $tag ) && is_array( $tag ) ) { foreach ( $tag as $t ) { //TODO: support tags } }*/ $webPage = new WebPage($this->retriever, $title, $src, null, $settings); $webPage->setOrderPosition($order); if (is_null($parentPage)) { $this->trees[] = $webPage; } else { $parentPage->addChild($webPage); } } $children = $node->childNodes; if (isset($children)) { for ($i = 0; $i < $children->length; $i++) { $this->readInChildNode($children->item($i), $webPage); } } }