eventsmanager

Limit recurrences created by recurring event

Oct 12th, 2019
292
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

Adblocker detected! Please consider disabling it...

We've detected AdBlock Plus or some other adblocking software preventing Pastebin.com from fully loading.

We don't have any obnoxious sound, or popup ads, we actively block these annoying types of ads!

Please add Pastebin.com to your ad blocker whitelist or disable your adblocking software.

×