Resources

My Agape try

Your Agape try


Support Forum

You must be logged in to post Login Register

Search 
Search Forums:


 




Function Test for Permissions?

UserPost

12:36 pm
July 14, 2010


Daljo628

Member

Lancaster, PA

posts 2

1

Hey, just wanted to say that we absolutely love RoleScoper!  It's a fantastic solution that's solved (or made great strides towards solving) what happens to be (in my humble opinion) one of WordPress's greatest failings.

I've spent the past few months building a custom WordPress plugin for a client, that will serve as the back-end event editor for a Mobile App run off the iPhone and Android devices.  We used EventCalendar3 initially, but are moving away from that presently towards an internalized solution.  One thing that we needed to ensure was that our users (companies/individuals that want to publish events to our app, not end-users) could only post or view in their own assigned category/categories.

To simplify the user experience, we integrated post/event creation and modification into a custom WordPress theme.  RoleScoper has been fantastic with how it plugs in to the current_user_can if-checks for whether the logged in user can edit_post (specified post #).

My question is this:  Is there a function internal to RoleScoper, or integration with current_user_can, that would permit the following if-checks:

  • Can the current user view items [drafts/posts] in category # ((X))
  • Can the current user manage category # ((X))
  • Can the current user create a new draft in category # ((X))
  • Can the current user modify draft post # ((X))
  • Can the current user publish draft post # ((X))
  • Can the current user modify published post # ((X))

I think that's it … the WP current_user_can function is rather badly documented from what I've found so far, so I've been bumbling my way through as best I can, but figured I'd best turn to the person who definitely knows what they're talking about on this.

One other minor thing … we're using Categories to bulk-import and arrange things, with the number of categories easily reaching into the thousands.  I've found that I can just comment the function calls to ScoperAdminBulkLib::taxonomy_scroll_links in the source code of both section_restrictions.php and section_roles.php — but any time I upgrade the plugin, that just gets overridden.  Perhaps that could be toggle-able via the control panel?  I realize it'll only be useful to a vast minority of users, and would be an unnecessary complication, but it was just something that had occurred to me.

Thanks again for all your fantastic work on this plugin, and if I can ever lend a second pair of eyes at some code (ZOMG I FORGOT A FREAKING SEMICOLON AND WASTED HOW MANY HOURS TRYING TO FIND IT WHAT?!?!!) let me know and I'd be glad to help out.

8:45 pm
August 2, 2010


Kevin

Admin

posts 2386

2

Daljo628 said:

Can the current user view items [drafts/posts] in category # ((X))

global $scoper;
$can_do = in_array( $cat_id, $scoper->qualify_terms( 'read', 'category' ) );

 
 

Can the current user manage category # ((X))

$can_do = current_user_can( 'manage_categories', $cat_id );

 
 

Can the current user create a new draft in category # ((X))

// RS requires edit_posts capability in WP role or RS General Role to add any new post
if ( awp_user_can( 'edit_posts', 'blog' ) ) {
   // now confirm edit_posts capability in specific category
   global $scoper;
   $can_do = in_array( $cat_id, $scoper->qualify_terms( 'edit_posts', 'category' ) );
}

 
 

Can the current user modify draft post # ((X))

$can_do = current_user_can( 'edit_post', $post_id );

 
 

Can the current user publish draft post # ((X))

$can_do = current_user_can( 'publish_posts', $post_id );

 
 

Can the current user modify published post # ((X))

$can_do = current_user_can( 'edit_post', $post_id );

 
 

One other minor thing … we're using Categories to bulk-import and arrange things, with the number of categories easily reaching into the thousands.  I've found that I can just comment the function calls to ScoperAdminBulkLib::taxonomy_scroll_links in the source code of both section_restrictions.php and section_roles.php — but any time I upgrade the plugin, that just gets overridden.  Perhaps that could be toggle-able via the control panel?

As of version 1.2.8.beta.2, scroll links in the Term Roles / Restrictions bulk admin form are suppressed if terms total over 300 (with that limit adjustable via constant definition).

1:21 pm
August 16, 2010


Daljo628

Member

Lancaster, PA

posts 2

3

Thank you, sir!

One question that I am having some problems with … whenever I try to do something like …

current_user_can( 'manage_categories', $thisCategory )

I get an error like:

Fatal error: Call to a member function user_can_admin_terms() on a non-object in /home/directory/public_html/wp-content/plugins/role-scoper/cap-interceptor_rs.php on line 370

Any thoughts?


3:59 pm
August 16, 2010


Kevin

Admin

posts 2386

4

Thanks for reporting that bug (which only applies when the manage_categories capability is checked from the front end. Try changing that line in cap-interceptor_rs.php as follows:

change:

if ( $scoper->admin->user_can_admin_terms($object_type, $object_id, $user) ) {

to:

require_once( 'admin/permission_lib_rs.php' );
if ( user_can_admin_terms_rs($object_type, $object_id, $user) ) {


About the Agapetry forum

Currently Online:

12 Guests

Maximum Online: 150

Forums:

Groups: 2

Forums: 7

Topics: 1185

Posts: 5380

Members:

There are 1176 members

There are 1 guests


Kevin has made 2386 posts

Top Posters:

metal450 - 152

Ragnar - 105

YikYak - 70

whiteorb - 44

Daisy - 35

Administrator: Kevin | Moderators: Kevin