PluginProbe
Polylang / 1.8
Polylang v1.8
3.8.9 3.8.8 3.8.7 3.8.6 3.8.5 3.8.4 3.8.3 2.7 2.7.0.1 2.7.1 2.7.2 2.7.3 2.7.4 2.8 2.8.1 2.8.2 2.8.3 2.8.4 2.9 2.9.1 2.9.2 3.0 3.0.1 3.0.2 3.0.3 All 233 releases
polylang / include / links-permalinks.php

links-permalinks.php in Polylang 1.8, at include/links-permalinks.php

96 lines 2.7 KB
No matching file
Up and down to move Enter to open Esc to close
Raw Download Zip
1 <?php
2
3 /*
4 * links model base class when using pretty permalinks
5 *
6 * @since 1.6
7 */
8 abstract class PLL_Links_Permalinks extends PLL_Links_Model {
9 public $using_permalinks = true;
10 protected $index = 'index.php'; // need this before $wp_rewrite is created, also harcoded in wp-includes/rewrite.php
11 protected $root, $use_trailing_slashes;
12 protected $always_rewrite = array( 'date', 'root', 'comments', 'search', 'author' );
13
14 /*
15 * constructor
16 *
17 * @since 1.8
18 *
19 * @param object $model PLL_Model instance
20 */
21 public function __construct( &$model ) {
22 parent::__construct( $model );
23
24 // inspired by wp-includes/rewrite.php
25 $permalink_structure = get_option( 'permalink_structure' );
26 $this->root = preg_match( '#^/*' . $this->index . '#', $permalink_structure ) ? $this->index . '/' : '';
27 $this->use_trailing_slashes = ( '/' == substr( $permalink_structure, -1, 1 ) );
28 }
29
30 /*
31 * returns the link to the first page when using pretty permalinks
32 *
33 * @since 1.2
34 *
35 * @param string $url url to modify
36 * @return string modified url
37 */
38 public function remove_paged_from_link( $url ) {
39 return preg_replace( '#\/page\/[0-9]+\/#', '/', $url ); // FIXME trailing slash ?
40 }
41
42 /*
43 * returns the link to the paged page when using pretty permalinks
44 *
45 * @since 1.5
46 *
47 * @param string $url url to modify
48 * @param int $page
49 * @return string modified url
50 */
51 public function add_paged_to_link( $url, $page ) {
52 return trailingslashit( $url ) . 'page/' . $page; // FIXME trailing slash ?
53 }
54
55 /*
56 * returns the home url
57 *
58 * @since 1.3.1
59 *
60 * @param object $lang PLL_Language object
61 * @return string
62 */
63 public function home_url( $lang ) {
64 return trailingslashit( parent::home_url( $lang ) );
65 }
66
67 /*
68 * returns the static front page url
69 *
70 * @since 1.8
71 *
72 * @param object $lang
73 * @return string
74 */
75 public function front_page_url( $lang ) {
76 if ( $this->options['hide_default'] && $lang->slug == $this->options['default_lang'] ) {
77 return trailingslashit( $this->home );
78 }
79 $url = home_url( $this->root . get_page_uri( $lang->page_on_front ) );
80 $url = $this->use_trailing_slashes ? trailingslashit( $url ) : untrailingslashit( $url );
81 return $this->options['force_lang'] ? $this->add_language_to_link( $url, $lang ) : $url;
82 }
83
84 /*
85 * prepares rewrite rules filters
86 *
87 * @since 1.6
88 */
89 public function get_rewrite_rules_filters() {
90 // make sure we have the right post types and taxonomies
91 $types = array_values( array_merge( $this->model->get_translated_post_types(), $this->model->get_translated_taxonomies(), $this->model->get_filtered_taxonomies() ) );
92 $types = array_merge( $this->always_rewrite, $types );
93 return apply_filters( 'pll_rewrite_rules', $types ); // allow plugins to add rewrite rules to the language filter
94 }
95 }
96