Created
December 3, 2018 21:42
-
-
Save cliffordp/ac4a68769787352369ab0c5e41dc28ab to your computer and use it in GitHub Desktop.
The Events Calendar: All Venue slugs get prefixed with a custom string. Works in wp-admin and Community Events.
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 characters
<?php | |
/** | |
* The Events Calendar: All Venue slugs get prefixed with a custom string. Works in wp-admin and Community Events. | |
* | |
* !!! Change the prefix to your own !!! | |
* | |
* @link https://gist.github.com/cliffordp/ac4a68769787352369ab0c5e41dc28ab This snippet. | |
*/ | |
function cliff_prefix_venue_slugs( $data ) { | |
// TODO: Change this to what you want!!! | |
$prefix = 'xvenue-'; | |
if ( | |
( | |
'publish' === $data['post_status'] | |
|| 'draft' === $data['post_status'] | |
|| 'pending' === $data['post_status'] | |
) | |
&& class_exists( 'Tribe__Events__Venue' ) | |
&& Tribe__Events__Venue::POSTTYPE === $data['post_type'] | |
&& 0 !== strpos( $data['post_name'], $prefix ) // is not already prefixed, such as when moving from Deleted back to Published | |
) { | |
$data['post_name'] = $prefix . $data['post_name']; | |
} | |
return $data; | |
} | |
add_filter( 'wp_insert_post_data', 'cliff_prefix_venue_slugs' ); |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment