wpForoMember::profi...
 
Notifications
Clear all

wpForo 1.x.x [Closed] wpForoMember::profile_url() is called too early in class-members.php:1175

5 Posts
2 Users
0 Reactions
724 Views
Posts: 3
Topic starter
(@mrwhisk)
Active Member
Joined: 4 years ago

Hello,

It is not possible to use the filter 'wpforo_member_profile_url' correctly due to the way that wpForoMember is written. Trace:

(71) wpForoMember::__construct() calls init_current_user on action 'set_current_user'. 

(1900) wpForoMember::init_current_user() calls wpForoMember::get_member() 

(1175) wpForoMember::get_member() calls wpForoMember::profile_url()

The issue here is that the 'set_current_user' action fires before 'init'. As a result, using core wp functions when filtering with 'wpforo_member_profile_url' causes critical exceptions. For example, calling get_author_posts_url yields:

PHP Fatal error: Uncaught Error: Call to a member function get_author_permastruct() on null

---

A simple fix would be to defer getting an actual value for $member['profile_url'] until at the earliest 'init'.

Fixing this issue would be most appreciated to avoid me having to fork wpforo.

With thanks,

Dr Teapot.

4 Replies
Alvina
Posts: 1868
Moderator
(@alvina)
Member
Joined: 5 years ago

Hi @mrwhisk,

I've just asked our developers about it and currently, I'm waiting for the response from them. I'll update the topic one I get some response from them.

Alvina
Posts: 1868
Moderator
(@alvina)
Member
Joined: 5 years ago

Hi @mrwhisk,

Please note the wpForo connects to the correct hook set_current_user. And each time when in the new user set in WordPress, we change the current user values we have with the new user's values. This is the right way and to refuse it is wrong. 

The issue here is that the 'set_current_user' action fires before 'init'. As a result, using core wp functions when filtering with 'wpforo_member_profile_url' causes critical exceptions. For example, calling get_author_posts_url yields:

The problem is in that most of WordPress plugins and themes can call the set_current_user hook, before the init hook is called, and there is no way to avoid that. You just need to check if the set_current_user hook exis using the following functions, to avoid the fatal errors:

function_exists()

is_null()

method exists()

Posts: 3
Topic starter
(@mrwhisk)
Active Member
Joined: 4 years ago

Hi There,

Thankyou for the reply. Absolutely, I agree that initializing the wpForoMember object on the set_current_user hook is indeed the correct behavior.

To be clear, the issue here is that wpForoMember fetches a value for $member['profile_url'] on initialization. Wouldn't it make much more sense to defer setting this value until (at least) wordpress has finished loading?

Whilst we can indeed avoid the critical errors with functions_exist() calls etc, we then run the risk of $member['profile_url'] containing an erroneous value. FYI, our goal here is to have total control of $member['profile_url'] using the hook wpforo_member_profile_url.

Does that make sense?

Thanks again 🙂

1 Reply
Alvina
Moderator
(@alvina)
Joined: 5 years ago

Member
Posts: 1868

@mrwhisk,

We will check it and if it possible we will try to implement it.