• Love the plugin. Great way to have different views of categories based on user name or role. But What if I have pages as well? How can I restrict those based on user name and category? And then I have not even mentioned tags yet, but I understood there is a plugin for that. The reason I ask about the page restriction option is that I have not found an option for that. And the Role Scoper plugin does not do the trick either as it seems to ignore the new role I created using the Members plugin. Any tips are very welcome!

    https://www.ads-software.com/extend/plugins/restrict-categories/

Viewing 8 replies - 1 through 8 (of 8 total)
  • Plugin Author Matthew Muro

    (@mmuro)

    If you have registered your categories for Pages, then it should restrict them.

    Plugin Author Matthew Muro

    (@mmuro)

    function add_category_box_on_page(){
    add_meta_box('categorydiv', __('Categories'), 'post_categories_meta_box', 'page', 'side', 'low');
    }
    
    add_action('admin_menu', 'add_category_box_on_page');

    I added that to my theme’s function.php file, went into Restrict Categories and selected a few categories to restrict and only those selected showed up in the box.

    Thread Starter Rhand

    (@rhand)

    OK, thanks. Will check this out asap.

    @mmuro: Also thanks a lot for the plugin, works fine with standard WP 3.2.1!

    Came here to look for a fix for two problems with my enhanced site:

    1. Wrong/no categories in combination with WPML Multilingual CMS plugin (more or less the standard plugin for multi-language WordPress sites).

    2. Support for categories with my “custom post types” which I added with Custom Post Type UI plugin.

    Did not find anything, so I took a look at the plugin itself, it is well documented so I immediately saw where the problems were. Here my contribution to your development.

    1. Support for WPML plugin in public function posts():

    $this->cat_list = '';	/* Ov3rfly, added, avoids notice in strict debug */
    /* Selected categories for User overwrites Roles selection */
    if ( is_array( $settings_user ) && !empty( $settings_user[ $user_login . '_user_cats' ] ) ) {
    	/* Build the category list */
    	foreach ( $settings_user[ $user_login . '_user_cats' ] as $category ) {
    		/* old: $this->cat_list .= get_term_by( 'slug', $category, 'category' )->term_id . ','; */
    		/* Ov3rfly new: */
    		$_id = get_term_by( 'slug', $category, 'category' )->term_id;
    		if ( function_exists('icl_object_id') ) {
    			$_id = icl_object_id( $_id, 'category', true );
    		}
    		$this->cat_list .= $_id . ',';
    		/* end of new */
    	}
    	$this->cat_filters( $this->cat_list );
    }
    else {
    	foreach ( $user_cap as $key ) {
    		/* Make sure the settings from the DB isn't empty before building the category list */
    		if ( is_array( $settings ) && !empty( $settings[ $key . '_cats' ] ) ) {
    			/* Build the category list */
    			foreach ( $settings[ $key . '_cats' ] as $category ) {
    				/* old: $this->cat_list .= get_term_by( 'slug', $category, 'category' )->term_id . ','; */
    				/* Ov3rfly new: */
    				$_id = get_term_by( 'slug', $category, 'category' )->term_id;
    				if ( function_exists('icl_object_id') ) {
    					$_id = icl_object_id( $_id, 'category', true );
    				}
    				$this->cat_list .= $_id . ',';
    				/* end of new */
    			}
    		}
    		$this->cat_filters( $this->cat_list );
    	}
    }

    More about the WPML-API here.

    2. Support for “custom post types” in public function __construct():

    /* old: if ( $post_type == false || $post_type == 'post' ) { */
    /* Ov3rfly new: */
    if ( $post_type == false || $post_type == 'post' || in_array($post_type, array('my_custom_type_1', 'my_custom_type_2')) ) {

    The custom post types are hardcoded here, as the wordpress api did not know yet about my types during construction of your plugin. Maybe it is possible to do the add_action(Where the magic happens) always and move the $post_type check inside public function posts(), then you could add an options-tab for custom post types selection or a checkbox for all custom types which you can get like this:

    function rc_get_custom_post_types() {
    	$rc_custom_post_types = array();
    	$args = array(
    		'public'   => true,
    		'_builtin' => false
    	);
    	$post_types = get_post_types($args, 'names');
    		foreach ($post_types as $post_type ) {
    			$rc_custom_post_types[] = $post_type;
    	}
    	return $rc_custom_post_types;
    }

    I first planned to solve this with Role Scoper, but it can not hide the categories and has other problems with WPML. And for my needs it was just overkill, so your plugin came in handy! Keep the work, it is appreciated! Looking for an update with above fixes…

    Plugin Author Matthew Muro

    (@mmuro)

    Great! Thanks for contributing. I’ll take a look more closely with your code soon.

    50% resolved, “Support for WPML plugin” fix is included in Version 2.3

    This is great Ov3rfly!
    Your update to work on Custom Post Types did exactly what I was looking for.

    Thanks.

    It would be great if this was built-in to the actual plugin later on.
    Great work!

    can you explain again how can i work with custom post type as i try to do the previous steps but i can’t find the expected result??

Viewing 8 replies - 1 through 8 (of 8 total)
  • The topic ‘Extension of "Restrict Categories" Plugin to cover Pages’ is closed to new replies.