Skip to:
Content
Pages
Categories
Search
Top
Bottom

Blog creation at registration checked by defauld


  • gebar
    Participant

    @gebar

    During registration, I am trying to have the checkbox “Yes, I’d like to create a new site” checked by default.

    In register.php you have

    <input type="checkbox" name="signup_with_blog" id="signup_with_blog" value="1"<?php if ( (int) bp_get_signup_with_blog_value() ) : ?> checked="checked"<?php endif; ?> /> <?php _e( 'Yes, I\'d like to create a new site', 'buddypress' ); ?>

    and in bp-members-template.php,

    function bp_get_signup_with_blog_value() {
    		$value = '';
    		if ( isset( $_POST['signup_with_blog'] ) )
    			$value = $_POST['signup_with_blog'];
    }

    I can’t understand how this works, and I don’t want to break something. As far as I can tell, this says, “If the checkbox is checked (after submission), then set its default state to checked (before submission)”, which does not make sense. Or am I missing something?

    I could just remove the php conditional around checked=”checked”. Would that create any problems?

    Or anyway what is the best way to do this?

Viewing 6 replies - 1 through 6 (of 6 total)

  • gebar
    Participant

    @gebar

    Bump?


    danbp
    Moderator

    @danbp

    @gebar,
    the allow blog checkbox is a conditionnal who open a sub form via ajax. If you remove it from the template, it will compromise the register process. But as the only thing we need is the value (0 or 1), we have to change it from 0 (empty) to 1 (ckecked) in the core. The function who made this is bp_get_signup_with_blog_value which contains a filter for $value.

    Give this a try. Add it to bp-custom.php

    function create_blog_activated( $value ) {
    if ( function_exists( 'bp_get_signup_with_blog_value' ) )
    // default value is ''
    	$value = 1;
    return $value;
    }
    add_filter( 'bp_get_signup_with_blog_value', 'create_blog_activated', 10, 1 );

    Now the register page shows blog activation part open and checkbox is ticked.


    gebar
    Participant

    @gebar

    Thanks for the answer.

    Strangely enough, this subform is open by default (with the checkbox unchecked). If you look at the code I gave in the initial question, you will see that the checkbox value is set to 1 in register.php, and the div with the blog details is also set to class=”show” by default (although in buddypress.js there is a section to handle exactly the toggling of the subform on-off). Any idea why?

    However, I will try your suggestion. It must better than setting the checkbox checked in register.php.


    danbp
    Moderator

    @danbp

    By default it’s closed. Which theme/plugins do you use ? Do a test with one of twenty theme.
    Are what’s new form or activity comment working correctly or do you have also toggle issue with them ?


    gebar
    Participant

    @gebar

    Well, you are right. On the Twenty Fifteen theme the subform is indeed closed.

    However your code did not do the trick. The subform opens on page load but closes again (checkbox unchecked). Any further ideas?

    By the way, I am using the child Nirvana theme, and I have to stick to it as I have put a lot of work in its customization. The subform being open is convenient for me, and adding checked to register.php checks it. Would there be any problems from that?

    Thanks


    webifydevs
    Participant

    @webifydevs

    Hi, you can add this

    
    <script>document.getElementById("signup_with_blog").checked = true;</script>

    in the footer or header of your theme

Viewing 6 replies - 1 through 6 (of 6 total)
  • The topic ‘Blog creation at registration checked by defauld’ is closed to new replies.
Skip to toolbar