/** * Setup the rule. * * @since 1.0.0 */ public function prepare_obj() { if (MS_Rule_Post_Model::is_active()) { MS_Model_Rule::register_rule(self::RULE_ID, __CLASS__, __('Posts', 'membership2'), 11, true); } $this->add_filter('ms_view_protectedcontent_define-' . self::RULE_ID, 'handle_render_callback', 10, 2); $this->add_filter('ms_rule_listtable-' . self::RULE_ID, 'return_listtable'); }
/** * Protect post from showing. * * Related Action Hooks: * - pre_get_posts * * @since 1.0.0 * * @param WP_Query $query The WP_Query object to filter. */ public function protect_posts($wp_query) { if (empty(self::$denied_ids) && empty(self::$allowed_ids)) { return $wp_query; } if (!empty(self::$denied_ids)) { // Remove duplicate entries from the ID arrays. self::$denied_ids = array_unique(self::$denied_ids, SORT_NUMERIC); self::$allowed_ids = array_unique(self::$allowed_ids, SORT_NUMERIC); // Remove any post that is allowed from the denied_ids list. self::$denied_ids = array_diff(self::$denied_ids, self::$allowed_ids); // Tell the WP query which posts are actually off limit for the user. $wp_query->query_vars['post__not_in'] = array_merge($wp_query->query_vars['post__not_in'], self::$denied_ids); } self::$denied_ids = array(); self::$allowed_ids = array(); do_action('ms_rule_post_model_protect_posts', $wp_query, $this); }