PLL_Links_Default

Links model for default permalinks for example mysite.com/?somevar=something&lang=en implements the "links_model interface".

Defined (1)

The class is defined in the following location(s).

/include/links-default.php  
  1. class PLL_Links_Default extends PLL_Links_Model { 
  2. public $using_permalinks = false; 
  3.  
  4. /** 
  5. * Adds language information to an url 
  6. * links_model interface 
  7. * @since 1.2 
  8. * @param string $url url to modify 
  9. * @param object $lang language 
  10. * @return string modified url 
  11. */ 
  12. public function add_language_to_link( $url, $lang ) { 
  13. return empty( $lang ) || ( $this->options['hide_default'] && $this->options['default_lang'] == $lang->slug ) ? $url : add_query_arg( 'lang', $lang->slug, $url ); 
  14.  
  15. /** 
  16. * Removes the language information from an url 
  17. * links_model interface 
  18. * @since 1.2 
  19. * @param string $url url to modify 
  20. * @return string modified url 
  21. */ 
  22. public function remove_language_from_link( $url ) { 
  23. return remove_query_arg( 'lang', $url ); 
  24.  
  25. /** 
  26. * Returns the link to the first page 
  27. * links_model interface 
  28. * @since 1.2 
  29. * @param string $url url to modify 
  30. * @return string modified url 
  31. */ 
  32. function remove_paged_from_link( $url ) { 
  33. return remove_query_arg( 'paged', $url ); 
  34.  
  35. /** 
  36. * Returns the link to the paged page when using pretty permalinks 
  37. * @since 1.5 
  38. * @param string $url url to modify 
  39. * @param int $page 
  40. * @return string modified url 
  41. */ 
  42. public function add_paged_to_link( $url, $page ) { 
  43. return add_query_arg( array( 'paged' => $page ), $url ); 
  44.  
  45. /** 
  46. * Gets the language slug from the url if present 
  47. * links_model interface 
  48. * @since 1.2 
  49. * @since 2.0 add $url argument 
  50. * @param string $url optional, defaults to current url 
  51. * @return string language slug 
  52. */ 
  53. public function get_language_from_url( $url = '' ) { 
  54. if ( empty( $url ) ) { 
  55. $url = $_SERVER['REQUEST_URI']; 
  56.  
  57. $pattern = '#lang=('.implode( '|', $this->model->get_languages_list( array( 'fields' => 'slug' ) ) ).')#'; 
  58. return preg_match( $pattern, trailingslashit( $url ), $matches ) ? $matches[1] : ''; // $matches[1] is the slug of the requested language 
  59.  
  60. /** 
  61. * Returns the static front page url 
  62. * @since 1.8 
  63. * @param object $lang 
  64. * @return string 
  65. */ 
  66. public function front_page_url( $lang ) { 
  67. if ( $this->options['hide_default'] && $lang->slug == $this->options['default_lang'] ) { 
  68. return trailingslashit( $this->home ); 
  69. $url = home_url( '/?page_id=' . $lang->page_on_front ); 
  70. return $this->options['force_lang'] ? $this->add_language_to_link( $url, $lang ) : $url;