Repository navigation
Fatal error in wp_insert_term() when the term name is not a string #13521
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
base: trunk
Are you sure you want to change the base?
Changes from all commits
0890e0c
0f1e84c
99cded9
10a1d92
a21ad67
402aaaa
f216122
5f65187
4188078
1f8bcc4
19ef32b
51ab927
f406733
cb770c2
88f20e1
7ac3e7e
7f728ca
7a115d9
d7c4351
baf7adf
2b96c60
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
| Original file line number | Diff line number | Diff line change |
|---|---|---|
|
|
@@ -374,6 +374,10 @@ public function login_pass_ok( | |
| * @param string|array $data Escape single string or array of strings. | ||
| * @return string|null Returns with string if passed, alters by-reference | ||
| * when array is passed. | ||
| * | ||
| * @phpstan-template T of string|array | ||
| * @phpstan-param T $data | ||
| * @phpstan-param-out T $data | ||
| */ | ||
| public function escape( &$data ) { | ||
| if ( ! is_array( $data ) ) { | ||
|
|
@@ -387,6 +391,8 @@ public function escape( &$data ) { | |
| $v = wp_slash( $v ); | ||
| } | ||
| } | ||
|
|
||
| // @phpstan-ignore paramOut.type (The loop only slashes string values in place, so the shape of T is preserved.) | ||
| return null; | ||
| } | ||
|
|
||
|
|
@@ -1658,7 +1664,11 @@ protected function _insert_post( $user, $content_struct ) { | |
| return new IXR_Error( 401, __( 'Sorry, you are not allowed to assign a term to one of the given taxonomies.' ) ); | ||
| } | ||
|
|
||
| $term_ids = $post_data['terms'][ $taxonomy ]; | ||
| $term_ids = $post_data['terms'][ $taxonomy ]; | ||
| if ( ! is_array( $term_ids ) ) { | ||
| return new IXR_Error( 403, __( 'Invalid term ID.' ) ); | ||
| } | ||
|
|
||
| $terms[ $taxonomy ] = array(); | ||
| foreach ( $term_ids as $term_id ) { | ||
| $term = get_term_by( 'id', $term_id, $taxonomy ); | ||
|
|
@@ -1709,12 +1719,21 @@ protected function _insert_post( $user, $content_struct ) { | |
| } | ||
|
|
||
| $term_names = $post_data['terms_names'][ $taxonomy ]; | ||
|
Member
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. 🤖 Comment by Claude Opus 5.5
Member
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. 🤖 Comment by Claude Opus 5.5 Addressed in cb770c2. Both the |
||
| if ( ! is_array( $term_names ) ) { | ||
| return new IXR_Error( 401, __( 'Invalid term name.' ) ); | ||
|
Member
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Why 401 and not 400? |
||
| } | ||
|
|
||
| foreach ( $term_names as $term_name ) { | ||
| // Numeric names may arrive as <int> or <double> values. | ||
| if ( ! ( is_string( $term_name ) || is_int( $term_name ) || is_float( $term_name ) ) ) { | ||
| return new IXR_Error( 401, __( 'Invalid term name.' ) ); | ||
|
Member
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Why 401 and not 400? |
||
| } | ||
|
|
||
| if ( in_array( $term_name, $ambiguous_terms, true ) ) { | ||
|
Member
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. 🤖 Comment by Claude Opus 5.5 Ambiguous numeric term names cannot be detected here.
Member
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. 🤖 Comment by Claude Opus 5.5 Addressed in 5f65187. |
||
| return new IXR_Error( 401, __( 'Ambiguous term name used in a hierarchical taxonomy. Please use term ID instead.' ) ); | ||
| } | ||
|
|
||
| $term = get_term_by( 'name', $term_name, $taxonomy ); | ||
| $term = get_term_by( 'name', (string) $term_name, $taxonomy ); | ||
|
|
||
| if ( ! $term ) { | ||
| // Term doesn't exist, so check that the user is allowed to create new terms. | ||
|
|
@@ -2198,6 +2217,10 @@ public function wp_newTerm( $args ) { | |
| // Hold the data of the term. | ||
| $term_data = array(); | ||
|
|
||
| if ( isset( $content_struct['name'] ) && ! ( is_string( $content_struct['name'] ) || is_int( $content_struct['name'] ) || is_float( $content_struct['name'] ) ) ) { | ||
| return new IXR_Error( 403, __( 'Invalid term name.' ) ); | ||
|
Member
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Ditto above about the error code. 400 seems more appropriate. |
||
| } | ||
|
|
||
| $term_data['name'] = trim( $content_struct['name'] ); | ||
| if ( empty( $term_data['name'] ) ) { | ||
| return new IXR_Error( 403, __( 'The term name cannot be empty.' ) ); | ||
|
|
@@ -2316,6 +2339,10 @@ public function wp_editTerm( $args ) { | |
| } | ||
|
|
||
| if ( isset( $content_struct['name'] ) ) { | ||
| if ( ! ( is_string( $content_struct['name'] ) || is_int( $content_struct['name'] ) || is_float( $content_struct['name'] ) ) ) { | ||
| return new IXR_Error( 403, __( 'Invalid term name.' ) ); | ||
|
Member
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Ditto |
||
| } | ||
|
|
||
| $term_data['name'] = trim( $content_struct['name'] ); | ||
|
|
||
| if ( empty( $term_data['name'] ) ) { | ||
|
|
@@ -3541,6 +3568,10 @@ public function wp_newCategory( $args ) { | |
| return new IXR_Error( 401, __( 'Sorry, you are not allowed to add a category.' ) ); | ||
| } | ||
|
|
||
| if ( isset( $category['name'] ) && ! ( is_string( $category['name'] ) || is_int( $category['name'] ) || is_float( $category['name'] ) ) ) { | ||
| return new IXR_Error( 403, __( 'Invalid term name.' ) ); | ||
|
Member
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Ditto |
||
| } | ||
|
|
||
| /* | ||
| * If no slug was provided, make it empty | ||
| * so that WordPress will generate one. | ||
|
|
||
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Nit:
This seems like a more appropriate error code.