Merge branch 'master' of https://github.com/tainacan/tainacan
This commit is contained in:
commit
387169d2ee
|
@ -78,23 +78,7 @@ class Collection extends Entity {
|
|||
'slug' => $this->get_slug()
|
||||
],
|
||||
'map_meta_cap' => true,
|
||||
'capabilities' => [
|
||||
'edit_post' => 'edit_'.$this->get_db_identifier(),
|
||||
'read_post' => 'read_'.$this->get_db_identifier(),
|
||||
'delete_post' => 'delete_'.$this->get_db_identifier(),
|
||||
'edit_posts' => 'edit_'.$this->get_db_identifier().'s',
|
||||
'edit_others_posts' => 'edit_others_'.$this->get_db_identifier().'s',
|
||||
'publish_posts' => 'publish_'.$this->get_db_identifier().'s',
|
||||
'read_private_posts' => 'read_private_'.$this->get_db_identifier().'s',
|
||||
'create_posts' => 'create_'.$this->get_db_identifier().'s',
|
||||
'read' => 'read_'.$this->get_db_identifier(),
|
||||
'delete_posts' => 'delete_'.$this->get_db_identifier().'s',
|
||||
'delete_private_posts' => 'delete_private_'.$this->get_db_identifier().'s',
|
||||
'delete_published_posts'=> 'delete_published_'.$this->get_db_identifier().'s',
|
||||
'delete_others_posts' => 'delete_others_'.$this->get_db_identifier().'s',
|
||||
'edit_private_posts' => 'edit_private_'.$this->get_db_identifier().'s',
|
||||
'edit_published_posts' => 'edit_published_'.$this->get_db_identifier().'s'
|
||||
],
|
||||
'capability_type' => $this->get_db_identifier(),
|
||||
'supports' => [
|
||||
'title',
|
||||
'editor',
|
||||
|
@ -191,6 +175,15 @@ class Collection extends Entity {
|
|||
function get_default_view_mode() {
|
||||
return $this->get_mapped_property('default_view_mode');
|
||||
}
|
||||
|
||||
/**
|
||||
* Get collection moderators ids
|
||||
*
|
||||
* @return array
|
||||
*/
|
||||
function get_moderators_ids() {
|
||||
return $this->get_mapped_property('moderators_ids');
|
||||
}
|
||||
|
||||
/**
|
||||
* Get collection DB identifier
|
||||
|
@ -312,5 +305,28 @@ class Collection extends Entity {
|
|||
function set_default_view_mode($value) {
|
||||
$this->set_mapped_property('default_view_mode', $value);
|
||||
}
|
||||
|
||||
/**
|
||||
* Set collection moderators ids
|
||||
*
|
||||
* @param [string] $value
|
||||
* @return void
|
||||
*/
|
||||
function set_moderators_ids($value) {
|
||||
$this->set_mapped_property('moderators_ids', $value);
|
||||
}
|
||||
|
||||
/**
|
||||
* TODO implement the following methods to handle moderators_ids
|
||||
*
|
||||
* set_moderators
|
||||
* get_moderators
|
||||
* (the same as moderators_ids but gets and sets WP_User objects)
|
||||
*
|
||||
* add_moderator_id
|
||||
* remove moderator_id
|
||||
* (add or remove one moderator from the moderators_ids array)
|
||||
*
|
||||
*/
|
||||
|
||||
}
|
||||
|
|
|
@ -100,6 +100,13 @@ class Collections extends Repository {
|
|||
*
|
||||
*
|
||||
*/
|
||||
'moderators_ids' => [
|
||||
'map' => 'meta_multi',
|
||||
'title' => __('Moderators', 'tainacan'),
|
||||
'type' => 'string',
|
||||
'description' => __('The IDs of users assigned as moderators of this collection', 'tainacan'),
|
||||
'validation' => ''
|
||||
],
|
||||
|
||||
]);
|
||||
}
|
||||
|
@ -135,24 +142,8 @@ class Collections extends Repository {
|
|||
'query_var' => true,
|
||||
'can_export' => true,
|
||||
'rewrite' => true,
|
||||
//'capability_type' => Entities\Collection::get_post_type(),
|
||||
'capability_type' => 'tainacan-collection', // hardcode because post_type is in plural
|
||||
'map_meta_cap' => true,
|
||||
'capabilities' => [
|
||||
'read_post' => 'read_tainacan-collection',
|
||||
'read_private_posts' => 'read_private_tainacan-collections',
|
||||
'create_posts' => 'create_tainacan-collections',
|
||||
'publish_posts' => 'publish_tainacan-collections',
|
||||
'delete_post' => 'delete_tainacan-collection',
|
||||
'delete_posts' => 'delete_tainacan-collections',
|
||||
'delete_private_posts' => 'delete_private_tainacan-collections',
|
||||
'delete_published_posts'=> 'delete_published_tainacan-collections',
|
||||
'delete_others_posts' => 'delete_others_tainacan-collections',
|
||||
'edit_post' => 'edit_tainacan-collection',
|
||||
'edit_posts' => 'edit_tainacan-collections',
|
||||
'edit_others_posts' => 'edit_others_tainacan-collections',
|
||||
'edit_private_posts' => 'edit_private_tainacan-collections',
|
||||
'edit_published_posts' => 'edit_published_tainacan-collections'
|
||||
],
|
||||
'supports' => [
|
||||
'title',
|
||||
'editor',
|
||||
|
@ -248,7 +239,6 @@ class Collections extends Repository {
|
|||
'read_private_'.$name.'s',
|
||||
'delete_published_'.$name.'s',
|
||||
'edit_published_'.$name.'s',
|
||||
'edit_published_'.$name,
|
||||
'edit_others_'.$name.'s',
|
||||
'delete_others_'.$name.'s',
|
||||
'read_'.$name.'s',
|
||||
|
@ -278,7 +268,6 @@ class Collections extends Repository {
|
|||
'read_private_'.$name.'s',
|
||||
'delete_published_'.$name.'s',
|
||||
'edit_published_'.$name.'s',
|
||||
'edit_published_'.$name,
|
||||
'edit_others_'.$name.'s',
|
||||
'delete_others_'.$name.'s',
|
||||
'read_'.$name.'s',
|
||||
|
|
|
@ -103,7 +103,7 @@ class Filters extends Repository {
|
|||
'query_var' => true,
|
||||
'can_export' => true,
|
||||
'rewrite' => true,
|
||||
'capability_type' => 'post',
|
||||
'capability_type' => Entities\Filter::get_post_type(),
|
||||
'supports' => [
|
||||
'title',
|
||||
'editor',
|
||||
|
|
|
@ -153,13 +153,7 @@ class Items extends Repository {
|
|||
}
|
||||
|
||||
if (empty($collections)){
|
||||
$wp_query = $Tainacan_Collections->fetch();
|
||||
if( $wp_query->have_posts() ){
|
||||
while ( $wp_query->have_posts() ){
|
||||
$wp_query->the_post();
|
||||
$collections[] = new Entities\Collection( get_the_ID() );
|
||||
}
|
||||
}
|
||||
$collections = $Tainacan_Collections->fetch([], 'OBJECT');
|
||||
}
|
||||
|
||||
if (is_numeric($collections)){
|
||||
|
|
|
@ -132,23 +132,7 @@ class Logs extends Repository {
|
|||
'can_export' => true,
|
||||
'rewrite' => true,
|
||||
'map_meta_cap' => true,
|
||||
'capabilities' => [
|
||||
'edit_post' => 'edit_tainacan-log',
|
||||
'read_post' => 'read_tainacan-log',
|
||||
'delete_post' => 'delete_tainacan-log',
|
||||
'edit_posts' => 'edit_tainacan-logs',
|
||||
'edit_others_posts' => 'edit_others_tainacan-logs',
|
||||
'publish_posts' => 'publish_tainacan-logs',
|
||||
'read_private_posts' => 'read_private_tainacan-logs',
|
||||
'create_posts' => 'create_tainacan-logs',
|
||||
'read' => 'read_tainacan-log',
|
||||
'delete_posts' => 'delete_tainacan-logs',
|
||||
'delete_private_posts' => 'delete_private_tainacan-logs',
|
||||
'delete_published_posts'=> 'delete_published_tainacan-logs',
|
||||
'delete_others_posts' => 'delete_others_tainacan-logs',
|
||||
'edit_private_posts' => 'edit_private_tainacan-logs',
|
||||
'edit_published_posts' => 'edit_published_tainacan-logs'
|
||||
],
|
||||
'capability_type' => Entities\Log::get_post_type(),
|
||||
'supports' => [
|
||||
'title',
|
||||
'editor',
|
||||
|
|
|
@ -167,23 +167,7 @@ class Metadatas extends Repository {
|
|||
'can_export' => true,
|
||||
'rewrite' => true,
|
||||
'map_meta_cap' => true,
|
||||
'capabilities' => [
|
||||
'edit_post' => 'edit_tainacan-metadata',
|
||||
'read_post' => 'read_tainacan-metadata',
|
||||
'delete_post' => 'delete_tainacan-metadata',
|
||||
'edit_posts' => 'edit_tainacan-metadatas',
|
||||
'edit_others_posts' => 'edit_others_tainacan-metadatas',
|
||||
'publish_posts' => 'publish_tainacan-metadatas',
|
||||
'read_private_posts' => 'read_private_tainacan-metadatas',
|
||||
'create_posts' => 'create_tainacan-metadatas',
|
||||
'read' => 'read_tainacan-metadata',
|
||||
'delete_posts' => 'delete_tainacan-metadatas',
|
||||
'delete_private_posts' => 'delete_private_tainacan-metadatas',
|
||||
'delete_published_posts'=> 'delete_published_tainacan-metadatas',
|
||||
'delete_others_posts' => 'delete_others_tainacan-metadatas',
|
||||
'edit_private_posts' => 'edit_private_tainacan-metadatas',
|
||||
'edit_published_posts' => 'edit_published_tainacan-metadatas'
|
||||
],
|
||||
'capability_type' => Entities\Metadata::get_post_type(),
|
||||
'supports' => [
|
||||
'title',
|
||||
'editor',
|
||||
|
|
|
@ -19,6 +19,8 @@ abstract class Repository {
|
|||
//add_action('admin_init', array(&$this, 'init_caps'));
|
||||
add_action('init', array(&$this, 'init_capabilities'), 11);
|
||||
add_filter('tainacan-get-map-'.$this->get_name(), array($this, 'get_default_properties'));
|
||||
|
||||
add_filter('map_meta_cap', array($this, 'map_meta_cap'), 10, 4);
|
||||
}
|
||||
|
||||
/**
|
||||
|
@ -457,12 +459,12 @@ abstract class Repository {
|
|||
}
|
||||
$entity = self::get_entity_by_post($entity);
|
||||
|
||||
$name = $entity::get_post_type();
|
||||
if($name === false) {
|
||||
$post_type = $entity::get_post_type();
|
||||
if($post_type === false) { // There is no post
|
||||
return user_can($user, 'edit_posts');
|
||||
}
|
||||
|
||||
return user_can($user, 'edit_post', $entity);
|
||||
return user_can($user, $entity->cap->edit_post, $entity);
|
||||
}
|
||||
|
||||
/**
|
||||
|
@ -480,9 +482,8 @@ abstract class Repository {
|
|||
}
|
||||
$entity = self::get_entity_by_post($entity);
|
||||
|
||||
$name = $entity::get_post_type();
|
||||
if($name === false)
|
||||
{
|
||||
$post_type = $entity::get_post_type();
|
||||
if($post_type === false) { // There is no post
|
||||
return user_can($user, 'read');
|
||||
}
|
||||
|
||||
|
@ -503,12 +504,12 @@ abstract class Repository {
|
|||
$user = $user->ID;
|
||||
}
|
||||
$entity = self::get_entity_by_post($entity);
|
||||
$name = $entity::get_post_type();
|
||||
if($name === false) {
|
||||
$post_type = $entity::get_post_type();
|
||||
if($post_type === false) { // There is no post
|
||||
return user_can($user, 'delete_posts');
|
||||
}
|
||||
|
||||
return user_can($user, 'delete_post', $entity);
|
||||
return user_can($user, $entity->cap->delete_post, $entity);
|
||||
}
|
||||
|
||||
/**
|
||||
|
@ -525,13 +526,39 @@ abstract class Repository {
|
|||
$user = $user->ID;
|
||||
}
|
||||
$entity = self::get_entity_by_post($entity);
|
||||
$name = $entity::get_post_type();
|
||||
if($name === false) {
|
||||
$post_type = $entity::get_post_type();
|
||||
if($post_type === false) { // There is no post
|
||||
return user_can($user, 'publish_posts');
|
||||
}
|
||||
|
||||
return user_can($user, 'publish_post', $entity);
|
||||
return user_can($user, $entity->cap->publish_posts, $entity);
|
||||
}
|
||||
|
||||
/**
|
||||
* Filter to handle special permissions
|
||||
*
|
||||
* @see https://developer.wordpress.org/reference/hooks/map_meta_cap/
|
||||
*
|
||||
*/
|
||||
public function map_meta_cap($caps, $cap, $user_id, $args) {
|
||||
|
||||
// Filters meta caps edit_tainacan-collection and check if user is moderator
|
||||
$collection_cpt = get_post_type_object(Entities\Collection::get_post_type());
|
||||
if ($cap == $collection_cpt->cap->edit_post) {
|
||||
$entity = new Entities\Collection($args[0]);
|
||||
if ($entity) {
|
||||
$moderators = $entity->get_moderators_ids();
|
||||
if (in_array($user_id, $moderators)) {
|
||||
// if user is moderator, we clear the current caps
|
||||
// (that might fave edit_others_posts) and leave only edit_posts
|
||||
$caps = [$collection_cpt->cap->edit_posts];
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
return $caps;
|
||||
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
?>
|
|
@ -97,23 +97,7 @@ class Taxonomies extends Repository {
|
|||
'can_export' => true,
|
||||
'rewrite' => true,
|
||||
'map_meta_cap' => true,
|
||||
'capabilities' => [
|
||||
'edit_post' => 'edit_tainacan-taxonomy',
|
||||
'read_post' => 'read_tainacan-taxonomy',
|
||||
'delete_post' => 'delete_tainacan-taxonomy',
|
||||
'edit_posts' => 'edit_tainacan-taxonomies',
|
||||
'edit_others_posts' => 'edit_others_tainacan-taxonomies',
|
||||
'publish_posts' => 'publish_tainacan-taxonomies',
|
||||
'read_private_posts' => 'read_private_tainacan-taxonomies',
|
||||
'create_posts' => 'create_tainacan-taxonomies',
|
||||
'read' => 'read_tainacan-taxonomy',
|
||||
'delete_posts' => 'delete_tainacan-taxonomies',
|
||||
'delete_private_posts' => 'delete_private_tainacan-taxonomies',
|
||||
'delete_published_posts'=> 'delete_published_tainacan-taxonomies',
|
||||
'delete_others_posts' => 'delete_others_tainacan-taxonomies',
|
||||
'edit_private_posts' => 'edit_private_tainacan-taxonomies',
|
||||
'edit_published_posts' => 'edit_published_tainacan-taxonomies'
|
||||
],
|
||||
'capability_type' => Entities\Taxonomy::get_post_type(),
|
||||
'supports' => [
|
||||
'title',
|
||||
'editor',
|
||||
|
|
Loading…
Reference in New Issue