Created
August 31, 2022 16:23
-
-
Save adczk/68db359343f68533d8df184b6ccccec7 to your computer and use it in GitHub Desktop.
Forminator - ACF checkbox compatibility
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| <?php | |
| /* | |
| * * | |
| * makes Forminator's "post data" custom field checkbox | |
| * compatible with ACF checkbox | |
| * | |
| *1. post data custom field label must be same as name of ACF checkbox field | |
| *2. and it has to be mapped to a chekbox form field | |
| *3. $chekboxes array should contain names of ACF chekcbox fields (same as set as labels in postdata custom fields) | |
| * | |
| * | |
| * use as MU plugin | |
| * tested with Forminator 1.17.2 and ACF 5.12.3 | |
| * | |
| * by Adam/WPMU DEV | |
| */ | |
| add_action( 'forminator_post_data_field_post_saved', 'forminator_acf_check_compat', 10, 3 ); | |
| function forminator_acf_check_compat( $post_id, $field, $data ) { | |
| $checkboxes = array( 'check' ); // list of ACF checkbox fields to be made compatible | |
| ######### | |
| $cs_data = $data['post-custom']; | |
| if ( !empty( $cs_data ) && is_array( $cs_data ) ) { | |
| foreach ($cs_data as $key=>$cs_field) { | |
| if ( in_array( $cs_field['key'], $checkboxes ) ) { | |
| $acf_checkbox = explode( ',', $cs_field['value'] ) ; | |
| foreach ($acf_checkbox as $a=>$b) { | |
| $acf_checkbox[$a]=trim($b); | |
| } | |
| update_post_meta( $post_id, $cs_field['key'], $acf_checkbox ); | |
| } | |
| } | |
| } | |
| } |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment