Make WordPress Core

Changeset 62682


Ignore:
Timestamp:
07/09/2026 08:55:02 PM (3 weeks ago)
Author:
westonruter
Message:

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 https://github.com/WordPress/wordpress-develop/pull/12465.
Follow-up to r62680.

See #64898.

File:
1 edited

Legend:

Unmodified
Added
Removed
  • trunk/src/wp-includes/taxonomy.php

    r62680 r62682  
    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 */
    20512057function wp_delete_term( $term, $taxonomy, $args = array() ) {
     
    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 */
    24412458function wp_insert_term( $term, $taxonomy, $args = array() ) {
     
    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
     
    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 */
    32333262function wp_update_term( $term_id, $taxonomy, $args = array() ) {
Note: See TracChangeset for help on using the changeset viewer.