function filter_query() { if (is_comment_feed()) { // we are inside a comment feed wp_die(__('Comments are closed.'), '', array('response' => 403)); } }
function apply_filters() { if (is_feed()) { $hs_settings = get_option('hs_settings'); if ($hs_settings !== false && !empty($hs_settings['hs_portal'])) { $this->portal_id = $hs_settings['hs_portal']; add_filter('the_content_feed', array($this, 'hs_add_rss_readers_tracking')); add_filter('the_excerpt_rss', array($this, 'hs_add_rss_readers_tracking')); if (!is_category() && !is_comment_feed()) { add_filter('the_content_feed', array($this, 'hs_add_rss_subscribers_tracking')); } } } }
/** * Redirect the browser to the custom feed URI. * * Exits PHP after redirect. * * @since 1.3.0 * * @uses genesis_get_option() Get theme setting value. * * @return null Return early on failure. Exits on success. */ function genesis_feed_redirect() { if (!is_feed() || isset($_SERVER['HTTP_USER_AGENT']) && preg_match('/feed(blitz|burner|validator)/i', $_SERVER['HTTP_USER_AGENT'])) { return; } //* Don't redirect if viewing archive, search, or post comments feed if (is_archive() || is_search() || is_singular()) { return; } $feed_uri = genesis_get_option('feed_uri'); $comments_feed_uri = genesis_get_option('comments_feed_uri'); if ($feed_uri && !is_comment_feed() && genesis_get_option('redirect_feed')) { wp_redirect($feed_uri, 302); exit; } if ($comments_feed_uri && is_comment_feed() && genesis_get_option('redirect_comments_feed')) { wp_redirect($comments_feed_uri, 302); exit; } }
/** * Filter out the comment feed * * @since 0.0.2 * @access public * @link https://github.com/solarissmoke/disable-comments-mu * @uses wp_die() */ public static function filterFeedComments() { if (is_comment_feed()) { wp_die('There are no comments enabled on this site.', '', ['response' => 403]); } }
function pre_get_posts($query) { // don't make anything if no language has been defined yet // $this->post_types & $this->taxonomies are defined only once the action 'wp_loaded' has been fired // honor suppress_filters if (!$this->get_languages_list() || !did_action('wp_loaded') || $query->get('suppress_filters')) { return $query; } $qv = $query->query_vars; // users may want to display content in a different language than the current one by setting it explicitely in the query if (!$this->first_query && $this->curlang && isset($qv['lang']) && $qv['lang']) { return $query; } $this->first_query = false; // detect our exclude pages query and returns to avoid conflicts // this test should be sufficient if (isset($qv['tax_query'][0]['taxonomy']) && $qv['tax_query'][0]['taxonomy'] == 'language' && isset($qv['tax_query'][0]['operator']) && $qv['tax_query'][0]['operator'] == 'NOT IN') { return $query; } // special case for wp-signup.php & wp-activate.php if (is_home() && false === strpos($_SERVER['SCRIPT_NAME'], 'index.php')) { $this->curlang = $this->get_preferred_language(); return $query; } // homepage is requested, let's set the language // take care to avoid posts page for which is_home = 1 if (!$this->curlang && empty($query->query) && (is_home() || is_page() && $qv['page_id'] == $this->page_on_front)) { $this->home_requested($query); } // redirect the language page to the homepage if ($this->options['redirect_lang'] && is_tax('language') && $this->page_on_front && (count($query->query) == 1 || is_paged() && count($query->query) == 2)) { $qv['page_id'] = $this->get_post($this->page_on_front, $this->get_language(get_query_var('lang'))); $query->parse_query($qv); return $query; } // sets is_home on translated home page when it displays posts // is_home must be true on page 2, 3... too if (!$this->page_on_front && is_tax('language') && (count($query->query) == 1 || is_paged() && count($query->query) == 2)) { $query->is_home = true; $query->is_tax = false; $this->curlang = $this->get_language(get_query_var('lang')); // sets the language now otherwise it will be too late to filter sticky posts ! } // sets the language for posts page in case the front page displays a static page if ($this->page_for_posts) { // If permalinks are used, WordPress does set and use $query->queried_object_id and sets $query->query_vars['page_id'] to 0 // and does set and use $query->query_vars['page_id'] if permalinks are not used :( if (isset($qv['pagename']) && $qv['pagename'] && isset($query->queried_object_id)) { $page_id = $query->queried_object_id; } elseif (isset($qv['page_id'])) { $page_id = $qv['page_id']; } if (isset($page_id) && $page_id && $this->get_post($page_id, $this->get_post_language($this->page_for_posts)) == $this->page_for_posts) { $this->page_for_posts = $page_id; $this->curlang = $this->get_post_language($page_id); $query->set('lang', $this->curlang->slug); $query->is_page = false; $query->is_singular = false; $query->is_home = true; $query->is_posts_page = true; } } $is_post_type = isset($qv['post_type']) && (in_array($qv['post_type'], $this->post_types) || is_array($qv['post_type']) && array_intersect($qv['post_type'], $this->post_types)); // FIXME to generalize as I probably forget things $is_archive = count($query->query) == 1 && isset($qv['paged']) && $qv['paged'] || isset($qv['m']) && $qv['m'] || isset($qv['author']) && $qv['author'] || isset($qv['post_type']) && is_post_type_archive() && $is_post_type; // sets 404 when the language is not set for archives needing the language in the url if (!$this->options['hide_default'] && !isset($qv['lang']) && !$GLOBALS['wp_rewrite']->using_permalinks() && $is_archive) { $query->set_404(); } // sets the language in case we hide the default language if ($this->options['hide_default'] && !isset($qv['lang']) && ($is_archive || is_search() || count($query->query) == 1 && isset($qv['feed']) && $qv['feed'])) { $query->set('lang', $this->options['default_lang']); } // allow filtering recent posts and secondary queries by the current language // take care not to break queries for non visible post types such as nav_menu_items, attachments... if ($this->curlang && (!isset($qv['post_type']) || $is_post_type)) { $query->set('lang', $this->curlang->slug); } // remove pages query when the language is set unless we do a search // FIXME is only search broken by this ? if (isset($qv['lang']) && $qv['lang'] && !isset($qv['post_type']) && !is_search()) { $query->set('post_type', 'post'); } // unset the is_archive flag for language pages to prevent loading the archive template // keep archive flag for comment feed otherwise the language filter does not work if (isset($qv['lang']) && $qv['lang'] && !is_comment_feed() && !is_post_type_archive() && !is_date() && !is_author() && !is_category() && !is_tag() && !is_tax('post_format')) { $query->is_archive = false; } // unset the is_tax flag for authors pages and post types archives // FIXME Probably I should do this for other cases if (isset($qv['lang']) && $qv['lang'] && (is_author() || is_post_type_archive() || is_date() || is_search())) { $query->is_tax = false; unset($query->queried_object); } // sets a language for theme preview if (is_preview() && is_front_page()) { $this->curlang = $this->get_current_language(); $query->set('lang', $this->curlang->slug); } // sets the language for an empty string search when hiding the code for default language // http://wordpress.org/support/topic/search-for-empty-string-in-default-language if (!$this->curlang && !get_query_var('lang') && $this->options['hide_default'] && isset($query->query['s']) && !$query->query['s']) { $query->set('lang', $this->options['default_lang']); } // to avoid conflict beetwen taxonomies if (isset($query->tax_query->queries)) { foreach ($query->tax_query->queries as $tax) { if (in_array($tax['taxonomy'], $this->taxonomies)) { unset($query->query_vars['lang']); } } } return $query; }
/** * Redirect on comment feed, set status 301 * * @since 04/08/2013 * @param void * @return void */ public function filter_query() { if (!is_comment_feed()) { return NULL; } if (isset($_GET['feed'])) { wp_redirect(remove_query_arg('feed'), 301); exit; } // redirect_canonical will do the rest set_query_var('feed', ''); }
public function getQuery() { $query = ['isArchive' => is_archive(), 'isPostTypeArchive' => is_post_type_archive(), 'isAttachment' => is_attachment(), 'isAuthor' => is_author(), 'isCategory' => is_category(), 'isTag' => is_tag(), 'isTaxonomy' => is_tax(), 'isCommentsPopup' => is_comments_popup(), 'isDate' => is_date(), 'isDay' => is_day(), 'isFeed' => is_feed(), 'isCommentFeed' => is_comment_feed(), 'isFrontPage' => is_front_page(), 'isHome' => is_home(), 'isMonth' => is_month(), 'isPage' => is_page(), 'isPaged' => is_paged(), 'isPreview' => is_preview(), 'isRobots' => is_robots(), 'isSearch' => is_search(), 'isSingle' => is_single(), 'isSingular' => is_singular(), 'isTime' => is_time(), 'isTrackback' => is_trackback(), 'isYear' => is_year(), 'is404' => is_404(), 'postType' => is_singular() ? get_queried_object()->post_type : get_query_var('post_type', null), 'attachmentId' => is_attachment() ? get_queried_object()->ID : null, 'authorId' => is_author() ? get_queried_object()->ID : null, 'categoryId' => is_category() ? get_queried_object()->term_id : null, 'tagId' => is_tag() ? get_queried_object()->term_id : null, 'taxonomy' => is_tax() ? get_queried_object()->taxonomy : null, 'termId' => is_tax() ? get_queried_object()->term_id : null, 'feed' => is_feed() ? get_query_var('feed', null) : null, 'postId' => is_single() ? get_queried_object()->ID : null]; return $query; }
/** * */ function filter_query() { if (is_comment_feed()) { if (isset($_GET['feed'])) { // remove possible XSS $url = esc_url_raw(remove_query_arg('feed', 301)); wp_redirect($url); exit; } set_query_var('feed', ''); // redirect_canonical will do the rest redirect_canonical(); } }
function pshb_template_redirect() { if ((is_comment_feed() && !is_singular()) || (is_feed() && !is_comment_feed() && !is_archive())) { $hub_urls = pshb_get_pubsub_endpoints(); foreach ($hub_urls as $hub_url) { header('Link: <'.$hub_url.'>; rel=hub', false); } header('Link: <'.( is_ssl() ? 'https://' : 'http://' ) . $_SERVER['HTTP_HOST'] . $_SERVER['REQUEST_URI'].'>; rel=self', false); } }
/** * HideMyWP::wp() * * Disable WP components when permalink is enabled * @return */ function wp() { //delete_option('pp_important_messages_last'); /*echo 'last raw:'.get_option('pp_important_messages_last'); echo '<br>last timestap +70'; // strtotime( '+70 hours', strtotime($recent_message_last) echo strtotime( '+70 hours', strtotime(get_option('pp_important_messages_last'))); echo ' again str:'; echo date('Y-m-d H:i:s', strtotime( '+70 hours', strtotime(get_option('pp_important_messages_last')))); echo '<p>'; echo current_time('timestamp', 1) < strtotime( '+70 hours', strtotime(get_option('pp_important_messages_last')));*/ if ((is_feed() || is_comment_feed()) && !isset($_GET['feed']) && !$this->opt('feed_enable')) { $this->block_access(); } if (is_author() && !isset($_GET['author']) && !isset($_GET['author']) && !$this->opt('author_enable')) { $this->block_access(); } if (is_search() && !isset($_GET['s']) && !$this->opt('search_enable')) { $this->block_access(); } if (is_paged() && !isset($_GET['paged']) && !$this->opt('paginate_enable')) { $this->block_access(); } if (is_page() && !isset($_GET['page_id']) && !isset($_GET['pagename']) && !$this->opt('page_enable')) { $this->block_access(); } if (is_single() && !isset($_GET['p']) && !$this->opt('post_enable')) { $this->block_access(); } if (is_category() && !isset($_GET['cat']) && !$this->opt('category_enable')) { $this->block_access(); } if (is_tag() && !isset($_GET['tag']) && !$this->opt('tag_enable')) { $this->block_access(); } if ((is_date() || is_time()) && !isset($_GET['monthnum']) && !isset($_GET['m']) && !isset($_GET['w']) && !isset($_GET['second']) && !isset($_GET['year']) && !isset($_GET['day']) && !isset($_GET['hour']) && !isset($_GET['second']) && !isset($_GET['minute']) && !isset($_GET['calendar']) && $this->opt('disable_archive')) { $this->block_access(); } if ((is_tax() || is_post_type_archive() || is_trackback() || is_comments_popup() || is_attachment()) && !isset($_GET['post_type']) && !isset($_GET['taxonamy']) && !isset($_GET['attachment']) && !isset($_GET['attachment_id']) && !isset($_GET['preview']) && $this->opt('disable_other_wp')) { $this->block_access(); } if (isset($_SERVER['HTTP_USER_AGENT']) && !is_404() && !is_home() && (stristr($_SERVER['HTTP_USER_AGENT'], 'BuiltWith') || stristr($_SERVER['HTTP_USER_AGENT'], '2ip.ru'))) { wp_redirect(home_url()); } if ($this->opt('remove_other_meta')) { if (function_exists('header_remove')) { header_remove('X-Powered-By'); } else { header('X-Powered-By: '); } } }
/** * Determine whether the current request is for a frontend (i.e. themed) page. * * @return boolean [description] */ protected function is_frontend_request() { global $pagenow; $is_login = '******' === $pagenow; // @todo Might want to allow this to run on feeds... $is_backend = is_feed() || is_robots() || is_trackback() || is_comment_feed() || is_admin() || $is_login; return !$is_backend; }
function pre_get_posts($query) { $qvars = $query->query_vars; // detect our exclude pages query and returns to avoid conflicts // this test should be sufficient if (isset($qvars['tax_query'][0]['taxonomy']) && $qvars['tax_query'][0]['taxonomy'] == 'language' && isset($qvars['tax_query'][0]['operator'])) { return; } // homepage is requested, let's set the language // second check not to break wp-signup & wp-activate if (empty($query->query) && home_url('/') == trailingslashit((is_ssl() ? 'https://' : 'http://') . $_SERVER['HTTP_HOST'] . $_SERVER['REQUEST_URI'])) { // find out the language if ($this->options['hide_default'] && isset($_COOKIE['wordpress_polylang'])) { $this->curlang = $this->get_language($this->options['default_lang']); } else { $this->curlang = $this->get_preferred_language(); } // sets the language according to browser preference or default language // we are already on the right page if ($this->options['default_lang'] == $this->curlang->slug && $this->options['hide_default']) { if ($this->page_on_front && ($link_id = $this->get_post($this->page_on_front, $this->curlang))) { $query->set('page_id', $link_id); } else { $query->set('lang', $this->curlang->slug); } } else { wp_redirect($this->get_home_url($this->curlang)); exit; } } // redirect the language page to the homepage if ($this->options['redirect_lang'] && is_tax('language') && count($query->query) == 1 && $this->page_on_front) { $this->curlang = $this->get_language(get_query_var('lang')); $query->parse_query('page_id=' . $this->get_post($this->page_on_front, $this->curlang)); return; } // sets is_home on translated home page when it displays posts // is_home must be true on page 2, 3... too if (!$this->page_on_front && is_tax('language') && (count($query->query) == 1 || is_paged() && count($query->query) == 2)) { $query->is_home = true; $query->is_tax = false; $this->curlang = $this->get_language(get_query_var('lang')); // sets the language now otherwise it will be too late to filter sticky posts ! } // sets the language for posts page in case the front page displays a static page if ($this->page_for_posts) { // If permalinks are used, WordPress does set and use $query->queried_object_id and sets $query->query_vars['page_id'] to 0 // and does set and use $query->query_vars['page_id'] if permalinks are not used :( if (isset($qvars['pagename']) && $qvars['pagename'] && isset($query->queried_object_id)) { $page_id = $query->queried_object_id; } elseif (isset($qvars['page_id'])) { $page_id = $qvars['page_id']; } if (isset($page_id) && $page_id && $this->get_post($page_id, $this->get_post_language($this->page_for_posts)) == $this->page_for_posts) { $this->page_for_posts = $page_id; $this->curlang = $this->get_post_language($page_id); $query->set('lang', $this->curlang->slug); $query->is_page = false; $query->is_home = true; $query->is_posts_page = true; $query->is_singular = false; } } // FIXME to generalize as I probably forget things $is_archive = count($query->query) == 1 && isset($qvars['paged']) && $qvars['paged'] || isset($qvars['m']) && $qvars['m'] || isset($qvars['author']) && $qvars['author'] || isset($qvars['post_type']) && is_post_type_archive() && in_array($qvars['post_type'], $this->post_types); // sets 404 when the language is not set for archives needing the language in the url if (!$this->options['hide_default'] && !isset($qvars['lang']) && !$GLOBALS['wp_rewrite']->using_permalinks() && $is_archive) { $query->set_404(); } // sets the language in case we hide the default language if ($this->options['hide_default'] && !isset($qvars['lang']) && ($is_archive || count($query->query) == 1 && isset($qvars['feed']) && $qvars['feed'])) { $query->set('lang', $this->options['default_lang']); } // allow filtering recent posts by the current language // take care not to break queries for non visible post types such as nav_menu_items, attachments... if ($query->is_home && $this->curlang && (!isset($qvars['post_type']) || in_array($qvars['post_type'], $this->post_types) || is_array($qvars['post_type']) && array_intersect($qvars['post_type'], $this->post_types))) { $query->set('lang', $this->curlang->slug); } // remove pages query when the language is set unless we do a search // FIXME is only search broken by this ? if (isset($qvars['lang']) && $qvars['lang'] && !isset($qvars['post_type']) && !is_search()) { $query->set('post_type', 'post'); } // unset the is_archive flag for language pages to prevent loading the archive template // keep archive flag for comment feed otherwise the language filter does not work if (isset($qvars['lang']) && $qvars['lang'] && !is_comment_feed() && !is_post_type_archive() && !is_date() && !is_author() && !is_category() && !is_tag() && !is_tax('post_format')) { $query->is_archive = false; } // unset the is_tax flag for authors pages and post types archives // FIXME Probably I should do this for other cases if (isset($qvars['lang']) && $qvars['lang'] && (is_author() || is_post_type_archive())) { $query->is_tax = false; unset($query->queried_object); } // sets a language for theme preview if (isset($_GET['preview'])) { $query->set('lang', $this->options['default_lang']); } if (PLL_DISPLAY_ALL) { // add posts with no language set $query->query_vars['tax_query'] = array('relation' => 'OR', array('taxonomy' => 'language', 'terms' => get_terms('language', array('fields' => 'ids')), 'operator' => 'NOT IN')); } }
public function comment_text() { if (!is_feed() && !is_comment_feed()) { //Yay, filters. add_filter('comment_excerpt', array("AECFilters", 'add_edit_links'), '1000'); //Commented out because some ppl add issues with these screwing up their theme //add_filter('get_comment_date', array(&$this, 'add_date_spans'), '1000'); //add_filter('get_comment_time', array(&$this, 'add_time_spans'), '1000'); add_filter('comment_text', array("AECFilters", 'add_edit_links'), '1000'); //Low priority so other HTML can be added first add_filter('thesis_comment_text', array("AECFilters", 'add_edit_links'), '1000'); //For Thesis (todo - remove when necessary) add_filter('get_comment_author_link', array("AECFilters", 'add_author_spans'), '1000'); //Low priority so other HTML can be added first } }
/** * HideMyWP::wp() * * Disable WP components when permalink is enabled * @return */ function wp() { if ((is_feed() || is_comment_feed()) && !isset($_GET['feed']) && !$this->opt('feed_enable')) { $this->block_access(); } if (is_author() && !isset($_GET['author']) && !isset($_GET['author']) && !$this->opt('author_enable')) { $this->block_access(); } if (is_search() && !isset($_GET['s']) && !$this->opt('search_enable')) { $this->block_access(); } if (is_paged() && !isset($_GET['paged']) && !$this->opt('paginate_enable')) { $this->block_access(); } if (is_page() && !isset($_GET['page_id']) && !isset($_GET['pagename']) && !$this->opt('page_enable')) { $this->block_access(); } if (is_single() && !isset($_GET['p']) && !$this->opt('post_enable')) { $this->block_access(); } if (is_category() && !isset($_GET['cat']) && !$this->opt('category_enable')) { $this->block_access(); } if (is_tag() && !isset($_GET['tag']) && !$this->opt('tag_enable')) { $this->block_access(); } if ((is_date() || is_time()) && !isset($_GET['monthnum']) && !isset($_GET['m']) && !isset($_GET['w']) && !isset($_GET['second']) && !isset($_GET['year']) && !isset($_GET['day']) && !isset($_GET['hour']) && !isset($_GET['second']) && !isset($_GET['minute']) && !isset($_GET['calendar']) && $this->opt('disable_archive')) { $this->block_access(); } if ((is_tax() || is_post_type_archive() || is_trackback() || is_comments_popup() || is_attachment()) && !isset($_GET['post_type']) && !isset($_GET['taxonamy']) && !isset($_GET['attachment']) && !isset($_GET['attachment_id']) && !isset($_GET['preview']) && $this->opt('disable_other_wp')) { $this->block_access(); } if (!is_404() && !is_home() && (stristr($_SERVER['HTTP_USER_AGENT'], 'BuiltWith') || stristr($_SERVER['HTTP_USER_AGENT'], '2ip.ru'))) { wp_redirect(home_url()); } }
/** * Hook into front-end routing. * Setup the router API to be executed before * theme default templates. */ public function setRouter() { if (is_feed() || is_comment_feed()) { return; } try { $request = $this->container['request']; $response = $this->container['router']->dispatch($request); // We only send back the content because, headers are already defined // by WordPress internals. $response->sendContent(); } catch (\Symfony\Component\HttpKernel\Exception\NotFoundHttpException $exception) { /* * Fallback to WordPress templates. */ } }
function hook_template_redirect() { global $cache_stop, $hyper_cache_stop, $lite_cache_stop; if ($this->ob_started) { return; } $home_root = parse_url(get_option('home'), PHP_URL_PATH); if ($cache_stop || $hyper_cache_stop || $lite_cache_stop) { } else { if ($_SERVER['REQUEST_METHOD'] == 'POST') { $cache_stop = true; } else { if (!empty($_SERVER['QUERY_STRING'])) { $cache_stop = true; } else { if (is_user_logged_in()) { $cache_stop = true; } else { if (is_trackback()) { $cache_stop = true; } else { if (isset($this->options['reject_feeds']) && is_feed()) { $cache_stop = true; } else { if (isset($this->options['reject_comment_feeds']) && is_comment_feed()) { $cache_stop = true; } else { if (isset($this->options['reject_home']) && is_front_page()) { $cache_stop = true; } else { if (is_robots()) { $cache_stop = true; } } } } } } } } } if (defined('SID') && SID != '') { $cache_stop = true; } else { if (substr($_SERVER['REQUEST_URI'], 0, strlen($home_root) + 8) == $home_root . '/sitemap') { $cache_stop = true; } else { if (is_404()) { if (isset($this->options['reject_404'])) { $cache_stop = true; } else { $file = $this->get_folder() . '/' . substr(get_option('home'), strpos(get_option('home'), '://') + 3) . '/404.html'; if (file_exists($file) && ($this->options['max_age'] == 0 || filemtime($file) > time() - $this->options['max_age'] * 3600)) { header('Content-Type: text/html;charset=UTF-8'); // For some reason it seems more performant than readfile... header('X-Hyper-Cache: hit,404'); echo file_get_contents($file); die; } } } } } if (!$cache_stop && substr($_SERVER['REQUEST_URI'], 0, strlen($home_root) + 4) == $home_root . '/wp-') { $cache_stop = true; } // URLs to reject (exact) if (!$cache_stop && isset($this->options['reject_uris_exact_enabled'])) { if (is_array($this->options['reject_uris_exact'])) { foreach ($this->options['reject_uris_exact'] as &$uri) { if ($_SERVER['REQUEST_URI'] == $uri) { $cache_stop = true; break; } } } } // URLs to reject if (!$cache_stop && isset($this->options['reject_uris_enabled'])) { if (is_array($this->options['reject_uris'])) { foreach ($this->options['reject_uris'] as &$uri) { if (strpos($_SERVER['REQUEST_URI'], $uri) === 0) { $cache_stop = true; break; } } } } if (!$cache_stop && !empty($this->options['reject_old_posts']) && is_single()) { global $post; if (strtotime($post->post_date_gmt) < time() - 86400 * $this->options['reject_old_posts']) { return; } } // If is not require to bypass the comment authors, remove the cookies so the page is generated without // comment moderation noticies if (!isset($this->options['reject_comment_authors'])) { foreach ($_COOKIE as $n => $v) { if (substr($n, 0, 14) == 'comment_author') { unset($_COOKIE[$n]); } } } $this->ob_started = true; ob_start('hyper_cache_callback'); }
public function filter_query() { if (is_comment_feed()) { wp_die(__('Comments are closed.'), '', array('response' => 403)); } }
function filter_query() { if (is_comment_feed()) { if (isset($_GET['feed'])) { wp_redirect(remove_query_arg('feed'), 301); exit; } set_query_var('feed', ''); // redirect_canonical will do the rest redirect_canonical(); } }
/** * Exclude restricted comments from comment feed * * @since 1.0.0 * @param array $posts * @param WP_Query $query * @return array */ public function exclude_restricted_comments($posts, WP_Query $query) { if (is_comment_feed() && $query->comment_count) { foreach ($query->comments as $key => $comment) { $post_id = $comment->comment_post_ID; $is_product = in_array(get_post_type($post_id), array('product', 'product_variation')); // Determine if user can view the comment post $can_view = $is_product ? current_user_can('wc_memberships_view_restricted_product', $post_id) : current_user_can('wc_memberships_view_restricted_post_content', $post_id); // If not, exclude this comment from the feed if (!$can_view) { unset($query->comments[$key]); } } // Re-index and re-count comments $query->comments = array_values($query->comments); $query->comment_count = count($query->comments); } return $posts; }