Commit 96c872ae authored by agnez's avatar agnez

user menu setup

parent 682052a8
......@@ -23,19 +23,19 @@ add_action( 'init', 'create_post_types' );
function create_post_types() {
register_post_type('gasap', // GASAP
array(
'labels' => array(
'name' => _x( 'GASAP', 'post type general name', 'gasap-posttypes' ),
'singular_name' => _x( 'GASAP', 'post type singular name', 'gasap-posttypes' ),
'add_new' => _x( 'Add New', 'GASAP', 'gasap-posttypes' ),
'add_new_item' => __( 'Add New GASAP', 'gasap-posttypes' ),
'edit_item' => __( 'Edit GASAP', 'gasap-posttypes' ),
'new_item' => __( 'New GASAP', 'gasap-posttypes' ),
'view' => __( 'View GASAP', 'gasap-posttypes' ),
'view_item' => __( 'View GASAP', 'gasap-posttypes' ),
'search_items' => __( 'Search GASAP', 'gasap-posttypes' ),
'not_found' => __( 'No GASAP found', 'gasap-posttypes' ),
'not_found_in_trash' => __( 'No GASAP found in Trash', 'gasap-posttypes' ),
),
'labels' => array(
'name' => _x( 'GASAP', 'post type general name', 'gasap-posttypes' ),
'singular_name' => _x( 'GASAP', 'post type singular name', 'gasap-posttypes' ),
'add_new' => _x( 'Add New', 'GASAP', 'gasap-posttypes' ),
'add_new_item' => __( 'Add New GASAP', 'gasap-posttypes' ),
'edit_item' => __( 'Edit GASAP', 'gasap-posttypes' ),
'new_item' => __( 'New GASAP', 'gasap-posttypes' ),
'view' => __( 'View GASAP', 'gasap-posttypes' ),
'view_item' => __( 'View GASAP', 'gasap-posttypes' ),
'search_items' => __( 'Search GASAP', 'gasap-posttypes' ),
'not_found' => __( 'No GASAP found', 'gasap-posttypes' ),
'not_found_in_trash' => __( 'No GASAP found in Trash', 'gasap-posttypes' ),
),
'public' => true,
'has_archive' => false,
'show_ui' => true,
......@@ -66,7 +66,7 @@ function create_post_types() {
'exclude_from_search' => true,
'hierarchical' => false,
'supports' => array( 'title', 'editor', 'thumbnail', 'excerpt' ),
'capability_type' => 'post',
'capability_type' => 'page',
'query_var' => true,
'menu_position' => 8,
)
......@@ -90,7 +90,7 @@ function create_post_types() {
'exclude_from_search' => true,
'hierarchical' => false,
'supports' => array( 'title', 'editor', 'thumbnail', 'excerpt' ),
'capability_type' => 'post',
'capability_type' => 'page',
'query_var' => true,
'menu_position' => 11,
)
......@@ -114,7 +114,7 @@ function create_post_types() {
'exclude_from_search' => true,
'hierarchical' => false,
'supports' => array( 'title', 'thumbnail', ),
'capability_type' => 'post',
'capability_type' => 'page',
'query_var' => true,
'menu_position' => 12,
)
......
......@@ -20,13 +20,12 @@ function gasap_users_load_plugin_textdomain() {
}
/*
* class for moving admin role out of editor's reach
* http://wordpress.stackexchange.com/questions/4479/editor-can-create-any-new-user-except-administrator
* class for moving admin role out of editor's reach http://wordpress.stackexchange.com/questions/4479/editor-can-create-any-new-user-except-administrator
*/
class JPB_User_Caps {
class GASAP_User_Caps {
// Add our filters
function JPB_User_Caps(){
function GASAP_User_Caps(){
add_filter( 'editable_roles', array(&$this, 'editable_roles'));
add_filter( 'map_meta_cap', array(&$this, 'map_meta_cap'),10,4);
}
......@@ -75,44 +74,30 @@ class JPB_User_Caps {
}
}
$jpb_user_caps = new JPB_User_Caps();
$GASAP_user_caps = new GASAP_User_Caps();
/*
* user roles and capabilities
*/
remove_role( 'subscriber' );
remove_role( 'contributor' );
add_action( 'admin_init', 'gasap_add_capabilities');
function gasap_add_capabilities() {
$editor = get_role( 'editor' );
$author = get_role( 'author' );
$editor->add_cap( 'create_users' );
$editor->add_cap( 'delete_users' );
$editor->add_cap( 'edit_users' );
$editor->add_cap( 'list_users' );
$editor->add_cap( 'promote_users' );
$editor->add_cap( 'remove_users' );
//$editor->add_cap( 'edit_theme_options' );
//$author->add_cap( 'edit_published_pages' );
$author->add_cap( 'upload_files' );
//$author->add_cap( 'publish_pages' );
//$author->add_cap( 'delete_published_pages' );
//$author->add_cap( 'edit_pages' );
//$author->add_cap( 'delete_pages' );
}
//check if role exist before removing it
if( get_role('subscriber') ){
remove_role( 'subscriber' );
}
if( get_role('contributor') ){
remove_role( 'contributor' );
}
/**
* Remove capabilities from editors. https://codex.wordpress.org/Function_Reference/remove_cap
* Remove capabilities from authors and referents
*/
add_action( 'init', 'gasap_remove_capabilities' );
function gasap_remove_capabilities() {
$author = get_role( 'author' );
$caps = array(
'edit_pages',
'publish_pages',
'publish_pages',
'delete_pages',
'edit_contentpieces',
'publish_contentpieces',
......@@ -120,7 +105,7 @@ function gasap_remove_capabilities() {
);
foreach ( $caps as $cap ) {
$author->remove_cap( $cap );
}
}
}
// hide from admin menu http://www.wpmayor.com/how-to-remove-menu-items-in-admin-depending-on-user-role/
......@@ -133,34 +118,39 @@ function gasap_remove_menu_pages() {
remove_menu_page('tools.php'); // tools
}
if ( current_user_can( 'editor' ) ) {
remove_submenu_page( 'themes.php', 'themes.php' ); // hide the theme selection submenu
remove_submenu_page( 'themes.php', 'widgets.php' ); // hide the widgets submenu
remove_submenu_page( 'themes.php', 'customize.php' ); //not working
remove_submenu_page( 'themes.php', 'background_image' ); //not working
remove_submenu_page( 'themes.php', 'themes.php' ); // hide the theme selection submenu
remove_submenu_page( 'themes.php', 'widgets.php' ); // hide the widgets submenu
remove_submenu_page( 'themes.php', 'customize.php' ); //not working
remove_submenu_page( 'themes.php', 'background_image' ); //not working
}
}
add_action( 'admin_bar_menu', 'remove_wp_nodes', 999 );
function remove_wp_nodes()
{
global $wp_admin_bar;
$wp_admin_bar->remove_node( 'customize' );
$wp_admin_bar->remove_node( 'new-media' );
// remove toolbar https://developer.wordpress.org/reference/classes/wp_admin_bar/remove_node/
add_action( 'admin_bar_menu', 'gasap_remove_wp_nodes', 999 );
function gasap_remove_wp_nodes($wp_admin_bar) {
$wp_admin_bar->remove_node( 'new-page' );
$wp_admin_bar->remove_node( 'new-contentpiece' );
$wp_admin_bar->remove_node( 'new-media' );
$wp_admin_bar->remove_node( 'wp-logo' );
if ( current_user_can( 'author' ) ) {
$wp_admin_bar->remove_node( 'new-headerimage' );
$wp_admin_bar->remove_node( 'new-logolink' );
$wp_admin_bar->remove_node( 'new-gasap' );
$wp_admin_bar->remove_node( 'new-producer' );
$wp_admin_bar->remove_node( 'new-worker' );
$wp_admin_bar->remove_node( 'new-partner' );
$wp_admin_bar->remove_node( 'new-user' );
}
}
//rename role
add_action('init', 'change_role_name');
function change_role_name() {
add_action('init', 'gasap_change_role_name');
function gasap_change_role_name() {
global $wp_roles;
if ( ! isset( $wp_roles ) ) $wp_roles = new WP_Roles();
if ( ! isset( $wp_roles ) )
$wp_roles = new WP_Roles();
//You can replace "administrator" with any other role "editor", "author", "contributor" or "subscriber"...
$wp_roles->roles['author']['name'] = 'Owner';
$wp_roles->role_names['author'] = 'Owner';
$wp_roles->roles['editor']['name'] = __( 'super GASAPiens', 'gasap-users' );
$wp_roles->role_names['editor'] = __( 'super GASAPiens', 'gasap-users' );
$wp_roles->roles['author']['name'] = __( 'GASAPiens', 'gasap-users' );
$wp_roles->role_names['author'] = __( 'GASAPiens', 'gasap-users' );
}
\ No newline at end of file
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