Created
October 26, 2017 03:40
-
-
Save msaari/daa1c9bdceacdfe61e130bbbf42409c2 to your computer and use it in GitHub Desktop.
Relevanssi support for Simple Membership
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
<?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