Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- function pm_replace_course_tag($default_uri, $native_slug, $post, $slug, $native_uri) {
- // Do not affect native URIs
- if($native_uri == true || empty($post->post_type)) { return $default_uri; }
- if(preg_match('/(%course(s)?%)/', $default_uri)) {
- if($post->post_type == 'lesson') {
- $course_id = get_post_meta($post->ID, '_tutor_course_id_for_lesson', true);
- } else if($post->post_type == 'tutor_quiz' && !empty($post->post_parent)) {
- $ancestors = get_post_ancestors($post->ID);
- $root = count($ancestors) - 1;
- $course_id = $ancestors[$root];
- }
- if(!empty($course_id)) {
- $course_slug = get_post_field('post_name', $course_id);
- $default_uri = (!empty($course_slug)) ? preg_replace('/(%course(s)?%)/', sanitize_title($course_slug), $default_uri) : $default_uri;
- }
- }
- return $default_uri;
- }
- add_filter('permalink_manager_filter_default_post_uri', 'pm_replace_course_tag', 5, 5);
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement