function premise_has_content_access() { global $post; if (!premise_is_protected_content()) { return true; } // if it's not published let WP handle permissions if ($post->post_status == 'draft' && 'true' == $_GET['preview']) { return true; } // don't let visitors access protected content if (!is_user_logged_in()) { return false; } $user = wp_get_current_user(); $cap = 'edit_other_' . ('page' == $post->post_type ? 'post' : $post->post_type) . 's'; if ($user->ID == $post->post_author || current_user_can($cap)) { return true; } $access_level = get_post_meta($post->ID, '_acp_access_levels', true); $protected = accesspress_get_custom_field('_acp_protection'); if (member_has_access_level($access_level)) { if ('member' == $protected) { return true; } } elseif ('nonmember' == $protected) { return true; } return false; }
function post_content_filter($content) { if (!premise_is_protected_content()) { return $content; } // close comments on protected content add_filter('comments_open', '__return_false', 99); if (!is_user_logged_in()) { return sprintf(__('Please <a href="%s">Log in</a> to view this content.', 'premise'), memberaccess_login_redirect(get_permalink())); } if (premise_has_content_access()) { return $content; } return ''; }