WordPress.org

Make WordPress Core

Opened 8 months ago

Closed 6 months ago

#39308 closed defect (bug) (fixed)

Invalid taxonomy error in WP 4.7

Reported by: wpfo Owned by: swissspidy
Milestone: 4.7.3 Priority: normal
Severity: minor Version: 4.7
Component: Taxonomy Keywords: has-patch has-unit-tests fixed-major
Focuses: Cc:

Description

Some plugins e.g 'more taxonomies' works not more properly in WP 4.7

We get such an url
/wp-admin/edit-tags.php?taxonomy=
After click on such an url we get white screen with the message:
Invalid taxonomy.

Tested on Desktop (Host: Windows 8.1 update)
Firefox: 50.0.2

Error cause:
'name' is not more set in $args array in function register_taxonomy()
In WP 4.6.1:

<?php
$args['name'] = $taxonomy;

This should fix the problem:

Set it again as below:

In \wp-includes\class-wp-taxonomy.php
In function set_props() insert this line:

<?php
$args['name'] = $this->name;

before the line:

<?php
foreach ( $args as $property_name => $property_value ) {

NOTE: I know that no one use this property in args list!
In codex is even not mentioned that this property exists.
But as we see some plugins uses it and there's really no reason to remove setting it.

Attachments (3)

ticket_39308_solution_1.patch (363 bytes) - added by wpfo 8 months ago.
ticket_39308_solution_1.patch
ticket_39308_solution_2.patch (524 bytes) - added by wpfo 8 months ago.
ticket_39308_solution_2.patch
39308.diff (1.0 KB) - added by swissspidy 7 months ago.

Download all attachments as: .zip

Change History (14)

#1 @wpfo
8 months ago

  • Keywords has-patch added

#2 @swissspidy
8 months ago

  • Keywords reporter-feedback added; has-patch removed

Hey there,

Thanks for your report.

It's worth noting that the name is being set in the constructor (WP_Taxonomy::__construct()). There's no need to set it again in WP_Taxonomy::set_props() because it's already there. If there's a problem it's probably somewhere else.

It's worth noting that the 'More Taxonomies' plugin hasn't been updated in over 5 years and directly modifies the $wp_taxonomies global. Are there any other plugins where this happens? Some sample code to reproduce would be nice.

Ps. The has-patch keyword is only for when there's a patch file attached to a ticket.

#3 @wpfo
8 months ago

  • Keywords reporter-feedback removed

Hey swissspidy,
You are wrong!

It's worth noting that the name is being set in the constructor

(WP_Taxonomy::__construct()). There's no need to set it again in
WP_Taxonomy::set_props() because it's already there. If there's a
problem it's probably somewhere else.

1)
'name' is setted in __construct() of WP_Taxonomy from field $taxonomy
$this->name = $taxonomy;

2)
In function 'set_props()' $this->name is setted (resetted) again from $args 'name'
if 'name' in $args exists and 'name' in $args is , in this code block:

<?php
foreach ( $args as $property_name => $property_value ) {
        $this->$property_name = $property_value;
}

And I haven't said to set it again, but to set ($argsname? = $this->name);
to avoid that $this->name would be reseted;

Also solution (as posted) should work well:

<?php
$args['name'] = $this->name;//There is no reason not to have this. Why this was removed?

foreach ( $args as $property_name => $property_value ) {
        $this->$property_name = $property_value;
}

It's worth noting that the 'More Taxonomies' plugin hasn't been updated in

over 5 years and directly modifies the $wp_taxonomies global. Are there
any other plugins where this happens? Some sample code to reproduce would
be nice.

Plugin 'More Taxonomies' has over 2000 Active Installs.

To reproduce it:
1)
Install that plugin and create a taxonomy e.g for post_type 'post'.

2)
Or Create a taxonomy in code and set 'name' -> in $args

Ps. The has-patch keyword is only for when there's a patch file attached

to a ticket.

I don't see Keyword has-solution.

Last edited 7 months ago by SergeyBiryukov (previous) (diff)

#4 @theMikeD
8 months ago

FWIW: In general, it's best practice to let a senior dev or core committer set the keywords once the validity of the bug has been confirmed.

At a quick glance this looks like a really old plugin (ancient even) that needs an update to conform to the term splitting stuff that took place a few releases back that made the taxonomy field no longer required. Have you tried contacting the plugin author?

#5 @wpfo
8 months ago

@theMikeD:
I have resolved my problem using filter 'register_taxonomy_args'.
It is about 2000 websites.

@swissspidy:
Regardless of plugin you should avoid overwriting 'name' property, taxonomy key.

Slution 2 would be to ignore $argsname? to avoid overwriting
'name' Property (Taxonomy key) setted from param $taxonomy in construct()

<?php
foreach ( $args as $property_name => $property_value ) {
        // Avoid overwriting 'name' Property ('Taxonomy key')
        if ( 'name' !== $property_name ) {
                $this->$property_name = $property_value;
        }
}

I have attached patches for both solutions.

@wpfo
8 months ago

ticket_39308_solution_1.patch

@wpfo
8 months ago

ticket_39308_solution_2.patch

@swissspidy
7 months ago

#6 @swissspidy
7 months ago

  • Keywords has-patch has-unit-tests added
  • Milestone changed from Awaiting Review to 4.7.3
  • Severity changed from normal to minor

Moving to the 4.7.3 milestone for consideration as it's a regression in 4.7.

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


6 months ago

#8 @swissspidy
6 months ago

  • Owner set to swissspidy
  • Status changed from new to accepted

#9 @swissspidy
6 months ago

  • Resolution set to fixed
  • Status changed from accepted to closed

In 40049:

Taxonomy: Disallow overriding the name property when registering a taxonomy.

Props wpfo for initial patch.
Fixes #39308.

#10 @swissspidy
6 months ago

  • Keywords fixed-major added
  • Resolution fixed deleted
  • Status changed from closed to reopened

Reopening for consideration.

#11 @dd32
6 months ago

  • Resolution set to fixed
  • Status changed from reopened to closed

In 40083:

Taxonomy: Disallow overriding the name property when registering a taxonomy.

Props wpfo for initial patch, swissspidy.
Merges [40049] to the 4.7 branch.
Fixes #39308.

Note: See TracTickets for help on using tickets.