當前位置: 首頁>>代碼示例>>PHP>>正文


PHP wp_create_tag函數代碼示例

本文整理匯總了PHP中wp_create_tag函數的典型用法代碼示例。如果您正苦於以下問題:PHP wp_create_tag函數的具體用法?PHP wp_create_tag怎麽用?PHP wp_create_tag使用的例子?那麽, 這裏精選的函數代碼示例或許可以為您提供幫助。


在下文中一共展示了wp_create_tag函數的4個代碼示例,這些例子默認根據受歡迎程度排序。您可以為喜歡或者感覺有用的代碼點讚,您的評價將有助於係統推薦出更棒的PHP代碼示例。

示例1: validate_settings

 /**
  * Validate settings
  *
  * Make sure that all user supplied content is in an expected format before
  * saving to the database. This function will also delete the transient set in
  * Featured_Content::get_featured_content().
  *
  * @uses Featured_Content::delete_transient()
  *
  * @param array $input
  * @return array $output
  */
 public static function validate_settings($input)
 {
     $output = array();
     if (empty($input['tag-name'])) {
         $output['tag-id'] = 0;
     } else {
         $term = get_term_by('name', $input['tag-name'], 'post_tag');
         if ($term) {
             $output['tag-id'] = $term->term_id;
         } else {
             $new_tag = wp_create_tag($input['tag-name']);
             if (!is_wp_error($new_tag) && isset($new_tag['term_id'])) {
                 $output['tag-id'] = $new_tag['term_id'];
             }
         }
         $output['tag-name'] = $input['tag-name'];
     }
     $output['hide-tag'] = isset($input['hide-tag']) && $input['hide-tag'] ? 1 : 0;
     $output['show-all'] = isset($input['show-all']) && $input['show-all'] ? 1 : 0;
     self::delete_transient();
     return $output;
 }
開發者ID:martincarson,項目名稱:jetpack,代碼行數:34,代碼來源:featured-content.php

示例2: validate_settings

 /**
  * Validate Settings.
  *
  * Make sure that all user supplied content is in an
  * expected format before saving to the database. This
  * function will also delete the transient set in
  * Featured_Content::get_featured_content().
  *
  * @uses Featured_Content::self::sanitize_quantity()
  * @uses Featured_Content::self::delete_transient()
  */
 function validate_settings($input)
 {
     $output = array();
     if (isset($input['tag-id'])) {
         $output['tag-id'] = absint($input['tag-id']);
     }
     if (isset($input['tag-name'])) {
         $new_tag = wp_create_tag($input['tag-name']);
         if (!is_wp_error($new_tag) && isset($new_tag['term_id'])) {
             $tag = get_term($new_tag['term_id'], 'post_tag');
         }
         if (isset($tag->term_id)) {
             $output['tag-id'] = $tag->term_id;
         }
     }
     if (isset($input['quantity'])) {
         $output['quantity'] = self::sanitize_quantity($input['quantity']);
     }
     $output['hide-tag'] = isset($input['hide-tag']) ? 1 : 0;
     self::delete_transient();
     return $output;
 }
開發者ID:kevinreilly,項目名稱:mendelements.com,代碼行數:33,代碼來源:featured-content.php

示例3: validate_settings

 /**
  * Validate featured content settings.
  *
  * Make sure that all user supplied content is in an expected
  * format before saving to the database. This function will also
  * delete the transient set in Featured_Content::get_featured_content().
  *
  * @static
  * @access public
  * @since 1.0
  *
  * @param array $input Array of settings input.
  * @return array Validated settings output.
  */
 public static function validate_settings($input)
 {
     $output = array();
     if (empty($input['tag-name'])) {
         $output['tag-id'] = 0;
     } else {
         $term = get_term_by('name', $input['tag-name'], 'post_tag');
         if ($term) {
             $output['tag-id'] = $term->term_id;
         } else {
             $new_tag = wp_create_tag($input['tag-name']);
             if (!is_wp_error($new_tag) && isset($new_tag['term_id'])) {
                 $output['tag-id'] = $new_tag['term_id'];
             }
         }
         $output['tag-name'] = $input['tag-name'];
     }
     if (isset($input['quantity'])) {
         $output['quantity'] = self::sanitize_quantity($input['quantity']);
     }
     $output['hide-tag'] = isset($input['hide-tag']) && $input['hide-tag'] ? 1 : 0;
     // Delete the featured post ids transient.
     self::delete_transient();
     return $output;
 }
開發者ID:quyip8818,項目名稱:wps,代碼行數:39,代碼來源:featured-content.php

示例4: test_terms

 function test_terms()
 {
     $this->make_user_by_role('editor');
     $tag1 = wp_create_tag('tag1');
     $this->assertInternalType('array', $tag1);
     $tag2 = wp_create_tag('tag2');
     $this->assertInternalType('array', $tag2);
     $tag3 = wp_create_tag('tag3');
     $this->assertInternalType('array', $tag3);
     $post = array('post_title' => 'Test', 'terms' => array('post_tag' => array($tag2['term_id'], $tag3['term_id'])));
     $result = $this->myxmlrpcserver->wp_newPost(array(1, 'editor', 'editor', $post));
     $this->assertNotInstanceOf('IXR_Error', $result);
     $post_tags = wp_get_object_terms($result, 'post_tag', array('fields' => 'ids'));
     $this->assertNotContains($tag1['term_id'], $post_tags);
     $this->assertContains($tag2['term_id'], $post_tags);
     $this->assertContains($tag3['term_id'], $post_tags);
 }
開發者ID:atimmer,項目名稱:wordpress-develop-mirror,代碼行數:17,代碼來源:newPost.php


注:本文中的wp_create_tag函數示例由純淨天空整理自Github/MSDocs等開源代碼及文檔管理平台,相關代碼片段篩選自各路編程大神貢獻的開源項目,源碼版權歸原作者所有,傳播和使用請參考對應項目的License;未經允許,請勿轉載。