mbis

Support %drts_page_slug% tag (Directories Pro)

Jun 7th, 2021 (edited)
241
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
PHP 1.22 KB | None | 0 0
  1. function pm_directory_tags($default_uri, $native_slug, $element, $slug, $native_uri) {
  2.     // Do not affect native URIs
  3.     if($native_uri == true) { return $default_uri; }
  4.    
  5.     if(strpos($default_uri, '%drts_page_slug%') !== false) {
  6.         $page_slugs = get_option('drts_page_slugs');
  7.        
  8.         if(!empty($page_slugs[5])) {
  9.             $all_data = $page_slugs[5];
  10.            
  11.             foreach($all_data as $index => $data) {
  12.                 if(!empty($element->post_type) && !empty($data['post_type']) && $element->post_type == $data['post_type']) {
  13.                     $drts_page_slug = (!empty($page_slugs[0][$index])) ? $page_slugs[0][$index] : '';
  14.                 } else if(!empty($element->taxonomy) && !empty($data['taxonomy']) && $element->taxonomy == $data['taxonomy']) {
  15.                     $drts_page_slug = (!empty($page_slugs[0][$index])) ? $page_slugs[0][$index] : '';
  16.                 }
  17.             }
  18.         }
  19.        
  20.         $default_uri = str_replace('%drts_page_slug%', $drts_page_slug, $default_uri);
  21.     }
  22.    
  23.     return $default_uri;
  24. }
  25. add_filter('permalink_manager_filter_default_post_uri', 'pm_directory_tags', 3, 5);
  26. add_filter('permalink_manager_filter_default_term_uri', 'pm_directory_tags', 3, 5);
Add Comment
Please, Sign In to add comment