<?php

/**
 * @Author	Jonathon byrd
 * @link http://www.5twentystudios.com
 * @Package Wordpress
 * @SubPackage Better User Management
 * @Since 1.0.0
 * @copyright  Copyright (C) 2011 5Twenty Studios
 * 
 */
defined('ABSPATH') or die("Cannot access pages directly.");
//initializing
global $bum_errors;
$type = bum_get_registration_type();
?>
<div class="registration-wrapper">
<?php 
if (!get_option('users_can_register')) {
    ?>

	<H2 class="registration-title"><?php 
    echo __('Sorry!', 'bum');
    ?>
</H2>
	<p><?php 
    echo sprintf(__('Registration for %s is currently closed.', 'bum'), get_bloginfo('site'));
    ?>
</p>

<?php 
/**
 * Function is responsible for managing the user registrations
 * 
 * @return string
 */
function bum_init_page_registration()
{
    global $wp_roles;
    //reasons to return
    if (!bum_is_page('Registration')) {
        return false;
    }
    foreach ($wp_roles->roles as $slug => $role) {
        if ($role['register'] == 'yes') {
            registration_page(array('role' => $slug, 'name' => $role['name'], 'redirect_to' => get_bloginfo('url') . '/profile/', 'fields' => array('user_login', 'user_email'), 'force_login' => false));
        }
    }
    if (is_user_logged_in()) {
        wp_redirect(bum_get_permalink_profile());
        exit;
    }
    //initializing
    global $bum_errors;
    if (!empty($_POST)) {
        $role = bum_get_registration_type();
        $bum_errors = bum_register_new_user($_POST['user_login'], $_POST['user_email'], $_POST['user_type']);
        if ((string) (int) $bum_errors == $bum_errors) {
            bum_save_user_meta_data($bum_errors);
        }
    }
}