/**
 * Remove add-ons if _any product_ in the cart is in a given category
 * Example: remove add-ons if any product is in the "Gift box" category
 */
function sv_wc_checkout_add_ons_remove_add_ons_for_giftboxes()
{
    // bail if Checkout Add-ons isn't active
    if (!function_exists('wc_checkout_add_ons')) {
        return;
    }
    // set a flag
    $cat_check = false;
    // check each cart item for our category
    foreach (WC()->cart->get_cart() as $cart_item_key => $cart_item) {
        $product = $cart_item['data'];
        $product_in_cat = false;
        // replace 'gift_box' with your category's slug
        if (has_term('gift_box', 'product_cat', $product->id)) {
            // flag the cart as containing this category, we only need one "true" to break
            $cat_check = true;
            break;
        }
    }
    // get the position of checkout add-ons so we can remove them properly
    $position = get_option('wc_checkout_add_ons_position', 'woocommerce_checkout_after_customer_details');
    // if a product in the cart is in our category, remove the add-ons
    if ($position && $cat_check) {
        remove_action($position, array(wc_checkout_add_ons()->get_frontend_instance(), 'render_add_ons'), 20);
    }
}
function add_post_to_cat()
{
    // Get the Post ID
    if (isset($_POST['post_id']) && !empty($_POST['post_id'])) {
        $post_id = esc_html($_POST['post_id']);
    } else {
        echo json_encode(array('success' => false, 'reason' => 'No Post ID.'));
        exit;
    }
    // Get the Category
    if (isset($_POST['cat_id']) && !empty($_POST['cat_id'])) {
        $cat_id = esc_html($_POST['cat_id']);
    } else {
        echo json_encode(array('success' => false, 'reason' => 'No Cat ID.'));
        exit;
    }
    // Check if Post is already in this category
    if (has_term($cat_id, 'bookmark-category', $post_id)) {
        echo json_encode(array('success' => true, 'reason' => 'duplicate'));
        exit;
    }
    // Add Post to Bookmark Category
    $did_add_cat = wp_set_post_terms($post_id, $cat_id, 'bookmark-category', true);
    if ($did_add_cat) {
        echo json_encode(array('success' => true, 'reason' => 'inserted'));
    } else {
        echo json_encode(array('success' => false, 'reason' => "Couldn't add cat."));
    }
    exit;
}
 function add_custom_field_to_comment_form()
 {
     //Check case single
     if (!is_singular('cases')) {
         return;
     }
     if (has_term('', 'results')) {
         ?>
       <div class="toggle_case_result close_case">
           <input type="checkbox" id="openCase" name="case_reset_result_cp" value="openCase">
           <label for="openCase">Возобновить дело</label>
       </div>
       <?php 
     } else {
         ?>
         <div class="toggle_case_result open_case">
             <input type="checkbox" id="close_case_cp" name="close_case_comment_cp" value="1">
             <label for="close_case_cp">Закрыть дело</label>
             <div id="result_select_container"><span>Укажите результат:</span>
                 <?php 
         wp_dropdown_categories('taxonomy=results&hide_empty=0&name=case_result_select&id=result_select&hide_if_empty=true');
         ?>
             </div>
         </div>
       <?php 
     }
 }
示例#4
0
function add_blog_automatically($post_ID)
{
    global $wpdb;
    if (!has_term('', 'blog_categoria', $post_ID)) {
        $cat = 'blog';
        wp_set_object_terms($post_ID, $cat, 'blog_categoria');
    }
}
function register_txn_trail_story()
{
    $labels = array('name' => _x('Trail Story Category', 'trail-story-category'), 'singular_name' => _x('Trail Story Category', 'trail-story-category'), 'search_items' => _x('Search Trail Story Categories', 'trail-story-category'), 'popular_items' => _x('Popular Trail Story Categories', 'trail-story-category'), 'all_items' => _x('All Trail Story Categories', 'trail-story-category'), 'parent_item' => _x('Parent Trail Story Category', 'trail-story-category'), 'parent_item_colon' => _x('Parent Trail Story Category:', 'trail-story-category'), 'edit_item' => _x('Edit Trail Story Category', 'trail-story-category'), 'update_item' => _x('Update Trail Story Category', 'trail-story-category'), 'add_new_item' => _x('Add New', 'trail-story-category'), 'new_item_name' => _x('New Trail Story Category', 'trail-story-category'), 'separate_items_with_commas' => _x('Separate Trail Story Categories with commas', 'trail-story-category'), 'add_or_remove_items' => _x('Add or remove Trail Story Categories', 'trail-story-category'), 'choose_from_most_used' => _x('Choose from the most used Trail Story Category', 'trail-story-category'), 'menu_name' => _x('Categories', 'trail-story-category'));
    $args = array('labels' => $labels, 'public' => true, 'show_in_nav_menus' => true, 'show_ui' => true, 'show_in_menu' => true, 'show_tagcloud' => true, 'show_admin_column' => true, 'hierarchical' => true, 'rewrite' => array('slug' => 'story-category'), 'query_var' => true);
    register_taxonomy('trail-story-category', array('trail-story'), $args);
    if (!has_term('iata-stories', 'trail-story-category')) {
        wp_insert_term('Trail Stories', 'trail-story-category', array('User Submitted Trail Stories', 'iata-stories'));
    }
}
function add_wikipedia_category_automatically($post_ID)
{
    global $wpdb;
    if (!has_term('', 'category', $post_ID)) {
        $category = get_term_by('slug', 'cat-00-02', 'category');
        $cat = array($category->term_id);
        wp_set_object_terms($post_ID, $cat, 'category');
    }
}
function woo_custom_cart_button_text()
{
    global $product;
    if (has_term('credit', 'product_cat', $product->ID)) {
        return __('Buy Now', 'woocommerce');
    }
    /** default */
    return __('Add to cart', 'woocommerce');
}
示例#8
0
 protected function getTourDestination($post)
 {
     $toursRegions = array('N. America', 'Latin America', 'Europe', 'Asia', 'Africa', 'Oceania');
     if (has_term($toursRegions, 'destinations')) {
         $getTermsArgs = array('fields' => 'names');
         $tourPostTerms = wp_get_post_terms(get_the_id(), 'destinations', $getTermsArgs);
         $result = array_values(array_intersect($toursRegions, $tourPostTerms));
         return $result[0];
     }
 }
/**
 * Plugin Name: AffiliateWP - Disable Referrals Per Category In Easy Digital Downloads
 * Plugin URI: http://affiliatewp.com
 * Description: Disable referrals on specific product categories in Easy Digital Downloads
 * Author: Andrew Munro
 * Author URI: http://affiliatewp.com
 * Version: 1.0
 */
function affwp_drpc_edd_disable_referrals_per_category($referral_amount, $affiliate_id, $amount, $reference, $product_id)
{
    // Array of categories to disable referrals for. Separate by a comma and use either the term name, term_id, or slug
    $disabled_categories = array('category-one', 5);
    // Disable referral if product exists in array of categories
    if (has_term($disabled_categories, 'download_category', $product_id)) {
        $referral_amount = 0.0;
    }
    return $referral_amount;
}
 public function createPostVar()
 {
     $posts = get_posts($this->args);
     foreach ($posts as $post) {
         $post_content = (array) $post->post_content;
         if (has_term('Site', 'notice_type', $post)) {
             $this->content = array_merge((array) $this->content, (array) $post_content);
         }
     }
 }
function wpt_filter_a_term($continue, $args)
{
    $id = $args['id'];
    // 1,2,3 are term IDs that should not be Tweeted.
    $terms = array(1, 2, 3);
    if (has_term($terms, 'post_tags', $id)) {
        return false;
    }
    return $continue;
}
/**
 * Check if a post has any of the given formats, or any format.
 *
 * @since 3.1.0
 *
 * @param string|array    $format Optional. The format or formats to check.
 * @param object|int|null $post   Optional. The post to check. If not supplied, defaults to the current post if used in the loop.
 * @return bool True if the post has any of the given formats (or any format, if no format specified), false otherwise.
 */
function has_post_format($format = array(), $post = null)
{
    $prefixed = array();
    if ($format) {
        foreach ((array) $format as $single) {
            $prefixed[] = 'post-format-' . sanitize_key($single);
        }
    }
    return has_term($prefixed, 'post_format', $post);
}
function ubik_recordpress_meta($meta)
{
    global $post;
    if (has_term('', 'artists')) {
        $meta .= ubik_terms_popular_list($post->ID, 'artists', 'Artists: ', ', ', '. ');
    }
    if (has_term('', 'styles')) {
        $meta .= ubik_terms_popular_list($post->ID, 'styles', 'Styles: ', ', ', '. ');
    }
    return $meta;
}
示例#14
0
/**
 * Check if a post has a particular format
 *
 * @since 3.1.0
 *
 * @uses has_term()
 *
 * @param string|array $format The format or formats to check.
 * @param object|int   $post   The post to check. If not supplied, defaults to the current post if used in the loop.
 * @return bool True if the post has the format, false otherwise.
 */
function has_post_format($format, $post = null)
{
    if (!is_array($format)) {
        $format = array($format);
    }
    $prefixed = array();
    foreach ($format as $single) {
        $prefixed[] = 'post-format-' . sanitize_key($single);
    }
    return has_term($prefixed, 'post_format', $post);
}
示例#15
0
function reg_assembly_cat()
{
    $labels = array('name' => _x('Assembly Categories', 'assembly-category'), 'singular_name' => _x('Assembly Category', 'assembly-category'), 'search_items' => _x('Search Assembly Category', 'assembly-category'), 'popular_items' => _x('Popular Assembly Category', 'assembly-category'), 'all_items' => _x('All Assembly Category', 'assembly-category'), 'parent_item' => _x('Parent Assembly Category', 'assembly-category'), 'parent_item_colon' => _x('Parent Assembly Category:', 'assembly-category'), 'edit_item' => _x('Edit Assembly Category', 'assembly-category'), 'update_item' => _x('Update Assembly Category', 'assembly-category'), 'add_new_item' => _x('Add New Assembly Category', 'assembly-category'), 'new_item_name' => _x('New Assembly Category', 'assembly-category'), 'separate_items_with_commas' => _x('Separate Assembly Category with commas', 'assembly-category'), 'add_or_remove_items' => _x('Add or remove Assembly Category', 'assembly-category'), 'choose_from_most_used' => _x('Choose from the most used Assembly Category', 'assembly-category'), 'menu_name' => _x('Categories', 'assembly-category'));
    $args = array('labels' => $labels, 'public' => true, 'show_in_menu' => true, 'show_in_nav_menus' => true, 'show_ui' => true, 'show_tagcloud' => true, 'show_admin_column' => true, 'sort' => true, 'hierarchical' => true, 'rewrite' => true, 'query_var' => true);
    register_taxonomy('assembly-category', array('assembly'), $args);
    if (!has_term('assembly', 'assembly-category')) {
        wp_insert_term('Assembly', 'assembly-category', array('Assembly', 'assembly'));
    }
    if (!has_term('sub-assembly', 'assembly-category')) {
        wp_insert_term('Sub iAssembly', 'assembly-category', array('Sub Assembly', 'sub-assembly'));
    }
}
示例#16
0
function forbid_credits_page()
{
    global $post;
    $terms = wp_get_post_terms($post->ID, 'product_cat');
    $categories = array();
    foreach ($terms as $term) {
        $categories[] = $term->slug;
    }
    if (is_product_category('credit') || is_product() && has_term('credit', 'product_cat')) {
        header('Location: ' . get_permalink(woocommerce_get_page_id('shop')) . '');
    }
}
示例#17
0
 function x_integrity_entry_meta()
 {
     $author = sprintf('<span><i class="x-icon-pencil"></i> %s</span>', get_the_author());
     $date = sprintf('<span><time class="entry-date" datetime="%1$s"><i class="x-icon-calendar"></i> %2$s</time></span>', esc_attr(get_the_date('c')), esc_html(get_the_date()));
     if (get_post_type() == 'x-portfolio') {
         if (has_term('', 'portfolio-category', NULL)) {
             $categories = get_the_terms(get_the_ID(), 'portfolio-category');
             $separator = ', ';
             $categories_output = '';
             foreach ($categories as $category) {
                 $categories_output .= '<a href="' . get_term_link($category->slug, 'portfolio-category') . '" title="' . esc_attr(sprintf(__("View all posts in: &ldquo;%s&rdquo;", '__x__'), $category->name)) . '"><i class="x-icon-bookmark"></i> ' . $category->name . '</a>' . $separator;
             }
             $categories_list = sprintf('<span>%s</span>', trim($categories_output, $separator));
         } else {
             $categories_list = '';
         }
     } else {
         $categories = get_the_category();
         $separator = ', ';
         $categories_output = '';
         foreach ($categories as $category) {
             $categories_output .= '<a href="' . get_category_link($category->term_id) . '" title="' . esc_attr(sprintf(__("View all posts in: &ldquo;%s&rdquo;", '__x__'), $category->name)) . '"><i class="x-icon-bookmark"></i> ' . $category->name . '</a>' . $separator;
         }
         $categories_list = sprintf('<span>%s</span>', trim($categories_output, $separator));
     }
     if (comments_open()) {
         $title = get_the_title();
         $link = get_comments_link();
         $number = get_comments_number();
         if ($number == 0) {
             $comments = sprintf('<span><a href="%1$s" title="%2$s" class="meta-comments"><i class="x-icon-comments"></i> %3$s</a></span>', esc_url($link), esc_attr(sprintf(__('Leave a comment on: &ldquo;%s&rdquo;', '__x__'), $title)), __('Leave a Comment', '__x__'));
         } else {
             if ($number == 1) {
                 $comments = sprintf('<span><a href="%1$s" title="%2$s" class="meta-comments"><i class="x-icon-comments"></i> %3$s</a></span>', esc_url($link), esc_attr(sprintf(__('Leave a comment on: &ldquo;%s&rdquo;', '__x__'), $title)), $number . ' ' . __('Comment', '__x__'));
             } else {
                 $comments = sprintf('<span><a href="%1$s" title="%2$s" class="meta-comments"><i class="x-icon-comments"></i> %3$s</a></span>', esc_url($link), esc_attr(sprintf(__('Leave a comment on: &ldquo;%s&rdquo;', '__x__'), $title)), $number . ' ' . __('Comments', '__x__'));
             }
         }
     } else {
         $comments = '';
     }
     $post_type = get_post_type();
     $post_type_post = $post_type == 'post';
     $post_type_portfolio = $post_type == 'x-portfolio';
     $no_post_meta = get_theme_mod('x_blog_enable_post_meta') == 0;
     $no_portfolio_meta = get_theme_mod('x_portfolio_enable_post_meta') == 0;
     if ($post_type_post && $no_post_meta || $post_type_portfolio && $no_portfolio_meta) {
         return;
     } else {
         printf('<p class="p-meta">%1$s%2$s%3$s%4$s</p>', $author, $date, $categories_list, $comments);
     }
 }
示例#18
0
function theburgh_specials_template($template)
{
    $new_template = '';
    if (is_single()) {
        global $post;
        if (has_term('longform', 'category', $post)) {
            $new_template = locate_template(array('single-special.php'));
        }
    }
    if ('' != $new_template) {
        return $new_template;
    }
    return $template;
}
示例#19
0
function wpfc_sermon_update()
{
    $sermon_settings = get_option('wpfc_options');
    $sermon_version = $sermon_settings['version'];
    $args = array('post_type' => 'wpfc_sermon', 'posts_per_page' => '-0');
    $wpfc_sermon_update_query = new WP_Query($args);
    while ($wpfc_sermon_update_query->have_posts()) {
        $wpfc_sermon_update_query->the_post();
        global $post;
        if (empty($sermon_version)) {
            $service_type = get_post_meta($post->ID, 'service_type', 'true');
            if (!has_term('wpfc_service_type')) {
                wp_set_object_terms($post->ID, $service_type, 'wpfc_service_type');
            }
            $current = get_post_meta($post->ID, 'sermon_audio', 'true');
            $currentsize = get_post_meta($post->ID, '_wpfc_sermon_size', 'true');
            // only grab if different (getting data from dropbox can be a bit slow)
            if (empty($currentsize)) {
                // get file data
                $size = wpfc_get_filesize($current);
                $duration = wpfc_mp3_duration($current);
                // store in hidden custom fields
                update_post_meta($post->ID, '_wpfc_sermon_duration', $duration);
                update_post_meta($post->ID, '_wpfc_sermon_size', $size);
            }
            //Alter the options array appropriately
            $sermon_settings['version'] = wpfc_plugin_get_version();
            //Update entire array
            update_option('wpfc_options', $sermon_settings);
        }
        if ($sermon_version < '1.8') {
            $current = get_post_meta($post->ID, 'sermon_audio', 'true');
            $currentsize = get_post_meta($post->ID, '_wpfc_sermon_size', 'true');
            // only grab if different (getting data from dropbox can be a bit slow)
            if (empty($currentsize)) {
                // get file data
                $size = wpfc_get_filesize($current);
                $duration = wpfc_mp3_duration($current);
                // store in hidden custom fields
                update_post_meta($post->ID, '_wpfc_sermon_duration', $duration);
                update_post_meta($post->ID, '_wpfc_sermon_size', $size);
            }
            //Alter the options array appropriately
            $sermon_settings['version'] = wpfc_plugin_get_version();
            //Update entire array
            update_option('wpfc_options', $sermon_settings);
        }
    }
    wp_reset_query();
}
    function add_view_cover_to_action_box()
    {
        if (is_singular('cases') and has_term($this->case_category, 'functions')) {
            $url = add_query_arg(array('view' => $this->url_key));
            ?>
        <li>
            <a href="<?php 
            echo $url;
            ?>
" target="_blank">Печать исходящего письма</a>
        </li>
        <?php 
        }
    }
function wpuw_custom_woocommerce_auto_complete_order($order_id)
{
    if (!$order_id) {
        return;
    }
    $order = new WC_Order($order_id);
    if (count($order->get_items()) > 0) {
        foreach ($order->get_items() as $item) {
            if (has_term('credit', 'product_cat', $item['product_id'])) {
                $order->update_status('completed');
            }
        }
    }
}
示例#22
0
/**
 * Shows the page alerts (if any).
 *
 * @since 1.3.0
 */
function show_alerts()
{
    global $post;
    if (($alerts = get_option('jc_active_alerts', false)) === false) {
        return;
    }
    $active_alerts = array();
    // Everywhere
    if (!empty($alerts['everywhere'])) {
        $active_alerts = array_merge($active_alerts, array_keys($alerts['everywhere']));
    }
    // Individual pages
    if (isset($post) && isset($alerts['posts'][$post->ID])) {
        $active_alerts = array_merge($active_alerts, array_keys($alerts['posts'][$post->ID]));
    }
    // Taxonomies
    if (!empty($alerts['taxonomies']) && isset($post)) {
        foreach ($alerts['taxonomies'] as $taxonomy => $alert_IDs) {
            $taxonomy_parts = explode(':', $taxonomy);
            $taxonomy = $taxonomy_parts[0];
            $term_ID = $taxonomy_parts[1];
            if (has_term($term_ID, $taxonomy)) {
                $active_alerts = array_merge($active_alerts, array_keys($alert_IDs));
            }
        }
    }
    // Post Types
    if (!empty($alerts['post_types']) && ($post_type = get_post_type())) {
        if (isset($alerts['post_types'][$post_type])) {
            $active_alerts = array_merge($active_alerts, array_keys($alerts['post_types'][$post_type]));
        }
    }
    // Show alerts by welcome slug
    if (isset($_GET['jc-alert-id'])) {
        if ($alert = get_post($_GET['jc-alert-id'])) {
            $active_alerts = array_merge($active_alerts, array($alert->ID));
        }
    }
    // Filter any duplicates
    $active_alerts = array_unique($active_alerts);
    $active_alerts = apply_filters('jc_alerts', $active_alerts);
    // Show any matching alerts
    if (!empty($active_alerts)) {
        foreach ($active_alerts as $alert) {
            jc_alert($alert);
        }
    }
}
        public function wbm_footer()
        {
            global $post;
            if (WBM_Frontend_Product::wbm_enabled($post->ID)) {
                $productId = $post->ID;
                $secondary_attr_id = get_post_meta($productId, '_wbm_sub_attribute', true);
                $secondary_variations = get_terms($secondary_attr_id);
                ?>
                <div id="wbm_hidden_container" class="wbm_hidden">
                <div id="wbm_main_attr">
                    <input type="hidden" value="" class="wbm_title">
                    <input type="hidden" value="" class="wbm_term">
                </div>
                <?php 
                if (isset($secondary_variations) && !empty($secondary_variations)) {
                    foreach ($secondary_variations as $variation) {
                        if (has_term(absint($variation->term_id), $secondary_attr_id, $productId)) {
                            ?>
                        <div id="wbm_attr_<?php 
                            echo $variation->taxonomy;
                            ?>
_<?php 
                            echo $variation->term_id;
                            ?>
" class="wbm_attr_container">
                            <div class="wbm_secondary_container">
                                <input type="hidden" value="" class="wbm_title">
                                <input type="hidden" value="" class="wbm_term">
                                <input type="hidden" value="no" class="wbm_check">
                                <input type="hidden" value="" class="wbm_price">
                            </div>
                            <div class="wbm_selectbox_container">

                            </div>
                            <div class="wbm_date_container">

                            </div>
                        </div>
                <?php 
                        }
                    }
                }
                ?>
                </div>
            <?php 
            }
        }
示例#24
0
function hocwp_the_terms($args = array())
{
    $terms = hocwp_get_value_by_key($args, 'terms');
    $before = hocwp_get_value_by_key($args, 'before');
    $sep = hocwp_get_value_by_key($args, 'separator', ', ');
    $after = hocwp_get_value_by_key($args, 'after');
    if (hocwp_array_has_value($terms)) {
        echo $before;
        $html = '';
        foreach ($terms as $term) {
            $html .= hocwp_get_term_link($term) . $sep;
        }
        $html = trim($html, $sep);
        echo $html;
        echo $after;
    } else {
        $post_id = hocwp_get_value_by_key($args, 'post_id', get_the_ID());
        $taxonomy = hocwp_get_value_by_key($args, 'taxonomy');
        $taxonomies = hocwp_get_value_by_key($args, 'taxonomies');
        if (!is_array($taxonomies)) {
            $taxonomies = array();
        }
        if (!empty($taxonomy) && !in_array($taxonomy, $taxonomies)) {
            $taxonomies[] = $taxonomy;
        }
        $has_term = false;
        foreach ($taxonomies as $taxonomy) {
            if (has_term('', $taxonomy, $post_id)) {
                $has_term = true;
                break;
            }
        }
        if (!$has_term) {
            return;
        }
        echo $before;
        ob_start();
        foreach ($taxonomies as $taxonomy) {
            the_terms($post_id, $taxonomy, '', $sep, '');
            echo $sep;
        }
        $html = ob_get_clean();
        $html = trim($html, $sep);
        echo $html;
        echo $after;
    }
}
示例#25
0
文件: custom.php 项目: 30mps/data.gov
/**
 * Redirect topic introduction pages to their topic landing page
 **/
function redirect_intro()
{
    if (!isset($post)) {
        return;
    }
    if (is_page() or is_single()) {
        $post =& get_post($post->ID);
        $intro_page = has_term('browse', 'featured', $post);
        if ($intro_page) {
            $categories = get_the_category($post->ID);
            $category_slug = $categories[0]->slug;
            $redirect = home_url() . '/' . $category_slug;
            wp_redirect($redirect, 301);
            exit;
        }
    }
}
示例#26
0
function roots_custom_nav_menu_css_class($classes, $item)
{
    $menu_locations = get_nav_menu_locations();
    $slug = sanitize_title($item->title);
    $classes = preg_replace('/(current(-menu-|[-_]page[-_])(item|parent|ancestor))/', 'active', $classes);
    $classes = preg_replace('/^((menu|page)[-_\\w+]+)+/', '', $classes);
    if ($item->menu_item_parent == 0 && has_term($menu_locations['primary_navigation'], 'nav_menu', $item)) {
        $classes[] = 'col-sm-2 col-xs-6 hidden-xs nopadding scrollto menu-item menu-' . $slug;
    }
    if ($item->menu_item_parent >= 0 && has_term($menu_locations['primary_navigation'], 'nav_menu', $item)) {
        $classes[] = 'scrollto menu-item menu-' . $slug;
    }
    $classes = array_unique($classes);
    return array_filter($classes, function ($element) {
        $element = trim($element);
        return !empty($element);
    });
}
 /**
  * Class constructor
  * 
  * @since 1.0.1
  */
 public function __construct($post_type = '', $labels = '', $args = '', $has_taxonomy = True, $taxonomies = array(), $meta_boxes = array())
 {
     $this->np_error = new WP_Error();
     // Check if the MUST values are provided
     if ($post_type == '' || $labels == '' || $args == '') {
         $this->np_error->add('cpt_error', '$post_type, $labels and $args all needs to be defined.');
     } else {
         $this->np_error->remove('cpt_error');
     }
     // Setup custom post type
     $labels_default = array('name' => $post_type, 'singular_name' => $post_type, 'menu_name' => $post_type, 'name_admin_bar' => $post_type, 'add_new' => 'Add New', 'add_new_item' => 'Add New ' . $post_type, 'new_item' => 'New ' . $post_type, 'edit_item' => 'Edit ' . $post_type, 'view_item' => 'View ' . $post_type, 'all_items' => 'All ' . $post_type, 'search_items' => 'Search ' . $post_type, 'parent_item_colon' => 'Parent ' . $post_type . ':', 'not_found' => 'No ' . $post_type . ' found.', 'not_found_in_trash' => 'No ' . $post_type . ' found in Trash.');
     $this->labels = wp_parse_args($labels, $labels_default);
     $args_default = array('labels' => $this->labels, 'description' => 'Description.', 'public' => true, 'publicly_queryable' => true, 'show_ui' => true, 'show_in_menu' => true, 'query_var' => true, 'rewrite' => array('slug' => $post_type), 'capability_type' => 'post', 'has_archive' => true, 'hierarchical' => false, 'menu_position' => 104, 'menu_icon' => 'dashicons-clipboard', 'supports' => array('title', 'editor', 'author', 'thumbnail', 'excerpt', 'comments'));
     $this->args = wp_parse_args($args, $args_default);
     $this->post_type = $post_type;
     /**
      * Adds argument to create itinerary category
      */
     if ($has_taxonomy === True) {
         $tax_domain = 'itinerary-category';
         $tax_labels = array('name' => _x('Itinerary Category', 'itinerary-category'), 'singular_name' => _x('Itinerary Category', 'itinerary-category'), 'search_items' => _x('Search Itinerary Categories', 'itinerary-category'), 'popular_items' => _x('Popular Itinerary Categories', 'itinerary-category'), 'all_items' => _x('All Itinerary Categories', 'itinerary-category'), 'parent_item' => _x('Parent Itinerary Category', 'itinerary-category'), 'parent_item_colon' => _x('Parent Itinerary Category:', 'itinerary-category'), 'edit_item' => _x('Edit Itinerary Category', 'itinerary-category'), 'update_item' => _x('Update Itinerary Category', 'itinerary-category'), 'add_new_item' => _x('Add New', 'itinerary-category'), 'new_item_name' => _x('New Itinerary Category', 'itinerary-category'), 'separate_items_with_commas' => _x('Separate Itinerary Categories with commas', 'itinerary-category'), 'add_or_remove_items' => _x('Add or remove Itinerary Categories', 'itinerary-category'), 'choose_from_most_used' => _x('Choose from the most used Itinerary Category', 'itinerary-category'), 'menu_name' => _x('Categories', 'itinerary-category'));
         $tax_args = array('labels' => $tax_labels, 'public' => true, 'show_in_nav_menus' => true, 'show_ui' => true, 'show_in_menu' => true, 'show_tagcloud' => true, 'show_admin_column' => true, 'hierarchical' => true, 'rewrite' => true, 'query_var' => true);
         register_taxonomy('itinerary-category', array($post_type), $tax_args);
         if (!has_term('iata-trail-itinerary', 'itinerary-category')) {
             wp_insert_term('Itineraries', 'itinerary-category', array('Trail Itinerary Documents', 'iata-trail-itinerary'));
         }
     }
     // Check if there is any taxonomy defined
     if ($taxonomies == '' || !is_array($taxonomies)) {
         $taxonomies = array();
     }
     if (count($taxonomies) > 0) {
         foreach ($taxonomies as $tax => $val) {
             $tax_default = array('hierarchical' => false, 'labels' => array('name' => $tax, 'singular_name' => $tax, 'search_items' => 'Search ' . $tax, 'popular_items' => 'Popular ' . $tax, 'all_items' => 'All ' . $tax, 'parent_item' => null, 'parent_item_colon' => null, 'edit_item' => 'Edit ' . $tax, 'update_item' => 'Update ' . $tax, 'add_new_item' => 'Add New ' . $tax, 'new_item_name' => 'New Taxonomy ' . $tax, 'separate_items_with_commas' => 'Separate ' . $tax . ' with commas', 'add_or_remove_items' => 'Add or remove ' . $tax, 'choose_from_most_used' => 'Choose from the most used ' . $tax, 'not_found' => 'No ' . $tax . ' found.', 'menu_name' => $tax), 'show_ui' => true, 'show_admin_column' => false, 'query_var' => true, 'rewrite' => array('slug' => $tax));
             $this->taxonomies[$tax] = wp_parse_args($val, $tax_default);
         }
     }
     // Check if there is any meta box defined
     if (count($meta_boxes) > 0) {
         $this->meta_boxes = $meta_boxes;
         add_action('add_meta_boxes', array(&$this, 'np_add_meta_box'));
     }
 }
function get_post_search_link()
{
    global $post;
    if ($type === 'event' && has_term('rsvp', 'event_category')) {
        $link = get_permalink(get_page_by_title('Photos')) . '#' . $post->post_name;
    } else {
        if (get_field('document_link')) {
            $link = get_field('document_link') . '" target="_blank';
        } else {
            if ($type === 'person') {
                $departments = wp_get_object_terms($post->ID, 'departments');
                $department = reset($departments);
                $link = get_term_link($department);
            } else {
                $link = get_permalink();
            }
        }
    }
    return $link;
}
示例#29
0
function add_custom_fields()
{
    if (has_term('', 'post_tag')) {
        ?>
        <li>
            <input type="checkbox" id="openCase" name="openCase" value="openCase">
            <label for="openCase">Возобновить дело</label>
        </li>
        <?php 
    } else {
        ?>
        <li>
            <input type="checkbox" id="closeCase" name="closeCase" value="closeCase">
            <label for="closeCase">Закрыть дело</label>
        </li>
        <li style="display: none">
            <div id="result_select_container"><span>Укажите результат:</span>
                <?php 
        wp_dropdown_categories('taxonomy=results&hide_empty=0&name=result_select&id=result_select&hide_if_empty=true');
        ?>
            </div>
        </li>
        <script type="text/javascript">
            var checkbox = document.getElementById('closeCase');
            var conteiner = document.getElementById('result_select_container').parentNode;
            if("onpropertychange" in checkbox) {
                // для старого IE
                checkbox.onpropertychange = function() {
                    // проверим имя изменённого свойства
                    conteiner.style.display = (checkbox.checked) ? 'block' : 'none';
                };
            } else {
                // остальные браузеры
                checkbox.onchange = function() {
                    conteiner.style.display = (checkbox.checked) ? 'block' : 'none';
                };
            }
        </script>
        <?php 
    }
}
示例#30
0
function rb_exibir_filme($content)
{
    global $post;
    if (is_single() && $post->post_type == 'filme') {
        if (has_post_thumbnail($post->ID)) {
            $capa = get_the_post_thumbnail($post->ID, 'full');
        }
        // verifica se no meu post há uma taxonomy "genero" cadastrada
        if (has_term('', 'genero', $post->ID)) {
            $genero = get_the_term_list($post->ID, 'genero', '', ', ', '');
        }
        if (has_term('', 'estudio', $post->ID)) {
            $estudio = get_the_term_list($post->ID, 'estudio', '', ', ', '');
        }
        // pega os dados do campo personalizado "duracao";
        $duracao = get_post_meta($post->ID, 'duracao', TRUE);
        $resumo = get_the_excerpt();
        //$resumo = substr($resumo, 0, strpos($resumo, '<a'));
        $conteudo_full = $content;
        $content = '<div class="filme">';
        if (isset($capa)) {
            $content .= $capa;
        }
        if (isset($genero)) {
            $content .= '<p> <strong> Gênero : </strong> ' . $genero . '</p>';
        }
        if (isset($estudio)) {
            $content .= '<p> <strong> Estúdio : </strong> ' . $estudio . '</p>';
        }
        if (isset($duracao)) {
            $content .= '<p> <strong> Duração : </strong> ' . $duracao . '</p>';
        }
        if (isset($resumo)) {
            $content .= '<p> <strong> Resumo : </strong> ' . $resumo . '</p>';
        }
        $content .= '<h2> Descrição completa do filme </h2>' . $conteudo_full;
        $content .= '</div>';
    }
    return $content;
}