Exemplo n.º 1
0
 /**
  * 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;
 }
 /**
  * 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;
 }
Exemplo n.º 3
0
 /**
  * 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;
 }
Exemplo n.º 4
0
 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);
 }