Opened 9 years ago
Closed 8 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)
Change History (6)
#2
in reply to:
↑ 1
@
9 years ago
Replying to johnjamesjacoby:
Another approach might be to set
$pass1Text
inbindPasswordForm
first, before callingbindPass1
, 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.)
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 whenbindPass1
is calledbindPasswordForm
only callsbindPass1
if$pass1
is not emptybindPasswordForm
sets all of the other variables that are used within that scopeAnother approach might be to set
$pass1Text
inbindPasswordForm
first, before callingbindPass1
, but I'm not yet confident that won't break other things.