- Timestamp:
- 12/28/2022 02:07:16 PM (3 years ago)
- File:
-
- 1 edited
Legend:
- Unmodified
- Added
- Removed
-
trunk/tests/phpunit/includes/factory/class-wp-unittest-factory-for-term.php
r51298 r55019 7 7 * as a way to indicate expected return values from the given factory methods. 8 8 * 9 * @method int create( $args = array(), $generation_definitions = null )10 * @method WP_Term create_and_get( $args = array(), $generation_definitions = null )11 * @method int[]create_many( $count, $args = array(), $generation_definitions = null )9 * @method int|WP_Error create( $args = array(), $generation_definitions = null ) 10 * @method WP_Term|WP_Error|null create_and_get( $args = array(), $generation_definitions = null ) 11 * @method (int|WP_Error)[] create_many( $count, $args = array(), $generation_definitions = null ) 12 12 */ 13 13 class WP_UnitTest_Factory_For_Term extends WP_UnitTest_Factory_For_Thing { … … 29 29 * Creates a term object. 30 30 * 31 * @ param array $args Array or string of arguments for inserting a term.31 * @since UT (3.7.0) 32 32 * 33 * @return array|WP_Error 33 * @param array $args Array of arguments for inserting a term. 34 * 35 * @return int|WP_Error The term ID on success, WP_Error object on failure. 34 36 */ 35 37 public function create_object( $args ) { 36 38 $args = array_merge( array( 'taxonomy' => $this->taxonomy ), $args ); 37 39 $term_id_pair = wp_insert_term( $args['name'], $args['taxonomy'], $args ); 40 38 41 if ( is_wp_error( $term_id_pair ) ) { 39 42 return $term_id_pair; 40 43 } 44 41 45 return $term_id_pair['term_id']; 42 46 } … … 45 49 * Updates the term. 46 50 * 47 * @ param int|object $term The term to update.48 * @ param array|string $fields The context in which to relate the term to the object.51 * @since UT (3.7.0) 52 * @since 6.2.0 Returns a WP_Error object on failure. 49 53 * 50 * @return int The term ID. 54 * @param int|object $term The term to update. 55 * @param array $fields Array of arguments for updating a term. 56 * 57 * @return int|WP_Error The term ID on success, WP_Error object on failure. 51 58 */ 52 59 public function update_object( $term, $fields ) { 53 60 $fields = array_merge( array( 'taxonomy' => $this->taxonomy ), $fields ); 61 54 62 if ( is_object( $term ) ) { 55 63 $taxonomy = $term->taxonomy; 56 64 } 65 57 66 $term_id_pair = wp_update_term( $term, $taxonomy, $fields ); 67 68 if ( is_wp_error( $term_id_pair ) ) { 69 return $term_id_pair; 70 } 71 58 72 return $term_id_pair['term_id']; 59 73 } … … 61 75 /** 62 76 * Attach terms to the given post. 77 * 78 * @since UT (3.7.0) 63 79 * 64 80 * @param int $post_id The post ID. … … 80 96 * Create a term and returns it as an object. 81 97 * 98 * @since 4.3.0 99 * 82 100 * @param array $args Array or string of arguments for inserting a term. 83 101 * @param null $generation_definitions The default values. … … 93 111 94 112 $taxonomy = isset( $args['taxonomy'] ) ? $args['taxonomy'] : $this->taxonomy; 113 95 114 return get_term( $term_id, $taxonomy ); 96 115 } … … 98 117 /** 99 118 * Retrieves the term by a given ID. 119 * 120 * @since UT (3.7.0) 100 121 * 101 122 * @param int $term_id ID of the term to retrieve.
Note: See TracChangeset
for help on using the changeset viewer.