Last active
June 28, 2024 13:42
-
-
Save wpmudev-sls/8c3fa0124b58ec2a08ce9895bc0f087e to your computer and use it in GitHub Desktop.
[Forminator Pro] - Add notes in draft notification 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] Add notes in draft notification. | |
* Description: Adds a notes field and renders it in draft notification mail. | |
* Author: Prashant @ WPMUDEV | |
* Task: SLS-6263 | |
* Author URI: https://premium.wpmudev.org | |
* License: GPLv2 or later | |
*/ | |
if ( ! defined( 'ABSPATH' ) ) { | |
exit; // Exit if accessed directly. | |
} | |
add_filter( 'forminator_form_save_draft_response', 'wpmudev_add_notes_in_draft', 10, 2 ); | |
function wpmudev_add_notes_in_draft( $response, $form_id ) { | |
if ( 2960 !== intval( $form_id ) ) { // Please change the form ID. | |
return $response; | |
} | |
$notes_html = '<div class="forminator-row"> | |
<div id="text-1" class="forminator-col forminator-col-12 "> | |
<div class="forminator-field"> | |
<label for="forminator-field-text-1" class="forminator-label">Notes</label> | |
<input | |
type="text" | |
name="notes" | |
placeholder="Enter your note." | |
id="forminator-field-text-1" | |
class="forminator-input forminator-input--field" | |
style="background-color:#EDEDED;color:#000000;border:none;width:100%;outline: none;"> | |
</div> | |
</div> | |
</div>'; | |
$response['message'] = str_replace( '<div class="forminator-row">', $notes_html . '<div class="forminator-row">', $response['message'] ); | |
return $response; | |
} | |
add_filter( 'forminator_custom_form_mail_admin_message', 'wpmudev_add_notes_in_draft_mail', 10, 5 ); | |
function wpmudev_add_notes_in_draft_mail( $message, $custom_form, $data, $entry, $cls_mail ) { | |
if ( 2960 !== intval( $custom_form->id ) ) { // Please change the form ID. | |
return $message; | |
} | |
if ( false !== strpos( $message, '{notes}' ) ) { | |
$notes = Forminator_Core::sanitize_text_field( 'notes' ); | |
$message = str_replace( '{notes}', $notes, $message ); | |
} | |
return $message; | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment