当前位置: 首页>>代码示例>>PHP>>正文


PHP wp_unique_term_slug函数代码示例

本文整理汇总了PHP中wp_unique_term_slug函数的典型用法代码示例。如果您正苦于以下问题:PHP wp_unique_term_slug函数的具体用法?PHP wp_unique_term_slug怎么用?PHP wp_unique_term_slug使用的例子?那么恭喜您, 这里精选的函数代码示例或许可以为您提供帮助。


在下文中一共展示了wp_unique_term_slug函数的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的PHP代码示例。

示例1: wc1c_wp_unique_term_slug

function wc1c_wp_unique_term_slug($slug, $term, $original_slug)
{
    if (mb_strlen($slug) <= 200) {
        return $slug;
    }
    do {
        $slug = urldecode($slug);
        $slug = mb_substr($slug, 0, mb_strlen($slug) - 1);
        $slug = urlencode($slug);
        $slug = wp_unique_term_slug($slug, $term);
    } while (mb_strlen($slug) > 200);
    return $slug;
}
开发者ID:sgtpep,项目名称:woocommerce-1c,代码行数:13,代码来源:import.php

示例2: get_term

 public function test_nonunique_slug_in_same_hierarchical_taxonomy_at_different_level_of_hierarchy_should_be_suffixed_with_number()
 {
     $parent = $this->factory->term->create(array('taxonomy' => 'wptests_tax2', 'slug' => 'parent-term'));
     $term1 = $this->factory->term->create(array('taxonomy' => 'wptests_tax2', 'name' => 'bar', 'slug' => 'bar', 'parent' => $parent));
     $term2 = $this->factory->term->create(array('taxonomy' => 'wptests_tax2', 'name' => 'foo', 'slug' => 'foo'));
     $term2_object = get_term($term2, 'wptests_tax2');
     $actual = wp_unique_term_slug('bar', $term2_object);
     $this->assertEquals('bar-2', $actual);
 }
开发者ID:Benrajalu,项目名称:philRaj,代码行数:9,代码来源:wpUniqueTermSlug.php

示例3: wpmf_import_categories

 function wpmf_import_categories()
 {
     $option_import_taxo = get_option('_wpmf_import_notice_flag');
     if (isset($option_import_taxo) && $option_import_taxo == 'yes') {
         die;
     }
     if ($_POST['doit'] === 'true') {
         $terms = get_terms('category', array('orderby' => 'name', 'order' => 'ASC', 'hide_empty' => false, 'child_of' => 0));
         $termsRel = array('0' => 0);
         foreach ($terms as $term) {
             $inserted = wp_insert_term($term->name, 'wpmf-category', array('slug' => wp_unique_term_slug($term->slug, $term)));
             if (is_wp_error($inserted)) {
                 wp_send_json($inserted->get_error_message());
             }
             $termsRel[$term->term_id] = $inserted['term_id'];
         }
         foreach ($terms as $term) {
             wp_update_term($termsRel[$term->term_id], 'wpmf-category', array('parent' => $termsRel[$term->parent]));
         }
         //update attachments
         $attachments = get_posts(array('posts_per_page' => -1, 'post_type' => 'attachment'));
         foreach ($attachments as $attachment) {
             $terms = wp_get_post_terms($attachment->ID, 'category');
             $termsArray = array();
             foreach ($terms as $term) {
                 $termsArray[] = $termsRel[$term->term_id];
             }
             if ($termsArray != null) {
                 wp_set_post_terms($attachment->ID, $termsArray, 'wpmf-category');
             }
         }
     }
     if ($_POST['doit'] === 'true') {
         update_option('_wpmf_import_notice_flag', 'yes');
     } else {
         update_option('_wpmf_import_notice_flag', 'no');
     }
     die;
 }
开发者ID:uwmadisoncals,项目名称:Cluster-Plugins,代码行数:39,代码来源:class-media-folder.php

示例4: wp_update_term

/**
 * 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 ) );
//.........这里部分代码省略.........
开发者ID:staylor,项目名称:develop.svn.wordpress.org,代码行数:101,代码来源:taxonomy.php

示例5: wpsc_convert_variation_sets

function wpsc_convert_variation_sets()
{
    global $wpdb, $user_ID;
    $variation_sets = $wpdb->get_results("SELECT * FROM `" . WPSC_TABLE_PRODUCT_VARIATIONS . "`");
    $wpsc_update = WPSC_Update::get_instance();
    foreach ((array) $variation_sets as $variation_set) {
        $wpsc_update->check_timeout();
        $variation_set_id = wpsc_get_meta($variation_set->id, 'variation_set_id', 'wpsc_variation_set');
        if (!is_numeric($variation_set_id) || $variation_set_id < 1) {
            $slug = sanitize_title($variation_set->name);
            $dummy_term = (object) array('taxonomy' => 'wpsc-variation', 'parent' => 0);
            $slug = wp_unique_term_slug($slug, $dummy_term);
            $new_variation_set = wp_insert_term($variation_set->name, 'wpsc-variation', array('parent' => 0, 'slug' => $slug));
            if (!is_wp_error($new_variation_set)) {
                $variation_set_id = $new_variation_set['term_id'];
            }
        }
        if (!empty($variation_set_id) && is_numeric($variation_set_id)) {
            wpsc_update_meta($variation_set->id, 'variation_set_id', $variation_set_id, 'wpsc_variation_set');
            $variations = $wpdb->get_results("SELECT * FROM `" . WPSC_TABLE_VARIATION_VALUES . "` WHERE `variation_id` IN ({$variation_set->id})");
            foreach ((array) $variations as $variation) {
                $variation_id = wpsc_get_meta($variation->id, 'variation_id', 'wpsc_variation');
                if (!is_numeric($variation_id) || $variation_id < 1) {
                    $new_variation = wp_insert_term($variation->name, 'wpsc-variation', array('parent' => $variation_set_id));
                    if (!is_wp_error($new_variation)) {
                        $variation_id = $new_variation['term_id'];
                    }
                }
                if (is_numeric($variation_id)) {
                    wpsc_update_meta($variation->id, 'variation_id', $variation_id, 'wpsc_variation');
                }
            }
        }
    }
}
开发者ID:ashik968,项目名称:digiplot,代码行数:35,代码来源:updating-functions.php

示例6: test_wp_unique_term_slug

	function test_wp_unique_term_slug() {
		// set up test data
		$a = wp_insert_term( 'parent', $this->taxonomy );
		$this->assertInternalType( 'array', $a );
		$b = wp_insert_term( 'child',  $this->taxonomy, array( 'parent' => $a['term_id'] ) );
		$this->assertInternalType( 'array', $b );
		$c = wp_insert_term( 'neighbor', $this->taxonomy );
		$this->assertInternalType( 'array', $c );
		$d = wp_insert_term( 'pet',  $this->taxonomy, array( 'parent' => $c['term_id'] )  );
		$this->assertInternalType( 'array', $c );

		$a_term = get_term( $a['term_id'], $this->taxonomy );
		$b_term = get_term( $b['term_id'], $this->taxonomy );
		$c_term = get_term( $c['term_id'], $this->taxonomy );
		$d_term = get_term( $d['term_id'], $this->taxonomy );

		// a unique slug gets unchanged
		$this->assertEquals( 'unique-term', wp_unique_term_slug( 'unique-term', $c_term ) );

		// a non-hierarchicial dupe gets suffixed with "-#"
		$this->assertEquals( 'parent-2', wp_unique_term_slug( 'parent', $c_term ) );

		// a hierarchical dupe initially gets suffixed with its parent term
		$this->assertEquals( 'child-neighbor', wp_unique_term_slug( 'child', $d_term ) );

		// a hierarchical dupe whose parent already contains the {term}-{parent term}
		// term gets suffixed with parent term name and then '-#'
		$e = wp_insert_term( 'child-neighbor', $this->taxonomy, array( 'parent' => $c['term_id'] ) );
		$this->assertEquals( 'child-neighbor-2', wp_unique_term_slug( 'child', $d_term ) );

		$f = wp_insert_term( 'foo', $this->taxonomy );
		$this->assertInternalType( 'array', $f );
		$f_term = get_term( $f['term_id'], $this->taxonomy );
		$this->assertEquals( 'foo', $f_term->slug );
		$this->assertEquals( 'foo', wp_unique_term_slug(  'foo', $f_term ) );

		$g = wp_insert_term( 'foo',  $this->taxonomy );
		$this->assertInstanceOf( 'WP_Error', $g );

		// clean up
		foreach ( array( $a, $b, $c, $d, $e, $f ) as $t )
			$this->assertTrue( wp_delete_term( $t['term_id'], $this->taxonomy ) );
	}
开发者ID:staylor,项目名称:develop.svn.wordpress.org,代码行数:43,代码来源:term.php

示例7: 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.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));
//.........这里部分代码省略.........
开发者ID:pankajsinghjarial,项目名称:SYLC-AMERICAN,代码行数:101,代码来源:taxonomy.php

示例8: edit_slug

 /**
  * Handles Product/Category slug editor
  *
  * @author Jonathan Davis
  * @since 1.1
  *
  * @return void
  **/
 public function edit_slug()
 {
     check_admin_referer('wp_ajax_shopp_edit_slug');
     $defaults = array('slug' => false, 'type' => false, 'id' => false, 'title' => false);
     $p = array_merge($defaults, $_POST);
     extract($p);
     if (false === $slug || false === $id) {
         die('-1');
     }
     switch ($type) {
         case 'category':
             $Category = new ProductCategory($_POST['id']);
             if ($slug == $Category->slug) {
                 die('-1');
             }
             $term = get_term($Category->id, $Category->taxonomy);
             $Category->slug = wp_unique_term_slug(sanitize_title_with_dashes($slug), $term);
             $Category->save();
             echo apply_filters('editable_slug', $Category->slug);
             break;
         case 'product':
             $Product = new ShoppProduct($_POST['id']);
             if ($slug == $Product->slug) {
                 die('-1');
             }
             // Same as before? Nothing to do so bail
             // Regardless of the true post status, we'll pass 'publish' here to ensure we get a unique slug back
             $Product->slug = wp_unique_post_slug(sanitize_title_with_dashes($slug), $Product->id, 'publish', ShoppProduct::posttype(), 0);
             $Product->save();
             echo apply_filters('editable_slug', $Product->slug);
             break;
     }
     exit;
 }
开发者ID:msigley,项目名称:shopp,代码行数:42,代码来源:Ajax.php

示例9: sslp_staff_member_options_page

function sslp_staff_member_options_page()
{
    // Get existing options
    $default_slug = get_option('_staff_listing_default_slug');
    $default_name_singular = get_option('_staff_listing_default_name_singular');
    $default_name_plural = get_option('_staff_listing_default_name_plural');
    // Check Nonce and then update options
    if (!empty($_POST) && check_admin_referer('staff-member-options', 'staff-list-options')) {
        update_option('_staff_listing_custom_slug', wp_unique_term_slug($_POST["staff-listing-slug"], 'staff-member'));
        update_option('_staff_listing_custom_name_singular', $_POST["staff-listing-name-singular"]);
        update_option('_staff_listing_custom_name_plural', $_POST["staff-listing-name-plural"]);
        $custom_slug = stripslashes_deep(get_option('_staff_listing_custom_slug'));
        $custom_name_singular = stripslashes_deep(get_option('_staff_listing_custom_name_singular'));
        $custom_name_plural = stripslashes_deep(get_option('_staff_listing_custom_name_plural'));
    } else {
        $custom_slug = stripslashes_deep(get_option('_staff_listing_custom_slug'));
        $custom_name_singular = stripslashes_deep(get_option('_staff_listing_custom_name_singular'));
        $custom_name_plural = stripslashes_deep(get_option('_staff_listing_custom_name_plural'));
    }
    $output .= '<div class="wrap sslp-options">';
    $output .= '<div id="icon-edit" class="icon32 icon32-posts-staff-member"><br></div><h2>' . __('Simple Staff List', 'simple-staff-list') . '</h2>';
    $output .= '<h2>Options</h2>';
    $output .= '<div>';
    $output .= '<form method="post" action="">';
    $output .= '<fieldset id="staff-listing-field-slug" class="sslp-fieldset">';
    $output .= '<legend class="sslp-field-label">' . __('Staff Members URL Slug', 'simple-staff-list') . '</legend>';
    $output .= '<input type="text" name="staff-listing-slug" value="' . $custom_slug . '"></fieldset>';
    $output .= '<p>' . __('The slug used for building the staff members URL. The current URL is: ', 'simple-staff-list');
    $output .= site_url($custom_slug) . '/';
    $output .= '</p>';
    $output .= '<fieldset id="staff-listing-field-name-plural" class="sslp-fieldset">';
    $output .= '<legend class="sslp-field-label">' . __('Staff Member title', 'simple-staff-list') . '</legend>';
    $output .= '<input type="text" name="staff-listing-name-plural" value="' . $custom_name_plural . '"></fieldset>';
    $output .= '<p>' . __('The title that displays on the Staff Member archive page. Default is "Staff Members"', 'simple-staff-list') . '</p>';
    $output .= '<fieldset id="staff-listing-field-name-singular" class="sslp-fieldset">';
    $output .= '<legend class="sslp-field-label">' . __('Staff Member singular title', 'simple-staff-list') . '</legend>';
    $output .= '<input type="text" name="staff-listing-name-singular" value="' . $custom_name_singular . '"></fieldset>';
    $output .= '<p>' . __('The Staff Member taxonomy singular name. No need to change this unless you need to use the singular_name field in your theme. Default is "Staff Member"', 'simple-staff-list') . '</p>';
    $output .= '<p><input type="submit" value="' . __('Save ALL Changes', 'simple-staff-list') . '" class="button button-primary button-large"></p><br /><br />';
    $output .= wp_nonce_field('staff-member-options', 'staff-list-options');
    $output .= '</form>';
    $output .= '</div>';
    echo $output;
}
开发者ID:humancopy,项目名称:Staff-List-Plugin,代码行数:44,代码来源:admin-views.php

示例10: 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.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));
//.........这里部分代码省略.........
开发者ID:ugurbastan,项目名称:swe-574-group4,代码行数:101,代码来源:taxonomy.php

示例11: geodir_imex_insert_term

/**
 * Create new the post term.
 *
 * @since 1.4.6
 * @package GeoDirectory
 *
 * @param string $taxonomy Post taxonomy.
 * @param array $term_data {
 *    Attributes of term data.
 *
 *    @type string $name Term name.
 *    @type string $slug Term slug.
 *    @type string $description Term description.
 *    @type string $top_description Term top description.
 *    @type string $image Default Term image.
 *    @type string $icon Default Term icon.
 *    @type string $taxonomy Term taxonomy.
 *    @type int $parent Term parent ID.
 *
 * }
 * @return int|bool Term id when success, false when fail.
 */
function geodir_imex_insert_term($taxonomy, $term_data)
{
    if (empty($taxonomy) || empty($term_data)) {
        return false;
    }
    $term = isset($term_data['name']) && !empty($term_data['name']) ? $term_data['name'] : '';
    $args = array();
    $args['description'] = isset($term_data['description']) ? $term_data['description'] : '';
    $args['slug'] = isset($term_data['slug']) ? $term_data['slug'] : '';
    $args['parent'] = isset($term_data['parent']) ? (int) $term_data['parent'] : '';
    if (!empty($args['slug']) && term_exists($args['slug'], $taxonomy) || empty($args['slug'])) {
        $term_args = array_merge($term_data, $args);
        $defaults = array('alias_of' => '', 'description' => '', 'parent' => 0, 'slug' => '');
        $term_args = wp_parse_args($term_args, $defaults);
        $term_args = sanitize_term($term_args, $taxonomy, 'db');
        $args['slug'] = wp_unique_term_slug($args['slug'], (object) $term_args);
    }
    if (!empty($term)) {
        $result = wp_insert_term($term, $taxonomy, $args);
        if (!is_wp_error($result)) {
            return $term_id = isset($result['term_id']) ? $result['term_id'] : 0;
        }
    }
    return false;
}
开发者ID:jefferose,项目名称:geodirectory,代码行数:47,代码来源:admin_functions.php

示例12: wp_update_term

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);
    $empty_slug = false;
    if (empty($slug)) {
        $empty_slug = true;
        $slug = sanitize_title($name);
    }
    if ($alias_of) {
        $alias = $wpdb->fetch_row("SELECT term_id, term_group FROM {$wpdb->terms} WHERE slug = '{$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} GROUP BY term_group") + 1;
            $wpdb->query("UPDATE {$wpdb->terms} SET term_group = {$term_group} WHERE term_id = {$alias->term_id}");
        }
    }
    // Check for duplicate slug
    $id = $wpdb->get_var("SELECT term_id FROM {$wpdb->terms} WHERE slug = '{$slug}'");
    if ($id && $id != $term_id) {
        // If an empty slug was passed, reset the slug to something unique.
        // Otherwise, bail.
        if ($empty_slug) {
            $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->query("UPDATE {$wpdb->terms} SET name = '{$name}', slug = '{$slug}', term_group = '{$term_group}' WHERE term_id = '{$term_id}'");
    if (empty($slug)) {
        $slug = sanitize_title($name, $term_id);
        $wpdb->query("UPDATE {$wpdb->terms} SET slug = '{$slug}' WHERE term_id = '{$term_id}'");
    }
    $tt_id = $wpdb->get_var("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 = '{$taxonomy}' AND t.term_id = {$term_id}");
    $wpdb->query("UPDATE {$wpdb->term_taxonomy} SET term_id = '{$term_id}', taxonomy = '{$taxonomy}', description = '{$description}', parent = '{$parent}' WHERE 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);
}
开发者ID:helmonaut,项目名称:owb-mirror,代码行数:59,代码来源:taxonomy.php

示例13: sync_term

 function sync_term()
 {
     try {
         // return false if request method is empty
         if (empty($_REQUEST['method'])) {
             throw new Exception(__('There is an error occurred', ET_DOMAIN), 400);
         }
         $method = empty($_REQUEST['method']) ? '' : $_REQUEST['method'];
         $data = $_REQUEST['content'];
         switch ($method) {
             case 'delete':
                 $term = $_REQUEST['content']['id'];
                 $default = isset($_REQUEST['content']['default']) ? $_REQUEST['content']['default'] : false;
                 $taxonomy = $_REQUEST['content']['tax'];
                 // check if category has children or not
                 $children = get_terms($taxonomy, array('parent' => $term, 'hide_empty' => false));
                 if (!empty($children)) {
                     throw new Exception(__('You cannot delete a parent category. You need to delete its sub-categories first.', ET_DOMAIN));
                 }
                 // delete
                 $result = $this->tax->delete($term, $taxonomy, $default);
                 if (is_wp_error($result)) {
                     throw new Exception($result->get_error_message());
                 } else {
                     if ($result) {
                         $resp = array('success' => true);
                     } else {
                         throw new Exception(__("Can't delete category", ET_DOMAIN));
                     }
                 }
                 break;
             case 'create':
                 $term = $_POST['content']['name'];
                 $args = array('color' => 0, 'icon' => 'fa-map-marker');
                 if (empty($term)) {
                     throw new Exception(__('Category name is required', ET_DOMAIN));
                 }
                 if (isset($_REQUEST['content']['color'])) {
                     $args['color'] = $_REQUEST['content']['color'];
                 }
                 if (isset($_REQUEST['content']['icon'])) {
                     $args['icon'] = $_REQUEST['content']['icon'];
                 }
                 if (isset($_REQUEST['content']['parent'])) {
                     $args['parent'] = $_REQUEST['content']['parent'];
                 }
                 if (isset($_REQUEST['content']['tax'])) {
                     $args['taxonomy'] = $_REQUEST['content']['tax'];
                 }
                 $result = $this->tax->create($term, $args);
                 if (is_wp_error($result)) {
                     throw new Exception($result->get_error_message());
                 } else {
                     $data = get_term($result['term_id'], $args['taxonomy']);
                     $data->color = $this->tax->get_term_color($result['term_id'], $args['taxonomy']);
                     $data->icon = $this->tax->get_term_icon($result['term_id'], $args['taxonomy']);
                     $resp = array('success' => true, 'data' => array('term' => $data));
                 }
                 break;
             case 'update':
                 $term = $_REQUEST['content']['id'];
                 $args = array();
                 if (empty($term)) {
                     throw new Exception(__("Cannot find category", ET_DOMAIN));
                 }
                 if (isset($_REQUEST['content']['name'])) {
                     $args['name'] = $_REQUEST['content']['name'];
                 }
                 if (isset($_REQUEST['content']['color'])) {
                     $args['color'] = $_REQUEST['content']['color'];
                 }
                 if (isset($_REQUEST['content']['icon'])) {
                     $args['icon'] = $_REQUEST['content']['icon'];
                 }
                 if (isset($_REQUEST['content']['parent'])) {
                     $args['parent'] = $_REQUEST['content']['parent'];
                 }
                 if (isset($_REQUEST['content']['tax'])) {
                     $args['taxonomy'] = $_REQUEST['content']['tax'];
                 }
                 $term_data = get_term($term, $this->tax->taxonomy);
                 $slug = sanitize_title($_REQUEST['content']['name']);
                 $slug = wp_unique_term_slug($slug, (object) $term_data);
                 if ($slug) {
                     $args['slug'] = $slug;
                 }
                 $result = $this->tax->update($term, $args);
                 if (is_wp_error($result)) {
                     throw new Exception($result->get_error_message());
                 } else {
                     $data = get_term($result['term_id'], $args['taxonomy']);
                     $data->color = $this->tax->get_term_color($result['term_id'], $args['taxonomy']);
                     $data->icon = $this->tax->get_term_icon($result['term_id'], $args['taxonomy']);
                     $resp = array('success' => true, 'data' => array('term' => $data));
                 }
                 break;
             case 'sort':
                 $taxonomy = $_POST['content']['tax'];
                 wp_parse_str($_POST['content']['order'], $order);
                 $order = $order['tax'];
//.........这里部分代码省略.........
开发者ID:rinodung,项目名称:wp-question,代码行数:101,代码来源:category.php

示例14: string2slug

 private function string2slug($string)
 {
     $slug = strtolower($string);
     $slug = sanitize_title($slug);
     $slug = @wp_unique_term_slug($slug);
     return $slug;
 }
开发者ID:ricasiano,项目名称:mca-site,代码行数:7,代码来源:CataBlog.class.php

示例15: ipin_edit

function ipin_edit()
{
    $nonce = $_POST['nonce'];
    if (!wp_verify_nonce($nonce, 'ajax-nonce')) {
        die;
    }
    do_action('ipin_before_edit_pin', $_POST);
    global $user_ID;
    $postinfo = get_post(intval($_POST['postdata_pid']), ARRAY_A);
    $user_id = $postinfo['post_author'];
    if (!(current_user_can('administrator') || current_user_can('editor') || $user_id == $user_ID)) {
        die;
    }
    //Get board info
    $board_add_new = sanitize_text_field($_POST['postdata_board_add_new']);
    $board_add_new_category = $_POST['postdata_board_add_new_category'];
    $board_parent_id = get_user_meta($user_id, '_Board Parent ID', true);
    if ($board_add_new !== '') {
        $board_children = get_term_children($board_parent_id, 'board');
        $found = '0';
        foreach ($board_children as $board_child) {
            $board_child_term = get_term_by('id', $board_child, 'board');
            if (stripslashes(htmlspecialchars($board_add_new, ENT_NOQUOTES, 'UTF-8')) == $board_child_term->name) {
                $found = '1';
                $found_board_id = $board_child_term->term_id;
                break;
            }
        }
        if ($found == '0') {
            $slug = wp_unique_term_slug($board_add_new . '__ipinboard', 'board');
            //append __ipinboard to solve slug conflict with category and 0 in title
            if ($board_add_new_category == '-1') {
                $board_add_new_category = '1';
            }
            $new_board_id = wp_insert_term($board_add_new, 'board', array('description' => $board_add_new_category, 'parent' => $board_parent_id, 'slug' => $slug));
            $postdata_board = $new_board_id['term_id'];
        } else {
            $postdata_board = $found_board_id;
        }
    } else {
        $postdata_board = $_POST['postdata_board'];
    }
    //category ID is stored in the board description field
    $category_id = get_term_by('id', $postdata_board, 'board');
    $post_id = intval($_POST['postdata_pid']);
    $edit_post = array();
    $edit_post['ID'] = $post_id;
    $edit_post['post_category'] = array($category_id->description);
    $edit_post['post_name'] = '';
    $allowed_html = array('a' => array('href' => true), 'em' => array(), 'blockquote' => array(), 'p' => array(), 'li' => array(), 'ol' => array(), 'strong' => array(), 'ul' => array());
    if (of_get_option('htmltags') != 'enable') {
        unset($allowed_html);
        $allowed_html = array();
    }
    if (of_get_option('form_title_desc') != 'separate') {
        $edit_post['post_title'] = balanceTags(wp_kses($_POST['postdata_title'], $allowed_html), true);
    } else {
        $edit_post['post_title'] = sanitize_text_field($_POST['postdata_title']);
    }
    $edit_post['post_content'] = balanceTags(wp_kses($_POST['postdata_content'], $allowed_html), true);
    remove_action('save_post', 'ipin_save_post', 50, 2);
    wp_update_post($edit_post);
    wp_set_post_terms($post_id, array($postdata_board), 'board');
    //update postmeta for new post
    if ($_POST['postdata_source'] != '') {
        update_post_meta($post_id, '_Photo Source', esc_url($_POST['postdata_source']));
        update_post_meta($post_id, '_Photo Source Domain', parse_url(esc_url($_POST['postdata_source']), PHP_URL_HOST));
    } else {
        delete_post_meta($post_id, '_Photo Source');
        delete_post_meta($post_id, '_Photo Source Domain');
    }
    //add tags
    wp_set_post_tags($post_id, sanitize_text_field($_POST['postdata_tags']));
    //add price
    if ($_POST['postdata_price']) {
        if (strpos($_POST['postdata_price'], '.') !== false) {
            $_POST['postdata_price'] = number_format($_POST['postdata_price'], 2);
        }
        update_post_meta($post_id, '_Price', sanitize_text_field($_POST['postdata_price']));
    } else {
        if (get_post_meta($post_id, '_Price', true) !== '') {
            delete_post_meta($post_id, '_Price');
        }
    }
    //add new board to followers who fully follow user
    if ($new_board_id && !is_wp_error($new_board_id)) {
        $usermeta_followers_id_allboards = get_user_meta($user_id, '_Followers User ID All Boards');
        $followers_id_allboards = $usermeta_followers_id_allboards[0];
        if (!empty($followers_id_allboards)) {
            foreach ($followers_id_allboards as $followers_id_allboard) {
                $usermeta_following_board_id = get_user_meta($followers_id_allboard, '_Following Board ID');
                $following_board_id = $usermeta_following_board_id[0];
                array_unshift($following_board_id, $new_board_id['term_id']);
                update_user_meta($followers_id_allboard, '_Following Board ID', $following_board_id);
            }
        }
    }
    do_action('ipin_after_edit_pin', $post_id);
    echo get_permalink($post_id);
    exit;
//.........这里部分代码省略.........
开发者ID:leshuis,项目名称:testwp,代码行数:101,代码来源:functions.php


注:本文中的wp_unique_term_slug函数示例由纯净天空整理自Github/MSDocs等开源代码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。