Skip to content
This repository has been archived by the owner on Jan 21, 2020. It is now read-only.

Commit

Permalink
Added post capability limiter
Browse files Browse the repository at this point in the history
  • Loading branch information
Roelof Roos committed Oct 8, 2018
1 parent 4e38f22 commit f0b44be
Showing 1 changed file with 34 additions and 0 deletions.
34 changes: 34 additions & 0 deletions gumbo-millennium/src/Hooks/PostTypeHandler.php
Original file line number Diff line number Diff line change
Expand Up @@ -32,6 +32,9 @@ public function bind() : void
{
// Add custom post types
add_action('init', [$this, 'init']);

// De-register capabilities
add_action('admin_init', [$this, 'restrictPostTypeCapabilities']);
}

/**
Expand All @@ -48,4 +51,35 @@ public function init() : void
}
}
}

/**
* Restrict capabilities for post types, such as thumbnails on pages and comments on all pages.
*
* @return void
*/
public function restrictPostTypeCapabilities() : void
{
/*
* All core features are directly associated with a functional area of the edit
* screen, such as the editor or a meta box. Features include: 'title', 'editor',
* 'comments', 'revisions', 'trackbacks', 'author', 'excerpt', 'page-attributes',
* 'thumbnail', 'custom-fields', and 'post-formats'.
*/
$allowedCapabilityMap = [
'comments' => ['activity'],
'trackbacks' => null,
'thumbnail' => ['posts', 'attachments'],
'post-formats' => null
];

// Check all capabilities, and remove all non-matching ones
foreach ($allowedCapabilityMap as $capability => $types) {
$currentTypes = get_post_types_by_support($capability);
foreach ($currentTypes as $type) {
if ($types === null || !in_array($type, $types)) {
remove_post_type_support($type, $capability);
}
}
}
}
}

0 comments on commit f0b44be

Please sign in to comment.