Skip to content

Instantly share code, notes, and snippets.

@msaari
Created October 26, 2017 03:40
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save msaari/daa1c9bdceacdfe61e130bbbf42409c2 to your computer and use it in GitHub Desktop.
Save msaari/daa1c9bdceacdfe61e130bbbf42409c2 to your computer and use it in GitHub Desktop.
Relevanssi support for Simple Membership
<?php
// Replace the relevanssi_default_post_ok() function in lib/common.php with this to add support for Simple Membership
function relevanssi_default_post_ok($post_ok, $doc) {
$status = relevanssi_get_post_status($doc);
// if it's not public, don't show
if ('publish' != $status) {
$post_ok = false;
}
// ...unless
if ('private' == $status) {
$post_ok = false;
if (function_exists('awp_user_can')) {
// Role-Scoper, though Role-Scoper actually uses a different function to do this
// So whatever is in here doesn't actually run.
$current_user = wp_get_current_user();
$post_ok = awp_user_can('read_post', $doc, $current_user->ID);
}
else if (defined('GROUPS_CORE_VERSION')) {
// Groups
$current_user = wp_get_current_user();
$access = Groups_Post_Access::user_can_read_post($doc, $current_user->ID);
}
else if (defined('SIMPLE_WP_MEMBERSHIP_VER')) {
// Simple Membership
$access_ctrl = SwpmAccessControl::get_instance();
$access = $access_ctrl->can_i_read_post($post);
}
else {
// Basic WordPress version
$type = relevanssi_get_post_type($doc);
if (isset($GLOBALS['wp_post_types'][$type]->cap->read_private_posts)) {
$cap = $GLOBALS['wp_post_types'][$type]->cap->read_private_posts;
}
else {
// guessing here
$cap = 'read_private_' . $type . 's';
}
if (current_user_can($cap)) {
$post_ok = true;
}
}
}
?>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment