PluginProbe
Polylang / 2.3
Polylang v2.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 | settings/settings-url.php +30 -60 2.82.3 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,26 +30,25 @@
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 - ?>
34 + protected function force_lang() {?>
48 35 <label>
49 36 <?php
50 37 printf(
51 38 '<input name="force_lang" type="radio" value="0" %s /> %s',
52 - checked( $this->options['force_lang'], 0, false ),
39 + $this->options['force_lang'] ? '' : 'checked="checked"',
53 40 esc_html__( 'The language is set from content', 'polylang' )
54 41 );
55 42 ?>
56 43 </label>
57 - <p class="description"><?php esc_html_e( 'Posts, pages, categories and tags URLs will not be modified.', 'polylang' ); ?></p>
44 + <p class="description"><?php esc_html_e( 'Posts, pages, categories and tags urls are not modified.', 'polylang' ); ?></p>
58 45 <label>
59 46 <?php
60 47 printf(
61 48 '<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' ) )
49 + 1 == $this->options['force_lang'] ? 'checked="checked"' : '',
50 + $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 51 );
65 52 ?>
66 53 </label>
67 54 <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,10 +55,10 @@
68 55 <label>
69 56 <?php
70 57 printf(
71 58 '<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 ),
59 + $this->links_model->using_permalinks ? '' : 'disabled="disabled"',
60 + 2 == $this->options['force_lang'] ? 'checked="checked"' : '',
74 61 esc_html__( 'The language is set from the subdomain name in pretty permalinks', 'polylang' )
75 62 );
76 63 ?>
77 64 </label>
@@ -79,10 +66,10 @@
79 66 <label>
80 67 <?php
81 68 printf(
82 69 '<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 ),
70 + $this->links_model->using_permalinks ? '' : 'disabled="disabled"',
71 + 3 == $this->options['force_lang'] ? 'checked="checked"' : '',
85 72 esc_html__( 'The language is set from different domains', 'polylang' )
86 73 );
87 74 ?>
88 75 </label>
@@ -88,15 +75,14 @@
88 75 </label>
89 76 <table id="pll-domains-table" class="form-table" <?php echo 3 == $this->options['force_lang'] ? '' : 'style="display: none;"'; ?>>
90 77 <?php
91 78 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 79 printf(
94 80 '<tr><td><label for="pll-domain[%1$s]">%2$s</label></td>' .
95 81 '<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 82 esc_attr( $lg->slug ),
97 83 esc_attr( $lg->name ),
98 - esc_url( $url )
84 + esc_url( isset( $this->options['domains'][ $lg->slug ] ) ? $this->options['domains'][ $lg->slug ] : ( $lg->slug == $this->options['default_lang'] ? $this->links_model->home : '' ) )
99 85 );
100 86 }
101 87 ?>
102 88 </table>
@@ -113,9 +99,9 @@
113 99 <label>
114 100 <?php
115 101 printf(
116 102 '<input name="hide_default" type="checkbox" value="1" %s /> %s',
117 - checked( $this->options['hide_default'], 1, false ),
103 + $this->options['hide_default'] ? 'checked="checked"' : '',
118 104 esc_html__( 'Hide URL language information for default language', 'polylang' )
119 105 );
120 106 ?>
121 107 </label>
@@ -132,10 +118,10 @@
132 118 <label>
133 119 <?php
134 120 printf(
135 121 '<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 ),
122 + $this->links_model->using_permalinks ? '' : 'disabled="disabled"',
123 + $this->options['rewrite'] ? 'checked="checked"' : '',
138 124 esc_html__( 'Remove /language/ in pretty permalinks', 'polylang' )
139 125 );
140 126 ?>
141 127 </label>
@@ -143,10 +129,10 @@
143 129 <label>
144 130 <?php
145 131 printf(
146 132 '<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 ),
133 + $this->links_model->using_permalinks ? '' : 'disabled="disabled"',
134 + $this->options['rewrite'] ? '' : 'checked="checked"',
149 135 esc_html__( 'Keep /language/ in pretty permalinks', 'polylang' )
150 136 );
151 137 ?>
152 138 </label>
@@ -164,9 +150,9 @@
164 150 <label>
165 151 <?php
166 152 printf(
167 153 '<input name="redirect_lang" type="checkbox" value="1" %s/> %s',
168 - checked( $this->options['redirect_lang'], 1, false ),
154 + $this->options['redirect_lang'] ? 'checked="checked"' : '',
169 155 esc_html__( 'The front page url contains the language code instead of the page name or page id', 'polylang' )
170 156 );
171 157 ?>
172 158 </label>
@@ -231,10 +217,8 @@
231 217 *
232 218 * @param array $options
233 219 */
234 220 protected function update( $options ) {
235 - $newoptions = array();
236 -
237 221 foreach ( array( 'force_lang', 'rewrite' ) as $key ) {
238 222 $newoptions[ $key ] = isset( $options[ $key ] ) ? (int) $options[ $key ] : 0;
239 223 }
240 224
@@ -241,19 +225,12 @@
241 225 if ( 3 == $options['force_lang'] && isset( $options['domains'] ) && is_array( $options['domains'] ) ) {
242 226 foreach ( $options['domains'] as $key => $domain ) {
243 227 if ( empty( $domain ) ) {
244 228 $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 - );
229 + add_settings_error( 'general', 'pll_invalid_domain', esc_html( sprintf(
230 + /* translators: %s is a native language name */
231 + __( 'Please enter a valid URL for %s.', 'polylang' ), $lang->name
232 + ) ) );
256 233 }
257 234 else {
258 235 $newoptions['domains'][ $key ] = esc_url_raw( trim( $domain ) );
259 236 }
@@ -296,19 +273,12 @@
296 273 $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 274 $response_code = wp_remote_retrieve_response_code( $response );
298 275
299 276 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 - );
277 + add_settings_error( 'general', 'pll_invalid_domain', esc_html( sprintf(
278 + /* translators: %s is an url */
279 + __( 'Polylang was unable to access the URL %s. Please check that the URL is valid.', 'polylang' ), $url
280 + ) ) );
311 281 }
312 282 }
313 283 }
314 284 }