Automattic / sensei

Sensei LMS - Online Courses, Quizzes, & Learning
https://senseilms.com
GNU General Public License v2.0
539 stars 198 forks source link

Incorrect User ID and SENSEI_PREVIEW data returned by wp_get_current_user() when Sensei LMS Preview Setting is Enabled #6840

Open SchneiderSam opened 1 year ago

SchneiderSam commented 1 year ago

When using Sensei LMS with WishList Member, we discovered an issue that persists even after conducting plugin/theme conflict testing. The issue is related to the data returned by Sensei LMS when the WordPress function wp_get_current_user() is called, and the user viewing the page has some kind of preview setting enabled.

Upon investigation, we found that when a user with a preview setting enabled views a course, the ID value returned by the wp_get_current_user() function is incorrect, and the user_login points to "SENSEI_PREVIEW". The expected behavior is to return the correct user ID and user_login without the "SENSEI_PREVIEW" data.

Here is the recorded data for a user with a preview setting enabled: WP_User Object ( [data] => stdClass Object ( [ID] => 1528 [user_login] => sensei_preview_68329329_1_4864 [user_pass] =>REDACTED [user_nicename] => sensei_preview_68329329_1_4864 [user_email] => sensei_preview_68329329_1_4864@preview.senseilms [user_url] => [user_registered] => 2023-04-17 13:28:31 [user_activation_key] => [user_status] => 0 [display_name] => Preview Student 4864-1 (Samuel) [spam] => 0 [deleted] => 0 ) [ID] => 1528 [caps] => Array ( [preview_student] => 1 ) [cap_key] => FtyLPLc6_capabilities [roles] => Array ( [0] => preview_student ) [allcaps] => Array ( [preview_student] => 1 ) [filter] => [site_id:WP_User:private] => 1 )

For comparison, here is the recorded data for a user without a preview setting enabled: WP_User Object ( [data] => stdClass Object ( [ID] => 1531 [user_login] => wishlistraffy@gmail.com [user_pass] => REDACTED [user_nicename] => wishlistraffygmail-com [user_email] => wishlistraffy@gmail.com [user_url] => [user_registered] => 2023-04-20 13:35:00 [user_activation_key] => [user_status] => 0 [display_name] => Raffy Wishlist [spam] => 0 [deleted] => 0 ) [ID] => 1531 [caps] => Array ( [administrator] => 1 ) [cap_key] => FtyLPLc6_capabilities [roles] => Array ( [0] => administrator ) [allcaps] => Array ( [switch_themes] => 1 [edit_themes] => 1 [activate_plugins] => 1 [edit_plugins] => 1 [edit_users] => 1 [edit_files] => 1 [manage_options] => 1 [moderate_comments] => 1 [manage_categories] => ||--REMOVED FURTHER LINES--||

Lastly, here's the data for the user with a preview setting enabled visiting a different course without the preview setting: WP_User Object ( [data] => stdClass Object ( [ID] => 1 [user_login] => samuel@abc.de [user_pass] => $P$BWHHkwYVdk5/hNFAoUDo2ZqkSKbDoc. [user_nicename] => samuelbaubeaver-de [user_email] => samuel@abc.de [user_url] => [user_registered] => 2020-02-07 12:58:47 [user_activation_key] => [user_status] => 0 [display_name] => Samuel [spam] => 0 [deleted] => 0 ) [ID] => 1 [caps] => Array ( [wpml_manage_translation_management] => 1 [wpml_manage_languages] => 1 [wpml_manage_theme_and_plugin_localization] => 1 [wpml_manage_support] => 1 [wpml_manage

From the collected data, it appears that the issue is caused by a setting in Sensei LMS that alters the data returned by the WordPress function wp_get_current_user().

Steps to reproduce:

Install and activate Sensei LMS and WishList Member plugins Enable the preview setting for a user in Sensei LMS Call the wp_get_current_user() function and observe the returned data Expected result: The wp_get_current_user() function should return the correct user ID and user_login without the "SENSEI_PREVIEW" data.

Actual result: The wp_get_current_user() function returns an incorrect user ID and user_login containing "SENSEI_PREVIEW" data when the user has a preview setting enabled in Sensei LMS.

SchneiderSam commented 1 year ago

With this filter it works, but i still think: this issue is a bug.

add_filter( 'sensei_feature_preview_students', '__return_false' );