Opened 8 years ago
Closed 8 years 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)
Change History (14)
#3
@
8 years 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.
#4
@
8 years 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
@
8 years 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.
#6
@
8 years 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.
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 inWP_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.