get_error_messages(); $top_message = wpbc_send_request__get_top_message(); //------------------------------------------------------------------------------------------------------------------ // Send JSON. Its will make "wp_json_encode" - so pass only array, and This function call wp_die( '', '', array( 'response' => null, ) ) Pass JS OBJ: response_data in "jQuery.post( " function on success. wp_send_json( array( 'ajx_show_content' => $top_message, 'ajx_error_messages' => $error_messages ) ); } // Ajax Handlers. add_action( 'wp_ajax_' . 'SHOW_MESSAGE_TOP', 'wpbc_ajax__get_message_top' ); // Admin & Client (logged-in users). Note. "locale_for_ajax" rechecked in wpbc-ajax.php /** * Get top message * * @return array|false|mixed|string|string[] */ function wpbc_send_request__get_top_message(){ $is_apply_in_demo = true; $v=array(); if (class_exists('wpdev_bk_personal')) $v[] = 'wpdev_bk_personal'; if (class_exists('wpdev_bk_biz_s')) $v[] = 'wpdev_bk_biz_s'; if (class_exists('wpdev_bk_biz_m')) $v[] = 'wpdev_bk_biz_m'; if (class_exists('wpdev_bk_biz_l')) $v[] = 'wpdev_bk_biz_l'; if (class_exists('wpdev_bk_multiuser')) $v[] = 'wpdev_bk_multiuser'; $obc_settings = array(); $ver = get_bk_option( 'bk_version_data' ); if ( $ver !== false ) { $obc_settings = array( 'subscription_key'=>wp_json_encode($ver) ); } $params = array( 'action' => 'get_top_message' ); $request = new WP_Http(); $result = $request->request( OBC_CHECK_URL . 'info/message_top/' // 'http://real.wpbookingcalendar.com/info/message_top/' , array( 'method' => 'POST', 'timeout' => 15, 'body' => $params ) ); if ( ! is_wp_error( $result ) && ( $result['response']['code'] == '200' ) && ( true ) ) { $string = ( $result['body'] ); //$string = str_replace( "'", ''', $string ); $shortcodes_arr = wpbc_get_shortcodes_in_text__as_unique_replace( $string , array( 'wpbc_dismiss' ) ); $string = $shortcodes_arr['content']; $is_panel_visible = false; foreach ( $shortcodes_arr['shortcodes'] as $shortcode_text_to_replace => $shortcode_params_arr ) { if ( isset( $shortcode_params_arr['params']['id'] ) ) { ob_start(); ob_clean(); $is_panel_visible = wpbc_is_dismissed( $shortcode_params_arr['params']['id'], array( 'is_apply_in_demo' => $is_apply_in_demo ) ); // This function also display 'Dismiss' button $new_html = ob_get_contents(); ob_end_clean(); $string = str_replace( '[' . $shortcode_text_to_replace . ']', $new_html, $string ); } } if ( $is_panel_visible ) { //$string = str_replace( 'script', 'ajax_script', $string ); return $string; } } return ''; }