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:
<?php
defined( 'ABSPATH' ) || exit;
if ( ! function_exists( 'vsp_send_json_callback' ) ) {
function vsp_send_json_callback( $status = true, $functions = array(), $other_info = array(), $window_args = array(), $status_code = null ) {
$function = ( true === $status ) ? 'wp_send_json_success' : 'wp_send_json_error';
if ( is_object( $functions ) ) {
$functions = array( $functions );
} elseif ( is_string( $functions ) ) {
$functions = array( $functions );
}
if ( ! empty( $window_args ) ) {
foreach ( $window_args as $key => $args ) {
if ( is_array( $args ) ) {
$window_args[ $key ] = 'window.vsp_js_helper.window_arg(' . wp_json_encode( $args ) . ')';
}
}
$functions = array_merge( $functions, $window_args );
}
foreach ( $functions as $fid => $val ) {
if ( is_numeric( $fid ) ) {
unset( $functions[ $fid ] );
$fid = 'vspjs' . md5( wp_json_encode( $val ) . '-' . microtime() ) . 'function';
}
$functions[ $fid ] = trim( $val );
$functions[ $fid ] = str_replace( array( "\n", "\r" ), ' ', $functions[ $fid ] );
}
$data = array_merge( array( 'callback' => $functions ), $other_info );
$function( $data, $status_code );
wp_die();
}
}
if ( ! function_exists( 'vsp_send_callback_error' ) ) {
function vsp_send_callback_error( $functions = array(), $data = array(), $window_args = array(), $status_code = null ) {
vsp_send_json_callback( false, $functions, $data, $window_args, $status_code );
}
}
if ( ! function_exists( 'vsp_send_callback_success' ) ) {
function vsp_send_callback_success( $functions = array(), $data = array(), $window_args = array(), $status_code = null ) {
vsp_send_json_callback( true, $functions, $data, $window_args, $status_code );
}
}