bobbingwide / oik-clone

Clone content between sites
https://www.oik-plugins.com/oik-plugins/oik-clone-clone-your-wordpress-content/
GNU General Public License v2.0
5 stars 0 forks source link

Fatal error from create_term when term already exists #33

Closed bobbingwide closed 3 years ago

bobbingwide commented 5 years ago

While running oikwp class-oik-clone-pull.php jetpack.wp.a2z block url=blocks.wp.a2z to pull blocks from jetpack.wp.a2z to blocks.wp.a2z there was a Fatal error: Uncaught Error: Cannot use object of type WP_Error as array in C:\apache\htdocs\wordpress\wp-content\plugins\oik-clone\admin\class-oik-clone-taxonomies.php:462

A WP_Error was returned from the wp_insert_term() call in create_term() for the taxonomy term "contact" where the source term id was 139 and the existing term was 132.

The existing term was "Contact" - which has a different case from the term we were trying to create.

bobbingwide commented 5 years ago

There was also a similar message when a taxonomy being cloned does not exist in the slave.

bobbingwide commented 5 years ago

The fix for the first problem is to find the term using the slug rather than the name. The fix for the second problem is to not continue processing taxonomy terms when the taxonomy is not known to the slave.

bobbingwide commented 5 years ago

Changing to match on slug works some of the time, but not for a taxonomy term with a name of &. Try changing it back to match on lower case name.

We can't do that since the name fields in the list of terms are mixed case.
A pragmatic solution, other than to attempt to create the term and then be told there's a problem, is to check if the term_id and slug are the same. If they are then attempt to match on the term name else match on the slug.

bobbingwide commented 5 years ago

IMO WordPress’s logic is flawed. Why tell the calling routine that creating a term failed when there’s a problem with the case? WordPress is responsible for creating the slug, so it should just say, ‘here’s the term you were looking for’.

bobbingwide commented 3 years ago

oik-clone v2.0.0 is now released. Closing this issue.