/** * Filter Jobify widget output depending on RCP subscription level. * * @since Jobify 1.6.0 * * @return $widget */ function widget_visibility($widget, $instance, $args) { extract($args); if (!isset($instance['subscription'])) { return $widget; } $sub_level = maybe_unserialize($instance['subscription']); if (!is_array($sub_level)) { $sub_level = array(); } if (!in_array(rcp_get_subscription_id(get_current_user_id()), $sub_level) && !empty($sub_level)) { $widget = $before_widget . $this->subscription_teaser() . $after_widget; } return $widget; }
/** * This will hide subscription levels on the registration form page * if their price is lower than the price of member's current * subscription level. */ function jp_hide_lower_cost_levels($levels) { if (!rcp_is_registration_page() || !is_user_logged_in()) { return $levels; } $existing_sub = rcp_get_subscription_id(wp_get_current_user()->ID); if (empty($existing_sub)) { return $levels; } foreach ($levels as $key => $level) { if (rcp_get_subscription_price($level->id) < rcp_get_subscription_price($existing_sub)) { unset($levels[$key]); } } return $levels; }
/** * Filter restricted content based on category restrictions * * @access public * @since 2.0 * @return $content */ function rcp_filter_restricted_category_content($content) { global $post, $user_ID, $rcp_options; $has_access = true; $categories = get_the_category($post->ID); if (empty($categories)) { return $content; } // Loop through the categories and determine if one has restriction options foreach ($categories as $category) { $term_meta = get_option("rcp_category_meta_{$category->term_id}"); if (!empty($term_meta)) { /** * Check that the user has a paid subscription */ $paid_only = !empty($term_meta['paid_only']); if ($paid_only && !rcp_is_paid_user()) { $has_access = false; } /** * If restricted to one or more subscription levels, make sure that the user is a member of one of the levls */ $subscriptions = !empty($term_meta['subscriptions']) ? array_map('absint', $term_meta['subscriptions']) : false; if ($subscriptions && !in_array(rcp_get_subscription_id(), $subscriptions)) { $has_access = false; } /** * If restricted to one or more access levels, make sure that the user is a member of one of the levls */ $access_level = !empty($term_meta['access_level']) ? absint($term_meta['access_level']) : 0; if ($access_level > 0 && !rcp_user_has_access($user_ID, $access_level)) { $has_access = false; } } } if (!$has_access) { $message = !empty($rcp_options['paid_message']) ? $rcp_options['paid_message'] : __('You need to have an active subscription to view this content.', 'rcp'); return rcp_format_teaser($message); } return $content; }
function rcp_user_has_access( $user_id = 0, $access_level_needed ) { $subscription_level = rcp_get_subscription_id( $user_id ); $user_access_level = rcp_get_subscription_access_level( $subscription_level ); if( ( $user_access_level >= $access_level_needed ) || $access_level_needed == 0 || current_user_can( 'manage_options' ) ) { // the user has access return true; } // the user does not have access return false; }
function rcp_process_data() { if (!is_admin()) { return; } if (!empty($_POST)) { /**************************************** * subscription levels ****************************************/ // add a new subscription level if (isset($_POST['rcp-action']) && $_POST['rcp-action'] == 'add-level') { if (!current_user_can('rcp_manage_levels')) { wp_die(__('You do not have permission to perform this action.', 'rcp')); } $levels = new RCP_Levels(); $add = $levels->insert($_POST); if ($add) { $url = get_bloginfo('wpurl') . '/wp-admin/admin.php?page=rcp-member-levels&rcp_message=level_added'; } else { $url = get_bloginfo('wpurl') . '/wp-admin/admin.php?page=rcp-member-levels&rcp_message=level_not_added'; } wp_safe_redirect($url); exit; } // edit a subscription level if (isset($_POST['rcp-action']) && $_POST['rcp-action'] == 'edit-subscription') { if (!current_user_can('rcp_manage_levels')) { wp_die(__('You do not have permission to perform this action.', 'rcp')); } $levels = new RCP_Levels(); $update = $levels->update($_POST['subscription_id'], $_POST); if ($update) { // clear the cache $url = get_bloginfo('wpurl') . '/wp-admin/admin.php?page=rcp-member-levels&rcp_message=level_updated'; } else { $url = get_bloginfo('wpurl') . '/wp-admin/admin.php?page=rcp-member-levels&rcp_message=level_not_updated'; } wp_safe_redirect($url); exit; } // add a subscription for an existing member if (isset($_POST['rcp-action']) && $_POST['rcp-action'] == 'add-subscription') { if (!current_user_can('rcp_manage_members')) { wp_die(__('You do not have permission to perform this action.', 'rcp')); } if (isset($_POST['expiration']) && strtotime('NOW') > strtotime($_POST['expiration']) && 'none' !== $_POST['expiration']) { $url = get_bloginfo('wpurl') . '/wp-admin/admin.php?page=rcp-members&rcp_message=user_not_added'; header("Location:" . $url); } else { $levels = new RCP_Levels(); $user = get_user_by('login', $_POST['user']); $expiration = isset($_POST['expiration']) ? sanitize_text_field($_POST['expiration']) : 'none'; $level_id = absint($_POST['level']); rcp_set_expiration_date($user->ID, $expiration); rcp_set_status($user->ID, 'active'); update_user_meta($user->ID, 'rcp_signup_method', 'manual'); // Add a role, if needed, to the user $subscription = $levels->get_level($level_id); update_user_meta($user->ID, 'rcp_subscription_level', $level_id); // Add the new user role $role = !empty($subscription->role) ? $subscription->role : 'subscriber'; $user->add_role($role); if (isset($_POST['recurring'])) { update_user_meta($user->ID, 'rcp_recurring', 'yes'); } else { delete_user_meta($user->ID, 'rcp_recurring'); } $url = get_bloginfo('wpurl') . '/wp-admin/admin.php?page=rcp-members&rcp_message=user_added'; header("Location:" . $url); } } // bulk edit members if (isset($_POST['rcp-bulk-action']) && $_POST['rcp-bulk-action']) { if (!wp_verify_nonce($_POST['rcp_bulk_edit_nonce'], 'rcp_bulk_edit_nonce')) { wp_die(__('Nonce verification failed.', 'rcp')); } if (!current_user_can('rcp_manage_members')) { wp_die(__('You do not have permission to perform this action.', 'rcp')); } if (empty($_POST['member-ids'])) { wp_die(__('Please select at least one member to edit.', 'rcp')); } $member_ids = array_map('absint', $_POST['member-ids']); $action = !empty($_POST['rcp-bulk-action']) ? sanitize_text_field($_POST['rcp-bulk-action']) : false; foreach ($member_ids as $member_id) { $member = new RCP_Member($member_id); if (!empty($_POST['expiration']) && 'delete' !== $action) { $member->set_expiration_date(date('Y-m-d H:i:s', strtotime($_POST['expiration']))); } if ($action) { switch ($action) { case 'mark-active': $member->set_status('active'); break; case 'mark-expired': $member->set_status('expired'); break; case 'mark-cancelled': $member->set_status('cancelled'); break; case 'delete': wp_delete_user($member->ID); break; } } } wp_redirect(admin_url('admin.php?page=rcp-members&rcp_message=members_updated')); exit; } // edit a member's subscription if (isset($_POST['rcp-action']) && $_POST['rcp-action'] == 'edit-member') { if (!current_user_can('rcp_manage_members')) { wp_die(__('You do not have permission to perform this action.', 'rcp')); } $levels = new RCP_Levels(); $user_id = absint($_POST['user']); $member = new RCP_Member($user_id); $status = sanitize_text_field($_POST['status']); $level_id = absint($_POST['level']); $expiration = isset($_POST['expiration']) ? sanitize_text_field($_POST['expiration']) : 'none'; $expiration = 'none' !== $expiration ? date('Y-m-d 23:59:59', strtotime($_POST['expiration'])) : $expiration; if (!empty($_POST['expiration'])) { $member->set_expiration_date($expiration); } if (isset($_POST['level'])) { $current_id = rcp_get_subscription_id($user_id); $new_level = $levels->get_level($level_id); $old_level = $levels->get_level($current_id); if ($current_id != $level_id) { update_user_meta($user_id, 'rcp_subscription_level', $level_id); // Remove the old user role $role = !empty($old_level->role) ? $old_level->role : 'subscriber'; $member->remove_role($role); // Add the new user role $role = !empty($new_level->role) ? $new_level->role : 'subscriber'; $member->add_role($role); } } if (isset($_POST['recurring'])) { $member->set_recurring(true); } else { $member->set_recurring(false); } if (isset($_POST['trialing'])) { update_user_meta($user_id, 'rcp_is_trialing', 'yes'); } else { delete_user_meta($user_id, 'rcp_is_trialing'); } if (isset($_POST['signup_method'])) { update_user_meta($user_id, 'rcp_signup_method', $_POST['signup_method']); } if (isset($_POST['notes'])) { update_user_meta($user_id, 'rcp_notes', wp_kses($_POST['notes'], array())); } if (isset($_POST['status'])) { rcp_set_status($user_id, $status); } if (isset($_POST['payment-profile-id'])) { $member->set_payment_profile_id($_POST['payment-profile-id']); } do_action('rcp_edit_member', $user_id); wp_redirect(admin_url('admin.php?page=rcp-members&edit_member=' . $user_id . '&rcp_message=user_updated')); exit; } /**************************************** * discount codes ****************************************/ // add a new discount code if (isset($_POST['rcp-action']) && $_POST['rcp-action'] == 'add-discount') { if (!current_user_can('rcp_manage_discounts')) { wp_die(__('You do not have permission to perform this action.', 'rcp')); } $discounts = new RCP_Discounts(); // Setup unsanitized data $data = array('name' => $_POST['name'], 'description' => $_POST['description'], 'amount' => $_POST['amount'], 'unit' => isset($_POST['unit']) && $_POST['unit'] == '%' ? '%' : 'flat', 'code' => $_POST['code'], 'status' => 'active', 'expiration' => $_POST['expiration'], 'max_uses' => $_POST['max'], 'subscription_id' => $_POST['subscription']); $add = $discounts->insert($data); if ($add) { $url = get_bloginfo('wpurl') . '/wp-admin/admin.php?page=rcp-discounts&rcp_message=discount_added'; } else { $url = get_bloginfo('wpurl') . '/wp-admin/admin.php?page=rcp-discounts&rcp_message=discount_not_added'; } wp_safe_redirect($url); exit; } // edit a discount code if (isset($_POST['rcp-action']) && $_POST['rcp-action'] == 'edit-discount') { if (!current_user_can('rcp_manage_discounts')) { wp_die(__('You do not have permission to perform this action.', 'rcp')); } $discounts = new RCP_Discounts(); // Setup unsanitized data $data = array('name' => $_POST['name'], 'description' => $_POST['description'], 'amount' => $_POST['amount'], 'unit' => isset($_POST['unit']) && $_POST['unit'] == '%' ? '%' : 'flat', 'code' => $_POST['code'], 'status' => $_POST['status'], 'expiration' => $_POST['expiration'], 'max_uses' => $_POST['max'], 'subscription_id' => $_POST['subscription']); $update = $discounts->update($_POST['discount_id'], $data); if ($update) { $url = get_bloginfo('wpurl') . '/wp-admin/admin.php?page=rcp-discounts&discount-updated=1'; } else { $url = get_bloginfo('wpurl') . '/wp-admin/admin.php?page=rcp-discounts&discount-updated=0'; } wp_safe_redirect($url); exit; } // add a new manual payment if (isset($_POST['rcp-action']) && $_POST['rcp-action'] == 'add-payment') { if (!current_user_can('rcp_manage_payments')) { wp_die(__('You do not have permission to perform this action.', 'rcp')); } $payments = new RCP_Payments(); $user = get_user_by('login', $_POST['user']); if ($user) { $data = array('amount' => empty($_POST['amount']) ? 0.0 : sanitize_text_field($_POST['amount']), 'user_id' => $user->ID, 'date' => empty($_POST['date']) ? date('Y-m-d H:i:s', current_time('timestamp')) : date('Y-m-d', strtotime($_POST['date'], current_time('timestamp'))) . ' ' . date('H:i:s', current_time('timestamp')), 'payment_type' => 'manual', 'subscription' => rcp_get_subscription($user->ID), 'subscription_key' => rcp_get_subscription_key($user->ID), 'transaction_id' => sanitize_text_field($_POST['transaction-id']), 'status' => sanitize_text_field($_POST['status'])); $add = $payments->insert($data); } if (!empty($add)) { $cache_args = array('earnings' => 1, 'subscription' => 0, 'user_id' => 0, 'date' => ''); $cache_key = md5(implode(',', $cache_args)); delete_transient($cache_key); $url = admin_url('admin.php?page=rcp-payments&rcp_message=payment_added'); } else { $url = admin_url('admin.php?page=rcp-payments&rcp_message=payment_not_added'); } wp_safe_redirect($url); exit; } // edit a payment if (isset($_POST['rcp-action']) && $_POST['rcp-action'] == 'edit-payment') { if (!current_user_can('rcp_manage_payments')) { wp_die(__('You do not have permission to perform this action.', 'rcp')); } $payments = new RCP_Payments(); $payment_id = absint($_POST['payment-id']); $user = get_user_by('login', $_POST['user']); if ($user && $payment_id) { $data = array('amount' => empty($_POST['amount']) ? 0.0 : sanitize_text_field($_POST['amount']), 'user_id' => $user->ID, 'date' => empty($_POST['date']) ? date('Y-m-d H:i:s', current_time('timestamp')) : date('Y-m-d', strtotime($_POST['date'], current_time('timestamp'))) . ' ' . date('H:i:s', current_time('timestamp')), 'subscription' => rcp_get_subscription($user->ID), 'subscription_key' => rcp_get_subscription_key($user->ID), 'transaction_id' => sanitize_text_field($_POST['transaction-id']), 'status' => sanitize_text_field($_POST['status'])); $update = $payments->update($payment_id, $data); } if (!empty($update)) { $cache_args = array('earnings' => 1, 'subscription' => 0, 'user_id' => 0, 'date' => ''); $cache_key = md5(implode(',', $cache_args)); delete_transient($cache_key); $url = admin_url('admin.php?page=rcp-payments&rcp_message=payment_updated'); } else { $url = admin_url('admin.php?page=rcp-payments&rcp_message=payment_not_updated'); } wp_safe_redirect($url); exit; } } /************************************* * delete data *************************************/ if (!empty($_GET)) { /* member processing */ if (isset($_GET['revoke_access'])) { if (!current_user_can('rcp_manage_members')) { wp_die(__('You do not have permission to perform this action.', 'rcp')); } rcp_set_status(urldecode(absint($_GET['revoke_access'])), 'cancelled'); } if (isset($_GET['activate_member'])) { if (!current_user_can('rcp_manage_members')) { wp_die(__('You do not have permission to perform this action.', 'rcp')); } rcp_set_status(urldecode(absint($_GET['activate_member'])), 'active'); } if (isset($_GET['cancel_member'])) { if (!current_user_can('rcp_manage_members')) { wp_die(__('You do not have permission to perform this action.', 'rcp')); } rcp_cancel_member_payment_profile(urldecode(absint($_GET['cancel_member']))); wp_safe_redirect(admin_url(add_query_arg('rcp_message', 'member_cancelled', 'admin.php?page=rcp-members'))); exit; } /* subscription processing */ if (isset($_GET['delete_subscription']) && $_GET['delete_subscription'] > 0) { if (!current_user_can('rcp_manage_levels')) { wp_die(__('You do not have permission to perform this action.', 'rcp')); } $members_of_subscription = rcp_get_members_of_subscription(absint($_GET['delete_subscription'])); // cancel all active members of this subscription if ($members_of_subscription) { foreach ($members_of_subscription as $member) { rcp_set_status($member, 'cancelled'); } } $levels = new RCP_Levels(); $levels->remove($_GET['delete_subscription']); } if (isset($_GET['activate_subscription']) && $_GET['activate_subscription'] > 0) { if (!current_user_can('rcp_manage_levels')) { wp_die(__('You do not have permission to perform this action.', 'rcp')); } $levels = new RCP_Levels(); $update = $levels->update(absint($_GET['activate_subscription']), array('status' => 'active')); delete_transient('rcp_subscription_levels'); } if (isset($_GET['deactivate_subscription']) && $_GET['deactivate_subscription'] > 0) { if (!current_user_can('rcp_manage_levels')) { wp_die(__('You do not have permission to perform this action.', 'rcp')); } $levels = new RCP_Levels(); $update = $levels->update(absint($_GET['deactivate_subscription']), array('status' => 'inactive')); delete_transient('rcp_subscription_levels'); } /* discount processing */ if (!empty($_GET['delete_discount'])) { if (!current_user_can('rcp_manage_discounts')) { wp_die(__('You do not have permission to perform this action.', 'rcp')); } $discounts = new RCP_Discounts(); $discounts->delete($_GET['delete_discount']); } if (!empty($_GET['activate_discount'])) { if (!current_user_can('rcp_manage_discounts')) { wp_die(__('You do not have permission to perform this action.', 'rcp')); } $discounts = new RCP_Discounts(); $discounts->update($_GET['activate_discount'], array('status' => 'active')); } if (!empty($_GET['deactivate_discount'])) { if (!current_user_can('rcp_manage_discounts')) { wp_die(__('You do not have permission to perform this action.', 'rcp')); } $discounts = new RCP_Discounts(); $discounts->update($_GET['deactivate_discount'], array('status' => 'disabled')); } if (!empty($_GET['rcp-action']) && $_GET['rcp-action'] == 'delete_payment' && wp_verify_nonce($_GET['_wpnonce'], 'rcp_delete_payment_nonce')) { if (!current_user_can('rcp_manage_payments')) { wp_die(__('You do not have permission to perform this action.', 'rcp')); } $payments = new RCP_Payments(); $payments->delete(absint($_GET['payment_id'])); wp_safe_redirect(admin_url(add_query_arg('rcp_message', 'payment_deleted', 'admin.php?page=rcp-payments'))); exit; } } }
/** * Get subscriptions to which this user can upgrade * * @since 2.5 * @param int $user_id the ID of the user to check * * @return mixed|void */ function rcp_get_upgrade_paths($user_id = 0) { if (empty($user_id)) { $user_id = get_current_user_id(); } // make sure the user is active and get the subscription ID $user_subscription = rcp_is_recurring($user_id) && rcp_is_active($user_id) && 'cancelled' !== rcp_get_status() ? rcp_get_subscription_id($user_id) : ''; $subscriptions = rcp_get_subscription_levels('active'); // remove the user's current subscription from the list foreach ($subscriptions as $key => $subscription) { if ($user_subscription == $subscription->id) { unset($subscriptions[$key]); } } return apply_filters('rcp_get_upgrade_paths', array_values($subscriptions), $user_id); }
function edd_search() { if (isset($_GET['key'])) { $_POST['key'] = $_GET['key']; $_POST['parent'] = array('all'); } ?> <style type="text/css"> .search_for_{ width:100%; min-height:500px; height:auto; } .search_option_{ width:100%; height:auto; } .option_,.last_option_,.option_ li,.last_option_ li{ width:auto; height:auto; float:left; list-style:none; } .option_ li{ padding-right:10px; } .option_,.last_option_{ width:100%; padding:0px!important; margin:0px!important; } .option_ li.title,.last_option_ li.title{ width:100%; } .last_option_{ } .last_option_ li{ width:30%!important; } [data-group="sub"]{ display:none; } .entry-content > *:not(.edd_downloads_list) .edd_purchase_submit_wrapper, .popup .edd_purchase_submit_wrapper, .entry-content > *:not(.edd_downloads_list) .edd_download_purchase_form:last-of-type{ margin-top:0px!important; } div.content-grid-download div.entry-image div.actions{ overflow:visible; } </style> <div class="search_for_"> <form method="post" action="<?php echo get_the_permalink(get_page_by_path('search')); ?> "> <div class="searchcontainer"> <div class="searchfieldholder"> <div class="searchfield"> <span class="screen-reader-text">Search for:</span> <input type="search" class="sitesearchfield" placeholder="Search..." value="<?php echo isset($_POST['key']) ? $_POST['key'] : ''; ?> " name="key" title="Search for:"> <div class="clear"></div> </div> <button type="submit" class="sitesearchbttn"> <i class="fa fa-search"></i> </button> <div class="clear"></div> </div> <div class="clear"></div> </div> <div class="search_option_"> <ul class="option_"> <li class='title'> <h1 class="home-widget-title" style="text-transform:none;"> What are looking for? </h1> </li> <li><label><input type="checkbox" name="parent[]" data-all="all" value="all" <?php echo check_if_posted('all'); ?> <?php echo !isset($_POST) ? "checked" : ''; ?> /> Match any</label></li> <?php $finished_items = array(); $data = get_categories_structure(); foreach ($data['finished'] as $key => $options_) { $finished_items[] = $key; ?> <li><label><input type="checkbox" name="parent[]" <?php echo check_if_posted($key); ?> value="<?php echo $key; ?> " data-type="<?php echo $key; ?> " /> <?php echo ucfirst($options_['key']); ?> </label></li> <?php } if (rcp_get_subscription_id(get_current_user_id()) == 1) { ?> <li><label><input type="checkbox" name="parent[]" <?php echo check_if_posted('67'); ?> value="67" data-type="67" /> Compose</label></li> <li><label><input type="checkbox" name="parent[]" <?php echo check_if_posted('4'); ?> value="4" data-type="4" /> Unfinished design</label></li> <li><label><input type="checkbox" name="parent[]" <?php echo check_if_posted('80'); ?> value="80" data-type="80" /> Write</label></li> <?php } ?> </ul> <?php $op_ = ''; if (check_if_posted('all', 'parent', false) == true) { $op_ = 'display:none;text-transform:none;'; } else { $op_ = 'display:block;text-transform:none;'; } ?> <h1 data-group="sub" class="home-widget-title" style="<?php echo $op_; ?> "> Do you want more filter options? </h1> <?php $all_rerms = array(); $stc = get_categories_structure(); foreach ($stc as $key => $val) { foreach ($val as $key_ => $val_) { $_terms = get_term_children($key_, 'download_category'); //print_r($_terms);die; foreach ($_terms as $key__ => $val__) { $term = get_term_by("id", $val__, 'download_category'); $childs__ = get_term_children($val__, "download_category"); if (strtolower(trim($term->name)) != 'other') { $all_rerms[$key_][$val__] = array("term_id" => $val__, "name" => str_replace("'", "", $term->name)); } if (is_array($childs__) && sizeof($childs__)) { foreach ($childs___ as $key___ => $val___) { $details____ = get_term_by('id', $val___, 'download_category'); if (strtolower(trim($details____->name)) != 'other') { $all_rerms[$key_][$key__]["children"][$key___] = array("term_id" => $key___, "name" => str_replace("'", "", $details____->name)); } } } } } } ?> <ul class="last_option_" data-group="sub" style="<?php echo $op_; ?> "> <?php foreach ($all_rerms as $key => $_last) { foreach ($_last as $__last) { ?> <li <?php echo check_if_posted($key) ? 'style="display:block;"' : 'style="display:none;"'; ?> ><label><input name="sub[]" <?php echo check_if_posted($__last['term_id'], 'sub'); ?> value="<?php echo $__last['term_id']; ?> " data-parent-id="<?php echo $key; ?> " data-id="<?php echo $__last['name']; ?> " <?php echo check_if_posted($__last['term_id'], 'sub'); ?> type="checkbox" /> <?php echo $__last['name']; ?> </label></li> <?php } } ?> </ul> </div> </form> <div class="clear"></div> <?php //print_r($_POST); $args = array(); if (isset($_POST['key']) && $_POST['key'] != '') { $args['s'] = $_POST['key']; } if (!check_if_posted('all')) { if (isset($_POST['parent']) && is_array($_POST['parent'])) { if (!isset($_POST['sub']) && !is_array($_POST['sub'])) { $args['tax_query'] = array(array('taxonomy' => 'download_category', 'field' => 'id', 'terms' => $_POST['parent'], 'include_children' => true)); } } //allitems if (isset($_POST['sub']) && is_array($_POST['sub'])) { $args['tax_query']['include_children'] = false; $args['tax_query'] = array(array('taxonomy' => 'download_category', 'field' => 'id', 'terms' => $_POST['sub'], 'include_children' => false)); } } else { if (rcp_get_subscription_id(get_current_user_id()) != 1) { $args['tax_query'] = array(array('taxonomy' => 'download_category', 'field' => 'id', 'terms' => $finished_items, 'include_children' => true)); } } $args['post_type'] = 'download'; $the_query = new WP_Query($args); echo '<div class="row"> <div class="col-lg-12">'; if ($the_query->have_posts()) { ?> <h1 class="home-widget-title">Search Results</h1> <div class="row"> <?php while ($the_query->have_posts()) { $the_query->the_post(); ?> <div class="col-lg-3 col-md-6 col-sm-12"> <?php get_template_part('content-grid', 'download'); ?> <div class="clear"></div> </div> <?php } ?> </div> <?php } else { ?> <h1 class="home-widget-title">Search Results</h1> <p>No products found matching your products.</p> <?php } echo '</div></div>'; wp_reset_postdata(); ?> </div> <script type="text/javascript"> jQuery(document).ready(function(e) { jQuery("[data-all]").click(function(){ if(jQuery(this).is(":checked")){ jQuery('[data-group="sub"]').hide() jQuery("[data-type]").prop('checked',false); } }) jQuery("[data-type]").click(function(){ jQuery("[data-parent-id]").closest('li').hide(); jQuery("[data-parent-id]").prop('checked',false); jQuery("[data-all]").prop('checked',false); jQuery('[data-group="sub"]').show() if(jQuery("[data-type]").is(":checked")){ jQuery.each(jQuery("[data-type]"),function(i,v){ if(jQuery(v).is(":checked")){ jQuery("[data-parent-id='"+jQuery(v).data('type')+"']").prop("checked",false); jQuery("[data-parent-id='"+jQuery(v).data('type')+"']").closest('li').show(); }else{ jQuery("[data-parent-id='"+jQuery(v).data('type')+"']").prop("checked",false); //jQuery("[data-parent-id='"+jQuery(v).data('type')+"']").closest('li').hide(); } }) }else{ jQuery('[data-group="sub"]').hide() jQuery("[data-all]").prop('checked',true); } }) jQuery("[data-all-items]").click(function(){ if(jQuery(this).is(":checked")){ jQuery.each(jQuery("[data-type]"),function(i,v){ if(jQuery(v).is(":checked")){ jQuery('[data-parent-id="'+jQuery(v).data('type')+'"]').prop('checked',true); } }) }else{ jQuery("[data-parent-id]").prop('checked',false); } }) jQuery("[data-parent-id]").click(function(){ if(jQuery("[data-parent-id]").not(":checked")){ jQuery("[data-all-items]").prop('checked',false); } }) }); </script> <?php }
function rcp_restrict_shortcode( $atts, $content = null ) { extract( shortcode_atts( array( 'userlevel' => 'none', 'message' => '', 'paid' => false, 'level' => 0, 'subscription' => '' ), $atts ) ); global $rcp_options, $user_ID; if( strlen( trim( $message ) ) > 0 ) { $teaser = $message; } elseif( $paid ) { $teaser = $rcp_options['paid_message']; } else { $teaser = $rcp_options['free_message']; } $subscription = explode( ',', $subscription ); if( $paid ) { $has_access = false; if( rcp_is_active( $user_ID ) && rcp_user_has_access( $user_ID, $level ) ) { $has_access = true; if( ! empty( $subscription ) && ! empty( $subscription[0] ) ) { if( ! in_array( rcp_get_subscription_id( $user_ID ), $subscription ) ) { $has_access = false; } } } if ( $userlevel == 'admin' && current_user_can( 'switch_themes' ) && $has_access ) { return do_shortcode( wpautop( $content ) ); } if ( $userlevel == 'editor' && current_user_can( 'moderate_comments' ) && $has_access ) { return do_shortcode( wpautop( $content ) ); } if ( $userlevel == 'author' && current_user_can( 'upload_files' ) && $has_access ) { return do_shortcode( wpautop( $content ) ); } if ( $userlevel == 'contributor' && current_user_can( 'edit_posts' ) && $has_access ) { return do_shortcode( wpautop( $content ) ); } if ( $userlevel == 'subscriber' && current_user_can( 'read' ) && $has_access ) { return do_shortcode( wpautop( $content ) ); } if ( $userlevel == 'none' && is_user_logged_in() && $has_access ) { return do_shortcode( wpautop( $content ) ); } else { return '<div class="rcp_restricted rcp_paid_only">' . rcp_format_teaser($teaser) . '</div>'; } } else { $has_access = false; if(rcp_user_has_access($user_ID, $level)) { $has_access = true; if( ! empty( $subscription ) && ! empty( $subscription[0] ) ) { if( in_array( rcp_get_subscription_id( $user_ID ), $subscription ) ) { $has_access = false; } } } if ( $userlevel == 'admin' && current_user_can( 'switch_themes' ) && $has_access ) { return do_shortcode( wpautop( $content ) ); } elseif ( $userlevel == 'editor' && current_user_can( 'moderate_comments' ) && $has_access ) { return do_shortcode( wpautop( $content ) ); } elseif ( $userlevel == 'author' && current_user_can( 'upload_files' ) && $has_access ) { return do_shortcode( wpautop( $content ) ); } elseif ( $userlevel == 'contributor' && current_user_can( 'edit_posts' ) && $has_access ) { return do_shortcode( wpautop( $content ) ); } elseif ( $userlevel == 'subscriber' && current_user_can( 'read' ) && $has_access ) { return do_shortcode( wpautop( $content ) ); } elseif ( $userlevel == 'none' && is_user_logged_in() && $has_access ) { return do_shortcode( wpautop( $content ) ); } else { return '<div class="rcp_restricted">' . do_shortcode( wpautop( $teaser ) ) . '</div>'; } } }
/** * Check the provided taxonomy along with the given post id to see if any restrictions are found * * @since 2.5 * @param $post_id * @param $taxonomy * @param null $user_id * * @return int|bool true if tax is restricted, false if user can access, -1 if unrestricted or invalid */ function rcp_is_post_taxonomy_restricted($post_id, $taxonomy, $user_id = null) { $restricted = -1; if (current_user_can('edit_post', $post_id)) { return $restricted; } // make sure this post supports the supplied taxonomy $post_taxonomies = get_post_taxonomies($post_id); if (!in_array($taxonomy, (array) $post_taxonomies)) { return $restricted; } $terms = get_the_terms($post_id, $taxonomy); if (empty($terms) || is_wp_error($terms)) { return $restricted; } if (!$user_id) { $user_id = get_current_user_id(); } // Loop through the categories and determine if one has restriction options foreach ($terms as $term) { $term_meta = rcp_get_term_restrictions($term->term_id); if (empty($term_meta['paid_only']) && empty($term_meta['subscriptions']) && (empty($term_meta['access_level']) || 'None' == $term_meta['access_level'])) { continue; } $restricted = false; /** Check that the user has a paid subscription ****************************************************************/ $paid_only = !empty($term_meta['paid_only']); if ($paid_only && !rcp_is_paid_user($user_id)) { $restricted = true; } /** If restricted to one or more subscription levels, make sure that the user is a member of one of the levels */ $subscriptions = !empty($term_meta['subscriptions']) ? array_map('absint', $term_meta['subscriptions']) : false; if ($subscriptions && !in_array(rcp_get_subscription_id($user_id), $subscriptions)) { $restricted = true; } /** If restricted to one or more access levels, make sure that the user is a member of one of the levls ********/ $access_level = !empty($term_meta['access_level']) ? absint($term_meta['access_level']) : 0; if ($access_level > 0 && !rcp_user_has_access($user_id, $access_level)) { $restricted = true; } $match_all = apply_filters('rcp_restricted_taxonomy_term_match_all', false, $post_id, $taxonomy, $user_id); // if we are matching all terms then it only takes one restricted term to restrict the taxonomy if ($restricted && $match_all) { break; } // if we are matching any term, then we only need the user to have access to one if (!$match_all && !$restricted) { break; } } return apply_filters('rcp_is_post_taxonomy_restricted', $restricted, $taxonomy, $post_id, $user_id); }
/** * Show User's Subscription ID Shortcode * * @since 2.5 * @access public * * @return string */ function rcp_user_subscription_name_shortcode() { if (!is_user_logged_in()) { return ''; } if (!($id = rcp_get_subscription_id())) { return ''; } return rcp_get_subscription_name($id); }
public function get_checkout_details($token = '') { $args = array('USER' => $this->username, 'PWD' => $this->password, 'SIGNATURE' => $this->signature, 'VERSION' => '121', 'METHOD' => 'GetExpressCheckoutDetails', 'TOKEN' => $token); $request = wp_remote_get(add_query_arg($args, $this->api_endpoint), array('timeout' => 45, 'sslverify' => false)); if (is_wp_error($request)) { return $request; } elseif (200 == $request['response']['code'] && 'OK' == $request['response']['message']) { parse_str($request['body'], $data); $data['subscription'] = (array) rcp_get_subscription_details(rcp_get_subscription_id($_GET['user_id'])); return $data; } return false; }
function rcp_show_subscription_level($level_id = 0, $user_id = 0) { if (empty($user_id)) { $user_id = get_current_user_id(); } $ret = true; $user_level = rcp_get_subscription_id($user_id); $sub_length = rcp_get_subscription_length($level_id); $sub_price = rcp_get_subscription_price($level_id); // Don't show free trial if user has already used it. Don't show if sub is free and user is already free if (is_user_logged_in() && $sub_price == '0' && $sub_length->duration > 0 && rcp_has_used_trial($user_id) || is_user_logged_in() && $sub_price == '0' && $user_level == $level_id) { $ret = false; } return apply_filters('rcp_show_subscription_level', $ret, $level_id, $user_id); }
function get_users_collab_alerts() { if (is_user_logged_in() && rcp_get_subscription_id(get_current_user_id()) == 1) { $alerts = edd_get_unread_alerts(get_current_user_id()); $styles = ''; //if(sizeof($alerts)>0){ $styles = '<span id="Alert_Count" class="nav_notice_counter">' . sizeof($alerts) . '</span>'; //} $str .= ' <li class="collabnoticeparent"> <a href="JavaScript:void(0)"> <i class="fa fa-envelope"></i> <span>Notifications ' . $styles . '</span> </a>'; if (sizeof($alerts) > 0) { $str .= '<ul class="collabnotices" id="alert_ul">'; foreach ($alerts as $val) { $url = get_post_meta($val->ID, 'Edd_Alert_Message_Url', true); $str .= ' <li data-alert-id="' . $val->ID . '"> <a href="' . $url . '"> <span>' . $val->post_title . '</span> </a> </li>'; } $str .= '</ul>'; } $str .= '</li>'; return $str; } }
/** * Apply the discounts to the cart * * @since 1.0 * * @access public * @return void */ public function apply_discounts($download_id, $options) { if (!function_exists('rcp_is_active')) { return; } $user_id = get_current_user_id(); if (!rcp_is_active($user_id)) { return; } $sub_id = rcp_get_subscription_id($user_id); if (!$sub_id) { $this->clear_cart_discounts(); return; } // Check for member discounts $discounts = get_posts(array('post_type' => 'edd_rcp_discount', 'posts_per_page' => '1', 'fields' => 'ids', 'meta_query' => array('relation' => 'AND', array('key' => '_edd_rcp_discount_subscription', 'value' => $sub_id)))); if (!$discounts) { $this->clear_cart_discounts(); return; } // Get cart details $cart_amount = edd_get_cart_subtotal(); $cart_details = edd_get_cart_content_details(); if (empty($cart_details)) { $this->clear_cart_discounts(); return; } // Subtract exclusions from the cart amount before calculating the discount below. foreach ($cart_details as $key => $download) { // Check for product-level exclusion if (get_post_meta($download['id'], 'rcp_member_discount_exclude')) { $cart_amount -= $download['item_price']; continue; } // Check for download category exclusions $terms = wp_get_object_terms($download['id'], 'download_category'); if (!$terms) { continue; } $term_discounted = false; foreach ($terms as $term) { if (!$term_discounted && get_term_meta($term->term_id, 'rcp_member_discount_exclude')) { $cart_amount -= $download['item_price']; $term_discounted = true; continue; } } } // If the cart amount is 0 after subtracting exclusions, no member discount is applied. if ('0' == $cart_amount) { $this->clear_cart_discounts(); return; } foreach ($discounts as $discount) { $percent = get_post_meta($discount, '_edd_rcp_discount_amount', true); $amount = $cart_amount * ($percent / 100) * -1; EDD()->fees->add_fee(array('amount' => $amount, 'label' => get_the_title($discount), 'id' => 'rcp_member_discount')); EDD()->session->set('rcp_member_discount_id', $discount); } }
function rcp_check_ipn() { global $rcp_options; if (!class_exists('IpnListener')) { // instantiate the IpnListener class include RCP_PLUGIN_DIR . 'includes/gateways/paypal/ipnlistener.php'; } $listener = new IpnListener(); if (isset($rcp_options['sandbox'])) { $listener->use_sandbox = true; } if (isset($rcp_options['ssl'])) { $listener->use_ssl = true; } else { $listener->use_ssl = false; } //To post using the fsockopen() function rather than cURL, use: if (isset($rcp_options['disable_curl'])) { $listener->use_curl = false; } try { $listener->requirePostMethod(); $verified = $listener->processIpn(); } catch (Exception $e) { //exit(0); } /* The processIpn() method returned true if the IPN was "VERIFIED" and false if it was "INVALID". */ if ($verified || isset($_POST['verification_override']) || (isset($rcp_options['sandbox']) || isset($rcp_options['disable_ipn_verify']))) { $posted = apply_filters('rcp_ipn_post', $_POST); // allow $_POST to be modified $user_id = $posted['custom']; $subscription_name = $posted['item_name']; $subscription_key = $posted['item_number']; $amount = number_format((double) $posted['mc_gross'], 2); $amount2 = number_format((double) $posted['mc_amount3'], 2); $payment_status = $posted['payment_status']; $currency_code = $posted['mc_currency']; $subscription_id = rcp_get_subscription_id($user_id); $subscription_price = number_format((double) rcp_get_subscription_price(rcp_get_subscription_id($user_id)), 2); $user_data = get_userdata($user_id); if (!$user_data || !$subscription_id) { return; } if (!rcp_get_subscription_details($subscription_id)) { return; } // setup the payment info in an array for storage $payment_data = array('date' => date('Y-m-d g:i:s', strtotime($posted['payment_date'])), 'subscription' => $posted['item_name'], 'payment_type' => $posted['txn_type'], 'subscription_key' => $subscription_key, 'amount' => $amount, 'user_id' => $user_id, 'transaction_id' => $posted['txn_id']); do_action('rcp_valid_ipn', $payment_data, $user_id, $posted); if ($posted['txn_type'] == 'web_accept' || $posted['txn_type'] == 'subscr_payment') { // only check for an existing payment if this is a payment IPD request if (rcp_check_for_existing_payment($posted['txn_type'], $posted['payment_date'], $subscription_key)) { $log_data = array('post_title' => __('Duplicate Payment', 'rcp'), 'post_content' => __('A duplicate payment was detected. The new payment was still recorded, so you may want to check into both payments.', 'rcp'), 'post_parent' => 0, 'log_type' => 'gateway_error'); $log_meta = array('user_subscription' => $posted['item_name'], 'user_id' => $user_id); $log_entry = WP_Logging::insert_log($log_data, $log_meta); return; // this IPN request has already been processed } /* do some quick checks to make sure all necessary data validates */ if ($amount < $subscription_price && $amount2 < $subscription_price) { /* // the subscription price doesn't match, so lets check to see if it matches with a discount code if( ! rcp_check_paypal_return_price_after_discount( $subscription_price, $amount, $amount2, $user_id ) ) { $log_data = array( 'post_title' => __( 'Price Mismatch', 'rcp' ), 'post_content' => sprintf( __( 'The price in an IPN request did not match the subscription price. Payment data: %s', 'rcp' ), json_encode( $payment_data ) ), 'post_parent' => 0, 'log_type' => 'gateway_error' ); $log_meta = array( 'user_subscription' => $posted['item_name'], 'user_id' => $user_id ); $log_entry = WP_Logging::insert_log( $log_data, $log_meta ); //return; } */ } if (strtolower($currency_code) != strtolower($rcp_options['currency'])) { // the currency code is invalid $log_data = array('post_title' => __('Invalid Currency Code', 'rcp'), 'post_content' => sprintf(__('The currency code in an IPN request did not match the site currency code. Payment data: %s', 'rcp'), json_encode($payment_data)), 'post_parent' => 0, 'log_type' => 'gateway_error'); $log_meta = array('user_subscription' => $posted['item_name'], 'user_id' => $user_id); $log_entry = WP_Logging::insert_log($log_data, $log_meta); return; } } if (isset($rcp_options['email_ipn_reports'])) { wp_mail(get_bloginfo('admin_email'), __('IPN report', 'rcp'), $listener->getTextReport()); } if (rcp_get_subscription_key($user_id) != $subscription_key) { // the subscription key is invalid $log_data = array('post_title' => __('Subscription Key Mismatch', 'rcp'), 'post_content' => sprintf(__('The subscription key in an IPN request did not match the subscription key recorded for the user. Payment data: %s', 'rcp'), json_encode($payment_data)), 'post_parent' => 0, 'log_type' => 'gateway_error'); $log_meta = array('user_subscription' => $posted['item_name'], 'user_id' => $user_id); $log_entry = WP_Logging::insert_log($log_data, $log_meta); return; } /* now process the kind of subscription/payment */ $rcp_payments = new RCP_Payments(); // Subscriptions switch ($posted['txn_type']) { case "subscr_signup": // when a new user signs up // store the recurring payment ID update_user_meta($user_id, 'rcp_paypal_subscriber', $posted['payer_id']); // set the user's status to active rcp_set_status($user_id, 'active'); if (!isset($rcp_options['disable_new_user_notices'])) { wp_new_user_notification($user_id); } // send welcome email rcp_email_subscription_status($user_id, 'active'); update_user_meta($user_id, 'rcp_recurring', 'yes'); do_action('rcp_ipn_subscr_signup', $user_id); break; case "subscr_payment": // when a user makes a recurring payment // record this payment in the database $rcp_payments->insert($payment_data); $subscription = rcp_get_subscription_details(rcp_get_subscription_id($user_id)); // update the user's expiration to correspond with the new payment $member_new_expiration = date('Y-m-d H:i:s', strtotime('+' . $subscription->duration . ' ' . $subscription->duration_unit . ' 23:59:59')); rcp_set_expiration_date($user_id, $member_new_expiration); update_user_meta($user_id, 'rcp_paypal_subscriber', $posted['payer_id']); // make sure the user's status is active rcp_set_status($user_id, 'active'); update_user_meta($user_id, 'rcp_recurring', 'yes'); delete_user_meta($user_id, '_rcp_expired_email_sent'); do_action('rcp_ipn_subscr_payment', $user_id); break; case "subscr_cancel": // user is marked as cancelled but retains access until end of term rcp_set_status($user_id, 'cancelled'); // set the use to no longer be recurring delete_user_meta($user_id, 'rcp_recurring'); delete_user_meta($user_id, 'rcp_paypal_subscriber'); // send sub cancelled email rcp_email_subscription_status($user_id, 'cancelled'); do_action('rcp_ipn_subscr_cancel', $user_id); break; case "subscr_failed": do_action('rcp_ipn_subscr_failed'); break; case "subscr_eot": // user's subscription has reach the end of its term // set the use to no longer be recurring delete_user_meta($user_id, 'rcp_recurring'); if ('cancelled' !== rcp_get_status($user_id)) { rcp_set_status($user_id, 'expired'); // send expired email rcp_email_subscription_status($user_id, 'expired'); } do_action('rcp_ipn_subscr_eot', $user_id); break; case "cart": return; // get out of here // get out of here case "express_checkout": return; // get out of here // get out of here case "web_accept": switch (strtolower($payment_status)) { case 'completed': if (isset($_POST['verification_override'])) { // this is a method for providing a new expiration if it doesn't exist $subscription = rcp_get_subscription_details_by_name($payment_data['subscription']); // update the user's expiration to correspond with the new payment $member_new_expiration = date('Y-m-d H:i:s', strtotime('+' . $subscription->duration . ' ' . $subscription->duration_unit . ' 23:59:59')); rcp_set_expiration_date($user_id, $member_new_expiration); } // set this user to active rcp_set_status($user_id, 'active'); $rcp_payments->insert($payment_data); rcp_email_subscription_status($user_id, 'active'); if (!isset($rcp_options['disable_new_user_notices'])) { // send welcome email here wp_new_user_notification($user_id); } delete_user_meta($user_id, '_rcp_expired_email_sent'); break; case 'denied': case 'expired': case 'failed': case 'voided': rcp_set_status($user_id, 'cancelled'); // send cancelled email here break; } break; default: break; } } else { if (isset($rcp_options['email_ipn_reports'])) { // an invalid IPN attempt was made. Send an email to the admin account to investigate wp_mail(get_bloginfo('admin_email'), __('Invalid IPN', 'rcp'), $listener->getTextReport()); } } }
/** * Loads the restricted content template if required. * * @access public * @since 2.5 */ public function hide_template($template, $slug, $name) { $product_id = get_the_ID(); if (!is_singular('product')) { return $template; } if ('content-single-product' !== $slug . '-' . $name) { return $template; } if (current_user_can('edit_post', $product_id)) { return $template; } $active_only = get_post_meta($product_id, '_rcp_woo_active_to_view', true); $levels = (array) get_post_meta($product_id, '_rcp_woo_subscription_levels_to_view', true); $access_level = get_post_meta($product_id, '_rcp_woo_access_level_to_view', true); $product_cat = rcp_is_post_taxonomy_restricted($product_id, 'product_cat'); $product_tag = rcp_is_post_taxonomy_restricted($product_id, 'product_tag'); /** * rcp_is_post_taxonomy_restricted() returns: * - true when restrictions are found for the current user * - false when restrictions are not found for the current user * - -1 when no terms are assigned, for which we don't care. * We're normalizing the value here. If the value is false, * the user has already passed the restriction checks. */ $cat_restricted = true === $product_cat ? true : false; $tag_restricted = true === $product_tag ? true : false; // Return early if no restrictions if (!$active_only && empty($levels[0]) && !$access_level && !$cat_restricted && !$tag_restricted) { return $template; } $visible = true; // Active subscription setting if ($active_only && !rcp_is_active()) { $visible = false; } // Subscription level setting if (!in_array(rcp_get_subscription_id(), $levels)) { $visible = false; } // User level setting if ($access_level && rcp_user_has_access(get_current_user_id(), $access_level)) { $visible = false; } if ($visible) { return $template; } return rcp_get_template_part('woocommerce', 'single-no-access', false); }
/** * Checks if the user is at their submission limit * * @access public * @since 2.0 */ public function is_at_jobs_limit($user_id = 0) { $at_limit = false; if (empty($user_id)) { $user_id = get_current_user_id(); } $subscription_id = rcp_get_subscription_id($user_id); if ($subscription_id) { $max_jobs = absint(get_option('rcp_subscription_jobs_' . $subscription_id, 0)); $submitted = $this->get_job_count_for_period($user_id); if ($max_jobs >= 1 && $submitted >= $max_jobs) { $at_limit = true; } } return $at_limit; }
/** * Restrict the visibility of a product * * @access public * @since 2.2 */ public function is_visible($ret, $product_id) { if ($ret) { $has_access = true; $active_only = get_post_meta($product_id, '_rcp_woo_active_to_view', true); $levels = (array) get_post_meta($product_id, '_rcp_woo_subscription_levels_to_view', true); $access_level = get_post_meta($product_id, '_rcp_woo_access_level_to_view', true); if ($active_only) { if (!rcp_is_active()) { $has_access = false; } } if (is_array($levels) && !empty($array[0])) { if (!in_array(rcp_get_subscription_id(), $levels)) { $has_access = false; } } if ($access_level) { if (!rcp_user_has_access(get_current_user_id(), $access_level)) { $has_access = false; } } $ret = $has_access; } return $ret; }
*/ ?> <?php get_header(); ?> <?php if (is_user_logged_in()) { $user_id = get_current_user_id(); $user_type = get_user_meta($user_id, 'jobboard_user_role', true); $user = new WP_User($user_id); $user_role = $user->roles[0]; $user_level = rcp_get_subscription_id($user_id); // print_r($user->roles); //if( $user_type == 'job_seeker'|| current_user_can( 'edit_user' ) || in_array("candidate", $user->roles) ){ if ($user_type == 'job_seeker' || $user_level == 1 || current_user_can('edit_user')) { get_template_part('template-parts/dashboard', 'job_seeker'); } //if( $user_type == 'job_lister' || current_user_can( 'edit_user' ) || in_array("employer", $user->roles) ){ if ($user_type == 'job_lister' || $user_level == 2 || current_user_can('edit_user')) { get_template_part('template-parts/dashboard', 'job_lister'); } } else { jobboard_forbidden('login'); } //endif; ?>