Viewing 8 replies - 1 through 8 (of 8 total)
  • Plugin Author zavaboy

    (@zavaboy)

    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.

    Plugin Author zavaboy

    (@zavaboy)

    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' ) ) );
    }
    Plugin Author zavaboy

    (@zavaboy)

    $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->usrkey must match it to meet the second condition. If you look a little higher up in the code, you will find $this->oLnk->usrkey should 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 nothing

    There may be an error happening somewhere there causing $this->oLnk->usrkey to 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->usrkey

    In 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.

    Source: https://stackoverflow.com/questions/80646/how-do-the-php-equality-double-equals-and-identity-triple-equals-comp

    Plugin Author zavaboy

    (@zavaboy)

    Nice detective work! ?? That makes sense now that you mention it.

Viewing 8 replies - 1 through 8 (of 8 total)
  • The topic ‘widget signup button’ is closed to new replies.