-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathalways-show-admin-bar.php
More file actions
82 lines (73 loc) · 2.37 KB
/
always-show-admin-bar.php
File metadata and controls
82 lines (73 loc) · 2.37 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
<?php
/*
* Plugin Name: Always Show Admin Bar
* Plugin URI: http://www.ademti-software.co.uk/
* Description: Always show the admin bar
* Author: Ademti Software
* Version: 0.3
* Author URI: http://www.ademti-software.co.uk/
*/
/**
* Copyright (c) 2011-2015 Lee Willis. All rights reserved.
* Copyright (c) 2015-2024 Ademti Software. All rights reserved.
*
* Released under the GPL license
* http://www.opensource.org/licenses/gpl-license.php
*
* This is an add-on for WordPress
* http://wordpress.org/
*
* **********************************************************************
* This program is free software; you can redistribute it and/or modify
* it under the terms of the GNU General Public License as published by
* the Free Software Foundation; either version 2 of the License, or
* (at your option) any later version.
*
* This program is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
* GNU General Public License for more details.
* **********************************************************************
*/
class asabfa {
function __construct() {
add_action( 'init', array( $this, 'show_admin_bar' ) );
add_action( 'admin_bar_menu', array( $this, 'add_login_links' ), 11 );
}
function add_login_links() {
global $wp_admin_bar;
if ( $this->is_logged_in() )
return;
if ( isset( $wp_admin_bar ) )
$wp_admin_bar->add_menu( array( 'id' => 'login-link', 'title' => __( 'Not Logged in, login here', 'asabfa' ), 'href' => admin_url() ) );
}
function has_logged_in() {
// Have they ever logged in?
return isset( $_COOKIE['asabfa_logged_in'] ) && $_COOKIE['asabfa_logged_in'] ;
}
function is_logged_in() {
$user_id = get_current_user_id();
if ( 0 != $user_id ) {
return TRUE;
} else {
return FALSE;
}
}
function show_admin_bar( $show ) {
// If the user has logged in previously - show the bar
if ( $this->has_logged_in() ) {
$show = TRUE;
}
// If user is currently logged in. Show the bar, and set a cookie
if ( $this->is_logged_in() ) {
setcookie( 'asabfa_logged_in', '1', time() + 60 * 60 * 24 * 1000 );
$show = TRUE;
}
if ( $show && !is_admin() ) {
add_filter( 'show_admin_bar', '__return_true' );
} else {
add_filter( 'show_admin_bar', '__return_false' );
}
}
}
$asabfa = new asabfa();