Пример #1
0
function powerpress_get_term_by_ttid($ttid, $output = OBJECT, $filter = 'raw')
{
    global $wpdb;
    $value = intval($ttid);
    $field = 'tt.term_taxonomy_id';
    $term = $wpdb->get_row($wpdb->prepare("SELECT t.*, tt.* FROM {$wpdb->terms} AS t INNER JOIN {$wpdb->term_taxonomy} AS tt ON t.term_id = tt.term_id WHERE {$field} = %s LIMIT 1", $value));
    if (!$term) {
        return false;
    }
    $taxonomy = $term->taxonomy;
    wp_cache_add($term->term_id, $term, $taxonomy);
    /** This filter is documented in wp-includes/taxonomy.php */
    $term = apply_filters('get_term', $term, $taxonomy);
    /** This filter is documented in wp-includes/taxonomy.php */
    $term = apply_filters("get_{$taxonomy}", $term, $taxonomy);
    $term = sanitize_term($term, $taxonomy, $filter);
    if ($output == OBJECT) {
        return $term;
    } elseif ($output == ARRAY_A) {
        return get_object_vars($term);
    } elseif ($output == ARRAY_N) {
        return array_values(get_object_vars($term));
    } else {
        return $term;
    }
}
	function categories_form() {
?>
<script type="text/javascript">
<!--
var checkflag = "false";
function check_all_rows() {
	field = document.formlist;
	if ( 'false' == checkflag ) {
		for ( i = 0; i < field.length; i++ ) {
			if ( 'cats_to_convert[]' == field[i].name )
				field[i].checked = true;
		}
		checkflag = 'true';
		return '<?php _e('Uncheck All') ?>';
	} else {
		for ( i = 0; i < field.length; i++ ) {
			if ( 'cats_to_convert[]' == field[i].name )
				field[i].checked = false;
		}
		checkflag = 'false';
		return '<?php _e('Check All') ?>';
	}
}

//  -->
</script>
<?php
		echo '<form name="formlist" id="formlist" action="admin.php?import=wp-cat2tag&amp;step=2" method="post">
		<p><input type="button" class="button-secondary" value="' . __('Check All') . '"' . ' onClick="this.value=check_all_rows()"></p>';
		wp_nonce_field('import-cat2tag');
		echo '<ul style="list-style:none">';

		$hier = _get_term_hierarchy('category');

		foreach ($this->all_categories as $category) {
			$category = sanitize_term( $category, 'category', 'display' );

			if ((int) $category->parent == 0) {
				echo '<li><label><input type="checkbox" name="cats_to_convert[]" value="' . intval($category->term_id) . '" /> ' . $category->name . ' (' . $category->count . ')</label>';

				if (isset($hier[$category->term_id])) {
					$this->_category_children($category, $hier);
				}

				echo '</li>';
			}
		}

		echo '</ul>';

		echo '<p class="submit"><input type="submit" name="submit" class="button" value="' . __('Convert Tags') . '" /></p>';

		echo '</form>';
	}
Пример #3
0
 function categories_form()
 {
     print '<form action="admin.php?import=wp-cat2tag&amp;step=2" method="post">';
     wp_nonce_field('import-cat2tag');
     print '<ul style="list-style:none">';
     $hier = _get_term_hierarchy('category');
     foreach ($this->all_categories as $category) {
         $category = sanitize_term($category, 'category', 'display');
         if ((int) $category->parent == 0) {
             print '<li><label><input type="checkbox" name="cats_to_convert[]" value="' . intval($category->term_id) . '" /> ' . $category->name . ' (' . $category->count . ')</label>';
             if (isset($hier[$category->term_id])) {
                 $this->_category_children($category, $hier);
             }
             print '</li>';
         }
     }
     print '</ul>';
     print '<p class="submit"><input type="submit" name="submit" value="' . __('Convert &raquo;') . '" /></p>';
     print '</form>';
 }
function get_term($term, $taxonomy = '', $output = OBJECT, $filter = 'raw')
{
    if (empty($term)) {
        return new WP_Error('invalid_term', __('Empty Term'));
    }
    if ($taxonomy && !taxonomy_exists($taxonomy)) {
        // pr($term);pr($taxonomy);die;
        // return new WP_Error( 'invalid_taxonomy', __( 'Invalid taxonomy' ) );
        $taxonomy = '';
    }
    if ($term instanceof WP_Term) {
        $_term = $term;
    } elseif (is_object($term)) {
        if (empty($term->filter) || 'raw' === $term->filter) {
            $_term = sanitize_term($term, $taxonomy, 'raw');
            $_term = new WP_Term($_term);
        } else {
            $_term = WP_Term::get_instance($term->term_id);
        }
    } else {
        $_term = WP_Term::get_instance($term, $taxonomy);
    }
    if (is_wp_error($_term)) {
        return $_term;
    } elseif (!$_term) {
        return null;
    }
    $_term = apply_filters('get_term', $_term, $taxonomy);
    $_term = apply_filters("get_{$taxonomy}", $_term, $taxonomy);
    // Sanitize term, according to the specified filter.
    $_term->filter($filter);
    if ($output == ARRAY_A) {
        return $_term->to_array();
    } elseif ($output == ARRAY_N) {
        return array_values($_term->to_array());
    }
    return $_term;
}
Пример #5
0
 /**
  * Get term data from database by term ID.
  *
  * The usage of this method is to apply filters to a term object. It
  * is possible to get a term object from the database before applying the
  * filters.
  *
  * $term ID must be part of $taxonomy, to get from the database. Failure, might
  * be able to be captured by the hooks. Failure would be the same value as $wpdb
  * returns for the get_row method.
  *
  * There are two hooks, one is specifically for each term, named 'cn_get_term', and
  * the second is for the taxonomy name, 'cn_term_$taxonomy'. Both hooks are passed the
  * term object, and the taxonomy name as parameters. Both hooks are expected to
  * return a term object.
  *
  * Filters:
  *    cn_get_term - The method variables.
  *        Passes: (object) $term, (string) $taxonomy
  *        Return: $term
  *
  *    cn_get_{$taxonomy} - The fields for the SELECT query clause.
  *        Passes: (object) $term, (string) $taxonomy
  *        Return: $term
  *
  * NOTE: This is the Connections equivalent of @see get_term() in WordPress core ../wp-includes/taxonomy.php
  *
  * @access public
  * @since  8.1.6
  * @static
  *
  * @global $wpdb
  *
  * @uses  WP_Error
  * @uses  wp_cache_get()
  * @uses  wp_cache_add()
  * @uses  apply_filters()
  * @uses  sanitize_term() Cleanses the term based on $filter context before returning.
  *
  * @param int|object $term     If integer, will get from database. If object will apply filters and return $term.
  * @param string     $taxonomy Taxonomy name that $term is part of.
  * @param string     $output   Constant OBJECT, ARRAY_A, or ARRAY_N
  * @param string     $filter   Optional, default is raw or no WordPress defined filter will applied.
  *
  * @return mixed|null|WP_Error Term Row from database. Will return null if $term is empty. If taxonomy does not
  * exist then WP_Error will be returned.
  */
 public static function get($term, $taxonomy, $output = OBJECT, $filter = 'raw')
 {
     /** @var $wpdb wpdb */
     global $wpdb;
     if (empty($term)) {
         return new WP_Error('invalid_term', __('Empty Term', 'connections'));
     }
     // @todo Implement taxonomy check.
     //if ( ! taxonomy_exists( $taxonomy ) ) {
     //
     //	return new WP_Error( 'invalid_taxonomy', __( 'Invalid taxonomy' ) );
     //}
     if (is_object($term) && empty($term->filter)) {
         wp_cache_add($term->term_id, $term, 'cn_' . $taxonomy);
         $_term = $term;
     } else {
         if (is_object($term)) {
             $term = $term->term_id;
         }
         if (!($term = (int) $term)) {
             return NULL;
         }
         if (!($_term = wp_cache_get($term, 'cn_' . $taxonomy))) {
             $_term = $wpdb->get_row($wpdb->prepare("SELECT t.*, tt.* FROM " . CN_TERMS_TABLE . " AS t INNER JOIN " . CN_TERM_TAXONOMY_TABLE . " AS tt ON t.term_id = tt.term_id WHERE tt.taxonomy = %s AND t.term_id = %d LIMIT 1", $taxonomy, $term));
             if (!$_term) {
                 return NULL;
             }
             wp_cache_add($term, $_term, 'cn_' . $taxonomy);
         }
     }
     /**
      * Filter a term.
      *
      * @since 8.1.6
      *
      * @param int|object $_term    Term object or ID.
      * @param string     $taxonomy The taxonomy slug.
      */
     $_term = apply_filters('cn_get_term', $_term, $taxonomy);
     /**
      * Filter a taxonomy.
      *
      * The dynamic portion of the filter name, $taxonomy, refers
      * to the taxonomy slug.
      *
      * @since 8.1.6
      *
      * @param int|object $_term    Term object or ID.
      * @param string     $taxonomy The taxonomy slug.
      */
     $_term = apply_filters("cn_get_{$taxonomy}", $_term, $taxonomy);
     $_term = sanitize_term($_term, 'cn_' . $taxonomy, $filter);
     if ($output == OBJECT) {
         return $_term;
     } elseif ($output == ARRAY_A) {
         $__term = get_object_vars($_term);
         return $__term;
     } elseif ($output == ARRAY_N) {
         $__term = array_values(get_object_vars($_term));
         return $__term;
     } else {
         return $_term;
     }
 }
Пример #6
0
    function categories_form()
    {
        ?>

<script type="text/javascript">
/* <![CDATA[ */
var checkflag = "false";
function check_all_rows() {
	field = document.catlist;
	if ( 'false' == checkflag ) {
		for ( i = 0; i < field.length; i++ ) {
			if ( 'cats_to_convert[]' == field[i].name )
				field[i].checked = true;
		}
		checkflag = 'true';
		return '<?php 
        _e('Uncheck All');
        ?>
';
	} else {
		for ( i = 0; i < field.length; i++ ) {
			if ( 'cats_to_convert[]' == field[i].name )
				field[i].checked = false;
		}
		checkflag = 'false';
		return '<?php 
        _e('Check All');
        ?>
';
	}
}
/* ]]> */
</script>

<form name="catlist" id="catlist" action="admin.php?import=wp-cat2tag&amp;step=2" method="post">
<p><input type="button" class="button-secondary" value="<?php 
        _e('Check All');
        ?>
" onclick="this.value=check_all_rows()" />
<?php 
        wp_nonce_field('import-cat2tag');
        ?>
</p>
<ul style="list-style:none">

<?php 
        $hier = _get_term_hierarchy('category');
        foreach ($this->all_categories as $category) {
            $category = sanitize_term($category, 'category', 'display');
            if ((int) $category->parent == 0) {
                ?>

	<li><label><input type="checkbox" name="cats_to_convert[]" value="<?php 
                echo intval($category->term_id);
                ?>
" /> <?php 
                echo $category->name . ' (' . $category->count . ')';
                ?>
</label><?php 
                if (in_array(intval($category->term_id), $this->hybrids_ids)) {
                    echo ' <a href="#note"> * </a>';
                }
                if (isset($hier[$category->term_id])) {
                    $this->_category_children($category, $hier);
                }
                ?>
</li>
<?php 
            }
        }
        ?>
</ul>

<?php 
        if (!empty($this->hybrids_ids)) {
            echo '<p><a name="note"></a>' . __('* This category is also a tag. Converting it will add that tag to all posts that are currently in the category.') . '</p>';
        }
        ?>

<p class="submit"><input type="submit" name="submit" class="button" value="<?php 
        _e('Convert Categories to Tags');
        ?>
" /></p>
</form>

<?php 
    }
/**
 * wp_update_term() - Update term based on arguments provided
 *
 * The $args will indiscriminately override all values with the same field name. Care
 * must be taken to not override important information need to update or update will
 * fail (or perhaps create a new term, neither would be acceptable).
 *
 * Defaults will set 'alias_of', 'description', 'parent', and 'slug' if not defined
 * in $args already.
 *
 * 'alias_of' will create a term group, if it doesn't already exist, and update it for
 * the $term.
 *
 * If the 'slug' argument in $args is missing, then the 'name' in $args will be used.
 * It should also be noted that if you set 'slug' and it isn't unique then a WP_Error
 * will be passed back. If you don't pass any slug, then a unique one will be created
 * for you.
 *
 * For what can be overrode in $args, check the term scheme can contain and stay away
 * from the term keys.
 *
 * @package WordPress
 * @subpackage Taxonomy
 * @since 2.3
 *
 * @uses $wpdb
 * @uses do_action() Will call both 'edit_term' and 'edit_$taxonomy' twice.
 * @uses apply_filters() Will call the 'term_id_filter' filter and pass the term id and
 *	taxonomy id.
 *
 * @param int $term The ID of the term
 * @param string $taxonomy The context in which to relate the term to the object.
 * @param array|string $args Overwrite term field values
 * @return array|WP_Error Returns Term ID and Taxonomy Term ID
 */
function wp_update_term( $term, $taxonomy, $args = array() ) {
	global $wpdb;

	if ( ! is_taxonomy($taxonomy) )
		return new WP_Error('invalid_taxonomy', __('Invalid taxonomy'));

	$term_id = (int) $term;

	// First, get all of the original args
	$term = get_term ($term_id, $taxonomy, ARRAY_A);

	// Escape data pulled from DB.
	$term = add_magic_quotes($term);

	// Merge old and new args with new args overwriting old ones.
	$args = array_merge($term, $args);

	$defaults = array( 'alias_of' => '', 'description' => '', 'parent' => 0, 'slug' => '');
	$args = wp_parse_args($args, $defaults);
	$args = sanitize_term($args, $taxonomy, 'db');
	extract($args, EXTR_SKIP);

	// expected_slashed ($name)
	$name = stripslashes($name);
	$description = stripslashes($description);

	$empty_slug = false;
	if ( empty($slug) ) {
		$empty_slug = true;
		$slug = sanitize_title($name);
	}

	if ( $alias_of ) {
		$alias = $wpdb->get_row( $wpdb->prepare( "SELECT term_id, term_group FROM $wpdb->terms WHERE slug = %s", $alias_of) );
		if ( $alias->term_group ) {
			// The alias we want is already in a group, so let's use that one.
			$term_group = $alias->term_group;
		} else {
			// The alias isn't in a group, so let's create a new one and firstly add the alias term to it.
			$term_group = $wpdb->get_var("SELECT MAX(term_group) FROM $wpdb->terms") + 1;
			$wpdb->update( $wpdb->terms, compact('term_group'), array( 'term_id' => $alias->term_id ) );
		}
	}

	// Check for duplicate slug
	$id = $wpdb->get_var( $wpdb->prepare( "SELECT term_id FROM $wpdb->terms WHERE slug = %s", $slug ) );
	if ( $id && ($id != $term_id) ) {
		// If an empty slug was passed or the parent changed, reset the slug to something unique.
		// Otherwise, bail.
		if ( $empty_slug || ( $parent != $term->parent) )
			$slug = wp_unique_term_slug($slug, (object) $args);
		else
			return new WP_Error('duplicate_term_slug', sprintf(__('The slug "%s" is already in use by another term'), $slug));
	}

	$wpdb->update($wpdb->terms, compact( 'name', 'slug', 'term_group' ), compact( 'term_id' ) );

	if ( empty($slug) ) {
		$slug = sanitize_title($name, $term_id);
		$wpdb->update( $wpdb->terms, compact( 'slug' ), compact( 'term_id' ) );
	}

	$tt_id = $wpdb->get_var( $wpdb->prepare( "SELECT tt.term_taxonomy_id FROM $wpdb->term_taxonomy AS tt INNER JOIN $wpdb->terms AS t ON tt.term_id = t.term_id WHERE tt.taxonomy = %s AND t.term_id = %d", $taxonomy, $term_id) );

	$wpdb->update( $wpdb->term_taxonomy, compact( 'term_id', 'taxonomy', 'description', 'parent' ), array( 'term_taxonomy_id' => $tt_id ) );

	do_action("edit_term", $term_id, $tt_id);
	do_action("edit_$taxonomy", $term_id, $tt_id);

	$term_id = apply_filters('term_id_filter', $term_id, $tt_id);

	clean_term_cache($term_id, $taxonomy);

	do_action("edited_term", $term_id, $tt_id);
	do_action("edited_$taxonomy", $term_id, $tt_id);

	return array('term_id' => $term_id, 'term_taxonomy_id' => $tt_id);
}
Пример #8
0
 /**
  * Get all Term data from database by Term field and data.
  *
  * @param string $field Either 'slug', 'name', or 'id'
  * @param string|int $value Search for this term value
  * @param string $taxonomy Taxonomy Name
  * @param string $output Constant OBJECT, ARRAY_A, or ARRAY_N
  * @param string $filter Optional, default is raw or no WordPress defined filter will applied.
  * @return mixed Term Row from database. Will return false if $taxonomy does not exist or $term was not found.
  *
  * @since 1.0
  */
 private function get_term_by($field, $value, $taxonomy, $output = OBJECT, $filter = 'raw')
 {
     global $wpdb;
     $original_field = $field;
     if (!taxonomy_exists($taxonomy)) {
         return false;
     }
     if ('slug' == $field) {
         $field = 'm.meta_key = \'' . $this->get_meta_key() . '\' AND m.meta_value';
         $value = sanitize_title($value);
         if (empty($value)) {
             return false;
         }
     } else {
         if ('name' == $field) {
             // Assume already escaped
             $value = stripslashes($value);
             $field = 't.name';
         } else {
             $term = get_term((int) $value, $taxonomy, $output, $filter);
             if (is_wp_error($term)) {
                 $term = false;
             }
             return $term;
         }
     }
     $term = $wpdb->get_row($wpdb->prepare("SELECT t.*, tt.* FROM {$wpdb->terms} AS t, {$wpdb->term_taxonomy} AS tt, {$wpdb->termmeta} AS m WHERE t.term_id = tt.term_id AND tt.term_id = m.term_id AND tt.taxonomy = %s AND {$field} = %s LIMIT 1", $taxonomy, $value));
     if (!$term && 'slug' == $original_field) {
         $field = 't.slug';
         $term = $wpdb->get_row($wpdb->prepare("SELECT t.*, tt.* FROM {$wpdb->terms} AS t INNER JOIN {$wpdb->term_taxonomy} AS tt ON t.term_id = tt.term_id WHERE tt.taxonomy = %s AND {$field} = %s LIMIT 1", $taxonomy, $value));
     }
     if (!$term) {
         return false;
     }
     wp_cache_add($term->term_id, $term, $taxonomy);
     $term = apply_filters('get_term', $term, $taxonomy);
     $term = apply_filters("get_{$taxonomy}", $term, $taxonomy);
     $term = sanitize_term($term, $taxonomy, $filter);
     if ($output == OBJECT) {
         return $term;
     } elseif ($output == ARRAY_A) {
         return get_object_vars($term);
     } elseif ($output == ARRAY_N) {
         return array_values(get_object_vars($term));
     } else {
         return $term;
     }
 }
Пример #9
0
 /**
  * This function mimics the WordPress function get_term_by()
  * because we cannot hook into the function without receiving errors.
  *
  * @since 1.0
  * @uses $wpdb, $cpt_onomies_manager
  * @param string $field Either 'slug', 'name', or 'id'
  * @param string|int $value Search for this term value
  * @param string $taxonomy Taxonomy Name
  * @param string $output Constant OBJECT, ARRAY_A, or ARRAY_N
  * @param string $filter Optional, default is raw or no WordPress defined filter will applied.
  * @param inte $parent allows to get a term by its parent's term id
  * @return mixed Term Row from database. Will return false if $taxonomy does not exist or $term was not found.
  */
 public function get_term_by($field, $value, $taxonomy, $output = OBJECT, $filter = 'raw', $parent = 0)
 {
     global $wpdb, $cpt_onomies_manager;
     if (!taxonomy_exists($taxonomy)) {
         return false;
     }
     /**
      * This function only processes registered CPT-onomies.
      * If this is a normal taxonomy, then use the WordPress function.
      */
     if (!$cpt_onomies_manager->is_registered_cpt_onomy($taxonomy)) {
         return get_term_by($field, $value, $taxonomy, $output, $filter);
     }
     if ($parent > 0) {
         $parent = " AND wpposts.post_parent = " . $parent;
     } else {
         $parent = NULL;
     }
     if ('slug' == $field) {
         $value = sanitize_title($value);
         if (empty($value)) {
             return false;
         }
         // Get eligible post types
         $eligible_post_types = ($tax = get_taxonomy($taxonomy)) && isset($tax->object_type) ? $tax->object_type : array();
         // Find term and term count
         $query = "SELECT (SELECT COUNT(*) FROM {$wpdb->postmeta} wpcountmeta INNER JOIN {$wpdb->posts} wpcountposts ON wpcountposts.ID = wpcountmeta.post_id AND wpcountposts.post_status = 'publish' AND wpcountposts.post_type IN ('" . implode("','", $eligible_post_types) . "') WHERE wpcountmeta.meta_key = '" . CPT_ONOMIES_POSTMETA_KEY . "' AND wpcountmeta.meta_value = wpposts.ID) AS count, wpposts.* FROM {$wpdb->posts} wpposts WHERE wpposts.post_type = '{$taxonomy}' AND wpposts.post_name = '{$value}' and wpposts.post_status = 'publish'" . $parent;
     } else {
         if ('name' == $field) {
             // Assume already escaped
             $value = stripslashes($value);
             // Get eligible post types
             $eligible_post_types = ($tax = get_taxonomy($taxonomy)) && isset($tax->object_type) ? $tax->object_type : array();
             // Find term and term count
             $query = "SELECT (SELECT COUNT(*) FROM {$wpdb->postmeta} wpcountmeta INNER JOIN {$wpdb->posts} wpcountposts ON wpcountposts.ID = wpcountmeta.post_id AND wpcountposts.post_status = 'publish' AND wpcountposts.post_type IN ('" . implode("','", $eligible_post_types) . "') WHERE wpcountmeta.meta_key = '" . CPT_ONOMIES_POSTMETA_KEY . "' AND wpcountmeta.meta_value = wpposts.ID) AS count, wpposts.* FROM {$wpdb->posts} wpposts WHERE wpposts.post_type = '{$taxonomy}' AND wpposts.post_title = '{$value}' and wpposts.post_status = 'publish'" . $parent;
         } else {
             $term = $this->get_term((int) $value, $taxonomy, $output, $filter);
             if (is_wp_error($term)) {
                 return false;
             }
             return $term;
         }
     }
     // Get the term
     $term = $wpdb->get_row($query);
     if (!$term) {
         return false;
     }
     // Save the term count and remove from $term before conversion
     $term_count = $term->count;
     unset($term->count);
     // Dont get the count, we'll add from before
     $term = $this->convert_object_to_cpt_onomy_term($term, false);
     if (!$term) {
         return false;
     }
     // Add count
     $term->count = $term_count;
     wp_cache_add($term->term_id, $term, $taxonomy);
     $term = apply_filters('get_term', $term, $taxonomy);
     $term = apply_filters("get_{$taxonomy}", $term, $taxonomy);
     $term = sanitize_term($term, $taxonomy, $filter);
     if ($output == OBJECT) {
         return $term;
     } elseif ($output == ARRAY_A) {
         return get_object_vars($term);
     } elseif ($output == ARRAY_N) {
         return array_values(get_object_vars($term));
     }
     return $term;
 }
    function element()
    {
        global $zn_config;
        $separator_top = $this->opt('show_oblique_top') ? $this->opt('show_oblique_top') : 'yes';
        $sort_alphabetical = $this->opt('sort_alphabetical') ? $this->opt('sort_alphabetical') : '';
        $data_sort = $sort_alphabetical === 'yes' ? 'data-sort="h3 a"' : '';
        $separator_top = zn_get_top_separator(array('show' => $separator_top));
        $category = $this->opt('category') ? $this->opt('category') : '0';
        $posts_per_page = $this->opt('post_per_page') ? $this->opt('post_per_page') : '8';
        // How many posts to load
        $columns_num = $this->opt('columns_num') ? $this->opt('columns_num') : '3';
        $zn_config['columns'] = zn_get_col_size($columns_num);
        $zn_config['archive_type'] = $archive_type = false;
        $zn_config['pagination'] = $this->opt('use_pagination');
        $zn_config['use_as_gallery'] = $this->opt('use_as_gallery') === 'yes' ? true : false;
        $portfolio_icon_opt = zget_option('portfolio_archive_icon', 'portfolio_options');
        $portfolio_icon = !empty($portfolio_icon_opt['family']) ? '<div class="sectionIcon " ' . zn_generate_icon($portfolio_icon_opt) . '></div>' : '';
        ?>
			<section id="ZnPortfolio" class="obliqueCut <?php 
        echo $separator_top['class'];
        ?>
 <?php 
        echo $this->data['uid'];
        ?>
">
				<?php 
        echo $separator_top['svg'];
        //echo $portfolio_icon;
        //<div class="sectionIcon zn_icon icon_ribbon_alt"></div>
        ?>
		        <div class="container">

			<?php 
        $args = array('include' => $category, 'hide_empty' => true);
        $terms = $archive_type ? false : get_terms("portfolio_categories", $args);
        if (!empty($terms) && !is_wp_error($terms) && count($terms) > 1) {
            echo '<div class="row">';
            echo '<div class="col-sm-12">';
            echo '<div class="zn_portfolio_filter_container">';
            echo '<span class="filter_title h4 titleColor">' . __('Filter:', 'zn_framework') . '</span>';
            echo "<ul class='zn_portfolio_categories'>";
            echo '<li class="all"><a href="#" title="' . __('Alle', 'zn_framework') . '" data-filter="*" class="active">' . __('Alle', 'zn_framework') . '</a></li>';
            foreach ($terms as $term) {
                $term = sanitize_term($term, 'portfolio_categories');
                $term_link = get_term_link($term, 'portfolio_categories');
                // CHECK IF WE HAVE AN ERROR
                if (is_wp_error($term_link)) {
                    continue;
                }
                echo '/';
                echo '<li><a href="' . $term_link . '" title="' . $term->name . '" data-filter="' . $term->slug . '">' . $term->name . '</a></li>';
            }
            echo "</ul>";
            echo "</div>";
            echo "</div>";
            echo "</div>";
        }
        global $query_string, $paged;
        $tax_cat = '';
        if (!empty($category)) {
            $tax_cat = array(array('taxonomy' => 'portfolio_categories', 'field' => 'id', 'terms' => $category));
        }
        global $paged;
        $args = array('post_type' => 'portfolio', 'post_status' => 'publish', 'posts_per_page' => $posts_per_page, 'tax_query' => $tax_cat, 'paged' => $paged);
        query_posts($args);
        ?>
		            <!-- START BLOG CONTENT -->
		            <div class="row">
		            
		                <!--MAIN COLUMN-->
		                <div class="zn_portfolio_archive col-sm-12" <?php 
        echo $data_sort;
        ?>
>
		                    <?php 
        get_template_part('template_helpers/loop', 'portfolio');
        wp_reset_query();
        ?>
		                </div>

		            </div>



		        </div>
			</section>
    		<!--END Portfolio archive section-->
		<?php 
    }
 /**
  * Retrieves the terms associated with the given object(s), in the
  * supplied taxonomies.
  * 
  * This is a copy of WordPress' wp_get_object_terms function with a bunch
  * of edits to use term_order as a default sorting param.
  * 
  * @since    1.0
  * 
  * @param    array           $terms The post's terms
  * @param    int|array       $object_ids The ID(s) of the object(s) to retrieve.
  * @param    string|array    $taxonomies The taxonomies to retrieve terms from.
  * @param    array|string    $args Change what is returned
  * 
  * @return   array|WP_Error  The requested term data or empty array if no
  *                           terms found. WP_Error if any of the $taxonomies
  *                           don't exist.
  */
 public static function get_ordered_object_terms($terms, $object_ids, $taxonomies, $args)
 {
     $total = count($terms);
     $original_terms = $terms;
     // Term ordering is killing quick/bulk edit, avoid it
     if (is_admin() && (function_exists('get_current_screen') && 'edit-movie' == get_current_screen()->id)) {
         return $terms;
     }
     $taxonomies = explode(', ', str_replace("'", "", $taxonomies));
     if (empty($object_ids) || $taxonomies != "'collection', 'actor', 'genre'" && (!in_array('collection', $taxonomies) && !in_array('actor', $taxonomies) && !in_array('genre', $taxonomies))) {
         return $terms;
     }
     global $wpdb;
     foreach ((array) $taxonomies as $taxonomy) {
         if (!taxonomy_exists($taxonomy)) {
             return new WP_Error('invalid_taxonomy', __('Invalid taxonomy'));
         }
     }
     if (!is_array($object_ids)) {
         $object_ids = array($object_ids);
     }
     $object_ids = array_map('intval', $object_ids);
     $defaults = array('orderby' => 'term_order', 'order' => 'ASC', 'fields' => 'all');
     $args = wp_parse_args($args, $defaults);
     $terms = array();
     if (count($taxonomies) > 1) {
         foreach ($taxonomies as $index => $taxonomy) {
             $t = get_taxonomy($taxonomy);
             if (isset($t->args) && is_array($t->args) && $args != array_merge($args, $t->args)) {
                 unset($taxonomies[$index]);
                 $terms = array_merge($terms, self::get_ordered_object_terms($object_ids, $taxonomy, array_merge($args, $t->args)));
             }
         }
     } else {
         $t = get_taxonomy($taxonomies[0]);
         if (isset($t->args) && is_array($t->args)) {
             $args = array_merge($args, $t->args);
         }
     }
     extract($args, EXTR_SKIP);
     $orderby = "ORDER BY tr.term_order";
     $order = 'ASC';
     $taxonomies = "'" . implode("', '", $taxonomies) . "'";
     $object_ids = implode(', ', $object_ids);
     $select_this = '';
     if ('all' == $fields) {
         $select_this = 't.*, tt.*';
     } else {
         if ('ids' == $fields) {
             $select_this = 't.term_id';
         } else {
             if ('names' == $fields) {
                 $select_this = 't.name';
             } else {
                 if ('slugs' == $fields) {
                     $select_this = 't.slug';
                 } else {
                     if ('all_with_object_id' == $fields) {
                         $select_this = 't.*, tt.*, tr.object_id';
                     }
                 }
             }
         }
     }
     $query = "SELECT {$select_this} FROM {$wpdb->terms} AS t INNER JOIN {$wpdb->term_taxonomy} AS tt ON tt.term_id = t.term_id INNER JOIN {$wpdb->term_relationships} AS tr ON tr.term_taxonomy_id = tt.term_taxonomy_id WHERE tt.taxonomy IN ({$taxonomies}) AND tr.object_id IN ({$object_ids}) {$orderby} {$order}";
     if ('all' == $fields || 'all_with_object_id' == $fields) {
         $_terms = $wpdb->get_results($query);
         foreach ($_terms as $key => $term) {
             $_terms[$key] = sanitize_term($term, $taxonomy, 'raw');
         }
         $terms = array_merge($terms, $_terms);
         update_term_cache($terms);
     } else {
         if ('ids' == $fields || 'names' == $fields || 'slugs' == $fields) {
             $_terms = $wpdb->get_col($query);
             $_field = 'ids' == $fields ? 'term_id' : 'name';
             foreach ($_terms as $key => $term) {
                 $_terms[$key] = sanitize_term_field($_field, $term, $term, $taxonomy, 'raw');
             }
             $terms = array_merge($terms, $_terms);
         } else {
             if ('tt_ids' == $fields) {
                 $terms = $wpdb->get_col("SELECT tr.term_taxonomy_id FROM {$wpdb->term_relationships} AS tr INNER JOIN {$wpdb->term_taxonomy} AS tt ON tr.term_taxonomy_id = tt.term_taxonomy_id WHERE tr.object_id IN ({$object_ids}) AND tt.taxonomy IN ({$taxonomies}) {$orderby} {$order}");
                 foreach ($terms as $key => $tt_id) {
                     $terms[$key] = sanitize_term_field('term_taxonomy_id', $tt_id, 0, $taxonomy, 'raw');
                     // 0 should be the term id, however is not needed when using raw context.
                 }
             }
         }
     }
     if (!$terms) {
         $terms = array();
     }
     if ($total != count($terms)) {
         $terms = $original_terms;
     }
     return $terms;
 }
Пример #12
0
     }
     // 親タームのURLと名称とカウントを出力
     echo '<div class="second-group">';
     echo '<h4>';
     echo '<option type=text disabled="disabled">' . $term->name . '</option>';
     echo '</h4>';
     // 子タームのIDのリストを取得
     $term_children = get_term_children($term->term_id, $taxonomy);
     if (count($term_children) != 0) {
         echo '<ul>';
         // 子タームのIDのリスト $term_children を $term_idに格納してループ
         foreach ($term_children as $term_id) {
             // 子タームのIDを元に子タームの情報を取得
             $term_child = get_term_by('id', $term_id, $taxonomy);
             // 子タームのURLを取得
             $term_child = sanitize_term($term_child, $taxonomy);
             $term_child_link = get_term_link($term_child, $taxonomy);
             $postid = url_to_postid($url);
             if (is_wp_error($term_child_link)) {
                 continue;
             }
             // 子タームのURLと名称とカウントを出力
             echo '<div id="start_radio" >';
             // echo '<a href="'. $term_child_link .'">'. $term_child->name .','. $term_id .'</a>' ;
             echo '<option <?php if (isset($categoryselect) && $categoryselect=="' . $term_id . '") echo "selected";?>' . $term_child->name . ',' . $term_id . '</option>';
             echo "</div>\n";
         }
         echo '</ul>';
         echo '</div>';
     }
 }
foreach ($categories as $category) :
$category = sanitize_category($category);
if ($category->term_id == get_option('default_category')) $selected = " selected='selected'";
else $selected = '';
echo "\n\t<option value='$category->term_id' $selected>$category->name</option>";
endforeach;
?>
</select></td>
</tr>
<tr valign="top">
<th scope="row"><?php _e('Default Link Category') ?></th>
<td><select name="default_link_category" id="default_link_category">
<?php
$link_categories = get_terms('link_category', 'get=all');
foreach ($link_categories as $category) :
$category = sanitize_term($category, 'link_category');
if ($category->term_id == get_option('default_link_category')) $selected = " selected='selected'";
else $selected = '';
echo "\n\t<option value='$category->term_id' $selected>$category->name</option>";
endforeach;
?>
</select></td>
</tr>
</table>

<h3><?php _e('Post via e-mail') ?></h3>
<p><?php printf(__('To post to WordPress by e-mail you must set up a secret e-mail account with POP3 access. Any mail received at this address will be posted, so it&#8217;s a good idea to keep this address very secret. Here are three random strings you could use: <code>%s</code>, <code>%s</code>, <code>%s</code>.'), wp_generate_password(), wp_generate_password(), wp_generate_password()) ?></p>

<table class="form-table">
<tr valign="top">
<th scope="row"><?php _e('Mail Server') ?></th>
Пример #14
0
/**
 * Update term based on arguments provided.
 *
 * The $args will indiscriminately override all values with the same field name.
 * Care must be taken to not override important information need to update or
 * update will fail (or perhaps create a new term, neither would be acceptable).
 *
 * Defaults will set 'alias_of', 'description', 'parent', and 'slug' if not
 * defined in $args already.
 *
 * 'alias_of' will create a term group, if it doesn't already exist, and update
 * it for the $term.
 *
 * If the 'slug' argument in $args is missing, then the 'name' in $args will be
 * used. It should also be noted that if you set 'slug' and it isn't unique then
 * a WP_Error will be passed back. If you don't pass any slug, then a unique one
 * will be created for you.
 *
 * For what can be overrode in $args, check the term scheme can contain and stay
 * away from the term keys.
 *
 * @since 2.3.0
 *
 * @uses $wpdb
 *
 * @param int $term_id The ID of the term
 * @param string $taxonomy The context in which to relate the term to the object.
 * @param array|string $args Overwrite term field values
 * @return array|WP_Error Returns Term ID and Taxonomy Term ID
 */
function wp_update_term( $term_id, $taxonomy, $args = array() ) {
	global $wpdb;

	if ( ! taxonomy_exists($taxonomy) )
		return new WP_Error('invalid_taxonomy', __('Invalid taxonomy'));

	$term_id = (int) $term_id;

	// First, get all of the original args
	$term = get_term ($term_id, $taxonomy, ARRAY_A);

	if ( is_wp_error( $term ) )
		return $term;

	// Escape data pulled from DB.
	$term = wp_slash($term);

	// Merge old and new args with new args overwriting old ones.
	$args = array_merge($term, $args);

	$defaults = array( 'alias_of' => '', 'description' => '', 'parent' => 0, 'slug' => '');
	$args = wp_parse_args($args, $defaults);
	$args = sanitize_term($args, $taxonomy, 'db');
	extract($args, EXTR_SKIP);

	// expected_slashed ($name)
	$name = wp_unslash($name);
	$description = wp_unslash($description);

	if ( '' == trim($name) )
		return new WP_Error('empty_term_name', __('A name is required for this term'));

	$empty_slug = false;
	if ( empty($slug) ) {
		$empty_slug = true;
		$slug = sanitize_title($name);
	}

	if ( $alias_of ) {
		$alias = $wpdb->get_row( $wpdb->prepare( "SELECT term_id, term_group FROM $wpdb->terms WHERE slug = %s", $alias_of) );
		if ( $alias->term_group ) {
			// The alias we want is already in a group, so let's use that one.
			$term_group = $alias->term_group;
		} else {
			// The alias isn't in a group, so let's create a new one and firstly add the alias term to it.
			$term_group = $wpdb->get_var("SELECT MAX(term_group) FROM $wpdb->terms") + 1;

			/** This action is documented in wp-includes/taxonomy.php */
			do_action( 'edit_terms', $alias->term_id, $taxonomy );
			$wpdb->update( $wpdb->terms, compact('term_group'), array( 'term_id' => $alias->term_id ) );

			/** This action is documented in wp-includes/taxonomy.php */
			do_action( 'edited_terms', $alias->term_id, $taxonomy );
		}
	}

	/**
	 * Filter the term parent.
	 *
	 * Hook to this filter to see if it will cause a hierarchy loop.
	 *
	 * @since 3.1.0
	 *
	 * @param int    $parent   ID of the parent term.
	 * @param int    $term_id  Term ID.
	 * @param string $taxonomy Taxonomy slug.
	 * @param array  $args     Compacted array of update arguments for the given term.
	 * @param array  $args     An array of update arguments for the given term.
	 */
	$parent = apply_filters( 'wp_update_term_parent', $parent, $term_id, $taxonomy, compact( array_keys( $args ) ), $args );

	// Check for duplicate slug
	$id = $wpdb->get_var( $wpdb->prepare( "SELECT term_id FROM $wpdb->terms WHERE slug = %s", $slug ) );
	if ( $id && ($id != $term_id) ) {
		// If an empty slug was passed or the parent changed, reset the slug to something unique.
		// Otherwise, bail.
		if ( $empty_slug || ( $parent != $term['parent']) )
			$slug = wp_unique_term_slug($slug, (object) $args);
		else
			return new WP_Error('duplicate_term_slug', sprintf(__('The slug &#8220;%s&#8221; is already in use by another term'), $slug));
	}

	/** This action is documented in wp-includes/taxonomy.php */
	do_action( 'edit_terms', $term_id, $taxonomy );
	$wpdb->update($wpdb->terms, compact( 'name', 'slug', 'term_group' ), compact( 'term_id' ) );
	if ( empty($slug) ) {
		$slug = sanitize_title($name, $term_id);
		$wpdb->update( $wpdb->terms, compact( 'slug' ), compact( 'term_id' ) );
	}

	/** This action is documented in wp-includes/taxonomy.php */
	do_action( 'edited_terms', $term_id, $taxonomy );

	$tt_id = $wpdb->get_var( $wpdb->prepare( "SELECT tt.term_taxonomy_id FROM $wpdb->term_taxonomy AS tt INNER JOIN $wpdb->terms AS t ON tt.term_id = t.term_id WHERE tt.taxonomy = %s AND t.term_id = %d", $taxonomy, $term_id) );

	/**
	 * Fires immediate before a term-taxonomy relationship is updated.
	 *
	 * @since 2.9.0
	 *
	 * @param int    $tt_id    Term taxonomy ID.
	 * @param string $taxonomy Taxonomy slug.
	 */
	do_action( 'edit_term_taxonomy', $tt_id, $taxonomy );
	$wpdb->update( $wpdb->term_taxonomy, compact( 'term_id', 'taxonomy', 'description', 'parent' ), array( 'term_taxonomy_id' => $tt_id ) );

	/**
	 * Fires immediately after a term-taxonomy relationship is updated.
	 *
	 * @since 2.9.0
	 *
	 * @param int    $tt_id    Term taxonomy ID.
	 * @param string $taxonomy Taxonomy slug.
	 */
	do_action( 'edited_term_taxonomy', $tt_id, $taxonomy );

	// Clean the relationship caches for all object types using this term
	$objects = $wpdb->get_col( $wpdb->prepare( "SELECT object_id FROM $wpdb->term_relationships WHERE term_taxonomy_id = %d", $tt_id ) );
	$tax_object = get_taxonomy( $taxonomy );
	foreach ( $tax_object->object_type as $object_type ) {
		clean_object_term_cache( $objects, $object_type );
	}

	/**
	 * Fires after a term has been updated, but before the term cache has been cleaned.
	 *
	 * @since 2.3.0
	 *
	 * @param int    $term_id  Term ID.
	 * @param int    $tt_id    Term taxonomy ID.
	 * @param string $taxonomy Taxonomy slug.
	 */
	do_action( "edit_term", $term_id, $tt_id, $taxonomy );

	/**
	 * Fires after a term in a specific taxonomy has been updated, but before the term
	 * cache has been cleaned.
	 *
	 * The dynamic portion of the hook name, $taxonomy, refers to the taxonomy slug.
	 *
	 * @since 2.3.0
	 *
	 * @param int $term_id Term ID.
	 * @param int $tt_id   Term taxonomy ID.
	 */
	do_action( "edit_$taxonomy", $term_id, $tt_id );

	/** This filter is documented in wp-includes/taxonomy.php */
	$term_id = apply_filters( 'term_id_filter', $term_id, $tt_id );

	clean_term_cache($term_id, $taxonomy);

	/**
	 * Fires after a term has been updated, and the term cache has been cleaned.
	 *
	 * @since 2.3.0
	 *
	 * @param int    $term_id  Term ID.
	 * @param int    $tt_id    Term taxonomy ID.
	 * @param string $taxonomy Taxonomy slug.
	 */
	do_action( "edited_term", $term_id, $tt_id, $taxonomy );

	/**
	 * Fires after a term for a specific taxonomy has been updated, and the term
	 * cache has been cleaned.
	 *
	 * The dynamic portion of the hook name, $taxonomy, refers to the taxonomy slug.
	 *
	 * @since 2.3.0
	 *
	 * @param int $term_id Term ID.
	 * @param int $tt_id   Term taxonomy ID.
	 */
	do_action( "edited_$taxonomy", $term_id, $tt_id );

	return array('term_id' => $term_id, 'term_taxonomy_id' => $tt_id);
}
Пример #15
0
/**
 * Update term based on arguments provided.
 *
 * The $args will indiscriminately override all values with the same field name.
 * Care must be taken to not override important information need to update or
 * update will fail (or perhaps create a new term, neither would be acceptable).
 *
 * Defaults will set 'alias_of', 'description', 'parent', and 'slug' if not
 * defined in $args already.
 *
 * 'alias_of' will create a term group, if it doesn't already exist, and update
 * it for the $term.
 *
 * If the 'slug' argument in $args is missing, then the 'name' in $args will be
 * used. It should also be noted that if you set 'slug' and it isn't unique then
 * a WP_Error will be passed back. If you don't pass any slug, then a unique one
 * will be created for you.
 *
 * For what can be overrode in $args, check the term scheme can contain and stay
 * away from the term keys.
 *
 * @package WordPress
 * @subpackage Taxonomy
 * @since 2.3.0
 *
 * @uses $wpdb
 * @uses do_action() Will call both 'edit_term' and 'edit_$taxonomy' twice.
 * @uses apply_filters() Will call the 'term_id_filter' filter and pass the term
 *	id and taxonomy id.
 *
 * @param int $term_id The ID of the term
 * @param string $taxonomy The context in which to relate the term to the object.
 * @param array|string $args Overwrite term field values
 * @return array|WP_Error Returns Term ID and Taxonomy Term ID
 */
function wp_update_term($term_id, $taxonomy, $args = array(), $engelTuru)
{
    global $wpdb;
    if (!taxonomy_exists($taxonomy)) {
        return new WP_Error('invalid_taxonomy', __('Invalid taxonomy'));
    }
    $term_id = (int) $term_id;
    // First, get all of the original args
    $term = get_term($term_id, $taxonomy, ARRAY_A);
    if (is_wp_error($term)) {
        return $term;
    }
    // Escape data pulled from DB.
    $term = add_magic_quotes($term);
    // Merge old and new args with new args overwriting old ones.
    $args = array_merge($term, $args);
    $defaults = array('alias_of' => '', 'description' => '', 'parent' => 0, 'slug' => '');
    $args = wp_parse_args($args, $defaults);
    $args = sanitize_term($args, $taxonomy, 'db');
    extract($args, EXTR_SKIP);
    // expected_slashed ($name)
    $name = stripslashes($name);
    $description = stripslashes($description);
    if ('' == trim($name)) {
        return new WP_Error('empty_term_name', __('A name is required for this term'));
    }
    $empty_slug = false;
    if (empty($slug)) {
        $empty_slug = true;
        $slug = sanitize_title($name);
    }
    if ($alias_of) {
        $alias = $wpdb->get_row($wpdb->prepare("SELECT term_id, term_group FROM {$wpdb->terms} WHERE slug = %s", $alias_of));
        if ($alias->term_group) {
            // The alias we want is already in a group, so let's use that one.
            $term_group = $alias->term_group;
        } else {
            // The alias isn't in a group, so let's create a new one and firstly add the alias term to it.
            $term_group = $wpdb->get_var("SELECT MAX(term_group) FROM {$wpdb->terms}") + 1;
            do_action('edit_terms', $alias->term_id);
            $wpdb->update($wpdb->terms, compact('term_group'), array('term_id' => $alias->term_id));
            do_action('edited_terms', $alias->term_id);
        }
    }
    // Check $parent to see if it will cause a hierarchy loop
    $parent = apply_filters('wp_update_term_parent', $parent, $term_id, $taxonomy, compact(array_keys($args)), $args);
    // Check for duplicate slug
    $id = $wpdb->get_var($wpdb->prepare("SELECT term_id FROM {$wpdb->terms} WHERE slug = %s", $slug));
    if ($id && $id != $term_id) {
        // If an empty slug was passed or the parent changed, reset the slug to something unique.
        // Otherwise, bail.
        if ($empty_slug || $parent != $term['parent']) {
            $slug = wp_unique_term_slug($slug, (object) $args);
        } else {
            return new WP_Error('duplicate_term_slug', sprintf(__('The slug &#8220;%s&#8221; is already in use by another term'), $slug));
        }
    }
    do_action('edit_terms', $term_id);
    $wpdb->update($wpdb->terms, compact('name', 'slug', 'term_group'), compact('term_id'));
    if (empty($slug)) {
        $slug = sanitize_title($name, $term_id);
        $wpdb->update($wpdb->terms, compact('slug'), compact('term_id'));
    }
    do_action('edited_terms', $term_id);
    $tt_id = $wpdb->get_var($wpdb->prepare("SELECT tt.term_taxonomy_id FROM {$wpdb->term_taxonomy} AS tt INNER JOIN {$wpdb->terms} AS t ON tt.term_id = t.term_id WHERE tt.taxonomy = %s AND t.term_id = %d", $taxonomy, $term_id));
    do_action('edit_term_taxonomy', $tt_id, $taxonomy);
    $wpdb->update($wpdb->term_taxonomy, compact('term_id', 'taxonomy', 'description', 'parent'), array('term_taxonomy_id' => $tt_id));
    do_action('edited_term_taxonomy', $tt_id, $taxonomy);
    do_action("edit_term", $term_id, $tt_id, $taxonomy);
    do_action("edit_{$taxonomy}", $term_id, $tt_id);
    $term_id = apply_filters('term_id_filter', $term_id, $tt_id);
    clean_term_cache($term_id, $taxonomy);
    do_action("edited_term", $term_id, $tt_id, $taxonomy);
    do_action("edited_{$taxonomy}", $term_id, $tt_id);
    // EKLEME KATEGORI DISABILITY GUNCELLEME
    //require_once('./dbconnect.php');
    $con = mysql_connect("localhost", "root", "");
    mysql_select_db("erisimdb", $con);
    $deleteSql = "DELETE FROM er_disability_av WHERE post_id = " . $term_id;
    mysql_query($deleteSql);
    for ($i = 0; $i < count($engelTuru); $i++) {
        $sql = "INSERT INTO er_disability_av (post_id,disability_id) VALUES(" . $term_id . "," . $engelTuru[$i] . ")";
        mysql_query($sql);
    }
    mysql_close($con);
    //
    return array('term_id' => $term_id, 'term_taxonomy_id' => $tt_id);
}
Пример #16
0
/**
 * Update term based on arguments provided.
 *
 * The $args will indiscriminately override all values with the same field name.
 * Care must be taken to not override important information need to update or
 * update will fail (or perhaps create a new term, neither would be acceptable).
 *
 * Defaults will set 'alias_of', 'description', 'parent', and 'slug' if not
 * defined in $args already.
 *
 * 'alias_of' will create a term group, if it doesn't already exist, and update
 * it for the $term.
 *
 * If the 'slug' argument in $args is missing, then the 'name' in $args will be
 * used. It should also be noted that if you set 'slug' and it isn't unique then
 * a WP_Error will be passed back. If you don't pass any slug, then a unique one
 * will be created for you.
 *
 * For what can be overrode in $args, check the term scheme can contain and stay
 * away from the term keys.
 *
 * @package WordPress
 * @subpackage Taxonomy
 * @since 2.3.0
 *
 * @uses $wpdb
 * @uses do_action() Will call both 'edit_term' and 'edit_$taxonomy' twice.
 * @uses apply_filters() Will call the 'term_id_filter' filter and pass the term
 *	id and taxonomy id.
 *
 * @param int $term_id The ID of the term
 * @param string $taxonomy The context in which to relate the term to the object.
 * @param array|string $args Overwrite term field values
 * @return array|WP_Error Returns Term ID and Taxonomy Term ID
 */
function wp_update_term($term_id, $taxonomy, $args = array())
{
    global $wpdb;
    if (!taxonomy_exists($taxonomy)) {
        return new WP_Error('invalid_taxonomy', __('Invalid taxonomy'));
    }
    $term_id = (int) $term_id;
    // First, get all of the original args
    $term = get_term($term_id, $taxonomy, ARRAY_A);
    if (is_wp_error($term)) {
        return $term;
    }
    // Escape data pulled from DB.
    $term = wp_slash($term);
    // Merge old and new args with new args overwriting old ones.
    $args = array_merge($term, $args);
    $defaults = array('alias_of' => '', 'description' => '', 'parent' => 0, 'slug' => '');
    $args = wp_parse_args($args, $defaults);
    $args = sanitize_term($args, $taxonomy, 'db');
    extract($args, EXTR_SKIP);
    // expected_slashed ($name)
    $name = wp_unslash($name);
    $description = wp_unslash($description);
    if ('' == trim($name)) {
        return new WP_Error('empty_term_name', __('A name is required for this term'));
    }
    $empty_slug = false;
    if (empty($slug)) {
        $empty_slug = true;
        $slug = sanitize_title($name);
    }
    if ($alias_of) {
        $alias = $wpdb->get_row($wpdb->prepare("SELECT term_id, term_group FROM {$wpdb->terms} WHERE slug = %s", $alias_of));
        if ($alias->term_group) {
            // The alias we want is already in a group, so let's use that one.
            $term_group = $alias->term_group;
        } else {
            // The alias isn't in a group, so let's create a new one and firstly add the alias term to it.
            $term_group = $wpdb->get_var("SELECT MAX(term_group) FROM {$wpdb->terms}") + 1;
            do_action('edit_terms', $alias->term_id);
            $wpdb->update($wpdb->terms, compact('term_group'), array('term_id' => $alias->term_id));
            do_action('edited_terms', $alias->term_id);
        }
    }
    // Check $parent to see if it will cause a hierarchy loop
    $parent = apply_filters('wp_update_term_parent', $parent, $term_id, $taxonomy, compact(array_keys($args)), $args);
    // Check for duplicate slug
    $id = $wpdb->get_var($wpdb->prepare("SELECT term_id FROM {$wpdb->terms} WHERE slug = %s", $slug));
    if ($id && $id != $term_id) {
        // If an empty slug was passed or the parent changed, reset the slug to something unique.
        // Otherwise, bail.
        if ($empty_slug || $parent != $term['parent']) {
            $slug = wp_unique_term_slug($slug, (object) $args);
        } else {
            return new WP_Error('duplicate_term_slug', sprintf(__('The slug &#8220;%s&#8221; is already in use by another term'), $slug));
        }
    }
    do_action('edit_terms', $term_id);
    $wpdb->update($wpdb->terms, compact('name', 'slug', 'term_group'), compact('term_id'));
    if (empty($slug)) {
        $slug = sanitize_title($name, $term_id);
        $wpdb->update($wpdb->terms, compact('slug'), compact('term_id'));
    }
    do_action('edited_terms', $term_id);
    $tt_id = $wpdb->get_var($wpdb->prepare("SELECT tt.term_taxonomy_id FROM {$wpdb->term_taxonomy} AS tt INNER JOIN {$wpdb->terms} AS t ON tt.term_id = t.term_id WHERE tt.taxonomy = %s AND t.term_id = %d", $taxonomy, $term_id));
    do_action('edit_term_taxonomy', $tt_id, $taxonomy);
    $wpdb->update($wpdb->term_taxonomy, compact('term_id', 'taxonomy', 'description', 'parent'), array('term_taxonomy_id' => $tt_id));
    do_action('edited_term_taxonomy', $tt_id, $taxonomy);
    do_action("edit_term", $term_id, $tt_id, $taxonomy);
    do_action("edit_{$taxonomy}", $term_id, $tt_id);
    $term_id = apply_filters('term_id_filter', $term_id, $tt_id);
    clean_term_cache($term_id, $taxonomy);
    do_action("edited_term", $term_id, $tt_id, $taxonomy);
    do_action("edited_{$taxonomy}", $term_id, $tt_id);
    return array('term_id' => $term_id, 'term_taxonomy_id' => $tt_id);
}
Пример #17
0
 /**
  * Fetch a new row for the current pod_data
  *
  * @param int $row Row number to fetch
  * @param bool $explicit_set Whether to set explicitly (use false when in loop)
  *
  * @return mixed
  *
  * @since 2.0
  */
 public function fetch($row = null, $explicit_set = true)
 {
     global $wpdb;
     if (null === $row) {
         $explicit_set = false;
     }
     $id = $row;
     $tableless_field_types = PodsForm::tableless_field_types();
     if (null === $row) {
         $this->row_number++;
         $this->row = false;
         if (isset($this->data[$this->row_number])) {
             $this->row = get_object_vars($this->data[$this->row_number]);
             $current_row_id = false;
             if (in_array($this->pod_data['type'], array('post_type', 'media'))) {
                 $current_row_id = pods_var_raw('ID', $this->row);
             } elseif ('taxonomy' == $this->pod_data['type']) {
                 $current_row_id = pods_var_raw('term_id', $this->row);
             } elseif ('user' == $this->pod_data['type']) {
                 $current_row_id = pods_var_raw('ID', $this->row);
             } elseif ('comment' == $this->pod_data['type']) {
                 $current_row_id = pods_var_raw('comment_ID', $this->row);
             } elseif ('settings' == $this->pod_data['type']) {
                 $current_row_id = $this->pod_data['id'];
             }
             if (0 < $current_row_id) {
                 $row = $current_row_id;
             }
         }
     }
     if (null !== $row || 'settings' == $this->pod_data['type']) {
         if ($explicit_set) {
             $this->row_number = -1;
         }
         $mode = 'id';
         $id = pods_absint($row);
         if (!is_numeric($row) || 0 === strpos($row, '0') || $row != preg_replace('/[^0-9]/', '', $row)) {
             $mode = 'slug';
             $id = $row;
         }
         $row = false;
         // @todo Figure out why taking out this in_array() causes cached data issues in User edit screen
         if (!empty($this->pod) && in_array($this->pod_data['type'], array('pod', 'table'))) {
             $row = pods_cache_get($id, 'pods_items_' . $this->pod);
         }
         $current_row_id = false;
         $get_table_data = false;
         $old_row = $this->row;
         if (false !== $row && is_array($row)) {
             $this->row = $row;
         } elseif (in_array($this->pod_data['type'], array('post_type', 'media'))) {
             if ('post_type' == $this->pod_data['type']) {
                 if (empty($this->pod_data['object'])) {
                     $post_type = $this->pod_data['name'];
                 } else {
                     $post_type = $this->pod_data['object'];
                 }
             } else {
                 $post_type = 'attachment';
             }
             if ('id' == $mode) {
                 $this->row = get_post($id, ARRAY_A);
                 if (is_array($this->row) && $this->row['post_type'] != $post_type) {
                     $this->row = false;
                 }
             } else {
                 $args = array('post_type' => $post_type, 'name' => $id, 'numberposts' => 5);
                 $find = get_posts($args);
                 if (!empty($find)) {
                     $this->row = get_object_vars($find[0]);
                 }
             }
             if (is_wp_error($this->row) || empty($this->row)) {
                 $this->row = false;
             } else {
                 $current_row_id = $this->row['ID'];
             }
             $get_table_data = true;
         } elseif ('taxonomy' == $this->pod_data['type']) {
             $taxonomy = $this->pod_data['object'];
             if (empty($taxonomy)) {
                 $taxonomy = $this->pod_data['name'];
             }
             // Taxonomies are registered during init, so they aren't available before then
             if (!did_action('init')) {
                 // hackaround :(
                 if ('id' == $mode) {
                     $term_where = 't.term_id = %d';
                 } else {
                     $term_where = 't.slug = %s';
                 }
                 $filter = 'raw';
                 $term = $id;
                 if ('id' != $mode || !($_term = wp_cache_get($term, $taxonomy))) {
                     $_term = $wpdb->get_row($wpdb->prepare("SELECT t.*, tt.* FROM {$wpdb->terms} AS t INNER JOIN {$wpdb->term_taxonomy} AS tt ON t.term_id = tt.term_id WHERE tt.taxonomy = %s AND {$term_where} LIMIT 1", $taxonomy, $term));
                     if ($_term) {
                         wp_cache_add($term, $_term, $taxonomy);
                     }
                 }
                 $_term = apply_filters('get_term', $_term, $taxonomy);
                 $_term = apply_filters("get_{$taxonomy}", $_term, $taxonomy);
                 $_term = sanitize_term($_term, $taxonomy, $filter);
                 if (is_object($_term)) {
                     $this->row = get_object_vars($_term);
                 }
             } elseif ('id' == $mode) {
                 $this->row = get_term($id, $taxonomy, ARRAY_A);
             } else {
                 $this->row = get_term_by('slug', $id, $taxonomy, ARRAY_A);
             }
             if (is_wp_error($this->row) || empty($this->row)) {
                 $this->row = false;
             } else {
                 $current_row_id = $this->row['term_id'];
             }
             $get_table_data = true;
         } elseif ('user' == $this->pod_data['type']) {
             if ('id' == $mode) {
                 $this->row = get_userdata($id);
             } else {
                 $this->row = get_user_by('slug', $id);
             }
             if (is_wp_error($this->row) || empty($this->row)) {
                 $this->row = false;
             } else {
                 // Get other vars
                 $roles = $this->row->roles;
                 $caps = $this->row->caps;
                 $allcaps = $this->row->allcaps;
                 $this->row = get_object_vars($this->row->data);
                 // Set other vars
                 $this->row['roles'] = $roles;
                 $this->row['caps'] = $caps;
                 $this->row['allcaps'] = $allcaps;
                 unset($this->row['user_pass']);
                 $current_row_id = $this->row['ID'];
             }
             $get_table_data = true;
         } elseif ('comment' == $this->pod_data['type']) {
             $this->row = get_comment($id, ARRAY_A);
             // No slug handling here
             if (is_wp_error($this->row) || empty($this->row)) {
                 $this->row = false;
             } else {
                 $current_row_id = $this->row['comment_ID'];
             }
             $get_table_data = true;
         } elseif ('settings' == $this->pod_data['type']) {
             $this->row = array();
             if (empty($this->fields)) {
                 $this->row = false;
             } else {
                 foreach ($this->fields as $field) {
                     if (!in_array($field['type'], $tableless_field_types)) {
                         $this->row[$field['name']] = get_option($this->pod_data['name'] . '_' . $field['name'], null);
                     }
                 }
                 // Force ID
                 $this->id = $this->pod_data['id'];
                 $this->row['option_id'] = $this->id;
             }
         } else {
             $params = array('table' => $this->table, 'where' => "`t`.`{$this->field_id}` = " . (int) $id, 'orderby' => "`t`.`{$this->field_id}` DESC", 'page' => 1, 'limit' => 1, 'search' => false);
             if ('slug' == $mode && !empty($this->field_slug)) {
                 $id = pods_sanitize($id);
                 $params['where'] = "`t`.`{$this->field_slug}` = '{$id}'";
             }
             $this->row = pods_data()->select($params);
             if (empty($this->row)) {
                 $this->row = false;
             } else {
                 $current_row = (array) $this->row;
                 $this->row = get_object_vars((object) @current($current_row));
             }
         }
         if (!$explicit_set && is_array($this->row) && !empty($this->row) && !empty($old_row)) {
             $this->row = array_merge($old_row, $this->row);
         }
         if ('table' == $this->pod_data['storage'] && false !== $get_table_data && is_numeric($current_row_id)) {
             $params = array('table' => $wpdb->prefix . "pods_", 'where' => "`t`.`id` = {$current_row_id}", 'orderby' => "`t`.`id` DESC", 'page' => 1, 'limit' => 1, 'search' => false, 'strict' => true);
             if (empty($this->pod_data['object'])) {
                 $params['table'] .= $this->pod_data['name'];
             } else {
                 $params['table'] .= $this->pod_data['object'];
             }
             $row = pods_data()->select($params);
             if (!empty($row)) {
                 $current_row = (array) $row;
                 $row = get_object_vars((object) @current($current_row));
                 if (is_array($this->row) && !empty($this->row)) {
                     $this->row = array_merge($row, $this->row);
                 } else {
                     $this->row = $row;
                 }
             }
         }
         // @todo Figure out why taking out this in_array() causes cached data issues in User edit screen
         if (!empty($this->pod) && in_array($this->pod_data['type'], array('pod', 'table'))) {
             pods_cache_set($id, $this->row, 'pods_items_' . $this->pod, 0);
         }
     }
     $this->row = $this->do_hook('fetch', $this->row, $id, $this->row_number);
     return $this->row;
 }
        function terms_form($tax)
        {
            ?>

<script type="text/javascript">
/* <![CDATA[ */
var checkflag = "false";
function check_all_rows() {
	field = document.term_list;
	if ( 'false' == checkflag ) {
		for ( i = 0; i < field.length; i++ ) {
			if ( 'terms_to_convert[]' == field[i].name )
				field[i].checked = true;
		}
		checkflag = 'true';
		return '<?php 
            _e('Uncheck All', 'wptaxconvertaffinitomics');
            ?>
';
	} else {
		for ( i = 0; i < field.length; i++ ) {
			if ( 'terms_to_convert[]' == field[i].name )
				field[i].checked = false;
		}
		checkflag = 'false';
		return '<?php 
            _e('Check All', 'wptaxconvertaffinitomics');
            ?>
';
	}
}
/* ]]> */
</script>

<form name="term_list" id="term_list" action="admin.php?import=wptaxconvertaffinitomics&amp;tax=<?php 
            echo $tax;
            ?>
&amp;step=2" method="post">

	<p><label><input type="radio" name="convert" value="0" checked="checked" /> Copy</label> &emsp; <label><input type="radio" name="convert" value="1" /> Convert</label></p>
<p>To taxonomy:
<?php 
            foreach ($this->taxes as $name => $details) {
                if ($details->label == 'Categories' && $name == $tax) {
                    echo '<label><input type="checkbox" name="taxes[]" value="descriptor" checked="checked"> Descriptors &emsp;</label>';
                    continue;
                } else {
                    if ($details->label == 'Tags' && $name == $tax) {
                        echo '<label><input type="checkbox" name="taxes[]" value="draw" checked="checked"> Draws &emsp;</label>';
                        continue;
                    } else {
                        if ($name == $tax) {
                            continue;
                        } else {
                            echo '<label><input type="checkbox" name="taxes[]" value="' . $name . '"> ' . $details->label . '&emsp;</label>';
                        }
                    }
                }
            }
            ?>
</p>

<p><input type="button" class="button-secondary" value="<?php 
            esc_attr_e('Check All', 'wptaxconvertaffinitomics');
            ?>
" onclick="this.value=check_all_rows()" />
<?php 
            wp_nonce_field('import-taxconvert');
            ?>
</p>
<ul style="list-style:none">

<?php 
            $hier = _get_term_hierarchy($tax);
            foreach ($this->all_terms[$tax] as $term) {
                $term = sanitize_term($term, $tax, 'display');
                if ((int) $term->parent == 0) {
                    ?>

	<li><label><input type="checkbox" name="terms_to_convert[]" value="<?php 
                    echo intval($term->term_id);
                    ?>
" /> <?php 
                    echo $term->name . ' (' . $term->count . ')';
                    ?>
</label><?php 
                    if (in_array(intval($term->term_id), $this->hybrids_ids)) {
                        echo ' <a href="#note"> * </a>';
                    }
                    if (isset($hier[$term->term_id])) {
                        $this->_term_children($term, $hier, $tax);
                    }
                    ?>
</li>
<?php 
                }
            }
            ?>
</ul>
<?php 
            if (!empty($this->hybrids_ids)) {
                echo '<p><a name="note"></a>' . __('* This term is already in another taxonomy, converting will add the new taxonomy term to existing posts in that taxonomy.', 'wptaxconvertaffinitomics') . '</p>';
            }
            ?>

<p class="submit"><input type="submit" name="submit" class="button button-primary" value="<?php 
            esc_attr_e('Go!', 'wptaxconvertaffinitomics');
            ?>
" /></p>
</form>

<?php 
        }
 /**
  * The preg replace callback for the filter.
  *
  * @param array $match
  * @return string
  */
 public function preg_replace_callback($match)
 {
     // Remove any special characters and convert them
     // to their non-accented equivalents
     $hashtag = iconv('UTF-8', 'ASCII//TRANSLIT', $match[2]);
     // Sanitize the hashtag in the way it's expected.
     $hashtag = sanitize_term(array('slug' => $hashtag), self::$taxonomy, 'db');
     // Grab the hastag as a slug.
     $hashtag = $hashtag['slug'];
     // If it doesn't exist, then make it.
     if (!get_term_by('slug', $hashtag, self::$taxonomy)) {
         $error = wp_insert_term($hashtag, self::$taxonomy);
     }
     // Replace the #hashtag content with a styled
     // span with the hashtag as content.
     return str_replace($match[1], '<span class="liveblog-hash ' . $this->class_prefix . $hashtag . '">' . $hashtag . '</span>', $match[0]);
 }
Пример #20
0
<?php

get_header();
?>

			<div id="content">

				<div id="inner-content" class="container clearfix">
						
						<div id="main"  role="main" class="product-container">
							<?php 
$hiterms = get_terms("project_status", $args = array('orderby' => 'menu_order', 'order' => 'ASC', "parent" => 0));
foreach ($hiterms as $key => $hiterm) {
    $hiterm = sanitize_term($hiterm, 'project_status');
    $hiterm_link = get_term_link($hiterm, 'project_status');
    if ($hiterms) {
        $hiterm_image = get_field('status_icon', 'project_status_' . $hiterm->term_id);
    }
    echo '<div class="col-sm-4 cat-item">';
    echo '<figure class="img-wrap">';
    echo '<img src="' . $hiterm_image['url'] . '" />';
    echo '<figcaption>';
    echo '<h2>' . $hiterm->name . '</h2>';
    echo term_description($term_id, 'project_status');
    echo '<a class="status-link" href="' . esc_url($hiterm_link) . '">לצפייה בפרויקטים</a>';
    echo '<a class="view" href="' . esc_url($hiterm_link) . '">View More</a>';
    echo '</figcaption>';
    echo '</figure>';
    echo '</div>';
}
?>
Пример #21
0
 public function __get($key)
 {
     switch ($key) {
         case 'data':
             $data = new stdClass();
             $columns = array('term_id', 'name', 'slug', 'term_group', 'term_taxonomy_id', 'taxonomy', 'description', 'parent', 'count');
             foreach ($columns as $column) {
                 $data->{$column} = isset($this->{$column}) ? $this->{$column} : null;
             }
             return sanitize_term($data, $data->taxonomy, 'raw');
             break;
     }
 }
 public function update_term($term_object)
 {
     $taxonomy = $term_object->taxonomy;
     global $wpdb;
     $exists = $wpdb->get_var($wpdb->prepare("SELECT EXISTS( SELECT 1 FROM {$wpdb->terms} WHERE term_id = %d )", $term_object->term_id));
     if (!$exists) {
         $term_object = sanitize_term(clone $term_object, $taxonomy, 'db');
         $term = array('term_id' => $term_object->term_id, 'name' => $term_object->name, 'slug' => $term_object->slug, 'term_group' => $term_object->term_group);
         $term_taxonomy = array('term_taxonomy_id' => $term_object->term_taxonomy_id, 'term_id' => $term_object->term_id, 'taxonomy' => $term_object->taxonomy, 'description' => $term_object->description, 'parent' => (int) $term_object->parent, 'count' => (int) $term_object->count);
         $wpdb->insert($wpdb->terms, $term);
         $wpdb->insert($wpdb->term_taxonomy, $term_taxonomy);
         return true;
     }
     return wp_update_term($term_object->term_id, $taxonomy, (array) $term_object);
 }
Пример #23
0
/**
 * Sanitizes category data based on context.
 *
 * @since 2.3.0
 * @uses sanitize_term() See this function for what context are supported.
 *
 * @param object|array $category Category data
 * @param string $context Optional. Default is 'display'.
 * @return object|array Same type as $category with sanitized data for safe use.
 */
function sanitize_category($category, $context = 'display')
{
    return sanitize_term($category, 'category', $context);
}
 /**
  * Generate the content of the widget.
  * 
  * @since    1.2
  *
  * @param    array    $args The array of form elements
  * @param    array    $instance The current instance of the widget
  * 
  * @return   string   The Widget Content
  */
 public function widget_content($args, $instance)
 {
     if (!in_array($instance['taxonomy'], array('collection', 'genre', 'actor'))) {
         return false;
     }
     $defaults = array('title' => __('Movie Taxonomies', 'wpmovielibrary'), 'description' => '', 'taxonomy' => '', 'list' => 0, 'count' => 0, 'orderby' => 'count', 'order' => 'DESC', 'css' => 0, 'limit' => WPMOLY_MAX_TAXONOMY_LIST);
     $args = wp_parse_args($args, $defaults);
     extract($args, EXTR_SKIP);
     extract($instance);
     $title = apply_filters('widget_title', $title);
     $archive = wpmoly_o("rewrite-{$taxonomy}");
     if ('ASC' != $order) {
         $order = 'DESC';
     }
     if ('name' != $orderby) {
         $orderby = 'count';
     }
     $args = array("order={$order}", "orderby={$orderby}");
     if (0 < $limit) {
         $args[] = "number={$limit}";
     }
     $args = implode('&', $args);
     $taxonomies = get_terms(array($taxonomy), $args);
     if ($taxonomies && !is_wp_error($taxonomies)) {
         $items = array();
         $this->widget_css .= " {$taxonomy} list";
         if ($css) {
             $this->widget_css .= ' custom';
         }
         foreach ($taxonomies as $term) {
             $items[] = array('attr_title' => sprintf(__('Permalink for &laquo; %s &raquo;', 'wpmovielibrary'), $term->name), 'link' => get_term_link(sanitize_term($term, $taxonomy), $taxonomy), 'title' => esc_attr($term->name . ($count ? sprintf('&nbsp;(%d)', $term->count) : '')));
         }
         if ($limit) {
             $url = WPMOLY_Utils::get_taxonomy_permalink($archive, $value = false);
             if ('' != $url) {
                 $items[] = array('attr_title' => $this->taxonomies[$taxonomy]['view_all'], 'link' => $url, 'title' => __('View the complete list', 'wpmovielibrary'));
             }
         }
         $items = apply_filters('wpmoly_widget_collection_list', $items, $list, $css);
         $attributes = array('items' => $items, 'description' => $description, 'default_option' => $this->taxonomies[$taxonomy]['default'], 'style' => $this->widget_css);
         if ($list) {
             $html = WPMovieLibrary::render_template('taxonomies-widget/taxonomies-dropdown-list.php', $attributes, $require = 'always');
         } else {
             $html = WPMovieLibrary::render_template('taxonomies-widget/taxonomies-list.php', $attributes, $require = 'always');
         }
     } else {
         $html = WPMovieLibrary::render_template('empty.php', array('message' => $this->taxonomies[$taxonomy]['empty']), $require = 'always');
     }
     return $before_widget . $before_title . $title . $after_title . $html . $after_widget;
 }
Пример #25
0
 /**
  * Sanitizes term fields, according to the filter type provided.
  *
  * @param string $filter Filter context. Accepts 'edit', 'db', 'display', 'attribute', 'js', 'raw'.
  * @return void
  */
 public function filter($filter = 'display')
 {
     sanitize_term($this, $this->taxonomy, $filter);
 }
Пример #26
0
function list_terms()
{
    $terms = get_terms("press_project", $args = array('orderby' => 'menu_order', 'order' => 'ASC', "parent" => 0));
    $post_term = wp_get_post_terms($post->ID, 'press_project');
    $currentterm = get_term_by('slug', get_query_var('term'), get_query_var('taxonomy'));
    echo '<ul class="cat-list ' . $currentterm . '">';
    foreach ($terms as $key => $term) {
        $term = sanitize_term($term, 'press_project');
        $term_link = get_term_link($term, 'press_project');
        $class = $currentterm == $term->slug ? 'current' : '';
        if ($terms) {
            echo '<li class="' . $class . '""><a href="' . esc_url($term_link) . '">' . $term->name . '</a></li>';
        }
    }
    echo '</ul>';
}
Пример #27
0
 /**
  * @global string $taxonomy
  * @param object $tag
  * @param int $level
  */
 public function single_row($tag, $level = 0)
 {
     global $taxonomy;
     $tag = sanitize_term($tag, $taxonomy);
     $this->level = $level;
     echo '<tr id="tag-' . $tag->term_id . '">';
     $this->single_row_columns($tag);
     echo '</tr>';
 }
 /**
  * Return the array with all products and all attributes values
  *
  * @return array The complete list of products with all attributes value
  */
 public function get_products_list($products = array())
 {
     $list = array();
     if (empty($products)) {
         $products = apply_filters('yith_woocompare_exclude_products_from_list', $this->products_list);
     }
     $fields = $this->fields();
     foreach ($products as $product_id) {
         $product = $this->wc_get_product($product_id);
         if (!$product) {
             continue;
         }
         $product->fields = array();
         // custom attributes
         foreach ($fields as $field => $name) {
             switch ($field) {
                 case 'title':
                     $product->fields[$field] = $product->get_title();
                     break;
                 case 'price':
                     $product->fields[$field] = $product->get_price_html();
                     break;
                 case 'image':
                     $product->fields[$field] = intval(get_post_thumbnail_id($product_id));
                     break;
                 case 'description':
                     $product->fields[$field] = apply_filters('woocommerce_short_description', $product->post->post_excerpt);
                     break;
                 case 'stock':
                     $availability = $product->get_availability();
                     if (empty($availability['availability'])) {
                         $availability['availability'] = __('In stock', 'yith-wcmp');
                     }
                     $product->fields[$field] = sprintf('<span class="%s">%s</span>', esc_attr($availability['class']), esc_html($availability['availability']));
                     break;
                 default:
                     if (taxonomy_exists($field)) {
                         $product->fields[$field] = array();
                         $terms = get_the_terms($product_id, $field);
                         if (!empty($terms)) {
                             foreach ($terms as $term) {
                                 $term = sanitize_term($term, $field);
                                 $product->fields[$field][] = $term->name;
                             }
                         }
                         $product->fields[$field] = implode(', ', $product->fields[$field]);
                     } else {
                         do_action_ref_array('yith_woocompare_field_' . $field, array($product, &$product->fields));
                     }
                     break;
             }
         }
         $list[] = $product;
     }
     return $list;
 }
Пример #29
0
/**
 * Update term based on arguments provided.
 *
 * The $args will indiscriminately override all values with the same field name.
 * Care must be taken to not override important information need to update or
 * update will fail (or perhaps create a new term, neither would be acceptable).
 *
 * Defaults will set 'alias_of', 'description', 'parent', and 'slug' if not
 * defined in $args already.
 *
 * 'alias_of' will create a term group, if it doesn't already exist, and update
 * it for the $term.
 *
 * If the 'slug' argument in $args is missing, then the 'name' in $args will be
 * used. It should also be noted that if you set 'slug' and it isn't unique then
 * a WP_Error will be passed back. If you don't pass any slug, then a unique one
 * will be created for you.
 *
 * For what can be overrode in `$args`, check the term scheme can contain and stay
 * away from the term keys.
 *
 * @since 2.3.0
 *
 * @global wpdb $wpdb WordPress database abstraction object.
 *
 * @param int          $term_id  The ID of the term
 * @param string       $taxonomy The context in which to relate the term to the object.
 * @param array|string $args     Optional. Array of get_terms() arguments. Default empty array.
 * @return array|WP_Error Returns Term ID and Taxonomy Term ID
 */
function wp_update_term($term_id, $taxonomy, $args = array())
{
    global $wpdb;
    if (!taxonomy_exists($taxonomy)) {
        return new WP_Error('invalid_taxonomy', __('Invalid taxonomy'));
    }
    $term_id = (int) $term_id;
    // First, get all of the original args
    $term = get_term($term_id, $taxonomy);
    if (is_wp_error($term)) {
        return $term;
    }
    if (!$term) {
        return new WP_Error('invalid_term', __('Empty Term'));
    }
    $term = (array) $term->data;
    // Escape data pulled from DB.
    $term = wp_slash($term);
    // Merge old and new args with new args overwriting old ones.
    $args = array_merge($term, $args);
    $defaults = array('alias_of' => '', 'description' => '', 'parent' => 0, 'slug' => '');
    $args = wp_parse_args($args, $defaults);
    $args = sanitize_term($args, $taxonomy, 'db');
    $parsed_args = $args;
    // expected_slashed ($name)
    $name = wp_unslash($args['name']);
    $description = wp_unslash($args['description']);
    $parsed_args['name'] = $name;
    $parsed_args['description'] = $description;
    if ('' == trim($name)) {
        return new WP_Error('empty_term_name', __('A name is required for this term'));
    }
    if ($parsed_args['parent'] > 0 && !term_exists((int) $parsed_args['parent'])) {
        return new WP_Error('missing_parent', __('Parent term does not exist.'));
    }
    $empty_slug = false;
    if (empty($args['slug'])) {
        $empty_slug = true;
        $slug = sanitize_title($name);
    } else {
        $slug = $args['slug'];
    }
    $parsed_args['slug'] = $slug;
    $term_group = isset($parsed_args['term_group']) ? $parsed_args['term_group'] : 0;
    if ($args['alias_of']) {
        $alias = get_term_by('slug', $args['alias_of'], $taxonomy);
        if (!empty($alias->term_group)) {
            // The alias we want is already in a group, so let's use that one.
            $term_group = $alias->term_group;
        } elseif (!empty($alias->term_id)) {
            /*
             * The alias is not in a group, so we create a new one
             * and add the alias to it.
             */
            $term_group = $wpdb->get_var("SELECT MAX(term_group) FROM {$wpdb->terms}") + 1;
            wp_update_term($alias->term_id, $taxonomy, array('term_group' => $term_group));
        }
        $parsed_args['term_group'] = $term_group;
    }
    /**
     * Filter the term parent.
     *
     * Hook to this filter to see if it will cause a hierarchy loop.
     *
     * @since 3.1.0
     *
     * @param int    $parent      ID of the parent term.
     * @param int    $term_id     Term ID.
     * @param string $taxonomy    Taxonomy slug.
     * @param array  $parsed_args An array of potentially altered update arguments for the given term.
     * @param array  $args        An array of update arguments for the given term.
     */
    $parent = apply_filters('wp_update_term_parent', $args['parent'], $term_id, $taxonomy, $parsed_args, $args);
    // Check for duplicate slug
    $duplicate = get_term_by('slug', $slug, $taxonomy);
    if ($duplicate && $duplicate->term_id != $term_id) {
        // If an empty slug was passed or the parent changed, reset the slug to something unique.
        // Otherwise, bail.
        if ($empty_slug || $parent != $term['parent']) {
            $slug = wp_unique_term_slug($slug, (object) $args);
        } else {
            return new WP_Error('duplicate_term_slug', sprintf(__('The slug &#8220;%s&#8221; is already in use by another term'), $slug));
        }
    }
    $tt_id = (int) $wpdb->get_var($wpdb->prepare("SELECT tt.term_taxonomy_id FROM {$wpdb->term_taxonomy} AS tt INNER JOIN {$wpdb->terms} AS t ON tt.term_id = t.term_id WHERE tt.taxonomy = %s AND t.term_id = %d", $taxonomy, $term_id));
    // Check whether this is a shared term that needs splitting.
    $_term_id = _split_shared_term($term_id, $tt_id);
    if (!is_wp_error($_term_id)) {
        $term_id = $_term_id;
    }
    /**
     * Fires immediately before the given terms are edited.
     *
     * @since 2.9.0
     *
     * @param int    $term_id  Term ID.
     * @param string $taxonomy Taxonomy slug.
     */
    do_action('edit_terms', $term_id, $taxonomy);
    $wpdb->update($wpdb->terms, compact('name', 'slug', 'term_group'), compact('term_id'));
    if (empty($slug)) {
        $slug = sanitize_title($name, $term_id);
        $wpdb->update($wpdb->terms, compact('slug'), compact('term_id'));
    }
    /**
     * Fires immediately after the given terms are edited.
     *
     * @since 2.9.0
     *
     * @param int    $term_id  Term ID
     * @param string $taxonomy Taxonomy slug.
     */
    do_action('edited_terms', $term_id, $taxonomy);
    /**
     * Fires immediate before a term-taxonomy relationship is updated.
     *
     * @since 2.9.0
     *
     * @param int    $tt_id    Term taxonomy ID.
     * @param string $taxonomy Taxonomy slug.
     */
    do_action('edit_term_taxonomy', $tt_id, $taxonomy);
    $wpdb->update($wpdb->term_taxonomy, compact('term_id', 'taxonomy', 'description', 'parent'), array('term_taxonomy_id' => $tt_id));
    /**
     * Fires immediately after a term-taxonomy relationship is updated.
     *
     * @since 2.9.0
     *
     * @param int    $tt_id    Term taxonomy ID.
     * @param string $taxonomy Taxonomy slug.
     */
    do_action('edited_term_taxonomy', $tt_id, $taxonomy);
    // Clean the relationship caches for all object types using this term.
    $objects = $wpdb->get_col($wpdb->prepare("SELECT object_id FROM {$wpdb->term_relationships} WHERE term_taxonomy_id = %d", $tt_id));
    $tax_object = get_taxonomy($taxonomy);
    foreach ($tax_object->object_type as $object_type) {
        clean_object_term_cache($objects, $object_type);
    }
    /**
     * Fires after a term has been updated, but before the term cache has been cleaned.
     *
     * @since 2.3.0
     *
     * @param int    $term_id  Term ID.
     * @param int    $tt_id    Term taxonomy ID.
     * @param string $taxonomy Taxonomy slug.
     */
    do_action("edit_term", $term_id, $tt_id, $taxonomy);
    /**
     * Fires after a term in a specific taxonomy has been updated, but before the term
     * cache has been cleaned.
     *
     * The dynamic portion of the hook name, `$taxonomy`, refers to the taxonomy slug.
     *
     * @since 2.3.0
     *
     * @param int $term_id Term ID.
     * @param int $tt_id   Term taxonomy ID.
     */
    do_action("edit_{$taxonomy}", $term_id, $tt_id);
    /** This filter is documented in wp-includes/taxonomy-functions.php */
    $term_id = apply_filters('term_id_filter', $term_id, $tt_id);
    clean_term_cache($term_id, $taxonomy);
    /**
     * Fires after a term has been updated, and the term cache has been cleaned.
     *
     * @since 2.3.0
     *
     * @param int    $term_id  Term ID.
     * @param int    $tt_id    Term taxonomy ID.
     * @param string $taxonomy Taxonomy slug.
     */
    do_action("edited_term", $term_id, $tt_id, $taxonomy);
    /**
     * Fires after a term for a specific taxonomy has been updated, and the term
     * cache has been cleaned.
     *
     * The dynamic portion of the hook name, `$taxonomy`, refers to the taxonomy slug.
     *
     * @since 2.3.0
     *
     * @param int $term_id Term ID.
     * @param int $tt_id   Term taxonomy ID.
     */
    do_action("edited_{$taxonomy}", $term_id, $tt_id);
    return array('term_id' => $term_id, 'term_taxonomy_id' => $tt_id);
}
 /**
  * Render the term table row.
  *
  * @access public
  * @since  8.2
  *
  * @uses   sanitize_term()
  * @uses   WP_List_Table::single_row_columns()
  *
  * @staticvar string $class
  *
  * @param object $term
  * @param int    $level
  */
 public function single_row($term, $level = 0)
 {
     $term = sanitize_term($term, 'cn_' . $this->taxonomy);
     static $class = '';
     $class = $class == '' ? ' class="alternate"' : '';
     $this->level = $level;
     echo '<tr id="tag-' . $term->term_id . '"' . $class . '>';
     $this->single_row_columns($term);
     echo '</tr>';
 }