PluginProbe
Booking Manager – Sync WP Booking Calendar – Import Events, Export Bookings to ICS Calendar / 2.0.1
Booking Manager – Sync WP Booking Calendar – Import Events, Export Bookings to ICS Calendar v2.0.1
2.1.22 2.1.21 2.1.20 2.1.4 2.1.5 2.1.6 2.1.7 2.1.8 2.1.9 trunk 1.1 2.0 2.0.1 2.0.10.2 2.0.11 2.0.12 2.0.13 2.0.14 2.0.15 2.0.16 2.0.17 2.0.18 2.0.2 2.0.20 2.0.21 All 56 releases
booking-manager / core / any / wpbm-class-dismiss.php

wpbm-class-dismiss.php in Booking Manager – Sync WP Booking Calendar – Import Events, Export Bookings to ICS Calendar 2.0.1, at core/any/wpbm-class-dismiss.php

187 lines 5.7 KB
No matching file
Up and down to move Enter to open Esc to close
Raw Download Zip
1 <?php /**
2 * @version 1.0
3 * @description Dismiss Class
4 * @category Dismiss panels Class
5 * @author wpdevelop
6 *
7 * @web-site http://oplugins.com/
8 * @email [email protected]
9 *
10 * @modified 2015-11-13
11 */
12
13 if ( ! defined( 'ABSPATH' ) ) exit; // Exit if accessed directly
14
15 /** Dismiss Class
16 * @usage:
17 *
18 * Inline Setting Notice Dismiss'
19 *
20 $notice_id = 'wpbm_upload_help_section';
21 if ( ! wpbm_section_is_dismissed( $notice_id ) ) {
22
23 ?><div id="<?php echo $notice_id; ?>"
24 class="wpbm_system_notice wpbm_is_dismissible wpbm_is_hideable notice-warning wpbm_internal_notice"
25 data-nonce="<?php echo wp_create_nonce( $nonce_name = $notice_id . '_wpbmnonce' ); ?>"
26 data-user-id="<?php echo get_current_user_id(); ?>"
27 ><?php
28 wpbm_x_dismiss_button();
29 ....
30 ?></div><?php
31 *
32 * System Notice
33 *
34 $notice_id = 'wpbm_system_notice_free_instead_paid';
35 if ( ! wpbm_section_is_dismissed( $notice_id ) ) {
36 ?><div id="<?php echo $notice_id; ?>"
37 class="wpbm_system_notice wpbm_is_dismissible wpbm_is_hideable updated notice-warning"
38 data-nonce="<?php echo wp_create_nonce( $nonce_name = $notice_id . '_wpbmnonce' ); ?>"
39 data-user-id="<?php echo get_current_user_id(); ?>"
40 ><?php
41 wpbm_x_dismiss_button();
42 ...
43 ?></div><?php
44 *
45 */
46 final class WPBM_Dismiss {
47
48 static private $instance = NULL; // Define only one instance of this class
49
50 /** Get only one instance of this class
51 *
52 * @return class WPBM_Dismiss
53 */
54 public static function init() {
55
56 if ( ! isset( self::$instance ) && ! ( self::$instance instanceof WPBM_Dismiss ) ) {
57
58 self::$instance = new WPBM_Dismiss;
59
60 // JS & CSS
61 add_action( 'wpbm_enqueue_js_files', array( self::$instance, 'wpbm_js_load_files' ), 50 );
62 add_action( 'wpbm_enqueue_css_files', array( self::$instance, 'wpbm_enqueue_css_files' ), 50 );
63
64 // Ajax Handlers. Note. "locale_for_ajax" recehcked in wpbm-ajax.php
65 add_action( 'wp_ajax_' . 'WPBM_DISMISS', array( self::$instance, 'wpbm_ajax_' . 'WPBM_DISMISS' ) ); // Admin & Client (logged in usres)
66 //add_action( 'wp_ajax_nopriv_' . 'WPBM_DISMISS', array( self::$instance, 'wpbm_ajax_' . 'WPBM_DISMISS' ) ); // Client (not logged in)
67 }
68
69 return self::$instance;
70 }
71
72
73 /** Ajax Handler
74 * for request like:
75 * action: 'WPBM_DISMISS',
76 user_id: panel_obj.user_id ,
77 nonce: panel_obj.nonce,
78 element_id: panel_obj.id,
79 is_closed: 1
80 *
81 */
82 public function wpbm_ajax_WPBM_DISMISS() {
83
84 if ( ! isset( $_POST['element_id'] ) || empty( $_POST['element_id'] ) ) {
85 exit;
86 }
87
88 $action_name = $_POST['element_id'] . '_wpbmnonce';
89 $nonce_post_key = 'nonce';
90
91 // Check Security
92 $result = check_ajax_referer( $action_name, $nonce_post_key );
93
94 // Save status
95 update_user_option( (int) $_POST[ 'user_id' ], 'wpbm_win_' . esc_attr( $_POST[ 'element_id' ] ), (int) $_POST[ 'is_closed' ] );
96
97 // send JSON
98 wp_send_json( array( 'response' => 'success' ) ); // Return JS OBJ: response_data = { response: "success" } in "dismiss.js"
99 // This function call wp_die( '', '', array( 'response' => null, ) )
100 }
101
102
103 /** JSS */
104 public function wpbm_js_load_files( $where_to_load ) {
105
106 $in_footer = true;
107
108 if ( ( is_admin() ) && ( in_array( $where_to_load, array( 'admin', 'both' ) ) ) ) {
109
110 wp_enqueue_script( 'wpbm-dismiss', wpbm_plugin_url( '/core/any/js/dismiss.js' ), array( 'wpbm-global-vars' ), '1.1', $in_footer );
111 }
112 }
113
114
115 /** CSS */
116 public function wpbm_enqueue_css_files( $where_to_load ) {
117
118 if ( ( is_admin() ) && ( in_array( $where_to_load, array( 'admin', 'both' ) ) ) ) {
119
120 wp_enqueue_style( 'wpbm-dismiss', wpbm_plugin_url( '/core/any/css/dismiss.css' ), array(), WPBM_VERSION_NUM );
121 }
122 }
123
124
125 /** Check if this section dismissed or not.
126 *
127 * @param string $section_html_id
128 * @return boolean
129 */
130 public function is_dismissed( $section_html_id ) {
131
132 if ( '1' == get_user_option( 'wpbm_win_' . $section_html_id ) )
133 return true;
134 else
135 return false;
136 }
137
138 }
139
140
141 function wpbm_dismiss() {
142 return WPBM_Dismiss::init();
143 }
144 wpbm_dismiss(); // Run
145
146
147 /** Check if specific section dismissed or not
148 *
149 * @param type $section_html_id
150 * @return boolean
151 */
152 function wpbm_section_is_dismissed( $section_html_id ) {
153
154 $wpbm_dismiss = wpbm_dismiss();
155
156 return $wpbm_dismiss->is_dismissed( $section_html_id );
157 }
158
159
160 /** Show dismiss X button
161 *
162 * @param string $title
163 * @param array $attributes_arr - array of attributes, like: array( 'class' => 'wpbm_dismiss' )
164 * @param bool $echo
165 * @return string of dismiss button
166 */
167 function wpbm_x_dismiss_button( $title = '&times;', $attributes_arr = array(), $echo = true ) {
168
169 $defaults = array(
170 'style' => ''
171 , 'class' => 'wpbm_dismiss'
172 , 'title' => esc_js( __( 'Close', 'booking-manager' ) )
173 );
174 $attributes_arr = wp_parse_args( $attributes_arr, $defaults );
175
176 $attr_echo = array();
177 foreach ( $attributes_arr as $attr_name => $attr_value ) {
178 $attr_echo[] = esc_attr( $attr_name ) . '="' . esc_attr( $attr_value ) . '"';
179 }
180 $attr_echo = implode( ' ', $attr_echo );
181
182 if ( ! $echo ) { ob_start(); }
183
184 ?><a href="javascript:void(0)" <?php echo $attr_echo; ?> ><?php echo $title; ?></a><?php
185
186 if ( ! $echo ) { return ob_get_clean(); }
187 }