예제 #1
0
function current_user_is_member()
{
    $user = wp_get_current_user();
    $member = new M_Membership($user->ID);
    if (!empty($member)) {
        return $member->is_member();
    } else {
        return false;
    }
}
예제 #2
0
 function add_feed_key($output, $feed)
 {
     global $user;
     if (empty($user) || !method_exists($user, 'has_cap')) {
         $user = wp_get_current_user();
     }
     if ($user->ID > 0) {
         $member = new M_Membership($user->ID);
         if ($member->is_member()) {
             $key = get_user_meta($user->ID, '_membership_key', true);
             if (empty($key)) {
                 $key = md5($user->ID . $user->user_pass . time());
                 update_user_meta($user->ID, '_membership_key', $key);
             }
             if (!empty($key)) {
                 $output = add_query_arg('k', $key, untrailingslashit($output));
             }
         }
     }
     return $output;
 }
        function add_profile_feed_key($profileuser)
        {
            $id = $profileuser->ID;
            $member = new M_Membership($id);
            if ($member->is_member()) {
                $key = get_user_meta($id, '_membership_key', true);
                if (empty($key)) {
                    $key = md5($id . $profileuser->user_pass . time());
                    update_user_meta($id, '_membership_key', $key);
                }
                ?>
				<h3><?php 
                _e('Membership key', 'membership');
                ?>
</h3>

				<table class="form-table">
				<tr>
					<th><label for="description"><?php 
                _e('Membership key', 'membership');
                ?>
</label></th>
					<td><?php 
                esc_html_e($key);
                ?>
						<br />
					<span class="description"><?php 
                _e('This key is used to give you access the the members RSS feed, keep it safe and secret.', 'membership');
                ?>
</span></td>
				</tr>
				</table>
				<?php 
            }
        }
예제 #4
0
 function do_subscription_shortcode($atts, $content = null, $code = "")
 {
     global $nxt_query;
     $error = array();
     $page = addslashes($_REQUEST['action']);
     $M_options = get_option('membership_options', array());
     switch ($page) {
         case 'validatepage1':
             // Page 1 of the form has been submitted - validate
             include_once ABSPATH . nxtINC . '/registration.php';
             $required = array('user_login' => __('Username', 'membership'), 'user_email' => __('Email address', 'membership'), 'user_email2' => __('Email address confirmation', 'membership'), 'password' => __('Password', 'membership'), 'password2' => __('Password confirmation', 'membership'));
             $error = array();
             foreach ($required as $key => $message) {
                 if (empty($_POST[$key])) {
                     $error[] = __('Please ensure that the ', 'membership') . "<strong>" . $message . "</strong>" . __(' information is completed.', 'membership');
                 }
             }
             if ($_POST['user_email'] != $_POST['user_email2']) {
                 $error[] = __('Please ensure the email addresses match.', 'membership');
             }
             if ($_POST['password'] != $_POST['password2']) {
                 $error[] = __('Please ensure the passwords match.', 'membership');
             }
             if (username_exists(sanitize_user($_POST['user_login']))) {
                 $error[] = __('That username is already taken, sorry.', 'membership');
             }
             if (email_exists($_POST['user_email'])) {
                 $error[] = __('That email address is already taken, sorry.', 'membership');
             }
             if (function_exists('get_site_option')) {
                 $terms = get_site_option('signup_tos_data');
             } else {
                 $terms = '';
             }
             if (!empty($terms)) {
                 if (empty($_POST['tosagree'])) {
                     $error[] = __('You need to agree to the terms of service to register.', 'membership');
                 }
             }
             $error = apply_filters('membership_subscription_form_before_registration_process', $error);
             if (empty($error)) {
                 // Pre - error reporting check for final add user
                 $user_id = nxt_create_user(sanitize_user($_POST['user_login']), $_POST['password'], $_POST['user_email']);
                 if (is_nxt_error($user_id) && method_exists($userid, 'get_error_message')) {
                     $error[] = $userid->get_error_message();
                 } else {
                     $member = new M_Membership($user_id);
                     if (empty($M_options['enableincompletesignups']) || $M_options['enableincompletesignups'] != 'yes') {
                         $member->deactivate();
                     }
                     if (has_action('membership_susbcription_form_registration_notification')) {
                         do_action('membership_susbcription_form_registration_notification', $user_id, $_POST['password']);
                     } else {
                         nxt_new_user_notification($user_id, $_POST['password']);
                     }
                 }
             }
             do_action('membership_subscription_form_registration_process', $error, $user_id);
             if (!empty($error)) {
                 $content .= "<div class='error'>";
                 $content .= implode('<br/>', $error);
                 $content .= "</div>";
                 $content .= $this->show_subpage_one(true);
             } else {
                 // everything seems fine (so far), so we have our queued user so let's
                 // look at picking a subscription.
                 $content .= $this->show_subpage_two($user_id);
             }
             break;
         case 'validatepage1bp':
             global $bp;
             include_once ABSPATH . nxtINC . '/registration.php';
             $required = array('signup_username' => __('Username', 'membership'), 'signup_email' => __('Email address', 'membership'), 'signup_password' => __('Password', 'membership'), 'signup_password_confirm' => __('Password confirmation', 'membership'));
             $error = array();
             foreach ($required as $key => $message) {
                 if (empty($_POST[$key])) {
                     $error[] = __('Please ensure that the ', 'membership') . "<strong>" . $message . "</strong>" . __(' information is completed.', 'membership');
                 }
             }
             if ($_POST['signup_password'] != $_POST['signup_password_confirm']) {
                 $error[] = __('Please ensure the passwords match.', 'membership');
             }
             if (username_exists(sanitize_user($_POST['signup_username']))) {
                 $error[] = __('That username is already taken, sorry.', 'membership');
             }
             if (email_exists($_POST['signup_email'])) {
                 $error[] = __('That email address is already taken, sorry.', 'membership');
             }
             $meta_array = array();
             // xprofile required fields
             /* Now we've checked account details, we can check profile information */
             if (function_exists('xprofile_check_is_required_field')) {
                 /* Make sure hidden field is passed and populated */
                 if (isset($_POST['signup_profile_field_ids']) && !empty($_POST['signup_profile_field_ids'])) {
                     /* Let's compact any profile field info into an array */
                     $profile_field_ids = explode(',', $_POST['signup_profile_field_ids']);
                     /* Loop through the posted fields formatting any datebox values then validate the field */
                     foreach ((array) $profile_field_ids as $field_id) {
                         if (!isset($_POST['field_' . $field_id])) {
                             if (isset($_POST['field_' . $field_id . '_day'])) {
                                 $_POST['field_' . $field_id] = strtotime($_POST['field_' . $field_id . '_day'] . $_POST['field_' . $field_id . '_month'] . $_POST['field_' . $field_id . '_year']);
                             }
                         }
                         /* Create errors for required fields without values */
                         if (xprofile_check_is_required_field($field_id) && empty($_POST['field_' . $field_id])) {
                             $field = new BP_Xprofile_Field($field_id);
                             $error[] = __('Please ensure that the ', 'membership') . "<strong>" . $field->name . "</strong>" . __(' information is completed.', 'membership');
                         }
                         $meta_array[$field_id] = $_POST['field_' . $field_id];
                     }
                 }
             }
             $error = apply_filters('membership_subscription_form_before_registration_process', $error);
             if (empty($error)) {
                 // Pre - error reporting check for final add user
                 $user_id = nxt_create_user(sanitize_user($_POST['signup_username']), $_POST['signup_password'], $_POST['signup_email']);
                 if (is_nxt_error($user_id) && method_exists($userid, 'get_error_message')) {
                     $error[] = $userid->get_error_message();
                 } else {
                     $member = new M_Membership($user_id);
                     if (empty($M_options['enableincompletesignups']) || $M_options['enableincompletesignups'] != 'yes') {
                         $member->deactivate();
                     }
                     if (has_action('membership_susbcription_form_registration_notification')) {
                         do_action('membership_susbcription_form_registration_notification', $user_id, $_POST['password']);
                     } else {
                         nxt_new_user_notification($user_id, $_POST['signup_password']);
                     }
                     foreach ((array) $meta_array as $field_id => $field_content) {
                         if (function_exists('xprofile_set_field_data')) {
                             xprofile_set_field_data($field_id, $user_id, $field_content);
                         }
                     }
                 }
             }
             do_action('membership_subscription_form_registration_process', $error, $user_id);
             if (!empty($error)) {
                 $content .= "<div class='error'>";
                 $content .= implode('<br/>', $error);
                 $content .= "</div>";
                 $content .= $this->show_subpage_one(true);
             } else {
                 // everything seems fine (so far), so we have our queued user so let's
                 // look at picking a subscription.
                 $content .= $this->show_subpage_two($user_id);
             }
             break;
         case 'validatepage2':
             $content = apply_filters('membership_subscription_form_subscription_process', $content, $error);
             break;
         case 'page2':
         case 'page1':
         default:
             if (!is_user_logged_in()) {
                 $content .= $this->show_subpage_one();
             } else {
                 // logged in check for sub
                 $user = nxt_get_current_user();
                 $member = new M_Membership($user->ID);
                 if ($member->is_member()) {
                     // This person is a member - display already registered stuff
                     $content .= $this->show_subpage_member();
                 } else {
                     // Show page two;
                     $content .= $this->show_subpage_two($user->ID);
                 }
             }
             break;
     }
     $content = apply_filters('membership_subscription_form', $content);
     return $content;
 }