Custom Permalinks - Version 1.2.19

Version Description

  • April 10, 2018 =

    • Bugs
    • Fixed undefined variable issue on PostTypes Permalinks page
    • Fixed LIKE Query Issue
Download this release

Release Info

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

Code changes from version 1.2.18 to 1.2.19

admin/class-custom-permalinks-admin.php CHANGED
@@ -126,7 +126,8 @@ final class Custom_Permalinks_Admin {
126
  <input type="submit" id="doaction" class="button action" value="Apply">
127
  </div>';
128
 
129
- $posts = 0;
 
130
  if ( isset( $count_posts->total_permalinks )
131
  && $count_posts->total_permalinks > 0 ) {
132
 
@@ -135,7 +136,6 @@ final class Custom_Permalinks_Admin {
135
  $query = "SELECT p.ID, p.post_title, p.post_type, pm.meta_value FROM $wpdb->posts AS p LEFT JOIN $wpdb->postmeta AS pm ON (p.ID = pm.post_id) WHERE pm.meta_key = 'custom_permalink' AND pm.meta_value != '' " . $filter_permalink . " " . $sorting_by . " " . $page_limit . "";
136
  $posts = $wpdb->get_results( $query );
137
 
138
- $pagination_html = '';
139
  $total_pages = ceil( $count_posts->total_permalinks / 20 );
140
  if ( isset( $_GET['paged'] ) && is_numeric( $_GET['paged'] )
141
  && $_GET['paged'] > 0 ) {
126
  <input type="submit" id="doaction" class="button action" value="Apply">
127
  </div>';
128
 
129
+ $posts = 0;
130
+ $pagination_html = '';
131
  if ( isset( $count_posts->total_permalinks )
132
  && $count_posts->total_permalinks > 0 ) {
133
 
136
  $query = "SELECT p.ID, p.post_title, p.post_type, pm.meta_value FROM $wpdb->posts AS p LEFT JOIN $wpdb->postmeta AS pm ON (p.ID = pm.post_id) WHERE pm.meta_key = 'custom_permalink' AND pm.meta_value != '' " . $filter_permalink . " " . $sorting_by . " " . $page_limit . "";
137
  $posts = $wpdb->get_results( $query );
138
 
 
139
  $total_pages = ceil( $count_posts->total_permalinks / 20 );
140
  if ( isset( $_GET['paged'] ) && is_numeric( $_GET['paged'] )
141
  && $_GET['paged'] > 0 ) {
custom-permalinks.php CHANGED
@@ -3,7 +3,7 @@
3
  * Plugin Name: Custom Permalinks
4
  * Plugin URI: https://wordpress.org/plugins/custom-permalinks/
5
  * Description: Set custom permalinks on a per-post basis
6
- * Version: 1.2.18
7
  * Author: Sami Ahmed Siddiqui
8
  * Author URI: https://www.custompermalinks.com/
9
  * Donate link: https://www.paypal.me/yasglobal
@@ -64,7 +64,7 @@ final class Custom_Permalinks {
64
  }
65
 
66
  if ( ! defined( 'CUSTOM_PERMALINKS_PLUGIN_VERSION' ) ) {
67
- define( 'CUSTOM_PERMALINKS_PLUGIN_VERSION', '1.2.18' );
68
  }
69
 
70
  if ( ! defined( 'CUSTOM_PERMALINKS_PATH' ) ) {
3
  * Plugin Name: Custom Permalinks
4
  * Plugin URI: https://wordpress.org/plugins/custom-permalinks/
5
  * Description: Set custom permalinks on a per-post basis
6
+ * Version: 1.2.19
7
  * Author: Sami Ahmed Siddiqui
8
  * Author URI: https://www.custompermalinks.com/
9
  * Donate link: https://www.paypal.me/yasglobal
64
  }
65
 
66
  if ( ! defined( 'CUSTOM_PERMALINKS_PLUGIN_VERSION' ) ) {
67
+ define( 'CUSTOM_PERMALINKS_PLUGIN_VERSION', '1.2.19' );
68
  }
69
 
70
  if ( ! defined( 'CUSTOM_PERMALINKS_PATH' ) ) {
frontend/class-custom-permalinks-frontend.php CHANGED
@@ -13,18 +13,30 @@ final class Custom_Permalinks_Frontend {
13
  * @return void
14
  */
15
  public function init() {
16
- add_filter( 'request', array( $this, 'parse_request' ), 10, 1 );
17
-
18
- add_action( 'template_redirect', array( $this, 'make_redirect' ), 5 );
19
-
20
- add_filter( 'post_link', array( $this, 'custom_permalinks_post_link' ), 10, 2 );
21
- add_filter( 'post_type_link', array( $this, 'custom_permalinks_post_link' ), 10, 2 );
22
- add_filter( 'page_link', array( $this, 'custom_permalinks_page_link' ), 10, 2 );
23
-
24
- add_filter( 'tag_link', array( $this, 'custom_permalinks_term_link' ), 10, 2 );
25
- add_filter( 'category_link', array( $this, 'custom_permalinks_term_link' ), 10, 2 );
26
-
27
- add_filter( 'user_trailingslashit', array( $this, 'custom_permalinks_trailingslash' ), 10, 2 );
 
 
 
 
 
 
 
 
 
 
 
 
28
  }
29
 
30
  /**
@@ -105,23 +117,20 @@ final class Custom_Permalinks_Frontend {
105
 
106
  $posts = $wpdb->get_results( $sql );
107
 
108
- if ( ! $posts ) {
109
- $def_query = apply_filters( 'custom_permalinks_like_query', '__false' );
110
- if ( defined( 'POLYLANG_VERSION' ) || defined( 'AMP__VERSION' )
111
- || defined( 'TASTY_RECIPES_PLUGIN_VERSION' ) || '__false' !== $def_query ) {
112
- $sql = $wpdb->prepare( "SELECT p.ID, pm.meta_value, p.post_type, p.post_status FROM $wpdb->posts AS p " .
113
- " LEFT JOIN $wpdb->postmeta AS pm ON (p.ID = pm.post_id) WHERE " .
114
- " meta_key = 'custom_permalink' AND meta_value != '' AND " .
115
- " ( LOWER(meta_value) = LEFT(LOWER('%s'), LENGTH(meta_value)) OR " .
116
- " LOWER(meta_value) = LEFT(LOWER('%s'), LENGTH(meta_value)) ) " .
117
- " AND post_status != 'trash' AND post_type != 'nav_menu_item'" .
118
- " ORDER BY LENGTH(meta_value) DESC, " .
119
- " FIELD(post_status,'publish','private','draft','auto-draft','inherit')," .
120
- " FIELD(post_type,'post','page'), p.ID ASC LIMIT 1",
121
- $request_noslash, $request_noslash . "/" );
122
-
123
- $posts = $wpdb->get_results( $sql );
124
- }
125
  }
126
 
127
  if ( $posts ) {
@@ -198,8 +207,9 @@ final class Custom_Permalinks_Frontend {
198
  $original_url .= ( strpos( $original_url, '?' ) === false ? '?' : '&' ) . $query_vars;
199
  }
200
 
201
- // Now we have the original URL, run this back through WP->parse_request, in order to
202
- // parse parameters properly. We set $_SERVER variables to fool the function.
 
203
  $old_request_uri = $_SERVER['REQUEST_URI'];
204
  $old_query_string = '';
205
  if ( isset( $_SERVER['QUERY_STRING'] ) ) {
@@ -266,7 +276,9 @@ final class Custom_Permalinks_Frontend {
266
  }
267
 
268
  if ( defined( 'POLYLANG_VERSION' ) ) {
269
- require_once( CUSTOM_PERMALINKS_PATH . 'frontend/class-custom-permalinks-form.php' );
 
 
270
  $cp_form = new Custom_Permalinks_Form();
271
  $request = $cp_form->custom_permalinks_check_conflicts( $request );
272
  }
@@ -305,30 +317,28 @@ final class Custom_Permalinks_Frontend {
305
 
306
  $posts = $wpdb->get_results( $sql );
307
 
308
- if ( ! $posts ) {
309
- $def_query = apply_filters( 'custom_permalinks_like_query', '__false' );
310
- if ( defined( 'POLYLANG_VERSION' ) || defined( 'AMP__VERSION' )
311
- || defined( 'TASTY_RECIPES_PLUGIN_VERSION' ) || '__false' !== $def_query ) {
312
- $sql = $wpdb->prepare( "SELECT p.ID, pm.meta_value, p.post_type, p.post_status FROM $wpdb->posts AS p " .
313
- " LEFT JOIN $wpdb->postmeta AS pm ON (p.ID = pm.post_id) WHERE " .
314
- " meta_key = 'custom_permalink' AND meta_value != '' AND " .
315
- " ( LOWER(meta_value) = LEFT(LOWER('%s'), LENGTH(meta_value)) OR " .
316
- " LOWER(meta_value) = LEFT(LOWER('%s'), LENGTH(meta_value)) ) " .
317
- " AND post_status != 'trash' AND post_type != 'nav_menu_item'" .
318
- " ORDER BY LENGTH(meta_value) DESC, " .
319
- " FIELD(post_status,'publish','private','draft','auto-draft','inherit')," .
320
- " FIELD(post_type,'post','page'), p.ID ASC LIMIT 1",
321
- $request_noslash, $request_noslash . "/" );
322
-
323
- $posts = $wpdb->get_results( $sql );
324
- }
325
  }
326
 
327
  if ( ! isset( $posts[0]->ID ) || ! isset( $posts[0]->meta_value )
328
  || empty( $posts[0]->meta_value ) ) {
329
  global $wp_query;
330
 
331
- // If the post/tag/category we're on has a custom permalink, get it and check against the request
 
332
  if ( ( is_single() || is_page() ) && ! empty( $wp_query->post ) ) {
333
  $post = $wp_query->post;
334
  $custom_permalink = get_post_meta( $post->ID, 'custom_permalink', true );
13
  * @return void
14
  */
15
  public function init() {
16
+ add_filter( 'request', array( $this, 'parse_request' ), 10, 1 );
17
+
18
+ add_action( 'template_redirect', array( $this, 'make_redirect' ), 5 );
19
+
20
+ add_filter( 'post_link',
21
+ array( $this, 'custom_permalinks_post_link' ), 10, 2
22
+ );
23
+ add_filter( 'post_type_link',
24
+ array( $this, 'custom_permalinks_post_link' ), 10, 2
25
+ );
26
+ add_filter( 'page_link',
27
+ array( $this, 'custom_permalinks_page_link' ), 10, 2
28
+ );
29
+
30
+ add_filter(
31
+ 'tag_link', array( $this, 'custom_permalinks_term_link' ), 10, 2
32
+ );
33
+ add_filter( 'category_link',
34
+ array( $this, 'custom_permalinks_term_link' ), 10, 2
35
+ );
36
+
37
+ add_filter( 'user_trailingslashit',
38
+ array( $this, 'custom_permalinks_trailingslash' ), 10, 2
39
+ );
40
  }
41
 
42
  /**
117
 
118
  $posts = $wpdb->get_results( $sql );
119
 
120
+ $remove_like_query = apply_filters( 'cp_remove_like_query', '__true' );
121
+ if ( ! $posts && '__false' !== $remove_like_query ) {
122
+ $sql = $wpdb->prepare( "SELECT p.ID, pm.meta_value, p.post_type, p.post_status FROM $wpdb->posts AS p " .
123
+ " LEFT JOIN $wpdb->postmeta AS pm ON (p.ID = pm.post_id) WHERE " .
124
+ " meta_key = 'custom_permalink' AND meta_value != '' AND " .
125
+ " ( LOWER(meta_value) = LEFT(LOWER('%s'), LENGTH(meta_value)) OR " .
126
+ " LOWER(meta_value) = LEFT(LOWER('%s'), LENGTH(meta_value)) ) " .
127
+ " AND post_status != 'trash' AND post_type != 'nav_menu_item'" .
128
+ " ORDER BY LENGTH(meta_value) DESC, " .
129
+ " FIELD(post_status,'publish','private','draft','auto-draft','inherit')," .
130
+ " FIELD(post_type,'post','page'), p.ID ASC LIMIT 1",
131
+ $request_noslash, $request_noslash . "/" );
132
+
133
+ $posts = $wpdb->get_results( $sql );
 
 
 
134
  }
135
 
136
  if ( $posts ) {
207
  $original_url .= ( strpos( $original_url, '?' ) === false ? '?' : '&' ) . $query_vars;
208
  }
209
 
210
+ // Now we have the original URL, run this back through WP->parse_request,
211
+ // in order to parse parameters properly.
212
+ // We set $_SERVER variables to fool the function.
213
  $old_request_uri = $_SERVER['REQUEST_URI'];
214
  $old_query_string = '';
215
  if ( isset( $_SERVER['QUERY_STRING'] ) ) {
276
  }
277
 
278
  if ( defined( 'POLYLANG_VERSION' ) ) {
279
+ require_once(
280
+ CUSTOM_PERMALINKS_PATH . 'frontend/class-custom-permalinks-form.php'
281
+ );
282
  $cp_form = new Custom_Permalinks_Form();
283
  $request = $cp_form->custom_permalinks_check_conflicts( $request );
284
  }
317
 
318
  $posts = $wpdb->get_results( $sql );
319
 
320
+ $remove_like_query = apply_filters( 'cp_remove_like_query', '__true' );
321
+ if ( ! $posts && '__false' !== $remove_like_query ) {
322
+ $sql = $wpdb->prepare( "SELECT p.ID, pm.meta_value, p.post_type, p.post_status FROM $wpdb->posts AS p " .
323
+ " LEFT JOIN $wpdb->postmeta AS pm ON (p.ID = pm.post_id) WHERE " .
324
+ " meta_key = 'custom_permalink' AND meta_value != '' AND " .
325
+ " ( LOWER(meta_value) = LEFT(LOWER('%s'), LENGTH(meta_value)) OR " .
326
+ " LOWER(meta_value) = LEFT(LOWER('%s'), LENGTH(meta_value)) ) " .
327
+ " AND post_status != 'trash' AND post_type != 'nav_menu_item'" .
328
+ " ORDER BY LENGTH(meta_value) DESC, " .
329
+ " FIELD(post_status,'publish','private','draft','auto-draft','inherit')," .
330
+ " FIELD(post_type,'post','page'), p.ID ASC LIMIT 1",
331
+ $request_noslash, $request_noslash . "/" );
332
+
333
+ $posts = $wpdb->get_results( $sql );
 
 
 
334
  }
335
 
336
  if ( ! isset( $posts[0]->ID ) || ! isset( $posts[0]->meta_value )
337
  || empty( $posts[0]->meta_value ) ) {
338
  global $wp_query;
339
 
340
+ // If the post/tag/category we're on has a custom permalink, get it and
341
+ // check against the request
342
  if ( ( is_single() || is_page() ) && ! empty( $wp_query->post ) ) {
343
  $post = $wp_query->post;
344
  $custom_permalink = get_post_meta( $post->ID, 'custom_permalink', true );
readme.txt CHANGED
@@ -4,7 +4,7 @@ Donate link: https://www.paypal.me/yasglobal
4
  Tags: permalink, url, link, address, custom, redirect, custom post type
5
  Requires at least: 2.6
6
  Tested up to: 4.9
7
- Stable tag: 1.2.18
8
  License: GPLv3
9
  License URI: https://www.gnu.org/licenses/gpl.html
10
 
@@ -31,13 +31,13 @@ Plugin provides some filter which maybe used according to your needs.
31
 
32
  To exclude any Permalink to processed with the plugin so, just add the filter looks like this:
33
  `
34
- function check_xml_sitemap_url( $permalink ) {
35
  if ( false !== strpos( $permalink, 'sitemap.xml' )) {
36
  return '__true';
37
  }
38
  return;
39
  }
40
- add_filter( 'custom_permalinks_request_ignore', 'check_xml_sitemap_url' );
41
  `
42
 
43
  To exclude permalink from any post type so, just add the filter looks like this:
@@ -53,9 +53,9 @@ add_filter( 'custom_permalinks_exclude_post_type', 'yasglobal_exclude_post_types
53
 
54
  Note: custom_permalinks_exclude_post_type doesn't work on the posts permalink which has been created previously.
55
 
56
- To make the like query works as it was before so, just add this line in your theme's functions.php:
57
  `
58
- add_filter( 'custom_permalinks_like_query', '__return_true');
59
  `
60
 
61
  Note: Use `custom_permalinks_like_query` filter if the URLs doesn't works for you after upgrading to v1.2.9
@@ -93,6 +93,12 @@ This process defines you the steps to follow either you are installing through W
93
 
94
  == Changelog ==
95
 
 
 
 
 
 
 
96
  = 1.2.18 - April 05, 2018 =
97
 
98
  * Enhancement
4
  Tags: permalink, url, link, address, custom, redirect, custom post type
5
  Requires at least: 2.6
6
  Tested up to: 4.9
7
+ Stable tag: 1.2.19
8
  License: GPLv3
9
  License URI: https://www.gnu.org/licenses/gpl.html
10
 
31
 
32
  To exclude any Permalink to processed with the plugin so, just add the filter looks like this:
33
  `
34
+ function yasglobal_xml_sitemap_url( $permalink ) {
35
  if ( false !== strpos( $permalink, 'sitemap.xml' )) {
36
  return '__true';
37
  }
38
  return;
39
  }
40
+ add_filter( 'custom_permalinks_request_ignore', 'yasglobal_xml_sitemap_url' );
41
  `
42
 
43
  To exclude permalink from any post type so, just add the filter looks like this:
53
 
54
  Note: custom_permalinks_exclude_post_type doesn't work on the posts permalink which has been created previously.
55
 
56
+ To remove the like query to being work just add this line in your theme's functions.php:
57
  `
58
+ add_filter( 'cp_remove_like_query', '__return_false');
59
  `
60
 
61
  Note: Use `custom_permalinks_like_query` filter if the URLs doesn't works for you after upgrading to v1.2.9
93
 
94
  == Changelog ==
95
 
96
+ = 1.2.19 - April 10, 2018 =
97
+
98
+ * Bugs
99
+ * Fixed undefined variable issue on PostTypes Permalinks page
100
+ * Fixed LIKE Query Issue
101
+
102
  = 1.2.18 - April 05, 2018 =
103
 
104
  * Enhancement