function ml_subscriptions_filter_posts($posts, $user_id) { $filtered_posts = array(); foreach ($posts as $post) { if (Groups_Post_Access::user_can_read_post($post->ID, $user_id)) { $filtered_posts[] = $post; } } return $filtered_posts; }
/** * Handles redirection. */ public static function wp() { global $wp_query; $is_restricted_term = false; if (class_exists('Groups_Options') && class_exists('Groups_Restrict_Categories')) { $redirect_restricted_terms = Groups_Options::get_option('groups-404-redirect-restricted-terms', false); if ($redirect_restricted_terms) { $is_term = $wp_query->is_category || $wp_query->is_tag || $wp_query->is_tax; if ($is_term) { $restricted_term_ids = Groups_Restrict_Categories::get_user_restricted_term_ids(get_current_user_id()); $term_id = $wp_query->get_queried_object_id(); if (in_array($term_id, $restricted_term_ids)) { $is_restricted_term = true; } } } } if ($wp_query->is_404 || $is_restricted_term) { if (self::groups_is_active()) { $redirect_to = Groups_Options::get_option('groups-404-redirect-to', 'post'); $post_id = Groups_Options::get_option('groups-404-redirect-post-id', ''); $redirect_status = intval(Groups_Options::get_option('groups-404-redirect-status', '301')); $current_url = (is_ssl() ? 'https://' : 'http://') . $_SERVER['HTTP_HOST'] . $_SERVER['REQUEST_URI']; $current_post_id = url_to_postid($current_url); if (!$current_post_id) { $current_post_id = $wp_query->get_queried_object_id(); } if (!$current_post_id) { require_once 'groups-404-url-to-postid.php'; $current_post_id = groups_404_url_to_postid($current_url); } if ($current_post_id) { $is_restricted_by_term = false; if (class_exists('Groups_Restrict_Categories') && method_exists('Groups_Restrict_Categories', 'user_can_read')) { $is_restricted_by_term = !Groups_Restrict_Categories::user_can_read($current_post_id); } if (!Groups_Post_Access::user_can_read_post($current_post_id, get_current_user_id()) || $is_restricted_by_term || $is_restricted_term) { switch ($redirect_to) { case 'login': if (!is_user_logged_in()) { wp_redirect(wp_login_url($current_url), $redirect_status); exit; } else { // If the user is already logged in, we can't // redirect to the WordPress login again, // we either send them to the home page, or // to the page indicated in the settings. if (empty($post_id)) { wp_redirect(get_home_url(), $redirect_status); } else { $post_id = apply_filters('groups_404_redirect_post_id', $post_id, $current_post_id, $current_url); if ($post_id != $current_post_id) { wp_redirect(get_permalink($post_id), $redirect_status); } else { return; } } exit; } default: // 'post' if (empty($post_id)) { wp_redirect(get_home_url(), $redirect_status); } else { $post_id = apply_filters('groups_404_redirect_post_id', $post_id, $current_post_id, $current_url); if ($post_id != $current_post_id) { wp_redirect(get_permalink($post_id), $redirect_status); } else { return; } } exit; } } } } } }