Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- <?php
- /**
- * Please paste it to functions.php file in your child theme folder
- */
- function pm_assign_listing_uri($post_ID, $post, $update) {
- wp_schedule_single_event(time() + 60, 'pm_regenerate_uris_after_listing_added', array($post_ID));
- }
- add_action('wp_insert_post', 'pm_assign_listing_uri', 10, 1);
- function pm_regenerate_uri($post_id) {
- global $permalink_manager_uris;
- $permalink_manager_uris[$post_id] = Permalink_Manager_URI_Functions_Post::get_default_post_uri($post_id);
- update_option('permalink-manager-uris', $permalink_manager_uris);
- }
- add_action('pm_regenerate_uris_after_listing_added', 'pm_regenerate_uri', 10, 1);
- /**
- * Support %listing-type% and %listing_type% tag
- */
- function pm_replace_listing_type($uri, $post_name, $post, $slug, $native) {
- if($post->post_type == 'job_listing') {
- $listing_type = get_post_meta($post->ID, '_case27_listing_type', true);
- $uri = str_replace(array('%listing-type%', '%listing_type%'), $listing_type, $uri);
- }
- return $uri;
- }
- add_filter('permalink_manager_filter_default_post_uri', 'pm_replace_listing_type', 9, 5);
- /**
- * Fix the problem with pending/draft listing URLs
- */
- function pm_pending_listing_url($url, $post) {
- global $permalink_manager_uris;
- if(class_exists('Permalink_Manager_Helper_Functions') && $post->post_type == 'job_listing' && $post->post_status !== 'publish' && !empty($permalink_manager_uris[$post->ID])) {
- $url = sprintf('%s/%s', Permalink_Manager_Helper_Functions::get_permalink_base($post), $permalink_manager_uris[$post->ID]);
- // Control trailing slashes
- $url = Permalink_Manager_Core_Functions::control_trailing_slashes($url);
- }
- return $url;
- }
- add_filter('post_type_link', 'pm_pending_listing_url', 100, 2);
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement