| 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 info@oplugins.com |
| 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 |
// FixIn: 2.0.2.1 //Fix: We need to comment this line, because previously its possible that we already sent some messages, and its does not correct json format in this case. |
| 98 |
//Fix: of showing "parsererror ~ SyntaxError: JSON.parse: unexpected character at line 1 column 1 of the JSON data" |
| 99 |
// send JSON |
| 100 |
// wp_send_json( array( 'response' => 'success' ) ); // Return JS OBJ: response_data = { response: "success" } in "dismiss.js" |
| 101 |
// This function call wp_die( '', '', array( 'response' => null, ) ) |
| 102 |
wp_die( '', '', array( 'response' => null ) ); |
| 103 |
} |
| 104 |
|
| 105 |
|
| 106 |
/** JSS */ |
| 107 |
public function wpbm_js_load_files( $where_to_load ) { |
| 108 |
|
| 109 |
$in_footer = true; |
| 110 |
|
| 111 |
if ( ( is_admin() ) && ( in_array( $where_to_load, array( 'admin', 'both' ) ) ) ) { |
| 112 |
|
| 113 |
wp_enqueue_script( 'wpbm-dismiss', wpbm_plugin_url( '/core/any/js/dismiss.js' ), array( 'wpbm-global-vars' ), '1.1', $in_footer ); |
| 114 |
} |
| 115 |
} |
| 116 |
|
| 117 |
|
| 118 |
/** CSS */ |
| 119 |
public function wpbm_enqueue_css_files( $where_to_load ) { |
| 120 |
|
| 121 |
if ( ( is_admin() ) && ( in_array( $where_to_load, array( 'admin', 'both' ) ) ) ) { |
| 122 |
|
| 123 |
wp_enqueue_style( 'wpbm-dismiss', wpbm_plugin_url( '/core/any/css/dismiss.css' ), array(), WPBM_VERSION_NUM ); |
| 124 |
} |
| 125 |
} |
| 126 |
|
| 127 |
|
| 128 |
/** Check if this section dismissed or not. |
| 129 |
* |
| 130 |
* @param string $section_html_id |
| 131 |
* @return boolean |
| 132 |
*/ |
| 133 |
public function is_dismissed( $section_html_id ) { |
| 134 |
|
| 135 |
if ( '1' == get_user_option( 'wpbm_win_' . $section_html_id ) ) |
| 136 |
return true; |
| 137 |
else |
| 138 |
return false; |
| 139 |
} |
| 140 |
|
| 141 |
} |
| 142 |
|
| 143 |
|
| 144 |
function wpbm_dismiss() { |
| 145 |
return WPBM_Dismiss::init(); |
| 146 |
} |
| 147 |
wpbm_dismiss(); // Run |
| 148 |
|
| 149 |
|
| 150 |
/** Check if specific section dismissed or not |
| 151 |
* |
| 152 |
* @param type $section_html_id |
| 153 |
* @return boolean |
| 154 |
*/ |
| 155 |
function wpbm_section_is_dismissed( $section_html_id ) { |
| 156 |
|
| 157 |
$wpbm_dismiss = wpbm_dismiss(); |
| 158 |
|
| 159 |
return $wpbm_dismiss->is_dismissed( $section_html_id ); |
| 160 |
} |
| 161 |
|
| 162 |
|
| 163 |
/** Show dismiss X button |
| 164 |
* |
| 165 |
* @param string $title |
| 166 |
* @param array $attributes_arr - array of attributes, like: array( 'class' => 'wpbm_dismiss' ) |
| 167 |
* @param bool $echo |
| 168 |
* @return string of dismiss button |
| 169 |
*/ |
| 170 |
function wpbm_x_dismiss_button( $title = '×', $attributes_arr = array(), $echo = true ) { |
| 171 |
|
| 172 |
$defaults = array( |
| 173 |
'style' => '' |
| 174 |
, 'class' => 'wpbm_dismiss' |
| 175 |
, 'title' => esc_js( __( 'Close', 'booking-manager' ) ) |
| 176 |
); |
| 177 |
$attributes_arr = wp_parse_args( $attributes_arr, $defaults ); |
| 178 |
|
| 179 |
$attr_echo = array(); |
| 180 |
foreach ( $attributes_arr as $attr_name => $attr_value ) { |
| 181 |
$attr_echo[] = esc_attr( $attr_name ) . '="' . esc_attr( $attr_value ) . '"'; |
| 182 |
} |
| 183 |
$attr_echo = implode( ' ', $attr_echo ); |
| 184 |
|
| 185 |
if ( ! $echo ) { ob_start(); } |
| 186 |
|
| 187 |
?><a href="javascript:void(0)" <?php echo $attr_echo; ?> ><?php echo $title; ?></a><?php |
| 188 |
|
| 189 |
if ( ! $echo ) { return ob_get_clean(); } |
| 190 |
} |