Simple Membership Plugin › Forums › Simple Membership Plugin › Error message for WordPress administrator (wp_password_reset_hook)
- This topic has 2 replies, 3 voices, and was last updated 7 years, 3 months ago by
admin.
-
AuthorPosts
-
August 6, 2019 at 11:05 am #18694
John
ParticipantA small error in sourcecode.
The current version (3.8.3) has a small code error.
It’s in the file at simple-membership/classes/class.simple-wp-membership.php
That PHP file can be accessed in WP admin at
<domain>/wp-admin/plugin-editor.php?file=simple-membership%2Fclasses%2Fclass.simple-wp-membership.php&plugin=simple-membership%2Fsimple-wp-membership.phpfunction wp_password_reset_hook($user, $pass) { $swpm_id = SwpmUtils::get_user_by_user_name($user->user_login); if (!empty($swpm_id)) { $password_hash = SwpmUtils::encrypt_password($pass); global $wpdb; $wpdb->update($wpdb->prefix . "swpm_members_tbl", array('password' => $password_hash), array('member_id' => $swpm_id)); } }The issue is when someone is using the site with their WordPress admin account and doing something that invokes wp_password_reset_hook.
i.e. an account that was not created with SWPM registration form (e.g. Subscriber role), instead it was created inside WordPress dashboard directly (e.g. Administrator role, Editor role, etc).
wp_password_reset_hook gets triggered but leads to a PHP error because the WordPress administrator/editor user is being looked up in the SWPM database tables and such a doesn’t exist there. The administrator/editor user is exclusive to WordPress internal wp_users table.
This is a non-fatal error, but it when debugging is enabled (during dev phase, not for production), that PHP error text can be seen on the web page.
The code fix to avoid the PHP error is:
function wp_password_reset_hook($user, $pass) { $swpm_user = SwpmMemberUtils::get_user_by_user_name($user->user_login); if (empty($swpm_user)) { SwpmLog::log_auth_debug("[wp_password_reset_hook] - SWPM user not found for '" . $user->user_login ."' - this is OK, assuming that this user was created directly in WP Dashboard", true); return; } $swpm_id = $swpm_user->member_id; if (!empty($swpm_id)) { $password_hash = SwpmUtils::encrypt_password($pass); global $wpdb; $wpdb->update($wpdb->prefix . "swpm_members_tbl", array('password' => $password_hash), array('member_id' => $swpm_id)); } }August 6, 2019 at 12:10 pm #18695mbrsolution
ModeratorHi, thank you for sharing your solution. I have submitted a message to the developers to investigate further your fix.
Kind regards
August 7, 2019 at 7:05 am #18700admin
KeymasterThank you. I have updated the code to fix this. It will go out with the next release.
-
AuthorPosts
- You must be logged in to reply to this topic.