SHARE
TWEET

Limit recurrences created by recurring event

eventsmanager Oct 12th, 2019 162 Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
  1. <?php
  2. /*
  3. This snippet limits the number of recurrences a recurring event can create. Change $limit accordingly.
  4.  
  5. For installation instructions please see this documentation:
  6. http://wp-events-plugin.com/tutorials/how-to-safely-add-php-code-to-wordpress/
  7. */
  8. /**
  9.  * @param bool $result
  10.  * @param EM_Event $EM_Event
  11.  * @return boolean
  12.  */
  13. function my_em_recurring_events_limit( $result, $EM_Event ){
  14.     if( $result && $EM_Event->is_recurring() ){
  15.         $limit = 5;
  16.         $matching_days = $EM_Event->get_recurrence_days();
  17.         $count = count($matching_days);
  18.         if( $count > $limit ){
  19.             $EM_Event->add_error("You can only create a maxumum of $limit events, you are trying to create $count events. Please change your date schedule accordingly.");
  20.             return false;
  21.         }
  22.     }
  23.     return $result;
  24. }
  25. add_filter('em_event_validate_meta', 'my_em_recurring_events_limit', 10, 2);
RAW Paste Data
We use cookies for various purposes including analytics. By continuing to use Pastebin, you agree to our use of cookies as described in the Cookies Policy. OK, I Understand
Top