/**
*
* 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);
}
}
/**
* 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 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 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');
}
}
开发者ID:redelivre,项目名称:fluxo,代码行数:30,代码来源:taxs.php
示例14: woocommerce_init
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;
}
请发表评论