Example #1
0
/**
 * Include the profile link template
 * @param  string $label   	Link text. Default: 'Profile'
 * @param  string $classes 	Classes to add to the <a> tag. Default: 'profile'
 */
function tpl_link_profile($label = null, $classes = 'profile')
{
    if (is_null($label)) {
        $label = __('Profile', 'theme');
    }
    if (Settings::frontend_profile_enabled()) {
        $url = home_url('profile');
    } else {
        $url = admin_url('profile.php');
    }
    tpl('link', 'profile', array('url' => $url, 'label' => $label, 'classes' => $classes));
}
Example #2
0
 /**
  * Form handler for user registration.
  * Front end login will only use email address and password.
  * The username, while required for WP, will be auto-generated and completely hidden from the user.
  * 
  * @param  array $params {
  *
  * 		Parameters submitted from form
  *
  * 		@var string $password User submitted password
  * 		@var string $confirm_password User submitted password confirmation
  * 		@var array $data {
  *
  * 			Array of user data. By default, just display name and email,
  * 			but other user data fields added to the form will be saved too.
  *
  * 			@var string $display_name User submitted display name
  * 			@var string $user_email User submitted email address
  * 		}
  *
  * 		@var array $meta {
  *
  * 			Array of user meta fields. By default, just first and last name, 
  * 			but other user meta fields added to the form will be saved too.
  *
  * 			@var string $first_name User's first name
  * 			@var string $last_Name 	User's last name
  * 		}
  * }
  */
 static function _user_register($params)
 {
     // Verify the nonce
     if (!isset($_POST['user_register_nonce']) || !wp_verify_nonce($_POST['user_register_nonce'], 'user_register')) {
         print 'Invalid form submission';
         exit;
     }
     // If required fields are missing
     if (empty($params['password']) || empty($params['confirm_password']) || empty($params['data']['display_name']) || empty($params['data']['user_email'])) {
         wp_redirect(home_url('register/error/incomplete'));
         exit;
     }
     // If the passwords don't match
     if (trim($params['password']) !== trim($params['confirm_password'])) {
         wp_redirect(home_url('register/error/match'));
         exit;
     }
     // Build a username
     $username = '';
     // If a first-name was supplied, use that
     if (!empty($params['meta']['first_name'])) {
         $username = esc_attr(strtolower(trim($params['meta']['first_name'])));
         // If a last name was also supplied, append that with a '.'
         if (!empty($params['meta']['last_name'])) {
             $username .= '.' . esc_attr(strtolower(trim($params['meta']['last_name'])));
         }
         // If not a first name, maybe a last name was supplied, try that
     } elseif (!empty($params['meta']['last_name'])) {
         $username = esc_attr(strtolower(trim($params['meta']['last_name'])));
         // Otherwise, use the display name, since thats required anyway
     } else {
         $username = esc_attr(strtolower(trim($params['data']['display_name'])));
     }
     // Make sure the username is unique
     $username = self::uniquify_username($username);
     // Create the user
     $user_id = wp_create_user($username, esc_attr($params['password']), esc_attr($params['data']['user_email']));
     // Build a user data array for saving additional metadata and user data.
     // This might be repetative, but it allows for adding additional fields to the form
     // without needing to modify this function
     $user_data = array('ID' => $user_id);
     // Add each data field in the form
     foreach ($params['data'] as $key => $data) {
         $user_data[$key] = esc_attr($data);
     }
     // Add each meta field in the form
     foreach ($params['meta'] as $key => $meta) {
         $user_data[$key] = esc_attr($meta);
     }
     // * Note, even though user data and user meta are stored separately in the database,
     // They can be mixed together in the wp_update_user() function
     // If registration email activation is required
     // we will generate an activation key, and send a confirmation email.
     // The user's account will not be activated until they login from the provided link.
     // User "activation" is controlled by their assigned user role.
     // A user with no assigned role is considered inactive.
     if (Settings::registration_activation_required()) {
         // Set their role to empty, to make their account inactive
         $user_data['role'] = '';
         // Save the additional data
         wp_update_user($user_data);
         // Generate an activation key for the user
         $activation_key = self::get_user_activation_key($username);
         // Build an email message
         // TO DO: replace with content from option member_tools_settings[registration_email_content]
         // replace {activation_link}, {user_display_name}, {user_email}, {site_title}
         $message = '<p>';
         $message .= sprintf(__('Thank you for registering on %s. To complete the process, please click the link below and login.', 'theme'), get_bloginfo('name'));
         $message .= '</p><p>';
         $message .= __('Activaye your registration here:') . "\r\n\r\n" . '<br>';
         $message .= home_url('login/activate/' . rawurlencode($params['data']['user_email']) . '/' . $activation_key);
         $message .= '</p>';
         // Set the email headers
         $headers[] = 'From: ' . get_bloginfo('name') . ' <' . get_option('admin_email') . '>';
         $headers[] = 'Content-Type: text/html; charset=UTF-8';
         // Attempt to send the email
         if (!wp_mail($params['data']['user_email'], __('Complete Your Registration', 'theme'), $message, $headers)) {
             // Didn't work. Something went wrong with the email sending.
             // The displayed error message contains a link to email the site admin,
             // since this is not a user-generated error.
             wp_redirect(home_url('register/error/email'));
             exit;
         } else {
             // Worked. Redirect to the home page with a status message
             // instructing them to check their email.
             wp_redirect(home_url('status/registration-pending'));
             exit;
         }
         // Registration activation setting is not enabled,
         // so just log the user in right away
     } else {
         // Save the additional data
         wp_update_user($user_data);
         // Log the user in by setting their auth cookie
         wp_set_auth_cookie($user_id);
         // Redirect to either the profile page, or the admin
         if (Settings::frontend_profile_enabled()) {
             wp_redirect(home_url('profile/created'));
             exit;
         } else {
             wp_redirect(admin_url());
             exit;
         }
     }
 }
Example #3
0
if (is_user_logged_in()) {
    ?>

									<?php 
    if (Settings::frontend_login_enabled()) {
        ?>
										<li><?php 
        tpl_link_logout();
        ?>
</li>
									<?php 
    }
    ?>
									
									<?php 
    if (Settings::frontend_profile_enabled()) {
        ?>
										<li><?php 
        tpl_link_profile();
        ?>
</li>
									<?php 
    }
    ?>
								
								<?php 
} else {
    ?>

									<?php 
    if (Settings::frontend_login_enabled()) {
Example #4
0
add_action('init', 'tpl_init');
add_action('admin_enqueue_scripts', 'tpl_admin_enqueue_scripts');
/**
 * Required files
 */
// Plugin activation class
require get_template_directory() . '/includes/plugins/plugins.php';
// Settings class
require get_template_directory() . '/classes/settings.class.php';
// Main theme class
require get_template_directory() . '/classes/theme.class.php';
// Nav Menu Walkers
require get_template_directory() . '/classes/walkers/topbar-walker.class.php';
require get_template_directory() . '/classes/walkers/offcanvas-walker.class.php';
// Member tools class
if (Settings::frontend_login_enabled() || Settings::frontend_profile_enabled()) {
    require get_template_directory() . '/classes/member-tools.class.php';
}
/**
 * Theme has been activated
 */
function tpl_after_switch_theme()
{
    /**
     *  Set the permalink structure to use postname
     */
    global $wp_rewrite;
    $wp_rewrite->set_permalink_structure('/%postname%/');
}
/**
 * WP Initialized