WordPress.org

Make WordPress Core

Opened 6 years ago

Closed 5 years ago

#34653 closed enhancement (worksforme)

TypeError: undefined is not an object (evaluating '$pass1Text.prop')

Reported by: johnjamesjacoby Owned by:
Milestone: Priority: normal
Severity: normal Version: 4.3
Component: Users Keywords: 2nd-opinion has-patch
Focuses: javascript Cc:

Description

I'm trying to enqueue the user-profile script (see: wp-admin/js/user-profile.js) in the WP User Profiles plugin, but outside of WordPress's traditional contexts, a Javascript error occurs that causes all other scripts to halt.

This happens in my plugin because (unlike WordPress core) not all user profile fields are displayed on the page at the same time, so the bindPass1() function fails to set the $pass1Text variable. It's expected in WordPress that these fields always exist when this script is enqueued.

The code in question was introduced as part of the updated strong password generator in WordPress 4.3. Previous to 4.3, enqueuing this script in the above context worked OK.

I don't exactly consider this a bug, but a small improvement to the user-profile script will make it possible to reuse this code in other places that are still relevant to a "user profile" area (BuddyPress, bbPress, etc...)

First pass patch incoming.

Attachments (1)

34653.1.patch (598 bytes) - added by johnjamesjacoby 6 years ago.

Download all attachments as: .zip

Change History (6)

#1 follow-up: @johnjamesjacoby
6 years ago

The above patch takes the easy way out, and only touches the offending line of code causing the Javascript error. The issue is a bit complex otherwise, and I'm not sure this error necessitates a refactor of this code as it exists today.

  • $pass1Text is only set when bindPass1 is called
  • bindPasswordForm only calls bindPass1 if $pass1 is not empty
  • bindPasswordForm sets all of the other variables that are used within that scope

Another approach might be to set $pass1Text in bindPasswordForm first, before calling bindPass1, but I'm not yet confident that won't break other things.

#2 in reply to: ↑ 1 @adamsilverstein
6 years ago

Replying to johnjamesjacoby:

Another approach might be to set $pass1Text in bindPasswordForm first, before calling bindPass1, but I'm not yet confident that won't break other things.

Your fix seems reasonable here, although I'm not sure I understand exactly how this happens in your plugin- I will try it to see.

I think you could safely set up $pass1Text in the outer scope without breaking anything.

Another idea that might better enable reuse would be changing the startup so the script is triggered manually for each use (instead of on script load), then you could probably trigger it when you needed it. Might also make sense to break out into a separate file since we use it other contexts besides user profile page (install, soon pw reset, etc.)

#3 @ocean90
6 years ago

Related: #34700

The error should be gone since [35649].

#4 @johnjamesjacoby
6 years ago

I'm not seeing this error anymore, so I bet r35649 addressed it.

Please feel free to close as worksforme if you see fit.

#5 @dd32
5 years ago

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

Based on the above comments, marking as worksforme.

Note: See TracTickets for help on using tickets.