Hi @iovamihai which version of Helpful are you currently using?
Edit
You are welcome to test the current development version: Download
-
This reply was modified 7 years ago by
Pixelbart.
Hey @pixelbart,
The version I had when the customer reported the issue was 3.0.10. I’m currently on 3.0.11, but I can’t say if the issue is still happening or not.
Will give the development version a quick try this weekend.
All the best,
Mihai
@iovamihai All right, then please just let me know so I know if the bug’s fixed. You can also see the versions in the Helpful settings on the right side in the sidebar.
These would also be useful for me.
Hey @pixelbart,
Just tried out the development version and I got mixed results. For some WP instances on my machine I got the warning and for some I did not.
This is the error: Warning: Cannot modify header information – headers already sent by (output started at /development/web projects/socialpug/wp-content/themes/twentyseventeen/header.php:15) in /development/web projects/socialpug/wp-content/plugins/helpful/core/classes/Base.class.php on line 635
The warning appears just above the buttons and also in the header. I believe I’ve managed to track down the issue.
For the buttons, it seems to be tied to the “helpful_helpers” filter and the “frontend_helpers” callback added to the filter.
Within the “frontend_helpers” callback a call is made to the get_current_user() method. This method then calls the setcookie() function.
Given that the “helpful_helpers” filter runs in the callback for “the_content” filter, the setcookie() function might run after the output started, resulting in the warning.
For the header, I see the get_current_user() method runs in the callback to the “wp_enqueue_scripts” action. Given that this gets executed after the output started, it results in the warning.
These are the only two instances I’ve found the get_current_user() method, thus it seems the setcookie() is being called too late in both occasions.
I’m not sure why it works on some instances though. I hope this information helps.
All the best,
Mihai
@iovamihai
Wow, thanks for the detailed explanation. I couldn’t reproduce the error, so thank you very much.
I have now set the cookie differently. It is now set using template_redirect. This should (hopefully) solve the problems.
In case you don’t know the hook: It’s great!
-
This reply was modified 7 years ago by
Pixelbart.
You can download the development version here: Download
The version will also receive all updates in the future. So you don’t have to worry about that.
Hey @pixelbart,
No worries whatsoever, I really like your plugin, so glad I can help. Thank you for the quick responses, I really appreciate it!
There is a small issue though with the new code. On first run, the following error is thrown: “Notice: Undefined index: helpful_user in /development/web projects/socialpug/wp-content/plugins/helpful/core/classes/Base.class.php on line 626”
This is due to the missing “helpful_user” element of the $_COOKIE array from get_current_user(). On first load, the setcookie() will not alter the $_COOKIE global, thus the added cookie will not be available. It will be available on the second load.
Setting it directly in set_user_cookie() should do the trick.
To test it out I’ve deleted the cookie by adding the following line in set_user_cookie() right before the closing bracket:
setcookie( “helpful_user”, null, -1 );
Hope this helps!
All the best,
Mihai
@iovamihai
Thank you, that helped me a lot. The development version is updated. Should now (hopefully) work as intended.
Development Version
Hey @pixelbart,
Looking good on my end so far. If I find anything, I’ll let you know.
Thank you again for the quick replies and the quick updates.
All the best,
Mihai
I have to thank you! I’ll update Helpful then right away so all have the corrections. I have rewritten a lot of code and commented.
With the help of Codacy, I was also able to solve other things that I didn’t have on the screen before.
Kevin
No worries, glad I could help!
Will give Codacy a try, thank you for the recommendation.
All the best,
Mihai