Skip to content

Instantly share code, notes, and snippets.

@joelworsham
Created March 23, 2016 16:18
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save joelworsham/f64990299e061aea9896 to your computer and use it in GitHub Desktop.
Save joelworsham/f64990299e061aea9896 to your computer and use it in GitHub Desktop.
Custom Roles for DZS
<?php
/**
* Plugin Name: DZS Roles
* Description: Provides custom roles for the Detroit Zoo website.
* Author: Joel Worsham
* Author URI: http://realbigmarketing.com
* Version: 1.0.1
*/
if ( ! defined( 'ABSPATH' ) ) {
die;
}
// Define plugin constants
define( 'ROLES_VERSION', '1.0.1' );
define( 'ROLES_DIR', plugin_dir_path( __FILE__ ) );
define( 'ROLES_URL', plugins_url( '', __FILE__ ) );
/**
* Class ROLES
*
* Initiates the plugin.
*
* @since 0.1.0
*
* @package ROLES
*/
class ROLES {
private function __clone() {
}
private function __wakeup() {
}
/**
* Returns the *Singleton* instance of this class.
*
* @since 0.1.0
*
* @staticvar Singleton $instance The *Singleton* instances of this class.
*
* @return ROLES The *Singleton* instance.
*/
public static function getInstance() {
static $instance = null;
if ( null === $instance ) {
$instance = new static();
}
return $instance;
}
/**
* Initializes the plugin.
*
* @since 0.1.0
*/
protected function __construct() {
$this->add_base_actions();
$this->require_necessities();
}
/**
* Requires necessary base files.
*
* @since 0.1.0
*/
public function require_necessities() {
}
/**
* Adds global, base functionality actions.
*
* @since 0.1.0
*/
private function add_base_actions() {
add_action( 'init', array( $this, '_register_assets' ) );
add_action( 'admin_enqueue_scripts', array( $this, '_enqueue_assets' ) );
register_activation_hook( __FILE__, array( $this, '_activate_plugin' ) );
register_deactivation_hook( __FILE__, array( $this, '_deactivate_plugin' ) );
}
/**
* Registers the plugin's assets.
*
* @since 0.1.0
*/
function _register_assets() {
}
function _enqueue_assets() {
}
function _activate_plugin() {
global $wp_roles;
if ( ! isset( $wp_roles ) ) {
$wp_roles = new WP_Roles();
}
$admin = $wp_roles->get_role( 'administrator' );
add_role( 'site_manager', 'Site Manager', array_diff_key( $admin->capabilities, array(
'install_themes' => true,
'install_plugins' => true,
'delete_themes' => true,
'delete_plugins' => true,
'edit_plugins' => true,
'edit_themes' => true,
'edit_files' => true,
) ) );
add_role( 'marketing', 'Marketing', array(
'delete_events' => true,
'delete_published_events' => true,
'edit_events' => true,
'edit_published_events' => true,
'edit_others_events' => true,
'publish_events' => true,
'read' => true,
'upload_files' => true,
) );
add_role( 'communications_editor', 'Communications Editor', array(
'edit_others_pages' => true,
'edit_others_posts' => true,
'edit_posts' => true,
'edit_published_posts' => true,
'read' => true,
'upload_files' => true,
) );
add_role( 'communications_manager', 'Communications Manager', array(
'delete_others_pages' => true,
'delete_others_posts' => true,
'delete_pages' => true,
'delete_posts' => true,
'delete_private_pages' => true,
'delete_private_posts' => true,
'delete_published_pages' => true,
'delete_published_posts' => true,
'edit_others_pages' => true,
'edit_others_posts' => true,
'edit_pages' => true,
'edit_posts' => true,
'edit_private_pages' => true,
'edit_private_posts' => true,
'edit_published_pages' => true,
'edit_published_posts' => true,
'manage_categories' => true,
'moderate_comments' => true,
'publish_pages' => true,
'publish_posts' => true,
'read' => true,
'read_private_pages' => true,
'read_private_posts' => true,
'unfiltered_html' => true,
'upload_files' => true,
) );
}
function _deactivate_plugin() {
remove_role( 'site_manager' );
remove_role( 'marketing' );
remove_role( 'communications_editor' );
remove_role( 'communications_manager' );
}
}
Roles::getInstance();
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment