WordPress.org

Make WordPress Core

Opened 6 years ago

Last modified 2 years ago

#19590 new defect (bug)

Warnings when unregistering core taxonomies and post types

Reported by: xmarcos Owned by:
Milestone: Future Release 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)

number_format_i18n.jpg (56.3 KB) - added by xmarcos 6 years ago.
wp_error-1.jpg (125.2 KB) - added by xmarcos 6 years ago.
19590.patch (3.5 KB) - added by SergeyBiryukov 6 years ago.
19590.2.patch (6.4 KB) - added by SergeyBiryukov 6 years ago.

Download all attachments as: .zip

Change History (29)

#1 @SergeyBiryukov
6 years ago

  • Keywords reporter-feedback added

#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.

#2 @xmarcos
6 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.

@xmarcos
6 years ago

#3 @nacin
6 years ago

It's nto the first parameter being 0, it's the first parameter being passed a WP_Error.

#4 @nacin
6 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 @xmarcos
6 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 @SergeyBiryukov
6 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 @SergeyBiryukov
6 years ago

  • Keywords has-patch added

19590.patch adds some taxonomy_exists() checks and corrects wp_count_terms() inline docs.

#8 @SergeyBiryukov
6 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

#9 @SergeyBiryukov
6 years ago

  • Milestone changed from Awaiting Review to 3.4

#10 @SergeyBiryukov
6 years ago

  • Component changed from I18N to Taxonomy

#12 @SergeyBiryukov
6 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.

#13 @seancojr
6 years ago

  • Cc seancojr added

#14 @nacin
6 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

#17 @wonderboymusic
6 years ago

  • Milestone changed from Future Release to 3.5

#18 @nacin
6 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 @SergeyBiryukov
6 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.

#20 @SergeyBiryukov
6 years ago

Created a separate ticket for wp_count_terms() @return value correction: #21888.

#21 @SergeyBiryukov
5 years ago

#23031 was marked as a duplicate.

#22 @nacin
4 years ago

#16651 was marked as a duplicate.

#23 @chriscct7
3 years ago

  • Keywords needs-patch added; has-patch removed

This ticket was mentioned in Slack in #core by swissspidy. View the logs.


2 years ago

#25 @swissspidy
2 years ago

Note that since #14761 and #35227 unregister_post_type() and unregister_taxonomy() exist. They currently disallow disabling built-in post types/taxonomies

Note: See TracTickets for help on using tickets.