Custom Permalinks - Version 2.3.0

Version Description

  • Sep 21, 2021 =

  • Bugs

    • is_numeric warning in plugin API
    • Missing default WP redirect from URLs with no ending trailing slash
    • trailing slash
    • Fixed JS Error on updating Static page
  • Enhancements

    • Allow period in the permalink
Download this release

Release Info

Developer sasiddiqui
Plugin Icon Custom Permalinks
Version 2.3.0
Comparing to
See all releases

Code changes from version 2.2.0 to 2.3.0

assets/css/{about-plugins-2.2.0.min.css → about-plugins-2.3.0.min.css} RENAMED
File without changes
assets/js/script-form-2.2.0.min.js DELETED
@@ -1 +0,0 @@
1
- !function(){"use strict";let r="",a="",l=!1;function i(e){e.target&&(e.target.style.color="#000")}function d(e){var t;e.target&&(t=document.getElementById("original-permalink"),document.getElementById("custom_permalink").value=e.target.value,""!==e.target.value&&e.target.value!==t.value||(e.target.value=t.value,e.target.style.color="#ddd"))}function c(){if(r&&wpApiSettings&&wpApiSettings.nonce){const o=document.getElementsByClassName("edit-post-post-link__preview-label");var t,n=document.getElementById("custom_permalinks_home_url");let e="";o&&o[0]&&o[0].parentNode.classList.add("cp-permalink-hidden"),a=r.isSavingMetaBoxes(),a===l||a||(t=wp.data.select("core/editor").getEditedPostAttribute("id"),e=new XMLHttpRequest,l=a,e.onreadystatechange=function(){4===e.readyState&&200===e.status&&function(e){var t=document.getElementById("custom_permalinks_home_url"),n=document.getElementById("custom-permalinks-add");let o="",a="";if(document.getElementById("custom_permalink").value=e.custom_permalink,""===e.custom_permalink&&(e.custom_permalink=e.original_permalink),o=e.preview_permalink?t.value+e.preview_permalink:t.value+e.custom_permalink,document.getElementById("custom-permalinks-post-slug").value=e.custom_permalink,document.getElementById("original-permalink").value=e.original_permalink,document.querySelector("#view-post-btn a")&&(a=document.querySelector("#view-post-btn a").href,document.querySelector("#view-post-btn a").href=o),document.querySelector("a.editor-post-preview")&&(document.querySelector("a.editor-post-preview").href=o),""!==a){a=a.replace(/\//g,"/");let e=0;const r=document.querySelectorAll("body a");for(var l=new RegExp(a,"g"),s=r.length;e<s;)r[e]&&r[e].href&&(r[e].href=r[e].href.replace(l,o)),e+=1}n&&"add"===n.value&&(document.getElementById("custom-permalinks-edit-box").style.display=""),document.querySelector(".components-notice__content a")&&(document.querySelector(".components-notice__content a").href="/"+e.custom_permalink)}(JSON.parse(e.responseText))},e.open("GET",n.value+"wp-json/custom-permalinks/v1/get-permalink/"+t,!0),e.setRequestHeader("Cache-Control","private, max-age=0, no-cache"),e.setRequestHeader("X-WP-NONCE",wpApiSettings.nonce),e.send()),l=a}}function m(){const e=document.getElementsByClassName("edit-post-post-link__preview-label");e&&e[0]&&e[0].parentNode.classList.add("cp-permalink-hidden")}document.addEventListener("DOMContentLoaded",function(){const e=document.getElementsByClassName("edit-post-post-link__preview-label");let t=0;var n;const o=document.getElementById("custom-permalinks-edit-box"),a=document.getElementById("custom-permalinks-post-slug");let l="",s=0;if(a&&(a.addEventListener("focus",i),a.addEventListener("blur",d)),o&&""===document.querySelector("#custom-permalinks-edit-box .inside").innerHTML.trim()&&(o.style.display="none"),wp.data)for(n=document.getElementById("custom-permalinks-add"),l=document.querySelectorAll(".edit-post-sidebar .components-panel__header"),l&&l.length&&(s=l.length),n&&"add"===n.value&&(o.style.display="none"),r=wp.data.select("core/edit-post"),wp.data.subscribe(c),e&&e[0]&&e[0].parentNode.classList.add("cp-permalink-hidden"),o.classList.contains("closed")&&o.classList.remove("closed");t<s;)l[t].addEventListener("click",m),t+=1})}();
 
assets/js/script-form-2.3.0.min.js ADDED
@@ -0,0 +1 @@
 
1
+ !function(){"use strict";let r="",a="",l=!1;function i(e){e.target&&(e.target.style.color="#000")}function d(e){var t;e.target&&(t=document.getElementById("original-permalink"),document.getElementById("custom_permalink").value=e.target.value,""!==e.target.value&&e.target.value!==t.value||(e.target.value=t.value,e.target.style.color="#ddd"))}function c(){if(r&&wpApiSettings&&wpApiSettings.nonce){const o=document.getElementsByClassName("edit-post-post-link__preview-label");var t,n=document.getElementById("custom_permalinks_home_url");let e="";o&&o[0]&&o[0].parentNode.classList.add("cp-permalink-hidden"),a=r.isSavingMetaBoxes(),a!==l&&!a&&n&&(t=wp.data.select("core/editor").getEditedPostAttribute("id"),e=new XMLHttpRequest,l=a,e.onreadystatechange=function(){4===e.readyState&&200===e.status&&function(e){var t=document.getElementById("custom_permalinks_home_url"),n=document.getElementById("custom-permalinks-add");let o="",a="";if(document.getElementById("custom_permalink").value=e.custom_permalink,""===e.custom_permalink&&(e.custom_permalink=e.original_permalink),o=e.preview_permalink?t.value+e.preview_permalink:t.value+e.custom_permalink,document.getElementById("custom-permalinks-post-slug").value=e.custom_permalink,document.getElementById("original-permalink").value=e.original_permalink,document.querySelector("#view-post-btn a")&&(a=document.querySelector("#view-post-btn a").href,document.querySelector("#view-post-btn a").href=o),document.querySelector("a.editor-post-preview")&&(document.querySelector("a.editor-post-preview").href=o),""!==a){a=a.replace(/\//g,"/");let e=0;const r=document.querySelectorAll("body a");for(var l=new RegExp(a,"g"),s=r.length;e<s;)r[e]&&r[e].href&&(r[e].href=r[e].href.replace(l,o)),e+=1}n&&"add"===n.value&&(document.getElementById("custom-permalinks-edit-box").style.display=""),document.querySelector(".components-notice__content a")&&(document.querySelector(".components-notice__content a").href="/"+e.custom_permalink)}(JSON.parse(e.responseText))},e.open("GET",n.value+"wp-json/custom-permalinks/v1/get-permalink/"+t,!0),e.setRequestHeader("Cache-Control","private, max-age=0, no-cache"),e.setRequestHeader("X-WP-NONCE",wpApiSettings.nonce),e.send()),l=a}}function m(){const e=document.getElementsByClassName("edit-post-post-link__preview-label");e&&e[0]&&e[0].parentNode.classList.add("cp-permalink-hidden")}document.addEventListener("DOMContentLoaded",function(){const e=document.getElementsByClassName("edit-post-post-link__preview-label");let t=0;var n;const o=document.getElementById("custom-permalinks-edit-box"),a=document.getElementById("custom-permalinks-post-slug");let l="",s=0;if(a&&(a.addEventListener("focus",i),a.addEventListener("blur",d)),o&&""===document.querySelector("#custom-permalinks-edit-box .inside").innerHTML.trim()&&(o.style.display="none"),wp.data)for(n=document.getElementById("custom-permalinks-add"),l=document.querySelectorAll(".edit-post-sidebar .components-panel__header"),l&&l.length&&(s=l.length),n&&"add"===n.value&&(o.style.display="none"),r=wp.data.select("core/edit-post"),wp.data.subscribe(c),e&&e[0]&&e[0].parentNode.classList.add("cp-permalink-hidden"),o.classList.contains("closed")&&o.classList.remove("closed");t<s;)l[t].addEventListener("click",m),t+=1})}();
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.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.3.0
7
  * Requires at least: 2.6
8
  * Requires PHP: 5.4
9
  * Author: Sami Ahmed Siddiqui
includes/class-custom-permalinks-form.php CHANGED
@@ -333,22 +333,6 @@ class Custom_Permalinks_Form {
333
  }
334
  }
335
 
336
- // Allow only dot that are coming before any alphabet.
337
- $allow_dot = explode( '.', $permalink );
338
- if ( 0 < count( $allow_dot ) ) {
339
- $new_perm = $allow_dot[0];
340
- $dot_length = count( $allow_dot );
341
- for ( $i = 1; $i < $dot_length; ++$i ) {
342
- preg_match( '/^[a-z]/', $allow_dot[ $i ], $check_perm );
343
- if ( isset( $check_perm ) && ! empty( $check_perm ) ) {
344
- $new_perm .= '.';
345
- }
346
- $new_perm .= $allow_dot[ $i ];
347
- }
348
-
349
- $permalink = $new_perm;
350
- }
351
-
352
  $permalink = preg_replace( '/\s+/', '-', $permalink );
353
  $permalink = preg_replace( '|-+|', '-', $permalink );
354
  $permalink = str_replace( '-/', '/', $permalink );
@@ -945,7 +929,9 @@ class Custom_Permalinks_Form {
945
  'callback' => array( $this, 'refresh_meta_form' ),
946
  'args' => array(
947
  'id' => array(
948
- 'validate_callback' => 'is_numeric',
 
 
949
  ),
950
  ),
951
  'permission_callback' => function () {
333
  }
334
  }
335
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
336
  $permalink = preg_replace( '/\s+/', '-', $permalink );
337
  $permalink = preg_replace( '|-+|', '-', $permalink );
338
  $permalink = str_replace( '-/', '/', $permalink );
929
  'callback' => array( $this, 'refresh_meta_form' ),
930
  'args' => array(
931
  'id' => array(
932
+ 'validate_callback' => function( $pid ) {
933
+ return is_numeric( $pid );
934
+ },
935
  ),
936
  ),
937
  'permission_callback' => function () {
includes/class-custom-permalinks-frontend.php CHANGED
@@ -304,6 +304,7 @@ class Custom_Permalinks_Frontend {
304
  $request_no_slash = preg_replace( '@/+@', '/', trim( $request, '/' ) );
305
  $posts = $this->query_post( $request_no_slash );
306
  $permalink_matched = false;
 
307
 
308
  if ( $posts ) {
309
  /*
@@ -315,6 +316,7 @@ class Custom_Permalinks_Frontend {
315
  $permalink_matched = true;
316
  }
317
 
 
318
  if ( 'draft' === $posts[0]->post_status ) {
319
  if ( 'page' === $posts[0]->post_type ) {
320
  $original_url = '?page_id=' . $posts[0]->ID;
@@ -372,15 +374,16 @@ class Custom_Permalinks_Frontend {
372
  $term_permalink = true;
373
 
374
  /*
375
- * Preserve this url for later if it's the same as the
376
- * permalink (no extra stuff).
377
- */
378
  if ( trim( $permalink, '/' ) === $request_no_slash ) {
379
  $this->registered_url = $request;
380
  }
381
 
382
- $term_link = $this->original_term_link( $term['id'] );
383
- $original_url = str_replace(
 
384
  trim( $permalink, '/' ),
385
  $term_link,
386
  trim( $request, '/' )
@@ -394,6 +397,16 @@ class Custom_Permalinks_Frontend {
394
  if ( null !== $original_url ) {
395
  $this->parse_request_status = true;
396
 
 
 
 
 
 
 
 
 
 
 
397
  $original_url = str_replace( '//', '/', $original_url );
398
  $pos = strpos( $this->request_uri, '?' );
399
  if ( false !== $pos ) {
@@ -407,8 +420,8 @@ class Custom_Permalinks_Frontend {
407
 
408
  /*
409
  * Now we have the original URL, run this back through WP->parse_request,
410
- * in order to parse parameters properly.
411
- * We set $_SERVER variables to fool the function.
412
  */
413
  $_SERVER['REQUEST_URI'] = '/' . ltrim( $original_url, '/' );
414
  $path_info = apply_filters(
304
  $request_no_slash = preg_replace( '@/+@', '/', trim( $request, '/' ) );
305
  $posts = $this->query_post( $request_no_slash );
306
  $permalink_matched = false;
307
+ $found_permalink = '';
308
 
309
  if ( $posts ) {
310
  /*
316
  $permalink_matched = true;
317
  }
318
 
319
+ $found_permalink = $posts[0]->meta_value;
320
  if ( 'draft' === $posts[0]->post_status ) {
321
  if ( 'page' === $posts[0]->post_type ) {
322
  $original_url = '?page_id=' . $posts[0]->ID;
374
  $term_permalink = true;
375
 
376
  /*
377
+ * Preserve this url for later if it's the same as the
378
+ * permalink (no extra stuff).
379
+ */
380
  if ( trim( $permalink, '/' ) === $request_no_slash ) {
381
  $this->registered_url = $request;
382
  }
383
 
384
+ $found_permalink = $permalink;
385
+ $term_link = $this->original_term_link( $term['id'] );
386
+ $original_url = str_replace(
387
  trim( $permalink, '/' ),
388
  $term_link,
389
  trim( $request, '/' )
397
  if ( null !== $original_url ) {
398
  $this->parse_request_status = true;
399
 
400
+ /*
401
+ * Allow redirect function to work if permalink is not exactly matched
402
+ * with the requested url. Like Trailing slash (Requested URL doesn't
403
+ * contain trailing slash but permalink has trailing slash or vice versa)
404
+ * and letter-case issue etc.
405
+ */
406
+ if ( ! empty( $found_permalink ) && $found_permalink !== $request ) {
407
+ $this->parse_request_status = false;
408
+ }
409
+
410
  $original_url = str_replace( '//', '/', $original_url );
411
  $pos = strpos( $this->request_uri, '?' );
412
  if ( false !== $pos ) {
420
 
421
  /*
422
  * Now we have the original URL, run this back through WP->parse_request,
423
+ * in order to parse parameters properly. We set `$_SERVER` variables to
424
+ * fool the function.
425
  */
426
  $_SERVER['REQUEST_URI'] = '/' . ltrim( $original_url, '/' );
427
  $path_info = apply_filters(
includes/class-custom-permalinks.php CHANGED
@@ -18,7 +18,7 @@ class Custom_Permalinks {
18
  *
19
  * @var string
20
  */
21
- public $version = '2.2.0';
22
 
23
  /**
24
  * Class constructor.
18
  *
19
  * @var string
20
  */
21
+ public $version = '2.3.0';
22
 
23
  /**
24
  * Class constructor.
readme.txt CHANGED
@@ -2,7 +2,7 @@
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.2.0
6
  License: GPLv3
7
  License URI: https://www.gnu.org/licenses/gpl-3.0.html
8
 
@@ -188,12 +188,22 @@ This process defines you the steps to follow either you are installing through W
188
 
189
  == Changelog ==
190
 
 
 
 
 
 
 
 
 
 
 
191
  = 2.2.0 - Aug 13, 2021 =
192
 
193
  * Bugs
194
  * Show decoded permalink in meta box
195
  * Enhancements
196
- * Update script to fix linting issues and use updated permalink to view the post/page.
197
 
198
  = 2.1.0 - Aug 09, 2021 =
199
 
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.3.0
6
  License: GPLv3
7
  License URI: https://www.gnu.org/licenses/gpl-3.0.html
8
 
188
 
189
  == Changelog ==
190
 
191
+ = 2.3.0 - Sep 21, 2021 =
192
+
193
+ * Bugs
194
+ * [is_numeric warning in plugin API](https://wordpress.org/support/topic/is_numeric-error-for-plugin-api/)
195
+ * [Missing default WP redirect from URLs with no ending trailing slash](https://wordpress.org/support/topic/missing-default-wp-redirect-from-urls-with-no-ending-trailing-slash/)
196
+ * [trailing slash](https://wordpress.org/support/topic/trailing-slash-9/)
197
+ * Fixed JS Error on updating Static page
198
+ * Enhancements
199
+ * Allow period in the permalink
200
+
201
  = 2.2.0 - Aug 13, 2021 =
202
 
203
  * Bugs
204
  * Show decoded permalink in meta box
205
  * Enhancements
206
+ * Update script to fix linting issues and use updated permalink to view the post/page
207
 
208
  = 2.1.0 - Aug 09, 2021 =
209