Skip to:
Content
Pages
Categories
Search
Top
Bottom

Re: Simplified blog creation – blogname generated from Blog Title


peterverkooijen
Participant

@peterverkooijen

Success! Solution found here.

The Javascript:

<script type = "text/javascript">
function copyinput()
{
var tmp = document.getElementById('blog_title').value;
tmp = tmp.toLowerCase().replace(/^s+|s+$/g, "").replace(/[_|s]+/g, "");
tmp = tmp.replace(/[^a-z0-9-]+/g, "").replace(/[-]+/g, "-").replace(/^-+|-+$/g, "");
document.getElementById('blogname').value = tmp;
}
</script>

The customized function:

function custom_signup_show_blog_form( $blogname = '', $blog_title = '', $errors = '' ) {
global $current_site;

?>
<div id="blog-details-fields">

<label for="blog_title">Blog title</label>
<?php if ( $errmsg = $errors->get_error_message('blog_title') ) { ?>
<p class="error"><?php echo $errmsg ?></p>
<?php }
echo '<input name="blog_title" type="text" id="blog_title" value="'.wp_specialchars($blog_title, 1).'" maxlength="24" onkeyup="copyinput()"/></p>';

// Blog name
if ( 'no' == constant( "VHOST" ) )
echo '<label for="blogname">' . __('Blog Name:', 'buddypress') . '</label>';
else
echo '<label for="blogname">' . __('Blog Domain:', 'buddypress') . '</label>';

if ( $errmsg = $errors->get_error_message('blogname') ) { ?>
<p class="error"><?php echo $errmsg ?></p>
<?php }

if ( 'no' == constant( "VHOST" ) ) {
echo '<span class="prefix_address">' . $current_site->domain . $current_site->path . '</span><input name="blogname" type="text" id="blogname" value="'.$blogname.'" maxlength="50" /><br />';
} else {
echo '<input name="blogname" type="text" id="blogname" value="'.$blogname.'" maxlength="50" /><span class="suffix_address">.' . $current_site->domain . $current_site->path . '</span><br />';
}

if ( !is_user_logged_in() ) {
echo '<p class="help-text">';
print '(<strong>' . __( 'Your address will be ', 'buddypress' );
if( 'no' == constant( "VHOST" ) ) {
print $current_site->domain . $current_site->path . __( 'blogname', 'buddypress' );
} else {
print __( 'domain.', 'buddypress' ) . $current_site->domain . $current_site->path;
}
echo '</strong>. ' . __( 'Must be at least 4 characters, letters and numbers only. It cannot be changed so choose carefully!)', 'buddypress' ) . '</p>';
echo '</p>';
}
?>
<p>
<label for="blog_public_on"><?php _e( 'I would like my blog to appear in search engines like Google and Technorati, and in public listings around this site.', 'buddypress' ); ?> </label>
<label class="checkbox" for="blog_public_on">
<input type="radio" id="blog_public_on" name="blog_public" value="1" <?php if( !isset( $_POST['blog_public'] ) || '1' == $_POST['blog_public'] ) { ?>checked="checked"<?php } ?> />
 <?php _e( 'Yes', 'buddypress' ); ?>
</label>
<label class="checkbox" for="blog_public_off">
<input type="radio" id="blog_public_off" name="blog_public" value="0" <?php if( isset( $_POST['blog_public'] ) && '0' == $_POST['blog_public'] ) { ?>checked="checked"<?php } ?> />
 <?php _e( 'No', 'buddypress' ); ?>
</label>
</p>
</div>
<?php
do_action('signup_blogform', $errors);
}

What this does:

When the user starts typing the blog title – limited to 24 chars – the Javascript dynamically fills in the blogname for the URL.

The user can manually change the blogname if he/she wants. Not sure how that would work out…

You could probably also hide the blogname field, either through type=”hidden” or CSS. Haven’t tested all these options yet.

But imho this looks like a very versatile solution. :-)

Or have I overlooked some critical issues? Comments very much appreciated!

Skip to toolbar