function jp_disable_wish_list()
{
    // replace category-goes-here below with your category slug
    if (is_singular('download') && is_object_in_term(get_the_ID(), 'download_category', 'category-slug-goes-here')) {
        remove_action('edd_purchase_link_top', 'edd_wl_load_wish_list_link');
    }
}
function my_custom_filters($continue, $args)
{
    if (is_object_in_term($args['info']['id'], 'category', array('wordpress', 'plugins')) && $args['info']['authId'] == 2) {
        $continue = false;
    }
    return $continue;
}
Ejemplo n.º 3
0
function appthemes_get_custom_taxonomy($post_id, $tax_name, $tax_arg)
{
    $tax_array = get_terms($tax_name, array('hide_empty' => '0'));
    if ($tax_array && sizeof($tax_array) > 0) {
        if (is_object_in_term($post_id, $tax_name)) {
            foreach ($tax_array as $tax_val) {
                if (is_object_in_term($post_id, $tax_name, array($tax_val->term_id))) {
                    switch ($tax_arg) {
                        case 'slug':
                            $link = get_term_link($tax_val, $tax_name);
                            if (is_wp_error($link)) {
                                return $link;
                            }
                            return $link;
                            break;
                        case 'slug_name':
                            return $tax_val->slug;
                            break;
                        case 'name':
                            return $tax_val->name;
                            break;
                        case 'term_id':
                            return $tax_val->term_id;
                            break;
                        default:
                            return;
                            break;
                    }
                    // end switch
                }
            }
        }
    }
}
function remove_main_account_by_category($authors, $post_info)
{
    $categories = array('wordpress', 'plugins');
    if (is_object_in_term($post_info['id'], 'category', $categories)) {
        unset($authors['main']);
    }
    return $authors;
}
 function woocommerce_dynamic_pricing_is_applied_to($process_discounts, $_product, $module_id, $obj, $cat_id)
 {
     if ($cat_id && isset($obj->available_rulesets) && count($obj->available_rulesets) > 0) {
         global $sitepress;
         $cat_id = apply_filters('translate_object_id', $cat_id, 'product_cat', true, $sitepress->get_current_language());
         $process_discounts = is_object_in_term($_product->id, 'product_cat', $cat_id);
     }
     return $process_discounts;
 }
Ejemplo n.º 6
0
 /**
  * @ticket 29467
  */
 public function test_should_not_return_true_if_term_name_begins_with_existing_term_id()
 {
     register_taxonomy('wptests_tax', 'post');
     $t = $this->factory->term->create(array('taxonomy' => 'wptests_tax'));
     $post_ID = $this->factory->post->create();
     wp_set_object_terms($post_ID, $t, 'wptests_tax');
     $int_tax_name = $t . '_term_name';
     $this->assertFalse(is_object_in_term($post_ID, 'wptests_tax', $int_tax_name));
     // Verify it works properly when the post is actually in the term.
     wp_set_object_terms($post_ID, array($int_tax_name), 'wptests_tax');
     $this->assertTrue(is_object_in_term($post_ID, 'wptests_tax', $int_tax_name));
 }
function has_mediatag($tag = '', $_post = null)
{
    if ($_post) {
        $_post = get_post($_post);
    } else {
        $_post =& $GLOBALS['post'];
    }
    if (!$_post) {
        return false;
    }
    $r = is_object_in_term($_post->ID, MEDIA_TAGS_TAXONOMY, $tag);
    if (is_wp_error($r)) {
        return false;
    }
    return $r;
}
function send_to_user_account_by_category($authors, $post_info)
{
    /* 
     * Define an array with the slugs of all categories you want sent to this set of authors 
     * You can repeat this pattern to send different categories to different authors
     */
    $categories = array('wordpress', 'plugins');
    if (is_object_in_term($post_info['id'], 'category', $categories)) {
        /* Define array of author IDs that this set of categories are sent to */
        $authors = array(5);
    }
    $categories = array('drupal', 'core');
    if (is_object_in_term($post_info['id'], 'category', $categories)) {
        /* Define array of author IDs that this set of categories are sent to */
        $authors = array(4);
    }
    return $authors;
}
function cftl_find_override_page(&$query_obj)
{
    $override_query = array('post_type' => 'cftl-tax-landing', 'post_status' => 'publish', 'numberposts' => 1, 'tax_query' => $query_obj->tax_query->queries);
    if (is_array($override_query['tax_query'])) {
        foreach (array_keys($override_query['tax_query']) as $key) {
            if (is_array($override_query['tax_query'][$key])) {
                $override_query['tax_query'][$key]['include_children'] = false;
            }
        }
    }
    $landings = get_posts($override_query);
    if (!is_array($landings) || empty($landings)) {
        return false;
    }
    foreach ($query_obj->tax_query->queries as $tax_query) {
        if (is_object_in_term($landings[0]->ID, $tax_query['taxonomy'], $tax_query['terms'])) {
            return $landings[0];
        }
    }
    return false;
}
Ejemplo n.º 10
0
 /**
  * Returns whether or not the given term(s) are associated with the post. If no terms are provided
  * then whether or not the post has any terms within the taxonomy
  * @param  string             $taxonomy Single taxonomy name
  * @param  int|string|array   $term     Optional. Term term_id, name, slug or array of said. Default null.
  * @return boolean
  */
 public function has_term($taxonomy, $term = null)
 {
     $result = is_object_in_term($this->id, $taxonomy, $term);
     return $result && !is_wp_error($result);
 }
 public function is_applied_to_product($_product, $cat_id = false)
 {
     if (is_admin() && !is_ajax()) {
         return false;
     }
     $process_discounts = false;
     if (isset($this->available_rulesets) && count($this->available_rulesets) > 0 || isset($this->available_advanced_rulesets) && count($this->available_advanced_rulesets)) {
         if ($cat_id) {
             $process_discounts = is_object_in_term($_product->id, 'product_cat', $cat_id);
         }
     }
     return apply_filters('woocommerce_dynamic_pricing_is_applied_to', $process_discounts, $_product, $this->module_id, $this, $cat_id);
 }
Ejemplo n.º 12
0
 /**
  * Outputs the contents of the language picker meta box for the write screen
  */
 public function language_picker_meta_box()
 {
     global $post;
     $get_terms_args = array('hide_empty' => false);
     // Default language
     if ($default_language = $this->get_term($this->default_language)) {
         $get_terms_args['exclude'] = $this->default_language;
         $default_language = array($default_language);
     }
     $languages = get_terms($this->taxonomy_name, $get_terms_args);
     // If there's a default language, push it onto the front of the array
     // It won't appear twice as we excluded it already
     if (!empty($get_terms_args['exclude'])) {
         $languages = array_merge($default_language, $languages);
     }
     echo '<p><select name="' . esc_attr($this->taxonomy_name) . '_picker" style="width:100%">';
     foreach ($languages as $language) {
         echo '<option value="' . esc_attr($language->term_id) . '"';
         if (true === is_object_in_term($post->ID, $this->taxonomy_name, $language->term_id)) {
             echo ' selected="selected"';
         }
         echo '>' . esc_html($language->name) . '</option>';
     }
     echo '</select></p>';
 }
Ejemplo n.º 13
0
/**
 * Returns term data specified in arguments
 *
 * @param int $post_id Post ID
 * @param string $taxonomy The taxonomy
 * @param string $tax_arg The term data to retrieve
 *
 * @return string|bool The term data specified by $tax_arg or bool false if post has no terms
 */
function appthemes_get_custom_taxonomy($post_id, $taxonomy, $tax_arg)
{
    $tax_array = get_terms($taxonomy, array('hide_empty' => '0'));
    if (empty($tax_array)) {
        return false;
    }
    if (!is_object_in_term($post_id, $taxonomy)) {
        return false;
    }
    foreach ($tax_array as $tax_val) {
        if (!is_object_in_term($post_id, $taxonomy, array($tax_val->term_id))) {
            continue;
        }
        switch ($tax_arg) {
            case 'slug':
                $link = get_term_link($tax_val, $taxonomy);
                return $link;
                break;
            case 'slug_name':
                return $tax_val->slug;
                break;
            case 'name':
                return $tax_val->name;
                break;
            case 'term_id':
                return $tax_val->term_id;
                break;
            default:
                return false;
                break;
        }
    }
}
Ejemplo n.º 14
0
 /**
  * returns list of a comma delimited field names matching the custom term supplied
  *
  * @terms Comma separated list of terms.
  * @content Comma separated list of custom field ids.
  *
  * @return Comma separated list of field IDs filtered by terms
  */
 function filter_shortcode($atts, $content = null)
 {
     global $post;
     extract(shortcode_atts(array('terms' => '', 'not' => 'false'), $atts));
     $post_type = get_post_type($post->ID);
     $content = do_shortcode($content);
     $content = preg_replace('/\\s/', '', $content);
     $fields = array_map('trim', (array) explode(',', $content));
     if (!empty($terms)) {
         $belongs = false;
         $taxonomies = array_values(get_object_taxonomies($post_type, 'object'));
         $term_names = array_map('trim', (array) explode(',', $terms));
         foreach ($taxonomies as $taxonomy) {
             if ($taxonomy->hierarchical) {
                 //Only the category like
                 foreach ($term_names as $name) {
                     $term = get_term_by('slug', $name, $taxonomy->name);
                     if (empty($term->parent)) {
                         $children = get_term_children($term->term_id, $taxonomy->name);
                         if (is_object_in_term($post->ID, $taxonomy->name, $children)) {
                             $belongs = true;
                         }
                     }
                     if (is_object_in_term($post->ID, $taxonomy->name, $name)) {
                         $belongs = true;
                     }
                 }
             }
         }
         if (!$belongs) {
             $fields = array();
         }
     }
     if ($not == 'true') {
         foreach ($fields as &$field) {
             $field = preg_replace('/^(_ct|ct)_/', '', $field);
         }
         $fields = array_keys(array_diff_key($this->all_custom_fields, array_flip($fields)));
     }
     $result = implode(',', array_filter($fields));
     //filter blanks
     if ($result) {
         $result .= ',';
     }
     $result = apply_filters('custom_fields_filter', $result, $atts, $content);
     return $result;
 }
Ejemplo n.º 15
0
 /**
  * Obtains the gallery and overlay IDs for the post based on its categories, if any
  *
  * @param int $post_id The Post ID to check against
  * @param mixed $tax The queried object containing the taxonomy details
  */
 protected function getOverrideIds($post_id, $tax = null)
 {
     $cache_id = 'myatu_bgm_' . md5('override' . $this->taxonomy . (is_null($tax) ? $post_id : $tax->slug));
     // Check if we already have a cached value
     if ($cached_val = get_transient($cache_id)) {
         return unserialize($cached_val);
     }
     // Grab the galleries
     $galleries = get_posts(array('numberposts' => -1, 'orderby' => 'title', 'order' => 'ASC', 'post_type' => \Myatu\WordPress\BackgroundManager\Main::PT_GALLERY));
     // Iterate galleries
     foreach ($galleries as $gallery) {
         $overriding_tax = get_post_meta($gallery->ID, $this->meta_tax, true);
         // Grab the meta containing the overriding tax from gallery
         if (is_array($overriding_tax) && !empty($overriding_tax)) {
             $match = false;
             if (is_null($tax)) {
                 // Check if the specified post contains an overrding tax
                 $match = is_object_in_term($post_id, $this->taxonomy, $overriding_tax);
             } else {
                 // Check if the specified tax is in the overriding tax
                 $match = in_array($tax->term_id, $overriding_tax) || in_array($tax->name, $overriding_tax) || in_array($tax->slug, $overriding_tax);
             }
             // Match found
             if ($match) {
                 $cached_val = array('gallery_id' => $gallery->ID, 'overlay_id' => get_post_meta($gallery->ID, $this->meta_tax . static::MT_OVERLAY, true), 'background_color' => get_post_meta($gallery->ID, $this->meta_tax . static::MT_COLOR, true));
                 // Cache response before returning - WP claims it will serialize, but doesn't seem to work well for this
                 set_transient($cache_id, serialize($cached_val), 10);
                 return $cached_val;
             }
         }
     }
     // If we reach this point, there's nothing to override
     set_transient($cache_id, serialize(false), 10);
     return false;
 }
Ejemplo n.º 16
0
function section_meta_box($post)
{
    $tax_name = 'section';
    $taxonomy = get_taxonomy($tax_name);
    ?>
<div class="tagsdiv" id="<?php 
    echo $tax_name;
    ?>
">
	
	
	
	<script type="text/javascript" src="http://code.jquery.com/jquery.js"></script>
<script type="text/javascript">
	
	
jQuery(document).ready(function($) {
    jQuery('#category_faq').on('change',function() {
        jQuery('#wrapper div').show().not(".views-row-" + this.value).hide();
    });
});


</script>
	
	
	
    <div class="jaxtag">
    <?php 
    // Use nonce for verification
    wp_nonce_field(plugin_basename(__FILE__), 'section_noncename');
    $section_IDs = wp_get_object_terms($post->ID, 'section', array('fields' => 'ids'));
    wp_dropdown_categories('taxonomy=section&hide_empty=0&orderby=name&name=section&show_option_none=Select section&selected=' . $section_IDs[0]);
    ?>
    <p class="howto">Select the section</p>
    </div>
    
    
    <script type="text/javascript">
    
    
    $(document).ready(function(){
    
    
    
    
    
        $("#section").bind('change', function () {
    var str = "";
  
    str = parseInt($("select option:selected").val());
        
        if(str == 1178){
            
         $("#posttypeselector").show();
         
             $("#newswoo").show();  
       
             
         $("#opinionwoo").hide();
         
         
          $("#typeteller").val('news');
          
        
         
        
            
        
         
         $("#sportswoo").hide();
            
            
        }
        
        else if(str == 1180){
            
         $("#posttypeselector").show();
         
             
          $("#opinionwoo").show();  
          
           
         $("#newswoo").hide();
         
         $("#typeteller").val('opinion');
            
        
         
         $("#sportswoo").hide();
            
            
        }
        
       
        
        
        
      else
          $("#posttypeselector").hide();
          
});

$('#section').trigger('change');

});

</script>
  
    
    
     <div id="posttypeselector" class="jaxtag ifnews boxhider" style="display: none;">
   
   
   <div id="newswoo"> 
	   
	  <?php 
    wp_nonce_field('newsnonce', 'news_noncefield');
    ?>
	   
	   <select name="news_articletype" class='postform' >
		   
		   
		<option class="level-0" value="1183" <?php 
    if (is_object_in_term($post->ID, 'articletype', 'newsarticle')) {
        echo 'selected="selected"';
    } else {
        echo '';
    }
    ?>
>News Article</option>
	<option class="level-0" value="1184" <?php 
    if (is_object_in_term($post->ID, 'articletype', 'newsfeature')) {
        echo 'selected="selected"';
    } else {
        echo '';
    }
    ?>
>News Feature</option>
</select>
	   
	   
   </div>
   
   <div id="opinionwoo">
	   
	   
	   
	  
	<?php 
    wp_nonce_field('opinionnonce', 'opinion_noncefield');
    ?>
	
		  
	  <select name="opinion_articletype" class='postform' >
		
		
		<option class="level-0" value="1187" <?php 
    if (is_object_in_term($post->ID, 'articletype', 'opinioncontrib')) {
        echo 'selected="selected"';
    } else {
        echo '';
    }
    ?>
>Opinion Contribution</option>

<option class="level-0" value="1189" <?php 
    if (is_object_in_term($post->ID, 'articletype', 'analysis-2')) {
        echo 'selected="selected"';
    } else {
        echo '';
    }
    ?>
>Analysis</option>

	<option class="level-0" value="1185" <?php 
    if (is_object_in_term($post->ID, 'articletype', 'column')) {
        echo 'selected="selected"';
    } else {
        echo '';
    }
    ?>
>Column</option>

<option class="level-0" value="1186" <?php 
    if (is_object_in_term($post->ID, 'articletype', 'editorialarticle')) {
        echo 'selected="selected"';
    } else {
        echo '';
    }
    ?>
>Editorial</option>


<option class="level-0" value="1188" <?php 
    if (is_object_in_term($post->ID, 'articletype', 'op-ed')) {
        echo 'selected="selected"';
    } else {
        echo '';
    }
    ?>
>Op-ed</option>

	    </select>

	   
	   
	   
	   
	   
	    </div>
   
   <div id="sportswoo">SPORTS WOO!</div>
   
   
   
   
   
   	   
	   <input id="typeteller" type="hidden" name="typeteller"  value="" /> 
   
   
   
    <p class="howto">Select article type</p>
    </div>
    
</div>

 


<?php 
}
Ejemplo n.º 17
0
/**
 * Save the properties of a menu item or create a new one.
 *
 * @since 3.0.0
 *
 * @param int $menu_id The ID of the menu. Required. If "0", makes the menu item a draft orphan.
 * @param int $menu_item_db_id The ID of the menu item. If "0", creates a new menu item.
 * @param array $menu_item_data The menu item's data.
 * @return int|WP_Error The menu item's database ID or WP_Error object on failure.
 */
function wp_update_nav_menu_item($menu_id = 0, $menu_item_db_id = 0, $menu_item_data = array())
{
    $menu_id = (int) $menu_id;
    $menu_item_db_id = (int) $menu_item_db_id;
    // make sure that we don't convert non-nav_menu_item objects into nav_menu_item objects
    if (!empty($menu_item_db_id) && !is_nav_menu_item($menu_item_db_id)) {
        return new WP_Error('update_nav_menu_item_failed', __('The given object ID is not that of a menu item.'));
    }
    $menu = wp_get_nav_menu_object($menu_id);
    if (!$menu && 0 !== $menu_id) {
        return new WP_Error('invalid_menu_id', __('Invalid menu ID.'));
    }
    if (is_wp_error($menu)) {
        return $menu;
    }
    $defaults = array('menu-item-db-id' => $menu_item_db_id, 'menu-item-object-id' => 0, 'menu-item-object' => '', 'menu-item-parent-id' => 0, 'menu-item-position' => 0, 'menu-item-type' => 'custom', 'menu-item-title' => '', 'menu-item-url' => '', 'menu-item-description' => '', 'menu-item-attr-title' => '', 'menu-item-target' => '', 'menu-item-classes' => '', 'menu-item-xfn' => '', 'menu-item-status' => '');
    $args = wp_parse_args($menu_item_data, $defaults);
    if (0 == $menu_id) {
        $args['menu-item-position'] = 1;
    } elseif (0 == (int) $args['menu-item-position']) {
        $menu_items = 0 == $menu_id ? array() : (array) wp_get_nav_menu_items($menu_id, array('post_status' => 'publish,draft'));
        $last_item = array_pop($menu_items);
        $args['menu-item-position'] = $last_item && isset($last_item->menu_order) ? 1 + $last_item->menu_order : count($menu_items);
    }
    $original_parent = 0 < $menu_item_db_id ? get_post_field('post_parent', $menu_item_db_id) : 0;
    if ('custom' != $args['menu-item-type']) {
        /* if non-custom menu item, then:
         * use original object's URL
         * blank default title to sync with original object's
         */
        $args['menu-item-url'] = '';
        $original_title = '';
        if ('taxonomy' == $args['menu-item-type']) {
            $original_parent = get_term_field('parent', $args['menu-item-object-id'], $args['menu-item-object'], 'raw');
            $original_title = get_term_field('name', $args['menu-item-object-id'], $args['menu-item-object'], 'raw');
        } elseif ('post_type' == $args['menu-item-type']) {
            $original_object = get_post($args['menu-item-object-id']);
            $original_parent = (int) $original_object->post_parent;
            $original_title = $original_object->post_title;
        }
        if ($args['menu-item-title'] == $original_title) {
            $args['menu-item-title'] = '';
        }
        // hack to get wp to create a post object when too many properties are empty
        if ('' == $args['menu-item-title'] && '' == $args['menu-item-description']) {
            $args['menu-item-description'] = ' ';
        }
    }
    // Populate the menu item object
    $post = array('menu_order' => $args['menu-item-position'], 'ping_status' => 0, 'post_content' => $args['menu-item-description'], 'post_excerpt' => $args['menu-item-attr-title'], 'post_parent' => $original_parent, 'post_title' => $args['menu-item-title'], 'post_type' => 'nav_menu_item');
    $update = 0 != $menu_item_db_id;
    // New menu item. Default is draft status
    if (!$update) {
        $post['ID'] = 0;
        $post['post_status'] = 'publish' == $args['menu-item-status'] ? 'publish' : 'draft';
        $menu_item_db_id = wp_insert_post($post);
        if (!$menu_item_db_id || is_wp_error($menu_item_db_id)) {
            return $menu_item_db_id;
        }
    }
    // Associate the menu item with the menu term
    // Only set the menu term if it isn't set to avoid unnecessary wp_get_object_terms()
    if ($menu_id && (!$update || !is_object_in_term($menu_item_db_id, 'nav_menu', (int) $menu->term_id))) {
        wp_set_object_terms($menu_item_db_id, array($menu->term_id), 'nav_menu');
    }
    if ('custom' == $args['menu-item-type']) {
        $args['menu-item-object-id'] = $menu_item_db_id;
        $args['menu-item-object'] = 'custom';
    }
    $menu_item_db_id = (int) $menu_item_db_id;
    update_post_meta($menu_item_db_id, '_menu_item_type', sanitize_key($args['menu-item-type']));
    update_post_meta($menu_item_db_id, '_menu_item_menu_item_parent', strval((int) $args['menu-item-parent-id']));
    update_post_meta($menu_item_db_id, '_menu_item_object_id', strval((int) $args['menu-item-object-id']));
    update_post_meta($menu_item_db_id, '_menu_item_object', sanitize_key($args['menu-item-object']));
    update_post_meta($menu_item_db_id, '_menu_item_target', sanitize_key($args['menu-item-target']));
    $args['menu-item-classes'] = array_map('sanitize_html_class', explode(' ', $args['menu-item-classes']));
    $args['menu-item-xfn'] = implode(' ', array_map('sanitize_html_class', explode(' ', $args['menu-item-xfn'])));
    update_post_meta($menu_item_db_id, '_menu_item_classes', $args['menu-item-classes']);
    update_post_meta($menu_item_db_id, '_menu_item_xfn', $args['menu-item-xfn']);
    update_post_meta($menu_item_db_id, '_menu_item_url', esc_url_raw($args['menu-item-url']));
    if (0 == $menu_id) {
        update_post_meta($menu_item_db_id, '_menu_item_orphaned', (string) time());
    } elseif (get_post_meta($menu_item_db_id, '_menu_item_orphaned')) {
        delete_post_meta($menu_item_db_id, '_menu_item_orphaned');
    }
    // Update existing menu item. Default is publish status
    if ($update) {
        $post['ID'] = $menu_item_db_id;
        $post['post_status'] = 'draft' == $args['menu-item-status'] ? 'draft' : 'publish';
        wp_update_post($post);
    }
    /**
     * Fires after a navigation menu item has been updated.
     *
     * @since 3.0.0
     *
     * @see wp_update_nav_menu_items()
     *
     * @param int   $menu_id         ID of the updated menu.
     * @param int   $menu_item_db_id ID of the updated menu item.
     * @param array $args            An array of arguments used to update a menu item.
     */
    do_action('wp_update_nav_menu_item', $menu_id, $menu_item_db_id, $args);
    return $menu_item_db_id;
}
Ejemplo n.º 18
0
            <?php 
        global $featured_job_cat_id;
        $post_class = array('job');
        $expired = jr_check_expired($post);
        if ($expired) {
            $post_class[] = 'job-expired';
            $action = get_option('jr_expired_action');
            if ($action == 'hide') {
                continue;
            }
        }
        $alt = $alt * -1;
        if ($alt == 1) {
            $post_class[] = 'job-alt';
        }
        if (is_object_in_term($post->ID, 'job_cat', array($featured_job_cat_id))) {
            $post_class[] = 'job-featured';
        }
        ?>

            <li class="<?php 
        echo implode(' ', $post_class);
        ?>
">

                <dl>

                    <dt><?php 
        _e('Type', 'appthemes');
        ?>
</dt>
Ejemplo n.º 19
0
function jr_get_custom_taxonomy($post_id, $tax_name, $tax_class)
{
    $tax_array = get_terms($tax_name, array('hide_empty' => '0'));
    if ($tax_array && sizeof($tax_array) > 0) {
        foreach ($tax_array as $tax_val) {
            if (is_object_in_term($post_id, $tax_name, array($tax_val->term_id))) {
                echo '<span class="' . $tax_class . ' ' . $tax_val->slug . '">' . $tax_val->name . '</span>';
                break;
            }
        }
    }
}
Ejemplo n.º 20
0
 /**
  * Event in Category Conditional
  *
  * Returns true if the event is in the specified category slug
  *
  * @category Events
  * @param string $event_cat_slug
  * @param int    $event_id
  *
  * @return boolean
  */
 function tribe_event_in_category($event_cat_slug, $event_id = null)
 {
     if (empty($event_id)) {
         $event_id = get_the_ID();
     }
     $term = term_exists($event_cat_slug, Tribe__Events__Main::TAXONOMY);
     if (tribe_is_event($event_id) && is_object_in_term($event_id, Tribe__Events__Main::TAXONOMY, array($term['term_id']))) {
         $return = true;
     } else {
         $return = false;
     }
     return apply_filters('tribe_event_in_category', $return);
 }
Ejemplo n.º 21
0
function is_tax_branch($slug, $tax)
{
    global $post;
    $test = get_term_by('slug', $slug, $tax);
    if (empty($test)) {
        return false;
    }
    if (is_tax($tax)) {
        $qobj = get_queried_object();
        if ($qobj->term_id == $test->term_id || $qobj->parent == $test->term_id) {
            return true;
        }
    }
    if (is_singular() && is_object_in_term($post->ID, $tax, $test->term_id)) {
        return true;
    }
    return false;
}
/**
 * Identifies taxonomy type
 *
 * Use to identify the item type and do something.
 * Example: if ( rolo_type_is( 'contact' ) ) { do something }	
 *
 * @credits: Justin Tadlock: http://wordpress.org/support/topic/281899
 */
function rolo_type_is($type, $_post = null)
{
    if (empty($type)) {
        return false;
    }
    if ($_post) {
        $_post = get_post($_post);
    } else {
        $_post =& $GLOBALS['post'];
    }
    if (!$_post) {
        return false;
    }
    $r = is_object_in_term($_post->ID, 'type', $type);
    if (is_wp_error($r)) {
        return false;
    }
    return $r;
}
function pa_in_taxonomy($tax, $term, $_post = NULL)
{
    // if neither tax nor term are specified, return false
    if (!$tax || !$term) {
        return FALSE;
    }
    // if post parameter is given, get it, otherwise use $GLOBALS to get post
    if ($_post) {
        $_post = get_post($_post);
    } else {
        $_post =& $GLOBALS['post'];
    }
    // if no post return false
    if (!$_post) {
        return FALSE;
    }
    // check whether post matches term belongin to tax
    $return = is_object_in_term($_post->ID, $tax, $term);
    // if error returned, then return false
    if (is_wp_error($return)) {
        return FALSE;
    }
    return $return;
}
Ejemplo n.º 24
0
 /**
  * Worker method to create new items or update existing ones.
  */
 private function add_or_update_item($method, $type, $args, $assoc_args)
 {
     $menu = $args[0];
     $menu_item_db_id = \WP_CLI\Utils\get_flag_value($args, 1, 0);
     $menu = wp_get_nav_menu_object($menu);
     if (!$menu || is_wp_error($menu)) {
         WP_CLI::error("Invalid menu.");
     }
     // `url` is protected in WP-CLI, so we use `link` instead
     $assoc_args['url'] = \WP_CLI\Utils\get_flag_value($assoc_args, 'link');
     // Need to persist the menu item data. See https://core.trac.wordpress.org/ticket/28138
     if ('update' == $method) {
         $menu_item_obj = get_post($menu_item_db_id);
         $menu_item_obj = wp_setup_nav_menu_item($menu_item_obj);
         // Correct the menu position if this was the first item. See https://core.trac.wordpress.org/ticket/28140
         $position = 0 === $menu_item_obj->menu_order ? 1 : $menu_item_obj->menu_order;
         $default_args = array('position' => $position, 'title' => $menu_item_obj->title, 'url' => $menu_item_obj->url, 'description' => $menu_item_obj->description, 'object' => $menu_item_obj->object, 'object-id' => $menu_item_obj->object_id, 'parent-id' => $menu_item_obj->menu_item_parent, 'attr-title' => $menu_item_obj->attr_title, 'target' => $menu_item_obj->target, 'classes' => implode(' ', $menu_item_obj->classes), 'xfn' => $menu_item_obj->xfn, 'status' => $menu_item_obj->post_status);
     } else {
         $default_args = array('position' => 0, 'title' => '', 'url' => '', 'description' => '', 'object' => '', 'object-id' => 0, 'parent-id' => 0, 'attr-title' => '', 'target' => '', 'classes' => '', 'xfn' => '', 'status' => 'publish');
     }
     $menu_item_args = array();
     foreach ($default_args as $key => $default_value) {
         // wp_update_nav_menu_item() has a weird argument prefix
         $new_key = 'menu-item-' . $key;
         $menu_item_args[$new_key] = \WP_CLI\Utils\get_flag_value($assoc_args, $key, $default_value);
     }
     $menu_item_args['menu-item-type'] = $type;
     $ret = wp_update_nav_menu_item($menu->term_id, $menu_item_db_id, $menu_item_args);
     if (is_wp_error($ret)) {
         WP_CLI::error($ret->get_error_message());
     } else {
         if (!$ret) {
             if ('add' == $method) {
                 WP_CLI::error("Couldn't add menu item.");
             } else {
                 if ('update' == $method) {
                     WP_CLI::error("Couldn't update menu item.");
                 }
             }
         } else {
             /**
              * Set the menu
              *
              * wp_update_nav_menu_item() *should* take care of this, but
              * depends on wp_insert_post()'s "tax_input" argument, which
              * is ignored if the user can't edit the taxonomy
              *
              * @see https://core.trac.wordpress.org/ticket/27113
              */
             if (!is_object_in_term($ret, 'nav_menu', (int) $menu->term_id)) {
                 wp_set_object_terms($ret, array((int) $menu->term_id), 'nav_menu');
             }
             if ('add' == $method && !empty($assoc_args['porcelain'])) {
                 WP_CLI::line($ret);
             } else {
                 if ('add' == $method) {
                     WP_CLI::success("Menu item added.");
                 } else {
                     if ('update' == $method) {
                         WP_CLI::success("Menu item updated.");
                     }
                 }
             }
         }
     }
 }
Ejemplo n.º 25
0
 /**
  * Check if the post with the given ID has the meta term with the given ID or slug.
  *
  * @param int        $post_id Post ID.
  * @param int|string $term    Meta term ID or slug.
  *
  * @return bool
  */
 function has_meta_term($post_id, $term)
 {
     $taxonomy = new Taxonomy();
     return is_object_in_term($post_id, $taxonomy->get_name(), $term);
 }
 public function test_delete_item()
 {
     wp_set_current_user($this->admin_id);
     $tag = wp_insert_term('test-tag', 'post_tag');
     wp_set_object_terms($this->post_id, 'test-tag', 'post_tag');
     $request = new WP_REST_Request('DELETE', sprintf('/wp/v2/posts/%d/terms/tag/%d', $this->post_id, $tag['term_taxonomy_id']));
     $request['force'] = true;
     $response = $this->server->dispatch($request);
     $this->assertEquals(200, $response->get_status());
     $this->assertFalse(is_object_in_term($this->post_id, 'post_tag', $tag['term_id']));
 }
/**
 * Check if the current post has any of given terms.
 *
 * The given terms are checked against the post's terms' term_ids, names and slugs.
 * Terms given as integers will only be checked against the post's terms' term_ids.
 * If no terms are given, determines if post has any terms.
 *
 * @since 3.1.0
 *
 * @param string|int|array $term Optional. The term name/term_id/slug or array of them to check for.
 * @param string $taxonomy Taxonomy name
 * @param int|object $post Optional. Post to check instead of the current post.
 * @return bool True if the current post has any of the given tags (or any tag, if no tag specified).
 */
function has_term($term = '', $taxonomy = '', $post = null)
{
    $post = get_post($post);
    if (!$post) {
        return false;
    }
    $r = is_object_in_term($post->ID, $taxonomy, $term);
    if (is_wp_error($r)) {
        return false;
    }
    return $r;
}
 public function adjust_cart($temp_cart)
 {
     if ($this->adjustment_sets && count($this->adjustment_sets)) {
         $valid_sets = wp_list_filter($this->adjustment_sets, array('is_valid_rule' => true, 'is_valid_for_user' => true));
         if (empty($valid_sets)) {
             return;
         }
         foreach ($temp_cart as $cart_item_key => $values) {
             $temp_cart[$cart_item_key] = $values;
             $temp_cart[$cart_item_key]['available_quantity'] = $values['quantity'];
         }
         //Process block discounts first
         foreach ($valid_sets as $set_id => $set) {
             if ($set->mode != 'block') {
                 continue;
             }
             //check if this set is valid for the current user;
             $is_valid_for_user = $set->is_valid_for_user();
             if (!$is_valid_for_user) {
                 continue;
             }
             //Lets actuall process the rule.
             //Setup the matching quantity
             $targets = $set->targets;
             $collector = $set->get_collector();
             $q = 0;
             if (isset($collector['args']) && isset($collector['args']['cats']) && is_array($collector['args']['cats'])) {
                 foreach ($collector['args']['cats'] as $cat_id) {
                     $q += WC_Dynamic_Pricing_Counter::get_category_count($cat_id);
                 }
             } else {
                 continue;
                 //no categories
             }
             $rule = reset($set->pricing_rules);
             //block rules can only have one line item.
             if ($q < $rule['from']) {
                 //continue;
             }
             if ($rule['repeating'] == 'yes') {
                 $b = floor($q / $rule['from']);
                 //blocks - this is how many times has the required amount been met.
             } else {
                 $b = 1;
             }
             $ct = 0;
             //clean targets
             $mt = 0;
             $cq = 0;
             //matched clean quantity;
             $mq = 0;
             //matched mixed quantity;
             foreach ($temp_cart as $cart_item_key => &$cart_item) {
                 $terms = wp_get_post_terms($cart_item['product_id'], 'product_cat', array('fields' => 'ids'));
                 if (count(array_intersect($collector['args']['cats'], $terms)) > 0) {
                     if (count(array_intersect($targets, $terms)) > 0) {
                         $mq += $cart_item['available_quantity'];
                     } else {
                         $cq += $cart_item['available_quantity'];
                     }
                 }
                 if (count(array_intersect($targets, $terms)) > 0) {
                     if (count(array_intersect($collector['args']['cats'], $terms)) == 0) {
                         $ct += $cart_item['quantity'];
                     } else {
                         $mt += $cart_item['quantity'];
                     }
                 }
             }
             $rt = $ct + $mt;
             //remaining targets.
             $rcq = $cq;
             //remaining clean quantity
             $rmq = $mq;
             //remaining mixed quantity
             $tt = 0;
             //the total number of items we can discount.
             //for each block reduce the amount of remaining items which can make up a discount by the amount required.
             if ($rcq || $rmq) {
                 for ($x = 0; $x < $b; $x++) {
                     //If the remaining clean quantity minus what is required to make a block is greater than 0 there are more clean quantity items remaining.
                     //This means we don't have to eat into mixed quantities yet.
                     if ($rcq - $rule['from'] >= 0) {
                         $rcq -= $rule['from'];
                         $tt += $rule['adjust'];
                         //If the total items that can be dicsounted is greater than the number of clean items to be discounted, reduce the
                         //mixed quantity by the difference, because those items will be discounted and can not count towards making another discounted item.
                         if ($tt > $ct) {
                             $rmq -= $tt - $ct;
                         }
                         if ($tt > $mt + $ct) {
                             $tt = $mt + $ct;
                         }
                         $rt -= $ct + $mt - $tt;
                     } else {
                         //how many items left over from clean quantities.  if we have a buy two get one free, we may have one quantity of clean item, and two mixed items.
                         $l = $rcq ? $rule['from'] - $rcq : 0;
                         if ($rcq > 0) {
                             //If the remaining mixed quantity minus the left overs trigger items is more than 0, we have another discount available
                             if ($rt - $l > 0) {
                                 $tt += min($rt - $l, $rule['adjust']);
                             }
                             $rt -= $ct + $mt - $tt;
                         } elseif ($rmq > 0) {
                             $rt -= $rule['from'];
                             //$rt -= ($ct + $mt) - $tt;
                             if ($rt > 0) {
                                 $tt += min($rt, $rule['adjust']);
                                 $rt -= min($rt, $rule['adjust']);
                                 $rmq = $rmq - $l - ($rule['adjust'] + $rule['from']);
                             }
                         }
                         $rcq = 0;
                     }
                 }
                 foreach ($temp_cart as $cart_item_key => $ctitem) {
                     $price_adjusted = false;
                     $original_price = $this->get_price_to_discount($ctitem, $cart_item_key);
                     //Check if the original price is free, we don't want to apply any of these discounts, or use any of them up by
                     //applying a discount to a free item.
                     $op_check = floatval($original_price);
                     if (empty($op_check) && $rule['type'] != 'fixed_adjustment') {
                         continue;
                     }
                     $terms = wp_get_post_terms($ctitem['product_id'], 'product_cat', array('fields' => 'ids'));
                     if (count(array_intersect($targets, $terms)) > 0) {
                         $price_adjusted = $this->get_block_adjusted_price($ctitem, $original_price, $rule, $tt);
                         if ($tt > $ctitem['quantity']) {
                             $tt -= $ctitem['quantity'];
                             $temp_cart[$cart_item_key]['available_quantity'] = 0;
                         } else {
                             $temp_cart[$cart_item_key]['available_quantity'] = $ctitem['quantity'] - $tt;
                             $tt = 0;
                         }
                         if ($price_adjusted !== false && floatval($original_price) != floatval($price_adjusted)) {
                             WC_Dynamic_Pricing::apply_cart_item_adjustment($cart_item_key, $original_price, $price_adjusted, 'advanced_category', $set_id);
                         }
                     }
                 }
             }
         }
         //Now process bulk rules
         foreach ($valid_sets as $set_id => $set) {
             if ($set->mode != 'bulk') {
                 continue;
             }
             //check if this set is valid for the current user;
             $is_valid_for_user = $set->is_valid_for_user();
             if (!$is_valid_for_user) {
                 continue;
             }
             //Lets actuall process the rule.
             //Setup the matching quantity
             $targets = $set->targets;
             //Get the quantity to compare
             $collector = $set->get_collector();
             $q = 0;
             foreach ($temp_cart as $t_cart_item_key => $t_cart_item) {
                 $process_discounts = apply_filters('woocommerce_dynamic_pricing_process_product_discounts', true, $t_cart_item['data'], 'advanced_category', $this, $t_cart_item);
                 if (!$process_discounts) {
                     continue;
                 }
                 $terms = wp_get_post_terms($t_cart_item['product_id'], 'product_cat', array('fields' => 'ids'));
                 if (count(array_intersect($targets, $terms)) > 0) {
                     if (!$this->is_cumulative($t_cart_item, $t_cart_item_key)) {
                         if ($this->is_item_discounted($t_cart_item, $t_cart_item_key)) {
                             continue;
                         }
                     }
                     if (isset($collector['type']) && $collector['type'] == 'cat_product') {
                         $q = $t_cart_item['quantity'];
                     } else {
                         $q = 0;
                         if (isset($collector['args']) && isset($collector['args']['cats']) && is_array($collector['args']['cats'])) {
                             foreach ($temp_cart as $lck => $l_cart_item) {
                                 if (is_object_in_term($l_cart_item['product_id'], 'product_cat', $collector['args']['cats'])) {
                                     if (apply_filters('woocommerce_dynamic_pricing_count_categories_for_cart_item', true, $l_cart_item, $lck)) {
                                         $q += (int) $l_cart_item['quantity'];
                                     }
                                 }
                             }
                         }
                     }
                     $price_adjusted = false;
                     $original_price = $this->get_price_to_discount($t_cart_item, $t_cart_item_key);
                     if (is_array($set->pricing_rules) && sizeof($set->pricing_rules) > 0) {
                         foreach ($set->pricing_rules as $rule) {
                             $price_adjusted = $this->get_bulk_adjusted_price($t_cart_item, $original_price, $rule, $q);
                             if ($price_adjusted !== false) {
                                 break;
                             }
                         }
                     }
                     if ($price_adjusted !== false && floatval($original_price) != floatval($price_adjusted)) {
                         WC_Dynamic_Pricing::apply_cart_item_adjustment($t_cart_item_key, $original_price, $price_adjusted, 'advanced_category', $set_id);
                     }
                 }
             }
         }
     }
 }
Ejemplo n.º 29
0
    public function profile_edit_rank_section($user)
    {
        $tax = get_taxonomy('rank');
        /* Make sure the user can assign terms of the rank taxonomy before proceeding. */
        if (!current_user_can($tax->cap->assign_terms)) {
            return;
        }
        /* Get the terms of the 'rank' taxonomy. */
        $terms = get_terms('rank', array('hide_empty' => false, 'orderby' => 'id'));
        ?>

		<h3><?php 
        _e('Rank', 'ap');
        ?>
</h3>

		<table class="form-table">

			<tr>
				<th><label for="rank"><?php 
        _e('Select rank');
        ?>
</label></th>

				<td><?php 
        /* If there are any rank terms, loop through them and display checkboxes. */
        if (!empty($terms)) {
            foreach ($terms as $term) {
                ?>
						<input type="radio" name="rank" id="rank-<?php 
                echo esc_attr($term->slug);
                ?>
" value="<?php 
                echo esc_attr($term->slug);
                ?>
" <?php 
                checked(true, is_object_in_term($user->ID, 'rank', $term));
                ?>
 /> <label for="rank-<?php 
                echo esc_attr($term->slug);
                ?>
"><?php 
                echo $term->name;
                ?>
</label> <br />
					<?php 
            }
        } else {
            _e('There are no ranks available.', 'ap');
        }
        ?>
</td>
			</tr>

		</table>
	<?php 
    }
Ejemplo n.º 30
0
/**
 * Updates the order for and publishes an existing menu item.
 *
 * Skips the mess that is wp_update_nav_menu_item() and avoids
 * handling menu item fields that are not changed.
 *
 * Based on the parts of wp_update_nav_menu_item() that are needed here.
 * $menu_id must already be validated before running this function (to avoid re-validating for each item in the menu).
 *
 * @param int $menu_id The valid ID of the menu.
 * @param int $item_id The ID of the (existing) menu item.
 * @param int $order   The menu item's new order/position.
 * @return int|WP_Error The menu item's database ID or WP_Error object on failure.
 */
function menu_customizer_update_menu_item_order($menu_id, $item_id, $order)
{
    $item_id = (int) $item_id;
    // Make sure that we don't convert non-nav_menu_item objects into nav_menu_item objects.
    if (!is_nav_menu_item($item_id)) {
        return new WP_Error('update_nav_menu_item_failed', __('The given object ID is not that of a menu item.'));
    }
    // Associate the menu item with the menu term.
    // Only set the menu term if it isn't set to avoid unnecessary wp_get_object_terms().
    if ($menu_id && !is_object_in_term($item_id, 'nav_menu', (int) $menu_id)) {
        wp_set_object_terms($item_id, array($menu_id), 'nav_menu');
    }
    // Populate the potentially-changing fields of the menu item object.
    $post = array('ID' => $item_id, 'menu_order' => $order, 'post_status' => 'publish');
    // Update the menu item object.
    wp_update_post($post);
    return $item_id;
}