I'm trying to call custom file in network admin:
function admin_css_function(){
wp_enqueue_style('blaa', '/wp-content/themes/theme-name/assets/css/admin/admin.css', false);
}
if (is_admin()) {
add_action('admin_enqueue_scripts', 'admin_css_function');
}
or
if (is_network_admin()) {
add_action('admin_enqueue_scripts', 'admin_css_function');
}
But it doesn't work. This example css loads only in a single admin site from the network, but not on the network admin.
Thanks for help,
Related
I have created this code for my Wordpress Theme's function.php file. I want to redirect the user to certain URL if they are on a certain page.
Please check if this function is correct? The code is working, but it's creating an error with Woocommerce checkout and not letting customer place an order.
function user_login_check()
{
if (is_user_logged_in()) {
if (is_page(123)) {
wp_redirect('https://example.com/alpha');
exit;
};
if (is_page(456)) {
wp_redirect('https://example.com/beta');
exit;
}
}
}
add_action('wp', 'user_login_check');
After updating to Wordpress 4.3 users can see the admin bar. I use this code to hide it normally, but this is not working anymore in 4.3.
add_action('after_setup_theme', 'remove_admin_bar');
function remove_admin_bar() {
if (!current_user_can('administrator') && !is_admin()) {
show_admin_bar(false);
}
}
Any ideas?
The function current_user_can refers to capabilities or user role names. So try manage_options instead:
add_action('after_setup_theme', 'remove_admin_bar');
function remove_admin_bar() {
// 'manage_options' is a capability assigned only to administrators
if (!current_user_can('manage_options') && !is_admin()) {
show_admin_bar(false);
}
}
Instead of using the after_setup_theme action you can also add a filter (prefered for newer WP versions):
add_filter( 'show_admin_bar' , 'handle_admin_bar');
function handle_admin_bar($content) {
// 'manage_options' is a capability assigned only to administrators
// here, the check for the admin dashboard is not necessary
if (!current_user_can('manage_options')) {
return false;
}
}
Here is a 6 lines code nugget that will remove the admin bar for non contributor users :
add_action( 'init', 'fb_remove_admin_bar', 0 );
function fb_remove_admin_bar() {
if (!current_user_can('edit_posts')) { // you can change the test here depending on what you want
add_filter( 'show_admin_bar', '__return_false', PHP_INT_MAX );
}
}
Put that in your function.php file or in your custom plugin.
Thanx all for helping. Eventually the problem was a maintenance plugin. When i disabled this it was working again.
Place the code in your theme's functions.php file
if (!current_user_can('manage_options')) {
add_filter('show_admin_bar', '__return_false');
}
Disable the WordPress Admin Bar Using CSS
You only have to copy and paste the CSS code below in Appearance > Customize > Additional CSS, or your style.css file.
The CSS code to disable the toolbar is:
#wpadminbar { display:none !important;}
I have a site www.example.com and a wordpress blog at www.example.com/blog.
I want my user to login at www.example.com and $_SESSION['USERNAME'] is passed to www.example.com/blog.
I just want to know, how can i automatically login the end user to wordpress blog, once they login to my main site.
For now i am passing $_SESSION['USERNAME'] and using a plugin external database login, which I have linked to my main site database.
Any function that is used to login to wordpress using session username will be helpful.
Wordpress don't use $_SESSIONyou need to code a plugin or to add some code to your functions.php to do this - cf http://www.frank-verhoeven.com/using-session-in-wordpress/
You should add something like this :
function init_sessions() {
if (!session_id()) {
session_start();
}
}
add_action('init', 'init_sessions');
NB: there is also a plugin to manage Sessions with Wordpress, maybe you can use/hack this http://wordpress.org/plugins/wp-session-manager/
I have been reading on this. Here is what I have found as I am in the same issue. In your wp-config.php file at the top add:
add_action('init', 'myStartSession', 1);
function myStartSession() {
if(!session_id()) {
session_start();
}
}
HOWEVER, " The data stored in the session doesn’t go away when the user logs out or logs into a different account. For that you need to destroy the session. ..." (exerpt from this nice write up). It explains you also need to:
function myEndSession() {
session_destroy ();
}
if you can get wp user_id you could do something like this:
function init_sessions() {
if (user_logged_on_site) {
#session_start();
$user_id = $_SESSION['wp_user_id']; //this has to be set when the user logs on your website
wp_set_auth_cookie( $user_id); //log in the user on wordpress
}
}
add_action('init', 'init_sessions');
Documentation on wp_set_auth_cookie http://codex.wordpress.org/Function_Reference/wp_set_auth_cookie
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);
}
}
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.