[wp-hackers] Roles & Access

Frank Bueltge frank at bueltge.de
Thu Sep 1 12:21:04 UTC 2011


Yes, its possible.

CPT have an param for an object and you use this in your custom role.
See on the param capabilities of the args in function register_post_type()

i  set the opbejcts to this param in an array for different rights:
public $post_type_1 = 'archiv'
			$capabilities = array(
				'edit_post'          => 'edit_' . $this->post_type_1,
				'edit_posts'         => 'edit_' . $this->post_type_1 . 's',
				'edit_others_posts'  => 'edit_others_' . $this->post_type_1 . 's',
				'publish_posts'      => 'publish_' . $this->post_type_1 . 's',
				'read_post'          => 'read_' . $this->post_type_1,
				'read_private_posts' => 'read_private_' . $this->post_type_1 . 's',
				'delete_post'        => 'delete_' . $this->post_type_1
			);

You can create the roles with your objects via plugin, like members or
a small function in your plugin on the activation the plugin:
			foreach ( $this->todo_roles as $role ) {
				$wp_roles->add_cap( $role, 'edit_'			. $this->post_type_1 );
				$wp_roles->add_cap( $role, 'edit_'			. $this->post_type_1 . 's' );
				$wp_roles->add_cap( $role, 'edit_others_'	. $this->post_type_1 . 's' );
				$wp_roles->add_cap( $role, 'publish_'		. $this->post_type_1 . 's' );
				$wp_roles->add_cap( $role, 'read_'			. $this->post_type_1 );
				$wp_roles->add_cap( $role, 'read_private_'	. $this->post_type_1 . 's' );
				$wp_roles->add_cap( $role, 'delete_'		. $this->post_type_1 );
				$wp_roles->add_cap( $role, 'manage_'		. $this->taxonomy_type_1 );
			}
			
			foreach ( $this->read_roles as $role ) {
				$wp_roles->add_cap( $role, 'read_' . $this->post_type_1 );
				$wp_roles->add_cap( $role, 'read_' . $this->post_type_1 );
				$wp_roles->add_cap( $role, 'read_' . $this->post_type_1 );
			}

Reagrds
Frank



On Thu, Sep 1, 2011 at 2:11 PM, Charel Büchler
<charel.buechler at gmail.com> wrote:
> Charel Büchler


More information about the wp-hackers mailing list