How can I set my admin theme programmatically?
Now am using public theme for anonymous users and member theme for members. Am using role theme switcher to achieve this.
Now I want my admin theme as rubik. I tried to change it from /admin/settings/admin, but it is not effecting.
Is there any way to do this? I want public theme for my site front end and rubik theme for backend.
The admin theme is stored in the variable table; you can update it in code like so:
variable_set('admin_theme', 'theme_name');
You can also assign a theme to a specific path.
To apply admin theme to path /SOMEPATH/*
function MYMODULE_custom_theme() {
if (arg(0) == 'SOMEPATH') {
return variable_get('admin_theme');
}
}
To apply admin theme to path alias /SOMEPATH/*
function MYMODULE_custom_theme() {
//drupal_get_path_alias() may interfere with Global Redirect module
$arg = explode('/', substr(drupal_get_path_alias(request_uri(), 1), strlen(base_path())));
if ($arg[0] == 'SOMEPATH') {
return variable_get('admin_theme');
}
}
To apply a custom theme to /admin/*
function MYMODULE_custom_theme() {
if (arg(0) == 'admin') {
return 'MYADMINTHEME'; //list_themes() to see available themes
}
}
Pick a function and insert it inside your module, replacing MYMODULE with a module name.
Related
In WordPress I'd like to restrict the templates that the Editor role can create pages with. If I have 2 templates named Default Template and Advanced Template; how do I make it such that the Admin role has access to build pages off both but the Editor role can just use the "Default Template"?
Any idea how to do this please? Thank you.
You can unset the templates you want like this.
function remove_page_templates_by_role( $templates ) {
if( current_user_can('editor')) {
unset($templates['your-template.php']); // Change to your template
}
return $templates;
}
add_filter( 'theme_page_templates', 'remove_page_templates_by_role' );
I want to set different color on the dashboard of each site (in my multisite). For example the first site is based on the user's preference, but the second one always use Midnight theme.
Is there a way to set this in functions.php?
Thanks
Just found it on other's question. Put this on functions.php.
add_filter('get_user_option_admin_color', 'change_admin_color');
function change_admin_color($result) {
if(get_current_blog_id() === 2) {
return 'midnight';
}
else {
return $result;
}
}
I have been working on a client's WordPress Website and last day my client want to hide navigation menu and pages from author/contributor categories.
I have searched and tried some of the plugin but didn't get the exact thing. Please let me know what should i use to hide some pages from user and from navigation.
Only Admin can see all the pages and other members should see only 1 section that is allowed to visible for them.
Thank You
use this plugin to manage All roll:
http://wordpress.org/plugins/user-role-editor/
Here is the Complete function for removing each Menu and submenu from wp-admin for another user:
function remove_menus() {
global $menu, $submenu;
$restricted = array(__('Dashboard'), __('Profile'), __('Users'), __('Tools'), __('Comments'), __('Settings'), __('Plugins')); //Here you can also define the name like Pages
end($menu);
while (prev($menu)) {
$value = explode(' ', $menu[key($menu)][0]);
if (in_array($value[0] != NULL ? $value[0] : "", $restricted)) {
unset($menu[key($menu)]);
}
}
unset($menu[5]); // this is just for example
unset($submenu['edit.php'][16]); // this is just for example
}
Now You have to put a conditon for other user i.e:
$thisusername = $current_user->user_login; // this is to get the current user login
if (($thisusername == "user123")) {
add_action('admin_menu', 'remove_menus');
}
Note: You can find many plugins but all of them are not in depth like this code.Well you can try this plugin to manage your user's roles.Capability Manager Plugin
I have a WordPress site. There are many users. I want when an author logs in, the author who currently is currently logged on couldn't access the "edit page" menu in the admin bar.
Is there any plugin to disable that?
You can use this plugin :
http://wordpress.org/extend/plugins/admin-bar-disabler/
OR Alternative and manual way is under if condition place this
show_admin_bar(false);
E.g.
if(!is_admin())
{
show_admin_bar(false);
}
place this code in functions.php so that it will disable the admin bar for all the other users.
In your functions.php file, you can add one of the following code snippets to get the indicated results:
// Only display to administrators
add_action('after_setup_theme', 'remove_admin_bar');
function remove_admin_bar() {
if (!current_user_can('administrator') && !is_admin()) {
show_admin_bar(false);
}
}
// Disable for specific role (in this case, 'subscriber')
function remove_admin_bar() {
$user = wp_get_current_user();
if (in_array(‘subscriber’, $user->roles)) {
show_admin_bar(false);
}
}
Within the context of a module, how can you determine what theme is loaded for the current user?
drupal_get_path
path_to_theme
Neither of these are any good because they seem to only work in the template.php of a theme.
If users are allowed to select a theme for themselves, the theme they selected is saved in $user->theme, where $user is the user object.
The global variable $custom_theme contains the name of the theme currently set, if a module has set a custom theme.
The following snippet saves in $current_theme the name of the theme currently active:
global $custom_theme, $theme, $user;
if (!empty($user->theme)) {
$current_theme = $user->theme;
}
elseif (!empty($custom_theme)) {
$current_theme = $custom_theme;
}
else {
$current_theme = $theme ? $theme : variable_get('theme_default', 'garland');
}
path_to_theme should work just fine, I tested it on two Drupal installs, and both worked. If the theme has not been initialized yet, path_to_theme will do that, which is what Drupal uses internally to set different global theme variables like $theme_path, which is the variable you are looking for.