Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

LTW Editor custom user role #156

Merged
merged 3 commits into from
Jul 2, 2020
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -17,6 +17,7 @@
'/taxonomies/project-status.php',
'/taxonomies/project-org-type.php',
'/taxonomies/project-category.php',
'/user-roles/user-roles.php'
);
foreach ( $includes as $include ) {
if ( 0 === validate_file( $include ) ) {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -60,6 +60,8 @@ function projects_init() {
// 'page-attributes',
// 'post-formats',
),
'capability_type' => array( 'project', 'projects' ),
'map_meta_cap' => true,
) );

}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -14,10 +14,10 @@ function ltw_content_categories_init() {
'query_var' => true,
'rewrite' => true,
'capabilities' => array(
'manage_terms' => 'edit_posts',
'edit_terms' => 'edit_posts',
'delete_terms' => 'edit_posts',
'assign_terms' => 'edit_posts',
'manage_terms' => 'edit_projects',
'edit_terms' => 'edit_projects',
'delete_terms' => 'edit_projects',
'assign_terms' => 'edit_projects',
),
'labels' => array(
'name' => __( 'Content Categories', 'current-ltw-projects' ),
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -14,10 +14,10 @@ function project_org_type_init() {
'query_var' => true,
'rewrite' => true,
'capabilities' => array(
'manage_terms' => 'edit_posts',
'edit_terms' => 'edit_posts',
'delete_terms' => 'edit_posts',
'assign_terms' => 'edit_posts',
'manage_terms' => 'edit_projects',
'edit_terms' => 'edit_projects',
'delete_terms' => 'edit_projects',
'assign_terms' => 'edit_projects',
),
'labels' => array(
'name' => __( 'Organization Types', 'current-ltw-projects' ),
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -14,10 +14,10 @@ function ltw_status_init() {
'query_var' => true,
'rewrite' => true,
'capabilities' => array(
'manage_terms' => 'edit_posts',
'edit_terms' => 'edit_posts',
'delete_terms' => 'edit_posts',
'assign_terms' => 'edit_posts',
'manage_terms' => 'edit_projects',
'edit_terms' => 'edit_projects',
'delete_terms' => 'edit_projects',
'assign_terms' => 'edit_projects',
),
'labels' => array(
'name' => __( 'Status', 'current-ltw-projects' ),
Expand Down
65 changes: 65 additions & 0 deletions wp-content/plugins/current-ltw-projects/user-roles/user-roles.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,65 @@
<?php

function ltw_projects_user_roles_init() {
add_role(
'ltw_editor',
__( 'LTW Projects Editor', 'current-ltw-projects' ),
array(
'read' => true,
'edit_posts' => false,
'delete_posts' => false,
'publish_posts' => false,
'upload_files' => true,
'read_attachments' => true,
)
);
}
add_action( 'init', 'ltw_projects_user_roles_init' );

function ltw_projects_add_role_capabilities() {

$roles = array( 'ltw_editor', 'editor', 'administrator' );

foreach($roles as $the_role) {

$role = get_role($the_role);

$role->add_cap( 'read' );
$role->add_cap( 'read_project');
$role->add_cap( 'read_private_projects' );
$role->add_cap( 'edit_project' );
$role->add_cap( 'edit_projects' );
$role->add_cap( 'edit_others_projects' );
$role->add_cap( 'edit_published_projects' );
$role->add_cap( 'publish_projects' );
$role->add_cap( 'delete_projects' );
$role->add_cap( 'delete_others_projects' );
$role->add_cap( 'delete_private_projects' );
$role->add_cap( 'delete_published_projects' );

}

}
add_action( 'admin_init', 'ltw_projects_add_role_capabilities', 999 );

/**
* Unregister LTW taxonomies from Largo CFTL landing page object type
* so that the new ltw_editor user role doesn't have access to series landing pages
*
* @see https://github.com/INN/largo/blob/c41d8519370b48a6e53ce36b3b516d3e54e39d66/inc/wp-taxonomy-landing/functions/cftl-admin.php#L77-L84
* @see https://github.com/INN/umbrella-currentorg/pull/156#issuecomment-652672358
*/
function ltw_projects_unregister_taxonomies_from_cftl_landing() {

$ltw_projects_taxonomies = array(
'project-category',
'project-org-type',
'project-status'
);

foreach( $ltw_projects_taxonomies as $taxonomy ) {
unregister_taxonomy_for_object_type( $taxonomy, 'cftl-tax-landing' );
}

}
add_action( 'init', 'ltw_projects_unregister_taxonomies_from_cftl_landing', 999999 );