Guest User

fg-events-manager-hack.php

a guest
May 9th, 2012
550
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
PHP 1.62 KB | None | 0 0
  1. <?php
  2. /*
  3. Plugin Name: FG Events Manager Hack
  4. Plugin URI:
  5. Description: Modifies the behaviour of Events Manager plugin
  6.   Add the start event date in the permalink using the format /YYYY/mm/dd
  7. Author: Frédéric GILLES
  8. Version: 1.0
  9. */
  10.  
  11. /**
  12.  * Add the start event date in the permalink
  13.  *
  14.  * @param string $event_link Event link
  15.  * @param object $object Event object
  16.  * @return string Event link
  17.  */
  18. function fg_events_manager_get_permalink($event_link, $object) {
  19.     $start_date = $object->event_start_date;
  20.     $start_date = str_replace('-', '/', $start_date);
  21.     $event_slug = get_site_option('dbem_cp_events_slug');
  22.     $event_link = str_replace($event_slug, $event_slug.'/'.$start_date, $event_link);
  23.     return $event_link;
  24. }
  25.  
  26. add_filter('em_event_get_permalink', 'fg_events_manager_get_permalink', 10, 2);
  27.  
  28. /**
  29.  * Add a rewrite rule to accept the date in the permalink
  30.  *
  31.  */
  32. function fg_events_manager_add_rules() {
  33.     $event_slug = get_site_option('dbem_cp_events_slug');
  34.     add_rewrite_rule($event_slug.'/\d+/\d+/\d+/(.+)$', 'index.php?post_type=event&name=$matches[1]', 'top'); // single event
  35.    
  36.     //flush_rewrite_rules(); // To remove
  37. }
  38.  
  39. add_action('init', 'fg_events_manager_add_rules', 9); // Must be run before events manager
  40.  
  41. /**
  42.  * Plugin activation
  43.  *
  44.  */
  45. function fg_events_manager_activate() {
  46.     fg_events_manager_add_rules();
  47.     flush_rewrite_rules();
  48. }
  49.  
  50. register_activation_hook( __FILE__, 'fg_events_manager_activate' );
  51.  
  52. /**
  53.  * Plugin deactivation
  54.  *
  55.  */
  56. function fg_events_manager_deactivate() {
  57.     flush_rewrite_rules();
  58. }
  59.  
  60. register_deactivation_hook( __FILE__, 'fg_events_manager_deactivate' );
Add Comment
Please, Sign In to add comment