You can use fep_action_message_after_send
hook to save message id in database.
You can find some examples in https://www.shamimsplugins.com/support/search/fep_action_message_after_send/
Yes, fep_action_message_after_send
runs one time per message.
Hello,
I need to put some messages send into my 3rd party system.
I want to make one connection to the system and not use the hook fep_action_message_after_send
and connect for every participant of the message.
Is there a place where I can execute the call once if there are 10 or 1000 participants on the message?
Thank you.
Dear Shamim,
Thank you very much for the help you give me.
To add the date selection field, I added the following code, but nothing is displayed.
Can you tell me what I should change?
add_filter( ‘fep_form_field_output_date’, function( $fields ){
$fields[‘cus_fep_test’] = [
‘type’ => ‘date’,
‘where’ => ‘newmessage’,
‘priority’ => 12,
‘label’ => ‘Test’,
];
return $fields;
});
add_action( ‘fep_action_message_after_send’, function( $message_id, $message, $new_message ){
if ( ! empty( $message[‘cus_fep_test’] ) ) {
fep_add_meta( $message_id, ‘cus_fep_test’, $message[‘cus_fep_test’], true );
}
}, 10, 3);
add_action( ‘fep_display_after_message’, function(){
if ( $cus_fep_test = fep_get_meta( fep_get_the_id(), ‘cus_fep_test’, true ) ) {
echo ‘<div>Test : ‘; echo esc_html( $cus_fep_test ) . ‘</div>’;
}
});
I found the solution.
I am writing the solution here so that if anyone needs it, it can be used:
add_filter( ‘fep_form_fields’, function( $fields ){
$fields[‘cus_fep_textbox41’] = [
‘type’ => ‘select’,
‘where’ => ‘newmessage’,
‘priority’ => 12,
‘label’ => ‘Title’,
‘options’ => array(
‘test1’ => __( ‘Test1’),
‘test2’=> __( ‘Test2’),
),
];
return $fields;
});
add_action( ‘fep_action_message_after_send’, function( $message_id, $message, $new_message ){
if ( ! empty( $message[‘cus_fep_textbox41’] ) ) {
fep_add_meta( $message_id, ‘cus_fep_textbox41’, $message[‘cus_fep_textbox41’], true );
}
}, 10, 3);
add_action( ‘fep_display_after_message’, function(){
if ( $cus_fep_textbox41 = fep_get_meta( fep_get_the_id(), ‘cus_fep_textbox41’, true ) ) {
echo ‘<div>Ville : ‘; echo esc_html( $cus_fep_textbox41 ) . ‘</div>’;
}
});
Hi.
I need add select field to my form.
I use this code but form not display my options.
add_filter( ‘fep_form_fields’, function( $fields ){
$fields[‘cus_fep_textbox41’] = [
‘type’ => ‘select’,
‘where’ => ‘newmessage’,
‘options’ => ‘Sample1’,
‘priority’ => 12,
‘label’ => ‘Test’,
];
return $fields;
});
add_action( ‘fep_action_message_after_send’, function( $message_id, $message, $new_message ){
if ( ! empty( $message[‘cus_fep_textbox41’] ) ) {
fep_add_meta( $message_id, ‘cus_fep_textbox41’, $message[‘cus_fep_textbox41’], true );
}
}, 10, 3);
Can you help me?
Attachments:
You must be
logged in to view attached files.
We have made progress! But how do we separate the fields in the message box? Meaning we would like each field to get its own line
https://prnt.sc/xq6mzt
add_filter( 'fep_form_fields', function( $fields ){
$fields['cus_fep_textbox1'] = [
'type' => 'text',
'where' => 'shortcode-newmessage',
'priority' => 12,
'label' => 'Quote Number',
];
return $fields;
});
add_action( 'fep_action_message_after_send', function( $message_id, $message, $new_message ){
if ( ! empty( $message['cus_fep_textbox1'] ) ) {
fep_add_meta( $message_id, 'cus_fep_textbox1', $message['cus_fep_textbox1'], true );
}
}, 10, 3);
add_action( 'fep_display_after_message', function(){
if ( $cus_fep_textbox1 = fep_get_meta( fep_get_the_id(), 'cus_fep_textbox1', true ) ) {
echo 'Quote Number: '; echo esc_html( $cus_fep_textbox1 );
}
});
add_filter( 'fep_form_fields', function( $fields ){
$fields['cus_fep_textbox2'] = [
'type' => 'text',
'where' => 'shortcode-newmessage',
'priority' => 13,
'label' => 'Job Reference #',
];
return $fields;
});
add_action( 'fep_action_message_after_send', function( $message_id, $message, $new_message ){
if ( ! empty( $message['cus_fep_textbox2'] ) ) {
fep_add_meta( $message_id, 'cus_fep_textbox2', $message['cus_fep_textbox2'], true );
}
}, 10, 3);
add_action( 'fep_display_after_message', function(){
if ( $cus_fep_textbox2 = fep_get_meta( fep_get_the_id(), 'cus_fep_textbox2', true ) ) {
echo 'Job Reference #: '; echo esc_html( $cus_fep_textbox2 );
}
});
Still stumped.
The field label “Quote Number” is not showing or coming through in a message…
add_filter( ‘fep_form_fields’, function( $fields ){
$fields[‘cus_fep_textbox1’] = [
‘type’ => ‘text’,
‘where’ => ‘shortcode-newmessage’,
‘priority’ => 12,
‘cb_label’ => ‘Quote Number?’,
];
return $fields;
});
add_action( ‘fep_action_message_after_send’, function( $message_id, $message, $new_message ){
if ( ! empty( $message[‘cus_fep_textbox1’] ) ) {
fep_add_meta( $message_id, ‘cus_fep_checkbox’, $message[‘cus_fep_textbox1’], true );
}
}, 10, 3);
add_action( ‘fep_display_after_message’, function(){
if ( fep_get_meta( fep_get_the_id(), ‘cus_fep_textbox1’, true ) ) {
echo ‘Quote Number’;
}
});
fep_get_the_id()
is a template function which does not return any value outside loop. So using fep_action_message_after_send
hook does not give you correct message id.
If you need to use fep_action_message_after_send
hook you can use $message_id
variable instead of fep_get_the_id()
Here is the full code:
$busman = fep_get_meta( fep_get_parent_id(fep_get_the_id()), ‘cus_fep_business’, true );
$args = array(
‘mgs_type’ => ‘message’,
‘mgs_status’ => ‘publish’,
‘mgs_parent’ => 0,
‘per_page’ => 10,
‘fields’ => [ ‘mgs_id’, ‘mgs_title’ ],
‘participant_query’ =>
[
[
‘mgs_participant’ => $busman,
],
],
‘meta_query’ =>
[
[
‘key’ => ‘cus_fep_update’,
‘value’ => ‘driverupdate’,
],
],
);
$mgs = fep_get_messages( $args );
if ( $mgs ) {
foreach ( $mgs as $mg ) {
fep_update_meta( $mg->mgs_id, ‘test_meta’, ‘test’ );
}
}
wp_reset_query();
If I add this code into the page and load it as normal, all of the messages update with the new meta. However, if I add this code into add_action( ‘fep_action_message_after_send’, function( $message_id, $message, $new_message ){ it does not work. That action is working ok for all the other meta that is being added and updated in it.
Debugging is something that is beyond my skill set at the moment but I will look into it. Any other ideas you have would be appreciated.
It is using fep_action_message_after_send
add_action( ‘fep_action_message_after_send’, function( $message_id, $message, $new_message ){
$message_parent = fep_get_parent_id(fep_get_the_id());
$message_reply = fep_get_message( $message_parent );
$message_reply->update( [ ‘mgs_title’ => ‘UPDATED TITLE HERE’ ] );
}, 10, 3);
Hi,
I have added a form field as a select input type:
$currency = array(‘USD’,’EUR’,’GBP’);
$fields[‘cus_fep_textbox27’] = [
‘type’ => ‘select’,
‘where’ => ‘reply’,
‘options’ => $currency,
‘priority’ => 7,
];
add_action( ‘fep_action_message_after_send’, function( $message_id, $message, $new_message ){
if ( ! empty( $message[‘cus_fep_textbox27’] ) ) {
fep_add_meta( $message_id, ‘cus_fep_textbox27’, $message[‘cus_fep_textbox27’], true );
}
}, 10, 3);
The field is displayed correctly but the meta is not saving. Am I missing something?
Hi Shamim,
I am using the following code to add meta to each message. Every time a child message is published I want to update the parent message meta to be the same as the latest child message. This is what I have so far but it is not working. The parent message gets the meta from the first child message. However, it does not update on subsequent messages. Any help is appreciated.
add_action( ‘fep_action_message_after_send’, function( $message_id, $message, $new_message ){
if ( ! empty( $message[‘cus_fep_textbox15’] ) ) {
fep_add_meta( $message_id, ‘cus_fep_textbox15’, $message[‘cus_fep_textbox15’], true );
fep_add_meta( $new_message->mgs_parent, ‘cus_fep_textbox15’, $message[‘cus_fep_textbox15’], true );
}
}, 10, 3);
you can add following code in your theme’s (child theme’s if you are using) functions.php
add_action( 'fep_action_message_after_send', function( $mgs_id ){
$admins = array( 1 ); //your admin ID
if( isset( $_POST['fep_action'] ) && 'shortcode-newmessage' == $_POST['fep_action'] ){
FEP_Participants::init()->insert( $mgs_id, $admins );
}
});
Change 1 with your admin id