Last active
July 11, 2024 07:28
-
-
Save wpmudev-sls/71b4d7ee4771094e1d74b2dddfd08fe1 to your computer and use it in GitHub Desktop.
[Forminator Pro] - Send unchecked options in the mail
This file contains 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 | |
/** | |
* Plugin Name: [Forminator Pro] Send unchecked options only in mail. | |
* Description: Sends unchecked options of a checkbox in the mail. | |
* Author: Prashant @ WPMUDEV | |
* Task: SLS-6301 | |
* Author URI: https://premium.wpmudev.org | |
* License: GPLv2 or later | |
*/ | |
if ( ! defined( 'ABSPATH' ) ) { | |
exit; // Exit if accessed directly. | |
} | |
add_filter( 'forminator_custom_form_after_render_value', function( $value, $custom_form, $field_slug, $prepared_data ) { | |
if ( 2960 !== intval( $custom_form->id ) ) { // Please change the form ID. | |
return $value; | |
} | |
if ( 'checkbox-1' === $field_slug && ! empty( $value ) ) { // Please change the field ID. | |
$check_field = $custom_form->get_field( $field_slug, true ); | |
$field_options = ! empty( $check_field['options'] ) ? wp_list_pluck( $check_field['options'], 'label', 'value' ) : array(); | |
if ( ! empty( $field_options ) ) { | |
foreach ( $prepared_data[ $field_slug ] as $key => $option ) { | |
if ( array_key_exists( $option, $field_options ) ) { | |
unset( $field_options[ $option ] ); | |
} | |
} | |
} | |
$value = implode( ', ', array_keys( array_flip( $field_options ) ) ); | |
} | |
return $value; | |
}, 10, 4 ); |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment