abstracts
6 years ago
admin
6 years ago
export
6 years ago
fields
6 years ago
interfaces
8 years ago
libraries
7 years ago
log-handlers
8 years ago
shortcodes
6 years ago
templates
7 years ago
class-everest-forms.php
6 years ago
class-evf-ajax.php
6 years ago
class-evf-autoloader.php
7 years ago
class-evf-background-updater.php
7 years ago
class-evf-cache-helper.php
8 years ago
class-evf-deprecated-action-hooks.php
7 years ago
class-evf-deprecated-filter-hooks.php
7 years ago
class-evf-emails.php
7 years ago
class-evf-fields.php
7 years ago
class-evf-form-block.php
6 years ago
class-evf-form-handler.php
6 years ago
class-evf-form-task.php
6 years ago
class-evf-forms-features.php
7 years ago
class-evf-frontend-scripts.php
7 years ago
class-evf-install.php
6 years ago
class-evf-integrations.php
7 years ago
class-evf-log-levels.php
8 years ago
class-evf-logger.php
8 years ago
class-evf-post-types.php
7 years ago
class-evf-privacy.php
7 years ago
class-evf-session-handler.php
7 years ago
class-evf-shortcodes.php
7 years ago
class-evf-smart-tags.php
7 years ago
class-evf-template-loader.php
7 years ago
class-evf-validation.php
8 years ago
evf-conditional-functions.php
7 years ago
evf-core-functions.php
6 years ago
evf-deprecated-functions.php
7 years ago
evf-entry-functions.php
6 years ago
evf-formatting-functions.php
7 years ago
evf-notice-functions.php
6 years ago
evf-template-functions.php
7 years ago
evf-template-hooks.php
7 years ago
evf-update-functions.php
6 years ago
evf-core-functions.php
1987 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>' . $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 apply_filters( 'everest_forms_queued_js', $js ); // WPCS: XSS ok. |
| 243 | |
| 244 | unset( $evf_queued_js ); |
| 245 | } |
| 246 | } |
| 247 | |
| 248 | /** |
| 249 | * Set a cookie - wrapper for setcookie using WP constants. |
| 250 | * |
| 251 | * @param string $name Name of the cookie being set. |
| 252 | * @param string $value Value of the cookie. |
| 253 | * @param integer $expire Expiry of the cookie. |
| 254 | * @param bool $secure Whether the cookie should be served only over https. |
| 255 | * @param bool $httponly Whether the cookie is only accessible over HTTP, not scripting languages like JavaScript. @since 1.4.9. |
| 256 | */ |
| 257 | function evf_setcookie( $name, $value, $expire = 0, $secure = false, $httponly = false ) { |
| 258 | if ( ! headers_sent() ) { |
| 259 | setcookie( $name, $value, $expire, COOKIEPATH ? COOKIEPATH : '/', COOKIE_DOMAIN, $secure, apply_filters( 'everest_forms_cookie_httponly', $httponly, $name, $value, $expire, $secure ) ); |
| 260 | } elseif ( defined( 'WP_DEBUG' ) && WP_DEBUG ) { |
| 261 | headers_sent( $file, $line ); |
| 262 | trigger_error( "{$name} cookie cannot be set - headers already sent by {$file} on line {$line}", E_USER_NOTICE ); // @codingStandardsIgnoreLine |
| 263 | } |
| 264 | } |
| 265 | |
| 266 | /** |
| 267 | * Get a log file path. |
| 268 | * |
| 269 | * @since 1.0.0 |
| 270 | * |
| 271 | * @param string $handle name. |
| 272 | * @return string the log file path. |
| 273 | */ |
| 274 | function evf_get_log_file_path( $handle ) { |
| 275 | return EVF_Log_Handler_File::get_log_file_path( $handle ); |
| 276 | } |
| 277 | |
| 278 | /** |
| 279 | * Get a csv file name. |
| 280 | * |
| 281 | * File names consist of the handle, followed by the date, followed by a hash, .csv. |
| 282 | * |
| 283 | * @since 1.3.0 |
| 284 | * |
| 285 | * @param string $handle Name. |
| 286 | * @return bool|string The csv file name or false if cannot be determined. |
| 287 | */ |
| 288 | function evf_get_csv_file_name( $handle ) { |
| 289 | if ( function_exists( 'wp_hash' ) ) { |
| 290 | $date_suffix = date( 'Y-m-d', current_time( 'timestamp', true ) ); |
| 291 | $hash_suffix = wp_hash( $handle ); |
| 292 | return sanitize_file_name( implode( '-', array( 'evf-entry-export', $handle, $date_suffix, $hash_suffix ) ) . '.csv' ); |
| 293 | } else { |
| 294 | evf_doing_it_wrong( __METHOD__, __( 'This method should not be called before plugins_loaded.', 'everest-forms' ), '1.3.0' ); |
| 295 | return false; |
| 296 | } |
| 297 | } |
| 298 | |
| 299 | /** |
| 300 | * Recursively get page children. |
| 301 | * |
| 302 | * @param int $page_id Page ID. |
| 303 | * @return int[] |
| 304 | */ |
| 305 | function evf_get_page_children( $page_id ) { |
| 306 | $page_ids = get_posts( |
| 307 | array( |
| 308 | 'post_parent' => $page_id, |
| 309 | 'post_type' => 'page', |
| 310 | 'numberposts' => - 1, |
| 311 | 'post_status' => 'any', |
| 312 | 'fields' => 'ids', |
| 313 | ) |
| 314 | ); |
| 315 | |
| 316 | if ( ! empty( $page_ids ) ) { |
| 317 | foreach ( $page_ids as $page_id ) { |
| 318 | $page_ids = array_merge( $page_ids, evf_get_page_children( $page_id ) ); |
| 319 | } |
| 320 | } |
| 321 | |
| 322 | return $page_ids; |
| 323 | } |
| 324 | |
| 325 | /** |
| 326 | * Get user agent string. |
| 327 | * |
| 328 | * @since 1.0.0 |
| 329 | * @return string |
| 330 | */ |
| 331 | function evf_get_user_agent() { |
| 332 | return isset( $_SERVER['HTTP_USER_AGENT'] ) ? evf_clean( wp_unslash( $_SERVER['HTTP_USER_AGENT'] ) ) : ''; // @codingStandardsIgnoreLine |
| 333 | } |
| 334 | |
| 335 | // This function can be removed when WP 3.9.2 or greater is required. |
| 336 | if ( ! function_exists( 'hash_equals' ) ) : |
| 337 | /** |
| 338 | * Compare two strings in constant time. |
| 339 | * |
| 340 | * This function was added in PHP 5.6. |
| 341 | * It can leak the length of a string. |
| 342 | * |
| 343 | * @since 1.0.0 |
| 344 | * |
| 345 | * @param string $a Expected string. |
| 346 | * @param string $b Actual string. |
| 347 | * @return bool Whether strings are equal. |
| 348 | */ |
| 349 | function hash_equals( $a, $b ) { |
| 350 | $a_length = strlen( $a ); |
| 351 | if ( strlen( $b ) !== $a_length ) { |
| 352 | return false; |
| 353 | } |
| 354 | $result = 0; |
| 355 | |
| 356 | // Do not attempt to "optimize" this. |
| 357 | for ( $i = 0; $i < $a_length; $i ++ ) { |
| 358 | $result |= ord( $a[ $i ] ) ^ ord( $b[ $i ] ); |
| 359 | } |
| 360 | |
| 361 | return 0 === $result; |
| 362 | } |
| 363 | endif; |
| 364 | |
| 365 | /** |
| 366 | * Generate a rand hash. |
| 367 | * |
| 368 | * @since 1.0.0 |
| 369 | * @return string |
| 370 | */ |
| 371 | function evf_rand_hash() { |
| 372 | if ( ! function_exists( 'openssl_random_pseudo_bytes' ) ) { |
| 373 | return sha1( wp_rand() ); |
| 374 | } |
| 375 | |
| 376 | return bin2hex( openssl_random_pseudo_bytes( 20 ) ); // @codingStandardsIgnoreLine |
| 377 | } |
| 378 | |
| 379 | /** |
| 380 | * Find all possible combinations of values from the input array and return in a logical order. |
| 381 | * |
| 382 | * @since 1.0.0 |
| 383 | * @param array $input Input. |
| 384 | * @return array |
| 385 | */ |
| 386 | function evf_array_cartesian( $input ) { |
| 387 | $input = array_filter( $input ); |
| 388 | $results = array(); |
| 389 | $indexes = array(); |
| 390 | $index = 0; |
| 391 | |
| 392 | // Generate indexes from keys and values so we have a logical sort order. |
| 393 | foreach ( $input as $key => $values ) { |
| 394 | foreach ( $values as $value ) { |
| 395 | $indexes[ $key ][ $value ] = $index++; |
| 396 | } |
| 397 | } |
| 398 | |
| 399 | // Loop over the 2D array of indexes and generate all combinations. |
| 400 | foreach ( $indexes as $key => $values ) { |
| 401 | // When result is empty, fill with the values of the first looped array. |
| 402 | if ( empty( $results ) ) { |
| 403 | foreach ( $values as $value ) { |
| 404 | $results[] = array( $key => $value ); |
| 405 | } |
| 406 | } else { |
| 407 | // Second and subsequent input sub-array merging. |
| 408 | foreach ( $results as $result_key => $result ) { |
| 409 | foreach ( $values as $value ) { |
| 410 | // If the key is not set, we can set it. |
| 411 | if ( ! isset( $results[ $result_key ][ $key ] ) ) { |
| 412 | $results[ $result_key ][ $key ] = $value; |
| 413 | } else { |
| 414 | // If the key is set, we can add a new combination to the results array. |
| 415 | $new_combination = $results[ $result_key ]; |
| 416 | $new_combination[ $key ] = $value; |
| 417 | $results[] = $new_combination; |
| 418 | } |
| 419 | } |
| 420 | } |
| 421 | } |
| 422 | } |
| 423 | |
| 424 | // Sort the indexes. |
| 425 | arsort( $results ); |
| 426 | |
| 427 | // Convert indexes back to values. |
| 428 | foreach ( $results as $result_key => $result ) { |
| 429 | $converted_values = array(); |
| 430 | |
| 431 | // Sort the values. |
| 432 | arsort( $results[ $result_key ] ); |
| 433 | |
| 434 | // Convert the values. |
| 435 | foreach ( $results[ $result_key ] as $key => $value ) { |
| 436 | $converted_values[ $key ] = array_search( $value, $indexes[ $key ], true ); |
| 437 | } |
| 438 | |
| 439 | $results[ $result_key ] = $converted_values; |
| 440 | } |
| 441 | |
| 442 | return $results; |
| 443 | } |
| 444 | |
| 445 | /** |
| 446 | * Run a MySQL transaction query, if supported. |
| 447 | * |
| 448 | * @since 1.0.0 |
| 449 | * @param string $type Types: start (default), commit, rollback. |
| 450 | * @param bool $force use of transactions. |
| 451 | */ |
| 452 | function evf_transaction_query( $type = 'start', $force = false ) { |
| 453 | global $wpdb; |
| 454 | |
| 455 | $wpdb->hide_errors(); |
| 456 | |
| 457 | evf_maybe_define_constant( 'EVF_USE_TRANSACTIONS', true ); |
| 458 | |
| 459 | if ( EVF_USE_TRANSACTIONS || $force ) { |
| 460 | switch ( $type ) { |
| 461 | case 'commit': |
| 462 | $wpdb->query( 'COMMIT' ); |
| 463 | break; |
| 464 | case 'rollback': |
| 465 | $wpdb->query( 'ROLLBACK' ); |
| 466 | break; |
| 467 | default: |
| 468 | $wpdb->query( 'START TRANSACTION' ); |
| 469 | break; |
| 470 | } |
| 471 | } |
| 472 | } |
| 473 | |
| 474 | /** |
| 475 | * Outputs a "back" link so admin screens can easily jump back a page. |
| 476 | * |
| 477 | * @param string $label Title of the page to return to. |
| 478 | * @param string $url URL of the page to return to. |
| 479 | */ |
| 480 | function evf_back_link( $label, $url ) { |
| 481 | echo '<small class="evf-admin-breadcrumb"><a href="' . esc_url( $url ) . '" aria-label="' . esc_attr( $label ) . '">⤴</a></small>'; |
| 482 | } |
| 483 | |
| 484 | /** |
| 485 | * Display a EverestForms help tip. |
| 486 | * |
| 487 | * @since 1.0.0 |
| 488 | * |
| 489 | * @param string $tip Help tip text |
| 490 | * @param bool $allow_html Allow sanitized HTML if true or escape |
| 491 | * @return string |
| 492 | */ |
| 493 | function evf_help_tip( $tip, $allow_html = false ) { |
| 494 | if ( $allow_html ) { |
| 495 | $tip = evf_sanitize_tooltip( $tip ); |
| 496 | } else { |
| 497 | $tip = esc_attr( $tip ); |
| 498 | } |
| 499 | |
| 500 | return '<span class="everest-forms-help-tip" data-tip="' . $tip . '"></span>'; |
| 501 | } |
| 502 | |
| 503 | /** |
| 504 | * Wrapper for set_time_limit to see if it is enabled. |
| 505 | * |
| 506 | * @since 1.0.0 |
| 507 | * @param int $limit Time limit. |
| 508 | */ |
| 509 | function evf_set_time_limit( $limit = 0 ) { |
| 510 | 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 |
| 511 | @set_time_limit( $limit ); // @codingStandardsIgnoreLine |
| 512 | } |
| 513 | } |
| 514 | |
| 515 | /** |
| 516 | * Wrapper for nocache_headers which also disables page caching. |
| 517 | * |
| 518 | * @since 1.2.0 |
| 519 | */ |
| 520 | function evf_nocache_headers() { |
| 521 | EVF_Cache_Helper::set_nocache_constants(); |
| 522 | nocache_headers(); |
| 523 | } |
| 524 | |
| 525 | /** |
| 526 | * Get a shared logger instance. |
| 527 | * |
| 528 | * Use the everest_forms_logging_class filter to change the logging class. You may provide one of the following: |
| 529 | * - a class name which will be instantiated as `new $class` with no arguments |
| 530 | * - an instance which will be used directly as the logger |
| 531 | * In either case, the class or instance *must* implement EVF_Logger_Interface. |
| 532 | * |
| 533 | * @see EVF_Logger_Interface |
| 534 | * |
| 535 | * @return EVF_Logger |
| 536 | */ |
| 537 | function evf_get_logger() { |
| 538 | static $logger = null; |
| 539 | |
| 540 | $class = apply_filters( 'everest_forms_logging_class', 'EVF_Logger' ); |
| 541 | |
| 542 | if ( null !== $logger && is_string( $class ) && is_a( $logger, $class ) ) { |
| 543 | return $logger; |
| 544 | } |
| 545 | |
| 546 | $implements = class_implements( $class ); |
| 547 | |
| 548 | if ( is_array( $implements ) && in_array( 'EVF_Logger_Interface', $implements, true ) ) { |
| 549 | $logger = is_object( $class ) ? $class : new $class(); |
| 550 | } else { |
| 551 | evf_doing_it_wrong( |
| 552 | __FUNCTION__, |
| 553 | sprintf( |
| 554 | /* translators: 1: class name 2: everest_forms_logging_class 3: EVF_Logger_Interface */ |
| 555 | __( 'The class %1$s provided by %2$s filter must implement %3$s.', 'everest-forms' ), |
| 556 | '<code>' . esc_html( is_object( $class ) ? get_class( $class ) : $class ) . '</code>', |
| 557 | '<code>everest_forms_logging_class</code>', |
| 558 | '<code>EVF_Logger_Interface</code>' |
| 559 | ), |
| 560 | '1.2' |
| 561 | ); |
| 562 | $logger = is_a( $logger, 'EVF_Logger' ) ? $logger : new EVF_Logger(); |
| 563 | } |
| 564 | |
| 565 | return $logger; |
| 566 | } |
| 567 | |
| 568 | /** |
| 569 | * Prints human-readable information about a variable. |
| 570 | * |
| 571 | * Some server environments blacklist some debugging functions. This function provides a safe way to |
| 572 | * turn an expression into a printable, readable form without calling blacklisted functions. |
| 573 | * |
| 574 | * @since 1.0.0 |
| 575 | * |
| 576 | * @param mixed $expression The expression to be printed. |
| 577 | * @param bool $return Optional. Default false. Set to true to return the human-readable string. |
| 578 | * |
| 579 | * @return string|bool False if expression could not be printed. True if the expression was printed. |
| 580 | * If $return is true, a string representation will be returned. |
| 581 | */ |
| 582 | function evf_print_r( $expression, $return = false ) { |
| 583 | $alternatives = array( |
| 584 | array( |
| 585 | 'func' => 'print_r', |
| 586 | 'args' => array( $expression, true ), |
| 587 | ), |
| 588 | array( |
| 589 | 'func' => 'var_export', |
| 590 | 'args' => array( $expression, true ), |
| 591 | ), |
| 592 | array( |
| 593 | 'func' => 'json_encode', |
| 594 | 'args' => array( $expression ), |
| 595 | ), |
| 596 | array( |
| 597 | 'func' => 'serialize', |
| 598 | 'args' => array( $expression ), |
| 599 | ), |
| 600 | ); |
| 601 | |
| 602 | $alternatives = apply_filters( 'everest_forms_print_r_alternatives', $alternatives, $expression ); |
| 603 | |
| 604 | foreach ( $alternatives as $alternative ) { |
| 605 | if ( function_exists( $alternative['func'] ) ) { |
| 606 | $res = call_user_func_array( $alternative['func'], $alternative['args'] ); |
| 607 | if ( $return ) { |
| 608 | return $res; |
| 609 | } |
| 610 | |
| 611 | echo $res; // WPCS: XSS ok. |
| 612 | return true; |
| 613 | } |
| 614 | } |
| 615 | |
| 616 | return false; |
| 617 | } |
| 618 | |
| 619 | /** |
| 620 | * Registers the default log handler. |
| 621 | * |
| 622 | * @since 1.0.0 |
| 623 | * @param array $handlers Handlers. |
| 624 | * @return array |
| 625 | */ |
| 626 | function evf_register_default_log_handler( $handlers ) { |
| 627 | if ( defined( 'EVF_LOG_HANDLER' ) && class_exists( EVF_LOG_HANDLER ) ) { |
| 628 | $handler_class = EVF_LOG_HANDLER; |
| 629 | $default_handler = new $handler_class(); |
| 630 | } else { |
| 631 | $default_handler = new EVF_Log_Handler_File(); |
| 632 | } |
| 633 | |
| 634 | array_push( $handlers, $default_handler ); |
| 635 | |
| 636 | return $handlers; |
| 637 | } |
| 638 | |
| 639 | add_filter( 'everest_forms_register_log_handlers', 'evf_register_default_log_handler' ); |
| 640 | |
| 641 | /** |
| 642 | * Based on wp_list_pluck, this calls a method instead of returning a property. |
| 643 | * |
| 644 | * @since 1.0.0 |
| 645 | * @param array $list List of objects or arrays |
| 646 | * @param int|string $callback_or_field Callback method from the object to place instead of the entire object |
| 647 | * @param int|string $index_key Optional. Field from the object to use as keys for the new array. |
| 648 | * Default null. |
| 649 | * @return array Array of values. |
| 650 | */ |
| 651 | function evf_list_pluck( $list, $callback_or_field, $index_key = null ) { |
| 652 | // Use wp_list_pluck if this isn't a callback. |
| 653 | $first_el = current( $list ); |
| 654 | if ( ! is_object( $first_el ) || ! is_callable( array( $first_el, $callback_or_field ) ) ) { |
| 655 | return wp_list_pluck( $list, $callback_or_field, $index_key ); |
| 656 | } |
| 657 | if ( ! $index_key ) { |
| 658 | /* |
| 659 | * This is simple. Could at some point wrap array_column() |
| 660 | * if we knew we had an array of arrays. |
| 661 | */ |
| 662 | foreach ( $list as $key => $value ) { |
| 663 | $list[ $key ] = $value->{$callback_or_field}(); |
| 664 | } |
| 665 | return $list; |
| 666 | } |
| 667 | |
| 668 | /* |
| 669 | * When index_key is not set for a particular item, push the value |
| 670 | * to the end of the stack. This is how array_column() behaves. |
| 671 | */ |
| 672 | $newlist = array(); |
| 673 | foreach ( $list as $value ) { |
| 674 | // Get index. |
| 675 | if ( is_callable( array( $value, $index_key ) ) ) { |
| 676 | $newlist[ $value->{$index_key}() ] = $value->{$callback_or_field}(); |
| 677 | } elseif ( isset( $value->$index_key ) ) { |
| 678 | $newlist[ $value->$index_key ] = $value->{$callback_or_field}(); |
| 679 | } else { |
| 680 | $newlist[] = $value->{$callback_or_field}(); |
| 681 | } |
| 682 | } |
| 683 | return $newlist; |
| 684 | } |
| 685 | |
| 686 | /** |
| 687 | * Switch EverestForms to site language. |
| 688 | * |
| 689 | * @since 1.0.0 |
| 690 | */ |
| 691 | function evf_switch_to_site_locale() { |
| 692 | if ( function_exists( 'switch_to_locale' ) ) { |
| 693 | switch_to_locale( get_locale() ); |
| 694 | |
| 695 | // Filter on plugin_locale so load_plugin_textdomain loads the correct locale. |
| 696 | add_filter( 'plugin_locale', 'get_locale' ); |
| 697 | |
| 698 | // Init EVF locale. |
| 699 | EVF()->load_plugin_textdomain(); |
| 700 | } |
| 701 | } |
| 702 | |
| 703 | /** |
| 704 | * Switch EverestForms language to original. |
| 705 | * |
| 706 | * @since 1.0.0 |
| 707 | */ |
| 708 | function evf_restore_locale() { |
| 709 | if ( function_exists( 'restore_previous_locale' ) ) { |
| 710 | restore_previous_locale(); |
| 711 | |
| 712 | // Remove filter. |
| 713 | remove_filter( 'plugin_locale', 'get_locale' ); |
| 714 | |
| 715 | // Init EVF locale. |
| 716 | EVF()->load_plugin_textdomain(); |
| 717 | } |
| 718 | } |
| 719 | |
| 720 | /** |
| 721 | * Get an item of post data if set, otherwise return a default value. |
| 722 | * |
| 723 | * @since 1.0.0 |
| 724 | * @param string $key |
| 725 | * @param string $default |
| 726 | * @return mixed value sanitized by evf_clean |
| 727 | */ |
| 728 | function evf_get_post_data_by_key( $key, $default = '' ) { |
| 729 | return evf_clean( evf_get_var( $_POST[ $key ], $default ) ); |
| 730 | } |
| 731 | |
| 732 | /** |
| 733 | * Get data if set, otherwise return a default value or null. Prevents notices when data is not set. |
| 734 | * |
| 735 | * @since 1.0.0 |
| 736 | * @param mixed $var Variable. |
| 737 | * @param string $default Default value. |
| 738 | * @return mixed |
| 739 | */ |
| 740 | function evf_get_var( &$var, $default = null ) { |
| 741 | return isset( $var ) ? $var : $default; |
| 742 | } |
| 743 | |
| 744 | /** |
| 745 | * Read in EverestForms headers when reading plugin headers. |
| 746 | * |
| 747 | * @since 1.2.0 |
| 748 | * @param array $headers Headers. |
| 749 | * @return array |
| 750 | */ |
| 751 | function evf_enable_evf_plugin_headers( $headers ) { |
| 752 | if ( ! class_exists( 'EVF_Plugin_Updates' ) ) { |
| 753 | include_once dirname( __FILE__ ) . '/admin/plugin-updates/class-evf-plugin-updates.php'; |
| 754 | } |
| 755 | |
| 756 | // EVF requires at least - allows developers to define which version of Everest Forms the plugin requires to run. |
| 757 | $headers[] = EVF_Plugin_Updates::VERSION_REQUIRED_HEADER; |
| 758 | |
| 759 | // EVF tested up to - allows developers to define which version of Everest Forms they have tested up to. |
| 760 | $headers[] = EVF_Plugin_Updates::VERSION_TESTED_HEADER; |
| 761 | |
| 762 | return $headers; |
| 763 | } |
| 764 | add_filter( 'extra_theme_headers', 'evf_enable_evf_plugin_headers' ); |
| 765 | add_filter( 'extra_plugin_headers', 'evf_enable_evf_plugin_headers' ); |
| 766 | |
| 767 | /** |
| 768 | * Delete expired transients. |
| 769 | * |
| 770 | * Deletes all expired transients. The multi-table delete syntax is used. |
| 771 | * to delete the transient record from table a, and the corresponding. |
| 772 | * transient_timeout record from table b. |
| 773 | * |
| 774 | * Based on code inside core's upgrade_network() function. |
| 775 | * |
| 776 | * @since 1.0.0 |
| 777 | * @return int Number of transients that were cleared. |
| 778 | */ |
| 779 | function evf_delete_expired_transients() { |
| 780 | global $wpdb; |
| 781 | |
| 782 | $sql = "DELETE a, b FROM $wpdb->options a, $wpdb->options b |
| 783 | WHERE a.option_name LIKE %s |
| 784 | AND a.option_name NOT LIKE %s |
| 785 | AND b.option_name = CONCAT( '_transient_timeout_', SUBSTRING( a.option_name, 12 ) ) |
| 786 | AND b.option_value < %d"; |
| 787 | $rows = $wpdb->query( $wpdb->prepare( $sql, $wpdb->esc_like( '_transient_' ) . '%', $wpdb->esc_like( '_transient_timeout_' ) . '%', time() ) ); // WPCS: unprepared SQL ok. |
| 788 | |
| 789 | $sql = "DELETE a, b FROM $wpdb->options a, $wpdb->options b |
| 790 | WHERE a.option_name LIKE %s |
| 791 | AND a.option_name NOT LIKE %s |
| 792 | AND b.option_name = CONCAT( '_site_transient_timeout_', SUBSTRING( a.option_name, 17 ) ) |
| 793 | AND b.option_value < %d"; |
| 794 | $rows2 = $wpdb->query( $wpdb->prepare( $sql, $wpdb->esc_like( '_site_transient_' ) . '%', $wpdb->esc_like( '_site_transient_timeout_' ) . '%', time() ) ); // WPCS: unprepared SQL ok. |
| 795 | |
| 796 | return absint( $rows + $rows2 ); |
| 797 | } |
| 798 | add_action( 'everest_forms_installed', 'evf_delete_expired_transients' ); |
| 799 | |
| 800 | /** |
| 801 | * Make a URL relative, if possible. |
| 802 | * |
| 803 | * @since 1.0.0 |
| 804 | * @param string $url URL to make relative. |
| 805 | * @return string |
| 806 | */ |
| 807 | function evf_get_relative_url( $url ) { |
| 808 | return evf_is_external_resource( $url ) ? $url : str_replace( array( 'http://', 'https://' ), '//', $url ); |
| 809 | } |
| 810 | |
| 811 | /** |
| 812 | * See if a resource is remote. |
| 813 | * |
| 814 | * @since 1.0.0 |
| 815 | * @param string $url URL to check. |
| 816 | * @return bool |
| 817 | */ |
| 818 | function evf_is_external_resource( $url ) { |
| 819 | $wp_base = str_replace( array( 'http://', 'https://' ), '//', get_home_url( null, '/', 'http' ) ); |
| 820 | return strstr( $url, '://' ) && strstr( $wp_base, $url ); |
| 821 | } |
| 822 | |
| 823 | /** |
| 824 | * See if theme/s is activate or not. |
| 825 | * |
| 826 | * @since 1.0.0 |
| 827 | * @param string|array $theme Theme name or array of theme names to check. |
| 828 | * @return boolean |
| 829 | */ |
| 830 | function evf_is_active_theme( $theme ) { |
| 831 | return is_array( $theme ) ? in_array( get_template(), $theme, true ) : get_template() === $theme; |
| 832 | } |
| 833 | |
| 834 | /** |
| 835 | * Cleans up session data - cron callback. |
| 836 | * |
| 837 | * @since 1.0.0 |
| 838 | */ |
| 839 | function evf_cleanup_session_data() { |
| 840 | $session_class = apply_filters( 'everest_forms_session_handler', 'EVF_Session_Handler' ); |
| 841 | $session = new $session_class(); |
| 842 | |
| 843 | if ( is_callable( array( $session, 'cleanup_sessions' ) ) ) { |
| 844 | $session->cleanup_sessions(); |
| 845 | } |
| 846 | } |
| 847 | add_action( 'everest_forms_cleanup_sessions', 'evf_cleanup_session_data' ); |
| 848 | |
| 849 | /** |
| 850 | * Return the html selected attribute if stringified $value is found in array of stringified $options |
| 851 | * or if stringified $value is the same as scalar stringified $options. |
| 852 | * |
| 853 | * @param string|int $value Value to find within options. |
| 854 | * @param string|int|array $options Options to go through when looking for value. |
| 855 | * @return string |
| 856 | */ |
| 857 | function evf_selected( $value, $options ) { |
| 858 | if ( is_array( $options ) ) { |
| 859 | $options = array_map( 'strval', $options ); |
| 860 | return selected( in_array( (string) $value, $options, true ), true, false ); |
| 861 | } |
| 862 | |
| 863 | return selected( $value, $options, false ); |
| 864 | } |
| 865 | |
| 866 | /** |
| 867 | * Retrieve actual fields from a form. |
| 868 | * |
| 869 | * Non-posting elements such as section divider, page break, and HTML are |
| 870 | * automatically excluded. Optionally a white list can be provided. |
| 871 | * |
| 872 | * @since 1.0.0 |
| 873 | * |
| 874 | * @param mixed $form |
| 875 | * @param array $whitelist |
| 876 | * |
| 877 | * @return mixed boolean or array |
| 878 | */ |
| 879 | function evf_get_form_fields( $form = false, $whitelist = array() ) { |
| 880 | |
| 881 | // Accept form (post) object or form ID |
| 882 | if ( is_object( $form ) ) { |
| 883 | $form = json_decode( $form->post_content ); |
| 884 | } elseif ( is_numeric( $form ) ) { |
| 885 | $form = EVF()->form->get( |
| 886 | $form, |
| 887 | array( |
| 888 | 'content_only' => true, |
| 889 | ) |
| 890 | ); |
| 891 | } |
| 892 | |
| 893 | if ( ! is_array( $form ) || empty( $form['form_fields'] ) ) { |
| 894 | return false; |
| 895 | } |
| 896 | |
| 897 | // White list of field types to allow |
| 898 | $allowed_form_fields = array( |
| 899 | 'first-name', |
| 900 | 'last-name', |
| 901 | 'text', |
| 902 | 'textarea', |
| 903 | 'select', |
| 904 | 'radio', |
| 905 | 'checkbox', |
| 906 | 'email', |
| 907 | 'address', |
| 908 | 'country', |
| 909 | 'url', |
| 910 | 'name', |
| 911 | 'hidden', |
| 912 | 'date', |
| 913 | 'phone', |
| 914 | 'number', |
| 915 | 'file-upload', |
| 916 | 'image-upload', |
| 917 | 'payment-single', |
| 918 | 'payment-multiple', |
| 919 | 'payment-checkbox', |
| 920 | 'payment-total', |
| 921 | ); |
| 922 | $allowed_form_fields = apply_filters( 'everest_forms_allowed_form_fields', $allowed_form_fields ); |
| 923 | |
| 924 | $whitelist = ! empty( $whitelist ) ? $whitelist : $allowed_form_fields; |
| 925 | |
| 926 | $form_fields = $form['form_fields']; |
| 927 | |
| 928 | foreach ( $form_fields as $id => $form_field ) { |
| 929 | if ( ! in_array( $form_field['type'], $whitelist, true ) ) { |
| 930 | unset( $form_fields[ $id ] ); |
| 931 | } |
| 932 | } |
| 933 | |
| 934 | return $form_fields; |
| 935 | } |
| 936 | |
| 937 | /** |
| 938 | * @param $string |
| 939 | * |
| 940 | * @return string |
| 941 | */ |
| 942 | function evf_sanitize_textarea_field( $string ) { |
| 943 | if ( empty( $string ) || ! is_string( $string ) ) { |
| 944 | return $string; |
| 945 | } |
| 946 | |
| 947 | if ( function_exists( 'sanitize_textarea_field' ) ) { |
| 948 | $string = sanitize_textarea_field( $string ); |
| 949 | } else { |
| 950 | $string = implode( "\n", array_map( 'sanitize_text_field', explode( "\n", $string ) ) ); |
| 951 | } |
| 952 | |
| 953 | return $string; |
| 954 | } |
| 955 | |
| 956 | /** |
| 957 | * Formats, sanitizes, and returns/echos HTML element ID, classes, attributes, |
| 958 | * and data attributes. |
| 959 | * |
| 960 | * @param string $id |
| 961 | * @param array $class |
| 962 | * @param array $datas |
| 963 | * @param array $atts |
| 964 | * @param bool $echo |
| 965 | * |
| 966 | * @return string |
| 967 | */ |
| 968 | function evf_html_attributes( $id = '', $class = array(), $datas = array(), $atts = array(), $echo = false ) { |
| 969 | $id = trim( $id ); |
| 970 | $parts = array(); |
| 971 | |
| 972 | if ( ! empty( $id ) ) { |
| 973 | $id = sanitize_html_class( $id ); |
| 974 | if ( ! empty( $id ) ) { |
| 975 | $parts[] = 'id="' . $id . '"'; |
| 976 | } |
| 977 | } |
| 978 | |
| 979 | if ( ! empty( $class ) ) { |
| 980 | $class = evf_sanitize_classes( $class, true ); |
| 981 | if ( ! empty( $class ) ) { |
| 982 | $parts[] = 'class="' . $class . '"'; |
| 983 | } |
| 984 | } |
| 985 | |
| 986 | if ( ! empty( $datas ) ) { |
| 987 | foreach ( $datas as $data => $val ) { |
| 988 | $parts[] = 'data-' . sanitize_html_class( $data ) . '="' . esc_attr( $val ) . '"'; |
| 989 | } |
| 990 | } |
| 991 | |
| 992 | if ( ! empty( $atts ) ) { |
| 993 | foreach ( $atts as $att => $val ) { |
| 994 | if ( '0' == $val || ! empty( $val ) ) { |
| 995 | $parts[] = sanitize_html_class( $att ) . '="' . esc_attr( $val ) . '"'; |
| 996 | } |
| 997 | } |
| 998 | } |
| 999 | |
| 1000 | $output = implode( ' ', $parts ); |
| 1001 | |
| 1002 | if ( $echo ) { |
| 1003 | echo trim( $output ); // phpcs:ignore |
| 1004 | } else { |
| 1005 | return trim( $output ); |
| 1006 | } |
| 1007 | } |
| 1008 | |
| 1009 | /** |
| 1010 | * Sanitizes string of CSS classes. |
| 1011 | * |
| 1012 | * @param array|string $classes |
| 1013 | * @param bool $convert True will convert strings to array and vice versa. |
| 1014 | * |
| 1015 | * @return string|array |
| 1016 | */ |
| 1017 | function evf_sanitize_classes( $classes, $convert = false ) { |
| 1018 | $css = array(); |
| 1019 | $array = is_array( $classes ); |
| 1020 | |
| 1021 | if ( ! empty( $classes ) ) { |
| 1022 | if ( ! $array ) { |
| 1023 | $classes = explode( ' ', trim( $classes ) ); |
| 1024 | } |
| 1025 | foreach ( $classes as $class ) { |
| 1026 | $css[] = sanitize_html_class( $class ); |
| 1027 | } |
| 1028 | } |
| 1029 | |
| 1030 | if ( $array ) { |
| 1031 | return $convert ? implode( ' ', $css ) : $css; |
| 1032 | } else { |
| 1033 | return $convert ? $css : implode( ' ', $css ); |
| 1034 | } |
| 1035 | } |
| 1036 | |
| 1037 | /** |
| 1038 | * Performs json_decode and unslash. |
| 1039 | * |
| 1040 | * @since 1.0.0 |
| 1041 | * |
| 1042 | * @param string $data |
| 1043 | * @return array|bool |
| 1044 | */ |
| 1045 | function evf_decode( $data ) { |
| 1046 | if ( ! $data || empty( $data ) ) { |
| 1047 | return false; |
| 1048 | } |
| 1049 | |
| 1050 | return wp_unslash( json_decode( $data, true ) ); |
| 1051 | } |
| 1052 | |
| 1053 | /** |
| 1054 | * Performs json_encode and wp_slash. |
| 1055 | * |
| 1056 | * @since 1.0.0 |
| 1057 | * |
| 1058 | * @param mixed $data |
| 1059 | * |
| 1060 | * @return string |
| 1061 | */ |
| 1062 | function evf_encode( $data = false ) { |
| 1063 | if ( empty( $data ) ) { |
| 1064 | return false; |
| 1065 | } |
| 1066 | |
| 1067 | return wp_slash( wp_json_encode( $data ) ); |
| 1068 | } |
| 1069 | |
| 1070 | /** |
| 1071 | * @param $min |
| 1072 | * @param $max |
| 1073 | * |
| 1074 | * @return mixed |
| 1075 | */ |
| 1076 | function evf_crypto_rand_secure( $min, $max ) { |
| 1077 | $range = $max - $min; |
| 1078 | if ( $range < 1 ) { |
| 1079 | return $min; |
| 1080 | } // not so random... |
| 1081 | $log = ceil( log( $range, 2 ) ); |
| 1082 | $bytes = (int) ( $log / 8 ) + 1; // length in bytes |
| 1083 | $bits = (int) $log + 1; // length in bits |
| 1084 | $filter = (int) ( 1 << $bits ) - 1; // set all lower bits to 1 |
| 1085 | do { |
| 1086 | $rnd = hexdec( bin2hex( openssl_random_pseudo_bytes( $bytes ) ) ); |
| 1087 | $rnd = $rnd & $filter; // discard irrelevant bits |
| 1088 | } while ( $rnd > $range ); |
| 1089 | |
| 1090 | return $min + $rnd; |
| 1091 | } |
| 1092 | |
| 1093 | /** |
| 1094 | * @param int $length |
| 1095 | * |
| 1096 | * @return string |
| 1097 | */ |
| 1098 | function evf_get_random_string( $length = 10 ) { |
| 1099 | $string = ''; |
| 1100 | $codeAlphabet = 'ABCDEFGHIJKLMNOPQRSTUVWXYZ'; |
| 1101 | $codeAlphabet .= 'abcdefghijklmnopqrstuvwxyz'; |
| 1102 | $codeAlphabet .= '0123456789'; |
| 1103 | $max = strlen( $codeAlphabet ); // edited |
| 1104 | for ( $i = 0; $i < $length; $i ++ ) { |
| 1105 | $string .= $codeAlphabet[ evf_crypto_rand_secure( 0, $max - 1 ) ]; |
| 1106 | } |
| 1107 | |
| 1108 | return $string; |
| 1109 | } |
| 1110 | |
| 1111 | /** |
| 1112 | * Get all forms. |
| 1113 | * |
| 1114 | * @param bool $skip_disabled_entries True to skip disabled entries. |
| 1115 | * @return array of form data. |
| 1116 | */ |
| 1117 | function evf_get_all_forms( $skip_disabled_entries = false ) { |
| 1118 | $forms = array(); |
| 1119 | $form_ids = wp_parse_id_list( |
| 1120 | get_posts( |
| 1121 | array( |
| 1122 | 'post_type' => 'everest_form', |
| 1123 | 'numberposts' => -1, // @codingStandardsIgnoreLine |
| 1124 | 'status' => 'publish', |
| 1125 | 'fields' => 'ids', |
| 1126 | ) |
| 1127 | ) |
| 1128 | ); |
| 1129 | |
| 1130 | if ( ! empty( $form_ids ) ) { |
| 1131 | foreach ( $form_ids as $form_id ) { |
| 1132 | $form = EVF()->form->get( $form_id ); |
| 1133 | $form_data = ! empty( $form->post_content ) ? evf_decode( $form->post_content ) : ''; |
| 1134 | |
| 1135 | if ( $skip_disabled_entries && ( isset( $form_data['settings']['disabled_entries'] ) && '1' === $form_data['settings']['disabled_entries'] ) ) { |
| 1136 | continue; |
| 1137 | } |
| 1138 | |
| 1139 | $forms[ $form_id ] = $form->post_title; |
| 1140 | } |
| 1141 | } |
| 1142 | |
| 1143 | return $forms; |
| 1144 | } |
| 1145 | |
| 1146 | /** |
| 1147 | * Get random meta-key for field option. |
| 1148 | * |
| 1149 | * @param array $field Field data array |
| 1150 | * @return string |
| 1151 | */ |
| 1152 | function evf_get_meta_key_field_option( $field ) { |
| 1153 | $random_number = rand( pow( 10, 3 ), pow( 10, 4 ) - 1 ); |
| 1154 | return strtolower( str_replace( array( ' ', '/_' ), array( '_', '' ), $field['label'] ) ) . '_' . $random_number; |
| 1155 | } |
| 1156 | |
| 1157 | /** |
| 1158 | * Get current user IP Address. |
| 1159 | * |
| 1160 | * @return string |
| 1161 | */ |
| 1162 | function evf_get_ip_address() { |
| 1163 | if ( isset( $_SERVER['HTTP_X_REAL_IP'] ) ) { // WPCS: input var ok, CSRF ok. |
| 1164 | return sanitize_text_field( wp_unslash( $_SERVER['HTTP_X_REAL_IP'] ) ); // WPCS: input var ok, CSRF ok. |
| 1165 | } elseif ( isset( $_SERVER['HTTP_X_FORWARDED_FOR'] ) ) { // WPCS: input var ok, CSRF ok. |
| 1166 | // Proxy servers can send through this header like this: X-Forwarded-For: client1, proxy1, proxy2 |
| 1167 | // Make sure we always only send through the first IP in the list which should always be the client IP. |
| 1168 | 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. |
| 1169 | } elseif ( isset( $_SERVER['REMOTE_ADDR'] ) ) { // @codingStandardsIgnoreLine |
| 1170 | return sanitize_text_field( wp_unslash( $_SERVER['REMOTE_ADDR'] ) ); // @codingStandardsIgnoreLine |
| 1171 | } |
| 1172 | return ''; |
| 1173 | } |
| 1174 | |
| 1175 | /** |
| 1176 | * Get User Agent browser and OS type |
| 1177 | * |
| 1178 | * @since 1.1.0 |
| 1179 | * @return array |
| 1180 | */ |
| 1181 | function evf_get_browser() { |
| 1182 | $u_agent = $_SERVER['HTTP_USER_AGENT']; |
| 1183 | $bname = 'Unknown'; |
| 1184 | $platform = 'Unknown'; |
| 1185 | $version = ''; |
| 1186 | |
| 1187 | // First get the platform. |
| 1188 | if ( preg_match( '/linux/i', $u_agent ) ) { |
| 1189 | $platform = 'Linux'; |
| 1190 | } elseif ( preg_match( '/macintosh|mac os x/i', $u_agent ) ) { |
| 1191 | $platform = 'MAC OS'; |
| 1192 | } elseif ( preg_match( '/windows|win32/i', $u_agent ) ) { |
| 1193 | $platform = 'Windows'; |
| 1194 | } |
| 1195 | |
| 1196 | // Next get the name of the useragent yes seperately and for good reason. |
| 1197 | if ( preg_match( '/MSIE/i', $u_agent ) && ! preg_match( '/Opera/i', $u_agent ) ) { |
| 1198 | $bname = 'Internet Explorer'; |
| 1199 | $ub = 'MSIE'; |
| 1200 | } elseif ( preg_match( '/Trident/i', $u_agent ) ) { |
| 1201 | // this condition is for IE11 |
| 1202 | $bname = 'Internet Explorer'; |
| 1203 | $ub = 'rv'; |
| 1204 | } elseif ( preg_match( '/Firefox/i', $u_agent ) ) { |
| 1205 | $bname = 'Mozilla Firefox'; |
| 1206 | $ub = 'Firefox'; |
| 1207 | } elseif ( preg_match( '/Chrome/i', $u_agent ) ) { |
| 1208 | $bname = 'Google Chrome'; |
| 1209 | $ub = 'Chrome'; |
| 1210 | } elseif ( preg_match( '/Safari/i', $u_agent ) ) { |
| 1211 | $bname = 'Apple Safari'; |
| 1212 | $ub = 'Safari'; |
| 1213 | } elseif ( preg_match( '/Opera/i', $u_agent ) ) { |
| 1214 | $bname = 'Opera'; |
| 1215 | $ub = 'Opera'; |
| 1216 | } elseif ( preg_match( '/Netscape/i', $u_agent ) ) { |
| 1217 | $bname = 'Netscape'; |
| 1218 | $ub = 'Netscape'; |
| 1219 | } |
| 1220 | |
| 1221 | // Finally get the correct version number. |
| 1222 | // Added "|:" |
| 1223 | $known = array( 'Version', $ub, 'other' ); |
| 1224 | $pattern = '#(?<browser>' . join( '|', $known ) . |
| 1225 | ')[/|: ]+(?<version>[0-9.|a-zA-Z.]*)#'; |
| 1226 | if ( ! preg_match_all( $pattern, $u_agent, $matches ) ) { |
| 1227 | // We have no matching number just continue. |
| 1228 | } |
| 1229 | |
| 1230 | // See how many we have. |
| 1231 | $i = count( $matches['browser'] ); |
| 1232 | |
| 1233 | if ( $i != 1 ) { |
| 1234 | // we will have two since we are not using 'other' argument yet. |
| 1235 | // see if version is before or after the name. |
| 1236 | if ( strripos( $u_agent, 'Version' ) < strripos( $u_agent, $ub ) ) { |
| 1237 | $version = $matches['version'][0]; |
| 1238 | } else { |
| 1239 | $version = $matches['version'][1]; |
| 1240 | } |
| 1241 | } else { |
| 1242 | $version = $matches['version'][0]; |
| 1243 | } |
| 1244 | |
| 1245 | // Check if we have a number. |
| 1246 | if ( $version == null || $version == '' ) { |
| 1247 | $version = ''; |
| 1248 | } |
| 1249 | |
| 1250 | return array( |
| 1251 | 'userAgent' => $u_agent, |
| 1252 | 'name' => $bname, |
| 1253 | 'version' => $version, |
| 1254 | 'platform' => $platform, |
| 1255 | 'pattern' => $pattern, |
| 1256 | ); |
| 1257 | } |
| 1258 | |
| 1259 | /** |
| 1260 | * Get the certain date of a specified day in a specified format. |
| 1261 | * |
| 1262 | * @since 1.1.0 |
| 1263 | * |
| 1264 | * @param string $period Supported values: start, end. |
| 1265 | * @param string $timestamp Default is the current timestamp, if left empty. |
| 1266 | * @param string $format Default is a MySQL format. |
| 1267 | * |
| 1268 | * @return string |
| 1269 | */ |
| 1270 | function evf_get_day_period_date( $period, $timestamp = '', $format = 'Y-m-d H:i:s' ) { |
| 1271 | $date = ''; |
| 1272 | |
| 1273 | if ( empty( $timestamp ) ) { |
| 1274 | $timestamp = time(); |
| 1275 | } |
| 1276 | |
| 1277 | switch ( $period ) { |
| 1278 | case 'start_of_day': |
| 1279 | $date = date( $format, strtotime( 'today', $timestamp ) ); |
| 1280 | break; |
| 1281 | |
| 1282 | case 'end_of_day': |
| 1283 | $date = date( $format, strtotime( 'tomorrow', $timestamp ) - 1 ); |
| 1284 | break; |
| 1285 | |
| 1286 | } |
| 1287 | |
| 1288 | return $date; |
| 1289 | } |
| 1290 | |
| 1291 | /** |
| 1292 | * Get field label by meta key |
| 1293 | * |
| 1294 | * @param $form_id Form ID |
| 1295 | * @param $meta_key Field's meta key |
| 1296 | * @return mixed |
| 1297 | */ |
| 1298 | function evf_get_form_data_by_meta_key( $form_id, $meta_key ) { |
| 1299 | $get_post = get_post( $form_id ); |
| 1300 | $post_content = json_decode( $get_post->post_content, true ); |
| 1301 | $form_fields = isset( $post_content['form_fields'] ) ? $post_content['form_fields'] : array(); |
| 1302 | |
| 1303 | if ( ! empty( $form_fields ) ) { |
| 1304 | foreach ( $form_fields as $field ) { |
| 1305 | if ( isset( $field['meta-key'] ) && $meta_key == $field['meta-key'] ) { |
| 1306 | return $field['label']; |
| 1307 | } |
| 1308 | } |
| 1309 | } |
| 1310 | |
| 1311 | return false; |
| 1312 | } |
| 1313 | |
| 1314 | /** |
| 1315 | * Get field type by meta key |
| 1316 | * |
| 1317 | * @param $form_id Form ID |
| 1318 | * @param $meta_key Field's meta key |
| 1319 | * @return mixed |
| 1320 | */ |
| 1321 | function evf_get_field_type_by_meta_key( $form_id, $meta_key ) { |
| 1322 | $get_post = get_post( $form_id ); |
| 1323 | $post_content = json_decode( $get_post->post_content, true ); |
| 1324 | $form_fields = isset( $post_content['form_fields'] ) ? $post_content['form_fields'] : array(); |
| 1325 | |
| 1326 | if ( ! empty( $form_fields ) ) { |
| 1327 | foreach ( $form_fields as $field ) { |
| 1328 | if ( isset( $field['meta-key'] ) && $meta_key == $field['meta-key'] ) { |
| 1329 | return $field['type']; |
| 1330 | } |
| 1331 | } |
| 1332 | } |
| 1333 | |
| 1334 | return false; |
| 1335 | } |
| 1336 | |
| 1337 | /** |
| 1338 | * Get all the email fields of a Form. |
| 1339 | * |
| 1340 | * @param int $form_id |
| 1341 | */ |
| 1342 | function evf_get_all_email_fields_by_form_id( $form_id ) { |
| 1343 | $user_emails = array(); |
| 1344 | $form_obj = EVF()->form->get( $form_id ); |
| 1345 | $form_data = ! empty( $form_obj->post_content ) ? evf_decode( $form_obj->post_content ) : ''; |
| 1346 | |
| 1347 | if ( ! empty( $form_data['form_fields'] ) ) { |
| 1348 | foreach ( $form_data['form_fields'] as $form_fields ) { |
| 1349 | if ( 'email' === $form_fields['type'] ) { |
| 1350 | $user_emails[ $form_fields['meta-key'] ] = $form_fields['label']; |
| 1351 | } |
| 1352 | } |
| 1353 | } |
| 1354 | |
| 1355 | return $user_emails; |
| 1356 | } |
| 1357 | |
| 1358 | /** |
| 1359 | * Get all the field's meta-key label pair. |
| 1360 | * |
| 1361 | * @param int $form_id |
| 1362 | * @return array |
| 1363 | */ |
| 1364 | function evf_get_all_form_fields_by_form_id( $form_id ) { |
| 1365 | $data = array(); |
| 1366 | $form_obj = EVF()->form->get( $form_id ); |
| 1367 | $form_data = ! empty( $form_obj->post_content ) ? evf_decode( $form_obj->post_content ) : ''; |
| 1368 | |
| 1369 | if ( ! empty( $form_data['form_fields'] ) ) { |
| 1370 | foreach ( $form_data['form_fields'] as $form_fields ) { |
| 1371 | if ( isset( $form_fields['meta-key'], $form_fields['label'] ) ) { |
| 1372 | $data[ $form_fields['meta-key'] ] = $form_fields['label']; |
| 1373 | } |
| 1374 | } |
| 1375 | } |
| 1376 | |
| 1377 | return $data; |
| 1378 | } |
| 1379 | |
| 1380 | /** |
| 1381 | * Check if the string JSON. |
| 1382 | * |
| 1383 | * @param string $string |
| 1384 | * @return bool |
| 1385 | */ |
| 1386 | function evf_isJson( $string ) { |
| 1387 | json_decode( $string ); |
| 1388 | return ( json_last_error() == JSON_ERROR_NONE ); |
| 1389 | } |
| 1390 | |
| 1391 | /** |
| 1392 | * Checks whether the content passed contains a specific short code. |
| 1393 | * |
| 1394 | * @since 1.1.4 |
| 1395 | * @param string $tag Shortcode tag to check. |
| 1396 | * @return bool |
| 1397 | */ |
| 1398 | function evf_post_content_has_shortcode( $tag = '' ) { |
| 1399 | global $post; |
| 1400 | |
| 1401 | return is_singular() && is_a( $post, 'WP_Post' ) && has_shortcode( $post->post_content, $tag ); |
| 1402 | } |
| 1403 | |
| 1404 | /** |
| 1405 | * Convert a file size provided, such as "2M", to bytes. |
| 1406 | * |
| 1407 | * @since 1.2.0 |
| 1408 | * @link http://stackoverflow.com/a/22500394 |
| 1409 | * |
| 1410 | * @param string $size |
| 1411 | * |
| 1412 | * @return int |
| 1413 | */ |
| 1414 | function evf_size_to_bytes( $size ) { |
| 1415 | |
| 1416 | if ( is_numeric( $size ) ) { |
| 1417 | return $size; |
| 1418 | } |
| 1419 | |
| 1420 | $suffix = substr( $size, - 1 ); |
| 1421 | $value = substr( $size, 0, - 1 ); |
| 1422 | |
| 1423 | switch ( strtoupper( $suffix ) ) { |
| 1424 | case 'P': |
| 1425 | $value *= 1024; |
| 1426 | case 'T': |
| 1427 | $value *= 1024; |
| 1428 | case 'G': |
| 1429 | $value *= 1024; |
| 1430 | case 'M': |
| 1431 | $value *= 1024; |
| 1432 | case 'K': |
| 1433 | $value *= 1024; |
| 1434 | break; |
| 1435 | } |
| 1436 | |
| 1437 | return $value; |
| 1438 | } |
| 1439 | |
| 1440 | /** |
| 1441 | * Convert bytes to megabytes (or in some cases KB). |
| 1442 | * |
| 1443 | * @since 1.2.0 |
| 1444 | * |
| 1445 | * @param int $bytes |
| 1446 | * |
| 1447 | * @return string |
| 1448 | */ |
| 1449 | function evf_size_to_megabytes( $bytes ) { |
| 1450 | |
| 1451 | if ( $bytes < 1048676 ) { |
| 1452 | return number_format( $bytes / 1024, 1 ) . ' KB'; |
| 1453 | } else { |
| 1454 | return round( number_format( $bytes / 1048576, 1 ) ) . ' MB'; |
| 1455 | } |
| 1456 | } |
| 1457 | |
| 1458 | /** |
| 1459 | * Convert a file size provided, such as "2M", to bytes. |
| 1460 | * |
| 1461 | * @since 1.2.0 |
| 1462 | * @link http://stackoverflow.com/a/22500394 |
| 1463 | * |
| 1464 | * @param bool $bytes |
| 1465 | * @return mixed |
| 1466 | */ |
| 1467 | function evf_max_upload( $bytes = false ) { |
| 1468 | $max = wp_max_upload_size(); |
| 1469 | |
| 1470 | if ( $bytes ) { |
| 1471 | return $max; |
| 1472 | } else { |
| 1473 | return evf_size_to_megabytes( $max ); |
| 1474 | } |
| 1475 | } |
| 1476 | |
| 1477 | /** |
| 1478 | * Get the required label text, with a filter. |
| 1479 | * |
| 1480 | * @since 1.2.0 |
| 1481 | * @return string |
| 1482 | */ |
| 1483 | function evf_get_required_label() { |
| 1484 | return apply_filters( 'everest_forms_required_label', esc_html__( 'This field is required.', 'everest-forms' ) ); |
| 1485 | } |
| 1486 | |
| 1487 | /** |
| 1488 | * Get a PRO license plan. |
| 1489 | * |
| 1490 | * @since 1.2.0 |
| 1491 | * @return bool|string Plan on success, false on failure. |
| 1492 | */ |
| 1493 | function evf_get_license_plan() { |
| 1494 | $license_key = get_option( 'everest-forms-pro_license_key' ); |
| 1495 | |
| 1496 | if ( $license_key && is_plugin_active( 'everest-forms-pro/everest-forms-pro.php' ) ) { |
| 1497 | $license_data = get_transient( 'evf_pro_license_plan' ); |
| 1498 | |
| 1499 | if ( false === $license_data ) { |
| 1500 | $license_data = json_decode( |
| 1501 | EVF_Updater_Key_API::check( |
| 1502 | array( |
| 1503 | 'license' => $license_key, |
| 1504 | ) |
| 1505 | ) |
| 1506 | ); |
| 1507 | |
| 1508 | if ( ! empty( $license_data->item_plan ) ) { |
| 1509 | set_transient( 'evf_pro_license_plan', $license_data, WEEK_IN_SECONDS ); |
| 1510 | } |
| 1511 | } |
| 1512 | |
| 1513 | return isset( $license_data->item_plan ) ? $license_data->item_plan : false; |
| 1514 | } |
| 1515 | |
| 1516 | return false; |
| 1517 | } |
| 1518 | |
| 1519 | /** |
| 1520 | * Decode special characters, both alpha- (<) and numeric-based ('). |
| 1521 | * |
| 1522 | * @since 1.2.0 |
| 1523 | * @param string $string |
| 1524 | * @return string |
| 1525 | */ |
| 1526 | function evf_decode_string( $string ) { |
| 1527 | if ( ! is_string( $string ) ) { |
| 1528 | return $string; |
| 1529 | } |
| 1530 | |
| 1531 | return wp_kses_decode_entities( html_entity_decode( $string, ENT_QUOTES ) ); |
| 1532 | } |
| 1533 | add_filter( 'everest_forms_email_message', 'evf_decode_string' ); |
| 1534 | |
| 1535 | /** |
| 1536 | * Get Countries. |
| 1537 | * |
| 1538 | * @since 1.2.0 |
| 1539 | * @return array |
| 1540 | */ |
| 1541 | function evf_get_countries() { |
| 1542 | $countries = array( |
| 1543 | 'AF' => esc_html__( 'Afghanistan', 'everest-forms' ), |
| 1544 | 'AX' => esc_html__( '� |
| 1545 | land Islands', 'everest-forms' ), |
| 1546 | 'AL' => esc_html__( 'Albania', 'everest-forms' ), |
| 1547 | 'DZ' => esc_html__( 'Algeria', 'everest-forms' ), |
| 1548 | 'AS' => esc_html__( 'American Samoa', 'everest-forms' ), |
| 1549 | 'AD' => esc_html__( 'Andorra', 'everest-forms' ), |
| 1550 | 'AO' => esc_html__( 'Angola', 'everest-forms' ), |
| 1551 | 'AI' => esc_html__( 'Anguilla', 'everest-forms' ), |
| 1552 | 'AQ' => esc_html__( 'Antarctica', 'everest-forms' ), |
| 1553 | 'AG' => esc_html__( 'Antigua and Barbuda', 'everest-forms' ), |
| 1554 | 'AR' => esc_html__( 'Argentina', 'everest-forms' ), |
| 1555 | 'AM' => esc_html__( 'Armenia', 'everest-forms' ), |
| 1556 | 'AW' => esc_html__( 'Aruba', 'everest-forms' ), |
| 1557 | 'AU' => esc_html__( 'Australia', 'everest-forms' ), |
| 1558 | 'AT' => esc_html__( 'Austria', 'everest-forms' ), |
| 1559 | 'AZ' => esc_html__( 'Azerbaijan', 'everest-forms' ), |
| 1560 | 'BS' => esc_html__( 'Bahamas', 'everest-forms' ), |
| 1561 | 'BH' => esc_html__( 'Bahrain', 'everest-forms' ), |
| 1562 | 'BD' => esc_html__( 'Bangladesh', 'everest-forms' ), |
| 1563 | 'BB' => esc_html__( 'Barbados', 'everest-forms' ), |
| 1564 | 'BY' => esc_html__( 'Belarus', 'everest-forms' ), |
| 1565 | 'BE' => esc_html__( 'Belgium', 'everest-forms' ), |
| 1566 | 'BZ' => esc_html__( 'Belize', 'everest-forms' ), |
| 1567 | 'BJ' => esc_html__( 'Benin', 'everest-forms' ), |
| 1568 | 'BM' => esc_html__( 'Bermuda', 'everest-forms' ), |
| 1569 | 'BT' => esc_html__( 'Bhutan', 'everest-forms' ), |
| 1570 | 'BO' => esc_html__( 'Bolivia (Plurinational State of)', 'everest-forms' ), |
| 1571 | 'BA' => esc_html__( 'Bosnia and Herzegovina', 'everest-forms' ), |
| 1572 | 'BW' => esc_html__( 'Botswana', 'everest-forms' ), |
| 1573 | 'BV' => esc_html__( 'Bouvet Island', 'everest-forms' ), |
| 1574 | 'BR' => esc_html__( 'Brazil', 'everest-forms' ), |
| 1575 | 'IO' => esc_html__( 'British Indian Ocean Territory', 'everest-forms' ), |
| 1576 | 'BN' => esc_html__( 'Brunei Darussalam', 'everest-forms' ), |
| 1577 | 'BG' => esc_html__( 'Bulgaria', 'everest-forms' ), |
| 1578 | 'BF' => esc_html__( 'Burkina Faso', 'everest-forms' ), |
| 1579 | 'BI' => esc_html__( 'Burundi', 'everest-forms' ), |
| 1580 | 'CV' => esc_html__( 'Cabo Verde', 'everest-forms' ), |
| 1581 | 'KH' => esc_html__( 'Cambodia', 'everest-forms' ), |
| 1582 | 'CM' => esc_html__( 'Cameroon', 'everest-forms' ), |
| 1583 | 'CA' => esc_html__( 'Canada', 'everest-forms' ), |
| 1584 | 'KY' => esc_html__( 'Cayman Islands', 'everest-forms' ), |
| 1585 | 'CF' => esc_html__( 'Central African Republic', 'everest-forms' ), |
| 1586 | 'TD' => esc_html__( 'Chad', 'everest-forms' ), |
| 1587 | 'CL' => esc_html__( 'Chile', 'everest-forms' ), |
| 1588 | 'CN' => esc_html__( 'China', 'everest-forms' ), |
| 1589 | 'CX' => esc_html__( 'Christmas Island', 'everest-forms' ), |
| 1590 | 'CC' => esc_html__( 'Cocos (Keeling) Islands', 'everest-forms' ), |
| 1591 | 'CO' => esc_html__( 'Colombia', 'everest-forms' ), |
| 1592 | 'KM' => esc_html__( 'Comoros', 'everest-forms' ), |
| 1593 | 'CG' => esc_html__( 'Congo', 'everest-forms' ), |
| 1594 | 'CD' => esc_html__( 'Congo (Democratic Republic of the)', 'everest-forms' ), |
| 1595 | 'CK' => esc_html__( 'Cook Islands', 'everest-forms' ), |
| 1596 | 'CR' => esc_html__( 'Costa Rica', 'everest-forms' ), |
| 1597 | 'CI' => esc_html__( 'Côte d\'Ivoire', 'everest-forms' ), |
| 1598 | 'HR' => esc_html__( 'Croatia', 'everest-forms' ), |
| 1599 | 'CU' => esc_html__( 'Cuba', 'everest-forms' ), |
| 1600 | 'CW' => esc_html__( 'Curaçao', 'everest-forms' ), |
| 1601 | 'CY' => esc_html__( 'Cyprus', 'everest-forms' ), |
| 1602 | 'CZ' => esc_html__( 'Czech Republic', 'everest-forms' ), |
| 1603 | 'DK' => esc_html__( 'Denmark', 'everest-forms' ), |
| 1604 | 'DJ' => esc_html__( 'Djibouti', 'everest-forms' ), |
| 1605 | 'DM' => esc_html__( 'Dominica', 'everest-forms' ), |
| 1606 | 'DO' => esc_html__( 'Dominican Republic', 'everest-forms' ), |
| 1607 | 'EC' => esc_html__( 'Ecuador', 'everest-forms' ), |
| 1608 | 'EG' => esc_html__( 'Egypt', 'everest-forms' ), |
| 1609 | 'SV' => esc_html__( 'El Salvador', 'everest-forms' ), |
| 1610 | 'GQ' => esc_html__( 'Equatorial Guinea', 'everest-forms' ), |
| 1611 | 'ER' => esc_html__( 'Eritrea', 'everest-forms' ), |
| 1612 | 'EE' => esc_html__( 'Estonia', 'everest-forms' ), |
| 1613 | 'ET' => esc_html__( 'Ethiopia', 'everest-forms' ), |
| 1614 | 'FK' => esc_html__( 'Falkland Islands (Malvinas)', 'everest-forms' ), |
| 1615 | 'FO' => esc_html__( 'Faroe Islands', 'everest-forms' ), |
| 1616 | 'FJ' => esc_html__( 'Fiji', 'everest-forms' ), |
| 1617 | 'FI' => esc_html__( 'Finland', 'everest-forms' ), |
| 1618 | 'FR' => esc_html__( 'France', 'everest-forms' ), |
| 1619 | 'GF' => esc_html__( 'French Guiana', 'everest-forms' ), |
| 1620 | 'PF' => esc_html__( 'French Polynesia', 'everest-forms' ), |
| 1621 | 'TF' => esc_html__( 'French Southern Territories', 'everest-forms' ), |
| 1622 | 'GA' => esc_html__( 'Gabon', 'everest-forms' ), |
| 1623 | 'GM' => esc_html__( 'Gambia', 'everest-forms' ), |
| 1624 | 'GE' => esc_html_x( 'Georgia', 'Country', 'everest-forms' ), |
| 1625 | 'DE' => esc_html__( 'Germany', 'everest-forms' ), |
| 1626 | 'GH' => esc_html__( 'Ghana', 'everest-forms' ), |
| 1627 | 'GI' => esc_html__( 'Gibraltar', 'everest-forms' ), |
| 1628 | 'GR' => esc_html__( 'Greece', 'everest-forms' ), |
| 1629 | 'GL' => esc_html__( 'Greenland', 'everest-forms' ), |
| 1630 | 'GD' => esc_html__( 'Grenada', 'everest-forms' ), |
| 1631 | 'GP' => esc_html__( 'Guadeloupe', 'everest-forms' ), |
| 1632 | 'GU' => esc_html__( 'Guam', 'everest-forms' ), |
| 1633 | 'GT' => esc_html__( 'Guatemala', 'everest-forms' ), |
| 1634 | 'GG' => esc_html__( 'Guernsey', 'everest-forms' ), |
| 1635 | 'GN' => esc_html__( 'Guinea', 'everest-forms' ), |
| 1636 | 'GW' => esc_html__( 'Guinea-Bissau', 'everest-forms' ), |
| 1637 | 'GY' => esc_html__( 'Guyana', 'everest-forms' ), |
| 1638 | 'HT' => esc_html__( 'Haiti', 'everest-forms' ), |
| 1639 | 'HM' => esc_html__( 'Heard Island and McDonald Islands', 'everest-forms' ), |
| 1640 | 'HN' => esc_html__( 'Honduras', 'everest-forms' ), |
| 1641 | 'HK' => esc_html__( 'Hong Kong', 'everest-forms' ), |
| 1642 | 'HU' => esc_html__( 'Hungary', 'everest-forms' ), |
| 1643 | 'IS' => esc_html__( 'Iceland', 'everest-forms' ), |
| 1644 | 'IN' => esc_html__( 'India', 'everest-forms' ), |
| 1645 | 'ID' => esc_html__( 'Indonesia', 'everest-forms' ), |
| 1646 | 'IR' => esc_html__( 'Iran (Islamic Republic of)', 'everest-forms' ), |
| 1647 | 'IQ' => esc_html__( 'Iraq', 'everest-forms' ), |
| 1648 | 'IE' => esc_html__( 'Ireland (Republic of)', 'everest-forms' ), |
| 1649 | 'IM' => esc_html__( 'Isle of Man', 'everest-forms' ), |
| 1650 | 'IL' => esc_html__( 'Israel', 'everest-forms' ), |
| 1651 | 'IT' => esc_html__( 'Italy', 'everest-forms' ), |
| 1652 | 'JM' => esc_html__( 'Jamaica', 'everest-forms' ), |
| 1653 | 'JP' => esc_html__( 'Japan', 'everest-forms' ), |
| 1654 | 'JE' => esc_html__( 'Jersey', 'everest-forms' ), |
| 1655 | 'JO' => esc_html__( 'Jordan', 'everest-forms' ), |
| 1656 | 'KZ' => esc_html__( 'Kazakhstan', 'everest-forms' ), |
| 1657 | 'KE' => esc_html__( 'Kenya', 'everest-forms' ), |
| 1658 | 'KI' => esc_html__( 'Kiribati', 'everest-forms' ), |
| 1659 | 'KP' => esc_html__( 'Korea (Democratic People\'s Republic of)', 'everest-forms' ), |
| 1660 | 'KR' => esc_html__( 'Korea (Republic of)', 'everest-forms' ), |
| 1661 | 'KW' => esc_html__( 'Kuwait', 'everest-forms' ), |
| 1662 | 'KG' => esc_html__( 'Kyrgyzstan', 'everest-forms' ), |
| 1663 | 'LA' => esc_html__( 'Lao People\'s Democratic Republic', 'everest-forms' ), |
| 1664 | 'LV' => esc_html__( 'Latvia', 'everest-forms' ), |
| 1665 | 'LB' => esc_html__( 'Lebanon', 'everest-forms' ), |
| 1666 | 'LS' => esc_html__( 'Lesotho', 'everest-forms' ), |
| 1667 | 'LR' => esc_html__( 'Liberia', 'everest-forms' ), |
| 1668 | 'LY' => esc_html__( 'Libya', 'everest-forms' ), |
| 1669 | 'LI' => esc_html__( 'Liechtenstein', 'everest-forms' ), |
| 1670 | 'LT' => esc_html__( 'Lithuania', 'everest-forms' ), |
| 1671 | 'LU' => esc_html__( 'Luxembourg', 'everest-forms' ), |
| 1672 | 'MO' => esc_html__( 'Macao', 'everest-forms' ), |
| 1673 | 'MK' => esc_html__( 'Macedonia (Republic of)', 'everest-forms' ), |
| 1674 | 'MG' => esc_html__( 'Madagascar', 'everest-forms' ), |
| 1675 | 'MW' => esc_html__( 'Malawi', 'everest-forms' ), |
| 1676 | 'MY' => esc_html__( 'Malaysia', 'everest-forms' ), |
| 1677 | 'MV' => esc_html__( 'Maldives', 'everest-forms' ), |
| 1678 | 'ML' => esc_html__( 'Mali', 'everest-forms' ), |
| 1679 | 'MT' => esc_html__( 'Malta', 'everest-forms' ), |
| 1680 | 'MH' => esc_html__( 'Marshall Islands', 'everest-forms' ), |
| 1681 | 'MQ' => esc_html__( 'Martinique', 'everest-forms' ), |
| 1682 | 'MR' => esc_html__( 'Mauritania', 'everest-forms' ), |
| 1683 | 'MU' => esc_html__( 'Mauritius', 'everest-forms' ), |
| 1684 | 'YT' => esc_html__( 'Mayotte', 'everest-forms' ), |
| 1685 | 'MX' => esc_html__( 'Mexico', 'everest-forms' ), |
| 1686 | 'FM' => esc_html__( 'Micronesia (Federated States of)', 'everest-forms' ), |
| 1687 | 'MD' => esc_html__( 'Moldova (Republic of)', 'everest-forms' ), |
| 1688 | 'MC' => esc_html__( 'Monaco', 'everest-forms' ), |
| 1689 | 'MN' => esc_html__( 'Mongolia', 'everest-forms' ), |
| 1690 | 'ME' => esc_html__( 'Montenegro', 'everest-forms' ), |
| 1691 | 'MS' => esc_html__( 'Montserrat', 'everest-forms' ), |
| 1692 | 'MA' => esc_html__( 'Morocco', 'everest-forms' ), |
| 1693 | 'MZ' => esc_html__( 'Mozambique', 'everest-forms' ), |
| 1694 | 'MM' => esc_html__( 'Myanmar', 'everest-forms' ), |
| 1695 | 'NA' => esc_html__( 'Namibia', 'everest-forms' ), |
| 1696 | 'NR' => esc_html__( 'Nauru', 'everest-forms' ), |
| 1697 | 'NP' => esc_html__( 'Nepal', 'everest-forms' ), |
| 1698 | 'NL' => esc_html__( 'Netherlands', 'everest-forms' ), |
| 1699 | 'NC' => esc_html__( 'New Caledonia', 'everest-forms' ), |
| 1700 | 'NZ' => esc_html__( 'New Zealand', 'everest-forms' ), |
| 1701 | 'NI' => esc_html__( 'Nicaragua', 'everest-forms' ), |
| 1702 | 'NE' => esc_html__( 'Niger', 'everest-forms' ), |
| 1703 | 'NG' => esc_html__( 'Nigeria', 'everest-forms' ), |
| 1704 | 'NU' => esc_html__( 'Niue', 'everest-forms' ), |
| 1705 | 'NF' => esc_html__( 'Norfolk Island', 'everest-forms' ), |
| 1706 | 'MP' => esc_html__( 'Northern Mariana Islands', 'everest-forms' ), |
| 1707 | 'NO' => esc_html__( 'Norway', 'everest-forms' ), |
| 1708 | 'OM' => esc_html__( 'Oman', 'everest-forms' ), |
| 1709 | 'PK' => esc_html__( 'Pakistan', 'everest-forms' ), |
| 1710 | 'PW' => esc_html__( 'Palau', 'everest-forms' ), |
| 1711 | 'PS' => esc_html__( 'Palestine (State of)', 'everest-forms' ), |
| 1712 | 'PA' => esc_html__( 'Panama', 'everest-forms' ), |
| 1713 | 'PG' => esc_html__( 'Papua New Guinea', 'everest-forms' ), |
| 1714 | 'PY' => esc_html__( 'Paraguay', 'everest-forms' ), |
| 1715 | 'PE' => esc_html__( 'Peru', 'everest-forms' ), |
| 1716 | 'PH' => esc_html__( 'Philippines', 'everest-forms' ), |
| 1717 | 'PN' => esc_html__( 'Pitcairn', 'everest-forms' ), |
| 1718 | 'PL' => esc_html__( 'Poland', 'everest-forms' ), |
| 1719 | 'PT' => esc_html__( 'Portugal', 'everest-forms' ), |
| 1720 | 'PR' => esc_html__( 'Puerto Rico', 'everest-forms' ), |
| 1721 | 'QA' => esc_html__( 'Qatar', 'everest-forms' ), |
| 1722 | 'RE' => esc_html__( 'Réunion', 'everest-forms' ), |
| 1723 | 'RO' => esc_html__( 'Romania', 'everest-forms' ), |
| 1724 | 'RU' => esc_html__( 'Russian Federation', 'everest-forms' ), |
| 1725 | 'RW' => esc_html__( 'Rwanda', 'everest-forms' ), |
| 1726 | 'BL' => esc_html__( 'Saint Barthélemy', 'everest-forms' ), |
| 1727 | 'SH' => esc_html__( 'Saint Helena, Ascension and Tristan da Cunha', 'everest-forms' ), |
| 1728 | 'KN' => esc_html__( 'Saint Kitts and Nevis', 'everest-forms' ), |
| 1729 | 'LC' => esc_html__( 'Saint Lucia', 'everest-forms' ), |
| 1730 | 'MF' => esc_html__( 'Saint Martin (French part)', 'everest-forms' ), |
| 1731 | 'PM' => esc_html__( 'Saint Pierre and Miquelon', 'everest-forms' ), |
| 1732 | 'VC' => esc_html__( 'Saint Vincent and the Grenadines', 'everest-forms' ), |
| 1733 | 'WS' => esc_html__( 'Samoa', 'everest-forms' ), |
| 1734 | 'SM' => esc_html__( 'San Marino', 'everest-forms' ), |
| 1735 | 'ST' => esc_html__( 'Sao Tome and Principe', 'everest-forms' ), |
| 1736 | 'SA' => esc_html__( 'Saudi Arabia', 'everest-forms' ), |
| 1737 | 'SN' => esc_html__( 'Senegal', 'everest-forms' ), |
| 1738 | 'RS' => esc_html__( 'Serbia', 'everest-forms' ), |
| 1739 | 'SC' => esc_html__( 'Seychelles', 'everest-forms' ), |
| 1740 | 'SL' => esc_html__( 'Sierra Leone', 'everest-forms' ), |
| 1741 | 'SG' => esc_html__( 'Singapore', 'everest-forms' ), |
| 1742 | 'SX' => esc_html__( 'Sint Maarten (Dutch part)', 'everest-forms' ), |
| 1743 | 'SK' => esc_html__( 'Slovakia', 'everest-forms' ), |
| 1744 | 'SI' => esc_html__( 'Slovenia', 'everest-forms' ), |
| 1745 | 'SB' => esc_html__( 'Solomon Islands', 'everest-forms' ), |
| 1746 | 'SO' => esc_html__( 'Somalia', 'everest-forms' ), |
| 1747 | 'ZA' => esc_html__( 'South Africa', 'everest-forms' ), |
| 1748 | 'GS' => esc_html__( 'South Georgia and the South Sandwich Islands', 'everest-forms' ), |
| 1749 | 'SS' => esc_html__( 'South Sudan', 'everest-forms' ), |
| 1750 | 'ES' => esc_html__( 'Spain', 'everest-forms' ), |
| 1751 | 'LK' => esc_html__( 'Sri Lanka', 'everest-forms' ), |
| 1752 | 'SD' => esc_html__( 'Sudan', 'everest-forms' ), |
| 1753 | 'SR' => esc_html__( 'Suriname', 'everest-forms' ), |
| 1754 | 'SJ' => esc_html__( 'Svalbard and Jan Mayen', 'everest-forms' ), |
| 1755 | 'SZ' => esc_html__( 'Swaziland', 'everest-forms' ), |
| 1756 | 'SE' => esc_html__( 'Sweden', 'everest-forms' ), |
| 1757 | 'CH' => esc_html__( 'Switzerland', 'everest-forms' ), |
| 1758 | 'SY' => esc_html__( 'Syrian Arab Republic', 'everest-forms' ), |
| 1759 | 'TW' => esc_html__( 'Taiwan, Province of China', 'everest-forms' ), |
| 1760 | 'TJ' => esc_html__( 'Tajikistan', 'everest-forms' ), |
| 1761 | 'TZ' => esc_html__( 'Tanzania (United Republic of)', 'everest-forms' ), |
| 1762 | 'TH' => esc_html__( 'Thailand', 'everest-forms' ), |
| 1763 | 'TL' => esc_html__( 'Timor-Leste', 'everest-forms' ), |
| 1764 | 'TG' => esc_html__( 'Togo', 'everest-forms' ), |
| 1765 | 'TK' => esc_html__( 'Tokelau', 'everest-forms' ), |
| 1766 | 'TO' => esc_html__( 'Tonga', 'everest-forms' ), |
| 1767 | 'TT' => esc_html__( 'Trinidad and Tobago', 'everest-forms' ), |
| 1768 | 'TN' => esc_html__( 'Tunisia', 'everest-forms' ), |
| 1769 | 'TR' => esc_html__( 'Turkey', 'everest-forms' ), |
| 1770 | 'TM' => esc_html__( 'Turkmenistan', 'everest-forms' ), |
| 1771 | 'TC' => esc_html__( 'Turks and Caicos Islands', 'everest-forms' ), |
| 1772 | 'TV' => esc_html__( 'Tuvalu', 'everest-forms' ), |
| 1773 | 'UG' => esc_html__( 'Uganda', 'everest-forms' ), |
| 1774 | 'UA' => esc_html__( 'Ukraine', 'everest-forms' ), |
| 1775 | 'AE' => esc_html__( 'United Arab Emirates', 'everest-forms' ), |
| 1776 | 'GB' => esc_html__( 'United Kingdom of Great Britain and Northern Ireland', 'everest-forms' ), |
| 1777 | 'US' => esc_html__( 'United States of America', 'everest-forms' ), |
| 1778 | 'UM' => esc_html__( 'United States Minor Outlying Islands', 'everest-forms' ), |
| 1779 | 'UY' => esc_html__( 'Uruguay', 'everest-forms' ), |
| 1780 | 'UZ' => esc_html__( 'Uzbekistan', 'everest-forms' ), |
| 1781 | 'VU' => esc_html__( 'Vanuatu', 'everest-forms' ), |
| 1782 | 'VA' => esc_html__( 'Vatican City State', 'everest-forms' ), |
| 1783 | 'VE' => esc_html__( 'Venezuela (Bolivarian Republic of)', 'everest-forms' ), |
| 1784 | 'VN' => esc_html__( 'Viet Nam', 'everest-forms' ), |
| 1785 | 'VG' => esc_html__( 'Virgin Islands (British)', 'everest-forms' ), |
| 1786 | 'VI' => esc_html__( 'Virgin Islands (U.S.)', 'everest-forms' ), |
| 1787 | 'WF' => esc_html__( 'Wallis and Futuna', 'everest-forms' ), |
| 1788 | 'EH' => esc_html__( 'Western Sahara', 'everest-forms' ), |
| 1789 | 'YE' => esc_html__( 'Yemen', 'everest-forms' ), |
| 1790 | 'ZM' => esc_html__( 'Zambia', 'everest-forms' ), |
| 1791 | 'ZW' => esc_html__( 'Zimbabwe', 'everest-forms' ), |
| 1792 | ); |
| 1793 | |
| 1794 | return (array) apply_filters( 'everest_forms_countries', $countries ); |
| 1795 | } |
| 1796 | |
| 1797 | /** |
| 1798 | * Get builder fields groups. |
| 1799 | * |
| 1800 | * @return array |
| 1801 | */ |
| 1802 | function evf_get_fields_groups() { |
| 1803 | return (array) apply_filters( |
| 1804 | 'everest_forms_builder_fields_groups', |
| 1805 | array( |
| 1806 | 'general' => __( 'General Fields', 'everest-forms' ), |
| 1807 | 'advanced' => __( 'Advanced Fields', 'everest-forms' ), |
| 1808 | 'payment' => __( 'Payment Fields', 'everest-forms' ), |
| 1809 | 'survey' => __( 'Survey Fields', 'everest-forms' ), |
| 1810 | ) |
| 1811 | ); |
| 1812 | } |
| 1813 | |
| 1814 | /** |
| 1815 | * Get a builder fields type's name. |
| 1816 | * |
| 1817 | * @param string $type Coupon type. |
| 1818 | * @return string |
| 1819 | */ |
| 1820 | function evf_get_fields_group( $type = '' ) { |
| 1821 | $types = evf_get_fields_groups(); |
| 1822 | return isset( $types[ $type ] ) ? $types[ $type ] : ''; |
| 1823 | } |
| 1824 | |
| 1825 | /** |
| 1826 | * Get all fields settings. |
| 1827 | * |
| 1828 | * @return array Settings data. |
| 1829 | */ |
| 1830 | function evf_get_all_fields_settings() { |
| 1831 | $settings = array( |
| 1832 | 'label' => array( |
| 1833 | 'id' => 'label', |
| 1834 | 'title' => __( 'Label', 'everest-forms' ), |
| 1835 | 'desc' => __( 'Enter text for the form field label. This is recommended and can be hidden in the Advanced Settings.', 'everest-forms' ), |
| 1836 | 'default' => '', |
| 1837 | 'type' => 'text', |
| 1838 | 'desc_tip' => true, |
| 1839 | ), |
| 1840 | 'meta' => array( |
| 1841 | 'id' => 'meta-key', |
| 1842 | 'title' => __( 'Meta Key', 'everest-forms' ), |
| 1843 | 'desc' => __( 'Enter meta key to be stored in database.', 'everest-forms' ), |
| 1844 | 'default' => '', |
| 1845 | 'type' => 'text', |
| 1846 | 'desc_tip' => true, |
| 1847 | ), |
| 1848 | 'description' => array( |
| 1849 | 'id' => 'description', |
| 1850 | 'title' => __( 'Description', 'everest-forms' ), |
| 1851 | 'type' => 'textarea', |
| 1852 | 'desc' => __( 'Enter text for the form field description.', 'everest-forms' ), |
| 1853 | 'default' => '', |
| 1854 | 'desc_tip' => true, |
| 1855 | ), |
| 1856 | 'required' => array( |
| 1857 | 'id' => 'require', |
| 1858 | 'title' => __( 'Required', 'everest-forms' ), |
| 1859 | 'type' => 'checkbox', |
| 1860 | 'desc' => __( 'Check this option to mark the field required.', 'everest-forms' ), |
| 1861 | 'default' => 'no', |
| 1862 | 'desc_tip' => true, |
| 1863 | ), |
| 1864 | 'choices' => array( |
| 1865 | 'id' => 'choices', |
| 1866 | 'title' => __( 'Choices', 'everest-forms' ), |
| 1867 | 'desc' => __( 'Add choices for the form field.', 'everest-forms' ), |
| 1868 | 'type' => 'choices', |
| 1869 | 'desc_tip' => true, |
| 1870 | 'defaults' => array( |
| 1871 | 1 => __( 'First Choice', 'everest-forms' ), |
| 1872 | 2 => __( 'Second Choice', 'everest-forms' ), |
| 1873 | 3 => __( 'Third Choice', 'everest-forms' ), |
| 1874 | ), |
| 1875 | ), |
| 1876 | 'placeholder' => array( |
| 1877 | 'id' => 'placeholder', |
| 1878 | 'title' => __( 'Placeholder Text', 'everest-forms' ), |
| 1879 | 'desc' => __( 'Enter text for the form field placeholder.', 'everest-forms' ), |
| 1880 | 'default' => '', |
| 1881 | 'type' => 'text', |
| 1882 | 'desc_tip' => true, |
| 1883 | ), |
| 1884 | 'css' => array( |
| 1885 | 'id' => 'css', |
| 1886 | 'title' => __( 'CSS Classes', 'everest-forms' ), |
| 1887 | 'desc' => __( 'Enter CSS class for this field container. Class names should be separated with spaces.', 'everest-forms' ), |
| 1888 | 'default' => '', |
| 1889 | 'type' => 'text', |
| 1890 | 'desc_tip' => true, |
| 1891 | ), |
| 1892 | 'label_hide' => array( |
| 1893 | 'id' => 'label_hide', |
| 1894 | 'title' => __( 'Hide Label', 'everest-forms' ), |
| 1895 | 'type' => 'checkbox', |
| 1896 | 'desc' => __( 'Check this option to hide the form field label.', 'everest-forms' ), |
| 1897 | 'default' => 'no', |
| 1898 | 'desc_tip' => true, |
| 1899 | ), |
| 1900 | 'sublabel_hide' => array( |
| 1901 | 'id' => 'sublabel_hide', |
| 1902 | 'title' => __( 'Hide Sub-Labels', 'everest-forms' ), |
| 1903 | 'type' => 'checkbox', |
| 1904 | 'desc' => __( 'Check this option to hide the form field sub-label.', 'everest-forms' ), |
| 1905 | 'default' => 'no', |
| 1906 | 'desc_tip' => true, |
| 1907 | ), |
| 1908 | ); |
| 1909 | |
| 1910 | return apply_filters( 'everest_form_all_fields_settings', $settings ); |
| 1911 | } |
| 1912 | |
| 1913 | /** |
| 1914 | * Checks if date field exists in the form. |
| 1915 | * |
| 1916 | * @since 1.4.2 |
| 1917 | * @param int $form_id Form ID. |
| 1918 | * @return bool |
| 1919 | */ |
| 1920 | function evf_has_date_field( $form_id ) { |
| 1921 | $form_obj = EVF()->form->get( $form_id ); |
| 1922 | $form_data = ! empty( $form_obj->post_content ) ? evf_decode( $form_obj->post_content ) : ''; |
| 1923 | |
| 1924 | if ( ! empty( $form_data['form_fields'] ) ) { |
| 1925 | foreach ( $form_data['form_fields'] as $form_field ) { |
| 1926 | if ( 'date-time' === $form_field['type'] ) { |
| 1927 | return true; |
| 1928 | } |
| 1929 | } |
| 1930 | } |
| 1931 | |
| 1932 | return false; |
| 1933 | } |
| 1934 | |
| 1935 | /** |
| 1936 | * Helper function to display debug data. |
| 1937 | * |
| 1938 | * @since 1.3.2 |
| 1939 | * |
| 1940 | * @param mixed $expression The expression to be printed. |
| 1941 | * @param bool $return Optional. Default false. Set to true to return the human-readable string. |
| 1942 | * |
| 1943 | * @return string |
| 1944 | */ |
| 1945 | function evf_debug_data( $expression, $return = false ) { |
| 1946 | if ( defined( 'EVF_DEBUG' ) && true === EVF_DEBUG ) { |
| 1947 | $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>'; |
| 1948 | |
| 1949 | $output .= "==================== Everest Forms Debugging ====================\n\n"; |
| 1950 | |
| 1951 | if ( is_array( $expression ) || is_object( $expression ) ) { |
| 1952 | $output .= evf_print_r( $expression, true ); |
| 1953 | } else { |
| 1954 | $output .= $expression; |
| 1955 | } |
| 1956 | |
| 1957 | $output .= '</textarea>'; |
| 1958 | |
| 1959 | if ( $return ) { |
| 1960 | return $output; |
| 1961 | } else { |
| 1962 | echo $output; // phpcs:ignore |
| 1963 | } |
| 1964 | } |
| 1965 | } |
| 1966 | |
| 1967 | /** |
| 1968 | * String translation function. |
| 1969 | * |
| 1970 | * @since 1.4.9 |
| 1971 | * |
| 1972 | * @param int $form_id Form ID. |
| 1973 | * @param string $field_id Field ID. |
| 1974 | * @param mixed $variable To be translated for WPML compatibility. |
| 1975 | */ |
| 1976 | function evf_string_translation( $form_id, $field_id, $variable ) { |
| 1977 | if ( function_exists( 'icl_register_string' ) ) { |
| 1978 | icl_register_string( isset( $form_id ) ? 'everest_forms_' . absint( $form_id ) : 0, isset( $field_id ) ? $field_id : '', $variable ); |
| 1979 | } |
| 1980 | |
| 1981 | if ( function_exists( 'icl_t' ) ) { |
| 1982 | $variable = icl_t( isset( $form_id ) ? 'everest_forms_' . absint( $form_id ) : 0, isset( $field_id ) ? $field_id : '', $variable ); |
| 1983 | } |
| 1984 | |
| 1985 | return $variable; |
| 1986 | } |
| 1987 |