Resources

My Agape try

Your Agape try


Support Forum

You must be logged in to post Login Register

Search 
Search Forums:


 




Wordpress template tag - the_category

UserPost

1:14 pm
February 23, 2009


ericalynn

New Member

posts 1

1

Is it possible to restrict the_category to only show categories readers have permission to read? 


ie. If the reader has permission to read category B, but not category C .. but the post is posted in A, B & C .. then the post should show something like "posted in A, B" .. right now it will show A, B, C and the link to C will come up as 404.


I hope that makes sense, thank you!

1:50 pm
February 23, 2009


Kevin

Admin

posts 2402

2

Sure, this was bound to come up eventually. Currently WordPress does not include a convenient hook, so you should begin by hacking wp-includes/category-template.php as follows:

near the top of function get_the_category_list, change:

$categories = get_the_category( $post_id );

to:

$categories = apply_filters( 'get_the_category_for_list', get_the_category( $post_id ) );

Next, modify plugins/role-scoper/hardway/hardway_rs.php as follows:

above class ScoperHardway, add:

add_filter('get_the_category_for_list', 'scoper_get_the_category');

function scoper_get_the_category( $cats ) {
  $readable_cats = apply_filters( 'get_terms', array(), 'category', array('fields' => 'ids', 'skip_teaser' => true) );

  foreach ( $cats as $key => $cat )
    if ( ! in_array($cat->cat_ID, $readable_cats) )
      unset( $cats[$key] );

  return $cats;
}

To make this work with the Hidden Content Teaser enabled, you will also need to further modify hardway_rs.php as follows:

change:

$doing_teaser = ( ! is_admin() && ! defined('XMLRPC_REQUEST') && scoper_get_otype_option('do_teaser', 'post') );

to:

$doing_teaser = ( ! is_admin() && ! defined('XMLRPC_REQUEST') && empty($skip_teaser) && scoper_get_otype_option('do_teaser', 'post') );

I'll request that hook be added to the WordPress code. If that happens, this feature will be built into Role Scoper starting with the next version.


About the Agapetry forum

Currently Online:

15 Guests

Maximum Online: 150

Forums:

Groups: 2

Forums: 7

Topics: 1186

Posts: 5409

Members:

There are 1176 members

There are 1 guests


Kevin has made 2402 posts

Top Posters:

metal450 - 159

Ragnar - 105

YikYak - 70

whiteorb - 44

Daisy - 35

Administrator: Kevin | Moderators: Kevin