Version Description
Aug 02, 2021 =
-
Bugs
- Plugin not save persian alphabet
- 404 error when post/page custom permalink is part of category custom permalink
Download this release
Release Info
Developer | sasiddiqui |
Plugin | Custom Permalinks |
Version | 2.0.1 |
Comparing to | |
See all releases |
Code changes from version 2.0.0 to 2.0.1
- assets/css/{about-plugins-2.0.0.min.css → about-plugins-2.0.1.min.css} +0 -0
- assets/js/{script-form-2.0.0.min.js → script-form-2.0.1.min.js} +0 -0
- custom-permalinks.php +1 -1
- includes/class-custom-permalinks-form.php +124 -23
- includes/class-custom-permalinks-frontend.php +40 -28
- includes/class-custom-permalinks.php +1 -1
- readme.txt +19 -2
assets/css/{about-plugins-2.0.0.min.css → about-plugins-2.0.1.min.css}
RENAMED
File without changes
|
assets/js/{script-form-2.0.0.min.js → script-form-2.0.1.min.js}
RENAMED
File without changes
|
custom-permalinks.php
CHANGED
@@ -3,7 +3,7 @@
|
|
3 |
* Plugin Name: Custom Permalinks
|
4 |
* Plugin URI: https://www.custompermalinks.com/
|
5 |
* Description: Set custom permalinks on a per-post basis.
|
6 |
-
* Version: 2.0.
|
7 |
* Requires at least: 2.6
|
8 |
* Requires PHP: 5.4
|
9 |
* Author: Sami Ahmed Siddiqui
|
3 |
* Plugin Name: Custom Permalinks
|
4 |
* Plugin URI: https://www.custompermalinks.com/
|
5 |
* Description: Set custom permalinks on a per-post basis.
|
6 |
+
* Version: 2.0.1
|
7 |
* Requires at least: 2.6
|
8 |
* Requires PHP: 5.4
|
9 |
* Author: Sami Ahmed Siddiqui
|
includes/class-custom-permalinks-form.php
CHANGED
@@ -165,12 +165,39 @@ class Custom_Permalinks_Form {
|
|
165 |
* @since 2.0.0
|
166 |
* @access private
|
167 |
*
|
168 |
-
* @param string
|
|
|
169 |
*
|
170 |
* @return string Sanitized permalink.
|
171 |
*/
|
172 |
-
private function sanitize_permalink( $permalink ) {
|
173 |
-
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
174 |
$permalink = wp_strip_all_tags( $permalink );
|
175 |
// Preserve escaped octets.
|
176 |
$permalink = preg_replace( '|%([a-fA-F0-9][a-fA-F0-9])|', '---$1---', $permalink );
|
@@ -179,18 +206,18 @@ class Custom_Permalinks_Form {
|
|
179 |
// Restore octets.
|
180 |
$permalink = preg_replace( '|---([a-fA-F0-9][a-fA-F0-9])---|', '%$1', $permalink );
|
181 |
|
182 |
-
|
183 |
-
|
184 |
-
* disabled.
|
185 |
-
*/
|
186 |
-
$allow_caps = apply_filters( 'custom_permalinks_allow_caps', false );
|
187 |
-
if ( ! is_bool( $allow_caps ) && ! $allow_caps ) {
|
188 |
-
if ( seems_utf8( $permalink ) ) {
|
189 |
if ( function_exists( 'mb_strtolower' ) ) {
|
190 |
-
|
|
|
|
|
191 |
}
|
192 |
$permalink = utf8_uri_encode( $permalink );
|
193 |
}
|
|
|
|
|
|
|
194 |
$permalink = strtolower( $permalink );
|
195 |
}
|
196 |
|
@@ -243,18 +270,61 @@ class Custom_Permalinks_Form {
|
|
243 |
$permalink
|
244 |
);
|
245 |
|
246 |
-
|
247 |
$permalink = str_replace( '%c3%97', 'x', $permalink );
|
248 |
-
|
249 |
// Kill entities.
|
250 |
$permalink = preg_replace( '/&.+?;/', '', $permalink );
|
251 |
|
252 |
-
//
|
253 |
-
if (
|
254 |
-
|
|
|
|
|
|
|
|
|
|
|
|
|
255 |
} else {
|
256 |
-
|
257 |
-
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
258 |
}
|
259 |
|
260 |
// Allow only dot that are coming before any alphabet.
|
@@ -287,11 +357,12 @@ class Custom_Permalinks_Form {
|
|
287 |
*
|
288 |
* @access public
|
289 |
*
|
290 |
-
* @param int
|
|
|
291 |
*
|
292 |
* @return void
|
293 |
*/
|
294 |
-
public function save_post( $post_id ) {
|
295 |
if ( ! isset( $_REQUEST['_custom_permalinks_post_nonce'] )
|
296 |
&& ! isset( $_REQUEST['custom_permalink'] )
|
297 |
) {
|
@@ -310,8 +381,21 @@ class Custom_Permalinks_Form {
|
|
310 |
if ( ! empty( $_REQUEST['custom_permalink'] )
|
311 |
&& $_REQUEST['custom_permalink'] !== $original_link
|
312 |
) {
|
313 |
-
|
314 |
-
$
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
315 |
$permalink = apply_filters(
|
316 |
'custom_permalink_before_saving',
|
317 |
$permalink,
|
@@ -670,7 +754,24 @@ class Custom_Permalinks_Form {
|
|
670 |
|
671 |
$this->delete_term_permalink( $term_id );
|
672 |
|
673 |
-
$
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
674 |
$table = get_option( 'custom_permalink_table' );
|
675 |
|
676 |
if ( $permalink && ! array_key_exists( $permalink, $table ) ) {
|
165 |
* @since 2.0.0
|
166 |
* @access private
|
167 |
*
|
168 |
+
* @param string $permalink String that needs to be sanitized.
|
169 |
+
* @param string|null $language_code Language code.
|
170 |
*
|
171 |
* @return string Sanitized permalink.
|
172 |
*/
|
173 |
+
private function sanitize_permalink( $permalink, $language_code ) {
|
174 |
+
/*
|
175 |
+
* Add Capability to allow Accents letter (if required). By default, It is
|
176 |
+
* disabled.
|
177 |
+
*/
|
178 |
+
$check_accents_filter = apply_filters( 'custom_permalinks_allow_accents', false );
|
179 |
+
|
180 |
+
/*
|
181 |
+
* Add Capability to allow Capital letter (if required). By default, It is
|
182 |
+
* disabled.
|
183 |
+
*/
|
184 |
+
$check_caps_filter = apply_filters( 'custom_permalinks_allow_caps', false );
|
185 |
+
|
186 |
+
$allow_accents = false;
|
187 |
+
$allow_caps = false;
|
188 |
+
|
189 |
+
if ( is_bool( $check_accents_filter ) && $check_accents_filter ) {
|
190 |
+
$allow_accents = $check_accents_filter;
|
191 |
+
}
|
192 |
+
|
193 |
+
if ( is_bool( $check_caps_filter ) && $check_caps_filter ) {
|
194 |
+
$allow_caps = $check_caps_filter;
|
195 |
+
}
|
196 |
+
|
197 |
+
if ( ! $allow_accents ) {
|
198 |
+
$permalink = remove_accents( $permalink );
|
199 |
+
}
|
200 |
+
|
201 |
$permalink = wp_strip_all_tags( $permalink );
|
202 |
// Preserve escaped octets.
|
203 |
$permalink = preg_replace( '|%([a-fA-F0-9][a-fA-F0-9])|', '---$1---', $permalink );
|
206 |
// Restore octets.
|
207 |
$permalink = preg_replace( '|---([a-fA-F0-9][a-fA-F0-9])---|', '%$1', $permalink );
|
208 |
|
209 |
+
if ( seems_utf8( $permalink ) ) {
|
210 |
+
if ( ! $allow_accents ) {
|
|
|
|
|
|
|
|
|
|
|
211 |
if ( function_exists( 'mb_strtolower' ) ) {
|
212 |
+
if ( ! $allow_caps ) {
|
213 |
+
$permalink = mb_strtolower( $permalink, 'UTF-8' );
|
214 |
+
}
|
215 |
}
|
216 |
$permalink = utf8_uri_encode( $permalink );
|
217 |
}
|
218 |
+
}
|
219 |
+
|
220 |
+
if ( ! $allow_caps ) {
|
221 |
$permalink = strtolower( $permalink );
|
222 |
}
|
223 |
|
270 |
$permalink
|
271 |
);
|
272 |
|
273 |
+
// Convert × to 'x'.
|
274 |
$permalink = str_replace( '%c3%97', 'x', $permalink );
|
|
|
275 |
// Kill entities.
|
276 |
$permalink = preg_replace( '/&.+?;/', '', $permalink );
|
277 |
|
278 |
+
// Avoid removing characters of other languages like persian etc.
|
279 |
+
if ( 'en' === $language_code || strpos( $language_code, 'en_' ) === 0 ) {
|
280 |
+
// Allow Alphanumeric and few symbols only.
|
281 |
+
if ( ! $allow_caps ) {
|
282 |
+
$permalink = preg_replace( '/[^%a-z0-9 \.\/_-]/', '', $permalink );
|
283 |
+
} else {
|
284 |
+
// Allow Capital letters.
|
285 |
+
$permalink = preg_replace( '/[^%a-zA-Z0-9 \.\/_-]/', '', $permalink );
|
286 |
+
}
|
287 |
} else {
|
288 |
+
$reserved_chars = array(
|
289 |
+
'(',
|
290 |
+
')',
|
291 |
+
'[',
|
292 |
+
']',
|
293 |
+
);
|
294 |
+
$unsafe_chars = array(
|
295 |
+
'<',
|
296 |
+
'>',
|
297 |
+
'{',
|
298 |
+
'}',
|
299 |
+
'|',
|
300 |
+
'`',
|
301 |
+
'^',
|
302 |
+
'\\',
|
303 |
+
);
|
304 |
+
|
305 |
+
$permalink = str_replace( $reserved_chars, '', $permalink );
|
306 |
+
$permalink = str_replace( $unsafe_chars, '', $permalink );
|
307 |
+
// phpcs:ignore WordPress.PHP.DiscouragedPHPFunctions.urlencode_urlencode
|
308 |
+
$permalink = urlencode( $permalink );
|
309 |
+
// Replace encoded slash input with slash.
|
310 |
+
$permalink = str_replace( '%2F', '/', $permalink );
|
311 |
+
|
312 |
+
$replace_hyphen = array( '%20', '%2B', '+' );
|
313 |
+
$split_path = explode( '%3F', $permalink );
|
314 |
+
if ( 1 < count( $split_path ) ) {
|
315 |
+
// Replace encoded space and plus input with hyphen.
|
316 |
+
$replaced_path = str_replace( $replace_hyphen, '-', $split_path[0] );
|
317 |
+
$replaced_path = preg_replace( '/(\-+)/', '-', $replaced_path );
|
318 |
+
$permalink = str_replace(
|
319 |
+
$split_path[0],
|
320 |
+
$replaced_path,
|
321 |
+
$permalink
|
322 |
+
);
|
323 |
+
} else {
|
324 |
+
// Replace encoded space and plus input with hyphen.
|
325 |
+
$permalink = str_replace( $replace_hyphen, '-', $permalink );
|
326 |
+
$permalink = preg_replace( '/(\-+)/', '-', $permalink );
|
327 |
+
}
|
328 |
}
|
329 |
|
330 |
// Allow only dot that are coming before any alphabet.
|
357 |
*
|
358 |
* @access public
|
359 |
*
|
360 |
+
* @param int $post_id Post ID.
|
361 |
+
* @param WP_Post $post Post object.
|
362 |
*
|
363 |
* @return void
|
364 |
*/
|
365 |
+
public function save_post( $post_id, $post ) {
|
366 |
if ( ! isset( $_REQUEST['_custom_permalinks_post_nonce'] )
|
367 |
&& ! isset( $_REQUEST['custom_permalink'] )
|
368 |
) {
|
381 |
if ( ! empty( $_REQUEST['custom_permalink'] )
|
382 |
&& $_REQUEST['custom_permalink'] !== $original_link
|
383 |
) {
|
384 |
+
$language_code = get_locale();
|
385 |
+
$language_code = apply_filters(
|
386 |
+
'wpml_element_language_code',
|
387 |
+
null,
|
388 |
+
array(
|
389 |
+
'element_id' => $post_id,
|
390 |
+
'element_type' => $post->post_type,
|
391 |
+
)
|
392 |
+
);
|
393 |
+
|
394 |
+
$permalink = $this->sanitize_permalink(
|
395 |
+
// phpcs:ignore WordPress.Security.ValidatedSanitizedInput.InputNotSanitized
|
396 |
+
$_REQUEST['custom_permalink'],
|
397 |
+
$language_code
|
398 |
+
);
|
399 |
$permalink = apply_filters(
|
400 |
'custom_permalink_before_saving',
|
401 |
$permalink,
|
754 |
|
755 |
$this->delete_term_permalink( $term_id );
|
756 |
|
757 |
+
$language_code = get_locale();
|
758 |
+
if ( isset( $term->term_taxonomy_id ) ) {
|
759 |
+
$term_type = 'category';
|
760 |
+
if ( isset( $term->taxonomy ) ) {
|
761 |
+
$term_type = $term->taxonomy;
|
762 |
+
}
|
763 |
+
|
764 |
+
$language_code = apply_filters(
|
765 |
+
'wpml_element_language_code',
|
766 |
+
null,
|
767 |
+
array(
|
768 |
+
'element_id' => $term->term_taxonomy_id,
|
769 |
+
'element_type' => $term_type,
|
770 |
+
)
|
771 |
+
);
|
772 |
+
}
|
773 |
+
|
774 |
+
$permalink = $this->sanitize_permalink( $new_permalink, $language_code );
|
775 |
$table = get_option( 'custom_permalink_table' );
|
776 |
|
777 |
if ( $permalink && ! array_key_exists( $permalink, $table ) ) {
|
includes/class-custom-permalinks-frontend.php
CHANGED
@@ -250,16 +250,19 @@ class Custom_Permalinks_Frontend {
|
|
250 |
$cp_form = new Custom_Permalinks_Form();
|
251 |
$request = $cp_form->check_conflicts( $request );
|
252 |
}
|
253 |
-
|
254 |
-
$
|
|
|
|
|
255 |
|
256 |
if ( $posts ) {
|
257 |
/*
|
258 |
-
* A post matches our request. Preserve this url for later
|
259 |
-
*
|
260 |
*/
|
261 |
if ( trim( $posts[0]->meta_value, '/' ) === $request_no_slash ) {
|
262 |
$this->registered_url = $request;
|
|
|
263 |
}
|
264 |
|
265 |
if ( 'draft' === $posts[0]->post_status ) {
|
@@ -296,34 +299,43 @@ class Custom_Permalinks_Frontend {
|
|
296 |
}
|
297 |
}
|
298 |
|
299 |
-
if ( null === $original_url
|
|
|
|
|
300 |
// See if any terms have a matching permalink.
|
301 |
$table = get_option( 'custom_permalink_table' );
|
302 |
-
if (
|
303 |
-
|
304 |
-
|
305 |
-
|
306 |
-
|
307 |
-
|
308 |
-
|
309 |
-
|
310 |
-
|
311 |
-
$term = $table[ $permalink ];
|
312 |
-
|
313 |
-
/*
|
314 |
-
* Preserve this url for later if it's the same as the
|
315 |
-
* permalink (no extra stuff)
|
316 |
-
*/
|
317 |
-
if ( trim( $permalink, '/' ) === $request_no_slash ) {
|
318 |
-
$this->registered_url = $request;
|
319 |
}
|
320 |
|
321 |
-
|
322 |
-
|
323 |
-
|
324 |
-
$
|
325 |
-
|
326 |
-
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
327 |
}
|
328 |
}
|
329 |
}
|
250 |
$cp_form = new Custom_Permalinks_Form();
|
251 |
$request = $cp_form->check_conflicts( $request );
|
252 |
}
|
253 |
+
|
254 |
+
$request_no_slash = preg_replace( '@/+@', '/', trim( $request, '/' ) );
|
255 |
+
$posts = $this->query_post( $request_no_slash );
|
256 |
+
$permalink_matched = false;
|
257 |
|
258 |
if ( $posts ) {
|
259 |
/*
|
260 |
+
* A post matches our request. Preserve this url for later use. If it's
|
261 |
+
* the same as the permalink (no extra stuff).
|
262 |
*/
|
263 |
if ( trim( $posts[0]->meta_value, '/' ) === $request_no_slash ) {
|
264 |
$this->registered_url = $request;
|
265 |
+
$permalink_matched = true;
|
266 |
}
|
267 |
|
268 |
if ( 'draft' === $posts[0]->post_status ) {
|
299 |
}
|
300 |
}
|
301 |
|
302 |
+
if ( null === $original_url
|
303 |
+
|| ( null !== $original_url && ! $permalink_matched )
|
304 |
+
) {
|
305 |
// See if any terms have a matching permalink.
|
306 |
$table = get_option( 'custom_permalink_table' );
|
307 |
+
if ( $table ) {
|
308 |
+
$term_permalink = false;
|
309 |
+
foreach ( array_keys( $table ) as $permalink ) {
|
310 |
+
$perm_length = strlen( $permalink );
|
311 |
+
if ( ! $term_permalink
|
312 |
+
&& null !== $original_url
|
313 |
+
&& trim( $permalink, '/' ) !== $request_no_slash
|
314 |
+
) {
|
315 |
+
continue;
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
316 |
}
|
317 |
|
318 |
+
if ( substr( $request_no_slash, 0, $perm_length ) === $permalink
|
319 |
+
|| substr( $request_no_slash . '/', 0, $perm_length ) === $permalink
|
320 |
+
) {
|
321 |
+
$term = $table[ $permalink ];
|
322 |
+
$term_permalink = true;
|
323 |
+
|
324 |
+
/*
|
325 |
+
* Preserve this url for later if it's the same as the
|
326 |
+
* permalink (no extra stuff).
|
327 |
+
*/
|
328 |
+
if ( trim( $permalink, '/' ) === $request_no_slash ) {
|
329 |
+
$this->registered_url = $request;
|
330 |
+
}
|
331 |
+
|
332 |
+
$term_link = $this->original_term_link( $term['id'] );
|
333 |
+
$original_url = str_replace(
|
334 |
+
trim( $permalink, '/' ),
|
335 |
+
$term_link,
|
336 |
+
trim( $request, '/' )
|
337 |
+
);
|
338 |
+
}
|
339 |
}
|
340 |
}
|
341 |
}
|
includes/class-custom-permalinks.php
CHANGED
@@ -18,7 +18,7 @@ class Custom_Permalinks {
|
|
18 |
*
|
19 |
* @var string
|
20 |
*/
|
21 |
-
public $version = '2.0.
|
22 |
|
23 |
/**
|
24 |
* Class constructor.
|
18 |
*
|
19 |
* @var string
|
20 |
*/
|
21 |
+
public $version = '2.0.1';
|
22 |
|
23 |
/**
|
24 |
* Class constructor.
|
readme.txt
CHANGED
@@ -1,8 +1,8 @@
|
|
1 |
=== Custom Permalinks ===
|
2 |
-
Contributors: sasiddiqui
|
3 |
Tags: permalink, url, link, address, custom, redirect, custom post type, GDPR, GDPR Compliant
|
4 |
Tested up to: 5.8
|
5 |
-
Stable tag: 2.0.
|
6 |
License: GPLv3
|
7 |
License URI: https://www.gnu.org/licenses/gpl-3.0.html
|
8 |
|
@@ -115,6 +115,17 @@ function yasglobal_exclude_posts( $post ) {
|
|
115 |
add_filter( 'custom_permalinks_exclude_posts', 'yasglobal_exclude_posts' );
|
116 |
`
|
117 |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
118 |
=== Allow Uppercase Letters ===
|
119 |
|
120 |
To allow uppercase letters/words, please add below-mentioned line in your theme `functions.php`:
|
@@ -177,6 +188,12 @@ This process defines you the steps to follow either you are installing through W
|
|
177 |
|
178 |
== Changelog ==
|
179 |
|
|
|
|
|
|
|
|
|
|
|
|
|
180 |
= 2.0.0 - Jul 30, 2021 =
|
181 |
|
182 |
* Bugs
|
1 |
=== Custom Permalinks ===
|
2 |
+
Contributors: sasiddiqui
|
3 |
Tags: permalink, url, link, address, custom, redirect, custom post type, GDPR, GDPR Compliant
|
4 |
Tested up to: 5.8
|
5 |
+
Stable tag: 2.0.1
|
6 |
License: GPLv3
|
7 |
License URI: https://www.gnu.org/licenses/gpl-3.0.html
|
8 |
|
115 |
add_filter( 'custom_permalinks_exclude_posts', 'yasglobal_exclude_posts' );
|
116 |
`
|
117 |
|
118 |
+
=== Allow Accents Letters ===
|
119 |
+
|
120 |
+
To allow accents letters, please add below-mentioned line in your theme `functions.php`:
|
121 |
+
|
122 |
+
`
|
123 |
+
function yasglobal_permalink_allow_accents() {
|
124 |
+
return true;
|
125 |
+
}
|
126 |
+
add_filter( 'custom_permalinks_allow_accents', 'yasglobal_permalink_allow_accents' );
|
127 |
+
`
|
128 |
+
|
129 |
=== Allow Uppercase Letters ===
|
130 |
|
131 |
To allow uppercase letters/words, please add below-mentioned line in your theme `functions.php`:
|
188 |
|
189 |
== Changelog ==
|
190 |
|
191 |
+
= 2.0.1 - Aug 02, 2021 =
|
192 |
+
|
193 |
+
* Bugs
|
194 |
+
* [Plugin not save persian alphabet](https://wordpress.org/support/topic/plugin-not-save-persian-alphabet/)
|
195 |
+
* [404 error when post/page custom permalink is part of category custom permalink](https://github.com/samiahmedsiddiqui/custom-permalinks/issues/49)
|
196 |
+
|
197 |
= 2.0.0 - Jul 30, 2021 =
|
198 |
|
199 |
* Bugs
|