#31134 closed defect (bug) (fixed)
register_post_type() should call a _doing_it_wrong() when called with an empty post type name
Reported by: | tyxla | Owned by: | SergeyBiryukov |
---|---|---|---|
Milestone: | 4.2 | Priority: | normal |
Severity: | minor | Version: | 3.0 |
Component: | Posts, Post Types | Keywords: | has-patch commit |
Focuses: | Cc: |
Description
If you misuse register_post_type()
with an empty string as a first parameter, this will currently not throw any notice.
Anyway, it is definitely wrong and can lead to some very weird results both in the administration and in the frontend.
I suggest that a _doing_it_wrong()
should be called to cover this case.
Attachments (5)
Change History (17)
#2
@
10 years ago
- Keywords close added
Do we really have to catch every possible edge case?
Besides that, there is now too much code duplication, because you suggested the same thing for #31135. If we really do this, the code should be separated to a function like wp_str_min_max( $str, $min, $max, $encoding )
or something similar.
#3
@
10 years ago
- Keywords needs-unit-tests added; close removed
- Milestone changed from Awaiting Review to 4.2
- Severity changed from normal to minor
- Type changed from enhancement to defect (bug)
As I suggested on #31135, I think we can double up on the _doing_it_wrong()
call by defining the minimum and maximum in the same condition and string. It would be also be helpful to have a unit test to cover the empty string case.
#4
follow-up:
↓ 6
@
10 years ago
@DrewAPicture yeah, all makes sense, thanks. A single _doing_it_wrong()
call would be better, and unit tests would be needed here. Let me attach a patch. Since there is no unit test for the maximum post type length, I'll add one for that too.
@
10 years ago
Updating first patch. Now using a single _doing_it_wrong()
call for both post type min and max, also adding unit tests for both cases.
#6
in reply to:
↑ 4
@
10 years ago
- Keywords needs-unit-tests added
Replying to tyxla:
Since the issues between registering taxonomies and post types are fairly aligned, see comment:5:ticket:31135 for how I would approach the tests for this, except for post types instead of taxonomies. The difference of course would be that there isn't currently a test that I can find for either short or long post types.
So in this case, maybe creating a single test_register_post_type_length()
would suffice, again, following similar syntax to that of test_register_long_taxonomy()
– in terms of:
- Notating the ticket number
- Using
@expectedIncorrectUsage
- Checking for the
WP_Error
object to confirm instead of the_doing_it_wrong()
#7
@
10 years ago
- Keywords needs-unit-tests removed
Thanks for your suggestions, they definitely make things better. Attaching an updated patch again.
#8
@
10 years ago
- Keywords commit added
- Owner set to SergeyBiryukov
- Status changed from new to reviewing
Related: #28683
Adding a
_doing_it_wrong()
whenregister_post_type()
is called with an empty post type name.