PLL_Links_Permalinks

Links model base class when using pretty permalinks.

Defined (1)

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

/include/links-permalinks.php  
  1. abstract class PLL_Links_Permalinks extends PLL_Links_Model { 
  2. public $using_permalinks = true; 
  3. protected $index = 'index.php'; // Need this before $wp_rewrite is created, also harcoded in wp-includes/rewrite.php 
  4. protected $root, $use_trailing_slashes; 
  5. protected $always_rewrite = array( 'date', 'root', 'comments', 'search', 'author' ); 
  6.  
  7. /** 
  8. * Constructor 
  9. * @since 1.8 
  10. * @param object $model PLL_Model instance 
  11. */ 
  12. public function __construct( &$model ) { 
  13. parent::__construct( $model ); 
  14.  
  15. // Inspired by wp-includes/rewrite.php 
  16. $permalink_structure = get_option( 'permalink_structure' ); 
  17. $this->root = preg_match( '#^/*' . $this->index . '#', $permalink_structure ) ? $this->index . '/' : ''; 
  18. $this->use_trailing_slashes = ( '/' == substr( $permalink_structure, -1, 1 ) ); 
  19.   
  20. /** 
  21. * Returns the link to the first page when using pretty permalinks 
  22. * @since 1.2 
  23. * @param string $url url to modify 
  24. * @return string modified url 
  25. */ 
  26. public function remove_paged_from_link( $url ) { 
  27. /** 
  28. * Filter an url after the paged part has been removed 
  29. * @since 2.0.6 
  30. * @param string $modified_url The link to the first page 
  31. * @param string $orginal_url The link to the original paged page 
  32. */ 
  33. return apply_filters( 'pll_remove_paged_from_link', preg_replace( '#\/page\/[0-9]+\/?#', $this->use_trailing_slashes ? '/' : '', $url ), $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. /** 
  44. * Filter an url after the paged part has been added 
  45. * @since 2.0.6 
  46. * @param string $modified_url The link to the paged page 
  47. * @param string $orginal_url The link to the original first page 
  48. * @param int $page The page number 
  49. */ 
  50. return apply_filters( 'pll_add_paged_to_link', user_trailingslashit( trailingslashit( $url ) . 'page/' . $page, 'paged' ), $url, $page ); 
  51.  
  52. /** 
  53. * Returns the home url 
  54. * @since 1.3.1 
  55. * @param object $lang PLL_Language object 
  56. * @return string 
  57. */ 
  58. public function home_url( $lang ) { 
  59. return trailingslashit( parent::home_url( $lang ) ); 
  60.  
  61. /** 
  62. * Returns the static front page url 
  63. * @since 1.8 
  64. * @param object $lang 
  65. * @return string 
  66. */ 
  67. public function front_page_url( $lang ) { 
  68. if ( $this->options['hide_default'] && $lang->slug == $this->options['default_lang'] ) { 
  69. return trailingslashit( $this->home ); 
  70. $url = home_url( $this->root . get_page_uri( $lang->page_on_front ) ); 
  71. $url = $this->use_trailing_slashes ? trailingslashit( $url ) : untrailingslashit( $url ); 
  72. return $this->options['force_lang'] ? $this->add_language_to_link( $url, $lang ) : $url; 
  73.  
  74. /** 
  75. * Prepares rewrite rules filters 
  76. * @since 1.6 
  77. */ 
  78. public function get_rewrite_rules_filters() { 
  79. // Make sure we have the right post types and taxonomies 
  80. $types = array_values( array_merge( $this->model->get_translated_post_types(), $this->model->get_translated_taxonomies(), $this->model->get_filtered_taxonomies() ) ); 
  81. $types = array_merge( $this->always_rewrite, $types ); 
  82.  
  83. /** 
  84. * Filter the list of rewrite rules filters to be used by Polylang 
  85. * @since 0.8.1 
  86. * @param array $types the list of filters (without '_rewrite_rules' at the end) 
  87. */ 
  88. return apply_filters( 'pll_rewrite_rules', $types );