Support for Visual Composer (or any “the loop” processor)
-
Hello.
I definitely enjoy your plugin, however it doesn’t work with things like Visual Composer, or Cornerstone. Since the page/post actually has just a shortcode in it, and the_content is generated dynamically. Such that any page listing-out information from an article which is blocked, results in a access denied message.So I ventured into your plugin and wrote some code to make it work properly for these. Hope it finds you well, and in any case I hope it helps others out there in the same boat!
I didn’t document it, but basically it filters the WPQuery post resultants (shows the user only what they are allowed to see), and the taxonomy as well. That way categories are only shown if a post within it is actually accessible.
There are some issues that need worked on to further this I’m sure, But it’s a heck of a good start!functions-content-permissions.php line #104
function members_enable_content_permissions() { .... add_filter('get_terms','members_content_permissions_custom_get_terms',10,3); add_filter('the_posts','members_content_permissions_custom_the_posts',10,3); .... }function members_content_permissions_custom_the_posts($posts,$unk1=null,$unk2=null) { if ( is_admin() ) return $posts; if ( ! is_main_query() ) return $posts; $resultant=array(); $uid=get_current_user_id(); foreach($posts as $post) { if (members_can_user_view_post($uid,$post->ID)) { $resultant[]=$post; } } return $resultant; }function members_content_permissions_custom_get_terms($terms, $taxonomies=null, $args=null) { if ( is_admin() ) return $terms; global $wpdb; if ( !is_array($terms) && count($terms) < 1 ) return $terms; $taxonomy = $taxonomies[0]; $resultant=array(); $uid=get_current_user_id(); foreach($terms as $term) { $allow=false; if ($term->taxonomy == "") { $allow=true; } else { $post_ids_with_tax = $wpdb->get_var("SELECT GROUP_CONCAT(p.ID SEPARATOR ',') FROM ".$wpdb->posts." p JOIN ".$wpdb->term_relationships." rl ON p.ID = rl.object_id WHERE rl.term_taxonomy_id = ".$term->term_id." AND p.post_status = 'publish' GROUP BY p.id"); // 'tis better than looping queries. I would prefer outer joins and case conditionals to make this 10x faster, but your function to verify access already has all the logic in place.. Thus the following... if ($post_ids_with_tax!=null) { $pids=explode(',',$post_ids_with_tax); foreach($pids as $pid) { if (members_can_user_view_post($uid,$pid)) { $allow=true; break; // no need to check additional posts, the user can see at least one post in the category. } } } } if ($allow) $resultant[]=$term; } return $resultant; }
The topic ‘Support for Visual Composer (or any “the loop” processor)’ is closed to new replies.