PHP code example of alleyinteractive / wp-caper

1. Go to this page and download the library: Download alleyinteractive/wp-caper library. Choose the download type require.

2. Extract the ZIP file and open the index.php.

3. Add this code to the index.php.
    
        
<?php
require_once('vendor/autoload.php');

/* Start to develop here. Best regards https://php-download.com/ */

    

alleyinteractive / wp-caper example snippets




use Alley\WP\Caper;

Caper::grant_to( 'editor' )->primitives( 'edit_theme_options' );
Caper::deny_to( 'administrator' )->primitives( 'manage_options' );



use Alley\WP\Caper;

Caper::grant_to( 'author' )->caps_for( 'page' );
Caper::deny_to( 'editor' )->caps_for( 'category' );



use Alley\WP\Caper;

Caper::grant_to( 'author' )
    ->caps_for( 'page' )
    ->except( 'delete_posts' ); // Pass "generic" keys; the actual capability names will be determined automatically.

Caper::deny_to( 'editor' )
    ->caps_for( 'category' )
    ->except( 'assign_terms' ); // Pass "generic" keys; the actual capability names will be determined automatically.



use Alley\WP\Caper;

Caper::deny_to( 'editor' )
    ->caps_for( 'category' )
    ->only( 'delete_terms' );

Caper::grant_to( 'author' )
    ->only( 'create_posts' ) // `only()` and `except()` can occur in either order.
    ->caps_for( 'page' );



use Alley\WP\Caper;

Caper::grant_to( 'author' )
    ->caps_for( [ 'post', 'page' ] );

Caper::grant_to( 'contributor' )
    ->caps_for( [ 'post', 'category' ] );

Caper::deny_to( 'editor' )
    ->caps_for( [ 'post', 'page' ] )
    ->except( 'edit_posts' );

Caper::deny_to( 'administrator' )
    ->caps_for( [ 'page', 'category' ] )
    ->only( [ 'edit_posts', 'edit_published_posts', 'manage_terms' ] );



use Alley\WP\Caper;

Caper::grant_to_all()->primitives( 'moderate_comments' );
Caper::deny_to_all()->primitives( 'activate_plugins' );



use Alley\WP\Caper;

Caper::grant_to_all()
    ->caps_for( 'post' )
    ->then_deny_to( [ 'subscriber', 'contributor' ] );

Caper::deny_to_all()
    ->caps_for( 'category' )
    ->then_grant_to( 'administrator' );



use Alley\WP\Caper;

Caper::grant_to( 'editor' )->primitives( 'manage_options' )->at_priority( 99 );



use Alley\WP\Caper;

\register_post_type(
    'review',
    [
        // ...
        'capability_type' => 'post',
    ]
);

Caper::deny_to( 'editor' )->caps_for( 'review' );



\register_post_type(
    'review',
    [
        // ...
        'capability_type' => 'review',
    ]
);

\register_taxonomy(
    'rating',
    'review',
    [
        // ...
        'capabilities' => [
            'manage_terms' => 'manage_ratings',
            'edit_terms'   => 'edit_ratings',
            'delete_terms' => 'delete_ratings',
            'assign_terms' => 'assign_ratings',
        ]
    ]
);