modify function validate()
-
Hi, I use the Plugin: Events Manager. To avoid that users who are submitting events without, or very short event description using the form I have added two conditions in em-event.php file.
The Original code is
function validate(){ $validate_post = true; if( empty($this->event_name) ){ $validate_post = false; $this->add_error( sprintf(__("%s is required.", 'events-manager'), __('Event name','events-manager')) ); } //anonymous submissions and guest basic info if( !empty($this->event_owner_anonymous) ){ if( !is_email($this->event_owner_email) ){ $this->add_error( sprintf(__("%s is required.", 'events-manager'), __('A valid email','events-manager')) ); } if( empty($this->event_owner_name) ){ $this->add_error( sprintf(__("%s is required.", 'events-manager'), __('Your name','events-manager')) ); } }
I have added the conditions
if( empty($this->post_content)){ $validate_post = false; $this->add_error( sprintf(__("%s are mandatory.", 'events-manager'), __('The details (description) of the event','events-manager')) ); } if(strlen($this->post_content)>=1 && str_word_count($this->post_content)<=20 ){ $validate_post = false; $this->add_error( sprintf(__("%s are to short (min. 20 words).", 'events-manager'), __('the details (description) of the event','events-manager')) ); }
All together
function validate(){ $validate_post = true; if( empty($this->event_name) ){ $validate_post = false; $this->add_error( sprintf(__("%s is required.", 'events-manager'), __('Event name','events-manager')) ); } if( empty($this->post_content)){ $validate_post = false; $this->add_error( sprintf(__("%s are mandatory.", 'events-manager'), __('The details (description) of the event','events-manager')) ); } if(strlen($this->post_content)>=1 && str_word_count($this->post_content)<=20 ){ $validate_post = false; $this->add_error( sprintf(__("%s are to short (min. 20 words).", 'events-manager'), __('the details (description) of the event','events-manager')) ); } //anonymous submissions and guest basic info if( !empty($this->event_owner_anonymous) ){ if( !is_email($this->event_owner_email) ){ $this->add_error( sprintf(__("%s is required.", 'events-manager'), __('A valid email','events-manager')) ); } if( empty($this->event_owner_name) ){ $this->add_error( sprintf(__("%s is required.", 'events-manager'), __('Your name','events-manager')) ); } } $validate_tickets = true; //must pass if we can't validate bookings if( $this->can_manage('manage_bookings','manage_others_bookings') ){ $validate_tickets = $this->get_bookings()->get_tickets()->validate(); } $validate_image = $this->image_validate(); $validate_meta = $this->validate_meta(); return apply_filters('em_event_validate', $validate_post && $validate_image && $validate_meta && $validate_tickets, $this ); }
This works very fine!
Only problem when the plugin gets updates I have to modify the em-events.php file again.
So I’m wondering if it would not be possible to add this two conditions using the functions.php file of the theme.
Having limited PHP skills didn’t find the solution how to write the code.
Anyone an idea ??
Viewing 3 replies - 1 through 3 (of 3 total)
Viewing 3 replies - 1 through 3 (of 3 total)
- The topic ‘modify function validate()’ is closed to new replies.