PluginProbe
Polylang / 3.3
Polylang v3.3
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
← All changes | include/links-permalinks.php +63 -29 2.83.3 View file →
@@ -3,29 +3,61 @@
3 3 * @package Polylang
4 4 */
5 5
6 6 /**
7 - * Links model base class when using pretty permalinks
7 + * Links model base class when using pretty permalinks.
8 8 *
9 9 * @since 1.6
10 10 */
11 11 abstract class PLL_Links_Permalinks extends PLL_Links_Model {
12 + /**
13 + * Tells this child class of PLL_Links_Model is for pretty permalinks.
14 + *
15 + * @var bool
16 + */
12 17 public $using_permalinks = true;
13 - protected $index = 'index.php'; // Need this before $wp_rewrite is created, also hardcoded in wp-includes/rewrite.php
14 - protected $root, $use_trailing_slashes;
18 +
19 + /**
20 + * The name of the index file which is the entry point to all requests.
21 + * We need this before the global $wp_rewrite is created.
22 + * Also hardcoded in WP_Rewrite.
23 + *
24 + * @var string
25 + */
26 + protected $index = 'index.php';
27 +
28 + /**
29 + * The prefix for all permalink structures.
30 + *
31 + * @var string
32 + */
33 + protected $root;
34 +
35 + /**
36 + * Whether to add trailing slashes.
37 + *
38 + * @var bool
39 + */
40 + protected $use_trailing_slashes;
41 +
42 + /**
43 + * The name of the rewrite rules to always modify.
44 + *
45 + * @var string[]
46 + */
15 47 protected $always_rewrite = array( 'date', 'root', 'comments', 'search', 'author' );
16 48
17 49 /**
18 - * Constructor
50 + * Constructor.
19 51 *
20 52 * @since 1.8
21 53 *
22 - * @param object $model PLL_Model instance
54 + * @param PLL_Model $model PLL_Model instance.
23 55 */
24 56 public function __construct( &$model ) {
25 57 parent::__construct( $model );
26 58
27 - // Inspired by wp-includes/rewrite.php
59 + // Inspired by WP_Rewrite.
28 60 $permalink_structure = get_option( 'permalink_structure' );
29 61 $this->root = preg_match( '#^/*' . $this->index . '#', $permalink_structure ) ? $this->index . '/' : '';
30 62 $this->use_trailing_slashes = ( '/' == substr( $permalink_structure, -1, 1 ) );
31 63 }
@@ -30,55 +62,55 @@
30 62 $this->use_trailing_slashes = ( '/' == substr( $permalink_structure, -1, 1 ) );
31 63 }
32 64
33 65 /**
34 - * Returns the link to the first page when using pretty permalinks
66 + * Returns the link to the first page when using pretty permalinks.
35 67 *
36 68 * @since 1.2
37 69 *
38 - * @param string $url url to modify
39 - * @return string modified url
70 + * @param string $url The url to modify.
71 + * @return string The modified url.
40 72 */
41 73 public function remove_paged_from_link( $url ) {
42 74 /**
43 - * Filter an url after the paged part has been removed
75 + * Filters an url after the paged part has been removed.
44 76 *
45 77 * @since 2.0.6
46 78 *
47 - * @param string $modified_url The link to the first page
48 - * @param string $original_url The link to the original paged page
79 + * @param string $modified_url The link to the first page.
80 + * @param string $original_url The link to the original paged page.
49 81 */
50 82 return apply_filters( 'pll_remove_paged_from_link', preg_replace( '#/page/[0-9]+/?#', $this->use_trailing_slashes ? '/' : '', $url ), $url );
51 83 }
52 84
53 85 /**
54 - * Returns the link to the paged page when using pretty permalinks
86 + * Returns the link to the paged page when using pretty permalinks.
55 87 *
56 88 * @since 1.5
57 89 *
58 - * @param string $url url to modify
59 - * @param int $page
60 - * @return string modified url
90 + * @param string $url The url to modify.
91 + * @param int $page The page number.
92 + * @return string The modified url.
61 93 */
62 94 public function add_paged_to_link( $url, $page ) {
63 95 /**
64 - * Filter an url after the paged part has been added
96 + * Filters an url after the paged part has been added.
65 97 *
66 98 * @since 2.0.6
67 99 *
68 - * @param string $modified_url The link to the paged page
69 - * @param string $original_url The link to the original first page
70 - * @param int $page The page number
100 + * @param string $modified_url The link to the paged page.
101 + * @param string $original_url The link to the original first page.
102 + * @param int $page The page number.
71 103 */
72 104 return apply_filters( 'pll_add_paged_to_link', user_trailingslashit( trailingslashit( $url ) . 'page/' . $page, 'paged' ), $url, $page );
73 105 }
74 106
75 107 /**
76 - * Returns the home url
108 + * Returns the home url in a given language.
77 109 *
78 110 * @since 1.3.1
79 111 *
80 - * @param object $lang PLL_Language object
112 + * @param PLL_Language $lang A language object.
81 113 * @return string
82 114 */
83 115 public function home_url( $lang ) {
84 116 return trailingslashit( parent::home_url( $lang ) );
@@ -84,14 +116,14 @@
84 116 return trailingslashit( parent::home_url( $lang ) );
85 117 }
86 118
87 119 /**
88 - * Returns the static front page url
120 + * Returns the static front page url.
89 121 *
90 122 * @since 1.8
91 123 *
92 - * @param object $lang
93 - * @return string
124 + * @param PLL_Language $lang The language object.
125 + * @return string The static front page url.
94 126 */
95 127 public function front_page_url( $lang ) {
96 128 if ( $this->options['hide_default'] && $lang->slug == $this->options['default_lang'] ) {
97 129 return trailingslashit( $this->home );
@@ -101,23 +133,25 @@
101 133 return $this->options['force_lang'] ? $this->add_language_to_link( $url, $lang ) : $url;
102 134 }
103 135
104 136 /**
105 - * Prepares rewrite rules filters
137 + * Prepares rewrite rules filters.
106 138 *
107 139 * @since 1.6
140 + *
141 + * @return string[]
108 142 */
109 143 public function get_rewrite_rules_filters() {
110 - // Make sure we have the right post types and taxonomies
144 + // Make sure that we have the right post types and taxonomies.
111 145 $types = array_values( array_merge( $this->model->get_translated_post_types(), $this->model->get_translated_taxonomies(), $this->model->get_filtered_taxonomies() ) );
112 146 $types = array_merge( $this->always_rewrite, $types );
113 147
114 148 /**
115 - * Filter the list of rewrite rules filters to be used by Polylang
149 + * Filters the list of rewrite rules filters to be used by Polylang.
116 150 *
117 151 * @since 0.8.1
118 152 *
119 - * @param array $types the list of filters (without '_rewrite_rules' at the end)
153 + * @param array $types The list of filters (without '_rewrite_rules' at the end).
120 154 */
121 155 return apply_filters( 'pll_rewrite_rules', $types );
122 156 }
123 157 }