Created
July 15, 2020 09:07
Revisions
-
phparkle created this gist
Jul 15, 2020 .There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters. Learn more about bidirectional Unicode charactersOriginal file line number Diff line number Diff line change @@ -0,0 +1,60 @@ <?php /* Plugin Name: FG Events Manager Hack Plugin URI: Description: Modifies the behaviour of Events Manager plugin Add the start event date in the permalink using the format /YYYY/mm/dd Author: Frédéric GILLES Version: 1.0 */ /** * Add the start event date in the permalink * * @param string $event_link Event link * @param object $object Event object * @return string Event link */ function fg_events_manager_get_permalink($event_link, $object) { $start_date = $object->event_start_date; $start_date = str_replace('-', '/', $start_date); $event_slug = get_site_option('dbem_cp_events_slug'); $event_link = str_replace($event_slug, $event_slug.'/'.$start_date, $event_link); return $event_link; } add_filter('em_event_get_permalink', 'fg_events_manager_get_permalink', 10, 2); /** * Add a rewrite rule to accept the date in the permalink * */ function fg_events_manager_add_rules() { $event_slug = get_site_option('dbem_cp_events_slug'); add_rewrite_rule($event_slug.'/\d+/\d+/\d+/(.+)$', 'index.php?post_type=event&name=$matches[1]', 'top'); // single event //flush_rewrite_rules(); // To remove } add_action('init', 'fg_events_manager_add_rules', 9); // Must be run before events manager /** * Plugin activation * */ function fg_events_manager_activate() { fg_events_manager_add_rules(); flush_rewrite_rules(); } register_activation_hook( __FILE__, 'fg_events_manager_activate' ); /** * Plugin deactivation * */ function fg_events_manager_deactivate() { flush_rewrite_rules(); } register_deactivation_hook( __FILE__, 'fg_events_manager_deactivate' );