Opened 13 years ago
Last modified 6 years ago
#19590 new defect (bug)
Warnings when unregistering core taxonomies and post types
Reported by: |
|
Owned by: | |
---|---|---|---|
Milestone: | Priority: | normal | |
Severity: | normal | Version: | 3.3 |
Component: | Taxonomy | Keywords: | needs-patch |
Focuses: | Cc: |
Description
number_format_i18n (/wp-includes/functions.php, line 155) will raise a warning when the first parameter $number is not a double/float, which happens when it receives the value 0.
The error only shows up in the dashboard with a locale active (es_ES) in this case, screenshot attached.
The fix would be to cast the received value to float.
Current function,
function number_format_i18n( $number, $decimals = 0 ) { global $wp_locale; $formatted = number_format( $number, absint( $decimals ), $wp_locale->number_format['decimal_point'], $wp_locale->number_format['thousands_sep'] ); return apply_filters( 'number_format_i18n', $formatted ); }
Fix,
function number_format_i18n( $number, $decimals = 0 ) { global $wp_locale; $formatted = number_format( (float) $number, absint( $decimals ), $wp_locale->number_format['decimal_point'], $wp_locale->number_format['thousands_sep'] ); return apply_filters( 'number_format_i18n', $formatted ); }
It's the first bug i report here, so correct me if I'm doing it wrong.
Attachments (4)
Change History (29)
#2
@
13 years ago
- Cc xmarcos@… added
Ok, after reading your comment i further investigated, did a clean install and found that the problem raised when there are NO (zero) categories or tags. Here is a screenshot of both taxonomies empty.
#3
@
13 years ago
It's nto the first parameter being 0, it's the first parameter being passed a WP_Error.
#4
@
13 years ago
I can reproduce when the post_tag taxonomy is unregistered. Can you do a var_dump( $GLOBALS['wp_taxonomies'] );
if you think this isn't correct?
At the moment we rather terribly support a core taxonomy from being unregistered. (I doubt this is the only incompatibility.)
#5
@
13 years ago
You are right, the current theme disables core taxonomies because they are not used by the customer. (We are using custom tax and leaving them is confusing form an UI perspective)
The code I'm using is:
function fnx_disable_core_taxonomies() { global $wp_taxonomies; unset($wp_taxonomies['post_tag']); unset($wp_taxonomies['category']); } add_action('init', 'fnx_disable_core_taxonomies');
I understand the reason why this fails, but it'd be nice to support turning off unused features like this one in the future.
#6
@
13 years ago
- Keywords has-patch reporter-feedback removed
Reproduced with the code above. The number_format()
warning isn't the only one:
PHP 5.2.14:
Notice: Object of class WP_Error could not be converted to double in wp-includes/functions.php on line 155 Notice: Object of class WP_Error could not be converted to int in wp-includes/pomo/translations.php(171) : runtime-created function on line 2 Catchable fatal error: Object of class WP_Error could not be converted to string in wp-admin/includes/dashboard.php on line 552
PHP 5.3.3:
Warning: number_format() expects parameter 1 to be double, object given in wp-includes\functions.php on line 155 Notice: Object of class WP_Error could not be converted to int in wp-includes\pomo\translations.php(171) : runtime-created function on line 2 Catchable fatal error: Object of class WP_Error could not be converted to string in wp-admin/includes/dashboard.php on line 552
#7
@
13 years ago
- Keywords has-patch added
19590.patch adds some taxonomy_exists()
checks and corrects wp_count_terms()
inline docs.
#8
@
13 years ago
- Summary changed from number_format_i18n raise a warning when first parameter is 0 to number_format_i18n() raises a warning with unregistered taxonomies
#12
@
13 years ago
19590.2.patch also adds post_type_exists()
checks.
There are also warnings in Recent Comments widget and on Comments screen when unregistering post
post type. Didn't touch them for now, that should probably go into #14761.
#14
@
13 years ago
- Milestone changed from 3.4 to Future Release
- Summary changed from number_format_i18n() raises a warning with unregistered taxonomies to Warnings when unregistering core taxonomies and post types
#18
@
12 years ago
Lots of things will break all over core if you unregister a core tax or type. Very unexpected behavior. I'd rather deal with it with a systematic approach where we say we can truly support that, than duct tape patches. Still thinking punt.
#19
@
12 years ago
- Milestone changed from 3.5 to Future Release
- Severity changed from minor to normal
Agreed. There are a lot of patches in 3.5 milestone needing review, and this is out of scope.
#17299 also has a patch.
What are the steps to reproduce this?
I've checked es_ES package on PHP 5.2.14 and 5.3.3 with WP_DEBUG on, and didn't see the warning in the Dashboard.