Make WordPress Core

Opened 8 years ago

Closed 6 years ago

#39576 closed defect (bug) (invalid)

Admin - Tag autocomplete not work - WP >= 4.7

Reported by: mgermani's profile mgermani Owned by:
Milestone: Priority: normal
Severity: normal Version: 4.7
Component: Taxonomy Keywords: has-patch needs-testing close
Focuses: Cc:

Description

For WP 4.7 >= tags suggest not work properly. Ajax search return text delimited by "\n" but split parser fails:

File: wp-admin/js/tags-suggest.js
Line: 66 to 82

                                        if ( data ) {
                                                data = data.split( '\n' );

                                                for ( tagName in data ) {
                                                        var id = ++tempID;

                                                        tags.push({
                                                                id: id,
                                                                name: data[tagName]
                                                        });
                                                }

                                                cache = tags;
                                                response( tags );
                                        } else {
                                                response( tags );
                                        }  response( tags );
                    }

The method data = data.split( '\n' ); generate an Array() but "for in" construct set tagName with name method besides the int index.
I have fixed this issue checking if tagName is only a number:

                    if ( data ) {
                        data = data.split( '\n' );

                        for ( tagName in data ) {
                            var id = ++tempID;

                            if (!isNaN(tagName)) {
                                tags.push({
                                    id: id,
                                    name: data[tagName]
                                });
                            }
                        }

                        cache = tags;
                        response( tags );
                    } else {
                        response( tags );
                    }

I hope this help!
Best regards.

Attachments (1)

tags-suggest.js.patch (483 bytes) - added by mgermani 8 years ago.
tag-suggest.js patch

Download all attachments as: .zip

Change History (14)

#1 @swissspidy
8 years ago

Hey there,

Thanks for your report and welcome to WordPress Trac!

Would you mind uploading your changes in form of a patch? See https://make.wordpress.org/core/handbook/tutorials/trac/submitting-a-patch/ for details. This would make verifying these adjustments easier.

#2 @SergeyBiryukov
8 years ago

  • Milestone changed from Awaiting Review to 4.7.2

Related: [38797], [38880].

#3 @SergeyBiryukov
8 years ago

  • Version changed from 4.7.1 to 4.7

@mgermani
8 years ago

tag-suggest.js patch

#4 @swissspidy
8 years ago

  • Keywords has-patch needs-testing added

#5 @mgermani
8 years ago

I did some tests with clean Wordpress version and this bug is not present with default theme. The problem is encountered when install some custom themes like this:

Chrome Js console report this error with this message: "Uncaught TypeError: this._each is not a function" into prototype.js?ver=1.7.1:847

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


8 years ago

#7 @tristangemus
8 years ago

I can confirm in the latest version (4.8-alpha-39357-src) using the default Twenty Seventeen theme and a custom theme at random that tag autocomplete works as expected.

This sounds like a theme-specific issue.

#8 @swissspidy
8 years ago

  • Keywords close added

This sounds like a theme-specific issue.

Agreed. Plus, hard to test this with commercial themes. Until we're certain that a change in WordPress broke lots of themes and we can reproduce that easily, I'm suggesting to close this one.

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


8 years ago

#10 @jnylen0
8 years ago

  • Milestone changed from 4.7.3 to Awaiting Review

Cleaning up the 4.7.3 milestone.

#11 follow-up: @pampfelimetten
8 years ago

I got the same problem with 4.7.3, seems to be connected with the Geo Tag plugin (https://wordpress.org/plugins/geo-tag/)
When I deactivate that, it works again. Maybe that helps.

#12 in reply to: ↑ 11 @mgermani
8 years ago

You have tried to use the tags-suggest.js.patch to fix the problem?

Replying to pampfelimetten:

I got the same problem with 4.7.3, seems to be connected with the Geo Tag plugin (https://wordpress.org/plugins/geo-tag/)
When I deactivate that, it works again. Maybe that helps.

#13 @boonebgorges
6 years ago

  • Milestone Awaiting Review deleted
  • Resolution set to invalid
  • Status changed from new to closed

I managed to reproduce this using geo-tag, but the problem in that case is that they're loading a very old jQuery autocomplete script that interferes with tags-suggest.js. This kind of interference is difficult for core to avoid - it's the responsibility of plugin authors to use libraries that don't interfere with core functionality. I think we can close, unless someone can demonstrate how this is a problem with the way that WP itself loads its tag suggestion tools.

Note: See TracTickets for help on using tickets.