paulgibbs / achievements

Achievements gamifies your WordPress site with challenges, badges, and points.
http://achievementsapp.com
63 stars 9 forks source link

"A new user activates their account on your website" broken #102

Open paulgibbs opened 11 years ago

paulgibbs commented 11 years ago

Per http://wordpress.org/support/topic/a-new-user-activates-achievement there seems to be an issue after some very quick testing.

Need to test against 1.6 to see if a regression in BP.

paulgibbs commented 11 years ago

Achievements never worked with anything before 1.7, so it's not a regression.

I don't know how this ever worked, although I assume it must have because I would have tested it before shipping 3.0 ;) BuddyPress' action here happens before Achievements is fully loaded, so the achievement doesn't work.

I seriously dislike these 'on user registration/activation' hooks, they always cause some sort of annoying problem. I am probably going to remove this action from Achievements for 3.4.

paulgibbs commented 11 years ago

In 3.4, I've added a similar action for user creation for regular WordPress (when BuddyPress is NOT active). However, the new action (and the existing BP user registration action, which will eventually be removed in favour of the new action) doesn't work when BP is active.

Root cause is that dpa_register_events() doesn't do anything if is_user_logged_in() === false. The new filter added in f87fb4014 was intended to work around this by allowing extensions to conditionally filter whether to "skip" the logged-in user check. However, this revealed the true cause was load order problems.

I don't want to remove the logged-in user check totally because this will add a query to every front-end page load for all users (anonymous + logged-in). There may also be deeper changes needed to be made inside the core Achievements logic to support such a change. Therefore, I'd like to remove the is_user_logged_in() check only on the two BP screens where user registration occurs; bp_is_activation_page() and bp_is_register_page().

See commit 44bec5b1b01037585fb278f3ab4d74a0a29df9a5 in the ticket102 branch for my latest attempt at a fix for this (which doesn't work yet). When the execution gets to this point in the Achievements plugin, it's too early and BP's page request/navigation router hasn't run yet; so bp_is_activation_page() and bp_is_register_page() return false. It's also before WP_Query has been run, so I can't use it to tell if I'm on a "page" and then be able to compare that page ID against one of the page IDs in BP's bp_pages site option.

Parsing the URL manually is going to be very tricky to do reliably; I'd much rather leave WP or BP to figure out where I am for me. I also don't want to make Achievements run later as that's a fairly substantial change which will be hard for me to test thoroughly.