abstracts
4 years ago
admin
4 years ago
elementor
4 years ago
export
4 years ago
fields
4 years ago
interfaces
8 years ago
libraries
7 years ago
log-handlers
4 years ago
shortcodes
4 years ago
templates
5 years ago
class-everest-forms.php
4 years ago
class-evf-ajax.php
4 years ago
class-evf-autoloader.php
7 years ago
class-evf-background-updater.php
7 years ago
class-evf-cache-helper.php
6 years ago
class-evf-deprecated-action-hooks.php
6 years ago
class-evf-deprecated-filter-hooks.php
5 years ago
class-evf-emails.php
5 years ago
class-evf-fields.php
6 years ago
class-evf-form-block.php
4 years ago
class-evf-form-handler.php
4 years ago
class-evf-form-task.php
4 years ago
class-evf-forms-features.php
4 years ago
class-evf-frontend-scripts.php
4 years ago
class-evf-install.php
5 years ago
class-evf-integrations.php
7 years ago
class-evf-log-levels.php
8 years ago
class-evf-logger.php
5 years ago
class-evf-post-types.php
5 years ago
class-evf-privacy.php
6 years ago
class-evf-session-handler.php
7 years ago
class-evf-shortcodes.php
4 years ago
class-evf-smart-tags.php
4 years ago
class-evf-template-loader.php
4 years ago
class-evf-validation.php
6 years ago
evf-conditional-functions.php
6 years ago
evf-core-functions.php
4 years ago
evf-deprecated-functions.php
6 years ago
evf-entry-functions.php
4 years ago
evf-formatting-functions.php
4 years ago
evf-notice-functions.php
4 years ago
evf-template-functions.php
4 years ago
evf-template-hooks.php
7 years ago
evf-update-functions.php
5 years ago
evf-core-functions.php
2611 lines
| 1 | <?php |
| 2 | /** |
| 3 | * EverestForms Core Functions |
| 4 | * |
| 5 | * General core functions available on both the front-end and admin. |
| 6 | * |
| 7 | * @package EverestForms/Functions |
| 8 | * @version 1.0.0 |
| 9 | */ |
| 10 | |
| 11 | defined( 'ABSPATH' ) || exit; |
| 12 | |
| 13 | // Include core functions (available in both admin and frontend). |
| 14 | require EVF_ABSPATH . 'includes/evf-conditional-functions.php'; |
| 15 | require EVF_ABSPATH . 'includes/evf-deprecated-functions.php'; |
| 16 | require EVF_ABSPATH . 'includes/evf-formatting-functions.php'; |
| 17 | require EVF_ABSPATH . 'includes/evf-entry-functions.php'; |
| 18 | |
| 19 | /** |
| 20 | * Define a constant if it is not already defined. |
| 21 | * |
| 22 | * @since 1.0.0 |
| 23 | * @param string $name Constant name. |
| 24 | * @param mixed $value Value. |
| 25 | */ |
| 26 | function evf_maybe_define_constant( $name, $value ) { |
| 27 | if ( ! defined( $name ) ) { |
| 28 | define( $name, $value ); |
| 29 | } |
| 30 | } |
| 31 | |
| 32 | /** |
| 33 | * Get template part. |
| 34 | * |
| 35 | * EVF_TEMPLATE_DEBUG_MODE will prevent overrides in themes from taking priority. |
| 36 | * |
| 37 | * @param mixed $slug Template slug. |
| 38 | * @param string $name Template name (default: ''). |
| 39 | */ |
| 40 | function evf_get_template_part( $slug, $name = '' ) { |
| 41 | $cache_key = sanitize_key( implode( '-', array( 'template-part', $slug, $name, EVF_VERSION ) ) ); |
| 42 | $template = (string) wp_cache_get( $cache_key, 'everest-forms' ); |
| 43 | |
| 44 | if ( ! $template ) { |
| 45 | if ( $name ) { |
| 46 | $template = EVF_TEMPLATE_DEBUG_MODE ? '' : locate_template( |
| 47 | array( |
| 48 | "{$slug}-{$name}.php", |
| 49 | evf()->template_path() . "{$slug}-{$name}.php", |
| 50 | ) |
| 51 | ); |
| 52 | |
| 53 | if ( ! $template ) { |
| 54 | $fallback = evf()->plugin_path() . "/templates/{$slug}-{$name}.php"; |
| 55 | $template = file_exists( $fallback ) ? $fallback : ''; |
| 56 | } |
| 57 | } |
| 58 | |
| 59 | if ( ! $template ) { |
| 60 | // If template file doesn't exist, look in yourtheme/slug.php and yourtheme/everest-forms/slug.php. |
| 61 | $template = EVF_TEMPLATE_DEBUG_MODE ? '' : locate_template( |
| 62 | array( |
| 63 | "{$slug}.php", |
| 64 | evf()->template_path() . "{$slug}.php", |
| 65 | ) |
| 66 | ); |
| 67 | } |
| 68 | |
| 69 | wp_cache_set( $cache_key, $template, 'everest-forms' ); |
| 70 | } |
| 71 | |
| 72 | // Allow 3rd party plugins to filter template file from their plugin. |
| 73 | $template = apply_filters( 'evf_get_template_part', $template, $slug, $name ); |
| 74 | |
| 75 | if ( $template ) { |
| 76 | load_template( $template, false ); |
| 77 | } |
| 78 | } |
| 79 | |
| 80 | /** |
| 81 | * Get other templates passing attributes and including the file. |
| 82 | * |
| 83 | * @param string $template_name Template name. |
| 84 | * @param array $args Arguments. (default: array). |
| 85 | * @param string $template_path Template path. (default: ''). |
| 86 | * @param string $default_path Default path. (default: ''). |
| 87 | */ |
| 88 | function evf_get_template( $template_name, $args = array(), $template_path = '', $default_path = '' ) { |
| 89 | $cache_key = sanitize_key( implode( '-', array( 'template', $template_name, $template_path, $default_path, EVF_VERSION ) ) ); |
| 90 | $template = (string) wp_cache_get( $cache_key, 'everest-forms' ); |
| 91 | |
| 92 | if ( ! $template ) { |
| 93 | $template = evf_locate_template( $template_name, $template_path, $default_path ); |
| 94 | wp_cache_set( $cache_key, $template, 'everest-forms' ); |
| 95 | } |
| 96 | |
| 97 | // Allow 3rd party plugin filter template file from their plugin. |
| 98 | $filter_template = apply_filters( 'evf_get_template', $template, $template_name, $args, $template_path, $default_path ); |
| 99 | |
| 100 | if ( $filter_template !== $template ) { |
| 101 | if ( ! file_exists( $filter_template ) ) { |
| 102 | /* translators: %s template */ |
| 103 | evf_doing_it_wrong( __FUNCTION__, sprintf( __( '%s does not exist.', 'everest-forms' ), '<code>' . $filter_template . '</code>' ), '1.0.0' ); |
| 104 | return; |
| 105 | } |
| 106 | $template = $filter_template; |
| 107 | } |
| 108 | |
| 109 | $action_args = array( |
| 110 | 'template_name' => $template_name, |
| 111 | 'template_path' => $template_path, |
| 112 | 'located' => $template, |
| 113 | 'args' => $args, |
| 114 | ); |
| 115 | |
| 116 | if ( ! empty( $args ) && is_array( $args ) ) { |
| 117 | if ( isset( $args['action_args'] ) ) { |
| 118 | evf_doing_it_wrong( |
| 119 | __FUNCTION__, |
| 120 | __( 'action_args should not be overwritten when calling evf_get_template.', 'everest-forms' ), |
| 121 | '1.4.9' |
| 122 | ); |
| 123 | unset( $args['action_args'] ); |
| 124 | } |
| 125 | extract( $args ); // @codingStandardsIgnoreLine |
| 126 | } |
| 127 | |
| 128 | do_action( 'everest_forms_before_template_part', $action_args['template_name'], $action_args['template_path'], $action_args['located'], $action_args['args'] ); |
| 129 | |
| 130 | include $action_args['located']; |
| 131 | |
| 132 | do_action( 'everest_forms_after_template_part', $action_args['template_name'], $action_args['template_path'], $action_args['located'], $action_args['args'] ); |
| 133 | } |
| 134 | |
| 135 | /** |
| 136 | * Like evf_get_template, but returns the HTML instead of outputting. |
| 137 | * |
| 138 | * @see evf_get_template |
| 139 | * @since 1.0.0 |
| 140 | * @param string $template_name Template name. |
| 141 | * @param array $args Arguments. (default: array). |
| 142 | * @param string $template_path Template path. (default: ''). |
| 143 | * @param string $default_path Default path. (default: ''). |
| 144 | * @return string |
| 145 | */ |
| 146 | function evf_get_template_html( $template_name, $args = array(), $template_path = '', $default_path = '' ) { |
| 147 | ob_start(); |
| 148 | evf_get_template( $template_name, $args, $template_path, $default_path ); |
| 149 | return ob_get_clean(); |
| 150 | } |
| 151 | |
| 152 | /** |
| 153 | * Locate a template and return the path for inclusion. |
| 154 | * |
| 155 | * This is the load order: |
| 156 | * |
| 157 | * yourtheme/$template_path/$template_name |
| 158 | * yourtheme/$template_name |
| 159 | * $default_path/$template_name |
| 160 | * |
| 161 | * @param string $template_name Template name. |
| 162 | * @param string $template_path Template path. (default: ''). |
| 163 | * @param string $default_path Default path. (default: ''). |
| 164 | * @return string |
| 165 | */ |
| 166 | function evf_locate_template( $template_name, $template_path = '', $default_path = '' ) { |
| 167 | if ( ! $template_path ) { |
| 168 | $template_path = evf()->template_path(); |
| 169 | } |
| 170 | |
| 171 | if ( ! $default_path ) { |
| 172 | $default_path = evf()->plugin_path() . '/templates/'; |
| 173 | } |
| 174 | |
| 175 | // Look within passed path within the theme - this is priority. |
| 176 | $template = locate_template( |
| 177 | array( |
| 178 | trailingslashit( $template_path ) . $template_name, |
| 179 | $template_name, |
| 180 | ) |
| 181 | ); |
| 182 | |
| 183 | // Get default template/. |
| 184 | if ( ! $template || EVF_TEMPLATE_DEBUG_MODE ) { |
| 185 | $template = $default_path . $template_name; |
| 186 | } |
| 187 | |
| 188 | // Return what we found. |
| 189 | return apply_filters( 'everest_forms_locate_template', $template, $template_name, $template_path ); |
| 190 | } |
| 191 | |
| 192 | /** |
| 193 | * Send HTML emails from EverestForms. |
| 194 | * |
| 195 | * @param mixed $to Receiver. |
| 196 | * @param mixed $subject Subject. |
| 197 | * @param mixed $message Message. |
| 198 | * @param string $headers Headers. (default: "Content-Type: text/html\r\n"). |
| 199 | * @param string $attachments Attachments. (default: ""). |
| 200 | */ |
| 201 | function evf_mail( $to, $subject, $message, $headers = "Content-Type: text/html\r\n", $attachments = '' ) { |
| 202 | $mailer = evf()->mailer(); |
| 203 | |
| 204 | $mailer->send( $to, $subject, $message, $headers, $attachments ); |
| 205 | } |
| 206 | |
| 207 | /** |
| 208 | * Queue some JavaScript code to be output in the footer. |
| 209 | * |
| 210 | * @param string $code Code. |
| 211 | */ |
| 212 | function evf_enqueue_js( $code ) { |
| 213 | global $evf_queued_js; |
| 214 | |
| 215 | if ( empty( $evf_queued_js ) ) { |
| 216 | $evf_queued_js = ''; |
| 217 | } |
| 218 | |
| 219 | $evf_queued_js .= "\n" . $code . "\n"; |
| 220 | } |
| 221 | |
| 222 | /** |
| 223 | * Output any queued javascript code in the footer. |
| 224 | */ |
| 225 | function evf_print_js() { |
| 226 | global $evf_queued_js; |
| 227 | |
| 228 | if ( ! empty( $evf_queued_js ) ) { |
| 229 | // Sanitize. |
| 230 | $evf_queued_js = wp_check_invalid_utf8( $evf_queued_js ); |
| 231 | $evf_queued_js = preg_replace( '/&#(x)?0*(?(1)27|39);?/i', "'", $evf_queued_js ); |
| 232 | $evf_queued_js = str_replace( "\r", '', $evf_queued_js ); |
| 233 | |
| 234 | $js = "<!-- Everest Forms JavaScript -->\n<script type=\"text/javascript\">\njQuery(function($) { $evf_queued_js });\n</script>\n"; |
| 235 | |
| 236 | /** |
| 237 | * Queued jsfilter. |
| 238 | * |
| 239 | * @since 1.0.0 |
| 240 | * @param string $js JavaScript code. |
| 241 | */ |
| 242 | echo wp_kses( apply_filters( 'everest_forms_queued_js', $js ), array( 'script' => array( 'type' => true ) ) ); |
| 243 | unset( $evf_queued_js ); |
| 244 | } |
| 245 | } |
| 246 | |
| 247 | /** |
| 248 | * Set a cookie - wrapper for setcookie using WP constants. |
| 249 | * |
| 250 | * @param string $name Name of the cookie being set. |
| 251 | * @param string $value Value of the cookie. |
| 252 | * @param integer $expire Expiry of the cookie. |
| 253 | * @param bool $secure Whether the cookie should be served only over https. |
| 254 | * @param bool $httponly Whether the cookie is only accessible over HTTP, not scripting languages like JavaScript. @since 1.4.9. |
| 255 | */ |
| 256 | function evf_setcookie( $name, $value, $expire = 0, $secure = false, $httponly = false ) { |
| 257 | if ( ! headers_sent() ) { |
| 258 | setcookie( $name, $value, $expire, COOKIEPATH ? COOKIEPATH : '/', COOKIE_DOMAIN, $secure, apply_filters( 'everest_forms_cookie_httponly', $httponly, $name, $value, $expire, $secure ) ); |
| 259 | } elseif ( defined( 'WP_DEBUG' ) && WP_DEBUG ) { |
| 260 | headers_sent( $file, $line ); |
| 261 | trigger_error( "{$name} cookie cannot be set - headers already sent by {$file} on line {$line}", E_USER_NOTICE ); // @codingStandardsIgnoreLine |
| 262 | } |
| 263 | } |
| 264 | |
| 265 | /** |
| 266 | * Get a log file path. |
| 267 | * |
| 268 | * @since 1.0.0 |
| 269 | * |
| 270 | * @param string $handle name. |
| 271 | * @return string the log file path. |
| 272 | */ |
| 273 | function evf_get_log_file_path( $handle ) { |
| 274 | return EVF_Log_Handler_File::get_log_file_path( $handle ); |
| 275 | } |
| 276 | |
| 277 | /** |
| 278 | * Get a csv file name. |
| 279 | * |
| 280 | * File names consist of the handle, followed by the date, followed by a hash, .csv. |
| 281 | * |
| 282 | * @since 1.3.0 |
| 283 | * |
| 284 | * @param string $handle Name. |
| 285 | * @return bool|string The csv file name or false if cannot be determined. |
| 286 | */ |
| 287 | function evf_get_csv_file_name( $handle ) { |
| 288 | if ( function_exists( 'wp_hash' ) ) { |
| 289 | $date_suffix = date_i18n( 'Y-m-d', time() ); |
| 290 | $hash_suffix = wp_hash( $handle ); |
| 291 | return sanitize_file_name( implode( '-', array( 'evf-entry-export', $handle, $date_suffix, $hash_suffix ) ) . '.csv' ); |
| 292 | } else { |
| 293 | evf_doing_it_wrong( __METHOD__, __( 'This method should not be called before plugins_loaded.', 'everest-forms' ), '1.3.0' ); |
| 294 | return false; |
| 295 | } |
| 296 | } |
| 297 | |
| 298 | /** |
| 299 | * Recursively get page children. |
| 300 | * |
| 301 | * @param int $page_id Page ID. |
| 302 | * @return int[] |
| 303 | */ |
| 304 | function evf_get_page_children( $page_id ) { |
| 305 | $page_ids = get_posts( |
| 306 | array( |
| 307 | 'post_parent' => $page_id, |
| 308 | 'post_type' => 'page', |
| 309 | 'numberposts' => - 1, |
| 310 | 'post_status' => 'any', |
| 311 | 'fields' => 'ids', |
| 312 | ) |
| 313 | ); |
| 314 | |
| 315 | if ( ! empty( $page_ids ) ) { |
| 316 | foreach ( $page_ids as $page_id ) { |
| 317 | $page_ids = array_merge( $page_ids, evf_get_page_children( $page_id ) ); |
| 318 | } |
| 319 | } |
| 320 | |
| 321 | return $page_ids; |
| 322 | } |
| 323 | |
| 324 | /** |
| 325 | * Get user agent string. |
| 326 | * |
| 327 | * @since 1.0.0 |
| 328 | * @return string |
| 329 | */ |
| 330 | function evf_get_user_agent() { |
| 331 | return isset( $_SERVER['HTTP_USER_AGENT'] ) ? evf_clean( wp_unslash( $_SERVER['HTTP_USER_AGENT'] ) ) : ''; // @codingStandardsIgnoreLine |
| 332 | } |
| 333 | |
| 334 | // This function can be removed when WP 3.9.2 or greater is required. |
| 335 | if ( ! function_exists( 'hash_equals' ) ) : |
| 336 | /** |
| 337 | * Compare two strings in constant time. |
| 338 | * |
| 339 | * This function was added in PHP 5.6. |
| 340 | * It can leak the length of a string. |
| 341 | * |
| 342 | * @since 1.0.0 |
| 343 | * |
| 344 | * @param string $a Expected string. |
| 345 | * @param string $b Actual string. |
| 346 | * @return bool Whether strings are equal. |
| 347 | */ |
| 348 | function hash_equals( $a, $b ) { |
| 349 | $a_length = strlen( $a ); |
| 350 | if ( strlen( $b ) !== $a_length ) { |
| 351 | return false; |
| 352 | } |
| 353 | $result = 0; |
| 354 | |
| 355 | // Do not attempt to "optimize" this. |
| 356 | for ( $i = 0; $i < $a_length; $i ++ ) { |
| 357 | $result |= ord( $a[ $i ] ) ^ ord( $b[ $i ] ); |
| 358 | } |
| 359 | |
| 360 | return 0 === $result; |
| 361 | } |
| 362 | endif; |
| 363 | |
| 364 | /** |
| 365 | * Generate a rand hash. |
| 366 | * |
| 367 | * @since 1.0.0 |
| 368 | * @return string |
| 369 | */ |
| 370 | function evf_rand_hash() { |
| 371 | if ( ! function_exists( 'openssl_random_pseudo_bytes' ) ) { |
| 372 | return sha1( wp_rand() ); |
| 373 | } |
| 374 | |
| 375 | return bin2hex( openssl_random_pseudo_bytes( 20 ) ); // @codingStandardsIgnoreLine |
| 376 | } |
| 377 | |
| 378 | /** |
| 379 | * Find all possible combinations of values from the input array and return in a logical order. |
| 380 | * |
| 381 | * @since 1.0.0 |
| 382 | * @param array $input Input. |
| 383 | * @return array |
| 384 | */ |
| 385 | function evf_array_cartesian( $input ) { |
| 386 | $input = array_filter( $input ); |
| 387 | $results = array(); |
| 388 | $indexes = array(); |
| 389 | $index = 0; |
| 390 | |
| 391 | // Generate indexes from keys and values so we have a logical sort order. |
| 392 | foreach ( $input as $key => $values ) { |
| 393 | foreach ( $values as $value ) { |
| 394 | $indexes[ $key ][ $value ] = $index++; |
| 395 | } |
| 396 | } |
| 397 | |
| 398 | // Loop over the 2D array of indexes and generate all combinations. |
| 399 | foreach ( $indexes as $key => $values ) { |
| 400 | // When result is empty, fill with the values of the first looped array. |
| 401 | if ( empty( $results ) ) { |
| 402 | foreach ( $values as $value ) { |
| 403 | $results[] = array( $key => $value ); |
| 404 | } |
| 405 | } else { |
| 406 | // Second and subsequent input sub-array merging. |
| 407 | foreach ( $results as $result_key => $result ) { |
| 408 | foreach ( $values as $value ) { |
| 409 | // If the key is not set, we can set it. |
| 410 | if ( ! isset( $results[ $result_key ][ $key ] ) ) { |
| 411 | $results[ $result_key ][ $key ] = $value; |
| 412 | } else { |
| 413 | // If the key is set, we can add a new combination to the results array. |
| 414 | $new_combination = $results[ $result_key ]; |
| 415 | $new_combination[ $key ] = $value; |
| 416 | $results[] = $new_combination; |
| 417 | } |
| 418 | } |
| 419 | } |
| 420 | } |
| 421 | } |
| 422 | |
| 423 | // Sort the indexes. |
| 424 | arsort( $results ); |
| 425 | |
| 426 | // Convert indexes back to values. |
| 427 | foreach ( $results as $result_key => $result ) { |
| 428 | $converted_values = array(); |
| 429 | |
| 430 | // Sort the values. |
| 431 | arsort( $results[ $result_key ] ); |
| 432 | |
| 433 | // Convert the values. |
| 434 | foreach ( $results[ $result_key ] as $key => $value ) { |
| 435 | $converted_values[ $key ] = array_search( $value, $indexes[ $key ], true ); |
| 436 | } |
| 437 | |
| 438 | $results[ $result_key ] = $converted_values; |
| 439 | } |
| 440 | |
| 441 | return $results; |
| 442 | } |
| 443 | |
| 444 | /** |
| 445 | * Run a MySQL transaction query, if supported. |
| 446 | * |
| 447 | * @since 1.0.0 |
| 448 | * @param string $type Types: start (default), commit, rollback. |
| 449 | * @param bool $force use of transactions. |
| 450 | */ |
| 451 | function evf_transaction_query( $type = 'start', $force = false ) { |
| 452 | global $wpdb; |
| 453 | |
| 454 | $wpdb->hide_errors(); |
| 455 | |
| 456 | evf_maybe_define_constant( 'EVF_USE_TRANSACTIONS', true ); |
| 457 | |
| 458 | if ( EVF_USE_TRANSACTIONS || $force ) { |
| 459 | switch ( $type ) { |
| 460 | case 'commit': |
| 461 | $wpdb->query( 'COMMIT' ); |
| 462 | break; |
| 463 | case 'rollback': |
| 464 | $wpdb->query( 'ROLLBACK' ); |
| 465 | break; |
| 466 | default: |
| 467 | $wpdb->query( 'START TRANSACTION' ); |
| 468 | break; |
| 469 | } |
| 470 | } |
| 471 | } |
| 472 | |
| 473 | /** |
| 474 | * Outputs a "back" link so admin screens can easily jump back a page. |
| 475 | * |
| 476 | * @param string $label Title of the page to return to. |
| 477 | * @param string $url URL of the page to return to. |
| 478 | */ |
| 479 | function evf_back_link( $label, $url ) { |
| 480 | echo '<small class="evf-admin-breadcrumb"><a href="' . esc_url( $url ) . '" aria-label="' . esc_attr( $label ) . '">⤴</a></small>'; |
| 481 | } |
| 482 | |
| 483 | /** |
| 484 | * Display a EverestForms help tip. |
| 485 | * |
| 486 | * @since 1.0.0 |
| 487 | * |
| 488 | * @param string $tip Help tip text. |
| 489 | * @param bool $allow_html Allow sanitized HTML if true or escape. |
| 490 | * @return string |
| 491 | */ |
| 492 | function evf_help_tip( $tip, $allow_html = false ) { |
| 493 | if ( $allow_html ) { |
| 494 | $tip = evf_sanitize_tooltip( $tip ); |
| 495 | } else { |
| 496 | $tip = esc_attr( $tip ); |
| 497 | } |
| 498 | |
| 499 | return '<span class="everest-forms-help-tip" data-tip="' . $tip . '"></span>'; |
| 500 | } |
| 501 | |
| 502 | /** |
| 503 | * Wrapper for set_time_limit to see if it is enabled. |
| 504 | * |
| 505 | * @since 1.0.0 |
| 506 | * @param int $limit Time limit. |
| 507 | */ |
| 508 | function evf_set_time_limit( $limit = 0 ) { |
| 509 | if ( function_exists( 'set_time_limit' ) && false === strpos( ini_get( 'disable_functions' ), 'set_time_limit' ) && ! ini_get( 'safe_mode' ) ) { // phpcs:ignore PHPCompatibility.IniDirectives.RemovedIniDirectives.safe_modeDeprecatedRemoved |
| 510 | @set_time_limit( $limit ); // @codingStandardsIgnoreLine |
| 511 | } |
| 512 | } |
| 513 | |
| 514 | /** |
| 515 | * Wrapper for nocache_headers which also disables page caching. |
| 516 | * |
| 517 | * @since 1.2.0 |
| 518 | */ |
| 519 | function evf_nocache_headers() { |
| 520 | EVF_Cache_Helper::set_nocache_constants(); |
| 521 | nocache_headers(); |
| 522 | } |
| 523 | |
| 524 | /** |
| 525 | * Get a shared logger instance. |
| 526 | * |
| 527 | * Use the everest_forms_logging_class filter to change the logging class. You may provide one of the following: |
| 528 | * - a class name which will be instantiated as `new $class` with no arguments |
| 529 | * - an instance which will be used directly as the logger |
| 530 | * In either case, the class or instance *must* implement EVF_Logger_Interface. |
| 531 | * |
| 532 | * @see EVF_Logger_Interface |
| 533 | * |
| 534 | * @return EVF_Logger |
| 535 | */ |
| 536 | function evf_get_logger() { |
| 537 | static $logger = null; |
| 538 | |
| 539 | $class = apply_filters( 'everest_forms_logging_class', 'EVF_Logger' ); |
| 540 | |
| 541 | if ( null !== $logger && is_string( $class ) && is_a( $logger, $class ) ) { |
| 542 | return $logger; |
| 543 | } |
| 544 | |
| 545 | $implements = class_implements( $class ); |
| 546 | |
| 547 | if ( is_array( $implements ) && in_array( 'EVF_Logger_Interface', $implements, true ) ) { |
| 548 | $logger = is_object( $class ) ? $class : new $class(); |
| 549 | } else { |
| 550 | evf_doing_it_wrong( |
| 551 | __FUNCTION__, |
| 552 | sprintf( |
| 553 | /* translators: 1: class name 2: everest_forms_logging_class 3: EVF_Logger_Interface */ |
| 554 | __( 'The class %1$s provided by %2$s filter must implement %3$s.', 'everest-forms' ), |
| 555 | '<code>' . esc_html( is_object( $class ) ? get_class( $class ) : $class ) . '</code>', |
| 556 | '<code>everest_forms_logging_class</code>', |
| 557 | '<code>EVF_Logger_Interface</code>' |
| 558 | ), |
| 559 | '1.2' |
| 560 | ); |
| 561 | $logger = is_a( $logger, 'EVF_Logger' ) ? $logger : new EVF_Logger(); |
| 562 | } |
| 563 | |
| 564 | return $logger; |
| 565 | } |
| 566 | |
| 567 | /** |
| 568 | * Prints human-readable information about a variable. |
| 569 | * |
| 570 | * Some server environments blacklist some debugging functions. This function provides a safe way to |
| 571 | * turn an expression into a printable, readable form without calling blacklisted functions. |
| 572 | * |
| 573 | * @since 1.0.0 |
| 574 | * |
| 575 | * @param mixed $expression The expression to be printed. |
| 576 | * @param bool $return Optional. Default false. Set to true to return the human-readable string. |
| 577 | * |
| 578 | * @return string|bool False if expression could not be printed. True if the expression was printed. |
| 579 | * If $return is true, a string representation will be returned. |
| 580 | */ |
| 581 | function evf_print_r( $expression, $return = false ) { |
| 582 | $alternatives = array( |
| 583 | array( |
| 584 | 'func' => 'print_r', |
| 585 | 'args' => array( $expression, true ), |
| 586 | ), |
| 587 | array( |
| 588 | 'func' => 'var_export', |
| 589 | 'args' => array( $expression, true ), |
| 590 | ), |
| 591 | array( |
| 592 | 'func' => 'json_encode', |
| 593 | 'args' => array( $expression ), |
| 594 | ), |
| 595 | array( |
| 596 | 'func' => 'serialize', |
| 597 | 'args' => array( $expression ), |
| 598 | ), |
| 599 | ); |
| 600 | |
| 601 | $alternatives = apply_filters( 'everest_forms_print_r_alternatives', $alternatives, $expression ); |
| 602 | |
| 603 | foreach ( $alternatives as $alternative ) { |
| 604 | if ( function_exists( $alternative['func'] ) ) { |
| 605 | $res = call_user_func_array( $alternative['func'], $alternative['args'] ); |
| 606 | if ( $return ) { |
| 607 | return $res; |
| 608 | } |
| 609 | |
| 610 | echo wp_kses_post( $res ); |
| 611 | return true; |
| 612 | } |
| 613 | } |
| 614 | |
| 615 | return false; |
| 616 | } |
| 617 | |
| 618 | /** |
| 619 | * Registers the default log handler. |
| 620 | * |
| 621 | * @since 1.0.0 |
| 622 | * @param array $handlers Handlers. |
| 623 | * @return array |
| 624 | */ |
| 625 | function evf_register_default_log_handler( $handlers ) { |
| 626 | if ( defined( 'EVF_LOG_HANDLER' ) && class_exists( EVF_LOG_HANDLER ) ) { |
| 627 | $handler_class = EVF_LOG_HANDLER; |
| 628 | $default_handler = new $handler_class(); |
| 629 | } else { |
| 630 | $default_handler = new EVF_Log_Handler_File(); |
| 631 | } |
| 632 | |
| 633 | array_push( $handlers, $default_handler ); |
| 634 | |
| 635 | return $handlers; |
| 636 | } |
| 637 | |
| 638 | add_filter( 'everest_forms_register_log_handlers', 'evf_register_default_log_handler' ); |
| 639 | |
| 640 | /** |
| 641 | * Based on wp_list_pluck, this calls a method instead of returning a property. |
| 642 | * |
| 643 | * @since 1.0.0 |
| 644 | * @param array $list List of objects or arrays. |
| 645 | * @param int|string $callback_or_field Callback method from the object to place instead of the entire object. |
| 646 | * @param int|string $index_key Optional. Field from the object to use as keys for the new array. |
| 647 | * Default null. |
| 648 | * @return array Array of values. |
| 649 | */ |
| 650 | function evf_list_pluck( $list, $callback_or_field, $index_key = null ) { |
| 651 | // Use wp_list_pluck if this isn't a callback. |
| 652 | $first_el = current( $list ); |
| 653 | if ( ! is_object( $first_el ) || ! is_callable( array( $first_el, $callback_or_field ) ) ) { |
| 654 | return wp_list_pluck( $list, $callback_or_field, $index_key ); |
| 655 | } |
| 656 | if ( ! $index_key ) { |
| 657 | /* |
| 658 | * This is simple. Could at some point wrap array_column() |
| 659 | * if we knew we had an array of arrays. |
| 660 | */ |
| 661 | foreach ( $list as $key => $value ) { |
| 662 | $list[ $key ] = $value->{$callback_or_field}(); |
| 663 | } |
| 664 | return $list; |
| 665 | } |
| 666 | |
| 667 | /* |
| 668 | * When index_key is not set for a particular item, push the value |
| 669 | * to the end of the stack. This is how array_column() behaves. |
| 670 | */ |
| 671 | $newlist = array(); |
| 672 | foreach ( $list as $value ) { |
| 673 | // Get index. |
| 674 | if ( is_callable( array( $value, $index_key ) ) ) { |
| 675 | $newlist[ $value->{$index_key}() ] = $value->{$callback_or_field}(); |
| 676 | } elseif ( isset( $value->$index_key ) ) { |
| 677 | $newlist[ $value->$index_key ] = $value->{$callback_or_field}(); |
| 678 | } else { |
| 679 | $newlist[] = $value->{$callback_or_field}(); |
| 680 | } |
| 681 | } |
| 682 | return $newlist; |
| 683 | } |
| 684 | |
| 685 | /** |
| 686 | * Switch EverestForms to site language. |
| 687 | * |
| 688 | * @since 1.0.0 |
| 689 | */ |
| 690 | function evf_switch_to_site_locale() { |
| 691 | if ( function_exists( 'switch_to_locale' ) ) { |
| 692 | switch_to_locale( get_locale() ); |
| 693 | |
| 694 | // Filter on plugin_locale so load_plugin_textdomain loads the correct locale. |
| 695 | add_filter( 'plugin_locale', 'get_locale' ); |
| 696 | |
| 697 | // Init EVF locale. |
| 698 | evf()->load_plugin_textdomain(); |
| 699 | } |
| 700 | } |
| 701 | |
| 702 | /** |
| 703 | * Switch EverestForms language to original. |
| 704 | * |
| 705 | * @since 1.0.0 |
| 706 | */ |
| 707 | function evf_restore_locale() { |
| 708 | if ( function_exists( 'restore_previous_locale' ) ) { |
| 709 | restore_previous_locale(); |
| 710 | |
| 711 | // Remove filter. |
| 712 | remove_filter( 'plugin_locale', 'get_locale' ); |
| 713 | |
| 714 | // Init EVF locale. |
| 715 | evf()->load_plugin_textdomain(); |
| 716 | } |
| 717 | } |
| 718 | |
| 719 | /** |
| 720 | * Get an item of post data if set, otherwise return a default value. |
| 721 | * |
| 722 | * @since 1.0.0 |
| 723 | * @param string $key Key. |
| 724 | * @param string $default Default. |
| 725 | * @return mixed value sanitized by evf_clean |
| 726 | */ |
| 727 | function evf_get_post_data_by_key( $key, $default = '' ) { |
| 728 | return evf_clean( evf_get_var( $_POST[ $key ], $default ) ); // @codingStandardsIgnoreLine |
| 729 | } |
| 730 | |
| 731 | /** |
| 732 | * Get data if set, otherwise return a default value or null. Prevents notices when data is not set. |
| 733 | * |
| 734 | * @since 1.0.0 |
| 735 | * @param mixed $var Variable. |
| 736 | * @param string $default Default value. |
| 737 | * @return mixed |
| 738 | */ |
| 739 | function evf_get_var( &$var, $default = null ) { |
| 740 | return isset( $var ) ? $var : $default; |
| 741 | } |
| 742 | |
| 743 | /** |
| 744 | * Read in EverestForms headers when reading plugin headers. |
| 745 | * |
| 746 | * @since 1.2.0 |
| 747 | * @param array $headers Headers. |
| 748 | * @return array |
| 749 | */ |
| 750 | function evf_enable_evf_plugin_headers( $headers ) { |
| 751 | if ( ! class_exists( 'EVF_Plugin_Updates' ) ) { |
| 752 | include_once dirname( __FILE__ ) . '/admin/plugin-updates/class-evf-plugin-updates.php'; |
| 753 | } |
| 754 | |
| 755 | // EVF requires at least - allows developers to define which version of Everest Forms the plugin requires to run. |
| 756 | $headers[] = EVF_Plugin_Updates::VERSION_REQUIRED_HEADER; |
| 757 | |
| 758 | // EVF tested up to - allows developers to define which version of Everest Forms they have tested up to. |
| 759 | $headers[] = EVF_Plugin_Updates::VERSION_TESTED_HEADER; |
| 760 | |
| 761 | return $headers; |
| 762 | } |
| 763 | add_filter( 'extra_theme_headers', 'evf_enable_evf_plugin_headers' ); |
| 764 | add_filter( 'extra_plugin_headers', 'evf_enable_evf_plugin_headers' ); |
| 765 | |
| 766 | /** |
| 767 | * Delete expired transients. |
| 768 | * |
| 769 | * Deletes all expired transients. The multi-table delete syntax is used. |
| 770 | * to delete the transient record from table a, and the corresponding. |
| 771 | * transient_timeout record from table b. |
| 772 | * |
| 773 | * Based on code inside core's upgrade_network() function. |
| 774 | * |
| 775 | * @since 1.0.0 |
| 776 | * @return int Number of transients that were cleared. |
| 777 | */ |
| 778 | function evf_delete_expired_transients() { |
| 779 | global $wpdb; |
| 780 | |
| 781 | $sql = "DELETE a, b FROM $wpdb->options a, $wpdb->options b |
| 782 | WHERE a.option_name LIKE %s |
| 783 | AND a.option_name NOT LIKE %s |
| 784 | AND b.option_name = CONCAT( '_transient_timeout_', SUBSTRING( a.option_name, 12 ) ) |
| 785 | AND b.option_value < %d"; |
| 786 | $rows = $wpdb->query( $wpdb->prepare( $sql, $wpdb->esc_like( '_transient_' ) . '%', $wpdb->esc_like( '_transient_timeout_' ) . '%', time() ) ); // phpcs:ignore WordPress.DB.PreparedSQL.NotPrepared |
| 787 | |
| 788 | $sql = "DELETE a, b FROM $wpdb->options a, $wpdb->options b |
| 789 | WHERE a.option_name LIKE %s |
| 790 | AND a.option_name NOT LIKE %s |
| 791 | AND b.option_name = CONCAT( '_site_transient_timeout_', SUBSTRING( a.option_name, 17 ) ) |
| 792 | AND b.option_value < %d"; |
| 793 | $rows2 = $wpdb->query( $wpdb->prepare( $sql, $wpdb->esc_like( '_site_transient_' ) . '%', $wpdb->esc_like( '_site_transient_timeout_' ) . '%', time() ) ); // phpcs:ignore WordPress.DB.PreparedSQL.NotPrepared |
| 794 | |
| 795 | return absint( $rows + $rows2 ); |
| 796 | } |
| 797 | add_action( 'everest_forms_installed', 'evf_delete_expired_transients' ); |
| 798 | |
| 799 | /** |
| 800 | * Make a URL relative, if possible. |
| 801 | * |
| 802 | * @since 1.0.0 |
| 803 | * @param string $url URL to make relative. |
| 804 | * @return string |
| 805 | */ |
| 806 | function evf_get_relative_url( $url ) { |
| 807 | return evf_is_external_resource( $url ) ? $url : str_replace( array( 'http://', 'https://' ), '//', $url ); |
| 808 | } |
| 809 | |
| 810 | /** |
| 811 | * See if a resource is remote. |
| 812 | * |
| 813 | * @since 1.0.0 |
| 814 | * @param string $url URL to check. |
| 815 | * @return bool |
| 816 | */ |
| 817 | function evf_is_external_resource( $url ) { |
| 818 | $wp_base = str_replace( array( 'http://', 'https://' ), '//', get_home_url( null, '/', 'http' ) ); |
| 819 | return strstr( $url, '://' ) && strstr( $wp_base, $url ); |
| 820 | } |
| 821 | |
| 822 | /** |
| 823 | * See if theme/s is activate or not. |
| 824 | * |
| 825 | * @since 1.0.0 |
| 826 | * @param string|array $theme Theme name or array of theme names to check. |
| 827 | * @return boolean |
| 828 | */ |
| 829 | function evf_is_active_theme( $theme ) { |
| 830 | return is_array( $theme ) ? in_array( get_template(), $theme, true ) : get_template() === $theme; |
| 831 | } |
| 832 | |
| 833 | /** |
| 834 | * Cleans up session data - cron callback. |
| 835 | * |
| 836 | * @since 1.0.0 |
| 837 | */ |
| 838 | function evf_cleanup_session_data() { |
| 839 | $session_class = apply_filters( 'everest_forms_session_handler', 'EVF_Session_Handler' ); |
| 840 | $session = new $session_class(); |
| 841 | |
| 842 | if ( is_callable( array( $session, 'cleanup_sessions' ) ) ) { |
| 843 | $session->cleanup_sessions(); |
| 844 | } |
| 845 | } |
| 846 | add_action( 'everest_forms_cleanup_sessions', 'evf_cleanup_session_data' ); |
| 847 | |
| 848 | /** |
| 849 | * Return the html selected attribute if stringified $value is found in array of stringified $options |
| 850 | * or if stringified $value is the same as scalar stringified $options. |
| 851 | * |
| 852 | * @param string|int $value Value to find within options. |
| 853 | * @param string|int|array $options Options to go through when looking for value. |
| 854 | * @return string |
| 855 | */ |
| 856 | function evf_selected( $value, $options ) { |
| 857 | if ( is_array( $options ) ) { |
| 858 | $options = array_map( 'strval', $options ); |
| 859 | return selected( in_array( (string) $value, $options, true ), true, false ); |
| 860 | } |
| 861 | |
| 862 | return selected( $value, $options, false ); |
| 863 | } |
| 864 | |
| 865 | /** |
| 866 | * Retrieve actual fields from a form. |
| 867 | * |
| 868 | * Non-posting elements such as section divider, page break, and HTML are |
| 869 | * automatically excluded. Optionally a white list can be provided. |
| 870 | * |
| 871 | * @since 1.0.0 |
| 872 | * |
| 873 | * @param mixed $form Form data. |
| 874 | * @param array $whitelist Whitelist args. |
| 875 | * |
| 876 | * @return mixed boolean or array |
| 877 | */ |
| 878 | function evf_get_form_fields( $form = false, $whitelist = array() ) { |
| 879 | // Accept form (post) object or form ID. |
| 880 | if ( is_object( $form ) ) { |
| 881 | $form = json_decode( $form->post_content ); |
| 882 | } elseif ( is_numeric( $form ) ) { |
| 883 | $form = evf()->form->get( |
| 884 | $form, |
| 885 | array( |
| 886 | 'content_only' => true, |
| 887 | ) |
| 888 | ); |
| 889 | } |
| 890 | |
| 891 | if ( ! is_array( $form ) || empty( $form['form_fields'] ) ) { |
| 892 | return false; |
| 893 | } |
| 894 | |
| 895 | // White list of field types to allow. |
| 896 | $allowed_form_fields = array( |
| 897 | 'first-name', |
| 898 | 'last-name', |
| 899 | 'text', |
| 900 | 'textarea', |
| 901 | 'select', |
| 902 | 'radio', |
| 903 | 'checkbox', |
| 904 | 'email', |
| 905 | 'address', |
| 906 | 'country', |
| 907 | 'url', |
| 908 | 'name', |
| 909 | 'hidden', |
| 910 | 'date', |
| 911 | 'phone', |
| 912 | 'number', |
| 913 | 'file-upload', |
| 914 | 'image-upload', |
| 915 | 'payment-single', |
| 916 | 'payment-multiple', |
| 917 | 'payment-checkbox', |
| 918 | 'payment-total', |
| 919 | ); |
| 920 | $allowed_form_fields = apply_filters( 'everest_forms_allowed_form_fields', $allowed_form_fields ); |
| 921 | |
| 922 | $whitelist = ! empty( $whitelist ) ? $whitelist : $allowed_form_fields; |
| 923 | |
| 924 | $form_fields = $form['form_fields']; |
| 925 | |
| 926 | foreach ( $form_fields as $id => $form_field ) { |
| 927 | if ( ! in_array( $form_field['type'], $whitelist, true ) ) { |
| 928 | unset( $form_fields[ $id ] ); |
| 929 | } |
| 930 | } |
| 931 | |
| 932 | return $form_fields; |
| 933 | } |
| 934 | |
| 935 | /** |
| 936 | * Sanitize a string, that can be a multiline. |
| 937 | * If WP core `sanitize_textarea_field()` exists (after 4.7.0) - use it. |
| 938 | * Otherwise - split onto separate lines, sanitize each one, merge again. |
| 939 | * |
| 940 | * @since 1.4.1 |
| 941 | * |
| 942 | * @param string $string Raw string to sanitize. |
| 943 | * |
| 944 | * @return string If empty var is passed, or not a string - return unmodified. Otherwise - sanitize. |
| 945 | */ |
| 946 | function evf_sanitize_textarea_field( $string ) { |
| 947 | if ( empty( $string ) || ! is_string( $string ) ) { |
| 948 | return $string; |
| 949 | } |
| 950 | |
| 951 | if ( function_exists( 'sanitize_textarea_field' ) ) { |
| 952 | $string = sanitize_textarea_field( $string ); |
| 953 | } else { |
| 954 | $string = implode( "\n", array_map( 'sanitize_text_field', explode( "\n", $string ) ) ); |
| 955 | } |
| 956 | |
| 957 | return $string; |
| 958 | } |
| 959 | |
| 960 | /** |
| 961 | * Formats, sanitizes, and returns/echos HTML element ID, classes, attributes, |
| 962 | * and data attributes. |
| 963 | * |
| 964 | * @param string $id Element ID. |
| 965 | * @param array $class Class args. |
| 966 | * @param array $datas Data args. |
| 967 | * @param array $atts Attributes. |
| 968 | * @param bool $echo True to echo else return. |
| 969 | * |
| 970 | * @return string |
| 971 | */ |
| 972 | function evf_html_attributes( $id = '', $class = array(), $datas = array(), $atts = array(), $echo = false ) { |
| 973 | $id = trim( $id ); |
| 974 | $parts = array(); |
| 975 | |
| 976 | if ( ! empty( $id ) ) { |
| 977 | $id = sanitize_html_class( $id ); |
| 978 | if ( ! empty( $id ) ) { |
| 979 | $parts[] = 'id="' . $id . '"'; |
| 980 | } |
| 981 | } |
| 982 | |
| 983 | if ( ! empty( $class ) ) { |
| 984 | $class = evf_sanitize_classes( $class, true ); |
| 985 | if ( ! empty( $class ) ) { |
| 986 | $parts[] = 'class="' . $class . '"'; |
| 987 | } |
| 988 | } |
| 989 | |
| 990 | if ( ! empty( $datas ) ) { |
| 991 | foreach ( $datas as $data => $val ) { |
| 992 | $parts[] = 'data-' . sanitize_html_class( $data ) . '="' . esc_attr( $val ) . '"'; |
| 993 | } |
| 994 | } |
| 995 | |
| 996 | if ( ! empty( $atts ) ) { |
| 997 | foreach ( $atts as $att => $val ) { |
| 998 | if ( '0' === $val || ! empty( $val ) ) { |
| 999 | if ( $att[0] === '[' ) { //phpcs:ignore |
| 1000 | // Handle special case for bound attributes in AMP. |
| 1001 | $escaped_att = '[' . sanitize_html_class( trim( $att, '[]' ) ) . ']'; |
| 1002 | } else { |
| 1003 | $escaped_att = sanitize_html_class( $att ); |
| 1004 | } |
| 1005 | $parts[] = $escaped_att . '="' . esc_attr( $val ) . '"'; |
| 1006 | } |
| 1007 | } |
| 1008 | } |
| 1009 | |
| 1010 | $output = implode( ' ', $parts ); |
| 1011 | |
| 1012 | if ( $echo ) { |
| 1013 | echo esc_html( trim( $output ) ); |
| 1014 | } else { |
| 1015 | return trim( $output ); |
| 1016 | } |
| 1017 | } |
| 1018 | |
| 1019 | /** |
| 1020 | * Sanitize string of CSS classes. |
| 1021 | * |
| 1022 | * @param array|string $classes Class names. |
| 1023 | * @param bool $convert True will convert strings to array and vice versa. |
| 1024 | * |
| 1025 | * @return string|array |
| 1026 | */ |
| 1027 | function evf_sanitize_classes( $classes, $convert = false ) { |
| 1028 | $css = array(); |
| 1029 | $array = is_array( $classes ); |
| 1030 | |
| 1031 | if ( ! empty( $classes ) ) { |
| 1032 | if ( ! $array ) { |
| 1033 | $classes = explode( ' ', trim( $classes ) ); |
| 1034 | } |
| 1035 | foreach ( $classes as $class ) { |
| 1036 | $css[] = sanitize_html_class( $class ); |
| 1037 | } |
| 1038 | } |
| 1039 | |
| 1040 | if ( $array ) { |
| 1041 | return $convert ? implode( ' ', $css ) : $css; |
| 1042 | } else { |
| 1043 | return $convert ? $css : implode( ' ', $css ); |
| 1044 | } |
| 1045 | } |
| 1046 | |
| 1047 | /** |
| 1048 | * Performs json_decode and unslash. |
| 1049 | * |
| 1050 | * @since 1.0.0 |
| 1051 | * |
| 1052 | * @param string $data Data to decode. |
| 1053 | * |
| 1054 | * @return array|bool |
| 1055 | */ |
| 1056 | function evf_decode( $data ) { |
| 1057 | if ( ! $data || empty( $data ) ) { |
| 1058 | return false; |
| 1059 | } |
| 1060 | |
| 1061 | return json_decode( $data, true ); |
| 1062 | } |
| 1063 | |
| 1064 | /** |
| 1065 | * Performs json_encode and wp_slash. |
| 1066 | * |
| 1067 | * @since 1.0.0 |
| 1068 | * |
| 1069 | * @param mixed $data Data to encode. |
| 1070 | * |
| 1071 | * @return string |
| 1072 | */ |
| 1073 | function evf_encode( $data = false ) { |
| 1074 | if ( empty( $data ) ) { |
| 1075 | return false; |
| 1076 | } |
| 1077 | |
| 1078 | return wp_slash( wp_json_encode( $data ) ); |
| 1079 | } |
| 1080 | |
| 1081 | /** |
| 1082 | * Crypto rand secure. |
| 1083 | * |
| 1084 | * @param int $min Min value. |
| 1085 | * @param int $max Max value. |
| 1086 | * |
| 1087 | * @return mixed |
| 1088 | */ |
| 1089 | function evf_crypto_rand_secure( $min, $max ) { |
| 1090 | $range = $max - $min; |
| 1091 | if ( $range < 1 ) { |
| 1092 | return $min; |
| 1093 | } // not so random... |
| 1094 | $log = ceil( log( $range, 2 ) ); |
| 1095 | $bytes = (int) ( $log / 8 ) + 1; // Length in bytes. |
| 1096 | $bits = (int) $log + 1; // Length in bits. |
| 1097 | $filter = (int) ( 1 << $bits ) - 1; // Set all lower bits to 1. |
| 1098 | do { |
| 1099 | $rnd = hexdec( bin2hex( openssl_random_pseudo_bytes( $bytes ) ) ); |
| 1100 | $rnd = $rnd & $filter; // Discard irrelevant bits. |
| 1101 | } while ( $rnd > $range ); |
| 1102 | |
| 1103 | return $min + $rnd; |
| 1104 | } |
| 1105 | |
| 1106 | /** |
| 1107 | * Generate random string. |
| 1108 | * |
| 1109 | * @param int $length Length of string. |
| 1110 | * |
| 1111 | * @return string |
| 1112 | */ |
| 1113 | function evf_get_random_string( $length = 10 ) { |
| 1114 | $string = ''; |
| 1115 | $code_alphabet = 'ABCDEFGHIJKLMNOPQRSTUVWXYZ'; |
| 1116 | $code_alphabet .= 'abcdefghijklmnopqrstuvwxyz'; |
| 1117 | $code_alphabet .= '0123456789'; |
| 1118 | $max = strlen( $code_alphabet ); |
| 1119 | for ( $i = 0; $i < $length; $i ++ ) { |
| 1120 | $string .= $code_alphabet[ evf_crypto_rand_secure( 0, $max - 1 ) ]; |
| 1121 | } |
| 1122 | |
| 1123 | return $string; |
| 1124 | } |
| 1125 | |
| 1126 | /** |
| 1127 | * Get all forms. |
| 1128 | * |
| 1129 | * @param bool $skip_disabled_entries True to skip disabled entries. |
| 1130 | * @return array of form data. |
| 1131 | */ |
| 1132 | function evf_get_all_forms( $skip_disabled_entries = false ) { |
| 1133 | $forms = array(); |
| 1134 | $form_ids = wp_parse_id_list( |
| 1135 | evf()->form->get_multiple( |
| 1136 | array( |
| 1137 | 'fields' => 'ids', |
| 1138 | 'status' => 'publish', |
| 1139 | 'order' => 'DESC', |
| 1140 | 'numberposts' => -1, // @codingStandardsIgnoreLine |
| 1141 | ) |
| 1142 | ) |
| 1143 | ); |
| 1144 | |
| 1145 | if ( ! empty( $form_ids ) ) { |
| 1146 | foreach ( $form_ids as $form_id ) { |
| 1147 | $form = evf()->form->get( $form_id ); |
| 1148 | $entries = evf_get_entries_ids( $form_id ); |
| 1149 | $form_data = ! empty( $form->post_content ) ? evf_decode( $form->post_content ) : ''; |
| 1150 | |
| 1151 | if ( ! $form || ( $skip_disabled_entries && count( $entries ) < 1 ) && ( isset( $form_data['settings']['disabled_entries'] ) && '1' === $form_data['settings']['disabled_entries'] ) ) { |
| 1152 | continue; |
| 1153 | } |
| 1154 | |
| 1155 | // Check permissions for forms with viewable. |
| 1156 | if ( current_user_can( 'everest_forms_view_form_entries', $form_id ) ) { |
| 1157 | $forms[ $form_id ] = $form->post_title; |
| 1158 | } |
| 1159 | } |
| 1160 | } |
| 1161 | |
| 1162 | return $forms; |
| 1163 | } |
| 1164 | |
| 1165 | /** |
| 1166 | * Get random meta-key for field option. |
| 1167 | * |
| 1168 | * @param array $field Field data array. |
| 1169 | * @return string |
| 1170 | */ |
| 1171 | function evf_get_meta_key_field_option( $field ) { |
| 1172 | return str_replace( ' ', '_', preg_replace( '/[^a-zA-Z0-9\s`_]/', '', strtolower( $field['label'] ) ) ) . '_' . rand( pow( 10, 3 ), pow( 10, 4 ) - 1 ); // phpcs:ignore WordPress.WP.AlternativeFunctions.rand_rand. |
| 1173 | } |
| 1174 | |
| 1175 | /** |
| 1176 | * Get current user IP Address. |
| 1177 | * |
| 1178 | * @return string |
| 1179 | */ |
| 1180 | function evf_get_ip_address() { |
| 1181 | if ( isset( $_SERVER['HTTP_X_REAL_IP'] ) ) { // WPCS: input var ok, CSRF ok. |
| 1182 | return sanitize_text_field( wp_unslash( $_SERVER['HTTP_X_REAL_IP'] ) ); // WPCS: input var ok, CSRF ok. |
| 1183 | } elseif ( isset( $_SERVER['HTTP_X_FORWARDED_FOR'] ) ) { // WPCS: input var ok, CSRF ok. |
| 1184 | // Proxy servers can send through this header like this: X-Forwarded-For: client1, proxy1, proxy2 |
| 1185 | // Make sure we always only send through the first IP in the list which should always be the client IP. |
| 1186 | return (string) rest_is_ip_address( trim( current( preg_split( '/[,:]/', sanitize_text_field( wp_unslash( $_SERVER['HTTP_X_FORWARDED_FOR'] ) ) ) ) ) ); // WPCS: input var ok, CSRF ok. |
| 1187 | } elseif ( isset( $_SERVER['REMOTE_ADDR'] ) ) { // @codingStandardsIgnoreLine |
| 1188 | return sanitize_text_field( wp_unslash( $_SERVER['REMOTE_ADDR'] ) ); // @codingStandardsIgnoreLine |
| 1189 | } |
| 1190 | return ''; |
| 1191 | } |
| 1192 | |
| 1193 | /** |
| 1194 | * Get User Agent browser and OS type |
| 1195 | * |
| 1196 | * @since 1.1.0 |
| 1197 | * @return array |
| 1198 | */ |
| 1199 | function evf_get_browser() { |
| 1200 | $u_agent = ! empty( $_SERVER['HTTP_USER_AGENT'] ) ? sanitize_text_field( sanitize_text_field( wp_unslash( $_SERVER['HTTP_USER_AGENT'] ) ) ) : ''; |
| 1201 | $bname = 'Unknown'; |
| 1202 | $platform = 'Unknown'; |
| 1203 | $version = ''; |
| 1204 | |
| 1205 | // First get the platform. |
| 1206 | if ( preg_match( '/linux/i', $u_agent ) ) { |
| 1207 | $platform = 'Linux'; |
| 1208 | } elseif ( preg_match( '/macintosh|mac os x/i', $u_agent ) ) { |
| 1209 | $platform = 'MAC OS'; |
| 1210 | } elseif ( preg_match( '/windows|win32/i', $u_agent ) ) { |
| 1211 | $platform = 'Windows'; |
| 1212 | } |
| 1213 | |
| 1214 | // Next get the name of the useragent yes seperately and for good reason. |
| 1215 | if ( preg_match( '/MSIE/i', $u_agent ) && ! preg_match( '/Opera/i', $u_agent ) ) { |
| 1216 | $bname = 'Internet Explorer'; |
| 1217 | $ub = 'MSIE'; |
| 1218 | } elseif ( preg_match( '/Trident/i', $u_agent ) ) { |
| 1219 | // this condition is for IE11. |
| 1220 | $bname = 'Internet Explorer'; |
| 1221 | $ub = 'rv'; |
| 1222 | } elseif ( preg_match( '/Firefox/i', $u_agent ) ) { |
| 1223 | $bname = 'Mozilla Firefox'; |
| 1224 | $ub = 'Firefox'; |
| 1225 | } elseif ( preg_match( '/Chrome/i', $u_agent ) ) { |
| 1226 | $bname = 'Google Chrome'; |
| 1227 | $ub = 'Chrome'; |
| 1228 | } elseif ( preg_match( '/Safari/i', $u_agent ) ) { |
| 1229 | $bname = 'Apple Safari'; |
| 1230 | $ub = 'Safari'; |
| 1231 | } elseif ( preg_match( '/Opera/i', $u_agent ) ) { |
| 1232 | $bname = 'Opera'; |
| 1233 | $ub = 'Opera'; |
| 1234 | } elseif ( preg_match( '/Netscape/i', $u_agent ) ) { |
| 1235 | $bname = 'Netscape'; |
| 1236 | $ub = 'Netscape'; |
| 1237 | } |
| 1238 | |
| 1239 | // Finally get the correct version number. |
| 1240 | // Added "|:". |
| 1241 | $known = array( 'Version', $ub, 'other' ); |
| 1242 | $pattern = '#(?<browser>' . join( '|', $known ) . ')[/|: ]+(?<version>[0-9.|a-zA-Z.]*)#'; |
| 1243 | if ( ! preg_match_all( $pattern, $u_agent, $matches ) ) { // @codingStandardsIgnoreLine |
| 1244 | // We have no matching number just continue. |
| 1245 | } |
| 1246 | |
| 1247 | // See how many we have. |
| 1248 | $i = count( $matches['browser'] ); |
| 1249 | |
| 1250 | if ( 1 !== $i ) { |
| 1251 | // we will have two since we are not using 'other' argument yet. |
| 1252 | // see if version is before or after the name. |
| 1253 | if ( strripos( $u_agent, 'Version' ) < strripos( $u_agent, $ub ) ) { |
| 1254 | $version = $matches['version'][0]; |
| 1255 | } else { |
| 1256 | $version = $matches['version'][1]; |
| 1257 | } |
| 1258 | } else { |
| 1259 | $version = $matches['version'][0]; |
| 1260 | } |
| 1261 | |
| 1262 | // Check if we have a number. |
| 1263 | if ( null === $version || '' === $version ) { |
| 1264 | $version = ''; |
| 1265 | } |
| 1266 | |
| 1267 | return array( |
| 1268 | 'userAgent' => $u_agent, |
| 1269 | 'name' => $bname, |
| 1270 | 'version' => $version, |
| 1271 | 'platform' => $platform, |
| 1272 | 'pattern' => $pattern, |
| 1273 | ); |
| 1274 | } |
| 1275 | |
| 1276 | /** |
| 1277 | * Get the certain date of a specified day in a specified format. |
| 1278 | * |
| 1279 | * @since 1.1.0 |
| 1280 | * |
| 1281 | * @param string $period Supported values: start, end. |
| 1282 | * @param string $timestamp Default is the current timestamp, if left empty. |
| 1283 | * @param string $format Default is a MySQL format. |
| 1284 | * |
| 1285 | * @return string |
| 1286 | */ |
| 1287 | function evf_get_day_period_date( $period, $timestamp = '', $format = 'Y-m-d H:i:s' ) { |
| 1288 | $date = ''; |
| 1289 | |
| 1290 | if ( empty( $timestamp ) ) { |
| 1291 | $timestamp = time(); |
| 1292 | } |
| 1293 | |
| 1294 | switch ( $period ) { |
| 1295 | case 'start_of_day': |
| 1296 | $date = date( $format, strtotime( 'today', $timestamp ) ); // phpcs:ignore WordPress.DateTime.RestrictedFunctions.date_date |
| 1297 | break; |
| 1298 | |
| 1299 | case 'end_of_day': |
| 1300 | $date = date( $format, strtotime( 'tomorrow', $timestamp ) - 1 ); // phpcs:ignore WordPress.DateTime.RestrictedFunctions.date_date |
| 1301 | break; |
| 1302 | |
| 1303 | } |
| 1304 | |
| 1305 | return $date; |
| 1306 | } |
| 1307 | |
| 1308 | /** |
| 1309 | * Get field label by meta key |
| 1310 | * |
| 1311 | * @param int $form_id Form ID. |
| 1312 | * @param string $meta_key Field's meta key. |
| 1313 | * @param array $fields Entry Field Data. |
| 1314 | * |
| 1315 | * @return string|false True if field label exists in form. |
| 1316 | */ |
| 1317 | function evf_get_form_data_by_meta_key( $form_id, $meta_key, $fields = array() ) { |
| 1318 | $get_post = get_post( $form_id ); |
| 1319 | $post_content = json_decode( $get_post->post_content, true ); |
| 1320 | $form_fields = isset( $post_content['form_fields'] ) ? $post_content['form_fields'] : array(); |
| 1321 | |
| 1322 | if ( ! empty( $form_fields ) ) { |
| 1323 | foreach ( $form_fields as $field ) { |
| 1324 | if ( isset( $field['meta-key'] ) && $meta_key === $field['meta-key'] ) { |
| 1325 | return $field['label']; |
| 1326 | } |
| 1327 | } |
| 1328 | } |
| 1329 | |
| 1330 | if ( ! empty( $fields ) ) { |
| 1331 | foreach ( $fields as $field ) { |
| 1332 | if ( isset( $field->meta_key ) && $meta_key === $field->meta_key ) { |
| 1333 | return isset( $field->name ) ? $field->name : $field->value->name; |
| 1334 | } |
| 1335 | } |
| 1336 | } |
| 1337 | |
| 1338 | return false; |
| 1339 | } |
| 1340 | |
| 1341 | /** |
| 1342 | * Get field type by meta key |
| 1343 | * |
| 1344 | * @param int $form_id Form ID. |
| 1345 | * @param string $meta_key Field's meta key. |
| 1346 | * |
| 1347 | * @return string|false True if field type exists in form. |
| 1348 | */ |
| 1349 | function evf_get_field_type_by_meta_key( $form_id, $meta_key ) { |
| 1350 | $get_post = get_post( $form_id ); |
| 1351 | $post_content = json_decode( $get_post->post_content, true ); |
| 1352 | $form_fields = isset( $post_content['form_fields'] ) ? $post_content['form_fields'] : array(); |
| 1353 | |
| 1354 | if ( ! empty( $form_fields ) ) { |
| 1355 | foreach ( $form_fields as $field ) { |
| 1356 | if ( isset( $field['meta-key'] ) && $meta_key === $field['meta-key'] ) { |
| 1357 | return $field['type']; |
| 1358 | } |
| 1359 | } |
| 1360 | } |
| 1361 | |
| 1362 | return false; |
| 1363 | } |
| 1364 | |
| 1365 | /** |
| 1366 | * Get all the email fields of a Form. |
| 1367 | * |
| 1368 | * @param int $form_id Form ID. |
| 1369 | */ |
| 1370 | function evf_get_all_email_fields_by_form_id( $form_id ) { |
| 1371 | $user_emails = array(); |
| 1372 | $form_obj = evf()->form->get( $form_id ); |
| 1373 | $form_data = ! empty( $form_obj->post_content ) ? evf_decode( $form_obj->post_content ) : ''; |
| 1374 | |
| 1375 | if ( ! empty( $form_data['form_fields'] ) ) { |
| 1376 | foreach ( $form_data['form_fields'] as $form_fields ) { |
| 1377 | if ( 'email' === $form_fields['type'] ) { |
| 1378 | $user_emails[ $form_fields['meta-key'] ] = $form_fields['label']; |
| 1379 | } |
| 1380 | } |
| 1381 | } |
| 1382 | |
| 1383 | return $user_emails; |
| 1384 | } |
| 1385 | |
| 1386 | /** |
| 1387 | * Get all the field's meta-key label pair. |
| 1388 | * |
| 1389 | * @param int $form_id Form ID. |
| 1390 | * @return array |
| 1391 | */ |
| 1392 | function evf_get_all_form_fields_by_form_id( $form_id ) { |
| 1393 | $data = array(); |
| 1394 | $form_obj = evf()->form->get( $form_id ); |
| 1395 | $form_data = ! empty( $form_obj->post_content ) ? evf_decode( $form_obj->post_content ) : ''; |
| 1396 | |
| 1397 | if ( ! empty( $form_data['form_fields'] ) ) { |
| 1398 | foreach ( $form_data['form_fields'] as $form_fields ) { |
| 1399 | if ( isset( $form_fields['meta-key'], $form_fields['label'] ) ) { |
| 1400 | $data[ $form_fields['meta-key'] ] = $form_fields['label']; |
| 1401 | } |
| 1402 | } |
| 1403 | } |
| 1404 | |
| 1405 | return $data; |
| 1406 | } |
| 1407 | |
| 1408 | /** |
| 1409 | * Check if the string JSON. |
| 1410 | * |
| 1411 | * @param string $string String to check. |
| 1412 | * @return bool |
| 1413 | */ |
| 1414 | function evf_isJson( $string ) { |
| 1415 | json_decode( $string ); |
| 1416 | return ( json_last_error() == JSON_ERROR_NONE ); // phpcs:ignore WordPress.PHP.StrictComparisons.LooseComparison |
| 1417 | } |
| 1418 | |
| 1419 | /** |
| 1420 | * Checks whether the content passed contains a specific short code. |
| 1421 | * |
| 1422 | * @since 1.1.4 |
| 1423 | * @param string $tag Shortcode tag to check. |
| 1424 | * @return bool |
| 1425 | */ |
| 1426 | function evf_post_content_has_shortcode( $tag = '' ) { |
| 1427 | global $post; |
| 1428 | |
| 1429 | return is_singular() && is_a( $post, 'WP_Post' ) && has_shortcode( $post->post_content, $tag ); |
| 1430 | } |
| 1431 | |
| 1432 | /** |
| 1433 | * Convert a file size provided, such as "2M", to bytes. |
| 1434 | * |
| 1435 | * @since 1.2.0 |
| 1436 | * @link http://stackoverflow.com/a/22500394 |
| 1437 | * |
| 1438 | * @param string $size Size to convert to bytes. |
| 1439 | * |
| 1440 | * @return int |
| 1441 | */ |
| 1442 | function evf_size_to_bytes( $size ) { |
| 1443 | if ( is_numeric( $size ) ) { |
| 1444 | return $size; |
| 1445 | } |
| 1446 | |
| 1447 | $suffix = substr( $size, - 1 ); |
| 1448 | $value = substr( $size, 0, - 1 ); |
| 1449 | |
| 1450 | // @codingStandardsIgnoreStart |
| 1451 | switch ( strtoupper( $suffix ) ) { |
| 1452 | case 'P': |
| 1453 | $value *= 1024; |
| 1454 | case 'T': |
| 1455 | $value *= 1024; |
| 1456 | case 'G': |
| 1457 | $value *= 1024; |
| 1458 | case 'M': |
| 1459 | $value *= 1024; |
| 1460 | case 'K': |
| 1461 | $value *= 1024; |
| 1462 | break; |
| 1463 | } |
| 1464 | // @codingStandardsIgnoreEnd |
| 1465 | |
| 1466 | return $value; |
| 1467 | } |
| 1468 | |
| 1469 | /** |
| 1470 | * Convert bytes to megabytes (or in some cases KB). |
| 1471 | * |
| 1472 | * @since 1.2.0 |
| 1473 | * |
| 1474 | * @param int $bytes Bytes to convert to a readable format. |
| 1475 | * |
| 1476 | * @return string |
| 1477 | */ |
| 1478 | function evf_size_to_megabytes( $bytes ) { |
| 1479 | if ( $bytes < 1048676 ) { |
| 1480 | return number_format( $bytes / 1024, 1 ) . ' KB'; |
| 1481 | } else { |
| 1482 | return round( (float) number_format( $bytes / 1048576, 1 ) ) . ' MB'; |
| 1483 | } |
| 1484 | } |
| 1485 | |
| 1486 | /** |
| 1487 | * Convert a file size provided, such as "2M", to bytes. |
| 1488 | * |
| 1489 | * @since 1.2.0 |
| 1490 | * @link http://stackoverflow.com/a/22500394 |
| 1491 | * |
| 1492 | * @param bool $bytes Whether to convert Bytes to a readable format. |
| 1493 | * @return mixed |
| 1494 | */ |
| 1495 | function evf_max_upload( $bytes = false ) { |
| 1496 | $max = wp_max_upload_size(); |
| 1497 | |
| 1498 | if ( $bytes ) { |
| 1499 | return $max; |
| 1500 | } else { |
| 1501 | return evf_size_to_megabytes( $max ); |
| 1502 | } |
| 1503 | } |
| 1504 | |
| 1505 | /** |
| 1506 | * Get the required label text, with a filter. |
| 1507 | * |
| 1508 | * @since 1.2.0 |
| 1509 | * @return string |
| 1510 | */ |
| 1511 | function evf_get_required_label() { |
| 1512 | return apply_filters( 'everest_forms_required_label', esc_html__( 'This field is required.', 'everest-forms' ) ); |
| 1513 | } |
| 1514 | |
| 1515 | /** |
| 1516 | * Get a PRO license plan. |
| 1517 | * |
| 1518 | * @since 1.2.0 |
| 1519 | * @return bool|string Plan on success, false on failure. |
| 1520 | */ |
| 1521 | function evf_get_license_plan() { |
| 1522 | $license_key = get_option( 'everest-forms-pro_license_key' ); |
| 1523 | |
| 1524 | if ( ! function_exists( 'is_plugin_active' ) ) { |
| 1525 | include_once ABSPATH . 'wp-admin/includes/plugin.php'; |
| 1526 | } |
| 1527 | |
| 1528 | if ( $license_key && is_plugin_active( 'everest-forms-pro/everest-forms-pro.php' ) ) { |
| 1529 | $license_data = get_transient( 'evf_pro_license_plan' ); |
| 1530 | |
| 1531 | if ( false === $license_data ) { |
| 1532 | $license_data = json_decode( |
| 1533 | EVF_Updater_Key_API::check( |
| 1534 | array( |
| 1535 | 'license' => $license_key, |
| 1536 | ) |
| 1537 | ) |
| 1538 | ); |
| 1539 | |
| 1540 | if ( ! empty( $license_data->item_plan ) ) { |
| 1541 | set_transient( 'evf_pro_license_plan', $license_data, WEEK_IN_SECONDS ); |
| 1542 | } |
| 1543 | } |
| 1544 | |
| 1545 | return isset( $license_data->item_plan ) ? $license_data->item_plan : false; |
| 1546 | } |
| 1547 | |
| 1548 | return false; |
| 1549 | } |
| 1550 | |
| 1551 | /** |
| 1552 | * Decode special characters, both alpha- (<) and numeric-based ('). |
| 1553 | * |
| 1554 | * @since 1.2.0 |
| 1555 | * |
| 1556 | * @param string $string Raw string to decode. |
| 1557 | * |
| 1558 | * @return string |
| 1559 | */ |
| 1560 | function evf_decode_string( $string ) { |
| 1561 | if ( ! is_string( $string ) ) { |
| 1562 | return $string; |
| 1563 | } |
| 1564 | |
| 1565 | return wp_kses_decode_entities( html_entity_decode( $string, ENT_QUOTES ) ); |
| 1566 | } |
| 1567 | add_filter( 'everest_forms_email_message', 'evf_decode_string' ); |
| 1568 | |
| 1569 | /** |
| 1570 | * Get Countries. |
| 1571 | * |
| 1572 | * @since 1.2.0 |
| 1573 | * @return array |
| 1574 | */ |
| 1575 | function evf_get_countries() { |
| 1576 | $countries = array( |
| 1577 | 'AF' => esc_html__( 'Afghanistan', 'everest-forms' ), |
| 1578 | 'AX' => esc_html__( '� |
| 1579 | land Islands', 'everest-forms' ), |
| 1580 | 'AL' => esc_html__( 'Albania', 'everest-forms' ), |
| 1581 | 'DZ' => esc_html__( 'Algeria', 'everest-forms' ), |
| 1582 | 'AS' => esc_html__( 'American Samoa', 'everest-forms' ), |
| 1583 | 'AD' => esc_html__( 'Andorra', 'everest-forms' ), |
| 1584 | 'AO' => esc_html__( 'Angola', 'everest-forms' ), |
| 1585 | 'AI' => esc_html__( 'Anguilla', 'everest-forms' ), |
| 1586 | 'AQ' => esc_html__( 'Antarctica', 'everest-forms' ), |
| 1587 | 'AG' => esc_html__( 'Antigua and Barbuda', 'everest-forms' ), |
| 1588 | 'AR' => esc_html__( 'Argentina', 'everest-forms' ), |
| 1589 | 'AM' => esc_html__( 'Armenia', 'everest-forms' ), |
| 1590 | 'AW' => esc_html__( 'Aruba', 'everest-forms' ), |
| 1591 | 'AU' => esc_html__( 'Australia', 'everest-forms' ), |
| 1592 | 'AT' => esc_html__( 'Austria', 'everest-forms' ), |
| 1593 | 'AZ' => esc_html__( 'Azerbaijan', 'everest-forms' ), |
| 1594 | 'BS' => esc_html__( 'Bahamas', 'everest-forms' ), |
| 1595 | 'BH' => esc_html__( 'Bahrain', 'everest-forms' ), |
| 1596 | 'BD' => esc_html__( 'Bangladesh', 'everest-forms' ), |
| 1597 | 'BB' => esc_html__( 'Barbados', 'everest-forms' ), |
| 1598 | 'BY' => esc_html__( 'Belarus', 'everest-forms' ), |
| 1599 | 'BE' => esc_html__( 'Belgium', 'everest-forms' ), |
| 1600 | 'PW' => esc_html__( 'Belau', 'everest-forms' ), |
| 1601 | 'BZ' => esc_html__( 'Belize', 'everest-forms' ), |
| 1602 | 'BJ' => esc_html__( 'Benin', 'everest-forms' ), |
| 1603 | 'BM' => esc_html__( 'Bermuda', 'everest-forms' ), |
| 1604 | 'BT' => esc_html__( 'Bhutan', 'everest-forms' ), |
| 1605 | 'BO' => esc_html__( 'Bolivia', 'everest-forms' ), |
| 1606 | 'BQ' => esc_html__( 'Bonaire, Saint Eustatius and Saba', 'everest-forms' ), |
| 1607 | 'BA' => esc_html__( 'Bosnia and Herzegovina', 'everest-forms' ), |
| 1608 | 'BW' => esc_html__( 'Botswana', 'everest-forms' ), |
| 1609 | 'BV' => esc_html__( 'Bouvet Island', 'everest-forms' ), |
| 1610 | 'BR' => esc_html__( 'Brazil', 'everest-forms' ), |
| 1611 | 'IO' => esc_html__( 'British Indian Ocean Territory', 'everest-forms' ), |
| 1612 | 'BN' => esc_html__( 'Brunei', 'everest-forms' ), |
| 1613 | 'BG' => esc_html__( 'Bulgaria', 'everest-forms' ), |
| 1614 | 'BF' => esc_html__( 'Burkina Faso', 'everest-forms' ), |
| 1615 | 'BI' => esc_html__( 'Burundi', 'everest-forms' ), |
| 1616 | 'KH' => esc_html__( 'Cambodia', 'everest-forms' ), |
| 1617 | 'CM' => esc_html__( 'Cameroon', 'everest-forms' ), |
| 1618 | 'CA' => esc_html__( 'Canada', 'everest-forms' ), |
| 1619 | 'CV' => esc_html__( 'Cape Verde', 'everest-forms' ), |
| 1620 | 'KY' => esc_html__( 'Cayman Islands', 'everest-forms' ), |
| 1621 | 'CF' => esc_html__( 'Central African Republic', 'everest-forms' ), |
| 1622 | 'TD' => esc_html__( 'Chad', 'everest-forms' ), |
| 1623 | 'CL' => esc_html__( 'Chile', 'everest-forms' ), |
| 1624 | 'CN' => esc_html__( 'China', 'everest-forms' ), |
| 1625 | 'CX' => esc_html__( 'Christmas Island', 'everest-forms' ), |
| 1626 | 'CC' => esc_html__( 'Cocos (Keeling) Islands', 'everest-forms' ), |
| 1627 | 'CO' => esc_html__( 'Colombia', 'everest-forms' ), |
| 1628 | 'KM' => esc_html__( 'Comoros', 'everest-forms' ), |
| 1629 | 'CG' => esc_html__( 'Congo (Brazzaville)', 'everest-forms' ), |
| 1630 | 'CD' => esc_html__( 'Congo (Kinshasa)', 'everest-forms' ), |
| 1631 | 'CK' => esc_html__( 'Cook Islands', 'everest-forms' ), |
| 1632 | 'CR' => esc_html__( 'Costa Rica', 'everest-forms' ), |
| 1633 | 'HR' => esc_html__( 'Croatia', 'everest-forms' ), |
| 1634 | 'CU' => esc_html__( 'Cuba', 'everest-forms' ), |
| 1635 | 'CW' => esc_html__( 'Curaçao', 'everest-forms' ), |
| 1636 | 'CY' => esc_html__( 'Cyprus', 'everest-forms' ), |
| 1637 | 'CZ' => esc_html__( 'Czech Republic', 'everest-forms' ), |
| 1638 | 'DK' => esc_html__( 'Denmark', 'everest-forms' ), |
| 1639 | 'DJ' => esc_html__( 'Djibouti', 'everest-forms' ), |
| 1640 | 'DM' => esc_html__( 'Dominica', 'everest-forms' ), |
| 1641 | 'DO' => esc_html__( 'Dominican Republic', 'everest-forms' ), |
| 1642 | 'EC' => esc_html__( 'Ecuador', 'everest-forms' ), |
| 1643 | 'EG' => esc_html__( 'Egypt', 'everest-forms' ), |
| 1644 | 'SV' => esc_html__( 'El Salvador', 'everest-forms' ), |
| 1645 | 'GQ' => esc_html__( 'Equatorial Guinea', 'everest-forms' ), |
| 1646 | 'ER' => esc_html__( 'Eritrea', 'everest-forms' ), |
| 1647 | 'EE' => esc_html__( 'Estonia', 'everest-forms' ), |
| 1648 | 'ET' => esc_html__( 'Ethiopia', 'everest-forms' ), |
| 1649 | 'FK' => esc_html__( 'Falkland Islands', 'everest-forms' ), |
| 1650 | 'FO' => esc_html__( 'Faroe Islands', 'everest-forms' ), |
| 1651 | 'FJ' => esc_html__( 'Fiji', 'everest-forms' ), |
| 1652 | 'FI' => esc_html__( 'Finland', 'everest-forms' ), |
| 1653 | 'FR' => esc_html__( 'France', 'everest-forms' ), |
| 1654 | 'GF' => esc_html__( 'French Guiana', 'everest-forms' ), |
| 1655 | 'PF' => esc_html__( 'French Polynesia', 'everest-forms' ), |
| 1656 | 'TF' => esc_html__( 'French Southern Territories', 'everest-forms' ), |
| 1657 | 'GA' => esc_html__( 'Gabon', 'everest-forms' ), |
| 1658 | 'GM' => esc_html__( 'Gambia', 'everest-forms' ), |
| 1659 | 'GE' => esc_html__( 'Georgia', 'everest-forms' ), |
| 1660 | 'DE' => esc_html__( 'Germany', 'everest-forms' ), |
| 1661 | 'GH' => esc_html__( 'Ghana', 'everest-forms' ), |
| 1662 | 'GI' => esc_html__( 'Gibraltar', 'everest-forms' ), |
| 1663 | 'GR' => esc_html__( 'Greece', 'everest-forms' ), |
| 1664 | 'GL' => esc_html__( 'Greenland', 'everest-forms' ), |
| 1665 | 'GD' => esc_html__( 'Grenada', 'everest-forms' ), |
| 1666 | 'GP' => esc_html__( 'Guadeloupe', 'everest-forms' ), |
| 1667 | 'GU' => esc_html__( 'Guam', 'everest-forms' ), |
| 1668 | 'GT' => esc_html__( 'Guatemala', 'everest-forms' ), |
| 1669 | 'GG' => esc_html__( 'Guernsey', 'everest-forms' ), |
| 1670 | 'GN' => esc_html__( 'Guinea', 'everest-forms' ), |
| 1671 | 'GW' => esc_html__( 'Guinea-Bissau', 'everest-forms' ), |
| 1672 | 'GY' => esc_html__( 'Guyana', 'everest-forms' ), |
| 1673 | 'HT' => esc_html__( 'Haiti', 'everest-forms' ), |
| 1674 | 'HM' => esc_html__( 'Heard Island and McDonald Islands', 'everest-forms' ), |
| 1675 | 'HN' => esc_html__( 'Honduras', 'everest-forms' ), |
| 1676 | 'HK' => esc_html__( 'Hong Kong', 'everest-forms' ), |
| 1677 | 'HU' => esc_html__( 'Hungary', 'everest-forms' ), |
| 1678 | 'IS' => esc_html__( 'Iceland', 'everest-forms' ), |
| 1679 | 'IN' => esc_html__( 'India', 'everest-forms' ), |
| 1680 | 'ID' => esc_html__( 'Indonesia', 'everest-forms' ), |
| 1681 | 'IR' => esc_html__( 'Iran', 'everest-forms' ), |
| 1682 | 'IQ' => esc_html__( 'Iraq', 'everest-forms' ), |
| 1683 | 'IE' => esc_html__( 'Ireland', 'everest-forms' ), |
| 1684 | 'IM' => esc_html__( 'Isle of Man', 'everest-forms' ), |
| 1685 | 'IL' => esc_html__( 'Israel', 'everest-forms' ), |
| 1686 | 'IT' => esc_html__( 'Italy', 'everest-forms' ), |
| 1687 | 'CI' => esc_html__( 'Ivory Coast', 'everest-forms' ), |
| 1688 | 'JM' => esc_html__( 'Jamaica', 'everest-forms' ), |
| 1689 | 'JP' => esc_html__( 'Japan', 'everest-forms' ), |
| 1690 | 'JE' => esc_html__( 'Jersey', 'everest-forms' ), |
| 1691 | 'JO' => esc_html__( 'Jordan', 'everest-forms' ), |
| 1692 | 'KZ' => esc_html__( 'Kazakhstan', 'everest-forms' ), |
| 1693 | 'KE' => esc_html__( 'Kenya', 'everest-forms' ), |
| 1694 | 'KI' => esc_html__( 'Kiribati', 'everest-forms' ), |
| 1695 | 'KW' => esc_html__( 'Kuwait', 'everest-forms' ), |
| 1696 | 'XK' => esc_html__( 'Kosovo', 'everest-forms' ), |
| 1697 | 'KG' => esc_html__( 'Kyrgyzstan', 'everest-forms' ), |
| 1698 | 'LA' => esc_html__( 'Laos', 'everest-forms' ), |
| 1699 | 'LV' => esc_html__( 'Latvia', 'everest-forms' ), |
| 1700 | 'LB' => esc_html__( 'Lebanon', 'everest-forms' ), |
| 1701 | 'LS' => esc_html__( 'Lesotho', 'everest-forms' ), |
| 1702 | 'LR' => esc_html__( 'Liberia', 'everest-forms' ), |
| 1703 | 'LY' => esc_html__( 'Libya', 'everest-forms' ), |
| 1704 | 'LI' => esc_html__( 'Liechtenstein', 'everest-forms' ), |
| 1705 | 'LT' => esc_html__( 'Lithuania', 'everest-forms' ), |
| 1706 | 'LU' => esc_html__( 'Luxembourg', 'everest-forms' ), |
| 1707 | 'MO' => esc_html__( 'Macao', 'everest-forms' ), |
| 1708 | 'MK' => esc_html__( 'North Macedonia', 'everest-forms' ), |
| 1709 | 'MG' => esc_html__( 'Madagascar', 'everest-forms' ), |
| 1710 | 'MW' => esc_html__( 'Malawi', 'everest-forms' ), |
| 1711 | 'MY' => esc_html__( 'Malaysia', 'everest-forms' ), |
| 1712 | 'MV' => esc_html__( 'Maldives', 'everest-forms' ), |
| 1713 | 'ML' => esc_html__( 'Mali', 'everest-forms' ), |
| 1714 | 'MT' => esc_html__( 'Malta', 'everest-forms' ), |
| 1715 | 'MH' => esc_html__( 'Marshall Islands', 'everest-forms' ), |
| 1716 | 'MQ' => esc_html__( 'Martinique', 'everest-forms' ), |
| 1717 | 'MR' => esc_html__( 'Mauritania', 'everest-forms' ), |
| 1718 | 'MU' => esc_html__( 'Mauritius', 'everest-forms' ), |
| 1719 | 'YT' => esc_html__( 'Mayotte', 'everest-forms' ), |
| 1720 | 'MX' => esc_html__( 'Mexico', 'everest-forms' ), |
| 1721 | 'FM' => esc_html__( 'Micronesia', 'everest-forms' ), |
| 1722 | 'MD' => esc_html__( 'Moldova', 'everest-forms' ), |
| 1723 | 'MC' => esc_html__( 'Monaco', 'everest-forms' ), |
| 1724 | 'MN' => esc_html__( 'Mongolia', 'everest-forms' ), |
| 1725 | 'ME' => esc_html__( 'Montenegro', 'everest-forms' ), |
| 1726 | 'MS' => esc_html__( 'Montserrat', 'everest-forms' ), |
| 1727 | 'MA' => esc_html__( 'Morocco', 'everest-forms' ), |
| 1728 | 'MZ' => esc_html__( 'Mozambique', 'everest-forms' ), |
| 1729 | 'MM' => esc_html__( 'Myanmar', 'everest-forms' ), |
| 1730 | 'NA' => esc_html__( 'Namibia', 'everest-forms' ), |
| 1731 | 'NR' => esc_html__( 'Nauru', 'everest-forms' ), |
| 1732 | 'NP' => esc_html__( 'Nepal', 'everest-forms' ), |
| 1733 | 'NL' => esc_html__( 'Netherlands', 'everest-forms' ), |
| 1734 | 'NC' => esc_html__( 'New Caledonia', 'everest-forms' ), |
| 1735 | 'NZ' => esc_html__( 'New Zealand', 'everest-forms' ), |
| 1736 | 'NI' => esc_html__( 'Nicaragua', 'everest-forms' ), |
| 1737 | 'NE' => esc_html__( 'Niger', 'everest-forms' ), |
| 1738 | 'NG' => esc_html__( 'Nigeria', 'everest-forms' ), |
| 1739 | 'NU' => esc_html__( 'Niue', 'everest-forms' ), |
| 1740 | 'NF' => esc_html__( 'Norfolk Island', 'everest-forms' ), |
| 1741 | 'MP' => esc_html__( 'Northern Mariana Islands', 'everest-forms' ), |
| 1742 | 'KP' => esc_html__( 'North Korea', 'everest-forms' ), |
| 1743 | 'NO' => esc_html__( 'Norway', 'everest-forms' ), |
| 1744 | 'OM' => esc_html__( 'Oman', 'everest-forms' ), |
| 1745 | 'PK' => esc_html__( 'Pakistan', 'everest-forms' ), |
| 1746 | 'PS' => esc_html__( 'Palestinian Territory', 'everest-forms' ), |
| 1747 | 'PA' => esc_html__( 'Panama', 'everest-forms' ), |
| 1748 | 'PG' => esc_html__( 'Papua New Guinea', 'everest-forms' ), |
| 1749 | 'PY' => esc_html__( 'Paraguay', 'everest-forms' ), |
| 1750 | 'PE' => esc_html__( 'Peru', 'everest-forms' ), |
| 1751 | 'PH' => esc_html__( 'Philippines', 'everest-forms' ), |
| 1752 | 'PN' => esc_html__( 'Pitcairn', 'everest-forms' ), |
| 1753 | 'PL' => esc_html__( 'Poland', 'everest-forms' ), |
| 1754 | 'PT' => esc_html__( 'Portugal', 'everest-forms' ), |
| 1755 | 'PR' => esc_html__( 'Puerto Rico', 'everest-forms' ), |
| 1756 | 'QA' => esc_html__( 'Qatar', 'everest-forms' ), |
| 1757 | 'RE' => esc_html__( 'Reunion', 'everest-forms' ), |
| 1758 | 'RO' => esc_html__( 'Romania', 'everest-forms' ), |
| 1759 | 'RU' => esc_html__( 'Russia', 'everest-forms' ), |
| 1760 | 'RW' => esc_html__( 'Rwanda', 'everest-forms' ), |
| 1761 | 'BL' => esc_html__( 'Saint Barthélemy', 'everest-forms' ), |
| 1762 | 'SH' => esc_html__( 'Saint Helena', 'everest-forms' ), |
| 1763 | 'KN' => esc_html__( 'Saint Kitts and Nevis', 'everest-forms' ), |
| 1764 | 'LC' => esc_html__( 'Saint Lucia', 'everest-forms' ), |
| 1765 | 'MF' => esc_html__( 'Saint Martin (French part)', 'everest-forms' ), |
| 1766 | 'SX' => esc_html__( 'Saint Martin (Dutch part)', 'everest-forms' ), |
| 1767 | 'PM' => esc_html__( 'Saint Pierre and Miquelon', 'everest-forms' ), |
| 1768 | 'VC' => esc_html__( 'Saint Vincent and the Grenadines', 'everest-forms' ), |
| 1769 | 'SM' => esc_html__( 'San Marino', 'everest-forms' ), |
| 1770 | 'ST' => esc_html__( 'São Tomé and Príncipe', 'everest-forms' ), |
| 1771 | 'SA' => esc_html__( 'Saudi Arabia', 'everest-forms' ), |
| 1772 | 'SN' => esc_html__( 'Senegal', 'everest-forms' ), |
| 1773 | 'RS' => esc_html__( 'Serbia', 'everest-forms' ), |
| 1774 | 'SC' => esc_html__( 'Seychelles', 'everest-forms' ), |
| 1775 | 'SL' => esc_html__( 'Sierra Leone', 'everest-forms' ), |
| 1776 | 'SG' => esc_html__( 'Singapore', 'everest-forms' ), |
| 1777 | 'SK' => esc_html__( 'Slovakia', 'everest-forms' ), |
| 1778 | 'SI' => esc_html__( 'Slovenia', 'everest-forms' ), |
| 1779 | 'SB' => esc_html__( 'Solomon Islands', 'everest-forms' ), |
| 1780 | 'SO' => esc_html__( 'Somalia', 'everest-forms' ), |
| 1781 | 'ZA' => esc_html__( 'South Africa', 'everest-forms' ), |
| 1782 | 'GS' => esc_html__( 'South Georgia/Sandwich Islands', 'everest-forms' ), |
| 1783 | 'KR' => esc_html__( 'South Korea', 'everest-forms' ), |
| 1784 | 'SS' => esc_html__( 'South Sudan', 'everest-forms' ), |
| 1785 | 'ES' => esc_html__( 'Spain', 'everest-forms' ), |
| 1786 | 'LK' => esc_html__( 'Sri Lanka', 'everest-forms' ), |
| 1787 | 'SD' => esc_html__( 'Sudan', 'everest-forms' ), |
| 1788 | 'SR' => esc_html__( 'Suriname', 'everest-forms' ), |
| 1789 | 'SJ' => esc_html__( 'Svalbard and Jan Mayen', 'everest-forms' ), |
| 1790 | 'SZ' => esc_html__( 'Swaziland', 'everest-forms' ), |
| 1791 | 'SE' => esc_html__( 'Sweden', 'everest-forms' ), |
| 1792 | 'CH' => esc_html__( 'Switzerland', 'everest-forms' ), |
| 1793 | 'SY' => esc_html__( 'Syria', 'everest-forms' ), |
| 1794 | 'TW' => esc_html__( 'Taiwan', 'everest-forms' ), |
| 1795 | 'TJ' => esc_html__( 'Tajikistan', 'everest-forms' ), |
| 1796 | 'TZ' => esc_html__( 'Tanzania', 'everest-forms' ), |
| 1797 | 'TH' => esc_html__( 'Thailand', 'everest-forms' ), |
| 1798 | 'TL' => esc_html__( 'Timor-Leste', 'everest-forms' ), |
| 1799 | 'TG' => esc_html__( 'Togo', 'everest-forms' ), |
| 1800 | 'TK' => esc_html__( 'Tokelau', 'everest-forms' ), |
| 1801 | 'TO' => esc_html__( 'Tonga', 'everest-forms' ), |
| 1802 | 'TT' => esc_html__( 'Trinidad and Tobago', 'everest-forms' ), |
| 1803 | 'TN' => esc_html__( 'Tunisia', 'everest-forms' ), |
| 1804 | 'TR' => esc_html__( 'Turkey', 'everest-forms' ), |
| 1805 | 'TM' => esc_html__( 'Turkmenistan', 'everest-forms' ), |
| 1806 | 'TC' => esc_html__( 'Turks and Caicos Islands', 'everest-forms' ), |
| 1807 | 'TV' => esc_html__( 'Tuvalu', 'everest-forms' ), |
| 1808 | 'UG' => esc_html__( 'Uganda', 'everest-forms' ), |
| 1809 | 'UA' => esc_html__( 'Ukraine', 'everest-forms' ), |
| 1810 | 'AE' => esc_html__( 'United Arab Emirates', 'everest-forms' ), |
| 1811 | 'GB' => esc_html__( 'United Kingdom (UK)', 'everest-forms' ), |
| 1812 | 'US' => esc_html__( 'United States (US)', 'everest-forms' ), |
| 1813 | 'UM' => esc_html__( 'United States (US) Minor Outlying Islands', 'everest-forms' ), |
| 1814 | 'UY' => esc_html__( 'Uruguay', 'everest-forms' ), |
| 1815 | 'UZ' => esc_html__( 'Uzbekistan', 'everest-forms' ), |
| 1816 | 'VU' => esc_html__( 'Vanuatu', 'everest-forms' ), |
| 1817 | 'VA' => esc_html__( 'Vatican', 'everest-forms' ), |
| 1818 | 'VE' => esc_html__( 'Venezuela', 'everest-forms' ), |
| 1819 | 'VN' => esc_html__( 'Vietnam', 'everest-forms' ), |
| 1820 | 'VG' => esc_html__( 'Virgin Islands (British)', 'everest-forms' ), |
| 1821 | 'VI' => esc_html__( 'Virgin Islands (US)', 'everest-forms' ), |
| 1822 | 'WF' => esc_html__( 'Wallis and Futuna', 'everest-forms' ), |
| 1823 | 'EH' => esc_html__( 'Western Sahara', 'everest-forms' ), |
| 1824 | 'WS' => esc_html__( 'Samoa', 'everest-forms' ), |
| 1825 | 'YE' => esc_html__( 'Yemen', 'everest-forms' ), |
| 1826 | 'ZM' => esc_html__( 'Zambia', 'everest-forms' ), |
| 1827 | 'ZW' => esc_html__( 'Zimbabwe', 'everest-forms' ), |
| 1828 | ); |
| 1829 | |
| 1830 | return (array) apply_filters( 'everest_forms_countries', $countries ); |
| 1831 | } |
| 1832 | |
| 1833 | /** |
| 1834 | * Get U.S. States. |
| 1835 | * |
| 1836 | * @since 1.7.0 |
| 1837 | * @return array |
| 1838 | */ |
| 1839 | function evf_get_states() { |
| 1840 | $states = array( |
| 1841 | 'AL' => esc_html__( 'Alabama', 'everest-forms' ), |
| 1842 | 'AK' => esc_html__( 'Alaska', 'everest-forms' ), |
| 1843 | 'AZ' => esc_html__( 'Arizona', 'everest-forms' ), |
| 1844 | 'AR' => esc_html__( 'Arkansas', 'everest-forms' ), |
| 1845 | 'CA' => esc_html__( 'California', 'everest-forms' ), |
| 1846 | 'CO' => esc_html__( 'Colorado', 'everest-forms' ), |
| 1847 | 'CT' => esc_html__( 'Connecticut', 'everest-forms' ), |
| 1848 | 'DE' => esc_html__( 'Delaware', 'everest-forms' ), |
| 1849 | 'DC' => esc_html__( 'District of Columbia', 'everest-forms' ), |
| 1850 | 'FL' => esc_html__( 'Florida', 'everest-forms' ), |
| 1851 | 'GA' => esc_html__( 'Georgia', 'everest-forms' ), |
| 1852 | 'HI' => esc_html__( 'Hawaii', 'everest-forms' ), |
| 1853 | 'ID' => esc_html__( 'Idaho', 'everest-forms' ), |
| 1854 | 'IL' => esc_html__( 'Illinois', 'everest-forms' ), |
| 1855 | 'IN' => esc_html__( 'Indiana', 'everest-forms' ), |
| 1856 | 'IA' => esc_html__( 'Iowa', 'everest-forms' ), |
| 1857 | 'KS' => esc_html__( 'Kansas', 'everest-forms' ), |
| 1858 | 'KY' => esc_html__( 'Kentucky', 'everest-forms' ), |
| 1859 | 'LA' => esc_html__( 'Louisiana', 'everest-forms' ), |
| 1860 | 'ME' => esc_html__( 'Maine', 'everest-forms' ), |
| 1861 | 'MD' => esc_html__( 'Maryland', 'everest-forms' ), |
| 1862 | 'MA' => esc_html__( 'Massachusetts', 'everest-forms' ), |
| 1863 | 'MI' => esc_html__( 'Michigan', 'everest-forms' ), |
| 1864 | 'MN' => esc_html__( 'Minnesota', 'everest-forms' ), |
| 1865 | 'MS' => esc_html__( 'Mississippi', 'everest-forms' ), |
| 1866 | 'MO' => esc_html__( 'Missouri', 'everest-forms' ), |
| 1867 | 'MT' => esc_html__( 'Montana', 'everest-forms' ), |
| 1868 | 'NE' => esc_html__( 'Nebraska', 'everest-forms' ), |
| 1869 | 'NV' => esc_html__( 'Nevada', 'everest-forms' ), |
| 1870 | 'NH' => esc_html__( 'New Hampshire', 'everest-forms' ), |
| 1871 | 'NJ' => esc_html__( 'New Jersey', 'everest-forms' ), |
| 1872 | 'NM' => esc_html__( 'New Mexico', 'everest-forms' ), |
| 1873 | 'NY' => esc_html__( 'New York', 'everest-forms' ), |
| 1874 | 'NC' => esc_html__( 'North Carolina', 'everest-forms' ), |
| 1875 | 'ND' => esc_html__( 'North Dakota', 'everest-forms' ), |
| 1876 | 'OH' => esc_html__( 'Ohio', 'everest-forms' ), |
| 1877 | 'OK' => esc_html__( 'Oklahoma', 'everest-forms' ), |
| 1878 | 'OR' => esc_html__( 'Oregon', 'everest-forms' ), |
| 1879 | 'PA' => esc_html__( 'Pennsylvania', 'everest-forms' ), |
| 1880 | 'RI' => esc_html__( 'Rhode Island', 'everest-forms' ), |
| 1881 | 'SC' => esc_html__( 'South Carolina', 'everest-forms' ), |
| 1882 | 'SD' => esc_html__( 'South Dakota', 'everest-forms' ), |
| 1883 | 'TN' => esc_html__( 'Tennessee', 'everest-forms' ), |
| 1884 | 'TX' => esc_html__( 'Texas', 'everest-forms' ), |
| 1885 | 'UT' => esc_html__( 'Utah', 'everest-forms' ), |
| 1886 | 'VT' => esc_html__( 'Vermont', 'everest-forms' ), |
| 1887 | 'VA' => esc_html__( 'Virginia', 'everest-forms' ), |
| 1888 | 'WA' => esc_html__( 'Washington', 'everest-forms' ), |
| 1889 | 'WV' => esc_html__( 'West Virginia', 'everest-forms' ), |
| 1890 | 'WI' => esc_html__( 'Wisconsin', 'everest-forms' ), |
| 1891 | 'WY' => esc_html__( 'Wyoming', 'everest-forms' ), |
| 1892 | ); |
| 1893 | |
| 1894 | return (array) apply_filters( 'everest_forms_states', $states ); |
| 1895 | } |
| 1896 | |
| 1897 | /** |
| 1898 | * Get builder fields groups. |
| 1899 | * |
| 1900 | * @return array |
| 1901 | */ |
| 1902 | function evf_get_fields_groups() { |
| 1903 | return (array) apply_filters( |
| 1904 | 'everest_forms_builder_fields_groups', |
| 1905 | array( |
| 1906 | 'general' => __( 'General Fields', 'everest-forms' ), |
| 1907 | 'advanced' => __( 'Advanced Fields', 'everest-forms' ), |
| 1908 | 'payment' => __( 'Payment Fields', 'everest-forms' ), |
| 1909 | 'survey' => __( 'Survey Fields', 'everest-forms' ), |
| 1910 | ) |
| 1911 | ); |
| 1912 | } |
| 1913 | |
| 1914 | /** |
| 1915 | * Get a builder fields type's name. |
| 1916 | * |
| 1917 | * @param string $type Coupon type. |
| 1918 | * @return string |
| 1919 | */ |
| 1920 | function evf_get_fields_group( $type = '' ) { |
| 1921 | $types = evf_get_fields_groups(); |
| 1922 | return isset( $types[ $type ] ) ? $types[ $type ] : ''; |
| 1923 | } |
| 1924 | |
| 1925 | /** |
| 1926 | * Get all fields settings. |
| 1927 | * |
| 1928 | * @return array Settings data. |
| 1929 | */ |
| 1930 | function evf_get_all_fields_settings() { |
| 1931 | $settings = array( |
| 1932 | 'label' => array( |
| 1933 | 'id' => 'label', |
| 1934 | 'title' => __( 'Label', 'everest-forms' ), |
| 1935 | 'desc' => __( 'Enter text for the form field label. This is recommended and can be hidden in the Advanced Settings.', 'everest-forms' ), |
| 1936 | 'default' => '', |
| 1937 | 'type' => 'text', |
| 1938 | 'desc_tip' => true, |
| 1939 | ), |
| 1940 | 'meta' => array( |
| 1941 | 'id' => 'meta-key', |
| 1942 | 'title' => __( 'Meta Key', 'everest-forms' ), |
| 1943 | 'desc' => __( 'Enter meta key to be stored in database.', 'everest-forms' ), |
| 1944 | 'default' => '', |
| 1945 | 'type' => 'text', |
| 1946 | 'desc_tip' => true, |
| 1947 | ), |
| 1948 | 'description' => array( |
| 1949 | 'id' => 'description', |
| 1950 | 'title' => __( 'Description', 'everest-forms' ), |
| 1951 | 'type' => 'textarea', |
| 1952 | 'desc' => __( 'Enter text for the form field description.', 'everest-forms' ), |
| 1953 | 'default' => '', |
| 1954 | 'desc_tip' => true, |
| 1955 | ), |
| 1956 | 'required' => array( |
| 1957 | 'id' => 'require', |
| 1958 | 'title' => __( 'Required', 'everest-forms' ), |
| 1959 | 'type' => 'checkbox', |
| 1960 | 'desc' => __( 'Check this option to mark the field required.', 'everest-forms' ), |
| 1961 | 'default' => 'no', |
| 1962 | 'desc_tip' => true, |
| 1963 | ), |
| 1964 | 'choices' => array( |
| 1965 | 'id' => 'choices', |
| 1966 | 'title' => __( 'Choices', 'everest-forms' ), |
| 1967 | 'desc' => __( 'Add choices for the form field.', 'everest-forms' ), |
| 1968 | 'type' => 'choices', |
| 1969 | 'desc_tip' => true, |
| 1970 | 'defaults' => array( |
| 1971 | 1 => __( 'First Choice', 'everest-forms' ), |
| 1972 | 2 => __( 'Second Choice', 'everest-forms' ), |
| 1973 | 3 => __( 'Third Choice', 'everest-forms' ), |
| 1974 | ), |
| 1975 | ), |
| 1976 | 'placeholder' => array( |
| 1977 | 'id' => 'placeholder', |
| 1978 | 'title' => __( 'Placeholder Text', 'everest-forms' ), |
| 1979 | 'desc' => __( 'Enter text for the form field placeholder.', 'everest-forms' ), |
| 1980 | 'default' => '', |
| 1981 | 'type' => 'text', |
| 1982 | 'desc_tip' => true, |
| 1983 | ), |
| 1984 | 'css' => array( |
| 1985 | 'id' => 'css', |
| 1986 | 'title' => __( 'CSS Classes', 'everest-forms' ), |
| 1987 | 'desc' => __( 'Enter CSS class for this field container. Class names should be separated with spaces.', 'everest-forms' ), |
| 1988 | 'default' => '', |
| 1989 | 'type' => 'text', |
| 1990 | 'desc_tip' => true, |
| 1991 | ), |
| 1992 | 'label_hide' => array( |
| 1993 | 'id' => 'label_hide', |
| 1994 | 'title' => __( 'Hide Label', 'everest-forms' ), |
| 1995 | 'type' => 'checkbox', |
| 1996 | 'desc' => __( 'Check this option to hide the form field label.', 'everest-forms' ), |
| 1997 | 'default' => 'no', |
| 1998 | 'desc_tip' => true, |
| 1999 | ), |
| 2000 | 'sublabel_hide' => array( |
| 2001 | 'id' => 'sublabel_hide', |
| 2002 | 'title' => __( 'Hide Sub-Labels', 'everest-forms' ), |
| 2003 | 'type' => 'checkbox', |
| 2004 | 'desc' => __( 'Check this option to hide the form field sub-label.', 'everest-forms' ), |
| 2005 | 'default' => 'no', |
| 2006 | 'desc_tip' => true, |
| 2007 | ), |
| 2008 | ); |
| 2009 | |
| 2010 | return apply_filters( 'everest_form_all_fields_settings', $settings ); |
| 2011 | } |
| 2012 | |
| 2013 | /** |
| 2014 | * Helper function to display debug data. |
| 2015 | * |
| 2016 | * @since 1.3.2 |
| 2017 | * |
| 2018 | * @param mixed $expression The expression to be printed. |
| 2019 | * @param bool $return Optional. Default false. Set to true to return the human-readable string. |
| 2020 | * |
| 2021 | * @return string |
| 2022 | */ |
| 2023 | function evf_debug_data( $expression, $return = false ) { |
| 2024 | if ( defined( 'EVF_DEBUG' ) && true === EVF_DEBUG ) { |
| 2025 | |
| 2026 | if ( ! $return ) { |
| 2027 | echo '<textarea style="color:#666;background:#fff;margin: 20px 0;width:100%;height:500px;font-size:12px;font-family: Consolas,Monaco,Lucida Console,monospace;direction: ltr;unicode-bidi: embed;line-height: 1.4;padding: 4px 6px 1px;" readonly>'; |
| 2028 | |
| 2029 | echo "==================== Everest Forms Debugging ====================\n\n"; |
| 2030 | |
| 2031 | if ( is_array( $expression ) || is_object( $expression ) ) { |
| 2032 | echo esc_html( evf_print_r( $expression, true ) ); |
| 2033 | } else { |
| 2034 | echo esc_html( $expression ); |
| 2035 | } |
| 2036 | echo '</textarea>'; |
| 2037 | |
| 2038 | } else { |
| 2039 | $output = '<textarea style="color:#666;background:#fff;margin: 20px 0;width:100%;height:500px;font-size:12px;font-family: Consolas,Monaco,Lucida Console,monospace;direction: ltr;unicode-bidi: embed;line-height: 1.4;padding: 4px 6px 1px;" readonly>'; |
| 2040 | |
| 2041 | $output .= "==================== Everest Forms Debugging ====================\n\n"; |
| 2042 | |
| 2043 | if ( is_array( $expression ) || is_object( $expression ) ) { |
| 2044 | $output .= evf_print_r( $expression, true ); |
| 2045 | } else { |
| 2046 | $output .= $expression; |
| 2047 | } |
| 2048 | |
| 2049 | $output .= '</textarea>'; |
| 2050 | |
| 2051 | return $output; |
| 2052 | } |
| 2053 | } |
| 2054 | } |
| 2055 | |
| 2056 | /** |
| 2057 | * String translation function. |
| 2058 | * |
| 2059 | * @since 1.4.9 |
| 2060 | * |
| 2061 | * @param int $form_id Form ID. |
| 2062 | * @param string $field_id Field ID. |
| 2063 | * @param mixed $value The string that needs to be translated. |
| 2064 | * @param string $suffix The suffix to make the field have unique naem. |
| 2065 | * |
| 2066 | * @return mixed The translated string. |
| 2067 | */ |
| 2068 | function evf_string_translation( $form_id, $field_id, $value, $suffix = '' ) { |
| 2069 | $context = isset( $form_id ) ? 'everest_forms_' . absint( $form_id ) : 0; |
| 2070 | $name = isset( $field_id ) ? evf_clean( $field_id . $suffix ) : ''; |
| 2071 | |
| 2072 | if ( function_exists( 'icl_register_string' ) ) { |
| 2073 | icl_register_string( $context, $name, $value ); |
| 2074 | } |
| 2075 | |
| 2076 | if ( function_exists( 'icl_t' ) ) { |
| 2077 | $value = icl_t( $context, $name, $value ); |
| 2078 | } |
| 2079 | |
| 2080 | return $value; |
| 2081 | } |
| 2082 | |
| 2083 | /** |
| 2084 | * Trigger logging cleanup using the logging class. |
| 2085 | * |
| 2086 | * @since 1.6.2 |
| 2087 | */ |
| 2088 | function evf_cleanup_logs() { |
| 2089 | $logger = evf_get_logger(); |
| 2090 | |
| 2091 | if ( is_callable( array( $logger, 'clear_expired_logs' ) ) ) { |
| 2092 | $logger->clear_expired_logs(); |
| 2093 | } |
| 2094 | } |
| 2095 | add_action( 'everest_forms_cleanup_logs', 'evf_cleanup_logs' ); |
| 2096 | |
| 2097 | |
| 2098 | /** |
| 2099 | * Check whether it device is table or not from HTTP user agent |
| 2100 | * |
| 2101 | * @since 1.7.0 |
| 2102 | * |
| 2103 | * @return bool |
| 2104 | */ |
| 2105 | function evf_is_tablet() { |
| 2106 | return false !== stripos( evf_get_user_agent(), 'tablet' ) || false !== stripos( evf_get_user_agent(), 'tab' ); |
| 2107 | } |
| 2108 | |
| 2109 | /** |
| 2110 | * Get user device from user agent from HTTP user agent. |
| 2111 | * |
| 2112 | * @since 1.7.0 |
| 2113 | * |
| 2114 | * @return string |
| 2115 | */ |
| 2116 | function evf_get_user_device() { |
| 2117 | if ( evf_is_tablet() ) { |
| 2118 | return esc_html__( 'Tablet', 'everest-forms' ); |
| 2119 | } elseif ( wp_is_mobile() ) { |
| 2120 | return esc_html__( 'Mobile', 'everest-forms' ); |
| 2121 | } else { |
| 2122 | return esc_html__( 'Desktop', 'everest-forms' ); |
| 2123 | } |
| 2124 | } |
| 2125 | |
| 2126 | |
| 2127 | /** |
| 2128 | * A wp_parse_args() for multi-dimensional array. |
| 2129 | * |
| 2130 | * @see https://developer.wordpress.org/reference/functions/wp_parse_args/ |
| 2131 | * |
| 2132 | * @since 1.7.0 |
| 2133 | * |
| 2134 | * @param array $args Value to merge with $defaults. |
| 2135 | * @param array $defaults Array that serves as the defaults. |
| 2136 | * |
| 2137 | * @return array Merged user defined values with defaults. |
| 2138 | */ |
| 2139 | function evf_parse_args( &$args, $defaults ) { |
| 2140 | $args = (array) $args; |
| 2141 | $defaults = (array) $defaults; |
| 2142 | $result = $defaults; |
| 2143 | foreach ( $args as $k => &$v ) { |
| 2144 | if ( is_array( $v ) && isset( $result[ $k ] ) ) { |
| 2145 | $result[ $k ] = evf_parse_args( $v, $result[ $k ] ); |
| 2146 | } else { |
| 2147 | $result[ $k ] = $v; |
| 2148 | } |
| 2149 | } |
| 2150 | return $result; |
| 2151 | } |
| 2152 | |
| 2153 | /** |
| 2154 | * Get date of ranges. |
| 2155 | * |
| 2156 | * @since 1.7.0 |
| 2157 | * |
| 2158 | * @param string $first Starting date. |
| 2159 | * @param string $last End date. |
| 2160 | * @param string $step Date step. |
| 2161 | * @param string $format Date format. |
| 2162 | * |
| 2163 | * @return array Range dates. |
| 2164 | */ |
| 2165 | function evf_date_range( $first, $last = '', $step = '+1 day', $format = 'Y/m/d' ) { |
| 2166 | $dates = array(); |
| 2167 | $current = strtotime( $first ); |
| 2168 | $last = strtotime( $last ); |
| 2169 | |
| 2170 | while ( $current <= $last ) { |
| 2171 | $dates[] = date_i18n( $format, $current ); |
| 2172 | $current = strtotime( $step, $current ); |
| 2173 | } |
| 2174 | |
| 2175 | return $dates; |
| 2176 | } |
| 2177 | |
| 2178 | /** |
| 2179 | * Process syntaxes in a text. |
| 2180 | * |
| 2181 | * @since 1.7.0 |
| 2182 | * |
| 2183 | * @param string $text Text to be processed. |
| 2184 | * @param bool $escape_html Whether to escape all the htmls before processing or not. |
| 2185 | * @param bool $trim_trailing_spaces Whether to trim trailing spaces or not. |
| 2186 | * |
| 2187 | * @return string Processed text. |
| 2188 | */ |
| 2189 | function evf_process_syntaxes( $text, $escape_html = true, $trim_trailing_spaces = true ) { |
| 2190 | |
| 2191 | if ( true === $trim_trailing_spaces ) { |
| 2192 | $text = trim( $text ); |
| 2193 | } |
| 2194 | if ( true === $escape_html ) { |
| 2195 | $text = esc_html( $text ); |
| 2196 | } |
| 2197 | $text = evf_process_hyperlink_syntax( $text ); |
| 2198 | $text = evf_process_italic_syntax( $text ); |
| 2199 | $text = evf_process_bold_syntax( $text ); |
| 2200 | $text = evf_process_underline_syntax( $text ); |
| 2201 | $text = evf_process_line_breaks( $text ); |
| 2202 | return $text; |
| 2203 | } |
| 2204 | |
| 2205 | /** |
| 2206 | * Extract page ids from a text. |
| 2207 | * |
| 2208 | * @since 1.7.0 |
| 2209 | * |
| 2210 | * @param string $text Text to extract page ids from. |
| 2211 | * |
| 2212 | * @return mixed |
| 2213 | */ |
| 2214 | function evf_extract_page_ids( $text ) { |
| 2215 | $page_id_syntax_matches = array(); |
| 2216 | $page_ids = array(); |
| 2217 | |
| 2218 | while ( preg_match( '/page_id=([0-9]+)/', $text, $page_id_syntax_matches ) ) { |
| 2219 | $page_id = $page_id_syntax_matches[1]; |
| 2220 | $page_ids[] = $page_id; |
| 2221 | $text = str_replace( 'page_id=' . $page_id, '', $text ); |
| 2222 | } |
| 2223 | |
| 2224 | if ( count( $page_ids ) > 0 ) { |
| 2225 | return $page_ids; |
| 2226 | } |
| 2227 | return false; |
| 2228 | } |
| 2229 | |
| 2230 | /** |
| 2231 | * Process hyperlink syntaxes in a text. |
| 2232 | * The syntax used for hyperlink is: [Link Label](Link URL) |
| 2233 | * Example: [Google Search Page](https://google.com) |
| 2234 | * |
| 2235 | * @since 1.7.0 |
| 2236 | * |
| 2237 | * @param string $text Text to process. |
| 2238 | * @param string $use_no_a_tag If set to `true` only the link will be used and no `a` tag. Particularly useful for exporting CSV, |
| 2239 | * as the html tags are escaped in a CSV file. |
| 2240 | * |
| 2241 | * @return string Processed text. |
| 2242 | */ |
| 2243 | function evf_process_hyperlink_syntax( $text, $use_no_a_tag = false ) { |
| 2244 | $matches = array(); |
| 2245 | $regex = '/(\[[^\[\]]*\])(\([^\(\)]*\))/'; |
| 2246 | |
| 2247 | while ( preg_match( $regex, $text, $matches ) ) { |
| 2248 | $matched_string = $matches[0]; |
| 2249 | $label = $matches[1]; |
| 2250 | $link = $matches[2]; |
| 2251 | $class = ''; |
| 2252 | $page_id = ''; |
| 2253 | |
| 2254 | // Trim brackets. |
| 2255 | $label = trim( substr( $label, 1, -1 ) ); |
| 2256 | $link = trim( substr( $link, 1, -1 ) ); |
| 2257 | |
| 2258 | // Proceed only if label or link is not empty. |
| 2259 | if ( ! empty( $label ) || ! empty( $link ) ) { |
| 2260 | |
| 2261 | // Use hash(#) if the link is empty. |
| 2262 | if ( empty( $link ) ) { |
| 2263 | $link = '#'; |
| 2264 | } |
| 2265 | |
| 2266 | // Use link as label if it's empty. |
| 2267 | if ( empty( $label ) ) { |
| 2268 | $label = $link; |
| 2269 | } |
| 2270 | |
| 2271 | // See if it's a link to a local page. |
| 2272 | if ( strpos( $link, '?' ) === 0 ) { |
| 2273 | $class .= ' evf-privacy-policy-local-page-link'; |
| 2274 | |
| 2275 | // Extract page id. |
| 2276 | $page_ids = evf_extract_page_ids( $link ); |
| 2277 | |
| 2278 | if ( false !== $page_ids ) { |
| 2279 | $page_id = $page_ids[0]; |
| 2280 | $link = get_page_link( $page_id ); |
| 2281 | |
| 2282 | if ( empty( $link ) ) { |
| 2283 | $link = '#'; |
| 2284 | } |
| 2285 | } |
| 2286 | } |
| 2287 | |
| 2288 | // Insert hyperlink html. |
| 2289 | if ( true === $use_no_a_tag ) { |
| 2290 | $html = $link; |
| 2291 | } else { |
| 2292 | $html = sprintf( '<a data-page-id="%s" target="_blank" rel="noopener noreferrer nofollow" href="%s" class="%s">%s</a>', $page_id, $link, $class, $label ); |
| 2293 | } |
| 2294 | $text = str_replace( $matched_string, $html, $text ); |
| 2295 | } else { |
| 2296 | // If both label and link are empty then replace it with empty string. |
| 2297 | $text = str_replace( $matched_string, '', $text ); |
| 2298 | } |
| 2299 | } |
| 2300 | |
| 2301 | return $text; |
| 2302 | } |
| 2303 | |
| 2304 | /** |
| 2305 | * Process italic syntaxes in a text. |
| 2306 | * The syntax used for italic text is: `text` |
| 2307 | * Just wrap the text with back tick characters. To escape a backtick insert a backslash(\) before the character like "\`". |
| 2308 | * |
| 2309 | * @since 1.7.0 |
| 2310 | * |
| 2311 | * @param string $text Text to process. |
| 2312 | * |
| 2313 | * @return string Processed text. |
| 2314 | */ |
| 2315 | function evf_process_italic_syntax( $text ) { |
| 2316 | $matches = array(); |
| 2317 | $regex = '/`[^`]+`/'; |
| 2318 | $text = str_replace( '\`', '<&&&&&>', $text ); // To preserve an escaped special character '`'. |
| 2319 | |
| 2320 | while ( preg_match( $regex, $text, $matches ) ) { |
| 2321 | $matched_string = $matches[0]; |
| 2322 | $label = substr( trim( $matched_string ), 1, -1 ); |
| 2323 | $html = sprintf( '<i>%s</i>', $label ); |
| 2324 | $text = str_replace( $matched_string, $html, $text ); |
| 2325 | } |
| 2326 | |
| 2327 | return str_replace( '<&&&&&>', '`', $text ); |
| 2328 | } |
| 2329 | |
| 2330 | /** |
| 2331 | * Process bold syntaxes in a text. |
| 2332 | * The syntax used for bold text is: *text* |
| 2333 | * Just wrap the text with asterisk characters. To escape an asterisk insert a backslash(\) before the character like "\*". |
| 2334 | * |
| 2335 | * @since 1.7.0 |
| 2336 | * |
| 2337 | * @param string $text Text to process. |
| 2338 | * |
| 2339 | * @return string Processed text. |
| 2340 | */ |
| 2341 | function evf_process_bold_syntax( $text ) { |
| 2342 | $matches = array(); |
| 2343 | $regex = '/\*[^*]+\*/'; |
| 2344 | $text = str_replace( '\*', '<&&&&&>', $text ); // To preserve an escaped special character '*'. |
| 2345 | |
| 2346 | while ( preg_match( $regex, $text, $matches ) ) { |
| 2347 | $matched_string = $matches[0]; |
| 2348 | $label = substr( trim( $matched_string ), 1, -1 ); |
| 2349 | $html = sprintf( '<b>%s</b>', $label ); |
| 2350 | $text = str_replace( $matched_string, $html, $text ); |
| 2351 | } |
| 2352 | |
| 2353 | return str_replace( '<&&&&&>', '*', $text ); |
| 2354 | } |
| 2355 | |
| 2356 | /** |
| 2357 | * Process underline syntaxes in a text. |
| 2358 | * The syntax used for bold text is: __text__ |
| 2359 | * Wrap the text with double underscore characters. To escape an underscore insert a backslash(\) before the character like "\_". |
| 2360 | * |
| 2361 | * @since 1.7.0 |
| 2362 | * |
| 2363 | * @param string $text Text to process. |
| 2364 | * |
| 2365 | * @return string Processed text. |
| 2366 | */ |
| 2367 | function evf_process_underline_syntax( $text ) { |
| 2368 | $matches = array(); |
| 2369 | $regex = '/__[^_]+__/'; |
| 2370 | $text = str_replace( '\_', '<&&&&&>', $text ); // To preserve an escaped special character '_'. |
| 2371 | |
| 2372 | while ( preg_match( $regex, $text, $matches ) ) { |
| 2373 | $matched_string = $matches[0]; |
| 2374 | $label = substr( trim( $matched_string ), 2, -2 ); |
| 2375 | $html = sprintf( '<u>%s</u>', $label ); |
| 2376 | $text = str_replace( $matched_string, $html, $text ); |
| 2377 | } |
| 2378 | |
| 2379 | $text = str_replace( '<&&&&&>', '_', $text ); |
| 2380 | return $text; |
| 2381 | } |
| 2382 | |
| 2383 | /** |
| 2384 | * It replaces `\n` characters with `<br/>` tag because new line `\n` character is not supported in html. |
| 2385 | * |
| 2386 | * @since 1.7.0 |
| 2387 | * |
| 2388 | * @param string $text Text to process. |
| 2389 | * |
| 2390 | * @return string Processed text. |
| 2391 | */ |
| 2392 | function evf_process_line_breaks( $text ) { |
| 2393 | return str_replace( "\n", '<br/>', $text ); |
| 2394 | } |
| 2395 | |
| 2396 | /** |
| 2397 | * Check whether the current page is in AMP mode or not. |
| 2398 | * We need to check for specific functions, as there is no special AMP header. |
| 2399 | * |
| 2400 | * @since 1.8.4 |
| 2401 | * |
| 2402 | * @param bool $check_theme_support Whether theme support should be checked. Defaults to true. |
| 2403 | * |
| 2404 | * @return bool |
| 2405 | */ |
| 2406 | function evf_is_amp( $check_theme_support = true ) { |
| 2407 | |
| 2408 | $is_amp = false; |
| 2409 | |
| 2410 | if ( |
| 2411 | // AMP by Automattic. |
| 2412 | ( function_exists( 'amp_is_request' ) && amp_is_request() ) || |
| 2413 | // Better AMP. |
| 2414 | ( function_exists( 'is_better_amp' ) && is_better_amp() ) |
| 2415 | ) { |
| 2416 | $is_amp = true; |
| 2417 | } |
| 2418 | |
| 2419 | if ( $is_amp && $check_theme_support ) { |
| 2420 | $is_amp = current_theme_supports( 'amp' ); |
| 2421 | } |
| 2422 | |
| 2423 | return apply_filters( 'evf_is_amp', $is_amp ); |
| 2424 | } |
| 2425 | |
| 2426 | /** |
| 2427 | * EVF KSES. |
| 2428 | * |
| 2429 | * @since 1.8.2.1 |
| 2430 | * |
| 2431 | * @param string $context Context. |
| 2432 | */ |
| 2433 | function evf_get_allowed_html_tags( $context = '' ) { |
| 2434 | |
| 2435 | $post_tags = wp_kses_allowed_html( 'post' ); |
| 2436 | if ( 'builder' === $context ) { |
| 2437 | $builder_tags = get_transient( 'evf-builder-tags-list' ); |
| 2438 | if ( ! empty( $builder_tags ) ) { |
| 2439 | return $builder_tags; |
| 2440 | } |
| 2441 | $allowed_tags = evf_get_json_file_contents( 'assets/allowed_tags/allowed_tags.json', true ); |
| 2442 | if ( ! empty( $allowed_tags ) ) { |
| 2443 | foreach ( $allowed_tags as $tag => $args ) { |
| 2444 | if ( array_key_exists( $tag, $post_tags ) ) { |
| 2445 | foreach ( $args as $arg => $value ) { |
| 2446 | if ( ! array_key_exists( $arg, $post_tags[ $tag ] ) ) { |
| 2447 | $post_tags[ $tag ][ $arg ] = true; |
| 2448 | } |
| 2449 | } |
| 2450 | } else { |
| 2451 | $post_tags[ $tag ] = $args; |
| 2452 | } |
| 2453 | } |
| 2454 | set_transient( 'evf-builder-tags-list', $post_tags, DAY_IN_SECONDS ); |
| 2455 | } |
| 2456 | return $post_tags; |
| 2457 | } |
| 2458 | |
| 2459 | return wp_parse_args( |
| 2460 | $post_tags, |
| 2461 | array( |
| 2462 | 'input' => array( |
| 2463 | 'type' => true, |
| 2464 | 'name' => true, |
| 2465 | 'value' => true, |
| 2466 | ), |
| 2467 | 'select' => array( |
| 2468 | 'name' => true, |
| 2469 | 'id' => true, |
| 2470 | ), |
| 2471 | 'option' => array( |
| 2472 | 'value' => true, |
| 2473 | 'selected' => true, |
| 2474 | ), |
| 2475 | 'textarea' => array( |
| 2476 | 'style' => true, |
| 2477 | ), |
| 2478 | ) |
| 2479 | ); |
| 2480 | } |
| 2481 | |
| 2482 | /** |
| 2483 | * Parse Builder Post Data. |
| 2484 | * |
| 2485 | * @param mixed $post_data Post Data. |
| 2486 | * |
| 2487 | * @since 1.8.2.2 |
| 2488 | */ |
| 2489 | function evf_sanitize_builder( $post_data = array() ) { |
| 2490 | |
| 2491 | if ( empty( $post_data ) || ! is_array( $post_data ) ) { |
| 2492 | return array(); |
| 2493 | } |
| 2494 | |
| 2495 | $form_data = array(); |
| 2496 | foreach ( $post_data as $data_key => $data ) { |
| 2497 | $name = sanitize_text_field( $data->name ); |
| 2498 | if ( preg_match( '/\<.*\>/', $data->value ) ) { |
| 2499 | $value = wp_kses_post( $data->value ); |
| 2500 | } else { |
| 2501 | $value = sanitize_text_field( $data->value ); |
| 2502 | } |
| 2503 | |
| 2504 | $form_data[ sanitize_text_field( $data_key ) ] = (object) array( |
| 2505 | 'name' => $name, |
| 2506 | 'value' => $value, |
| 2507 | ); |
| 2508 | } |
| 2509 | return $form_data; |
| 2510 | } |
| 2511 | |
| 2512 | /** |
| 2513 | * Entry Post Data. |
| 2514 | * |
| 2515 | * @param mixed $entry Post Data. |
| 2516 | * |
| 2517 | * @since 1.8.2.2 |
| 2518 | */ |
| 2519 | function evf_sanitize_entry( $entry = array() ) { |
| 2520 | if ( empty( $entry ) || ! is_array( $entry ) || empty( $entry['form_fields'] ) ) { |
| 2521 | return $entry; |
| 2522 | } |
| 2523 | |
| 2524 | $form_id = absint( $entry['id'] ); |
| 2525 | $form_data = evf()->form->get( $form_id, array( 'contents_only' => true ) ); |
| 2526 | |
| 2527 | if ( ! $form_data ) { |
| 2528 | return array(); |
| 2529 | } |
| 2530 | |
| 2531 | $form_data = evf_decode( $form_data->post_content ); |
| 2532 | |
| 2533 | $form_fields = $form_data['form_fields']; |
| 2534 | |
| 2535 | if ( empty( $form_fields ) ) { |
| 2536 | return array(); |
| 2537 | } |
| 2538 | |
| 2539 | foreach ( $form_fields as $key => $field ) { |
| 2540 | $key = sanitize_text_field( $key ); |
| 2541 | if ( array_key_exists( $key, $entry['form_fields'] ) ) { |
| 2542 | switch ( $field['type'] ) { |
| 2543 | case 'email': |
| 2544 | if ( isset( $entry['form_fields'][ $key ]['primary'] ) ) { |
| 2545 | $entry['form_fields'][ $key ]['primary'] = sanitize_email( $entry['form_fields'][ $key ]['primary'] ); |
| 2546 | $entry['form_fields'][ $key ]['secondary'] = sanitize_email( $entry['form_fields'][ $key ]['secondary'] ); |
| 2547 | } else { |
| 2548 | $entry['form_fields'][ $key ] = sanitize_email( $entry['form_fields'][ $key ] ); |
| 2549 | } |
| 2550 | break; |
| 2551 | case 'file-upload': |
| 2552 | case 'signature': |
| 2553 | case 'image-upload': |
| 2554 | $entry['form_fields'][ $key ] = is_array( $entry['form_fields'][ $key ] ) ? $entry['form_fields'][ $key ] : esc_url_raw( $entry['form_fields'][ $key ] ); |
| 2555 | break; |
| 2556 | case 'textarea': |
| 2557 | case 'html': |
| 2558 | case 'privacy-policy': |
| 2559 | case 'wysiwug': |
| 2560 | $entry['form_fields'][ $key ] = wp_kses_post( $entry['form_fields'][ $key ] ); |
| 2561 | break; |
| 2562 | case 'repeater-fields': |
| 2563 | $entry['form_fields'][ $key ] = $entry['form_fields'][ $key ]; |
| 2564 | break; |
| 2565 | default: |
| 2566 | if ( is_array( $entry['form_fields'][ $key ] ) ) { |
| 2567 | foreach ( $entry['form_fields'][ $key ] as $field_key => $value ) { |
| 2568 | $field_key = sanitize_text_field( $field_key ); |
| 2569 | $entry['form_fields'][ $key ][ $field_key ] = sanitize_text_field( $value ); |
| 2570 | } |
| 2571 | } else { |
| 2572 | $entry['form_fields'][ $key ] = sanitize_text_field( $entry['form_fields'][ $key ] ); |
| 2573 | } |
| 2574 | } |
| 2575 | } |
| 2576 | return $entry; |
| 2577 | } |
| 2578 | } |
| 2579 | |
| 2580 | /** |
| 2581 | * EVF Get json file contents. |
| 2582 | * |
| 2583 | * @param mixed $file File path. |
| 2584 | * @param mixed $to_array Returned data in array. |
| 2585 | */ |
| 2586 | function evf_get_json_file_contents( $file, $to_array = false ) { |
| 2587 | if ( $to_array ) { |
| 2588 | return json_decode( evf_file_get_contents( $file ), true ); |
| 2589 | } |
| 2590 | return json_decode( evf_file_get_contents( $file ) ); |
| 2591 | } |
| 2592 | |
| 2593 | /** |
| 2594 | * EVF file get contents. |
| 2595 | * |
| 2596 | * @param mixed $file File path. |
| 2597 | */ |
| 2598 | function evf_file_get_contents( $file ) { |
| 2599 | if ( $file ) { |
| 2600 | global $wp_filesystem; |
| 2601 | require_once ABSPATH . '/wp-admin/includes/file.php'; |
| 2602 | WP_Filesystem(); |
| 2603 | $local_file = preg_replace( '/\\\\|\/\//', '/', plugin_dir_path( EVF_PLUGIN_FILE ) . $file ); |
| 2604 | if ( $wp_filesystem->exists( $local_file ) ) { |
| 2605 | $response = $wp_filesystem->get_contents( $local_file ); |
| 2606 | return $response; |
| 2607 | } |
| 2608 | } |
| 2609 | return; |
| 2610 | } |
| 2611 |