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