Actions & Filters of RSVP Addon
Last Updated: October 4, 2023
As RSVP addon evolves it get added more and more actions and filters to allow users to customize more and more parts of the addon that was not initially supported. Below are such code snippets. Bare in mind, all these actions and filters may be pasted on functions.php file in your theme.
Increase Additional Fields
By default RSVP form support upto 5 additional fields on the RSVP form and you can use the below code snippet to increase the max number of additional fields.
1 2 3 4 |
add_filter('evors_field_count','evors0',10,1); function evors0($val){ return 7; } |
Add New Additional Field Type
First, add the new form field type to the select list. Pay special attention to the field slug name you are going to use. In the below case it is “file”
1 2 3 4 5 |
add_filter('evors_additional_field_types','evors1',10,1); function evors1($ar){ $ar['file'] = 'File Field'; return $ar; } |
Next add the HTML to show in the form how this new field type will look. This action receive 3 parameters that can be used to fill the necessary data in the HTML for the field. Also the add_action slug name, pay attention to the last word. “file” which is the same as above slug name you used for the field.
1 2 3 4 5 6 7 8 9 |
add_action('evors_additional_field_file','evors2',10, 3); function evors2($value, $FIELDNAME, $required){ ?> <p> <label><?php echo $FIELDNAME;?></label> <input name='samplefield' type='file' value='<?php echo $value;?>'> </p> <?php } |
That code should now show a new field – which allow for choosing a file – like in the below RSVP form.
The code below is only required if saving this special field needs special data saving steps. By default the field value will be saved to evo-rsvp (RSVP post meta) If you need special saving steps you can use this code.
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 |
add_action('evors_save_other_metadata', 'evors3', 10,1); function evors3($postid){ // if saving the data as file if( !empty( $_FILES ) && 'POST' == $_SERVER['REQUEST_METHOD'] ){ $__var_name = 'samplefield'; if ($_FILES[$__var_name]['error'] !== UPLOAD_ERR_OK) __return_false(); require_once (ABSPATH.'/wp-admin/includes/media.php'); require_once (ABSPATH.'/wp-admin/includes/file.php'); require_once (ABSPATH.'/wp-admin/includes/image.php'); // upload the file and get attachment id $attachmentId = media_handle_upload($__var_name, $postid); unset($_FILES); // save the attachment ID update_post_meta($postid, 'rsvp_file_id', $attachmentId); } // if saving the data as just data if(!empty($_POST['samplefield'])){ update_post_meta($postid, 'fieldname', $_POST['samplefield']); } } |
Did this article help you? If not, send us a ticket via helpdesk
RSVP Events Addon Buy Now