/** * Build WP_Query object for the given slider * * @see Hyyan_Slider_Shortcode::FILTER_SHORTCODE_QueryArgs * * @param string $slider slider name * @param string $order slides order * @param string $orderBy order slides by ? * * @return \WP_Query * @throws \RuntimeException if the slider does not exist */ function hyyan_slider_query($slider, $order = 'DESC', $orderBy = 'rand') { $slider = esc_attr((string) $slider); /** check for term existance */ if (!term_exists($slider, Hyyan_Slider::CUSTOM_TAXONOMY)) { throw new \RuntimeException(sprintf('Can not build query for %s slider - term does not exist', $slider)); } if (function_exists('pll_get_term')) { // get slider object $term = get_term_by('slug', $slider, Hyyan_Slider::CUSTOM_TAXONOMY); $slider = $term->slug; if ($term) { // find the id of translated slider $id = pll_get_term($term->term_id); // get translated slider object $trans_term = get_term($id, Hyyan_Slider::CUSTOM_TAXONOMY); if ($trans_term && !$trans_term instanceof WP_Error) { $slider = $trans_term->slug; } } } /** * Query object * * @see Hyyan_Slider_Shortcode::FILTER_SHORTCODE_QueryArgs * * @var WP_Query */ $query = new WP_Query(apply_filters(Hyyan_Slider_Events::FILTER_SHORTCODE_QueryArgs, array('post_type' => Hyyan_Slider::CUSTOM_POST, 'taxonomy' => Hyyan_Slider::CUSTOM_TAXONOMY, 'term' => $slider, 'post_status' => 'publish', 'order' => esc_attr($order), 'orderby' => esc_attr($orderBy), 'posts_per_page' => -1, 'lang' => null))); return $query; }
/** * * Assigns random terms to all posts in a taxonomy. * * By default all objects of the 'post' post type will be randomized, use the * --post_type flag to target pages or a custom post type. Use the --include * and --exclude flags to filter or ignore specific object IDs and the --before * and --after flags to specify a date range. Also, optionally pass --terms as * a list of terms you want to use for the randomization. If terms exist in the * target taxonomy, those terms will be used. If not, a string of 6 words * generated randomly will be used for the randomization. * * ## Options * * <taxonomy> * : The taxonomy that should get randomized * * ## Exmples * * wp randomize category * * @synopsis <taxonomy> [--include=<bar>] [--exclude=<foo>] [--post_type=<foo>] * [--before=<bar>] [--after=<date>] [--terms=<terms>] * **/ public function taxonomy($args, $assoc_args) { $taxonomy = $args[0]; $get_posts = $this->get_specified_posts($assoc_args); $message = $get_posts['message']; $posts = $get_posts['posts']; $args = $get_posts['args']; $preamble = "Will assign random {$taxonomy} terms"; print_r("{$preamble} {$message}.\n"); if (isset($assoc_args['terms'])) { $terms = explode(',', $assoc_args['terms']); \WP_CLI::log('Using terms ' . $assoc_args['terms']); } else { \WP_CLI::log('Gathering and processing random terms.'); $terms = $this->get_random_terms(); \WP_CLI::log('No term list given, using random terms.'); } foreach ($posts as $p) { $index = array_rand($terms); $term = $terms[$index]; \WP_CLI::log("Assigning {$term} to taxonomy {$taxonomy} for {$p->post_type} {$p->ID}"); if (!term_exists($term, $taxonomy)) { wp_insert_term($term, $taxonomy); } wp_set_object_terms($p->ID, $term, $taxonomy, $append = false); } }
private function categorize($post_id, $categories_str) { $categories_arr = explode(',', $categories_str); foreach ($categories_arr as $category) { $categories_par = explode('>', $category); if (!isset($categories_par[0], $categories_par[1])) { $this->err($category, $post_id); } $categories_par[0] = trim($categories_par[0]); $categories_par[1] = trim($categories_par[1]); $parent_term = term_exists($categories_par[0], 'venture_categories'); if (!$parent_term) { $parent_term = wp_insert_term($categories_par[0], 'venture_categories'); } $parent_term_id = intval($parent_term['term_id']); $term = term_exists($categories_par[1], 'venture_categories', $parent_term_id); if (!$term) { $term = wp_insert_term($categories_par[1], 'venture_categories', array('parent' => $parent_term_id)); } if (is_wp_error($term)) { $this->err($category, $post_id); } $term_id = intval($term['term_id']); wp_set_object_terms($post_id, $parent_term_id, 'venture_categories', true); wp_set_object_terms($post_id, $term_id, 'venture_categories', true); } }
function woocommerce_osc_run_cats($parent = 0, $parent_term_id = 0) { global $wpdb, $oscdb, $import_cat_counter; $categories = $oscdb->get_results("SELECT c.*, cd.* FROM categories c, categories_description cd WHERE c.categories_id=cd.categories_id AND cd.language_id=1 AND c.parent_id='" . (int) $parent . "'", ARRAY_A); if (!empty($categories)) { foreach ($categories as $category) { if (!is_wp_error($category)) { $term = term_exists($category['categories_name'], 'product_cat', (int) $parent_term_id); // array is returned if taxonomy is given if ((int) $term['term_id'] == 0) { $term = wp_insert_term($category['categories_name'], 'product_cat', array('parent' => $parent_term_id)); delete_option('product_cat_children'); // clear the cache $attach_id = 0; if ($category['categories_image'] != '') { $url = rtrim($_POST['store_url'], '/') . '/images/' . urlencode($category['categories_image']); $attach_id = woocommerce_osc_import_image($url); } add_woocommerce_term_meta($term['term_id'], 'order', $category['sort_order']); add_woocommerce_term_meta($term['term_id'], 'display_type', ''); add_woocommerce_term_meta($term['term_id'], 'thumbnail_id', (int) $attach_id); add_woocommerce_term_meta($term['term_id'], 'osc_id', $category['categories_id']); woocommerce_osc_run_cats($category['categories_id'], $term['term_id']); $import_cat_counter++; } else { woocommerce_osc_run_cats($category['categories_id'], $term['term_id']); } } } } }
/** * initialize_container - Initialiaze the PAIR containers if the associated * option is checked * * @param {type} $option the checkbox to evaluate * @param {type} $oldValue the oldvalue (should be false) * @param {type} $_newValue the new checkbox value (should be true) * @return {type} description */ function initialize_container($force = false) { if (isset($_GET['settings-updated']) || $force) { $ldp_container_init = get_option('ldp_container_init', false); if ($ldp_container_init || $force) { //TODO: Initialize the PAIR containers $pair_terms = array('initiative' => array('label' => __('Initiative', 'wpldp'), 'rdftype' => 'pair:initiative'), 'organization' => array('label' => __('Organization', 'wpldp'), 'rdftype' => 'foaf:organization'), 'group' => array('label' => __('Group', 'wpldp'), 'rdftype' => 'foaf:group'), 'document' => array('label' => __('Document', 'wpldp'), 'rdftype' => 'foaf:document'), 'goodorservice' => array('label' => __('Good or Service', 'wpldp'), 'rdftype' => 'goodRelation:goodOrService'), 'artwork' => array('label' => __('Artwork', 'wpldp'), 'rdftype' => 'schema:artwork'), 'event' => array('label' => __('Event', 'wpldp'), 'rdftype' => 'schema:event'), 'place' => array('label' => __('Place', 'wpldp'), 'rdftype' => 'schema:place'), 'theme' => array('label' => __('Theme', 'wpldp'), 'rdftype' => 'pair:theme'), 'thesis' => array('label' => __('Thesis', 'wpldp'), 'rdftype' => 'pair:thesis'), 'person' => array('label' => __('Person', 'wpldp'), 'rdftype' => 'pair:person')); foreach ($pair_terms as $term => $properties) { // Loop on the models files (or hardcoded array) and push them each as taxonomy term in the database $model = file_get_contents(__DIR__ . '/models/' . $term . '.json'); $term_id = null; if (!term_exists($term, 'ldp_container')) { $new_term = wp_insert_term($properties['label'], 'ldp_container', array('slug' => $term, 'description' => sprintf(__('The %1$s object model', 'wpldp'), $term))); $term_id = $new_term['term_id']; } else { $existing_term = get_term_by('slug', $term, 'ldp_container'); $updated_term = wp_update_term($existing_term->term_id, 'ldp_container', array('slug' => $term, 'description' => sprintf(__('The %1$s object model', 'wpldp'), $term))); $term_id = $existing_term->term_id; } if (!empty($term_id)) { $term_meta = get_option("ldp_container_{$term_id}"); if (!is_array($term_meta)) { $term_meta = array(); } $term_meta['ldp_rdf_type'] = $properties['rdftype']; $term_meta['ldp_model'] = stripslashes_deep($model); update_option("ldp_container_{$term_id}", $term_meta); } } } } }
/** * initialize_container - Initialiaze the PAIR containers if the associated * option is checked * * @param {type} $option the checkbox to evaluate * @param {type} $oldValue the oldvalue (should be false) * @param {type} $_newValue the new checkbox value (should be true) * @return {type} description */ function initialize_container() { if (isset($_GET['settings-updated'])) { $ldp_container_init = get_option('ldp_container_init', false); if ($ldp_container_init) { //TODO: Initialize the PAIR containers $pair_terms = array('project', 'actor', 'idea', 'resource'); foreach ($pair_terms as $term) { // 1 - Check if they do not exists if (!term_exists($term, 'ldp_container')) { // - Else, loop on the models files (or hardcoded array) and push them each as taxonomy term in the database $model = file_get_contents(__DIR__ . '/models/' . $term . '_model.json'); $new_term = wp_insert_term(ucfirst($term), 'ldp_container', array('slug' => $term, 'description' => 'The ' . $term . ' object model')); $term_id = $new_term['term_id']; $term_meta = get_option("ldp_container_{$term_id}"); if (!is_array($term_meta)) { $term_meta = array(); } $term_meta['ldp_model'] = stripslashes_deep($model); update_option("ldp_container_{$term_id}", $term_meta); } } } } }
public function save_new_episode($item, $show_slug) { $item_date = $item->get_date('Y-m-d H:i:s'); $enclosure = $item->get_enclosure(); $post = array('post_title' => $item->get_title(), 'post_date' => $item_date, 'post_content' => $item->get_description(), 'post_status' => 'publish', 'post_type' => Dipo_Podcast_Post_Type::POST_TYPE, 'tags_input' => $enclosure->get_keywords()); $post_id = wp_insert_post($post); if (!empty($show_slug)) { $term_id = term_exists($show_slug, 'podcast_show'); wp_set_post_terms($post_id, $term_id, 'podcast_show'); } // save episodes data as metadata for post $subtitle = htmlspecialchars($this->get_subtitle($item)); update_post_meta($post_id, '_dipo_subtitle', $subtitle); $summary = htmlspecialchars($this->get_summary($item)); update_post_meta($post_id, '_dipo_summary', $summary); $explicit = htmlspecialchars(strtolower($this->get_explicit($item))); $possible_values = array('yes', 'no', 'clean'); if (in_array($explicit, $possible_values)) { update_post_meta($post_id, '_dipo_explicit', $explicit); } $medialink = esc_url_raw($enclosure->get_link()); $type = htmlspecialchars($enclosure->get_type()); $duration = htmlspecialchars($enclosure->get_duration('hh:mm:ss')); $length = htmlspecialchars($enclosure->get_length()); $mediafile = array('id' => 1, 'medialink' => $medialink, 'mediatype' => $type, 'duration' => $duration, 'filesize' => $length); update_post_meta($post_id, '_dipo_mediafile1', $mediafile); update_post_meta($post_id, '_dipo_max_mediafile_number', '1'); $this->created_episodes++; return $post_id; }
public function filter_query_request($args) { global $portfolio_page_name; if (is_admin()) { return $args; } // Make sure no 404 error is thrown for any sub pages of products-page if (!empty($args['portfolio_cat']) && 'page' != $args['portfolio_cat'] && !term_exists($args['portfolio_cat'], 'portfolio_cat')) { // Probably requesting a page that is a sub page of products page $pagename = $portfolio_page_name . "/{$args['portfolio_cat']}"; if (isset($args['name'])) { $pagename .= "/{$args['name']}"; } $args = array(); $args['pagename'] = $pagename; } // When product page is set to display all products or a category, and pagination is enabled, $wp_query is messed up // and is_home() is true. This fixes that. if (isset($args['post_type']) && 'a3-portfolio' == $args['post_type'] && !empty($args['a3-portfolio']) && isset($args['portfolio_cat']) && 'page' == $args['portfolio_cat']) { $page = $args['a3-portfolio']; $args = array(); $args['pagename'] = $portfolio_page_name; $args['page'] = $page; } return $args; }
function add_mediatags_alternate_link() { global $wp_version; $mediatag_rss_feed = get_option('mediatag_rss_feed', 'yes'); if (!$mediatag_rss_feed || $mediatag_rss_feed != "yes") { return; } $mediatag_var = get_query_var(MEDIA_TAGS_QUERYVAR); //echo "mediatag_var<pre>"; print_r($mediatag_var); echo "</pre>"; if ($mediatag_var) { if (version_compare($wp_version, '3.0', '<')) { $mediatag_term = is_term($mediatag_var, MEDIA_TAGS_TAXONOMY); } else { $mediatag_term = term_exists($mediatag_var, MEDIA_TAGS_TAXONOMY); } if ($mediatag_term) { $mediatag_term = get_term($mediatag_term['term_id'], MEDIA_TAGS_TAXONOMY); $feed_title = get_bloginfo('name') . " » " . __('Media-Tags RSS Feed', MEDIA_TAGS_I18N_DOMAIN) . " » " . $mediatag_term->name; $feed_link = get_mediatag_link($mediatag_term->term_id, true); if ($feed_link) { ?> <link id="MediaTagsRSS" rel="alternate" type="application/rss+xml" title="<?php echo $feed_title; ?> " href="<?php echo $feed_link; ?> " /> <?php } } } }
function rcl_update_grouppost_meta($post_id, $postdata, $action) { if ($postdata['post_type'] != 'post-group') { return false; } if (isset($_POST['term_id'])) { $term_id = intval(base64_decode($_POST['term_id'])); } if (isset($term_id)) { wp_set_object_terms($post_id, (int) $term_id, 'groups'); } $gr_tag = sanitize_text_field($_POST['group-tag']); if ($gr_tag) { if (!$term_id) { $groups = get_the_terms($post_id, 'groups'); foreach ($groups as $group) { if ($group->parent != 0) { continue; } $group_id = $group->term_id; } } else { $group_id = $term_id; } $term = term_exists($gr_tag, 'groups', $group_id); if (!$term) { $term = wp_insert_term($gr_tag, 'groups', array('description' => '', 'slug' => '', 'parent' => $group_id)); } wp_set_object_terms($post_id, array((int) $term['term_id'], (int) $group_id), 'groups'); } }
public function init_attribute_image_selector() { global $woocommerce, $_wp_additional_image_sizes; $screen = get_current_screen(); if (strpos($screen->id, 'pa_') !== false) { $this->taxonomy = $_REQUEST['taxonomy']; if (taxonomy_exists($_REQUEST['taxonomy'])) { $term_id = term_exists(isset($_REQUEST['tag_ID']) ? $_REQUEST['tag_ID'] : 0, $_REQUEST['taxonomy']); $term = 0; if ($term_id) { $term = get_term($term_id, $_REQUEST['taxonomy']); } $this->image_size = apply_filters('woocommerce_get_swatches_image_size', $this->image_size, $_REQUEST['taxonomy'], $term_id); } $the_size = isset($_wp_additional_image_sizes[$this->image_size]) ? $_wp_additional_image_sizes[$this->image_size] : $_wp_additional_image_sizes['shop_thumbnail']; if (isset($the_size['width']) && isset($the_size['height'])) { $this->image_width = $the_size['width']; $this->image_height = $the_size['height']; } else { $this->image_width = 32; $this->image_height = 32; } $attribute_taxonomies = WC_Swatches_Compatibility::wc_get_attribute_taxonomies(); if ($attribute_taxonomies) { foreach ($attribute_taxonomies as $tax) { add_action('pa_' . $tax->attribute_name . '_add_form_fields', array(&$this, 'woocommerce_add_attribute_thumbnail_field')); add_action('pa_' . $tax->attribute_name . '_edit_form_fields', array(&$this, 'woocommerce_edit_attributre_thumbnail_field'), 10, 2); add_filter('manage_edit-pa_' . $tax->attribute_name . '_columns', array(&$this, 'woocommerce_product_attribute_columns')); add_filter('manage_pa_' . $tax->attribute_name . '_custom_column', array(&$this, 'woocommerce_product_attribute_column'), 10, 3); } } } }
function wdm_modified_bid_place($args) { global $wpdb; $wpdb->show_errors(); $wpdb->insert($wpdb->prefix . 'wdm_bidders', array('name' => $args['orig_name'], 'email' => $args['orig_email'], 'auction_id' => $args['auc_id'], 'bid' => $args['orig_bid'], 'date' => date("Y-m-d H:i:s", time())), array('%s', '%s', '%d', '%f', '%s')); update_post_meta($args['auc_id'], 'wdm_previous_bid_value', $args['mod_bid']); //store bid value of the most recent bidder $place_bid = $wpdb->insert($wpdb->prefix . 'wdm_bidders', array('name' => $args['mod_name'], 'email' => $args['mod_email'], 'auction_id' => $args['auc_id'], 'bid' => $args['mod_bid'], 'date' => date("Y-m-d H:i:s", time())), array('%s', '%s', '%d', '%f', '%s')); if ($place_bid) { $c_code = substr(get_option('wdm_currency'), -3); $char = $args['site_char']; $ret_url = $args['auc_url']; $adm_email = get_option("wdm_auction_email"); if ($args['email_type'] === 'winner') { update_post_meta($args['auc_id'], 'wdm_listing_ends', date("Y-m-d H:i:s", time())); $check_term = term_exists('expired', 'auction-status'); wp_set_post_terms($args['auc_id'], $check_term["term_id"], 'auction-status'); update_post_meta($args['auc_id'], 'email_sent_imd', 'sent_imd'); $args['stat'] = "Won"; } else { $args['stat'] = "Placed"; } $args['adm_email'] = $adm_email; $args['ret_url'] = $ret_url; $args['type'] = 'proxy'; echo json_encode($args); } }
function register_emrede_taxonomies() { $labels = array('name' => __('Público Alvo', 'fluxo'), 'singular_name' => __('Público Alvo', 'fluxo'), 'search_items' => __('Procurar em Público Alvo', 'fluxo'), 'all_items' => __('Todos os Públicos Alvos', 'fluxo'), 'parent_item' => null, 'parent_item_colon' => null, 'edit_item' => __('Editar Público Alvo', 'fluxo'), 'update_item' => __('Atualizar um Público Alvo', 'fluxo'), 'add_new_item' => __('Adicionar Novo Público Alvo', 'fluxo'), 'add_new' => __('Adicionar Público Alvo', 'fluxo'), 'new_item_name' => __('Novo Público Alvo', 'fluxo'), 'view_item' => __('Visualizar Público Alvo', 'fluxo'), 'not_found' => __('Nenhum Público Alvo localizado', 'fluxo'), 'not_found_in_trash' => __('Nenhum Público Alvo localizado na lixeira', 'fluxo'), 'menu_name' => __('Público Alvo', 'fluxo')); register_taxonomy('publico-alvo', array('emrede'), array('hierarchical' => true, 'label' => 'Público Alvo', 'show_ui' => true, 'query_var' => true, 'show_admin_column' => true, 'labels' => $labels)); if (!term_exists('Público em Geral', 'publico-alvo')) { wp_insert_term("Coletivos, artistas", 'publico-alvo'); wp_insert_term("comunidades", 'publico-alvo'); wp_insert_term("Crianças, jovens e adultos", 'publico-alvo'); wp_insert_term("Desenvolvedores", 'publico-alvo'); wp_insert_term("Educadores", 'publico-alvo'); wp_insert_term("Indígenas", 'publico-alvo'); wp_insert_term("Jovens", 'publico-alvo'); wp_insert_term("Jovens e adultos", 'publico-alvo'); wp_insert_term("Jovens, adultos, idosos", 'publico-alvo'); wp_insert_term("juristas, sociólogos, economistas", 'publico-alvo'); wp_insert_term("Militantes e pesquisadores que atuam no Direito à Cidade", 'publico-alvo'); wp_insert_term("Militantes pela cultura", 'publico-alvo'); wp_insert_term("Movimentos sociais", 'publico-alvo'); wp_insert_term("organizaciones sociales, comunitarias, sindicales, movimientos de base, fundaciones, asociaciones civiles, cooperativas, empresas recuperadas, bancos populare", 'publico-alvo'); wp_insert_term("Produtores culturais", 'publico-alvo'); wp_insert_term("Produtores e artistas", 'publico-alvo'); wp_insert_term("Produtores, gestores e articuladores culturais", 'publico-alvo'); wp_insert_term("professores e lideranças populares", 'publico-alvo'); wp_insert_term("Público em Geral", 'publico-alvo'); wp_insert_term("artistas e arte-educadores de coletivos e Pontos de Cultura", 'publico-alvo'); wp_insert_term("Rádios comunitárias", 'publico-alvo'); wp_insert_term("Segmentos Populares", 'publico-alvo'); wp_insert_term("Outro#input#", 'publico-alvo'); } }
function woocommerce_init() { // create our Accommodation, Tour and Car Rental woocommerce categories if (!term_exists(BOOKYOURTRAVEL_WOO_PRODUCT_CAT_ACCOMMODATIONS, 'product_cat')) { $this->woocommerce_create_product_category(BOOKYOURTRAVEL_WOO_PRODUCT_CAT_ACCOMMODATIONS, __('Accommodations', 'bookyourtravel'), __('Accommodations category', 'bookyourtravel')); } if (!term_exists(BOOKYOURTRAVEL_WOO_PRODUCT_CAT_TOURS, 'product_cat')) { $this->woocommerce_create_product_category(BOOKYOURTRAVEL_WOO_PRODUCT_CAT_TOURS, __('Tours', 'bookyourtravel'), __('Tours Category', 'bookyourtravel')); } if (!term_exists(BOOKYOURTRAVEL_WOO_PRODUCT_CAT_CAR_RENTALS, 'product_cat')) { $this->woocommerce_create_product_category(BOOKYOURTRAVEL_WOO_PRODUCT_CAT_CAR_RENTALS, __('Car rentals', 'bookyourtravel'), __('Car Rentals Category', 'bookyourtravel')); } if (!term_exists(BOOKYOURTRAVEL_WOO_PRODUCT_CAT_CRUISES, 'product_cat')) { $this->woocommerce_create_product_category(BOOKYOURTRAVEL_WOO_PRODUCT_CAT_CRUISES, __('Cruises', 'bookyourtravel'), __('Cruises Category', 'bookyourtravel')); } // modify cart item name and link add_filter('woocommerce_cart_item_name', array($this, 'woocommerce_modify_cart_product_title'), 20, 3); add_filter('woocommerce_order_item_name', array($this, 'woocommerce_modify_order_product_title'), 20, 2); // prefill checkout form add_filter('woocommerce_checkout_get_value', array($this, 'woocommerce_checkout_get_value'), 20, 2); add_action('woocommerce_order_status_completed', array($this, 'woocommerce_handle_woo_payment')); // Add reservetions to Booking System after payment has been completed. add_action('woocommerce_order_status_pending_to_processing', array($this, 'woocommerce_handle_woo_payment')); // Add reservetions to Booking System after payment has been completed. add_action('woocommerce_order_status_pending_to_on-hold', array($this, 'woocommerce_handle_woo_payment')); // Add reservetions to Booking System after payment has been completed. add_action('woocommerce_order_status_failed_to_processing', array($this, 'woocommerce_handle_woo_payment')); // Add reservetions to Booking System after payment has been completed. // remove woocommerce breadcrumbs since BYT has it's own remove_action('woocommerce_before_main_content', array($this, 'woocommerce_breadcrumb'), 20); // override woocommerce template to not show // single-product.php, taxonomy-product_cat.php, taxonomy-product_tag.php, archive-product.php // as we don't need them for byt add_filter('template_include', array($this, 'woocommerce_template_include')); }
/** * Fixes for some inconsistencies about $wp_query when viewing WPEC pages. * * Causes the following URLs to work (with pagination enabled): * * /products-page/ (product listing) * /products-page/car-audio/ (existing product category) * /products-page/car-audio/page/2/ (existing product category, page 2) * /products-page/page/2/ (product listing, page 2) * /products-page/checkout/ (existing built-in sub page) * /products-page/anotherpage/ (another sub page that may exist) * * @param string $q Query String */ function wpsc_filter_query_request($args) { global $wpsc_page_titles; if (is_admin()) { return $args; } $is_sub_page = !empty($args['wpsc_product_category']) && 'page' != $args['wpsc_product_category'] && !term_exists($args['wpsc_product_category'], 'wpsc_product_category'); // Make sure no 404 error is thrown for any sub pages of products-page if ($is_sub_page) { // Probably requesting a page that is a sub page of products page $pagename = "{$wpsc_page_titles['products']}/{$args['wpsc_product_category']}"; if (isset($args['name'])) { $pagename .= "/{$args['name']}"; } $args = array(); $args['pagename'] = $pagename; } // When product page is set to display all products or a category, and pagination is enabled, $wp_query is messed up // and is_home() is true. This fixes that. $needs_pagination_fix = isset($args['post_type']) && !empty($args['wpsc_product_category']) && 'wpsc-product' == $args['post_type'] && !empty($args['wpsc-product']) && 'page' == $args['wpsc_product_category']; if ($needs_pagination_fix) { $default_category = get_option('wpsc_default_category'); if ($default_category == 'all' || $default_category != 'list') { $page = $args['wpsc-product']; $args = array(); $args['pagename'] = "{$wpsc_page_titles['products']}"; $args['page'] = $page; } } return $args; }
public function test_wp_insert_delete_term() { $taxonomy = 'wptests_tax'; register_taxonomy($taxonomy, 'post'); // a new unused term $term = rand_str(); $this->assertNull(term_exists($term)); $initial_count = wp_count_terms($taxonomy); $t = wp_insert_term($term, $taxonomy); $this->assertInternalType('array', $t); $this->assertNotWPError($t); $this->assertTrue($t['term_id'] > 0); $this->assertTrue($t['term_taxonomy_id'] > 0); $this->assertEquals($initial_count + 1, wp_count_terms($taxonomy)); // make sure the term exists $this->assertTrue(term_exists($term) > 0); $this->assertTrue(term_exists($t['term_id']) > 0); // now delete it add_filter('delete_term', array($this, 'deleted_term_cb'), 10, 5); $this->assertTrue(wp_delete_term($t['term_id'], $taxonomy)); remove_filter('delete_term', array($this, 'deleted_term_cb'), 10, 5); $this->assertNull(term_exists($term)); $this->assertNull(term_exists($t['term_id'])); $this->assertEquals($initial_count, wp_count_terms($taxonomy)); }
/** * Add flat taxonomy term from "checklist" meta box on the Media Manager Modal Window * * Adapted from the WordPress post_categories_meta_box() in /wp-admin/includes/meta-boxes.php. * * @since 2.20 * * @param string The taxonomy name, from $_POST['action'] * * @return void Sends JSON response with updated HTML for the checklist */ private static function _mla_ajax_add_flat_term($key) { $taxonomy = get_taxonomy($key); check_ajax_referer($_POST['action'], '_ajax_nonce-add-' . $key, true); if (!current_user_can($taxonomy->cap->edit_terms)) { wp_die(-1); } $new_names = explode(',', $_POST['new' . $key]); $new_terms_markup = ''; foreach ($new_names as $name) { if ('' === sanitize_title($name)) { continue; } if (!($id = term_exists($name, $key))) { $id = wp_insert_term($name, $key); } if (is_wp_error($id)) { continue; } if (is_array($id)) { $id = absint($id['term_id']); } else { continue; } $term = get_term($id, $key); $name = $term->name; $new_terms_markup .= "<li id='{$key}-{$id}'><label class='selectit'><input value='{$name}' type='checkbox' name='tax_input[{$key}][]' id='in-{$key}-{$id}' checked='checked' />{$name}</label></li>\n"; } // foreach new_name $input_new_parent_name = "new{$key}_parent"; $supplemental = "<input type='hidden' name='{$input_new_parent_name}' id='{$input_new_parent_name}' value='-1' />"; $add = array('what' => $key, 'id' => $id, 'data' => $new_terms_markup, 'position' => -1, 'supplemental' => array('newcat_parent' => $supplemental)); $x = new WP_Ajax_Response($add); $x->send(); }
function build_genre_taxonomies() { $parent_term = term_exists('genres', 'genres'); // array is returned if taxonomy is given $parent_term_id = $parent_term['term_id']; // get numeric term id wp_insert_term('Science fiction', 'genres', array('description' => '', 'slug' => 'scifi', 'parent' => $parent_term_id)); wp_insert_term('Satire', 'genres', array('description' => '', 'slug' => 'satire', 'parent' => $parent_term_id)); wp_insert_term('Drama', 'genres', array('description' => '', 'slug' => 'drama', 'parent' => $parent_term_id)); wp_insert_term('Romance', 'genres', array('description' => '', 'slug' => 'romance', 'parent' => $parent_term_id)); wp_insert_term('Mystery', 'genres', array('description' => '', 'slug' => 'mystery', 'parent' => $parent_term_id)); wp_insert_term('Horror', 'genres', array('description' => '', 'slug' => 'horror', 'parent' => $parent_term_id)); wp_insert_term('Self help', 'genres', array('description' => '', 'slug' => 'self-help', 'parent' => $parent_term_id)); wp_insert_term('Guide', 'genres', array('description' => '', 'slug' => 'guide', 'parent' => $parent_term_id)); wp_insert_term('Travel', 'genres', array('description' => '', 'slug' => 'travel', 'parent' => $parent_term_id)); wp_insert_term('Children', 'genres', array('description' => '', 'slug' => 'children', 'parent' => $parent_term_id)); wp_insert_term('Religious', 'genres', array('description' => '', 'slug' => 'religious', 'parent' => $parent_term_id)); wp_insert_term('Science', 'genres', array('description' => '', 'slug' => 'science', 'parent' => $parent_term_id)); wp_insert_term('History', 'genres', array('description' => '', 'slug' => 'history', 'parent' => $parent_term_id)); wp_insert_term('Anthologies', 'genres', array('description' => '', 'slug' => 'anthologies', 'parent' => $parent_term_id)); wp_insert_term('Poetry', 'genres', array('description' => '', 'slug' => 'poetry', 'parent' => $parent_term_id)); wp_insert_term('Encyclopedia', 'genres', array('description' => '', 'slug' => 'encyclopedia', 'parent' => $parent_term_id)); wp_insert_term('Dictionary', 'genres', array('description' => '', 'slug' => 'dictionary', 'parent' => $parent_term_id)); wp_insert_term('Comic', 'genres', array('description' => '', 'slug' => 'comic', 'parent' => $parent_term_id)); wp_insert_term('Art', 'genres', array('description' => '', 'slug' => 'art', 'parent' => $parent_term_id)); wp_insert_term('Cookbook', 'genres', array('description' => '', 'slug' => 'cookbook', 'parent' => $parent_term_id)); wp_insert_term('Diary', 'genres', array('description' => '', 'slug' => 'diary', 'parent' => $parent_term_id)); wp_insert_term('Journal', 'genres', array('description' => '', 'slug' => 'journal', 'parent' => $parent_term_id)); wp_insert_term('Prayer', 'genres', array('description' => '', 'slug' => 'prayer', 'parent' => $parent_term_id)); wp_insert_term('Series', 'genres', array('description' => '', 'slug' => 'series', 'parent' => $parent_term_id)); wp_insert_term('Trilogy', 'genres', array('description' => '', 'slug' => 'trilogy', 'parent' => $parent_term_id)); wp_insert_term('Biography', 'genres', array('description' => '', 'slug' => 'biography', 'parent' => $parent_term_id)); wp_insert_term('Autobiography', 'genres', array('description' => '', 'slug' => 'autobiography', 'parent' => $parent_term_id)); wp_insert_term('Fantasy', 'genres', array('description' => '', 'slug' => 'Fantasy', 'parent' => $parent_term_id)); }
function dt_geodir_default_taxonomies($post_type, $categories, $folder_name) { global $wpdb, $dummy_image_path; $cat_count = count($categories); for ($i = 0; $i < $cat_count; $i++) { $parent_catid = 0; if (is_array($categories[$i])) { $cat_name_arr = $categories[$i]; $count_cat_name_arr = count($cat_name_arr); for ($j = 0; $j < $count_cat_name_arr; $j++) { $catname = $cat_name_arr[$j]; if (!term_exists($catname, $post_type . 'category')) { $last_catid = wp_insert_term($catname, $post_type . 'category', $args = array('parent' => $parent_catid)); if ($j == 0) { $parent_catid = $last_catid; } dt_geodir_insert_taxonomy($post_type, $catname, $folder_name, $last_catid); } } } else { $catname = $categories[$i]; if (!term_exists($catname, $post_type . 'category')) { $last_catid = wp_insert_term($catname, $post_type . 'category'); dt_geodir_insert_taxonomy($post_type, $catname, $folder_name, $last_catid); } } } }
function aitGridPortfolioTaxonomies() { register_taxonomy('ait-grid-portfolio-category', array('ait-grid-portfolio'), array('hierarchical' => true, 'labels' => array('name' => _x('Kuvakansioiden kategoriat', 'taxonomy general name', 'ait'), 'singular_name' => _x('Kategoria', 'taxonomy singular name', 'ait'), 'search_items' => __('Etsi kategoriaa', 'ait'), 'all_items' => __('Kaikki kategoriat', 'ait'), 'parent_item' => __('Yläkategoria', 'ait'), 'parent_item_colon' => __('Yläkategoria:', 'ait'), 'edit_item' => __('Muokkaa kategoriaa', 'ait'), 'update_item' => __('Päivitä kategoria', 'ait'), 'add_new_item' => __('Lisää uusi kategoria', 'ait'), 'new_item_name' => __('Uuden kategorian nimi', 'ait')), 'show_ui' => true, 'query_var' => true, 'rewrite' => array('slug' => 'ait-grid-portfolio-category'))); // add uncategorized term if (!term_exists('Uncategorized Grid Portfolios', 'ait-grid-portfolio-category')) { wp_insert_term('Uncategorized Grid Portfolios', 'ait-grid-portfolio-category'); } }
function insert_dynamic_taxonomy_term($new_term, $taxonomy) { $term = term_exists($new_term, $taxonomy); if (FALSE !== $term && NULL !== $term) { return; } wp_insert_term($new_term, $taxonomy); }
function aitTestimonialTaxonomies() { register_taxonomy('ait-testimonial-category', array('ait-testimonial'), array('labels' => array('name' => _x('Testimonial Categories', 'taxonomy general name', 'ait'), 'singular_name' => _x('Testimonial Category', 'taxonomy singular name', 'ait'), 'search_items' => __('Search Category', 'ait'), 'all_items' => __('All Gategories', 'ait'), 'parent_item' => __('Parent Category', 'ait'), 'parent_item_colon' => __('Parent Category:', 'ait'), 'edit_item' => __('Edit Category', 'ait'), 'update_item' => __('Update Gategory', 'ait'), 'add_new_item' => __('Add New Category', 'ait'), 'new_item_name' => __('New Category Name', 'ait')), 'hierarchical' => true, 'show_ui' => true, 'query_var' => true, 'rewrite' => true)); // add uncategorized term if (!term_exists('Uncategorized Testimonials', 'ait-testimonial-category')) { wp_insert_term('Uncategorized Testimonials', 'ait-testimonial-category'); } }
function aitTeamTaxonomies() { register_taxonomy('ait-team-category', array('ait-team'), array('hierarchical' => true, 'labels' => array('name' => _x('Teams', 'taxonomy general name', 'ait'), 'singular_name' => _x('Team', 'taxonomy singular name', 'ait'), 'search_items' => __('Search Team', 'ait'), 'all_items' => __('All Teams', 'ait'), 'parent_item' => __('Parent Team', 'ait'), 'parent_item_colon' => __('Parent Team:', 'ait'), 'edit_item' => __('Edit Team', 'ait'), 'update_item' => __('Update Team', 'ait'), 'add_new_item' => __('Add New Team', 'ait'), 'new_item_name' => __('New Team Name', 'ait')), 'show_ui' => true, 'query_var' => true, 'rewrite' => array('slug' => 'ait-team-category'))); // add uncategorized term if (!term_exists('Uncategorized Teams', 'ait-team-category')) { wp_insert_term('Uncategorized Teams', 'ait-team-category'); } }
function aitGridPortfolioTaxonomies() { register_taxonomy('ait-grid-portfolio-category', array('ait-grid-portfolio'), array('hierarchical' => true, 'labels' => array('name' => _x('Grid Portfolio Categories', 'taxonomy general name', 'ait'), 'singular_name' => _x('Category', 'taxonomy singular name', 'ait'), 'search_items' => __('Search Category', 'ait'), 'all_items' => __('All Gategories', 'ait'), 'parent_item' => __('Parent Category', 'ait'), 'parent_item_colon' => __('Parent Category:', 'ait'), 'edit_item' => __('Edit Category', 'ait'), 'update_item' => __('Update Gategory', 'ait'), 'add_new_item' => __('Add New Category', 'ait'), 'new_item_name' => __('New Category Name', 'ait')), 'show_ui' => true, 'query_var' => true, 'rewrite' => array('slug' => 'ait-grid-portfolio-category'))); // add uncategorized term if (!term_exists('Uncategorized Grid Portfolios', 'ait-grid-portfolio-category')) { wp_insert_term('Uncategorized Grid Portfolios', 'ait-grid-portfolio-category'); } }
function pasw_generate_dest_terms() { $destinatari = array('Docenti', 'Alunni', 'Genitori', 'Personale ATA'); for ($i = 0; $i < 4; $i++) { if (!term_exists($destinatari[$i], 'paswdestinatari')) { wp_insert_term($destinatari[$i], 'paswdestinatari'); } } }
/** * Sets up Default Terms for Kind Taxonomy. */ public static function kind_defaultterms() { $terms = self::get_strings(); foreach ($terms as $key => $value) { if (!term_exists($key, 'kind')) { wp_insert_term($key, 'kind', array('description' => $value, 'slug' => $key)); } } }
function codex_custom_init() { $labels = array('name' => _x('Featured post type', 'region'), 'singular_name' => _x('Featured post type', 'region'), 'search_items' => __('Search featured post type'), 'popular_items' => __('Popular featured post type'), 'all_items' => __('All featured post types'), 'parent_item' => null, 'parent_item_colon' => null, 'edit_item' => __('Edit featured post type'), 'update_item' => __('Update featured post type'), 'add_new_item' => __('Add featured post type'), 'new_item_name' => __('New featured post type name'), 'separate_items_with_commas' => __('Separete featured post types with comas'), 'add_or_remove_items' => __('Add or remove featured post types'), 'choose_from_most_used' => __('Choose from most used featured post types'), 'not_found' => __('Featured post type not found'), 'menu_name' => __('Featured post type')); register_taxonomy('featured_post_type', 'post', array('label' => __('Featured post type'), 'rewrite' => array('slug' => 'featured_post_type'), 'hierarchical' => true, 'labels' => $labels)); $term = term_exists('featured_post', 'featured_post_type'); if ($term == 0 || $term == null) { wp_insert_term('Featured post', 'featured_post_type', array('slug' => 'featured_post', 'description' => 'Marks the fetured post')); } }
function ProjectTheme_state_activate() { $parent = term_exists('Massachusetts', 'project_location'); echo '123123123' . $parent; var_dump($parent); $args = array('alias_of' => 'boston', 'description' => 'Boston', 'parent' => 0, 'slug' => 'boston'); wp_insert_term($term, $taxonomy, $args); register_taxonomy(); }
function wpcf7_flamingo_init() { if (!class_exists('Flamingo_Inbound_Message')) { return; } if (!term_exists('contact-form-7', Flamingo_Inbound_Message::channel_taxonomy)) { wp_insert_term(__('Contact Form 7', 'wpcf7'), Flamingo_Inbound_Message::channel_taxonomy, array('slug' => 'contact-form-7')); } }
public function registerMenu() { global $themename; $menuname = $this->menuname; register_nav_menus(array($menuname => $menuname)); if (!term_exists($menuname, 'nav_menu')) { $menu = wp_insert_term($menuname, 'nav_menu', array('slug' => $menuname)); } }