| 1 |
<?php |
| 2 |
|
| 3 |
use ENS\Config; |
| 4 |
|
| 5 |
defined( 'ABSPATH' ) || exit; |
| 6 |
|
| 7 |
if ( !function_exists( 'ens_get_translatable_strings' ) ) { |
| 8 |
|
| 9 |
/** |
| 10 |
* will return strings after translation |
| 11 |
* |
| 12 |
* @return array |
| 13 |
*/ |
| 14 |
function ens_get_translatable_strings( $string, $text_domain ) { |
| 15 |
return $string; |
| 16 |
} |
| 17 |
} |
| 18 |
|
| 19 |
if ( !function_exists( 'ens_verify_nonce' ) ) { |
| 20 |
|
| 21 |
/** |
| 22 |
* will verify nonce |
| 23 |
* |
| 24 |
* @return array |
| 25 |
*/ |
| 26 |
function ens_verify_nonce( $nonce, $identifier ) { |
| 27 |
if ( ! empty( $nonce ) && wp_verify_nonce( $nonce, 'ens_' . $identifier . '_flow' ) ) { |
| 28 |
return true; |
| 29 |
} |
| 30 |
|
| 31 |
// Backward compatibility: plugins bundling an older SDK still send a |
| 32 |
// 'wp_rest' nonce. This is only a CSRF check; authorization is enforced |
| 33 |
// by the capability check in each route's permission_callback. |
| 34 |
if ( ! empty( $nonce ) && wp_verify_nonce( $nonce, 'wp_rest' ) ) { |
| 35 |
return true; |
| 36 |
} |
| 37 |
|
| 38 |
$response = [ |
| 39 |
'success' => 0, |
| 40 |
'status_code' => 403, |
| 41 |
'message' => __( 'Nonce not verified', get_config_data( $identifier,'text_domain' ) ), |
| 42 |
'data' => [], |
| 43 |
]; |
| 44 |
return new WP_HTTP_Response( $response, 403 ); |
| 45 |
} |
| 46 |
} |
| 47 |
|
| 48 |
if ( !function_exists( 'ens_sanitize_recursive' ) ) { |
| 49 |
|
| 50 |
/** |
| 51 |
* will sanitize recursive |
| 52 |
* |
| 53 |
* @return array |
| 54 |
*/ |
| 55 |
function ens_sanitize_recursive( $input ) { |
| 56 |
if ( is_array( $input ) ) { |
| 57 |
|
| 58 |
foreach ( $input as $key => $value ) { |
| 59 |
$input[$key] = ens_sanitize_recursive( $value ); |
| 60 |
} |
| 61 |
|
| 62 |
} elseif ( is_object( $input ) ) { |
| 63 |
|
| 64 |
foreach ( $input as $key => $value ) { |
| 65 |
$input->$key = ens_sanitize_recursive( $value ); |
| 66 |
} |
| 67 |
|
| 68 |
} else { |
| 69 |
if ( filter_var( $input, FILTER_VALIDATE_URL ) !== false ) { |
| 70 |
$input = sanitize_url( $input ); |
| 71 |
} elseif ( is_email( $input ) ) { |
| 72 |
$input = sanitize_email( $input ); |
| 73 |
} elseif ( is_int( $input ) ) { |
| 74 |
$input = intval( $input ); |
| 75 |
} elseif ( is_float( $input ) ) { |
| 76 |
$input = floatval( $input ); |
| 77 |
} elseif ( is_string( $input ) ) { |
| 78 |
if ( strpos( $input, '<svg' ) === false ) { |
| 79 |
$input = wp_kses_post( $input ); |
| 80 |
} |
| 81 |
} |
| 82 |
} |
| 83 |
|
| 84 |
return $input; |
| 85 |
} |
| 86 |
} |
| 87 |
|
| 88 |
if ( !function_exists( 'ens_get_post_status' ) ) { |
| 89 |
|
| 90 |
/** |
| 91 |
* will return post status |
| 92 |
* |
| 93 |
* @return array |
| 94 |
*/ |
| 95 |
function ens_get_post_status() { |
| 96 |
return ['publish', 'draft', 'trash']; |
| 97 |
} |
| 98 |
} |
| 99 |
|
| 100 |
if ( !function_exists( 'get_config_data' ) ) { |
| 101 |
|
| 102 |
/** |
| 103 |
* will return config data |
| 104 |
* |
| 105 |
* @return array |
| 106 |
*/ |
| 107 |
function get_config_data($prefix, $value_of) { |
| 108 |
$key = $prefix . '_ens_config'; |
| 109 |
|
| 110 |
$data = get_option( $key ); |
| 111 |
|
| 112 |
if (isset($data[$value_of])) { |
| 113 |
return $data[$value_of]; |
| 114 |
} |
| 115 |
|
| 116 |
return null; |
| 117 |
} |
| 118 |
} |
| 119 |
|