WordPress.org

Make WordPress Core

Opened 18 months ago

Last modified 6 months ago

#19590 new defect (bug)

Warnings when unregistering core taxonomies and post types

Reported by: xmarcos Owned by:
Priority: normal Milestone: Future Release
Component: Taxonomy Version: 3.3
Severity: normal Keywords: has-patch
Cc: xmarcos@…, seancojr

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 18 months ago.
wp_error-1.jpg (125.2 KB) - added by xmarcos 18 months ago.
19590.patch (3.5 KB) - added by SergeyBiryukov 18 months ago.
19590.2.patch (6.4 KB) - added by SergeyBiryukov 17 months ago.

Download all attachments as: .zip

Change History (25)

xmarcos18 months ago

comment:1 SergeyBiryukov18 months 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.

comment:2 xmarcos18 months 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.

xmarcos18 months ago

comment:3 nacin18 months ago

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

comment:4 nacin18 months 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.)

comment:5 xmarcos18 months 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.

comment:6 SergeyBiryukov18 months 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

SergeyBiryukov18 months ago

comment:7 SergeyBiryukov18 months ago

  • Keywords has-patch added

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

comment:8 SergeyBiryukov18 months 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

comment:9 SergeyBiryukov18 months ago

  • Milestone changed from Awaiting Review to 3.4

comment:10 SergeyBiryukov18 months ago

  • Component changed from I18N to Taxonomy

SergeyBiryukov17 months ago

comment:12 SergeyBiryukov17 months 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.

comment:13 seancojr14 months ago

  • Cc seancojr added

comment:14 nacin14 months 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

comment:17 wonderboymusic9 months ago

  • Milestone changed from Future Release to 3.5

comment:18 nacin9 months 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.

comment:19 SergeyBiryukov9 months 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.

comment:20 SergeyBiryukov9 months ago

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

comment:21 SergeyBiryukov6 months ago

#23031 was marked as a duplicate.

Note: See TracTickets for help on using tickets.