PluginProbe
weForms – Easy Drag & Drop Contact Form Builder For WordPress / 1.1.0
weForms – Easy Drag & Drop Contact Form Builder For WordPress v1.1.0
1.6.7 1.6.8 1.6.9 1.6.12 1.6.13 1.6.14 1.6.15 1.6.16 1.6.17 1.6.18 1.6.19 1.6.2 1.6.20 1.6.21 1.6.22 1.6.23 1.6.24 1.6.25 1.6.26 1.6.27 1.6.28 1.6.3 1.6.4 1.6.5 1.6.6 All 74 releases
weforms / includes / functions.php

functions.php in weForms – Easy Drag & Drop Contact Form Builder For WordPress 1.1.0, at includes/functions.php

823 lines 21.4 KB
No matching file
Up and down to move Enter to open Esc to close
Raw Download Zip
1 <?php
2
3 /**
4 * Get a single form
5 *
6 * @since 1.0.3
7 *
8 * @param int $form_id
9 *
10 * @return false|WP_Post
11 */
12 function weform_get_form( $form_id ) {
13 return weforms()->form->get( $form_id );
14 }
15
16 /**
17 * Get contact form templates
18 *
19 * @return array
20 */
21 function weforms_get_form_template_categories() {
22
23 $categories = array(
24 'default' => array(
25 'name' => 'Default Templates',
26 'icon' => 'fa fa-bars',
27 ),
28 // 'registration' => array(
29 // 'name' => 'Registration Templates',
30 // 'icon' => 'fa fa-user-plus',
31 // ),
32 'event' => array(
33 'name' => 'Event Templates',
34 'icon' => 'fa fa-calendar',
35 ),
36 );
37
38 return apply_filters( 'weforms_form_template_categories', $categories );
39 }
40
41 /**
42 * Get entries by a form_id
43 *
44 * @param int $form_id
45 * @param array $args
46 *
47 * @return Object
48 */
49 function weforms_get_form_entries( $form_id, $args = array() ) {
50 global $wpdb;
51
52 $defaults = array(
53 'number' => 10,
54 'offset' => 0,
55 'orderby' => 'created_at',
56 'status' => 'publish',
57 'order' => 'DESC',
58 );
59
60 $r = wp_parse_args( $args, $defaults );
61
62 $query = 'SELECT id, form_id, user_id, INET_NTOA( user_ip ) as ip_address, created_at
63 FROM ' . $wpdb->weforms_entries .
64 ' WHERE form_id = ' . $form_id . ' AND status = \'' . $r['status'] . '\''.
65 ' ORDER BY ' . $r['orderby'] . ' ' . $r['order'] .
66 ' LIMIT ' . $r['offset'] . ', ' . $r['number'];
67
68 $results = $wpdb->get_results( $query );
69
70 return $results;
71 }
72
73 /**
74 * Get an entry by id
75 *
76 * @param int $entry_id
77 *
78 * @return Object
79 */
80 function weforms_get_entry( $entry_id ) {
81 global $wpdb;
82
83 $cache_key = 'weforms-entry-' . $entry_id;
84 $entry = wp_cache_get( $cache_key, 'weforms' );
85
86 if ( false === $entry ) {
87 $query = 'SELECT id, form_id, user_id, user_device, referer, INET_NTOA( user_ip ) as ip_address, created_at
88 FROM ' . $wpdb->weforms_entries . '
89 WHERE id = %d';
90
91 $entry = $wpdb->get_row( $wpdb->prepare( $query, $entry_id ) );
92 wp_cache_set( $cache_key, $entry );
93 }
94
95 return $entry;
96 }
97
98 /**
99 * Insert a new entry
100 *
101 * @param array $args
102 * @param array $fields
103 *
104 * @return WP_Error|integer
105 */
106 function weforms_insert_entry( $args, $fields = array() ) {
107 global $wpdb;
108
109 $browser = weforms_get_browser();
110
111 $defaults = array(
112 'form_id' => 0,
113 'user_id' => get_current_user_id(),
114 'user_ip' => ip2long( weforms_get_client_ip() ),
115 'user_device' => $browser['name'] . '/' . $browser['platform'],
116 'referer' => $_SERVER['HTTP_REFERER'],
117 'created_at' => current_time( 'mysql' )
118 );
119
120 $r = wp_parse_args( $args, $defaults );
121
122 if ( !$r['form_id'] ) {
123 return new WP_Error( 'no-form-id', __( 'No form ID was found.', 'weforms' ) );
124 }
125
126 if ( !$fields ) {
127 return new WP_Error( 'no-fields', __( 'No form fields were found.', 'weforms' ) );
128 }
129
130 $success = $wpdb->insert( $wpdb->weforms_entries, $r );
131
132 if ( is_wp_error( $success ) || !$success ) {
133 return new WP_Error( 'could-not-create', __( 'Could not create an entry', 'weforms' ) );
134 }
135
136 $entry_id = $wpdb->insert_id;
137
138 foreach ($fields as $key => $value) {
139 weforms_add_entry_meta( $entry_id, $key, $value );
140 }
141
142 return $entry_id;
143 }
144
145 /**
146 * Change an entry status
147 *
148 * @param int $entry_id
149 * @param string $status
150 *
151 * @return int|boolean
152 */
153 function weforms_change_entry_status( $entry_id, $status ) {
154 global $wpdb;
155
156 return $wpdb->update( $wpdb->weforms_entries,
157 array( 'status' => $status ),
158 array( 'id' => $entry_id ),
159 array( '%s' ),
160 array( '%d' )
161 );
162 }
163
164 /**
165 * Delete an entry
166 *
167 * @param int $entry_id
168 *
169 * @return int|boolean
170 */
171 function weforms_delete_entry( $entry_id ) {
172 global $wpdb;
173
174 return $wpdb->delete( $wpdb->weforms_entries, array( 'id' => $entry_id ), array( '%d' ) );
175 }
176
177 /**
178 * Add meta data field to an entry.
179 *
180 * @param int $entry_id Entry ID.
181 * @param string $meta_key Metadata name.
182 * @param mixed $meta_value Metadata value. Must be serializable if non-scalar.
183 * @param bool $unique Optional. Whether the same key should not be added.
184 * Default false.
185 * @return int|false Meta ID on success, false on failure.
186 */
187 function weforms_add_entry_meta( $entry_id, $meta_key, $meta_value, $unique = false ) {
188 return add_metadata( 'weforms_entry', $entry_id, $meta_key, $meta_value, $unique);
189 }
190
191 /**
192 * Retrieve entry meta field for a entry.
193 *
194 * @param int $entry_id Entry ID.
195 * @param string $key Optional. The meta key to retrieve. By default, returns
196 * data for all keys. Default empty.
197 * @param bool $single Optional. Whether to return a single value. Default false.
198 * @return mixed Will be an array if $single is false. Will be value of meta data
199 * field if $single is true.
200 */
201 function weforms_get_entry_meta( $entry_id, $key = '', $single = false ) {
202 return get_metadata( 'weforms_entry', $entry_id, $key, $single );
203 }
204
205 /**
206 * Update entry meta field based on entry ID.
207 *
208 * Use the $prev_value parameter to differentiate between meta fields with the
209 * same key and entry ID.
210 *
211 * If the meta field for the entry does not exist, it will be added.
212 *
213 * @param int $entry_id entry ID.
214 * @param string $meta_key Metadata key.
215 * @param mixed $meta_value Metadata value. Must be serializable if non-scalar.
216 * @param mixed $prev_value Optional. Previous value to check before removing.
217 * Default empty.
218 * @return int|bool Meta ID if the key didn't exist, true on successful update,
219 * false on failure.
220 */
221 function weforms_update_entry_meta( $entry_id, $meta_key, $meta_value, $prev_value = '' ) {
222 return update_metadata( 'weforms_entry', $entry_id, $meta_key, $meta_value, $prev_value);
223 }
224
225 /**
226 * Delete everything from entry meta matching meta key.
227 *
228 * @param string $entry_meta_key Key to search for when deleting.
229 * @return bool Whether the entry meta key was deleted from the database.
230 */
231 function weforms_delete_entry_meta_by_key( $meta_key ) {
232 return delete_metadata( 'weforms_entry', null, $meta_key, '', true );
233 }
234
235 /**
236 * Retrieve entry meta fields, based on entry ID.
237 *
238 * The entry meta fields are retrieved from the cache where possible,
239 * so the function is optimized to be called more than once.
240 *
241 * @since 1.2.0
242 *
243 * @param int $entry_id Optional.
244 * @return array entry meta for the given entry.
245 */
246 function weforms_get_entry_custom( $entry_id = 0 ) {
247 $entry_id = absint( $entry_id );
248
249 return weforms_get_entry_meta( $entry_id );
250 }
251
252 /**
253 * Retrieve meta field names for a entry.
254 *
255 * If there are no meta fields, then nothing (null) will be returned.
256 *
257 * @param int $entry_id Optional.
258 * @return array|void Array of the keys, if retrieved.
259 */
260 function weforms_get_entry_custom_keys( $entry_id = 0 ) {
261 $custom = weforms_get_entry_custom( $entry_id );
262
263 if ( !is_array( $custom ) ) {
264 return false;
265 }
266
267 if ( $keys = array_keys($custom) ) {
268 return $keys;
269 }
270 }
271
272 /**
273 * Get the number of entries count on a form
274 *
275 * @param int $form_id
276 *
277 * @return int
278 */
279 function weforms_count_form_entries( $form_id, $status = 'publish' ) {
280 global $wpdb;
281
282 return (int) $wpdb->get_var( $wpdb->prepare( 'SELECT count(id) FROM ' . $wpdb->weforms_entries . ' WHERE form_id = %d AND status = %s', $form_id, $status ) );
283 }
284
285 /**
286 * Get table column heads for a form
287 *
288 * For now, return only text type fields
289 *
290 * @param int $form_id
291 *
292 * @return array
293 */
294 function weforms_get_entry_columns( $form_id, $limit = 6 ) {
295 $fields = weforms()->form->get( $form_id )->get_fields();
296 $columns = array();
297
298 // filter by input types
299 if ( $limit ) {
300
301 $fields = array_filter( $fields, function($item) {
302 return in_array( $item['template'], array( 'text_field', 'name_field', 'dropdown_field', 'radio_field', 'email_address', 'url_field' ) );
303 } );
304 }
305
306 if ( $fields ) {
307 foreach ($fields as $field) {
308 $columns[ $field['name'] ] = $field['label'];
309 }
310 }
311
312 // if passed 0/false, return all collumns
313 if ( $limit && sizeof($columns) > $limit ) {
314 $columns = array_slice( $columns, 0, $limit ); // max 6 columns
315 }
316
317 return apply_filters('weforms_get_entry_columns', $columns, $form_id);
318 }
319
320 /**
321 * Get fields from a form by it's meta key
322 *
323 * @param int $form_id
324 *
325 * @return array
326 */
327 function weforms_get_form_field_labels( $form_id ) {
328 $fields = weforms()->form->get( $form_id )->get_fields();
329 $exclude = array( 'step_start', 'section_break', 'recaptcha', 'shortcode', 'action_hook' );
330
331 if ( ! $fields ) {
332 return false;
333 }
334
335 $data = array();
336 foreach ($fields as $field) {
337 if ( empty( $field['name'] ) ) {
338 continue;
339 }
340
341 // exclude the fields
342 if ( in_array( $field['template'], $exclude ) ) {
343 continue;
344 }
345
346 $data[ $field['name'] ] = array(
347 'label' => $field['label'],
348 'type' => $field['template']
349 );
350 }
351
352 return $data;
353 }
354
355 /**
356 * Get data from an entry
357 *
358 * @param int $entry_id
359 * @param int $form_id
360 *
361 * @return false|array
362 */
363 function weforms_get_entry_data( $entry_id ) {
364 $data = array();
365 $entry = weforms_get_entry( $entry_id );
366 $fields = weforms_get_form_field_labels( $entry->form_id );
367
368 if ( ! $fields ) {
369 return false;
370 }
371
372 foreach ($fields as $meta_key => $field ) {
373 $value = weforms_get_entry_meta( $entry_id, $meta_key, true );
374
375 if ( $field['type'] == 'textarea' ) {
376
377 $data[ $meta_key ] = weforms_format_text( $value );
378
379 } elseif ( $field['type'] == 'name' ) {
380
381 $data[ $meta_key ] = implode( ' ', explode( WeForms::$field_separator, $value ) );
382
383 } elseif ( in_array( $field['type'], array( 'image_upload', 'file_upload' ) ) ) {
384
385 $data[ $meta_key ] = '';
386
387 if ( is_array( $value ) && $value ) {
388
389 foreach ($value as $attachment_id) {
390
391 if ( $field['type'] == 'image_upload' ) {
392 $thumb = wp_get_attachment_image( $attachment_id, 'thumbnail' );
393 } else {
394 $thumb = get_post_field( 'post_title', $attachment_id );
395 }
396
397 $full_size = wp_get_attachment_url( $attachment_id );
398
399 $data[ $meta_key ] .= sprintf( '<a href="%s" target="_blank">%s</a> ', $full_size, $thumb );
400 }
401 }
402
403 } elseif ( in_array( $field['type'], array( 'checkbox', 'multiselect' ) ) ) {
404
405 $data[ $meta_key ] = explode( WeForms::$field_separator, $value );
406
407 } elseif ( $field['type'] == 'map' ) {
408
409 list( $lat, $long ) = explode( ',', $value );
410
411 $data[ $meta_key ] = array( 'lat' => $lat, 'long' => $long );
412
413 } else {
414 $data[ $meta_key ] = $value;
415 }
416 }
417
418 return array(
419 'fields' => $fields,
420 'data' => $data
421 );
422 }
423
424 /**
425 * Format a text and apply WP function callbacks
426 *
427 * @param string $content
428 *
429 * @return string
430 */
431 function weforms_format_text( $content ) {
432 $content = wptexturize( $content );
433 $content = convert_smilies( $content );
434 $content = wpautop( $content );
435 $content = make_clickable( $content );
436
437 return $content;
438 }
439
440 /**
441 * Get User Agent browser and OS type
442 *
443 * @return array
444 */
445 function weforms_get_browser() {
446 $u_agent = $_SERVER['HTTP_USER_AGENT'];
447 $bname = 'Unknown';
448 $platform = 'Unknown';
449 $version = "";
450
451 // first get the platform
452 if (preg_match('/linux/i', $u_agent)) {
453 $platform = 'Linux';
454 } elseif (preg_match('/macintosh|mac os x/i', $u_agent)) {
455 $platform = 'MAC OS';
456 } elseif (preg_match('/windows|win32/i', $u_agent)) {
457 $platform = 'Windows';
458 }
459
460 // next get the name of the useragent yes seperately and for good reason
461 if ( preg_match('/MSIE/i',$u_agent) && !preg_match( '/Opera/i',$u_agent ) ) {
462 $bname = 'Internet Explorer';
463 $ub = "MSIE";
464 } elseif(preg_match('/Trident/i',$u_agent)) {
465 // this condition is for IE11
466 $bname = 'Internet Explorer';
467 $ub = "rv";
468 } elseif(preg_match('/Firefox/i',$u_agent)) {
469 $bname = 'Mozilla Firefox';
470 $ub = "Firefox";
471 } elseif(preg_match('/Chrome/i',$u_agent)) {
472 $bname = 'Google Chrome';
473 $ub = "Chrome";
474 } elseif(preg_match('/Safari/i',$u_agent)) {
475 $bname = 'Apple Safari';
476 $ub = "Safari";
477 } elseif(preg_match('/Opera/i',$u_agent)) {
478 $bname = 'Opera';
479 $ub = "Opera";
480 } elseif(preg_match('/Netscape/i',$u_agent)) {
481 $bname = 'Netscape';
482 $ub = "Netscape";
483 }
484
485 // finally get the correct version number
486 // Added "|:"
487 $known = array('Version', $ub, 'other');
488 $pattern = '#(?<browser>' . join('|', $known) .
489 ')[/|: ]+(?<version>[0-9.|a-zA-Z.]*)#';
490 if (!preg_match_all($pattern, $u_agent, $matches)) {
491 // we have no matching number just continue
492 }
493
494 // see how many we have
495 $i = count($matches['browser']);
496
497 if ($i != 1) {
498 //we will have two since we are not using 'other' argument yet
499 //see if version is before or after the name
500 if (strripos($u_agent,"Version") < strripos($u_agent,$ub)){
501 $version= $matches['version'][0];
502 } else {
503 $version= $matches['version'][1];
504 }
505 } else {
506 $version= $matches['version'][0];
507 }
508
509 // check if we have a number
510 if ( $version == null || $version == '' ) {
511 $version = '';
512 }
513
514 return array(
515 'userAgent' => $u_agent,
516 'name' => $bname,
517 'version' => $version,
518 'platform' => $platform,
519 'pattern' => $pattern
520 );
521 }
522
523 /**
524 * Get form notification merge tags
525 *
526 * @since 1.0
527 *
528 * @return array
529 */
530 function weforms_get_merge_tags() {
531 $tags = array(
532 'form' => array(
533 'title' => __( 'Form', 'weforms' ),
534 'tags' => array(
535 'entry_id' => __( 'Entry ID', 'weforms' ),
536 'form_id' => __( 'Form ID', 'weforms' ),
537 'form_name' => __( 'Form Name', 'weforms' )
538 )
539 ),
540 'system' => array(
541 'title' => __( 'System', 'weforms' ),
542 'tags' => array(
543 'admin_email' => __( 'Site Administrator Email', 'weforms' ),
544 'date' => __( 'Date', 'weforms' ),
545 'site_name' => __( 'Site Title', 'weforms' ),
546 'site_url' => __( 'Site URL', 'weforms' ),
547 'page_title' => __( 'Embedded Page Title', 'weforms' ),
548 )
549 ),
550 'user' => array(
551 'title' => __( 'User', 'weforms' ),
552 'tags' => array(
553 'ip_address' => __( 'IP Address', 'weforms' ),
554 'user_id' => __( 'User ID', 'weforms' ),
555 'first_name' => __( 'First Name', 'weforms' ),
556 'last_name' => __( 'Last Name', 'weforms' ),
557 'display_name' => __( 'Display Name', 'weforms' ),
558 'user_email' => __( 'Email', 'weforms' ),
559 )
560 ),
561 'urls' => array(
562 'title' => __( 'URL\'s', 'weforms' ),
563 'tags' => array(
564 'url_page' => __( 'Embeded Page URL', 'weforms' ),
565 'url_referer' => __( 'Referer URL', 'weforms' ),
566 'url_login' => __( 'Login URL', 'weforms' ),
567 'url_logout' => __( 'Logout URL', 'weforms' ),
568 'url_register' => __( 'Register URL', 'weforms' ),
569 'url_lost_password' => __( 'Lost Password URL', 'weforms' ),
570 )
571 ),
572 );
573
574 return apply_filters( 'wpuf_cf_merge_tags', $tags );
575 }
576
577 /**
578 * Record a form view count
579 *
580 * @param int $form_id
581 *
582 * @return void
583 */
584 function weforms_track_form_view( $form_id ) {
585 // don't track administrators
586 if ( current_user_can( 'administrator' ) ) {
587 return;
588 }
589
590 // ability to turn this off if someone doesn't like this tracking
591 $is_enabled = apply_filters( 'weforms_track_form_view', true );
592
593 if ( !$is_enabled ) {
594 return;
595 }
596
597 // increase the count
598 $meta_key = '_weforms_view_count';
599 $number = (int) get_post_meta( $form_id, $meta_key, true );
600
601 update_post_meta( $form_id, $meta_key, ( $number + 1 ) );
602 }
603
604 /**
605 * Get form view count of a form
606 *
607 * @param int $form_id
608 *
609 * @return int
610 */
611 function weforms_get_form_views( $form_id ) {
612 return (int) get_post_meta( $form_id, '_weforms_view_count', true );
613 }
614
615 /**
616 * Get the weForms global settings
617 *
618 * @param string $key
619 * @param mixed $default
620 *
621 * @return mixed
622 */
623 function weforms_get_settings( $key = '', $default = '' ) {
624
625 $settings = get_option( 'weforms_settings', array() );
626 $settings = apply_filters( 'weforms_get_settings', $settings );
627
628 if ( empty( $key ) ) {
629 return $settings;
630 }
631
632 if ( isset( $settings[ $key ] ) ) {
633 return $settings[ $key ];
634 }
635
636 return $default;
637 }
638
639 /**
640 * Form access capability for forms
641 *
642 * @since 1.0.5
643 *
644 * @return string
645 */
646 function weforms_form_access_capability() {
647 return apply_filters( 'weforms_form_access_capability', 'manage_options' );
648 }
649
650 /**
651 * Clear the buffer
652 *
653 * prevents ajax breakage and endless loading icon. A LIFE SAVER!!!
654 *
655 * @since 1.1.0
656 *
657 * @return void
658 */
659 function weforms_clear_buffer() {
660 ob_clean();
661 }
662
663 /**
664 * Get the client IP address
665 *
666 * @since 1.1.0
667 *
668 * @return string
669 */
670 function weforms_get_client_ip() {
671 $ipaddress = '';
672
673 if ( isset($_SERVER['HTTP_CLIENT_IP'] ) ) {
674 $ipaddress = $_SERVER['HTTP_CLIENT_IP'];
675 } else if ( isset( $_SERVER['HTTP_X_FORWARDED_FOR'] ) ) {
676 $ipaddress = $_SERVER['HTTP_X_FORWARDED_FOR'];
677 } else if ( isset( $_SERVER['HTTP_X_FORWARDED'] ) ) {
678 $ipaddress = $_SERVER['HTTP_X_FORWARDED'];
679 } else if ( isset( $_SERVER['HTTP_FORWARDED_FOR'] ) ) {
680 $ipaddress = $_SERVER['HTTP_FORWARDED_FOR'];
681 } else if ( isset( $_SERVER['HTTP_FORWARDED'] ) ) {
682 $ipaddress = $_SERVER['HTTP_FORWARDED'];
683 } else if ( isset( $_SERVER['REMOTE_ADDR'] ) ) {
684 $ipaddress = $_SERVER['REMOTE_ADDR'];
685 } else {
686 $ipaddress = 'UNKNOWN';
687 }
688
689 return $ipaddress;
690 }
691
692 /**
693 * Save form fields
694 *
695 * @since 1.1.0
696 *
697 * @param int $form_id
698 * @param array $field
699 * @param int $field_id
700 * @param int $order
701 *
702 * @return int ID of updated or inserted post
703 */
704 function weforms_insert_form_field( $form_id, $field = array(), $field_id = null, $order = 0 ) {
705
706 $args = array(
707 'post_type' => 'wpuf_input',
708 'post_parent' => $form_id,
709 'post_status' => 'publish',
710 'post_content' => maybe_serialize( wp_unslash( $field ) ),
711 'menu_order' => $order
712 );
713
714 if ( $field_id ) {
715 $args['ID'] = $field_id;
716 }
717
718 if ( $field_id ) {
719 return wp_update_post( $args );
720 } else {
721 return wp_insert_post( $args );
722 }
723 }
724
725 /**
726 * Allowed upload extensions
727 *
728 * @return array
729 */
730 function weforms_allowed_extensions() {
731 $extesions = array(
732 'images' => array(
733 'ext' => 'jpg,jpeg,gif,png,bmp',
734 'label' => __( 'Images', 'weforms' )
735 ),
736 'audio' => array(
737 'ext' => 'mp3,wav,ogg,wma,mka,m4a,ra,mid,midi',
738 'label' => __( 'Audio', 'weforms' )
739 ),
740 'video' => array(
741 'ext' => 'avi,divx,flv,mov,ogv,mkv,mp4,m4v,divx,mpg,mpeg,mpe',
742 'label' => __( 'Videos', 'weforms' )
743 ),
744 'pdf' => array(
745 'ext' => 'pdf',
746 'label' => __( 'PDF', 'weforms' )
747 ),
748 'office' => array(
749 'ext' => 'doc,ppt,pps,xls,mdb,docx,xlsx,pptx,odt,odp,ods,odg,odc,odb,odf,rtf,txt',
750 'label' => __( 'Office Documents', 'weforms' )
751 ),
752 'zip' => array(
753 'ext' => 'zip,gz,gzip,rar,7z',
754 'label' => __( 'Zip Archives' )
755 ),
756 'exe' => array(
757 'ext' => 'exe',
758 'label' => __( 'Executable Files', 'weforms' )
759 ),
760 'csv' => array(
761 'ext' => 'csv',
762 'label' => __( 'CSV', 'weforms' )
763 )
764 );
765
766 return apply_filters( 'weforms_allowed_extensions', $extesions );
767 }
768
769 /**
770 * Get form integration settings
771 *
772 * @since 1.1.0
773 *
774 * @param int $form_id
775 *
776 * @return array
777 */
778 function weforms_get_form_integrations( $form_id ) {
779 $integrations = get_post_meta( $form_id, 'integrations', true );
780
781 if ( ! $integrations ) {
782 return array();
783 }
784
785 return $integrations;
786 }
787
788
789 /**
790 * Check if an integration is active
791 *
792 * @since 1.1.0
793 *
794 * @param int $form_id
795 * @param string $integration_id
796 *
797 * @return boolean
798 */
799 function weforms_is_integration_active( $form_id, $integration_id ) {
800 $integrations = weforms_get_form_integrations( $form_id );
801
802 if ( ! $integrations ) {
803 return false;
804 }
805
806 foreach ($integrations as $id => $integration) {
807 if ( $integration_id == $id && $integration->enabled == true ) {
808 return $integration;
809 }
810 }
811
812 return false;
813 }
814
815
816 /**
817 * Get Flat UI Colors
818 *
819 * @return array
820 */
821 function weforms_get_flat_ui_colors() {
822 return array( '#1abc9c', '#2ecc71', '#3498db', '#9b59b6', '#34495e' );
823 }