function memberful_wp_save_postdata($post_id) { if (defined('DOING_AUTOSAVE') && DOING_AUTOSAVE) { return; } // Verify this came from the our screen and with proper authorization, // because save_post can be triggered at other times if (!memberful_wp_valid_nonce(plugin_basename(__FILE__))) { return; } if (!in_array($_POST['post_type'], memberful_wp_metabox_types())) { return; } $permission = $_POST['post_type'] === 'page' ? 'edit_page' : 'edit_post'; if (!current_user_can($permission, $post_id)) { return; } // Make sure we're using the actual post id and not a revision id if ($parent_id = wp_is_post_revision($post_id)) { $post_id = $parent_id; } $entities = array(Memberful_Post_ACL::DOWNLOAD, Memberful_Post_ACL::SUBSCRIPTION); foreach ($entities as $entity) { $field = 'memberful_' . $entity . '_acl'; $acl_list = empty($_POST[$field]) ? array() : (array) $_POST[$field]; $acl_manager = new Memberful_Post_ACL($entity); $acl_manager->set_acl($post_id, $acl_list); } $viewable_by_any_registered_users = isset($_POST['memberful_viewable_by_any_registered_users']) && $_POST['memberful_viewable_by_any_registered_users'] === '1'; memberful_wp_set_post_available_to_any_registered_users($post_id, $viewable_by_any_registered_users); if (!isset($_POST['memberful_marketing_content'])) { return; } $marketing_content = trim($_POST['memberful_marketing_content']); memberful_wp_update_post_marketing_content($post_id, $marketing_content); if (!empty($_POST['memberful_make_default_marketing_content'])) { memberful_wp_update_default_marketing_content($marketing_content); } }
function memberful_wp_bulk_protect() { if (!empty($_POST)) { $categories_to_protect = empty($_POST['memberful_protect_categories']) ? array() : (array) $_POST['memberful_protect_categories']; $acl_for_products = empty($_POST['memberful_product_acl']) ? array() : (array) $_POST['memberful_product_acl']; $acl_for_subscriptions = empty($_POST['memberful_subscription_acl']) ? array() : (array) $_POST['memberful_subscription_acl']; $marketing_content = empty($_POST['memberful_marketing_content']) ? '' : $_POST['memberful_marketing_content']; $things_to_protect = empty($_POST['target_for_restriction']) ? '' : $_POST['target_for_restriction']; $viewable_by_any_registered_user = empty($_POST['memberful_viewable_by_any_registered_users']) ? '' : $_POST['memberful_viewable_by_any_registered_users']; $product_acl_manager = new Memberful_Post_ACL('product'); $subscription_acl_manager = new Memberful_Post_ACL('subscription'); $query_params = array('nopaging' => true, 'fields' => 'ids'); switch ($things_to_protect) { case 'all_pages_and_posts': $query_params['post_type'] = array('post', 'page'); break; case 'all_pages': $query_params['post_type'] = 'page'; break; case 'all_posts': $query_params['post_type'] = 'post'; break; case 'all_posts_from_category': $query_params['category__in'] = $categories_to_protect; break; } $query = new WP_Query($query_params); foreach ($query->posts as $id) { $product_acl_manager->set_acl($id, $acl_for_products); $subscription_acl_manager->set_acl($id, $acl_for_subscriptions); memberful_wp_update_post_marketing_content($id, $marketing_content); memberful_wp_set_post_available_to_any_registered_users($id, $viewable_by_any_registered_user); } if (isset($_POST['memberful_make_default_marketing_content']) && $_POST['memberful_make_default_marketing_content']) { memberful_wp_update_default_marketing_content($marketing_content); } wp_redirect(memberful_wp_plugin_bulk_protect_url() . '&success=bulk'); } memberful_wp_render('bulk_protect', array('products' => memberful_wp_metabox_acl_format(array(), 'product'), 'subscriptions' => memberful_wp_metabox_acl_format(array(), 'subscription'), 'marketing_content' => '', 'form_target' => memberful_wp_plugin_bulk_protect_url(TRUE))); }