Skip to content

Commit 0527680

Browse files
committed
Code Quality: Add types for term insert/update/delete functions.
Add PHPStan array shapes for the `$args` parameter of `wp_insert_term()`, `wp_update_term()`, and `wp_delete_term()`, along with narrowed return types. The types describe the contract these functions are intended to be called with, rather than what unguarded callers happen to pass today. Developed in WordPress#12465. Follow-up to r62680. See #64898. git-svn-id: https://develop.svn.wordpress.org/trunk@62682 602fd350-edb4-49c9-b593-d223f7449a82
1 parent e8f519d commit 0527680

1 file changed

Lines changed: 29 additions & 0 deletions

File tree

src/wp-includes/taxonomy.php

Lines changed: 29 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -2047,6 +2047,12 @@ function wp_delete_object_term_relationships( $object_id, $taxonomies ) {
20472047
* }
20482048
* @return bool|int|WP_Error True on success, false if term does not exist. Zero on attempted
20492049
* deletion of default Category. WP_Error if the taxonomy does not exist.
2050+
* @phpstan-param non-empty-string $taxonomy
2051+
* @phpstan-param string|array{
2052+
* default?: positive-int,
2053+
* force_default?: bool,
2054+
* } $args
2055+
* @phpstan-return bool|WP_Error|0
20502056
*/
20512057
function wp_delete_term( $term, $taxonomy, $args = array() ) {
20522058
global $wpdb;
@@ -2437,6 +2443,17 @@ function wp_get_object_terms( $object_ids, $taxonomies, $args = array() ) {
24372443
* @type int $term_id The new term ID.
24382444
* @type int|string $term_taxonomy_id The new term taxonomy ID. Can be a numeric string.
24392445
* }
2446+
* @phpstan-param string|array{
2447+
* alias_of?: string,
2448+
* description?: string|null,
2449+
* parent?: non-negative-int,
2450+
* slug?: string|null,
2451+
* ...
2452+
* } $args
2453+
* @phpstan-return array{
2454+
* term_id: int,
2455+
* term_taxonomy_id: int|numeric-string,
2456+
* }|WP_Error
24402457
*/
24412458
function wp_insert_term( $term, $taxonomy, $args = array() ) {
24422459
global $wpdb;
@@ -2622,6 +2639,7 @@ function wp_insert_term( $term, $taxonomy, $args = array() ) {
26222639
do_action( 'edited_terms', $term_id, $taxonomy );
26232640
}
26242641

2642+
/** @var numeric-string|null $tt_id */
26252643
$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 ) );
26262644

26272645
if ( ! empty( $tt_id ) ) {
@@ -3229,6 +3247,17 @@ function wp_unique_term_slug( $slug, $term ) {
32293247
* }
32303248
* @return array|WP_Error An array containing the `term_id` and `term_taxonomy_id`,
32313249
* WP_Error otherwise.
3250+
* @phpstan-param array{
3251+
* alias_of?: string,
3252+
* description?: string,
3253+
* parent?: non-negative-int,
3254+
* slug?: string|null,
3255+
* ...
3256+
* } $args
3257+
* @phpstan-return array{
3258+
* term_id: int,
3259+
* term_taxonomy_id: int,
3260+
* }|WP_Error
32323261
*/
32333262
function wp_update_term( $term_id, $taxonomy, $args = array() ) {
32343263
global $wpdb;

0 commit comments

Comments
 (0)