/** * AccessPress Template Tags for displaying front-end content * * @package AccessPress */ function accesspress_checkout_form($args = array()) { global $product_member; $checkout_args = isset($_POST['accesspress-checkout']) ? $_POST['accesspress-checkout'] : $args; $checkout_args = apply_filters('premise_checkout_args', $checkout_args); $form_submitted = apply_filters('premise_checkout_form_submitted', isset($_POST['accesspress-checkout']) || isset($_REQUEST['action']), $args); /** If form submitted */ if ($form_submitted) { $checkout_complete = accesspress_checkout($checkout_args); /** If there was an error in the submission show the error to the user */ if (is_wp_error($checkout_complete)) { printf('<div class="acp-error">%s</div>', $checkout_complete->get_error_message()); } else { /** Show the comlpete message when the transaction is complete */ if ($checkout_complete) { do_action('premise_checkout_complete_before', $checkout_args, $checkout_args['product_id'], $args); if (!empty($checkout_complete['member_id'])) { $product_member = new WP_User($checkout_complete['member_id']); } $receipt_body = get_post_meta($checkout_args['product_id'], '_acp_product_email_receipt_intro', true); if (!empty($receipt_body)) { echo do_shortcode(str_replace("\n", '<br />', $receipt_body)); } do_action('premise_checkout_complete_after', $checkout_args, $checkout_args['product_id'], $args); } /** don't show the checkout form */ return; } } /** don't show the checkout form unless there is a product or checkout is in progress */ $product_id = isset($_GET['product_id']) ? $_GET['product_id'] : ''; if (!$form_submitted && !memberaccess_is_valid_product($product_id)) { return; } $checkout_button = '<input type="submit" value="%s" class="input-submit" />'; if (is_user_logged_in()) { $products = memberaccess_get_member_products(get_current_user_id(), true); if (in_array($product_id, $products)) { echo '<h3>' . __('You have already purchased this product', 'premise') . '</h3>'; $checkout_button = ''; } } do_action('premise_checkout_form_before', $checkout_args, $product_id, $args); echo '<div class="premise-checkout-wrap"><form method="post" action="">'; printf('<input type="hidden" name="accesspress-checkout[product_id]" id="accesspress-checkout-product-id" value="%s" />', $product_id); if (isset($_GET['renew']) && 'true' == $_GET['renew']) { echo '<input type="hidden" name="accesspress-checkout[renew]" value="true" />'; } do_action('premise_checkout_form', $checkout_args, $product_id, $args); $checkout_text = trim(is_user_logged_in() ? $args['member_text'] : $args['nonmember_text']); if (empty($checkout_text)) { $checkout_text = apply_filters('premise_checkout_button_text', is_user_logged_in() ? __('Submit Order', 'premise') : __('Submit Order and Create My Account', 'premise'), is_user_logged_in()); } printf($checkout_button, $checkout_text); echo '</form></div>'; do_action('premise_checkout_form_after', $checkout_args, $product_id, $args); }
/** * Determines if a user has a certain active access level. * * Checks the user meta to see if the user has a particular access * level, and if it is still active. * * @since 0.1.0 * * @param string $access_level. * @param string $user_id, optional. * @return boolean */ function member_has_access_level($access_level = '', $user_id = '', $delay = 0) { /** Check to see if $user_id is provided. If not, assume current logged in user */ $user_id = $user_id ? (int) $user_id : get_current_user_id(); if (user_can($user_id, 'manage_options')) { return true; } /** If user is not an AccessPress member, return false */ if (!user_can($user_id, 'access_membership')) { return false; } /** If no active subscriptions, return false */ $active_subscriptions = memberaccess_get_member_products($user_id, $delay); if (!$active_subscriptions) { return false; } /** Cycle through active subscriptions, look for one that has the proper access level, return true as soon as we find one. */ foreach ((array) $access_level as $level) { $level = sanitize_title_with_dashes($level); foreach ($active_subscriptions as $product) { if (has_term($level, 'acp-access-level', $product)) { return true; } } } /** Else, return false */ return false; }