@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…