PluginProbe
Polylang / 2.1
Polylang v2.1
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 | settings/settings-url.php +80 -147 2.8.22.1 View file →
@@ -1,8 +1,5 @@
1 1 <?php
2 -/**
3 - * @package Polylang
4 - */
5 2
6 3 /**
7 4 * A class to manage URL modifications settings
8 5 *
@@ -8,14 +5,8 @@
8 5 *
9 6 * @since 1.8
10 7 */
11 8 class PLL_Settings_Url extends PLL_Settings_Module {
12 - /**
13 - * Stores the display order priority.
14 - *
15 - * @var int
16 - */
17 - public $priority = 10;
18 9
19 10 /**
20 11 * Constructor
21 12 *
@@ -23,17 +14,14 @@
23 14 *
24 15 * @param object $polylang
25 16 */
26 17 public function __construct( &$polylang ) {
27 - parent::__construct(
28 - $polylang,
29 - array(
30 - 'module' => 'url',
31 - 'title' => __( 'URL modifications', 'polylang' ),
32 - 'description' => __( 'Decide how your URLs will look like.', 'polylang' ),
33 - 'configure' => true,
34 - )
35 - );
18 + parent::__construct( $polylang, array(
19 + 'module' => 'url',
20 + 'title' => __( 'URL modifications', 'polylang' ),
21 + 'description' => __( 'Decide how your URLs will look like.', 'polylang' ),
22 + 'configure' => true,
23 + ) );
36 24
37 25 $this->links_model = &$polylang->links_model;
38 26 $this->page_on_front = &$polylang->static_pages->page_on_front;
39 27 }
@@ -42,66 +30,53 @@
42 30 * Displays the fieldset to choose how the language is set
43 31 *
44 32 * @since 1.8
45 33 */
46 - protected function force_lang() {
47 - ?>
48 - <label>
49 - <?php
34 + protected function force_lang() {?>
35 + <label><?php
50 36 printf(
51 37 '<input name="force_lang" type="radio" value="0" %s /> %s',
52 - checked( $this->options['force_lang'], 0, false ),
38 + $this->options['force_lang'] ? '' : 'checked="checked"',
53 39 esc_html__( 'The language is set from content', 'polylang' )
54 - );
55 - ?>
40 + );?>
56 41 </label>
57 - <p class="description"><?php esc_html_e( 'Posts, pages, categories and tags URLs will not be modified.', 'polylang' ); ?></p>
58 - <label>
59 - <?php
42 + <p class="description"><?php esc_html_e( 'Posts, pages, categories and tags urls are not modified.', 'polylang' );?></p>
43 + <label><?php
60 44 printf(
61 45 '<input name="force_lang" type="radio" value="1" %s/> %s',
62 - checked( $this->options['force_lang'], 1, false ),
63 - ( $this->links_model->using_permalinks ? esc_html__( 'The language is set from the directory name in pretty permalinks', 'polylang' ) : esc_html__( 'The language is set from the code in the URL', 'polylang' ) )
64 - );
65 - ?>
46 + 1 == $this->options['force_lang'] ? 'checked="checked"' : '',
47 + $this->links_model->using_permalinks ? esc_html__( 'The language is set from the directory name in pretty permalinks', 'polylang' ) : esc_html__( 'The language is set from the code in the URL', 'polylang' )
48 + );?>
66 49 </label>
67 - <p class="description"><?php echo esc_html__( 'Example:', 'polylang' ) . ' <code>' . esc_html( home_url( $this->links_model->using_permalinks ? 'en/my-post/' : '?lang=en&p=1' ) ) . '</code>'; ?></p>
68 - <label>
69 - <?php
50 + <p class="description"><?php echo esc_html__( 'Example:', 'polylang' ) . ' <code>' . esc_html( home_url( $this->links_model->using_permalinks ? 'en/my-post/' : '?lang=en&p=1' ) ) . '</code>';?></p>
51 + <label><?php
70 52 printf(
71 53 '<input name="force_lang" type="radio" value="2" %s %s/> %s',
72 - disabled( $this->links_model->using_permalinks, false, false ),
73 - checked( $this->options['force_lang'], 2, false ),
54 + $this->links_model->using_permalinks ? '' : 'disabled="disabled"',
55 + 2 == $this->options['force_lang'] ? 'checked="checked"' : '',
74 56 esc_html__( 'The language is set from the subdomain name in pretty permalinks', 'polylang' )
75 - );
76 - ?>
57 + );?>
77 58 </label>
78 - <p class="description"><?php echo esc_html__( 'Example:', 'polylang' ) . ' <code>' . esc_html( str_replace( array( '://', 'www.' ), array( '://en.', '' ), home_url( 'my-post/' ) ) ) . '</code>'; ?></p>
79 - <label>
80 - <?php
59 + <p class="description"><?php echo esc_html__( 'Example:', 'polylang' ) . ' <code>' . esc_html( str_replace( array( '://', 'www.' ), array( '://en.', '' ), home_url( 'my-post/' ) ) ) . '</code>';?></p>
60 + <label><?php
81 61 printf(
82 62 '<input name="force_lang" type="radio" value="3" %s %s/> %s',
83 - disabled( $this->links_model->using_permalinks, false, false ),
84 - checked( $this->options['force_lang'], 3, false ),
63 + $this->links_model->using_permalinks ? '' : 'disabled="disabled"',
64 + 3 == $this->options['force_lang'] ? 'checked="checked"' : '',
85 65 esc_html__( 'The language is set from different domains', 'polylang' )
86 - );
87 - ?>
66 + );?>
88 67 </label>
89 - <table id="pll-domains-table" class="form-table" <?php echo 3 == $this->options['force_lang'] ? '' : 'style="display: none;"'; ?>>
90 - <?php
68 + <table id="pll-domains-table" class="form-table" <?php echo 3 == $this->options['force_lang'] ? '' : 'style="display: none;"'; ?>><?php
91 69 foreach ( $this->model->get_languages_list() as $lg ) {
92 - $url = isset( $this->options['domains'][ $lg->slug ] ) ? $this->options['domains'][ $lg->slug ] : ( $lg->slug == $this->options['default_lang'] ? $this->links_model->home : '' );
93 70 printf(
94 71 '<tr><td><label for="pll-domain[%1$s]">%2$s</label></td>' .
95 72 '<td><input name="domains[%1$s]" id="pll-domain[%1$s]" type="text" value="%3$s" class="regular-text code" aria-required="true" /></td></tr>',
96 73 esc_attr( $lg->slug ),
97 74 esc_attr( $lg->name ),
98 - esc_url( $url )
75 + esc_url( isset( $this->options['domains'][ $lg->slug ] ) ? $this->options['domains'][ $lg->slug ] : ( $lg->slug == $this->options['default_lang'] ? $this->links_model->home : '' ) )
99 76 );
100 - }
101 - ?>
102 - </table>
103 - <?php
77 + }?>
78 + </table><?php
104 79 }
105 80
106 81 /**
107 82 * Displays the fieldset to choose to hide the default language information in url
@@ -107,20 +82,16 @@
107 82 * Displays the fieldset to choose to hide the default language information in url
108 83 *
109 84 * @since 1.8
110 85 */
111 - protected function hide_default() {
112 - ?>
113 - <label>
114 - <?php
86 + protected function hide_default() { ?>
87 + <label><?php
115 88 printf(
116 89 '<input name="hide_default" type="checkbox" value="1" %s /> %s',
117 - checked( $this->options['hide_default'], 1, false ),
90 + $this->options['hide_default'] ? 'checked="checked"' :'',
118 91 esc_html__( 'Hide URL language information for default language', 'polylang' )
119 - );
120 - ?>
121 - </label>
122 - <?php
92 + );?>
93 + </label><?php
123 94 }
124 95
125 96 /**
126 97 * Displays the fieldset to choose to hide /language/ in url
@@ -126,33 +97,27 @@
126 97 * Displays the fieldset to choose to hide /language/ in url
127 98 *
128 99 * @since 1.8
129 100 */
130 - protected function rewrite() {
131 - ?>
132 - <label>
133 - <?php
101 + protected function rewrite() {?>
102 + <label><?php
134 103 printf(
135 104 '<input name="rewrite" type="radio" value="1" %s %s/> %s',
136 - disabled( $this->links_model->using_permalinks, false, false ),
137 - checked( $this->options['rewrite'], 1, false ),
105 + $this->links_model->using_permalinks ? '' : 'disabled="disabled"',
106 + $this->options['rewrite'] ? 'checked="checked"' : '',
138 107 esc_html__( 'Remove /language/ in pretty permalinks', 'polylang' )
139 - );
140 - ?>
108 + );?>
141 109 </label>
142 - <p class="description"><?php echo esc_html__( 'Example:', 'polylang' ) . ' <code>' . esc_html( home_url( 'en/' ) ) . '</code>'; ?></p>
143 - <label>
144 - <?php
110 + <p class="description"><?php echo esc_html__( 'Example:', 'polylang' ) . ' <code>' . esc_html( home_url( 'en/' ) ) . '</code>';?></p>
111 + <label><?php
145 112 printf(
146 113 '<input name="rewrite" type="radio" value="0" %s %s/> %s',
147 - disabled( $this->links_model->using_permalinks, false, false ),
148 - checked( $this->options['rewrite'], 0, false ),
114 + $this->links_model->using_permalinks ? '' : 'disabled="disabled"',
115 + $this->options['rewrite'] ? '' : 'checked="checked"',
149 116 esc_html__( 'Keep /language/ in pretty permalinks', 'polylang' )
150 - );
151 - ?>
117 + );?>
152 118 </label>
153 - <p class="description"><?php echo esc_html__( 'Example:', 'polylang' ) . ' <code>' . esc_html( home_url( 'language/en/' ) ) . '</code>'; ?></p>
154 - <?php
119 + <p class="description"><?php echo esc_html__( 'Example:', 'polylang' ) . ' <code>' . esc_html( home_url( 'language/en/' ) ) . '</code>';?></p><?php
155 120 }
156 121
157 122 /**
158 123 * Displays the fieldset to choose to redirect the home page to language page
@@ -158,33 +123,27 @@
158 123 * Displays the fieldset to choose to redirect the home page to language page
159 124 *
160 125 * @since 1.8
161 126 */
162 - protected function redirect_lang() {
163 - ?>
164 - <label>
165 - <?php
127 + protected function redirect_lang() { ?>
128 + <label><?php
166 129 printf(
167 130 '<input name="redirect_lang" type="checkbox" value="1" %s/> %s',
168 - checked( $this->options['redirect_lang'], 1, false ),
131 + $this->options['redirect_lang'] ? 'checked="checked"' :'',
169 132 esc_html__( 'The front page url contains the language code instead of the page name or page id', 'polylang' )
170 - );
171 - ?>
133 + );?>
172 134 </label>
173 - <p class="description">
174 - <?php
135 + <p class="description"><?php
175 136 // That's nice to display the right home urls but don't forget that the page on front may have no language yet
176 137 $lang = $this->model->post->get_language( $this->page_on_front );
177 138 $lang = $lang ? $lang : $this->model->get_language( $this->options['default_lang'] );
178 139 printf(
179 - /* translators: %1$s example url when the option is active. %2$s example url when the option is not active */
180 - esc_html__( 'Example: %1$s instead of %2$s', 'polylang' ),
140 + /* translators: %s are urls */
141 + esc_html__( 'Example: %s instead of %s', 'polylang' ),
181 142 '<code>' . esc_html( $this->links_model->home_url( $lang ) ) . '</code>',
182 143 '<code>' . esc_html( _get_page_link( $this->page_on_front ) ) . '</code>'
183 - );
184 - ?>
185 - </p>
186 - <?php
144 + ); ?>
145 + </p><?php
187 146 }
188 147
189 148 /**
190 149 * Displays the settings
@@ -190,39 +149,32 @@
190 149 * Displays the settings
191 150 *
192 151 * @since 1.8
193 152 */
194 - public function form() {
195 - ?>
153 + public function form() { ?>
196 154 <div class="pll-settings-url-col">
197 - <fieldset class="pll-col-left pll-url" id="pll-force-lang">
198 - <?php $this->force_lang(); ?>
155 + <fieldset class="pll-col-left pll-url" id="pll-force-lang"><?php
156 + $this->force_lang(); ?>
199 157 </fieldset>
200 158 </div>
201 159
202 160 <div class="pll-settings-url-col">
203 - <fieldset class="pll-col-right pll-url" id="pll-hide-default" <?php echo 3 > $this->options['force_lang'] ? '' : 'style="display: none;"'; ?>>
204 - <?php $this->hide_default(); ?>
205 - </fieldset>
206 - <?php
207 - if ( $this->links_model->using_permalinks ) {
208 - ?>
209 - <fieldset class="pll-col-right pll-url" id="pll-rewrite" <?php echo 2 > $this->options['force_lang'] ? '' : 'style="display: none;"'; ?>>
210 - <?php $this->rewrite(); ?>
211 - </fieldset>
212 - <?php
161 + <fieldset class="pll-col-right pll-url" id="pll-hide-default" <?php echo 3 > $this->options['force_lang'] ? '' : 'style="display: none;"'; ?>><?php
162 + $this->hide_default(); ?>
163 + </fieldset><?php
164 +
165 + if ( $this->links_model->using_permalinks ) { ?>
166 + <fieldset class="pll-col-right pll-url" id="pll-rewrite" <?php echo 2 > $this->options['force_lang'] ? '' : 'style="display: none;"'; ?>><?php
167 + $this->rewrite(); ?>
168 + </fieldset><?php
213 169 }
214 170
215 - if ( $this->page_on_front ) {
216 - ?>
217 - <fieldset class="pll-col-right pll-url" id="pll-redirect-lang" <?php echo 2 > $this->options['force_lang'] ? '' : 'style="display: none;"'; ?>>
218 - <?php $this->redirect_lang(); ?>
219 - </fieldset>
220 - <?php
221 - }
222 - ?>
223 - </div>
224 - <?php
171 + if ( $this->page_on_front ) { ?>
172 + <fieldset class="pll-col-right pll-url" id="pll-redirect-lang"><?php
173 + $this->redirect_lang(); ?>
174 + </fieldset><?php
175 + } ?>
176 + </div><?php
225 177 }
226 178
227 179 /**
228 180 * Sanitizes the settings before saving
@@ -231,10 +183,8 @@
231 183 *
232 184 * @param array $options
233 185 */
234 186 protected function update( $options ) {
235 - $newoptions = array();
236 -
237 187 foreach ( array( 'force_lang', 'rewrite' ) as $key ) {
238 188 $newoptions[ $key ] = isset( $options[ $key ] ) ? (int) $options[ $key ] : 0;
239 189 }
240 190
@@ -241,19 +191,12 @@
241 191 if ( 3 == $options['force_lang'] && isset( $options['domains'] ) && is_array( $options['domains'] ) ) {
242 192 foreach ( $options['domains'] as $key => $domain ) {
243 193 if ( empty( $domain ) ) {
244 194 $lang = $this->model->get_language( $key );
245 - add_settings_error(
246 - 'general',
247 - 'pll_invalid_domain',
248 - esc_html(
249 - sprintf(
250 - /* translators: %s is a native language name */
251 - __( 'Please enter a valid URL for %s.', 'polylang' ),
252 - $lang->name
253 - )
254 - )
255 - );
195 + add_settings_error( 'general', 'pll_invalid_domain', esc_html( sprintf(
196 + /* translators: %s is a native language name */
197 + __( 'Please enter a valid URL for %s.', 'polylang' ), $lang->name
198 + ) ) );
256 199 }
257 200 else {
258 201 $newoptions['domains'][ $key ] = esc_url_raw( trim( $domain ) );
259 202 }
@@ -264,12 +207,9 @@
264 207 $newoptions[ $key ] = isset( $options[ $key ] ) ? 1 : 0;
265 208 }
266 209
267 210 if ( 3 == $options['force_lang'] ) {
268 - if ( ! class_exists( 'PLL_Xdata_Domain', true ) ) {
269 - $newoptions['browser'] = 0;
270 - }
271 - $newoptions['hide_default'] = 0;
211 + $newoptions['browser'] = $newoptions['hide_default'] = 0;
272 212 }
273 213
274 214 // Check if domains exist
275 215 if ( $newoptions['force_lang'] > 1 ) {
@@ -296,19 +236,12 @@
296 236 $response = function_exists( 'vip_safe_wp_remote_get' ) ? vip_safe_wp_remote_get( esc_url_raw( $url ) ) : wp_remote_get( esc_url_raw( $url ) );
297 237 $response_code = wp_remote_retrieve_response_code( $response );
298 238
299 239 if ( 200 != $response_code ) {
300 - add_settings_error(
301 - 'general',
302 - 'pll_invalid_domain',
303 - esc_html(
304 - sprintf(
305 - /* translators: %s is an url */
306 - __( 'Polylang was unable to access the %s URL. Please check that the URL is valid.', 'polylang' ),
307 - $url
308 - )
309 - )
310 - );
240 + add_settings_error( 'general', 'pll_invalid_domain', esc_html( sprintf(
241 + /* translators: %s is an url */
242 + __( 'Polylang was unable to access the URL %s. Please check that the URL is valid.', 'polylang' ), $url
243 + ) ) );
311 244 }
312 245 }
313 246 }
314 247 }