Forced assignment of default category is eliminated (fixed) in Role Scoper 1.3.51
Thanks Kevin,
My work around was to give them privileges to uncategorised but I’m please it’s fixed.
Best
Jim
My WP site w/Role Scoper 1.3.51 limits members to one category each, and we have the repeated problem that Posts have their category reset to Uncategorized, even when it is edited without changing its categories at all.
I do rely on the Role Scoper to limit access to Post’s by Category, and it is working well, but this resetting to Uncategorized is a big problem.
We have the latest version of RS — 1.3.51, which includes the change log “Fixed: Default category is always stored when Category Restrictions prevent user from selecting some categories.” Does “Default category” mean “Uncategorized”? If so, it seems like the code is recently adjusted to do this more consistently, when I’d prefer that it not modify categories at all.
There may be complex logic to handle cases where Posts are edited to to an unauthorized category, but that’s not the situation on my site (in fact it has Post Editor adjustments to prevent access to the Category edit fields.) Is there any RS configuration that can prevent it from resetting categories to default/uncategorized?
After further debugging, I see that Role Scoper is not at fault.
The problem was in our own theme code for setting up post categories, which had a call to wp_set_post_categories with a single Category ID number (rather than the correct array of ID’s) as the second arg. This was incorrect. It went undetected because it seemed to be performing the function property on post creation, but I suppose it was really RS that was doing that work.
Well, the problem has returned: a post is being reset to Uncategorized after being edited, with no recognized reason to change its category.
This time the caller is Role Scoper, so I’m including the traceback in case it may help track down a real problem. It appears to be triggered not by the post edit directly, but by filters that go through the Contact Form 7 plugin. Here is the basic traceback:
- wp_set_object_terms (setting post to Uncategorized)
- plugins/role-scoper/cap-interceptor_rs.php, [line] => 44 [function] => _flt_user_has_cap
- [function] => flt_user_has_cap, [class] => CapInterceptor_RS
- wp-includes/plugin.php, [line] => 170, [function] => call_user_func_array
- capabilities.php, [line] => 871, [function] => apply_filters
- [function] => has_cap, [class] => WP_User
- wp-includes/capabilities.php, [line] => 1195, [function] => call_user_func_array
- plugin.php, [line] => 875, [function] => current_user_can
- wp-includes/plugins, contact-form-7/admin/admin.php, [line] => 115, [function] => add_menu_page
- [function] => wpcf7_admin_menu
- wp-includes/plugin.php, [line] => 405, [function] => call_user_func_array
- includes/menu.php, [line] => 97, [function] => do_action
- wp-admin/menu.php, [line] => 234
- wp-admin/admin.php, [line] => 106
- wp-admin/post.php, [line] => 12
WordPress 3.3.1
Role Scoper 1.3.51
Contact Form 7 3.0.2.1
The wp_set_object_terms call is in cap-interceptor_rs.php, around line 516. Try changing that preceding conditional as follows:
change:
if ( ( $set_terms != $stored_terms ) && $set_terms && ( $set_terms != array(1) ) ) {
to:
if ( ( $set_terms != $stored_terms ) && $set_terms && ( $set_terms != array(1) ) ) {
If you are wondering about removing the wp_set_object_terms call completely, be aware that would cause other problems. Under some conditions, an editing operation which should be allowed based on Category Roles will fail unless the new category association is stored prior to WP’s edit capability checks.
Thanks for the response. Your suggestion may work — I actually entered a wordier patch which was specific to my purpose, but overall seems similar to yours.
change:
wp_set_object_terms( $object_id, $set_terms, $taxonomy );
to:
// Don't allow setting category to Uncategorized
$isok = true;
if ($taxonomy == 'category') {
if (is_array($set_terms)) {
if (count($set_terms) == 1) {
if ($set_terms[0] == 1) {
$isok = false;
}
}
}
}
if ($isok) {
wp_set_object_terms( $object_id, $set_terms, $taxonomy );
}