q2a / question2answer

Question2Answer is a free and open source platform for Q&A sites, running on PHP/MySQL.
http://www.question2answer.org/
GNU General Public License v3.0
1.63k stars 628 forks source link

Fix captcha on feedback page not being shown for anonymous users #924

Closed pupi1985 closed 1 year ago

pupi1985 commented 2 years ago

When the "Use captcha for anonymous posts" setting is unchecked, captcha is not showing on feedback form, as it is treated as an anonymous post.

I could just fix this by checking if the user is anonymous and, if it is, just avoid calling the qa_user_captcha_reason(). The thing is that I would be getting part of the logic from that function out of the function. So I'd rather keep the logic (the if statement) in the function and just send the function the actual data to process it.

In other words, I think it is better to change the signature from:

function qa_user_captcha_reason($userlevel = null)

to:

function qa_user_captcha_reason($userlevel = null, $showCaptchaIfAnonymous = true)

This way the

if (qa_opt('captcha_on_anon_post') && !isset($userid))

would become parameterizable and the caller will determine if the captcha should respect the captcha_on_anon_post or any other setting or criteria.

Changes should be backwards-compatible as well