Commit c9fc23dc authored by John James Jacoby's avatar John James Jacoby
Browse files

Bump to 0.1.4.

Introduce better capability mapping
parent 4a3700ad
......@@ -690,7 +690,7 @@ class WP_Event_Calendar_Month_Table extends WP_List_Table {
private function get_pointer_title( $post = false ) {
// Title links to edit
if ( current_user_can( 'edit_post', $post->ID ) ) {
if ( current_user_can( 'edit_event', $post->ID ) ) {
$retval = '<a href="' . esc_url( get_edit_post_link( $post->ID ) ) . '">' . esc_js( $post->post_title ) . '</a>';
// No title link
......
<?php
/**
* Event Capabilities
*
* @package Calendar/Events/Capabilities
*/
// Exit if accessed directly
defined( 'ABSPATH' ) || exit;
/**
* Maps event capabilities
*
* @since 0.1.4
*
* @param array $caps Capabilities for meta capability
* @param string $cap Capability name
* @param int $user_id User id
* @param array $args Arguments
*
* @return array Actual capabilities for meta capability
*/
function wp_event_calendar_meta_caps( $caps = array(), $cap = '', $user_id = 0, $args = array() ) {
// What capability is being checked?
switch ( $cap ) {
// Reading
case 'read_event' :
$caps = array( 'read' );
break;
// Publishing
case 'publish_events' :
// Editing
case 'edit_events' :
case 'edit_others_events' :
case 'edit_event' :
// Deleting
case 'delete_event' :
case 'delete_events' :
case 'delete_others_events' :
$caps = array( 'list_users' );
break;
}
return apply_filters( 'wp_event_calendar_meta_caps', $caps, $cap, $user_id, $args );
}
/**
* Maps event type capabilities
*
* @since 0.1.4
*
* @param array $caps Capabilities for meta capability
* @param string $cap Capability name
* @param int $user_id User id
* @param array $args Arguments
*
* @return array Actual capabilities for meta capability
*/
function wp_event_calendar_type_meta_caps( $caps, $cap, $user_id, $args ) {
// What capability is being checked?
switch ( $cap ) {
case 'manage_event_types' :
case 'edit_event_types' :
case 'delete_event_types' :
case 'assign_event_types' :
$caps = array( 'list_users' );
break;
}
return apply_filters( 'wp_event_calendar_type_meta_caps', $caps, $cap, $user_id, $args );
}
/**
* Maps event category capabilities
*
* @since 0.1.4
*
* @param array $caps Capabilities for meta capability
* @param string $cap Capability name
* @param int $user_id User id
* @param array $args Arguments
*
* @return array Actual capabilities for meta capability
*/
function wp_event_calendar_category_meta_caps( $caps, $cap, $user_id, $args ) {
// What capability is being checked?
switch ( $cap ) {
case 'manage_event_categories' :
case 'edit_event_categories' :
case 'delete_event_categories' :
case 'assign_event_categories' :
$caps = array( 'list_users' );
break;
}
return apply_filters( 'wp_event_calendar_category_meta_caps', $caps, $cap, $user_id, $args );
}
/**
* Maps event tag capabilities
*
* @since 0.1.4
*
* @param array $caps Capabilities for meta capability
* @param string $cap Capability name
* @param int $user_id User id
* @param array $args Arguments
*
* @return array Actual capabilities for meta capability
*/
function wp_event_calendar_tag_meta_caps( $caps, $cap, $user_id, $args ) {
// What capability is being checked?
switch ( $cap ) {
case 'manage_event_tags' :
case 'edit_event_tags' :
case 'delete_event_tags' :
case 'assign_event_tags' :
$caps = array( 'list_users' );
break;
}
return apply_filters( 'wp_event_calendar_tag_meta_caps', $caps, $cap, $user_id, $args );
}
......@@ -17,6 +17,12 @@ add_action( 'init', 'wp_event_calendar_register_type_taxonomy' );
add_action( 'init', 'wp_event_calendar_register_category_taxonomy' );
add_action( 'init', 'wp_event_calendar_register_tag_taxonomy' );
// Caps
add_filter( 'map_meta_cap', 'wp_event_calendar_meta_caps', 10, 4 );
add_filter( 'map_meta_cap', 'wp_event_calendar_type_meta_caps', 10, 4 );
add_filter( 'map_meta_cap', 'wp_event_calendar_category_meta_caps', 10, 4 );
add_filter( 'map_meta_cap', 'wp_event_calendar_tag_meta_caps', 10, 4 );
// Metaboxes
add_action( 'add_meta_boxes', 'wp_event_calendar_add_metabox' );
add_action( 'save_post', 'wp_event_calendar_metabox_save' );
......
......@@ -43,6 +43,23 @@ function wp_event_calendar_register_post_types() {
'thumbnail'
);
// Capability types
$cap_types = array(
'event',
'events'
);
// Capabilities
$caps = array(
'edit_posts' => 'edit_events',
'edit_others_posts' => 'edit_others_events',
'publish_posts' => 'publish_events',
'read_private_posts' => 'read_private_events',
'read_hidden_posts' => 'read_hidden_events',
'delete_posts' => 'delete_events',
'delete_others_posts' => 'delete_others_events'
);
// Post type arguments
$args = array(
'labels' => $labels,
......@@ -59,7 +76,8 @@ function wp_event_calendar_register_post_types() {
'show_in_admin_bar' => true,
'menu_position' => 44,
'menu_icon' => 'dashicons-calendar',
'capability_type' => 'page',
'capabilities' => $caps,
'capability_type' => $cap_types,
'register_meta_box_cb' => null,
'taxonomies' => array(),
'has_archive' => false,
......
......@@ -39,17 +39,17 @@ function wp_event_calendar_register_type_taxonomy() {
// Capabilities
$caps = array(
'manage_terms' => 'manage_event_categories',
'edit_terms' => 'edit_event_categories',
'delete_terms' => 'delete_event_categories',
'assign_terms' => 'assign_event_categories'
'manage_terms' => 'manage_event_types',
'edit_terms' => 'edit_event_types',
'delete_terms' => 'delete_event_types',
'assign_terms' => 'assign_event_types'
);
// Arguments
$args = array(
'labels' => $labels,
'rewrite' => $rewrite,
//'capabilities' => $caps,
'capabilities' => $caps,
'update_count_callback' => '_update_post_term_count',
'query_var' => true,
'show_tagcloud' => true,
......@@ -103,7 +103,7 @@ function wp_event_calendar_register_category_taxonomy() {
$args = array(
'labels' => $labels,
'rewrite' => $rewrite,
//'capabilities' => $caps,
'capabilities' => $caps,
'update_count_callback' => '_update_post_term_count',
'query_var' => true,
'show_tagcloud' => false,
......@@ -157,7 +157,7 @@ function wp_event_calendar_register_tag_taxonomy() {
$args = array(
'labels' => $labels,
'rewrite' => $rewrite,
//'capabilities' => $caps,
'capabilities' => $caps,
'update_count_callback' => '_update_post_term_count',
'query_var' => true,
'show_tagcloud' => false,
......
......@@ -3,7 +3,7 @@ Contributors: johnjamesjacoby
Tags: event, calendar
Requires at least: 4.2
Tested up to: 4.3
Stable tag: 0.1.3
Stable tag: 0.1.4
== Description ==
......@@ -53,6 +53,9 @@ http://github.com/johnjamesjacoby/wp-event-calendar/
== Changelog ==
= 0.1.4 =
* More flexibile mapped capabilities
= 0.1.3 =
* Revert role & capability changes
......
......@@ -5,7 +5,7 @@
* Plugin URI: https://wordpress.org/plugins/wp-event-calendar/
* Description: Flexible events, with a calendar view.
* Author: John James Jacoby
* Version: 0.1.3
* Version: 0.1.4
* Author URI: https://profiles.wordpress.org/johnjamesjacoby/
* License: GPL v2 or later
*/
......@@ -29,6 +29,7 @@ function wp_event_calendar() {
require $plugin_path . 'includes/common/admin.php';
// Event files
require $plugin_path . 'includes/events/capabilities.php';
require $plugin_path . 'includes/events/post-types.php';
require $plugin_path . 'includes/events/taxonomies.php';
require $plugin_path . 'includes/events/metaboxes.php';
......@@ -56,5 +57,5 @@ function wp_event_calendar_get_plugin_url() {
* @return int
*/
function wp_event_calendar_get_asset_version() {
return 201509020001;
return 201509020002;
}
Markdown is supported
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment