widget signup button
-
Hi all. I have a problem with Challonge widget. I see the bug when users no logged in. Look at screen 1.
When count of participants = 0, signup button is good – http://imgur.com/xe3kNoD .
When count of participants > 0, dont’t see signup button – http://imgur.com/AWGiCwx .
Work good only if you are loged-in on wordpress.
My Privacy settings – http://imgur.com/GGI0Jnp .P.s Sorry for my bad englsih 🙂
-
That is odd. I am unfortunately unable to reproduce your issue. I will continue to look into this for any possible causes.
Thank you for your detailed feedback! 🙂
I can confirm this issue.
If the participant number is 0 the buttons show up correctly in shortcode list and the widget. But if there are already participants in the tournament, the buttons won’t show up.
But this issue only happens if you are not logged in! If you are logged in the buttons will show up in both cases.
Thanks for confirming this! I will take another look at this issue.
I found out that $this->oLnk->signed_up in class-challonge-ajax.php has the wrong value. It must be “false” to show the signup button but in the following code it gets set to “true”.
The error must be in $pmisc[0] because elseif statement is executed in this if clause
if ( empty( $pmisc[0] ) ) { $this->oLnk->all_have_misc = false; } elseif ( $pmisc[0] == $this->oLnk->usrkey ) { $this->oLnk->signed_up = true; $this->oLnk->participant_id = (int) $participant->id; $this->oLnk->misc = $pmisc; $this->oLnk->reported_scores = ( ! empty( $pmisc[1] ) && in_array( $pmisc[1], array( 'w', 'l', 't' ) ) ); }$pmisc[0]will be equal to a 32 character string or null. The first condition is met if it’s null and if it’s a string,$this->oLnk->usrkeymust match it to meet the second condition. If you look a little higher up in the code, you will find$this->oLnk->usrkeyshould be true and not a string unless you are a logged in.// User key hash if ( is_user_logged_in() && current_user_can( 'challonge_signup' ) ) $this->oLnk->usrkey = md5( $tourny->url . ' ' . $this->oUsr->user_login . ' <' . $this->oUsr->user_email . '>' ); // Shows signup elseif ( ! is_user_logged_in() && $this->aOptions['public_widget_signup'] ) $this->oLnk->usrkey = true; // Shows signup to login else $this->oLnk->usrkey = false; // Shows nothingThere may be an error happening somewhere there causing
$this->oLnk->usrkeyto have an incorrect value.I remember there were some challenges involved with checking valid logins over AJAX, perhaps I’ve forgotten something.
I will try more testing when I have a chance later today.
Thanks for your help! It is appreciated. 🙂
I fixed it by adding an additional elseif statement. Would be nice if you can have a look at it.
if ( empty( $pmisc[0] ) ) { $this->oLnk->all_have_misc = false; } elseif ( $this->oLnk->usrkey === true ){ $this->oLnk->signed_up = false; } elseif ( $pmisc[0] == $this->oLnk->usrkey ) { $this->oLnk->signed_up = true; $this->oLnk->participant_id = (int) $participant->id; $this->oLnk->misc = $pmisc; $this->oLnk->reported_scores = ( ! empty( $pmisc[1] ) && in_array( $pmisc[1], array( 'w', 'l', 't' ) ) ); }Ok I found the real reason. The problem is the
$pmisc[0] == $this->oLnk->usrkeyIn php any string converted to a boolean will be “true”. The == operator checks if the value of both sides equals each other regardless of the type. In this case we compare any string with the boolean true, which always will be true. To bypass this problem we can use === which works almost like == just with respect to the type. So besides the value both types must match each other, too.
By changing the code to $pmisc[0] === $this->oLnk->usrkey the elseif statement wont be exceuted if the user is not logged in.
Nice detective work! 🙂 That makes sense now that you mention it.
The topic ‘widget signup button’ is closed to new replies.