Example #1
0
 function the_quiz_button($button, $quiz_id)
 {
     global $post;
     $quiz_id = get_the_ID();
     $user_id = get_current_user_id();
     $flag = 1;
     if (in_array('woocommerce/woocommerce.php', apply_filters('active_plugins', get_option('active_plugins')))) {
         $pid = get_post_meta($quiz_id, 'vibe_quiz_product', true);
         if (isset($pid) && is_numeric($pid) && get_post_type($pid) == 'product') {
             $product_taken = wc_customer_bought_product('', $user_id, $pid);
             if (!$product_taken) {
                 $pid = get_permalink($pid);
                 $check = vibe_get_option('direct_checkout');
                 $check = intval($check);
                 if (isset($check) && $check) {
                     $pid .= '?redirect';
                 }
                 $flag = 0;
                 $html = '<a href="' . $pid . '"class="button create-group-button full"> ' . __('Take this Quiz', 'vibe') . '</a>';
             } else {
                 $flag = 1;
             }
         }
     }
     if (in_array('paid-memberships-pro/paid-memberships-pro.php', apply_filters('active_plugins', get_option('active_plugins'))) && is_user_logged_in()) {
         $membership_ids = vibe_sanitize(get_post_meta($quiz_id, 'vibe_quiz_membership', false));
         if (!pmpro_hasMembershipLevel($membership_ids, $user_id) && isset($membership_ids) && count($membership_ids) >= 1) {
             $membership_taken = get_user_meta($user_id, $quiz_id, true);
             if (!$membership_taken) {
                 $pmpro_levels_page_id = get_option('pmpro_levels_page_id');
                 $link = get_permalink($pmpro_levels_page_id);
                 $html = '<a href="' . $link . '"class="button create-group-button full"> ' . __('Take this Quiz', 'vibe') . '</a>';
                 $flag = 0;
             } else {
                 $flag = 1;
             }
         }
     }
     if (in_array('wplms-mycred-addon/wplms-mycred-addon.php', apply_filters('active_plugins', get_option('active_plugins')))) {
         $points = get_post_meta($quiz_id, 'vibe_quiz_mycred_points', true);
         $mycred = mycred();
         $balance = $mycred->get_users_cred($user_id);
         if ($balance < $points) {
             $flag = 0;
             $html = '<a href="#"class="button create-group-button full"> ' . __('Take this Quiz', 'vibe') . '<span>' . __('<br/>Not enough points.', 'vibe') . '</span></a>';
         }
         if (!$mycred->has_entry('purchase_quiz', $quiz_id, $user_id)) {
             $flag = 1;
             $deduct = -1 * $points;
             $mycred->update_users_balance($user_id, $deduct);
             $mycred->add_to_log('purchase_quiz', $user_id, $deduct, __('Student subscibed to quiz', 'wplms-mycred'), $quiz_id);
         } else {
             $flag = 1;
         }
     }
     if (!$flag) {
         return $html;
     }
     return $button;
 }
Example #2
0
function sp_user_register($user_id)
{
    // check if the new user is a teacher (see Chapter 15 for details)
    if (pmpro_hasMembershipLevel('teacher', $user_id)) {
        // add a new "course" CPT with this user as author
        wp_insert_post(array('post_title' => 'My First Course', 'post_content' => 'This is a sample course...', 'post_author' => $user_id, 'post_status' => 'draft', 'post_type' => 'course'));
    }
}
Example #3
0
function pmpro_checkout_start_date_keep_startdate($startdate, $user_id, $level)
{
    if (pmpro_hasMembershipLevel($level->id, $user_id)) {
        global $wpdb;
        $sqlQuery = "SELECT startdate FROM {$wpdb->pmpro_memberships_users} WHERE user_id = '" . esc_sql($user_id) . "' AND membership_id = '" . esc_sql($level->id) . "' AND status = 'active' ORDER BY id DESC LIMIT 1";
        $old_startdate = $wpdb->get_var($sqlQuery);
        if (!empty($old_startdate)) {
            $startdate = "'" . $old_startdate . "'";
        }
    }
    return $startdate;
}
function pmprobt_wp_footer()
{
    $options = get_option('pmprobt_options');
    if (empty($options) || empty($options['tracking_code'])) {
        return false;
    }
    //add tracking code
    echo $options['tracking_code'];
    //if user is logged in, identify them
    if (is_user_logged_in()) {
        global $current_user;
        ?>
        <script>
            _bt.identify('<?php 
        echo $current_user->user_id;
        ?>
');
            _bt.person.set({
                'email': '<?php 
        echo $current_user->user_email;
        ?>
',
                'firstName': '<?php 
        echo $current_user->first_name;
        ?>
',
                'lastName': '<?php 
        echo $current_user->last_name;
        ?>
'
            });
            <?php 
        if (function_exists('pmpro_hasMembershipLevel')) {
            if (pmpro_hasMembershipLevel()) {
                ?>
                        _bt.person.set({'membership_level': '<?php 
                echo $current_user->membership_level->id;
                ?>
'});
                        <?php 
            }
        }
        ?>
                    </script>
                <?php 
    }
}
function wplms_unit_check_pmpro_membership($content)
{
    global $post;
    if ($post->post_type != 'unit' || !is_user_logged_in()) {
        return $content;
    }
    $unit_id = $post->ID;
    $user_id = get_current_user_id();
    if (in_array('paid-memberships-pro/paid-memberships-pro.php', apply_filters('active_plugins', get_option('active_plugins'))) && function_exists('pmpro_getAllLevels')) {
        $membership_ids = get_post_meta($unit_id, 'vibe_pmpro_membership', true);
        if (!empty($membership_ids) && count($membership_ids) >= 1) {
            if (pmpro_hasMembershipLevel($membership_ids, $user_id)) {
                return $content;
            } else {
                $levels = pmpro_getAllLevels($membership_ids);
                foreach ($levels as $level) {
                    $level_array[$level->id] = $level->name;
                }
                $content = 'Please purchase membership plan ';
            }
        }
    }
    return $content;
}
                    $form_message_class = 'regular';
                } else {
                    $form_message = __('An error occured while updating. Please check the form and try again.', 'cp');
                    $form_message_class = 'red';
                }
            }
        }
    }
    $student = new Student(get_current_user_id());
    $user_id = get_current_user_id();
    $payment_status = $wpdb->get_var($wpdb->prepare("SELECT status \n\t\tFROM {$wpdb->pmpro_memberships_users} \n\t\tWHERE user_id = %s", $user_id));
    global $pmpro_pages;
    //PMPRO
    global $pmpro_msg, $pmpro_msgt, $pmpro_levels, $current_user, $levels;
    ob_start();
    if (pmpro_hasMembershipLevel()) {
        $ssorder = new MemberOrder();
        $ssorder->getLastMemberOrder();
        $invoices = $wpdb->get_results("SELECT *, UNIX_TIMESTAMP(timestamp) as timestamp FROM {$wpdb->pmpro_membership_orders} WHERE user_id = '{$current_user->ID}' ORDER BY timestamp DESC LIMIT 6");
        ?>
	
		<div id="pmpro_account">	
			<h5><?php 
        _e("Membership", "pmpro");
        ?>
</h5>
			<div class="row">
				<div class="col-md-4">
					<h6>Level</h6>
					<?php 
        echo $current_user->membership_level->name;
        $user = get_userdata($last_subscr_order->user_id);
        if (empty($user) || empty($user->ID)) {
            ipnlog("ERROR: Could not cancel membership. No user attached to order #" . $last_subscr_order->id . " with subscription transaction id = " . $subscr_id . ".");
        } else {
            /*
            	We want to make sure this is a cancel originating from PayPal and not one already handled by PMPro.
            	For example, if a user cancels on WP/PMPro side, we've already cancelled the membership.
            	Also, if a user is changing levels, we don't want to cancel their new membership, just the old subscription at PayPal.
            	
            	So we check 2 things and don't cancel if:
            	(1) This order already has "cancelled" status.
            	(2) The user doesn't currently have the level attached to this order.
            */
            if ($last_subscr_order->status == "cancelled") {
                ipnlog("We've already processed this cancellation. Probably originated from WP/PMPro. (Order #" . $last_subscr_order->id . ", Subscription Transaction ID #" . $subscr_id . ")");
            } elseif (!pmpro_hasMembershipLevel($last_subsc_order->membership_id, $user->ID)) {
                ipnlog("This user has a different level than the one associated with this order. Their membership was probably changed by an admin or through an upgrade/downgrade. (Order #" . $last_subscr_order->id . ", Subscription Transaction ID #" . $subscr_id . ")");
            } else {
                pmpro_changeMembershipLevel(0, $last_subscr_order->user_id, 'cancelled');
                ipnlog("Canceled membership for user with id = " . $last_subscr_order->user_id . ". Subscription transaction id = " . $subscr_id . ".");
                //send an email to the member
                $myemail = new PMProEmail();
                $myemail->sendCancelEmail($user);
                //send an email to the admin
                $myemail = new PMProEmail();
                $myemail->sendCancelAdminEmail($user, $last_subscr_order->membership_id);
            }
        }
        pmpro_ipnExit();
    }
}
?>
</h1>
			<div class="arrow bounce"></div>
    	</div>
  	</div>
</div>

<!--BANNER END-->
<div class="clearfix"></div>

<div class="container">
  
  	<div class="row text-center daily-performance">

  		<?php 
if (pmpro_hasMembershipLevel(1) || pmpro_hasMembershipLevel(2)) {
    $reports = getDailyReport();
    ?>

		  	<div class="col-md-4 col-md-offset-2">

			  	<h4>DAILY PROFT / LOSS STATUS</h4>

			  	<?php 
    foreach ($reports as $post) {
        setup_postdata($post);
        ?>

			  		<?php 
        $file = get_field('profit/loss_pdf');
        $filename = $file['title'];
Example #9
0
function wplms_pmp_pro_connect($course_id, $user_id)
{
    if (in_array('paid-memberships-pro/paid-memberships-pro.php', apply_filters('active_plugins', get_option('active_plugins'))) && is_user_logged_in()) {
        $membership_ids = vibe_sanitize(get_post_meta($course_id, 'vibe_pmpro_membership', false));
        if (pmpro_hasMembershipLevel($membership_ids, $user_id) && isset($membership_ids) && count($membership_ids) >= 1) {
            $coursetaken = get_user_meta($user_id, $course_id, true);
            if (!isset($coursetaken) || $coursetaken == '') {
                $duration = get_post_meta($course_id, 'vibe_duration', true);
                $course_duration_parameter = apply_filters('vibe_course_duration_parameter', 86400);
                $new_duration = time() + $course_duration_parameter * $duration;
                $new_duration = apply_filters('wplms_pmpro_course_check', $new_duration);
                if (update_user_meta($user_id, $course_id, $new_duration)) {
                    bp_course_update_user_course_status($user_id, $course_id, 0);
                    //since version 1.8.4
                    $group_id = get_post_meta($course_id, 'vibe_group', true);
                    if (isset($group_id) && $group_id != '') {
                        groups_join_group($group_id, $user_id);
                    }
                }
            }
        }
    }
}
function pmpro_shortcode_account($atts, $content = null, $code = "")
{
    global $wpdb, $pmpro_msg, $pmpro_msgt, $pmpro_levels, $current_user, $levels;
    // $atts    ::= array of attributes
    // $content ::= text within enclosing form of shortcode element
    // $code    ::= the shortcode found, when == callback name
    // examples: [pmpro_account] [pmpro_account sections="membership,profile"/]
    extract(shortcode_atts(array('section' => '', 'sections' => 'membership,profile,invoices,links'), $atts));
    //did they use 'section' instead of 'sections'?
    if (!empty($section)) {
        $sections = $section;
    }
    //turn into an array
    $sections = explode(',', $sections);
    ob_start();
    //if a member is logged in, show them some info here (1. past invoices. 2. billing information with button to update.)
    if (pmpro_hasMembershipLevel()) {
        $ssorder = new MemberOrder();
        $ssorder->getLastMemberOrder();
        $invoices = $wpdb->get_results("SELECT *, UNIX_TIMESTAMP(timestamp) as timestamp FROM {$wpdb->pmpro_membership_orders} WHERE user_id = '{$current_user->ID}' ORDER BY timestamp DESC LIMIT 6");
        ?>
	
	<div id="pmpro_account">		
		
		<?php 
        if (in_array('membership', $sections) || in_array('memberships', $sections)) {
            ?>
			<div id="pmpro_account-membership" class="pmpro_box">
				
				<h3><?php 
            _e("My Memberships", "pmpro");
            ?>
</h3>
				<table width="100%" cellpadding="0" cellspacing="0" border="0">
					<thead>
						<tr>
							<th><?php 
            _e("Level", "pmpro");
            ?>
</th>
							<th><?php 
            _e("Billing", "pmpro");
            ?>
</th>
							<th><?php 
            _e("Expiration", "pmpro");
            ?>
</th>
						</tr>
					</thead>
					<tbody>
						<?php 
            //TODO: v2.0 will loop through levels here
            $level = $current_user->membership_level;
            ?>
						<tr>
							<td class="pmpro_account-membership-levelname">
								<?php 
            echo $current_user->membership_level->name;
            ?>
								<div class="pmpro_actionlinks">
									<?php 
            do_action("pmpro_member_action_links_before");
            ?>
									
									<?php 
            if (pmpro_isLevelExpiringSoon($current_user->membership_level)) {
                ?>
										<a href="<?php 
                echo pmpro_url("checkout", "?level=" . $current_user->membership_level->id, "https");
                ?>
"><?php 
                _e("Renew", "pmpro");
                ?>
</a>
									<?php 
            }
            ?>

									<?php 
            if (isset($ssorder->status) && $ssorder->status == "success" && (isset($ssorder->gateway) && in_array($ssorder->gateway, array("authorizenet", "paypal", "stripe", "braintree", "payflow", "cybersource")))) {
                ?>
										<a href="<?php 
                echo pmpro_url("billing", "", "https");
                ?>
"><?php 
                _e("Update Billing Info", "pmpro");
                ?>
</a>
									<?php 
            }
            ?>
									
									<?php 
            //To do: Only show CHANGE link if this level is in a group that has upgrade/downgrade rules
            if (count($pmpro_levels) > 1 && !defined("PMPRO_DEFAULT_LEVEL")) {
                ?>
										<a href="<?php 
                echo pmpro_url("levels");
                ?>
"><?php 
                _e("Change", "pmpro");
                ?>
</a>
									<?php 
            }
            ?>
									<a href="<?php 
            echo pmpro_url("cancel", "?level=" . $current_user->membership_level->id);
            ?>
"><?php 
            _e("Cancel", "pmpro");
            ?>
</a>
									<?php 
            do_action("pmpro_member_action_links_after");
            ?>
								</div> <!-- end pmpro_actionlinks -->
							</td>
							<td class="pmpro_account-membership-levelfee">
								<p><?php 
            echo pmpro_getLevelCost($level, true, true);
            ?>
</p>
							</td>
							<td class="pmpro_account-membership-expiration">
							<?php 
            if ($current_user->membership_level->enddate) {
                echo date(get_option('date_format'), $current_user->membership_level->enddate);
            } else {
                echo "---";
            }
            ?>
							</td>
						</tr>
					</tbody>
				</table>
				<?php 
            //Todo: If there are multiple levels defined that aren't all in the same group defined as upgrades/downgrades
            ?>
				<div class="pmpro_actionlinks">
					<a href="<?php 
            echo pmpro_url("levels");
            ?>
"><?php 
            _e("View all Membership Options", "pmpro");
            ?>
</a>
				</div>

			</div> <!-- end pmpro_account-membership -->
		<?php 
        }
        ?>
		
		<?php 
        if (in_array('profile', $sections)) {
            ?>
			<div id="pmpro_account-profile" class="pmpro_box">	
				<?php 
            get_currentuserinfo();
            ?>
 
				<h3><?php 
            _e("My Account", "pmpro");
            ?>
</h3>
				<?php 
            if ($current_user->user_firstname) {
                ?>
					<p><?php 
                echo $current_user->user_firstname;
                ?>
 <?php 
                echo $current_user->user_lastname;
                ?>
</p>
				<?php 
            }
            ?>
				<ul>
					<?php 
            do_action('pmpro_account_bullets_top');
            ?>
					<li><strong><?php 
            _e("Username", "pmpro");
            ?>
:</strong> <?php 
            echo $current_user->user_login;
            ?>
</li>
					<li><strong><?php 
            _e("Email", "pmpro");
            ?>
:</strong> <?php 
            echo $current_user->user_email;
            ?>
</li>
					<?php 
            do_action('pmpro_account_bullets_bottom');
            ?>
				</ul>
				<div class="pmpro_actionlinks">
					<a href="<?php 
            echo admin_url('profile.php');
            ?>
"><?php 
            _e("Edit Profile", "pmpro");
            ?>
</a>
					<a href="<?php 
            echo admin_url('profile.php');
            ?>
"><?php 
            _e('Change Password', 'pmpro');
            ?>
</a>
				</div>
			</div> <!-- end pmpro_account-profile -->
		<?php 
        }
        ?>
	
		<?php 
        if (in_array('invoices', $sections) && !empty($invoices)) {
            ?>
		
		<div id="pmpro_account-invoices" class="pmpro_box">
			<h3><?php 
            _e("Past Invoices", "pmpro");
            ?>
</h3>
			<table width="100%" cellpadding="0" cellspacing="0" border="0">
				<thead>
					<tr>
						<th><?php 
            _e("Date", "pmpro");
            ?>
</th>
						<th><?php 
            _e("Level", "pmpro");
            ?>
</th>
						<th><?php 
            _e("Amount", "pmpro");
            ?>
</th>
					</tr>
				</thead>
				<tbody>
				<?php 
            $count = 0;
            foreach ($invoices as $invoice) {
                if ($count++ > 4) {
                    break;
                }
                //get an member order object
                $invoice_id = $invoice->id;
                $invoice = new MemberOrder();
                $invoice->getMemberOrderByID($invoice_id);
                $invoice->getMembershipLevel();
                ?>
						<tr id="pmpro_account-invoice-<?php 
                echo $invoice->code;
                ?>
">
							<td><a href="<?php 
                echo pmpro_url("invoice", "?invoice=" . $invoice->code);
                ?>
"><?php 
                echo date(get_option("date_format"), $invoice->timestamp);
                ?>
</td>
							<td><?php 
                echo $invoice->membership_level->name;
                ?>
</td>
							<td><?php 
                echo pmpro_formatPrice($invoice->total);
                ?>
</td>
						</tr>
						<?php 
            }
            ?>
				</tbody>
			</table>						
			<?php 
            if ($count == 6) {
                ?>
				<div class="pmpro_actionlinks"><a href="<?php 
                echo pmpro_url("invoice");
                ?>
"><?php 
                _e("View All Invoices", "pmpro");
                ?>
</a></div>
			<?php 
            }
            ?>
		</div> <!-- end pmpro_account-invoices -->
		<?php 
        }
        ?>
		
		<?php 
        if (in_array('links', $sections) && (has_filter('pmpro_member_links_top') || has_filter('pmpro_member_links_bottom'))) {
            ?>
		<div id="pmpro_account-links" class="pmpro_box">
			<h3><?php 
            _e("Member Links", "pmpro");
            ?>
</h3>
			<ul>
				<?php 
            do_action("pmpro_member_links_top");
            ?>
				
				<?php 
            do_action("pmpro_member_links_bottom");
            ?>
			</ul>
		</div> <!-- end pmpro_account-links -->		
		<?php 
        }
        ?>
	</div> <!-- end pmpro_account -->		
	<?php 
    }
    $content = ob_get_contents();
    ob_end_clean();
    return $content;
}
function pmprorh_checkFieldForLevel($field, $scope = "default", $args = NULL)
{
    if (!empty($field->levels)) {
        if ($scope == "profile") {
            //expecting the args to be the user id
            if (pmpro_hasMembershipLevel($field->levels, $args)) {
                return true;
            } else {
                return false;
            }
        } else {
            //check against $_REQUEST
            if (!empty($_REQUEST['level'])) {
                if (in_array($_REQUEST['level'], $field->levels)) {
                    return true;
                } else {
                    return false;
                }
            } else {
                return false;
            }
        }
    }
    return true;
}
function pmproap_pmpro_level_cost_text($text, $level)
{
    global $pmpro_pages;
    //only checkout page, with ap passed in, and have the level checking out for
    if (is_page($pmpro_pages['checkout']) && !empty($_REQUEST['ap']) && pmpro_hasMembershipLevel($level->id)) {
        $text = str_replace(__("The price for membership", "pmproap"), __("The price is", "pmproap"), $text);
        $text = str_replace(__(" now", "pmproap"), "", $text);
    }
    return $text;
}
function modify_nav_menu_args($args)
{
    //make sure PMPro is active
    if (!function_exists('pmpro_hasMembershipLevel')) {
        return $args;
    }
    //if not a member, return original
    if (!pmpro_hasMembershipLevel()) {
        return $args;
    }
    //get current user's level id
    global $current_user;
    $level = pmpro_getMembershipLevelForUser($current_user->ID);
    $level_id = $level->id;
    //get all menus
    $menus = get_registered_nav_menus();
    //reverse so level menus come first
    $menus = array_reverse($menus);
    //look for a member version of this and swap it in
    foreach ($menus as $location => $description) {
        if ($location == "members-" . $args['theme_location'] && has_nav_menu("members-" . $args['theme_location']) || $location == "members-" . $level_id . "-" . $args['theme_location'] && has_nav_menu("members-" . $level_id . "-" . $args['theme_location'])) {
            $args['theme_location'] = $location;
            break;
        }
    }
    return $args;
}
/**
 * Create, add, remove or updates the membership level of the given user to the given level.
 *
 * $level may either be the ID or name of the desired membership_level.
 * If $user_id is omitted, the value will be retrieved from $current_user.
 *
 * @param int $level ID of level to set as new level, use 0 to cancel membership
 * @param int $user_id ID of the user to change levels for
 * @param string $old_level_status The status to set for the row in the memberships users table. (e.g. inactive, cancelled, admin_cancelled, expired) Defaults to 'inactive'.
 * $param int $cancel_level If set cancel just this one level instead of all active levels (to support Multiple Memberships per User)
 *
 * Return values:
 *		Success returns boolean true.
 *		Failure returns boolean false.
 */
function pmpro_changeMembershipLevel($level, $user_id = NULL, $old_level_status = 'inactive', $cancel_level = NULL)
{
    global $wpdb;
    global $current_user, $pmpro_error;
    if (empty($user_id)) {
        $user_id = $current_user->ID;
    }
    if (empty($user_id)) {
        $pmpro_error = __("User ID not found.", "pmpro");
        return false;
    }
    //make sure user id is int for security
    $user_id = intval($user_id);
    if (empty($level)) {
        $level = 0;
    } else {
        if (is_array($level)) {
            //custom level
        } else {
            $level_obj = pmpro_getLevel($level);
            if (empty($level_obj)) {
                $pmpro_error = __("Invalid level.", "pmpro");
                return false;
            }
            $level = $level_obj->id;
        }
    }
    //if it's a custom level, they're changing
    if (!is_array($level)) {
        //are they even changing?
        if (pmpro_hasMembershipLevel($level, $user_id)) {
            $pmpro_error = __("not changing?", "pmpro");
            return false;
            //not changing
        }
    }
    //get all active membershipships for this user
    $old_levels = pmpro_getMembershipLevelsForUser($user_id);
    //get level id
    if (is_array($level)) {
        $level_id = $level['membership_id'];
    } else {
        $level_id = $level;
    }
    //just id
    /**
     * Action to run before the membership level changes.
     *
     * @param int $level_id ID of the level changed to.
     * @param int $user_id ID of the user changed.
     * @param array $old_levels array of prior levels the user belonged to.
     * $param int $cancel_level ID of the level being cancelled if specified
     */
    do_action("pmpro_before_change_membership_level", $level_id, $user_id, $old_levels, $cancel_level);
    //deactivate old memberships based on the old_level_status passed in (updates pmpro_memberships_users table)
    $pmpro_deactivate_old_levels = true;
    /**
     * Filter whether old levels should be deactivated or not. This supports the MMPU addon.
     * Typically you'll want to hook into pmpro_before_change_membership_level 
     * or pmpro_after_change_membership_level later to run your own deactivation logic.
     * 
     * @since  1.8.11
     * @var $pmpro_deactivate_old_levels bool True or false if levels should be deactivated. Defaults to true.
     */
    $pmpro_deactivate_old_levels = apply_filters("pmpro_deactivate_old_levels", $pmpro_deactivate_old_levels);
    //make sure we deactivate the specified level if it's passed in
    if (!empty($cancel_level)) {
        $pmpro_deactivate_old_levels = true;
        $new_old_levels = array();
        foreach ($old_levels as $key => $old_level) {
            if ($old_level->id == $cancel_level) {
                $new_old_levels[] = $old_levels[$key];
                break;
            }
        }
        $old_levels = $new_old_levels;
    }
    if ($old_levels && $pmpro_deactivate_old_levels) {
        foreach ($old_levels as $old_level) {
            $sql = "UPDATE {$wpdb->pmpro_memberships_users} SET `status`='{$old_level_status}', `enddate`='" . current_time('mysql') . "' WHERE `id`=" . $old_level->subscription_id;
            if (!$wpdb->query($sql)) {
                $pmpro_error = __("Error interacting with database", "pmpro") . ": " . ($wpdb->last_error ? $wpdb->last_error : 'unavailable');
                return false;
            }
        }
    }
    //should we cancel their gateway subscriptions?
    if (!empty($cancel_level)) {
        $pmpro_cancel_previous_subscriptions = true;
        //don't filter cause we're doing just the one
        $other_order_ids = $wpdb->get_col("SELECT id FROM {$wpdb->pmpro_membership_orders} WHERE user_id = '" . $user_id . "' AND status = 'success' AND membership_id = '" . esc_sql($cancel_level) . "' ORDER BY id DESC");
    } else {
        $pmpro_cancel_previous_subscriptions = true;
        if (isset($_REQUEST['cancel_membership']) && $_REQUEST['cancel_membership'] == false) {
            $pmpro_cancel_previous_subscriptions = false;
        }
        $pmpro_cancel_previous_subscriptions = apply_filters("pmpro_cancel_previous_subscriptions", $pmpro_cancel_previous_subscriptions);
        $other_order_ids = $wpdb->get_col("SELECT id FROM {$wpdb->pmpro_membership_orders} WHERE user_id = '" . $user_id . "' AND status = 'success' ORDER BY id DESC");
    }
    //cancel any other subscriptions they have (updates pmpro_membership_orders table)
    if ($pmpro_cancel_previous_subscriptions && !empty($other_order_ids)) {
        foreach ($other_order_ids as $order_id) {
            $c_order = new MemberOrder($order_id);
            $c_order->cancel();
            if (!empty($c_order->error)) {
                $pmpro_error = $c_order->error;
            }
        }
    }
    //insert current membership
    if (!empty($level)) {
        //make sure the dates are in good formats
        if (is_array($level)) {
            //Better support mySQL Strict Mode by passing  a proper enum value for cycle_period
            if ($level['cycle_period'] == '') {
                $level['cycle_period'] = 0;
            }
            // clean up date formatting (string/not string)
            $level['startdate'] = preg_replace('/\'/', '', $level['startdate']);
            $level['enddate'] = preg_replace('/\'/', '', $level['enddate']);
            $sql = $wpdb->prepare("\r\n\t\t\t\t\tINSERT INTO {$wpdb->pmpro_memberships_users}\r\n\t\t\t\t\t(`user_id`, `membership_id`, `code_id`, `initial_payment`, `billing_amount`, `cycle_number`, `cycle_period`, `billing_limit`, `trial_amount`, `trial_limit`, `startdate`, `enddate`)\r\n\t\t\t\t\tVALUES\r\n\t\t\t\t\t( %d, %d, %d, %s, %s, %d, %s, %d, %s, %d, %s, %s )", $level['user_id'], $level['membership_id'], $level['code_id'], $level['initial_payment'], $level['billing_amount'], $level['cycle_number'], $level['cycle_period'], $level['billing_limit'], $level['trial_amount'], $level['trial_limit'], $level['startdate'], $level['enddate']);
        } else {
            $sql = $wpdb->prepare("\r\n\t\t\t\tINSERT INTO {$wpdb->pmpro_memberships_users}\r\n\t\t\t\t( `user_id`, `membership_id`, `code_id`, `initial_payment`, `billing_amount`, `cycle_number`, `cycle_period`, `billing_limit`, `trial_amount`, `trial_limit`, `startdate`, `enddate`)\r\n\t\t\t\t\tVALUES \r\n\t\t\t\t\t( %d, %d, %d, %d, %d, %d, %d, %d, %d, %d, %s, %s )", $user_id, $level_id, '0', '0', '0', '0', '0', '0', '0', '0', current_time('mysql'), '0000-00-00 00:00:00');
        }
        if (false === $wpdb->query($sql)) {
            $pmpro_error = sprintf(__("Error interacting with database: %s", "pmpro"), !empty($wpdb->last_error) ? $wpdb->last_error : 'unavailable');
            return false;
        }
    }
    //remove cached level
    global $all_membership_levels;
    unset($all_membership_levels[$user_id]);
    //update user data and call action
    pmpro_set_current_user();
    /**
     * Action to run after the membership level changes.
     *
     * @param int $level_id ID of the level changed to.
     * @param int $user_id ID of the user changed.
     * $param int $cancel_level ID of the level being cancelled if specified.
     */
    do_action("pmpro_after_change_membership_level", $level_id, $user_id, $cancel_level);
    return true;
}
function pmpromd_profile_preheader()
{
    global $post, $pmpro_pages, $current_user;
    if (!empty($post->ID) && $post->ID == $pmpro_pages['profile']) {
        /*
        	Preheader operations here.
        */
        global $main_post_id;
        $main_post_id = $post->ID;
        //Get the profile user
        if (!empty($_REQUEST['pu']) && is_numeric($_REQUEST['pu'])) {
            $pu = get_user_by('id', $_REQUEST['pu']);
        } elseif (!empty($_REQUEST['pu'])) {
            $pu = get_user_by('slug', $_REQUEST['pu']);
        } elseif (!empty($current_user->ID)) {
            $pu = $current_user;
        } else {
            $pu = false;
        }
        //If no profile user, go to directory or home
        if (empty($pu) || empty($pu->ID)) {
            if (!empty($pmpro_pages['directory'])) {
                wp_redirect(get_permalink($pmpro_pages['directory']));
            } else {
                wp_redirect(home_url());
            }
            exit;
        }
        /*
        	If a level is required for the profile page, make sure the profile user has it.
        */
        //check is levels are required
        $levels = pmpro_getMatches("/ levels?=[\"']([^\"^']*)[\"']/", $post->post_content, true);
        if (!empty($levels) && !pmpro_hasMembershipLevel(explode(",", $levels), $pu->ID)) {
            if (!empty($pmpro_pages['directory'])) {
                wp_redirect(get_permalink($pmpro_pages['directory']));
            } else {
                wp_redirect(home_url());
            }
            exit;
        }
        /*
        	Update the head title and H1
        */
        function pmpromd_the_title($title, $post_id = NULL)
        {
            global $main_post_id, $current_user;
            if ($post_id == $main_post_id) {
                if (!empty($_REQUEST['pu'])) {
                    global $wpdb;
                    $user_nicename = $_REQUEST['pu'];
                    $display_name = $wpdb->get_var("SELECT display_name FROM {$wpdb->users} WHERE user_nicename = '" . esc_sql($user_nicename) . "' LIMIT 1");
                } elseif (!empty($current_user)) {
                    $display_name = $current_user->display_name;
                }
                if (!empty($display_name)) {
                    $title = $display_name;
                }
            }
            return $title;
        }
        add_filter("the_title", "pmpromd_the_title", 10, 2);
        function pmpromd_wp_title($title, $sep)
        {
            global $wpdb, $main_post_id, $post, $current_user;
            if ($post->ID == $main_post_id) {
                if (!empty($_REQUEST['pu'])) {
                    $user_nicename = $_REQUEST['pu'];
                    $display_name = $wpdb->get_var("SELECT display_name FROM {$wpdb->users} WHERE user_nicename = '" . esc_sql($user_nicename) . "' LIMIT 1");
                } elseif (!empty($current_user)) {
                    $display_name = $current_user->display_name;
                }
                if (!empty($display_name)) {
                    $title = $display_name . ' ' . $sep . ' ';
                }
                $title .= get_bloginfo('name');
            }
            return $title;
        }
        add_filter("wp_title", "pmpromd_wp_title", 10, 2);
    }
}
Example #16
0
function showProfile()
{
    $current_user = wp_get_current_user();
    $current_user_id = $current_user->ID;
    if (pmpro_hasMembershipLevel('5')) {
        ?>
		<script>
			jQuery(function($){
				$('.pmpro_actionlinks a:nth-child(1)').css('display', 'none');
			});
		</script>
	<?php 
    }
    ?>
	<div class="panel-wrapper">
		<div class="fcc-panel profile">
			<div class="title">My Profile<div class="section-collapse">collapse <i class="icon-chevron-up"></i></div></div>
			<div class="content">					
				<table>
					<tr class="row">
						<td class="five columns">Username</td>
						<td class="seven columns"><?php 
    echo $current_user->user_login;
    ?>
</td>
					</tr>
					<tr class="row">
						<td class="five columns">First Name</td>
						<td class="seven columns"><?php 
    echo $current_user->first_name;
    ?>
</td>
					</tr>
					<tr class="row">
						<td class="five columns">Last Name</td>
						<td class="seven columns"><?php 
    echo $current_user->user_lastname;
    ?>
</td>
					</tr>
					<tr class="row">
						<td class="five columns">Nickname</td>
						<td class="seven columns"><?php 
    echo $current_user->nickname;
    ?>
</td>
					</tr>
					<tr class="row">
						<td class="five columns">E-mail</td>
						<td class="seven columns"><?php 
    echo $current_user->user_email;
    ?>
</td>
					</tr>
					<tr class="row">
						<td class="five columns">Occupation</td>
						<td class="seven columns"><?php 
    echo get_user_meta($current_user_id, 'occupation', true);
    ?>
</td>
					</tr>
				</table>
				<table>
					<tr class="row table-header">
						<td class="twelve columns">Membership Account Information</td>
					</tr>
				</table>
				<table>
					<tr class="row">
						<td class="five columns">Level</td>
						<td class="seven columns membership-level"></td>
					</tr>
					<tr class="row">
						<td class="five columns">Billing</td>
						<td class="seven columns memberhsip-billing"></td>
					</tr>
					<tr class="row">
						<td class="five columns">Expiration</td>
						<td class="seven columns membership-expiration"></td>
					</tr>
				</table>
				<div style="display:none">
					<?php 
    echo do_shortcode('[pmpro_account]');
    ?>
</div>
			</div>
		</div>
		<div class="shadow"></div>
	</div>

	<div class="panel-wrapper">
		<div class="fcc-panel progress_report">
			<div class="title">Simulated Exam Progress Report<div class="section-collapse">collapse <i class="icon-chevron-up"></i></div></div>
			<div class="content">
				<div class="row">
					<div id="progress-report" class="<?php 
    echo $current_user_id;
    ?>
"></div>
				</div>
			</div>
		</div>
		<div class="shadow"></div>
	</div>

	<div class="panel-wrapper">
		<div class="fcc-panel">
			<div class="title">Forms<div class="section-collapse">collapse <i class="icon-chevron-up"></i></div></div>
			<div class="content">
				<div class="row">
					<p><a href="/wp-content/themes/passFCCExams/assets/pdfs/(GROL) FCC 605 Main Form.pdf" target="_blank">General Radiotelephone Operator License (GROL) FCC 605 Main Form</a></p>
					<p>NOTE: This sample FCC 605 Main Form is for new individual GROL applicant only. If you are filing out another FCC license form, please consult their FCC website, or call the FCC (888) 225-5322, and they will walk you through filling out your forms.</p> 
					<p><a href="/wp-content/themes/passFCCExams/assets/pdfs/Ship Radar Endorsement form FCC 605 Schedule E.pdf" target="_blank">Ship Radar Endorsement form FCC 605 Schedule E</a></p>
				</div>
			</div>
		</div>
		<div class="shadow"></div>
	</div>

	<div class="panel-wrapper">
		<div class="fcc-panel profile">
			<div class="title">Disclaimer<div class="section-collapse">collapse <i class="icon-chevron-up"></i></div></div>
			<div class="content">
				<table>
					<tr class="row table-header" style="border-top:none">
						<td class="twelve columns">Terms of Use</td>
					</tr>
					<tr class="row">
						<td class="twelve columns">
							Do not use or access this website if you do not agree with any of the contents, terms and conditions in this disclaimer. However, if you are using this website, you are by default accepting the terms and conditions.
						</td>
					</tr>
					<tr class="row table-header">
						<td class="twelve columns">Warranties and Liabilities</td>
					</tr>
					<tr class="row">
						<td class="twelve columns">
							<div>PassFCCExams.com has put in every effort in making sure the authenticity, accuracy and completeness of the information provided, however, PassFCCExams.com does not make any representation, warranties or claims for the information to be fully authentic, accurate and complete, as the information present on PassFCCExams.com is used on ‘as it is’ basis. With every intention of providing you with the best facility, no commitment or claims are made as to, keeping the information posted on PassFCCExams.com up dated, or would be completely viable or genuine every time, and would at any point of time and in any capacity might misinform or deceive you, or if you would be able to access or use the site forever (due to availability or non-availability of the website).</div>
							<div><br>The site may contain virus, errors or other kinds of bugs that may affect your system. It would be entirely your responsibility to keep your system virus free, with appropriate protection.  In case if your system gets any virus from the website PassFCCExams.com will not be responsible.  It is highly recommended that any files needed to be downloaded must be scanned for viruses.  PassFCCExams.com withdraws or rules out any and all site related claims and representations weather they are implied by low or not. The content on this site must not be taken as professional or a formal advice or recommendation in any form.</div>
							<div><br>In case of any minor, secondary, indirect, significant, castigatory and special damages of any kind, or any other damage of any kind, in any capacity, including damages that result in the form of loss of profit, dissolution, termination or loss of contracts, damage of reputation, profits, incomes, goodwill, savings, business or public relations, PassFCCExams.com shall not be held responsible, whether or not the cause of the damages may be due to the use of the website or the content in the website or any website or information linked with PassFCCExams.com.</div>
						</td>
					</tr>
				</table>
			</div>
		</div>
		<div class="shadow"></div>
	</div>

	<script>
		jQuery(function($){
			//hack
			var membership_level = $('.fcc-panel.profile #pmpro_account .pmpro_account-membership-levelname').html();
			var membership_billing = $('.fcc-panel.profile #pmpro_account .pmpro_account-membership-levelfee p strong').html();
			var membership_expiration = $('.fcc-panel.profile #pmpro_account .pmpro_account-membership-expiration').text();

			$('.fcc-panel.profile .membership-level').html(membership_level);
			$('.fcc-panel.profile .memberhsip-billing').html(membership_billing);
			$('.fcc-panel.profile .membership-expiration').html(membership_expiration);
		});
	</script>
	<?php 
}
function pmpros_hasAccess($user_id, $post_id)
{
    //is this post in a series?
    $post_series = get_post_meta($post_id, "_post_series", true);
    if (empty($post_series)) {
        return true;
    }
    //not in a series
    //does this user have a level giving them access to everything?
    $all_access_levels = apply_filters("pmproap_all_access_levels", array(), $user_id, $post_id);
    if (!empty($all_access_levels) && pmpro_hasMembershipLevel($all_access_levels, $user_id)) {
        return true;
    }
    //user has one of the all access levels
    //check each series
    foreach ($post_series as $series_id) {
        //does the user have access to any of the series pages?
        $results = pmpro_has_membership_access($series_id, $user_id, true);
        //passing true there to get the levels which have access to this page
        if ($results[0]) {
            //has the user been around long enough for any of the delays?
            $series_posts = get_post_meta($series_id, "_series_posts", true);
            if (!empty($series_posts)) {
                foreach ($series_posts as $sp) {
                    //this post we are checking is in this series
                    if ($sp->id == $post_id) {
                        //check specifically for the levels with access to this series
                        foreach ($results[1] as $level_id) {
                            if (max(0, pmpro_getMemberDays($user_id, $level_id)) >= $sp->delay) {
                                return true;
                                //user has access to this series and has been around longer than this post's delay
                            }
                        }
                    }
                }
            }
        }
    }
    //haven't found anything yet. so must not have access
    return false;
}
Example #18
0
File: config.php Project: 6226/wp
 /**
  * Checks $area for applied restrictions based on user status(logged in, membership level)
  * and does the proper redirect
  * @global object $current_user
  * @param string $area
  * @param array $restrict_options
  * @since 2.0
  */
 function kleo_check_access($area, $restrict_options = null)
 {
     global $current_user;
     if (!$restrict_options) {
         $restrict_options = kleo_memberships();
     }
     if (pmpro_url("levels")) {
         $default_redirect = pmpro_url("levels");
     } else {
         $default_redirect = bp_get_signup_page();
     }
     $default_redirect = apply_filters('kleo_pmpro_url_redirect', $default_redirect);
     //no restriction
     if ($restrict_options[$area]['type'] == 0) {
         return;
     }
     //restrict all members -> go to home url
     if ($restrict_options[$area]['type'] == 1) {
         wp_redirect(apply_filters('kleo_pmpro_home_redirect', home_url()));
         exit;
     }
     //is a member
     if (isset($current_user->membership_level) && $current_user->membership_level->ID) {
         //if restrict my level
         if ($restrict_options[$area]['type'] == 2 && is_array($restrict_options[$area]['levels']) && !empty($restrict_options[$area]['levels']) && pmpro_hasMembershipLevel($restrict_options[$area]['levels'])) {
             wp_redirect($default_redirect);
             exit;
         }
         //logged in but not a member
     } else {
         if (is_user_logged_in()) {
             if ($restrict_options[$area]['type'] == 2 && isset($restrict_options[$area]['not_member']) && $restrict_options[$area]['not_member'] == 1) {
                 wp_redirect($default_redirect);
                 exit;
             }
         } else {
             if ($restrict_options[$area]['type'] == 2 && isset($restrict_options[$area]['guest']) && $restrict_options[$area]['guest'] == 1) {
                 wp_redirect($default_redirect);
                 exit;
             }
         }
     }
 }
Example #19
0
function pmprorh_signup_shortcode($atts, $content = null, $code = "")
{
    // $atts    ::= array of attributes
    // $content ::= text within enclosing form of shortcode element
    // $code    ::= the shortcode found, when == callback name
    // examples: [pmpro_signup level="3" short="1" intro="0" button="Signup Now"]
    //make sure PMPro is activated
    if (!function_exists('pmpro_getLevel')) {
        return "Paid Memberships Pro must be installed to use the pmpro_signup shortcode.";
    }
    //default title
    if (!empty($level)) {
        $default_title = 'Register For ' . pmpro_getLevel($level)->name;
    } else {
        $default_title = 'Register For ' . get_option('blogname');
    }
    //set defaults
    extract(shortcode_atts(array('button' => "Sign Up Now", 'intro' => "0", 'level' => NULL, 'login' => true, 'short' => NULL, 'title' => $default_title), $atts));
    //turn 0's into falses
    if ($login === "0" || $login === "false" || $login === "no") {
        $login = false;
    } else {
        $login = true;
    }
    if ($short === "0" || $short === "false" || $short === "no") {
        $short = false;
    } else {
        $short = true;
    }
    if ($intro === "0" || $intro === "false" || $intro === "no") {
        $intro = false;
    }
    global $current_user, $membership_levels;
    ob_start();
    ?>
		<?php 
    if (!empty($current_user->ID) && pmpro_hasMembershipLevel($level, $current_user->ID)) {
        ?>
			<p>You are logged in as <?php 
        echo $current_user->user_login;
        ?>
.</p>
		<?php 
    } else {
        ?>
		<form class="pmpro_form pmpro_signup_form" action="<?php 
        echo pmpro_url("checkout");
        ?>
" method="post">
			<h2><?php 
        echo $title;
        ?>
</h2>
			<?php 
        if (!empty($intro)) {
            echo wpautop($intro);
        }
        ?>
			<input type="hidden" id="level" name="level" value="<?php 
        echo $level;
        ?>
" />
			<?php 
        if (!empty($current_user->ID)) {
            ?>
					<p id="pmpro_account_loggedin">
						<?php 
            printf(__('You are logged in as <strong>%s</strong>. If you would like to use a different account for this membership, <a href="%s">log out now</a>.', 'pmpro'), $current_user->user_login, wp_logout_url($_SERVER['REQUEST_URI']));
            ?>
					</p>
					<?php 
        } else {
            ?>
					<div>
						<label for="username">Username</label>
						<input id="username" name="username" type="text" class="input" size="30" value="" />
					</div>
					<?php 
            do_action("pmpro_checkout_after_username");
            ?>
					<div>
						<label for="password">Password</label>
						<input id="password" name="password" type="password" class="input" size="30" value="" />
					</div>
					<?php 
            if ($short) {
                ?>
						<input type="hidden" name="password2_copy" value="1" />
					<?php 
            } else {
                ?>
						<div>
							<label for="password2">Confirm Password</label>
							<input id="password2" name="password2" type="password" class="input" size="30" value="" />
						</div>
					<?php 
            }
            ?>
					<?php 
            do_action("pmpro_checkout_after_password");
            ?>
					<div>
						<label for="bemail">E-mail Address</label>
						<input id="bemail" name="bemail" type="email" class="input" size="30" value="" />
					</div>
					<?php 
            if ($short) {
                ?>
						<input type="hidden" name="bconfirmemail_copy" value="1" />
					<?php 
            } else {
                ?>
						<div>
							<label for="bconfirmemail">Confirm E-mail</label>
							<input id="bconfirmemail" name="bconfirmemail" type="email" class="input" size="30" value="" />
						</div>
					<?php 
            }
            ?>
					<?php 
            do_action("pmpro_checkout_after_email");
            ?>
					<div class="pmpro_hidden">
						<label for="fullname">Full Name</label>
						<input id="fullname" name="fullname" type="text" class="input" size="30" value="" /> <strong>LEAVE THIS BLANK</strong>
					</div>

					<div class="pmpro_captcha">
						<?php 
            global $recaptcha, $recaptcha_publickey;
            if ($recaptcha == 2 || !empty($level) && $recaptcha == 1 && pmpro_isLevelFree(pmpro_getLevel($level))) {
                echo pmpro_recaptcha_get_html($recaptcha_publickey, NULL, true);
            }
            ?>
					</div>
					<?php 
        }
        ?>
			<div>
				<span id="pmpro_submit_span" >
					<input type="hidden" name="submit-checkout" value="1" />
					<input type="submit" class="pmpro_btn pmpro_btn-submit-checkout" value="<?php 
        echo $button;
        ?>
" />
				</span>
			</div>
			<?php 
        if (!empty($login) && empty($current_user->ID)) {
            ?>
			<div style="text-align:center;">
				<a href="<?php 
            echo wp_login_url(get_permalink());
            ?>
"><?php 
            _e('Log In', 'pmpro');
            ?>
</a>
			</div>
			<?php 
        }
        ?>
		</form>
		<?php 
    }
    ?>
	<?php 
    $temp_content = ob_get_contents();
    ob_end_clean();
    return $temp_content;
}
Example #20
0
"
				href="<?php 
        echo pmpro_url("checkout", "?level=" . $level->id, "https");
        ?>
">
				<?php 
        _e('Select', 'pmpro');
        ?>
			</a>
		<?php 
    } elseif (!$current_level) {
        ?>
                	
			<a
				class="pmpro_btn <?php 
        echo $level->id == '1' && (user_has_expired_account() || pmpro_hasMembershipLevel()) ? 'disabled' : 'pmpro_btn-select';
        ?>
"
				href="<?php 
        echo pmpro_url("checkout", "?level=" . $level->id, "https");
        ?>
">
				<?php 
        _e('Select', 'pmpro');
        ?>
			</a>
		<?php 
    } elseif ($current_level) {
        ?>
      
			<a
function pmprowoo_checkout_level_extend_memberships($level_array)
{
    $level_obj = pmpro_getLevel($level_array['membership_id']);
    //does this level expire? are they an existing user of this level?
    if (!empty($level_obj) && !empty($level_obj->expiration_number) && pmpro_hasMembershipLevel($level_obj->id, $level_array['user_id'])) {
        //get the current enddate of their membership
        $user = get_userdata($level_array['user_id']);
        $user->membership_level = pmpro_getMembershipLevelForUser($user->ID);
        $expiration_date = $user->membership_level->enddate;
        //calculate days left
        $todays_date = current_time('timestamp');
        $time_left = $expiration_date - $todays_date;
        //time left?
        if ($time_left > 0) {
            //convert to days and add to the expiration date (assumes expiration was 1 year)
            $days_left = floor($time_left / (60 * 60 * 24));
            //figure out days based on period
            if ($level_obj->expiration_period == "Day") {
                $total_days = $days_left + $level_obj->expiration_number;
            } elseif ($level_obj->expiration_period == "Week") {
                $total_days = $days_left + $level_obj->expiration_number * 7;
            } elseif ($level_obj->expiration_period == "Month") {
                $total_days = $days_left + $level_obj->expiration_number * 30;
            } elseif ($level_obj->expiration_period == "Year") {
                $total_days = $days_left + $level_obj->expiration_number * 365;
            }
            //update the end date
            $level_array['enddate'] = date("Y-m-d", strtotime("+ {$total_days} Days", $todays_date));
        }
    }
    return $level_array;
}
function pmpro_changeMembershipLevel($level, $user_id = NULL, $old_level_status = 'inactive')
{
    global $wpdb;
    global $current_user, $pmpro_error;
    if (empty($user_id)) {
        $user_id = $current_user->ID;
    }
    if (empty($user_id)) {
        $pmpro_error = __("User ID not found.", "pmpro");
        return false;
    }
    //make sure user id is int for security
    $user_id = intval($user_id);
    if (empty($level)) {
        $level = 0;
    } else {
        if (is_array($level)) {
            //custom level
        } else {
            $level_obj = pmpro_getLevel($level);
            if (empty($level_obj)) {
                $pmpro_error = __("Invalid level.", "pmpro");
                return false;
            }
            $level = $level_obj->id;
        }
    }
    //if it's a custom level, they're changing
    if (!is_array($level)) {
        //are they even changing?
        if (pmpro_hasMembershipLevel($level, $user_id)) {
            $pmpro_error = __("not changing?", "pmpro");
            return false;
            //not changing
        }
    }
    //get all active membershipships for this user
    $old_levels = pmpro_getMembershipLevelsForUser($user_id);
    //deactivate old memberships based on the old_level_status passed in (updates pmpro_memberships_users table)
    if ($old_levels) {
        foreach ($old_levels as $old_level) {
            $sql = "UPDATE {$wpdb->pmpro_memberships_users} SET `status`='{$old_level_status}', `enddate`='" . current_time('mysql') . "' WHERE `id`=" . $old_level->subscription_id;
            if (!$wpdb->query($sql)) {
                $pmpro_error = __("Error interacting with database", "pmpro") . ": " . (mysql_errno() ? mysql_error() : 'unavailable');
                return false;
            }
        }
    }
    //should we cancel their gateway subscriptions?
    $pmpro_cancel_previous_subscriptions = true;
    if (isset($_REQUEST['cancel_membership']) && $_REQUEST['cancel_membership'] == false) {
        $pmpro_cancel_previous_subscriptions = false;
    }
    $pmpro_cancel_previous_subscriptions = apply_filters("pmpro_cancel_previous_subscriptions", $pmpro_cancel_previous_subscriptions);
    //cancel any other subscriptions they have (updates pmpro_membership_orders table)
    if ($pmpro_cancel_previous_subscriptions) {
        $other_order_ids = $wpdb->get_col("SELECT id FROM {$wpdb->pmpro_membership_orders} WHERE user_id = '" . $user_id . "' AND status = 'success' ORDER BY id DESC");
        foreach ($other_order_ids as $order_id) {
            $c_order = new MemberOrder($order_id);
            $c_order->cancel();
            if (!empty($c_order->error)) {
                $pmpro_error = $c_order->error;
            }
        }
    }
    //insert current membership
    if (!empty($level)) {
        if (is_array($level)) {
            //make sure the dates are in good formats
            if ($level['startdate'] != current_time('mysql') && $level['startdate'] != "NULL" && substr($level['startdate'], 0, 1) != "'") {
                $level['startdate'] = "'" . $level['startdate'] . "'";
            }
            if ($level['enddate'] != current_time('mysql') && $level['enddate'] != "NULL" && substr($level['enddate'], 0, 1) != "'") {
                $level['enddate'] = "'" . $level['enddate'] . "'";
            }
            //Better support mySQL Strict Mode by passing  a proper enum value for cycle_period
            if ($level['cycle_period'] == '') {
                $level['cycle_period'] = 0;
            }
            $sql = "INSERT INTO {$wpdb->pmpro_memberships_users} (user_id, membership_id, code_id, initial_payment, billing_amount, cycle_number, cycle_period, billing_limit, trial_amount, trial_limit, startdate, enddate)\n\t\t\t\t\tVALUES('" . $level['user_id'] . "',\n\t\t\t\t\t'" . $level['membership_id'] . "',\n\t\t\t\t\t'" . intval($level['code_id']) . "',\n\t\t\t\t\t'" . $level['initial_payment'] . "',\n\t\t\t\t\t'" . $level['billing_amount'] . "',\n\t\t\t\t\t'" . $level['cycle_number'] . "',\n\t\t\t\t\t'" . $level['cycle_period'] . "',\n\t\t\t\t\t'" . $level['billing_limit'] . "',\n\t\t\t\t\t'" . $level['trial_amount'] . "',\n\t\t\t\t\t'" . $level['trial_limit'] . "',\n\t\t\t\t\t" . $level['startdate'] . ",\n\t\t\t\t\t" . $level['enddate'] . ")";
            if (!$wpdb->query($sql)) {
                $pmpro_error = __("Error interacting with database", "pmpro") . ": " . (mysql_errno() ? mysql_error() : 'unavailable');
                return false;
            }
        } else {
            $sql = "INSERT INTO {$wpdb->pmpro_memberships_users} (user_id, membership_id, code_id, initial_payment, billing_amount, cycle_number, cycle_period, billing_limit, trial_amount, trial_limit, startdate, enddate)\n\t\t\t    VALUES (\n\t\t\t    '" . $user_id . "',\n\t\t\t    '" . $level . "',\n\t\t\t    '0',\n\t\t\t    '0',\n\t\t\t    '0',\n\t\t\t    '0',\n\t\t\t    '0',\n\t\t\t    '0',\n\t\t\t    '0',\n\t\t\t    '0',\n\t\t\t    '" . current_time('mysql') . "',\n                \t    '0000-00-00 00:00:00'\n                \t    )";
            if (!$wpdb->query($sql)) {
                $pmpro_error = __("Error interacting with database", "pmpro") . ": " . (mysql_errno() ? mysql_error() : 'unavailable');
                return false;
            }
        }
    }
    //get level id
    if (is_array($level)) {
        $level_id = $level['membership_id'];
    } else {
        $level_id = $level;
    }
    //just id
    //remove cached level
    global $all_membership_levels;
    unset($all_membership_levels[$user_id]);
    //update user data and call action
    pmpro_set_current_user();
    do_action("pmpro_after_change_membership_level", $level_id, $user_id);
    //$level is the $level_id here
    return true;
}
Example #23
0
function memberlite_menus($items, $args)
{
    if ($args->theme_location == 'member') {
        if (is_user_logged_in() && pmpro_hasMembershipLevel()) {
            //user is logged in and has a membership level
            $items .= '<li><a href="' . wp_logout_url() . '">' . __('Log Out', 'memberlite') . '</a></li>';
        } elseif (is_user_logged_in()) {
            //user is logged in and does not have a membership level
            $items = '<li><a href="' . wp_logout_url() . '">' . __('Log Out', 'memberlite') . '</a></li>';
        } else {
            //not logged in
            $items = '<li><a href="' . wp_login_url() . '">' . __('Log In', 'memberlite') . '</a></li>';
            $items .= '<li><a href="' . wp_registration_url() . '">' . __('Register', 'memberlite') . '</a></li>';
        }
    }
    if ($args->theme_location == 'primary') {
        $nav_menu_search = get_theme_mod('nav_menu_search', false);
        if (!empty($nav_menu_search)) {
            $items .= get_search_form(false);
        }
    }
    return $items;
}
function memberlitesc_signup_shortcode($atts, $content = null, $code = "")
{
    // $atts    ::= array of attributes
    // $content ::= text within enclosing form of shortcode element
    // $code    ::= the shortcode found, when == callback name
    // examples: [pmpro_signup level="3" short="1" intro="0" submit_button="Signup Now"]
    extract(shortcode_atts(array('level' => NULL, 'title' => NULL, 'short' => NULL, 'intro' => NULL, 'submit_button' => "Sign Up Now"), $atts));
    //turn 0's into falses
    if ($short == "0" || $short == "false" || $short == "no") {
        $short = false;
    }
    if (empty($title)) {
        $title = pmpro_getLevel($level)->name;
    }
    global $current_user, $membership_levels;
    ob_start();
    ?>
		<?php 
    if (empty($current_user->ID) || !pmpro_hasMembershipLevel($level, $current_user->ID)) {
        ?>
		<form class="pmpro_form memberlite_signup" action="<?php 
        echo pmpro_url("checkout", "?level=" . $level, "https");
        ?>
" method="post">
			<h2><?php 
        echo $title;
        ?>
</h2>
			<?php 
        if (!empty($intro)) {
            echo wpautop($intro);
        }
        ?>
			<input type="hidden" id="level" name="level" value="<?php 
        echo $level;
        ?>
" />
			<?php 
        if (!empty($current_user->ID)) {
            ?>
					<p id="pmpro_account_loggedin">
						<?php 
            printf(__('You are logged in as <strong>%s</strong>. If you would like to use a different account for this membership, <a href="%s">log out now</a>.', 'pmpro'), $current_user->user_login, wp_logout_url($_SERVER['REQUEST_URI']));
            ?>
			
					</p>
					<?php 
        } else {
            ?>
					<div>
						<label for="username">Username</label>
						<input id="username" name="username" type="text" class="input" size="30" value="" /> 
					</div>
					<?php 
            do_action("pmpro_checkout_after_username");
            ?>
					<div>
						<label for="password">Password</label>
						<input id="password" name="password" type="password" class="input" size="30" value="" /> 
					</div>
					<?php 
            if ($short) {
                ?>
						<input type="hidden" name="password2_copy" value="1" />
					<?php 
            } else {
                ?>
						<div>
							<label for="password2">Confirm Password</label>
							<input id="password2" name="password2" type="password" class="input" size="30" value="" /> 
						</div>			
					<?php 
            }
            ?>
					<?php 
            do_action("pmpro_checkout_after_password");
            ?>
					<div>
						<label for="bemail">E-mail Address</label>
						<input id="bemail" name="bemail" type="email" class="input" size="30" value="" /> 
					</div>
					<?php 
            if ($short) {
                ?>
						<input type="hidden" name="bconfirmemail_copy" value="1" />
					<?php 
            } else {
                ?>
						<div>
							<label for="bconfirmemail">Confirm E-mail</label>
							<input id="bconfirmemail" name="bconfirmemail" type="email" class="input" size="30" value="" /> 
						</div>	         
					<?php 
            }
            ?>
					<?php 
            do_action("pmpro_checkout_after_email");
            ?>
					<div class="pmpro_hidden">
						<label for="fullname">Full Name</label>
						<input id="fullname" name="fullname" type="text" class="input" size="30" value="" /> <strong>LEAVE THIS BLANK</strong>
					</div>
					
					<div class="pmpro_captcha">
						<?php 
            global $recaptcha, $recaptcha_publickey;
            if ($recaptcha == 2 || $recaptcha == 1 && pmpro_isLevelFree($pmpro_level)) {
                echo recaptcha_get_html($recaptcha_publickey, NULL, true);
            }
            ?>
								
					</div>
					<?php 
        }
        ?>
			<div>
				<span id="pmpro_submit_span" >
					<input type="hidden" name="submit-checkout" value="1" />		
					<input type="submit" class="pmpro_btn pmpro_btn-submit-checkout" value="<?php 
        echo $submit_button;
        ?>
" />
				</span>
			</div>	
		</form>
		<?php 
    }
    ?>
	<?php 
    $temp_content = ob_get_contents();
    ob_end_clean();
    return $temp_content;
}
function pmprosm_pmpro_checkout_boxes()
{
    global $current_user, $pmpro_level, $pmpro_currency_symbol;
    //only for PMPROSM_MAIN_ACCOUNT_LEVEL
    if (empty($pmpro_level) || !pmprosm_isMainLevel($pmpro_level->id)) {
        return;
    }
    //make sure options are defined for this
    $pmprosm_values = pmprosm_getValuesByMainLevel($pmpro_level->id);
    if (empty($pmprosm_values['max_seats']) || !isset($pmprosm_values['seat_cost'])) {
        return;
    }
    //get seats from submit
    if (isset($_REQUEST['seats'])) {
        $seats = intval($_REQUEST['seats']);
    } elseif (!empty($current_user->ID)) {
        $seats = get_user_meta($current_user->ID, "pmprosm_seats", true);
    } else {
        $seats = "";
    }
    ?>
	<table id="pmpro_extra_seats" class="pmpro_checkout top1em" width="100%" cellpadding="0" cellspacing="0" border="0">
	<thead>
		<tr>
			<th><?php 
    _e("Would you like to purchase extra seats?", "pmpro_sponsored_members");
    ?>
</th>
		</tr>
	</thead>
	<tbody>		
		<tr>
			<td>
				<div>
					<label for="seats"><?php 
    echo __("How many?", "pmpro_sponsored_members");
    ?>
</label>
					<input type="text" id="seats" name="seats" value="<?php 
    echo esc_attr($seats);
    ?>
" size="10" />
					<small>
						<?php 
    //min seats defaults to 1
    if (!empty($pmprosm_values['min_seats'])) {
        $min_seats = $pmprosm_values['min_seats'];
    } else {
        $min_seats = 1;
    }
    if (isset($pmprosm_values['seat_cost_text'])) {
        printf(__("Enter a number from %d to %d. %s", "pmpro_sponsored_members"), $min_seats, $pmprosm_values['max_seats'], $pmprosm_values['seat_cost_text']);
    } else {
        printf(__("Enter a number from %d to %d. +%s per extra seat.", "pmpro_sponsored_members"), $min_seats, $pmprosm_values['max_seats'], $pmpro_currency_symbol . $pmprosm_values['seat_cost']);
    }
    ?>
						
					</small>					
					
					<?php 
    //adding sub accounts at checkout?
    if (!empty($pmprosm_values['sponsored_accounts_at_checkout'])) {
        //look for existing sponsored accounts
        $children = pmprosm_getChildren($current_user->ID);
        if (!empty($children)) {
            echo "<hr />";
            //get checkbox values if there
            if (isset($_REQUEST['old_sub_accounts_active'])) {
                $old_sub_accounts_active = $_REQUEST['old_sub_accounts_active'];
            } else {
                $old_sub_accounts_active = array();
            }
            $i = 0;
            foreach ($children as $child_id) {
                ?>
							<div>
								<?php 
                //get user
                $child = get_userdata($child_id);
                //acive?
                if (pmpro_hasMembershipLevel(NULL, $child_id)) {
                    $active = true;
                } else {
                    $active = false;
                }
                //checked?
                if (isset($old_sub_accounts_active[$i])) {
                    $checked = $old_sub_accounts_active[$i];
                } else {
                    $checked = $active;
                }
                ?>
								<label><?php 
                echo $child->display_name;
                ?>
</label>
								<input type="checkbox" id="old_sub_accounts_active_<?php 
                echo $i;
                ?>
" class="old_sub_accounts_active" name="old_sub_accounts_active[]" value="<?php 
                echo $child_id;
                ?>
" <?php 
                checked($checked, true);
                ?>
 />
								<label class="pmpro_normal pmpro_clickable" for="old_sub_accounts_active_<?php 
                echo $i;
                ?>
">
								<?php 
                if (!empty($active)) {
                    ?>
									<?php 
                    _e('Keep checked to keep this account active.', 'pmprosm');
                    ?>
								<?php 
                } else {
                    ?>
									<?php 
                    _e('Check to reactivate this account.', 'pmprosm');
                    ?>
								<?php 
                }
                ?>
								</label>
							</div>
							<?php 
                $i++;
            }
        }
        //end existing sponsored accounts
        echo "<div id = 'sponsored_accounts'>";
        if (!empty($_REQUEST['add_sub_accounts_username'])) {
            $child_usernames = $_REQUEST['add_sub_accounts_username'];
        } elseif ($seats) {
            $child_usernames = array_fill(0, $seats, '');
        } else {
            $child_usernames = array();
        }
        if (!empty($_REQUEST['add_sub_accounts_first_name'])) {
            $child_first_names = $_REQUEST['add_sub_accounts_first_name'];
        } elseif ($seats) {
            $child_first_names = array_fill(0, $seats, '');
        } else {
            $child_first_names = array();
        }
        if (!empty($_REQUEST['add_sub_accounts_last_name'])) {
            $child_last_names = $_REQUEST['add_sub_accounts_last_name'];
        } elseif ($seats) {
            $child_last_names = array_fill(0, $seats, '');
        } else {
            $child_last_names = array();
        }
        if (!empty($_REQUEST['add_sub_accounts_email'])) {
            $child_emails = $_REQUEST['add_sub_accounts_email'];
        } elseif ($seats) {
            $child_emails = array_fill(0, $seats, '');
        } else {
            $child_emails = array();
        }
        for ($i = 0; $i < count($child_usernames); $i++) {
            if (is_array($child_usernames)) {
                $child_username = $child_usernames[$i];
            } else {
                $child_username = "";
            }
            if (is_array($child_usernames)) {
                $child_first_name = $child_first_names[$i];
            } else {
                $child_first_name = "";
            }
            if (is_array($child_usernames)) {
                $child_last_name = $child_last_names[$i];
            } else {
                $child_last_name = "";
            }
            if (is_array($child_usernames)) {
                $child_email = $child_emails[$i];
            } else {
                $child_email = "";
            }
            ?>
										
						<div id="sponsored_account_<?php 
            echo $i;
            ?>
">
							<hr />
							<?php 
            if (!empty($pmprosm_values['children_get_name'])) {
                ?>
								<label><?php 
                echo __("First Name", "pmpro_sponsored_members");
                ?>
</label>
								<input type="text" name="add_sub_accounts_first_name[]" value="<?php 
                echo esc_attr($child_first_name);
                ?>
" size="20" />
								<br>
								<label><?php 
                echo __("Last Name", "pmpro_sponsored_members");
                ?>
</label>
								<input type="text" name="add_sub_accounts_last_name[]" value="<?php 
                echo esc_attr($child_last_name);
                ?>
" size="20" />
								<br>
							<?php 
            }
            ?>
							<?php 
            if (empty($pmprosm_values['children_hide_username'])) {
                ?>
								<label><?php 
                echo __("Username", "pmpro_sponsored_members");
                ?>
</label>
								<input type="text" name="add_sub_accounts_username[]" value="<?php 
                echo esc_attr($child_username);
                ?>
" size="20" />
								<br>
							<?php 
            }
            ?>
							<?php 
            if (empty($pmprosm_values['children_hide_email'])) {
                ?>
								<label><?php 
                echo __("Email", "pmpro_sponsored_members");
                ?>
</label>
								<input type="text" name="add_sub_accounts_email[]" value="<?php 
                echo esc_attr($child_email);
                ?>
" size="20" />
								<br>
							<?php 
            }
            ?>
							<?php 
            if (empty($pmprosm_values['children_hide_password'])) {
                ?>
								<label><?php 
                echo __("Password", "pmpro_sponsored_members");
                ?>
</label>
								<input type="password" name="add_sub_accounts_password[]" value="" size="20" />
							<?php 
            }
            ?>
							<?php 
            do_action('pmprosm_children_fields', $i, $seats);
            ?>
						</div>
						<?php 
        }
        echo "</div>";
        /*
        	Get the HTML for the empty extra fields and save it to a variable.
        */
        ob_start();
        do_action("pmprosm_children_fields", false, $seats);
        $empty_child_fields = ob_get_contents();
        ob_end_clean();
        //also clean it up a bit
        $empty_child_fields = str_replace("\n", "", $empty_child_fields);
    }
    //if(!empty($pmprosm_values['sponsored_accounts_at_checkout']))
    ?>
						
					<script>
					jQuery(document).ready(function() {
						var pmpro_base_level_is_free = <?php 
    if (pmpro_isLevelFree($pmpro_level)) {
        echo "true";
    } else {
        echo "false";
    }
    ?>
;
						var seat_cost = <?php 
    echo intval($pmprosm_values['seat_cost']);
    ?>
;
						var min_seats = <?php 
    if (!empty($pmprosm_values['min_seats'])) {
        echo intval($pmprosm_values['min_seats']);
    } else {
        echo "0";
    }
    ?>
;
						var max_seats = <?php 
    if (!empty($pmprosm_values['max_seats'])) {
        echo intval($pmprosm_values['max_seats']);
    } else {
        echo "false";
    }
    ?>
;
						
						//update things when the # of seats changes
						jQuery('#seats, input.old_sub_accounts_active').bind("change", function() { 
							seatsChanged();
						});

						//run it once on load too
						seatsChanged();

						function seatsChanged()
						{
							//num seats entered
							seats = parseInt(jQuery('#seats').val());										

							//num of old seats checked
							old_sub_accounts_active = 0;
							jQuery("input.old_sub_accounts_active:checked").each(function(){
								old_sub_accounts_active += 1;
							});
														
							//max sure not over max
							if(max_seats && seats > max_seats)
							{
								seats = max_seats;
								jQuery('#seats').val(seats);
							}
							
							//and not under min
							if(min_seats && seats < min_seats)
							{
								seats = min_seats;
								jQuery('#seats').val(seats);
							}
							
							<?php 
    //how many child seats are shown now (if sponsored_accounts_at_checkout is set)
    if (!empty($pmprosm_values['sponsored_accounts_at_checkout'])) {
        ?>
								if(jQuery('#sponsored_accounts'))
								{
									children = jQuery('#sponsored_accounts').children();											
									i = children.length-1;
														
									//how many should we show
									newseats = seats - old_sub_accounts_active;
														
									if(newseats < children.length)
									{
										while(i >= newseats)
										{
											jQuery(children[i]).remove();
											i--;
										}
									}
									else if(newseats > children.length)
									{	
										i = children.length;
										
										while (i < newseats)
										{																
											jQuery('#sponsored_accounts').append('<div id = "sponsored_account_'+i+'"><hr /><?php 
        if (!empty($pmprosm_values["children_get_name"])) {
            ?>
<label>First Name</label><input type="text" name="add_sub_accounts_first_name[]" value="" size="20" /><br><label>Last Name</label><input type="text" name="add_sub_accounts_last_name[]" value="" size="20" /><br><?php 
        }
        if (empty($pmprosm_values["children_hide_username"])) {
            ?>
<label>Username</label><input type="text" name="add_sub_accounts_username[]" value="" size="20" /><br><?php 
        }
        ?>
<label>Email</label><input type="text" name="add_sub_accounts_email[]" value"" size="20" /><br><label>Password</label><input type="password" name="add_sub_accounts_password[]" value="" size="20" /><?php 
        echo $empty_child_fields;
        ?>
</div>');
											i++;
										}
									}
								}
								<?php 
    }
    ?>
							
							if(pmpro_base_level_is_free && seat_cost && seats)
							{
								//need to show billing fields
								jQuery('#pmpro_payment_method').show();
								jQuery('#pmpro_billing_address_fields').show();
								jQuery('#pmpro_payment_information_fields').show();
							}
							else if(pmpro_base_level_is_free)
							{
								//need to hide billing fields
								jQuery('#pmpro_payment_method').hide();
								jQuery('#pmpro_billing_address_fields').hide();
								jQuery('#pmpro_payment_information_fields').hide();
							}
							
							<?php 
    do_action('pmprosm_seats_changed_js');
    ?>
						}
					});
					</script>					
				</div>
			</td>
		</tr>
	</tbody>
</table>
<?php 
}
                                        <?php 
        $video_description = get_field('video_description', $post_id = $post->ID);
        ?>
                                        <div class="video_description">
                                            <?php 
        echo $video_description;
        ?>
                                        </div>
                                    </div>
                                    <div class="col-lg-4 col-md-4 col-sm-5 col-xs-12">
                                        <a class="video_downloads" href="#">
                                            <h5>DOWNLOADS</h5>
                                        </a>

                                        <?php 
        if (pmpro_hasMembershipLevel(array(6, 7, 12, 14))) {
            ?>
                                            <?php 
            $white_papers = get_field('white_papers', $post_id = $post->ID);
            ?>

                                            <?php 
            if ($white_papers) {
                ?>
                                                <div class="btn-group border_bottom">
                                                    <a class="icon-text" href="<?php 
                echo $white_papers;
                ?>
" target="_blank" data-original-title="" title="">
                                                        <img src="<?php 
                echo get_template_directory_uri() . "/assets/global/img/white-papers.png";
function pmprorh_checkFieldForLevel($field, $scope = "default", $args = NULL)
{
    if (!empty($field->levels)) {
        if ($scope == "profile") {
            //expecting the args to be the user id
            if (pmpro_hasMembershipLevel($field->levels, $args)) {
                return true;
            } else {
                return false;
            }
        } else {
            //check against $_REQUEST
            global $pmpro_level;
            if (!empty($pmpro_level) && !empty($pmpro_level->id)) {
                if (is_array($field->levels) && in_array($pmpro_level->id, $field->levels)) {
                    return true;
                } elseif (!is_array($field->levels) && $pmpro_level->id == intval($field->levels)) {
                    return true;
                } else {
                    return false;
                }
            } else {
                return false;
            }
        }
    }
    return true;
}
function bundlesandbonuses_videos_func($atts)
{
    //-> ONLY premium.
    if (pmpro_hasMembershipLevel(array(6, 7, 12, 14))) {
        global $wpdb, $pmpro_msg, $pmpro_msgt, $pmpro_levels, $current_user, $levels;
        $type = 'video';
        $max_count = 0;
        /*
         +===================================+
         | BEGIN 'Mandarin'                  |
         +===================================+
        */
        $bundlesandbonuses = array();
        $empty_bundlesandbonuses = true;
        $args = array('post_type' => array($type), 'post_status' => 'publish', 'posts_per_page' => '-1', 'caller_get_posts' => 1, 'tax_query' => array(array('taxonomy' => 'categories', 'field' => 'id', 'terms' => 20)));
        $bundlesandbonuses_query = null;
        $bundlesandbonuses_query = new WP_Query($args);
        if ($bundlesandbonuses_query->have_posts()) {
            while ($bundlesandbonuses_query->have_posts()) {
                $bundlesandbonuses_query->the_post();
                $thumbnail = "";
                $video_custom_thumbnail = get_field('video_custom_thumbnail', $post_id = $post->ID);
                if (!empty($video_custom_thumbnail)) {
                    $video_thumbnail_url = $video_custom_thumbnail;
                } else {
                    $video_thumbnail_url = get_field('video_thumbnail', $post_id = $post->ID);
                }
                if (!empty($video_thumbnail_url)) {
                    $thumbnail = '<img src="' . $video_thumbnail_url . '" alt="" class="img-responsive">';
                }
                $col = '<div class="col-lg-3 col-md-3 col-sm-6 col-xs-12">' . '<a class="dashboard-stat bundlesandbonuses dashboard-stat-light blue-soft" href="' . get_the_permalink($post_id = $post->ID) . '">' . '<div class="visual">' . '<div class="overlay"></div>' . $thumbnail . '</div>' . '<div class="details">' . '<div class="number">' . the_title($before = '', $after = '', $echo = false) . '</div>' . '</div>' . '<span class="caption-helper">' . '<ul class="post-meta clr">' . '<li class="meta-date">' . 'Posted on <span class="meta-date-text">' . get_the_date() . '</span>' . '</li>' . '</ul><!-- .post-meta -->' . '</span>' . '</a>' . '</div>';
                $return_membership_levels = pmpro_has_membership_access($post_id = $post->ID, $user_id = $current_user->ID, $return_membership_levels = true);
                if (empty($return_membership_levels[2]) && $return_membership_levels[0]) {
                    $hasaccess = FALSE;
                } else {
                    $hasaccess = $return_membership_levels[0];
                }
                if ($hasaccess) {
                    $bundlesandbonuses[] = $col;
                }
            }
        }
        $tmp = count($bundlesandbonuses);
        if ($tmp > $max_count) {
            $max_count = $tmp;
        }
        wp_reset_query();
        ?>
        <!-- BEGIN VIDEOS MENU-->
        <div class="row top-category">
            <div class="col-lg-12 col-md-12 col-sm-12 col-xs-12">
                <div class="easy-pie-chart">
                    <div class="number transactions" data-percent="55">
                        <img src="<?php 
        echo get_template_directory_uri();
        ?>
/assets/global/img/AR_bundles_icon.png" alt="" class=""/>
                    </div>
                    <a class="title" href="#">
                        Bundles & Bonuses
                    </a>
                </div>
            </div>
        </div>
        <div class="clearfix">
        </div>
        <div class="dashboard-page-bar" >
            <div class="line-full-width" ></div>

            <div class="line-container-left" >
                <div class="line" >
                    <div class="arrow-down" >
                    </div>
                </div>
            </div>

            <div class="middle-container-left" >
                <div class="line-middle" >
                    <div class="line" >
                        <div class="arrow-down" >
                        </div>
                    </div>
                </div>
            </div>          
            <div class="middle-container-right" >
                <div class="line-middle-right" >
                    <div class="line" >
                        <div class="arrow-down" >
                        </div>
                    </div>
                </div>
            </div>
            <div class="line-container-right" >
                <div class="line" >
                    <div class="arrow-down" >
                    </div>   
                </div>
            </div>
        </div>
        <div class="clearfix">
        </div>
        <!-- END VIDEOS MENU-->
        <!-- BEGIN VIDEO LIST-->
        <div class="row init-row">
            <?php 
        if ($max_count > 0) {
            ?>
                <?php 
            $row = 1;
            ?>
                <?php 
            for ($i = 0; $i <= $max_count; $i++) {
                ?>
                    <?php 
                if (isset($bundlesandbonuses[$i])) {
                    if ($row == 1) {
                        echo '<div class="row">';
                    }
                    echo $bundlesandbonuses[$i];
                    if ($row >= 4 || $i == $max_count) {
                        echo '</div>';
                        $row = 0;
                    }
                    $row = $row + 1;
                }
                ?>
                <?php 
            }
            ?>
 
            <?php 
        } else {
            ?>
                <div class="col-lg-12 col-md-12 col-sm-6 col-xs-12">
                    <a class="dashboard-stat bundlesandbonuses dashboard-stat-light blue-soft" href="javascript:void(0);">
                        <p> 
                            There are no videos yet for this Subscription plan on this category. <span class="meta-date-text">Check back soon!</span> 
                        </p>
                    </a>
                </div>
            <?php 
        }
        ?>
        </div>
    <?php 
    } else {
        ?>
        <br>
        <div class="row top-category no-allow">
            <div class="col-lg-12 col-md-12 col-sm-6 col-xs-12">
                <p> 
                    This content is for <span class="meta-date-text">Premium</span> members only. Visit the site and log in/register.
                </p>
            </div>
        </div>
    <?php 
    }
    ?>
    <div class="clearfix">
    </div>
    <div class="row">
        <div class="col-lg-12 col-md-12 col-sm-12 col-xs-12">
            <p class="notice">
                <?php 
    wpex_copyright_dashboard();
    ?>
            </p>
        </div>
    </div>
    <!-- END VIDEOS LIST-->
    <?php 
}
Example #29
0
function pmpro_set_current_user()
{
    //this code runs at the beginning of the plugin
    global $current_user, $wpdb;
    get_currentuserinfo();
    $id = intval($current_user->ID);
    if ($id) {
        $current_user->membership_level = pmpro_getMembershipLevelForUser($current_user->ID);
        if (!empty($current_user->membership_level)) {
            $current_user->membership_level->categories = pmpro_getMembershipCategories($current_user->membership_level->ID);
        }
        $current_user->membership_levels = pmpro_getMembershipLevelsForUser($current_user->ID);
    }
    //hiding ads?
    $hideads = pmpro_getOption("hideads");
    $hideadslevels = pmpro_getOption("hideadslevels");
    if (!is_array($hideadslevels)) {
        $hideadslevels = explode(",", $hideadslevels);
    }
    if ($hideads == 1 && pmpro_hasMembershipLevel() || $hideads == 2 && pmpro_hasMembershipLevel($hideadslevels)) {
        //disable ads in ezAdsense
        if (class_exists("ezAdSense")) {
            global $ezCount, $urCount;
            $ezCount = 100;
            $urCount = 100;
        }
        //disable ads in Easy Adsense (newer versions)
        if (class_exists("EzAdSense")) {
            global $ezAdSense;
            $ezAdSense->ezCount = 100;
            $ezAdSense->urCount = 100;
        }
        //set a global variable to hide ads
        global $pmpro_display_ads;
        $pmpro_display_ads = false;
    } else {
        global $pmpro_display_ads;
        $pmpro_display_ads = true;
    }
    do_action("pmpro_after_set_current_user");
}
Example #30
0
function sp_edit_class_preheader()
{
    if (!is_admin()) {
        global $post, $current_user;
        if (!empty($post->post_content) && strpos($post->post_content, "[sp_edit_class]") !== false) {
            /*
            	Preheader operations here.
            */
            //make sure user is logged in and a Teacher
            if (!pmpro_hasMembershipLevel(array(2, 3))) {
                wp_redirect('http://schoolpress.me/membership/');
                exit;
            }
            //adding a class?
            if (!empty($_POST['edit'])) {
                $edit = intval($_POST['edit']);
                //get values
                $class_name = $_REQUEST['class_name'];
                $class_description = $_REQUEST['class_description'];
                $class_department = $_REQUEST['class_department'];
                $class_semester = $_REQUEST['class_semester'];
                if (!empty($_REQUEST['class_enrollment'])) {
                    $class_enrollment = $_REQUEST['class_enrollment'];
                } else {
                    $class_enrollment = "";
                }
                //check values
                if (empty($class_name) || empty($class_description) || empty($class_department) || empty($class_semester)) {
                    sp_setMessage("Please complete all fields.", "error");
                } else {
                    //adding or updating?
                    if ($edit == -1) {
                        //woah, let's make sure they are a teacher
                        if (!pmpro_hasMembershipLevel(array(2, 3))) {
                            die("You do not have permission to do this.");
                        }
                        //add class
                        $class = new SPCLass(array('name' => $class_name, 'description' => $class_description, 'department' => $class_department, 'semester' => $class_semester, 'enrollment' => $class_enrollment));
                        if (!empty($class)) {
                            //redirect to the class page
                            wp_redirect(get_permalink($class->id));
                            exit;
                        } else {
                            sp_setMessage("Error adding class.", "error");
                        }
                    } else {
                        //update class
                        $class = new SPClass($edit);
                        //let's make sure they can edit this class
                        if (!$class->isTeacher() && !current_user_can("manage_options")) {
                            die("You do not have permission to do this.");
                        }
                        //okay update
                        if (!empty($class) && $class->editClass($class_name, $class_description, $class_department, $class_semester, $class_enrollment)) {
                            sp_setMessage("Class updated successfully.", "success");
                        } else {
                            sp_setMessage("Error updating class.", "error");
                        }
                    }
                }
            }
            //deleting a class?
            if (!empty($_REQUEST['delete'])) {
                $class_id = intval($_REQUEST['delete']);
                $class = new SPClass($class_id);
                //only teachers and admins can delete classes
                if ($class->isTeacher() || current_user_can("manage_options")) {
                    $r = wp_delete_post($class->post->ID);
                    wp_redirect(home_url("/my-classes/"));
                    exit;
                }
            }
        }
    }
}