__( 'The dismissible interface element is not valid.', 'booking-manager' ) ) );
}
$action_name = $element_id . '_wpbmnonce';
$nonce_post_key = 'nonce';
// Check Security
$result = check_ajax_referer( $action_name, $nonce_post_key );
$requested_user_id = isset( $_POST['user_id'] ) && is_scalar( $_POST['user_id'] )
? absint( wp_unslash( (string) $_POST['user_id'] ) )
: 0;
$authorized_user_id = wpbm_get_authorized_user_option_target_id( $requested_user_id );
if ( 0 === $authorized_user_id ) {
status_header( 403 );
wp_send_json_error( array( 'message' => __( 'You can update only your own interface preferences.', 'booking-manager' ) ) );
}
// Save status
$is_closed = isset( $_POST['is_closed'] ) && is_scalar( $_POST['is_closed'] )
? (int) wp_unslash( (string) $_POST['is_closed'] )
: 0;
update_user_option( $authorized_user_id, 'wpbm_win_' . $element_id, $is_closed );
// 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.
//Fix: of showing "parsererror ~ SyntaxError: JSON.parse: unexpected character at line 1 column 1 of the JSON data"
// send JSON
// wp_send_json( array( 'response' => 'success' ) ); // Return JS OBJ: response_data = { response: "success" } in "dismiss.js"
// This function call wp_die( '', '', array( 'response' => null, ) )
wp_die( '', '', array( 'response' => null ) );
}
/** JSS */
public function wpbm_js_load_files( $where_to_load ) {
$in_footer = true;
if ( ( is_admin() ) && ( in_array( $where_to_load, array( 'admin', 'both' ) ) ) ) {
wp_enqueue_script( 'wpbm-dismiss', wpbm_plugin_url( '/core/any/js/dismiss.js' ), array( 'wpbm-global-vars' ), '1.1', $in_footer );
}
}
/** CSS */
public function wpbm_enqueue_css_files( $where_to_load ) {
if ( ( is_admin() ) && ( in_array( $where_to_load, array( 'admin', 'both' ) ) ) ) {
wp_enqueue_style( 'wpbm-dismiss', wpbm_plugin_url( '/core/any/css/dismiss.css' ), array(), WPBM_VERSION_NUM );
}
}
/** Check if this section dismissed or not.
*
* @param string $section_html_id
* @return boolean
*/
public function is_dismissed( $section_html_id ) {
if ( '1' == get_user_option( 'wpbm_win_' . $section_html_id ) )
return true;
else
return false;
}
}
function wpbm_dismiss() {
return WPBM_Dismiss::init();
}
wpbm_dismiss(); // Run
/** Check if specific section dismissed or not
*
* @param type $section_html_id
* @return boolean
*/
function wpbm_section_is_dismissed( $section_html_id ) {
$wpbm_dismiss = wpbm_dismiss();
return $wpbm_dismiss->is_dismissed( $section_html_id );
}
/** Show dismiss X button
*
* @param string $title
* @param array $attributes_arr - array of attributes, like: array( 'class' => 'wpbm_dismiss' )
* @param bool $echo
* @return string of dismiss button
*/
function wpbm_x_dismiss_button( $title = '×', $attributes_arr = array(), $echo = true ) {
$defaults = array(
'style' => ''
, 'class' => 'wpbm_dismiss'
, 'title' => esc_js( __( 'Close', 'booking-manager' ) )
);
$attributes_arr = wp_parse_args( $attributes_arr, $defaults );
$attr_echo = array();
foreach ( $attributes_arr as $attr_name => $attr_value ) {
$attr_echo[] = esc_attr( $attr_name ) . '="' . esc_attr( $attr_value ) . '"';
}
$attr_echo = implode( ' ', $attr_echo );
if ( ! $echo ) { ob_start(); }
?> >