WordPress.org

Make WordPress Core

Opened 10 months ago

Last modified 8 months ago

#39576 new defect (bug)

Admin - Tag autocomplete not work - WP >= 4.7

Reported by: mgermani Owned by:
Milestone: Awaiting Review 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 10 months ago.
tag-suggest.js patch

Download all attachments as: .zip

Change History (13)

#1 @swissspidy
10 months 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
10 months ago

  • Milestone changed from Awaiting Review to 4.7.2

Related: [38797], [38880].

#3 @SergeyBiryukov
10 months ago

  • Version changed from 4.7.1 to 4.7

@mgermani
10 months ago

tag-suggest.js patch

#4 @swissspidy
10 months ago

  • Keywords has-patch needs-testing added

#5 @mgermani
10 months 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.


9 months ago

#7 @tristangemus
9 months 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
9 months 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.


9 months ago

#10 @jnylen0
9 months ago

  • Milestone changed from 4.7.3 to Awaiting Review

Cleaning up the 4.7.3 milestone.

#11 follow-up: @pampfelimetten
8 months 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 months 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.

Note: See TracTickets for help on using tickets.