Created
December 4, 2013 19:11
-
-
Save wturnerharris/7793594 to your computer and use it in GitHub Desktop.
Custom admin implementation for WP backend. This snippet provides references to removing and adding backend pages as well as custom roles and capabilities.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| class WP_Admin_Pages { | |
| var $reset_roles = false, | |
| $page_name = "member_approvals", | |
| $board_votes = "board_votes"; | |
| function __construct() { | |
| if ( ! function_exists( 'admin_url' ) ) return false; | |
| if ( is_admin() ) { | |
| add_action( 'init', array(&$this, 'rolescheck')); | |
| add_action( 'admin_menu', array(&$this, 'add_admin_page')); | |
| add_filter( 'custom_menu_order', array(&$this, 'custom_admin_menu_pages')); | |
| } | |
| } | |
| function add_admin_page() { | |
| if ( current_user_can('administrator') ) { | |
| add_submenu_page( | |
| $this->page_name, // slug | |
| __('Board Votes', 'abana'), | |
| __('Board Votes', 'abana'), | |
| 'can_approve_members', // cap | |
| $this->page_name."_sub", // slug | |
| array(&$this, 'member_approval_page') // func to ouput html | |
| ); | |
| } else { | |
| remove_menu_page('link-manager.php'); | |
| remove_menu_page('tools.php'); | |
| remove_menu_page('edit.php'); | |
| remove_menu_page('edit-comments.php'); | |
| } | |
| } | |
| function custom_admin_menu_pages($order) { | |
| if (!$order) return true; | |
| return array( | |
| 'index.php', | |
| 'separator1', | |
| 'edit.php', | |
| 'edit.php?post_type=page', | |
| 'upload.php', | |
| 'edit.php?post_type=slide', | |
| 'edit.php?post_type=news', | |
| 'edit.php?post_type=leader', | |
| 'edit.php?post_type=job', | |
| 'edit.php?post_type=offer', | |
| 'edit.php?post_type=event', | |
| 'link-manager.php', | |
| 'separator2', | |
| 'themes.php', | |
| 'plugins.php', | |
| 'users.php', | |
| 'tools.php', | |
| 'options-general.php', | |
| 'separator-last', | |
| ); | |
| } | |
| function rolescheck() { | |
| if ( $this->reset_roles === TRUE ) { | |
| remove_role('board'); | |
| remove_role('student'); | |
| remove_role('individual'); | |
| remove_role('institution'); | |
| remove_role('pending'); | |
| } | |
| $default_caps = array( | |
| 'read' => false, | |
| 'upload_files' => false, | |
| 'manage_options' => false, | |
| 'manage_individuals' => false, | |
| 'is_approved_member' => false, | |
| 'can_approve_members' => false, | |
| ); | |
| if ( current_user_can('administrator') && get_user_meta(get_current_user_id(), 'abana_admin_upgraded', true) != "3.0") { | |
| $admin = get_role('administrator'); | |
| // upgrade admin user for theme | |
| if (! current_user_can('manage_options') ) $admin->add_cap('manage_options'); | |
| if (! current_user_can('manage_individuals') ) $admin->add_cap('manage_individuals'); | |
| if (! current_user_can('is_approved_member') ) $admin->add_cap('is_approved_member'); | |
| if (! current_user_can('can_approve_members') ) $admin->add_cap('can_approve_members'); | |
| update_user_meta(get_current_user_id(), 'abana_admin_upgraded', "3.0"); | |
| } | |
| if (! get_role( 'pending' ) ) { | |
| add_role('pending', 'Pending Approval', $default_caps); | |
| } | |
| $default_caps['read'] = true; | |
| $default_caps['is_approved_member'] = true; | |
| $default_caps['upload_files'] = true; | |
| if (! get_role( 'student' ) ) { | |
| add_role('student', 'Student', $default_caps); | |
| } | |
| if (! get_role( 'individual' ) ) { | |
| add_role('individual', 'Individual', $default_caps); | |
| } | |
| $default_caps['manage_individuals'] = true; | |
| if (! get_role( 'institution' ) ) { | |
| add_role('institution', 'Institution', $default_caps); | |
| } | |
| $default_caps['can_approve_members'] = true; | |
| if ( get_role( 'board' ) ) { | |
| remove_role('board'); | |
| } | |
| } | |
| function member_approval_page(){ | |
| } | |
| } | |
| new WP_Admin_Pages(); |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment