-
Notifications
You must be signed in to change notification settings - Fork 3
/
sitewide-notice-wp.php
187 lines (155 loc) · 6.97 KB
/
sitewide-notice-wp.php
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
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
<?php
/**
* Plugin Name: Sitewide Notice WP
* Description: Adds a simple message bar to the front-end of your website.
* Plugin URI: https://yoohooplugins.com
* Version: 2.4.1
* Author: Yoohoo Plugins
* Author URI: https://yoohooplugins.com
* License: GPL2 or later
* License URI: https://www.gnu.org/licenses/gpl-2.0.html
* Text Domain: sitewide-notice-wp
*
* Sitewide Notice WP 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
* any later version.
*
* Sitewide Notice WP 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.
*
* You should have received a copy of the GNU General Public License
* along with Sitewide Notice WP. If not, see http://www.gnu.org/licenses/gpl.html
*
**/
defined( 'ABSPATH' ) or exit;
/**
* INCLUDES
*/
include 'sitewide-notice-settings.php'; //all admin code can be found in here.
class SiteWide_Notice_WP {
/** Refers to a single instance of this class. */
private static $instance = null;
/**
* Creates or returns an instance of this class.
*
* @return Sitewide_Notice_WP A single instance of this class.
*/
public static function get_instance() {
if ( null == self::$instance ) {
self::$instance = new self;
self::$instance->hooks();
}
return self::$instance;
} // end get_instance;
/**
* Initializes the plugin by setting localization, filters, and administration functions.
*/
private function __construct() {
} //end of construct
private static function hooks() {
global $pagenow;
//run this code regardless if the actual banner is activated or not.
add_action( 'init', array( 'SiteWide_Notice_WP', 'init' ) );
$swnza_options = get_option( 'swnza_options' );
if ( ( is_array( $swnza_options ) && $swnza_options['active'] ) && !is_admin() && ( $pagenow !== 'wp-login.php' ) ) {
add_action( 'wp_footer', array( 'SiteWide_Notice_WP', 'display_sitewide_notice_banner' ) );
add_action( 'wp_enqueue_scripts', array( 'SiteWide_Notice_WP', 'enqueue_scripts' ) );
}
}
public static function init() {
if( isset( $_REQUEST['remove_swnza_settings'] ) || !empty( $_REQUEST['remove_swnza_settings'] ) ) {
delete_option( 'swnza_options' );
}
}
public static function enqueue_scripts() {
wp_enqueue_style( 'swnza_css', plugins_url( '/css/swnza.css', __FILE__ ) );
wp_enqueue_script( 'swnza_css', plugins_url( '/js/jquery_cookie.js', __FILE__ ), array( 'jquery' ), '2.1.4', true );
}
public static function display_sitewide_notice_banner() {
$swnza_options = get_option( 'swnza_options' );
if( ( isset( $swnza_options[ 'hide_for_logged_in' ] ) && ! empty( $swnza_options['hide_for_logged_in'] ) ) && is_user_logged_in() ) {
return;
}
if( apply_filters( 'swnza_show_banner', true ) && $swnza_options[ 'active' ] ) {
// If show for PMPro members setting is enabled and user doesn't have membership level, return.
if( isset( $swnza_options['show_for_members'] ) && ! empty( $swnza_options['show_for_members'] ) && !pmpro_hasMembershipLevel() ) {
return;
} ?>
<!-- SiteWide Notice WP Cookies -->
<script type="text/javascript">
jQuery(document).ready(function($){
if( Cookies.get('swnza_hide_banner_cookie') != 1 ) {
$('.swnza_banner').show();
}
$('#swnza_close_button_link').click(function(){
Cookies.set('swnza_hide_banner_cookie', 1, { expires: 1, path: '/' }); //expire the cookie after 24 hours.
$('.swnza_banner').hide();
});
});
</script>
<!-- SiteWide Notice WP Custom CSS -->
<style type="text/css">
.swnza_banner{
position:fixed;
min-height:50px;
height:auto;
width:100%;
background:<?php echo esc_attr( $swnza_options['background_color'] ); ?>;
padding-top:10px;
z-index:999;
display:block;
}
<?php if( isset( $swnza_options['show_on_top'] ) && ! empty( $swnza_options['show_on_top'] ) ) { ?>
.admin-bar .swnza_banner { margin-top:32px; }
.swnza_banner { top:0; }
.swnza_close_button { bottom:-10px; }
<?php } else { ?>
.swnza_banner{ bottom:0; }
.swnza_close_button { top:-10px;}
<?php } ?>
.swnza_banner p {
color: <?php echo esc_attr( $swnza_options['font_color'] ); ?>;
text-align:center;
z-index:1000;
font-size:20px;
display:block;
margin: 0;
}
<?php if ( ! empty( $swnza_options['dismissible'] ) ) { ?>
.swnza_close_button{
display:block;
position:absolute;
right:5px;
width:20px;
height:20px;
background:url("<?php echo plugins_url( 'images/close-button.svg', __FILE__ ); ?>") no-repeat center center;
background-color:white;
border-radius:100px;
border: 1px solid #000;
}
.swnza_close_button:hover{
cursor: pointer;
}
<?php } ?>
#swnza_banner_text{
margin-top:0;
}
<?php if( $swnza_options[ 'show_on_mobile' ] != 1 ) { ?>
@media all and (max-width: 500px){
.swnza_banner{
display: none;
}
}
<?php } ?>
</style>
<?php } ?>
<div class="swnza_banner" id="swnza_banner_id" style="display:none;">
<p id="swnza_banner_text"><?php echo htmlspecialchars_decode( stripslashes( apply_filters( 'swnza_banner_text', $swnza_options['message'] ) ) ); ?></p>
<a id="swnza_close_button_link" class="swnza_close_button"></a>
</div>
<?php }
} //end of class
Sitewide_Notice_WP::get_instance();