Skip to content

Commit

Permalink
Setup capabilities for header & navigation CPTs
Browse files Browse the repository at this point in the history
  • Loading branch information
oakesjosh committed Feb 28, 2024
1 parent 9cf2748 commit a6299d8
Show file tree
Hide file tree
Showing 2 changed files with 52 additions and 0 deletions.
26 changes: 26 additions & 0 deletions includes/header/class-kadence-header-cpt.php
Original file line number Diff line number Diff line change
Expand Up @@ -35,6 +35,8 @@ public function __construct() {
// Register the post type.
add_action( 'init', array( $this, 'register_post_type' ), 2 );
add_action( 'init', array( $this, 'register_meta' ), 20 );
add_filter( 'user_has_cap', array( $this, 'filter_post_type_user_caps' ) );

}

/**
Expand Down Expand Up @@ -106,6 +108,30 @@ public function meta_auth_callback() {
return current_user_can( 'edit_kadence_header' );
}

/**
* Filters the capabilities of a user to conditionally grant them capabilities for managing headers.
*
* Any user who can 'edit_others_pages' will have access to manage headers.
*
* @param array $allcaps A user's capabilities.
* @return array Filtered $allcaps.
*/
public function filter_post_type_user_caps( $allcaps ) {
if ( isset( $allcaps['edit_others_pages'] ) ) {
$allcaps['edit_kadence_header'] = $allcaps['edit_others_pages'];
$allcaps['edit_others_kadence_header'] = $allcaps['edit_others_pages'];
$allcaps['edit_published_kadence_header'] = $allcaps['edit_others_pages'];
$allcaps['edit_private_kadence_header'] = $allcaps['edit_others_pages'];
$allcaps['delete_kadence_header'] = $allcaps['edit_others_pages'];
$allcaps['delete_others_kadence_header'] = $allcaps['edit_others_pages'];
$allcaps['delete_published_kadence_header'] = $allcaps['edit_others_pages'];
$allcaps['delete_private_kadence_header'] = $allcaps['edit_others_pages'];
$allcaps['publish_kadence_header'] = $allcaps['edit_others_pages'];
$allcaps['read_private_kadence_header'] = $allcaps['edit_others_pages'];
}
return $allcaps;
}

public function register_meta() {
$register_meta = array(
array(
Expand Down
26 changes: 26 additions & 0 deletions includes/navigation/class-kadence-navigation-cpt.php
Original file line number Diff line number Diff line change
Expand Up @@ -29,6 +29,7 @@ public function __construct() {
add_action( 'init', array( $this, 'register_post_type' ), 2 );
// Register the meta settings for from post.
add_action( 'init', array( $this, 'register_meta' ), 20 );
add_filter( 'user_has_cap', array( $this, 'filter_post_type_user_caps' ) );
}

/**
Expand Down Expand Up @@ -109,6 +110,31 @@ public function meta_auth_callback() {
return current_user_can( 'edit_kadence_navigation' );
}


/**
* Filters the capabilities of a user to conditionally grant them capabilities for managing navigations.
*
* Any user who can 'edit_others_pages' will have access to manage navigations.
*
* @param array $allcaps A user's capabilities.
* @return array Filtered $allcaps.
*/
public function filter_post_type_user_caps( $allcaps ) {
if ( isset( $allcaps['edit_others_pages'] ) ) {
$allcaps['edit_kadence_navigation'] = $allcaps['edit_others_pages'];
$allcaps['edit_others_kadence_navigation'] = $allcaps['edit_others_pages'];
$allcaps['edit_published_kadence_navigation'] = $allcaps['edit_others_pages'];
$allcaps['edit_private_kadence_navigation'] = $allcaps['edit_others_pages'];
$allcaps['delete_kadence_navigation'] = $allcaps['edit_others_pages'];
$allcaps['delete_others_kadence_navigation'] = $allcaps['edit_others_pages'];
$allcaps['delete_published_kadence_navigation'] = $allcaps['edit_others_pages'];
$allcaps['delete_private_kadence_navigation'] = $allcaps['edit_others_pages'];
$allcaps['publish_kadence_navigation'] = $allcaps['edit_others_pages'];
$allcaps['read_private_kadence_navigation'] = $allcaps['edit_others_pages'];
}
return $allcaps;
}

public function register_meta() {
$register_meta = array(
array(
Expand Down

0 comments on commit a6299d8

Please sign in to comment.