Title: modify function validate()
Last modified: December 24, 2022

---

# modify function validate()

 *  Resolved [julio75](https://wordpress.org/support/users/kingkurt/)
 * (@kingkurt)
 * [3 years, 5 months ago](https://wordpress.org/support/topic/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
 *     ```wp-block-code
       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
 *     ```wp-block-code
       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
 *     ```wp-block-code
       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)

 *  Thread Starter [julio75](https://wordpress.org/support/users/kingkurt/)
 * (@kingkurt)
 * [3 years, 1 month ago](https://wordpress.org/support/topic/modify-function-validate/#post-16649131)
 * Nobody any idea ?
 *  [joneiseman](https://wordpress.org/support/users/joneiseman/)
 * (@joneiseman)
 * [3 years, 1 month ago](https://wordpress.org/support/topic/modify-function-validate/#post-16649595)
 * You can use the em_event_validate [filter](https://www.wpbeginner.com/glossary/filter/).
   Add the following code snippet:
 *     ```wp-block-code
       add_filter( 'em_event_validate', 'my_em_event_validate', 10, 2 );
       function my_em_event_validate( $is_valid, $EM_Event ) {
               if ( $is_valid ) {
                       if( empty($EM_Event->post_content ) ){
                               $is_valid = false;
                               $EM_Event->add_error( sprintf(__("%s is mandatory.", 'events-manager'), __('The details (description) of the event','events-manager') ) );
                       }
                       if( strlen($EM_Event->post_content) >=1 && str_word_count($EM_Event->post_content) <= 20 ){
                               $is_valid = false;
                               $EM_Event->add_error( sprintf(__("%s is too short (min. 20 words).", 'events-manager'), __('the details (description) of the event','events-manager') ) );
                       }
               }
               return $is_valid;
       }
       ```
   
 * Code snippets can be put in the functions.php of a child theme or you could add
   the following plugin to add code snippets: [https://wordpress.org/plugins/header-footer-code-manager/](https://wordpress.org/plugins/header-footer-code-manager/)
 *  Thread Starter [julio75](https://wordpress.org/support/users/kingkurt/)
 * (@kingkurt)
 * [3 years, 1 month ago](https://wordpress.org/support/topic/modify-function-validate/#post-16652218)
 * Thank you very much [joneiseman](https://wordpress.org/support/users/joneiseman/)
   your snipplet works very fine

Viewing 3 replies - 1 through 3 (of 3 total)

The topic ‘modify function validate()’ is closed to new replies.

 * ![](https://ps.w.org/events-manager/assets/icon-256x256.png?rev=3550347)
 * [Events Manager - Calendar, Bookings, Tickets, and more!](https://wordpress.org/plugins/events-manager/)
 * [Frequently Asked Questions](https://wordpress.org/plugins/events-manager/#faq)
 * [Support Threads](https://wordpress.org/support/plugin/events-manager/)
 * [Active Topics](https://wordpress.org/support/plugin/events-manager/active/)
 * [Unresolved Topics](https://wordpress.org/support/plugin/events-manager/unresolved/)
 * [Reviews](https://wordpress.org/support/plugin/events-manager/reviews/)

 * 3 replies
 * 2 participants
 * Last reply from: [julio75](https://wordpress.org/support/users/kingkurt/)
 * Last activity: [3 years, 1 month ago](https://wordpress.org/support/topic/modify-function-validate/#post-16652218)
 * Status: resolved