Custom Permalinks - Version 1.2.3

Version Description

  • Fixed PHP Notice on Edit Post Page
Download this release

Release Info

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

Code changes from version 1.2.2 to 1.2.3

admin/class-custom-permalinks-form.php CHANGED
@@ -56,20 +56,19 @@ class Custom_Permalinks_Form {
56
  */
57
  public function custom_permalinks_delete_permalink( $id ) {
58
  global $wpdb;
59
- $wpdb->query( $wpdb->prepare( "DELETE FROM $wpdb->postmeta WHERE meta_key = 'custom_permalink' AND `post_id` = %d", $id ) );
60
  }
61
 
62
  /**
63
  * Per-post/page options (Wordpress > 2.9)
64
  */
65
- public function custom_permalinks_get_sample_permalink_html( $html, $id, $new_title, $new_slug ) {
 
 
 
66
  if ( $post->post_type == 'attachment' || $post->ID == get_option( 'page_on_front' ) ) {
67
  return $html;
68
  }
69
-
70
- $permalink = get_post_meta( $id, 'custom_permalink', true );
71
- $post = get_post( $id );
72
-
73
  ob_start();
74
 
75
  require_once( CUSTOM_PERMALINKS_PATH . 'frontend/class-custom-permalinks-frontend.php' );
@@ -244,8 +243,9 @@ class Custom_Permalinks_Form {
244
 
245
  require_once( CUSTOM_PERMALINKS_PATH . 'frontend/class-custom-permalinks-frontend.php' );
246
  $custom_permalinks_frontend = new Custom_Permalinks_Frontend();
247
- if ( $newPermalink == $custom_permalinks_frontend->custom_permalinks_original_tag_link( $id ) )
248
  $newPermalink = '';
 
249
 
250
  $term = get_term( $id, 'post_tag' );
251
  $this->custom_permalinks_save_term( $term, str_replace( '%2F', '/', urlencode( $newPermalink ) ) );
@@ -263,8 +263,9 @@ class Custom_Permalinks_Form {
263
 
264
  require_once( CUSTOM_PERMALINKS_PATH . 'frontend/class-custom-permalinks-frontend.php' );
265
  $custom_permalinks_frontend = new Custom_Permalinks_Frontend();
266
- if ( $newPermalink == $custom_permalinks_frontend->custom_permalinks_original_category_link( $id ) )
267
  $newPermalink = '';
 
268
 
269
  $term = get_term( $id, 'category' );
270
  $this->custom_permalinks_save_term( $term, str_replace( '%2F', '/', urlencode( $newPermalink ) ) );
@@ -308,19 +309,23 @@ class Custom_Permalinks_Form {
308
  * Check Conflicts and resolve it (e.g: Polylang)
309
  */
310
  public function custom_permalinks_check_conflicts( $requested_url = '' ) {
311
- if ( $requested_url == '' ) return;
 
 
312
 
313
  // Check if the Polylang Plugin is installed so, make changes in the URL
314
  if ( defined( 'POLYLANG_VERSION' ) ) {
315
  $polylang_config = get_option( 'polylang' );
316
  if ( $polylang_config['force_lang'] == 1 ) {
317
 
318
- if ( strpos( $requested_url, 'language/' ) !== false )
319
  $requested_url = str_replace( "language/", "", $requested_url );
 
320
 
321
  $remove_lang = ltrim( strstr( $requested_url, '/' ), '/' );
322
- if ( $remove_lang != '' )
323
  return $remove_lang;
 
324
  }
325
  }
326
  return $requested_url;
56
  */
57
  public function custom_permalinks_delete_permalink( $id ) {
58
  global $wpdb;
59
+ $wpdb->query( $wpdb->prepare( "DELETE FROM $wpdb->postmeta WHERE meta_key = 'custom_permalink' AND post_id = %d", $id ) );
60
  }
61
 
62
  /**
63
  * Per-post/page options (Wordpress > 2.9)
64
  */
65
+ public function custom_permalinks_get_sample_permalink_html( $html, $id, $new_title, $new_slug ) {
66
+ $permalink = get_post_meta( $id, 'custom_permalink', true );
67
+ $post = get_post( $id );
68
+
69
  if ( $post->post_type == 'attachment' || $post->ID == get_option( 'page_on_front' ) ) {
70
  return $html;
71
  }
 
 
 
 
72
  ob_start();
73
 
74
  require_once( CUSTOM_PERMALINKS_PATH . 'frontend/class-custom-permalinks-frontend.php' );
243
 
244
  require_once( CUSTOM_PERMALINKS_PATH . 'frontend/class-custom-permalinks-frontend.php' );
245
  $custom_permalinks_frontend = new Custom_Permalinks_Frontend();
246
+ if ( $newPermalink == $custom_permalinks_frontend->custom_permalinks_original_tag_link( $id ) ) {
247
  $newPermalink = '';
248
+ }
249
 
250
  $term = get_term( $id, 'post_tag' );
251
  $this->custom_permalinks_save_term( $term, str_replace( '%2F', '/', urlencode( $newPermalink ) ) );
263
 
264
  require_once( CUSTOM_PERMALINKS_PATH . 'frontend/class-custom-permalinks-frontend.php' );
265
  $custom_permalinks_frontend = new Custom_Permalinks_Frontend();
266
+ if ( $newPermalink == $custom_permalinks_frontend->custom_permalinks_original_category_link( $id ) ) {
267
  $newPermalink = '';
268
+ }
269
 
270
  $term = get_term( $id, 'category' );
271
  $this->custom_permalinks_save_term( $term, str_replace( '%2F', '/', urlencode( $newPermalink ) ) );
309
  * Check Conflicts and resolve it (e.g: Polylang)
310
  */
311
  public function custom_permalinks_check_conflicts( $requested_url = '' ) {
312
+ if ( $requested_url == '' ) {
313
+ return;
314
+ }
315
 
316
  // Check if the Polylang Plugin is installed so, make changes in the URL
317
  if ( defined( 'POLYLANG_VERSION' ) ) {
318
  $polylang_config = get_option( 'polylang' );
319
  if ( $polylang_config['force_lang'] == 1 ) {
320
 
321
+ if ( strpos( $requested_url, 'language/' ) !== false ) {
322
  $requested_url = str_replace( "language/", "", $requested_url );
323
+ }
324
 
325
  $remove_lang = ltrim( strstr( $requested_url, '/' ), '/' );
326
+ if ( $remove_lang != '' ) {
327
  return $remove_lang;
328
+ }
329
  }
330
  }
331
  return $requested_url;
custom-permalinks-main.php CHANGED
@@ -15,7 +15,7 @@ if ( ! function_exists( "add_action" ) || ! function_exists( "add_filter" ) ) {
15
  exit();
16
  }
17
 
18
- define( 'CUSTOM_PERMALINKS_PLUGIN_VERSION', '1.2.2' );
19
 
20
  if ( ! defined( 'CUSTOM_PERMALINKS_PATH' ) ) {
21
  define( 'CUSTOM_PERMALINKS_PATH', plugin_dir_path( __FILE__ ) );
15
  exit();
16
  }
17
 
18
+ define( 'CUSTOM_PERMALINKS_PLUGIN_VERSION', '1.2.3' );
19
 
20
  if ( ! defined( 'CUSTOM_PERMALINKS_PATH' ) ) {
21
  define( 'CUSTOM_PERMALINKS_PATH', plugin_dir_path( __FILE__ ) );
custom-permalinks.php CHANGED
@@ -4,7 +4,7 @@
4
  * Plugin Name: Custom Permalinks
5
  * Plugin URI: https://wordpress.org/plugins/custom-permalinks/
6
  * Description: Set custom permalinks on a per-post basis
7
- * Version: 1.2.2
8
  * Author: Sami Ahmed Siddiqui
9
  * Author URI: https://www.yasglobal.com/web-design-development/wordpress/custom-permalinks/
10
  * Donate link: https://www.paypal.me/yasglobal
4
  * Plugin Name: Custom Permalinks
5
  * Plugin URI: https://wordpress.org/plugins/custom-permalinks/
6
  * Description: Set custom permalinks on a per-post basis
7
+ * Version: 1.2.3
8
  * Author: Sami Ahmed Siddiqui
9
  * Author URI: https://www.yasglobal.com/web-design-development/wordpress/custom-permalinks/
10
  * Donate link: https://www.paypal.me/yasglobal
frontend/class-custom-permalinks-frontend.php CHANGED
@@ -36,16 +36,20 @@ class Custom_Permalinks_Frontend {
36
  $original_url = NULL;
37
 
38
  // Get request URI, strip parameters and /'s
39
- $url = parse_url( get_bloginfo( 'url' ) );
40
- $url = isset( $url['path'] ) ? $url['path'] : '';
41
  $request = ltrim( substr( $_SERVER['REQUEST_URI'], strlen( $url ) ), '/' );
42
  $request = ( ( $pos = strpos( $request, '?' ) ) ? substr( $request, 0, $pos ) : $request );
43
 
44
- if ( ! $request ) return $query;
 
 
45
 
46
  $ignore = apply_filters( 'custom_permalinks_request_ignore', $request );
47
 
48
- if ( $ignore === '__true' ) return $query;
 
 
49
 
50
  if ( defined( 'POLYLANG_VERSION' ) ) {
51
  require_once( CUSTOM_PERMALINKS_PATH . 'admin/class-custom-permalinks-form.php' );
@@ -71,8 +75,9 @@ class Custom_Permalinks_Frontend {
71
  // A post matches our request
72
 
73
  // Preserve this url for later if it's the same as the permalink (no extra stuff)
74
- if ( $request_noslash == trim( $posts[0]->meta_value, '/' ) )
75
  $_CPRegisteredURL = $request;
 
76
 
77
  if ( $posts[0]->post_status == 'draft' ) {
78
  if ( $posts[0]->post_type == 'page' ) {
@@ -99,7 +104,9 @@ class Custom_Permalinks_Frontend {
99
  if ( $original_url === NULL ) {
100
  // See if any terms have a matching permalink
101
  $table = get_option( 'custom_permalink_table' );
102
- if ( ! $table ) return $query;
 
 
103
 
104
  foreach ( array_keys( $table ) as $permalink ) {
105
  if ( $permalink == substr( $request_noslash, 0, strlen( $permalink ) )
@@ -107,8 +114,9 @@ class Custom_Permalinks_Frontend {
107
  $term = $table[$permalink];
108
 
109
  // Preserve this url for later if it's the same as the permalink (no extra stuff)
110
- if ( $request_noslash == trim( $permalink, '/' ) )
111
  $_CPRegisteredURL = $request;
 
112
 
113
  if ( $term['kind'] == 'category' ) {
114
  $category_link = $this->custom_permalinks_original_category_link( $term['id'] );
@@ -136,10 +144,11 @@ class Custom_Permalinks_Frontend {
136
  $_SERVER['QUERY_STRING'] = ( ( $pos = strpos( $original_url, '?' ) ) !== false ? substr( $original_url, $pos + 1 ) : '' );
137
  parse_str( $_SERVER['QUERY_STRING'], $query_array );
138
  $old_values = array();
139
- if ( is_array( $query_array ) )
140
- foreach ( $query_array as $key => $value ) {
141
- $old_values[$key] = $_REQUEST[$key];
142
- $_REQUEST[$key] = $_GET[$key] = $value;
 
143
  }
144
 
145
  // Re-run the filter, now with original environment in place
@@ -164,10 +173,13 @@ class Custom_Permalinks_Frontend {
164
  */
165
  public function custom_permalinks_redirect() {
166
  // Get request URI, strip parameters
167
- $url = parse_url( get_bloginfo( 'url' ) );
168
- $url = isset( $url['path'] ) ? $url['path'] : '';
169
  $request = ltrim( substr( $_SERVER['REQUEST_URI'], strlen( $url ) ), '/' );
170
- if ( ( $pos = strpos( $request, "?" ) ) ) $request = substr( $request, 0, $pos );
 
 
 
171
 
172
  if ( defined( 'POLYLANG_VERSION' ) ) {
173
  require_once( CUSTOM_PERMALINKS_PATH . 'admin/class-custom-permalinks-form.php' );
@@ -259,7 +271,9 @@ class Custom_Permalinks_Frontend {
259
  */
260
  public function custom_permalinks_term_link( $permalink, $term ) {
261
  $table = get_option( 'custom_permalink_table' );
262
- if ( is_object( $term ) ) $term = $term->term_id;
 
 
263
 
264
  $custom_permalink = $this->custom_permalinks_permalink_for_term( $term );
265
  if ( $custom_permalink ) {
@@ -346,7 +360,9 @@ class Custom_Permalinks_Frontend {
346
  $request = ltrim( isset( $url['path'] ) ? substr( $string, strlen( $url['path'] ) ) : $string, '/' );
347
  add_filter( 'user_trailingslashit', array( $this, 'custom_permalinks_trailingslash' ), 10, 2 );
348
 
349
- if ( ! trim( $request ) ) return $string;
 
 
350
 
351
  if ( trim( $_CPRegisteredURL, '/' ) == trim( $request, '/' ) ) {
352
  if ( isset( $url['path'] ) ) {
@@ -364,10 +380,11 @@ class Custom_Permalinks_Frontend {
364
  */
365
  public function custom_permalinks_permalink_for_term( $id ) {
366
  $table = get_option( 'custom_permalink_table' );
367
- if ( $table )
368
- foreach ( $table as $link => $info ) {
369
- if ( $info['id'] == $id ) {
370
- return $link;
 
371
  }
372
  }
373
  return false;
36
  $original_url = NULL;
37
 
38
  // Get request URI, strip parameters and /'s
39
+ $url = parse_url( get_bloginfo( 'url' ) );
40
+ $url = isset( $url['path'] ) ? $url['path'] : '';
41
  $request = ltrim( substr( $_SERVER['REQUEST_URI'], strlen( $url ) ), '/' );
42
  $request = ( ( $pos = strpos( $request, '?' ) ) ? substr( $request, 0, $pos ) : $request );
43
 
44
+ if ( ! $request ) {
45
+ return $query;
46
+ }
47
 
48
  $ignore = apply_filters( 'custom_permalinks_request_ignore', $request );
49
 
50
+ if ( '__true' === $ignore ) {
51
+ return $query;
52
+ }
53
 
54
  if ( defined( 'POLYLANG_VERSION' ) ) {
55
  require_once( CUSTOM_PERMALINKS_PATH . 'admin/class-custom-permalinks-form.php' );
75
  // A post matches our request
76
 
77
  // Preserve this url for later if it's the same as the permalink (no extra stuff)
78
+ if ( $request_noslash == trim( $posts[0]->meta_value, '/' ) ) {
79
  $_CPRegisteredURL = $request;
80
+ }
81
 
82
  if ( $posts[0]->post_status == 'draft' ) {
83
  if ( $posts[0]->post_type == 'page' ) {
104
  if ( $original_url === NULL ) {
105
  // See if any terms have a matching permalink
106
  $table = get_option( 'custom_permalink_table' );
107
+ if ( ! $table ) {
108
+ return $query;
109
+ }
110
 
111
  foreach ( array_keys( $table ) as $permalink ) {
112
  if ( $permalink == substr( $request_noslash, 0, strlen( $permalink ) )
114
  $term = $table[$permalink];
115
 
116
  // Preserve this url for later if it's the same as the permalink (no extra stuff)
117
+ if ( $request_noslash == trim( $permalink, '/' ) ) {
118
  $_CPRegisteredURL = $request;
119
+ }
120
 
121
  if ( $term['kind'] == 'category' ) {
122
  $category_link = $this->custom_permalinks_original_category_link( $term['id'] );
144
  $_SERVER['QUERY_STRING'] = ( ( $pos = strpos( $original_url, '?' ) ) !== false ? substr( $original_url, $pos + 1 ) : '' );
145
  parse_str( $_SERVER['QUERY_STRING'], $query_array );
146
  $old_values = array();
147
+ if ( is_array( $query_array ) ) {
148
+ foreach ( $query_array as $key => $value ) {
149
+ $old_values[$key] = $_REQUEST[$key];
150
+ $_REQUEST[$key] = $_GET[$key] = $value;
151
+ }
152
  }
153
 
154
  // Re-run the filter, now with original environment in place
173
  */
174
  public function custom_permalinks_redirect() {
175
  // Get request URI, strip parameters
176
+ $url = parse_url( get_bloginfo( 'url' ) );
177
+ $url = isset( $url['path'] ) ? $url['path'] : '';
178
  $request = ltrim( substr( $_SERVER['REQUEST_URI'], strlen( $url ) ), '/' );
179
+ $pos = strpos( $request, "?" );
180
+ if ( $pos ) {
181
+ $request = substr( $request, 0, $pos );
182
+ }
183
 
184
  if ( defined( 'POLYLANG_VERSION' ) ) {
185
  require_once( CUSTOM_PERMALINKS_PATH . 'admin/class-custom-permalinks-form.php' );
271
  */
272
  public function custom_permalinks_term_link( $permalink, $term ) {
273
  $table = get_option( 'custom_permalink_table' );
274
+ if ( is_object( $term ) ) {
275
+ $term = $term->term_id;
276
+ }
277
 
278
  $custom_permalink = $this->custom_permalinks_permalink_for_term( $term );
279
  if ( $custom_permalink ) {
360
  $request = ltrim( isset( $url['path'] ) ? substr( $string, strlen( $url['path'] ) ) : $string, '/' );
361
  add_filter( 'user_trailingslashit', array( $this, 'custom_permalinks_trailingslash' ), 10, 2 );
362
 
363
+ if ( ! trim( $request ) ) {
364
+ return $string;
365
+ }
366
 
367
  if ( trim( $_CPRegisteredURL, '/' ) == trim( $request, '/' ) ) {
368
  if ( isset( $url['path'] ) ) {
380
  */
381
  public function custom_permalinks_permalink_for_term( $id ) {
382
  $table = get_option( 'custom_permalink_table' );
383
+ if ( $table ) {
384
+ foreach ( $table as $link => $info ) {
385
+ if ( $info['id'] == $id ) {
386
+ return $link;
387
+ }
388
  }
389
  }
390
  return false;
readme.txt CHANGED
@@ -5,7 +5,7 @@ Donate link: https://www.paypal.me/yasglobal
5
  Tags: permalink, url, link, address, custom, redirect, custom post type
6
  Requires at least: 2.6
7
  Tested up to: 4.8
8
- Stable tag: 1.2.2
9
  License: GPLv2 or later
10
  License URI: http://www.gnu.org/licenses/gpl-2.0.html
11
 
@@ -31,7 +31,7 @@ within that category.
31
  If you want to exclude some Permalink to processed with the plugin so, just add the filter looks like this:
32
  `
33
  function check_xml_sitemap_url( $permalink ) {
34
- if ( strpos( $permalink, 'sitemap.xml' ) !== false ) {
35
  return '__true';
36
  }
37
  return;
@@ -47,6 +47,10 @@ add_filter( 'custom_permalinks_request_ignore', 'check_xml_sitemap_url' );
47
 
48
  == Changelog ==
49
 
 
 
 
 
50
  = 1.2.2 =
51
 
52
  * Fixed Typo of Class Object for term on Admin Page
5
  Tags: permalink, url, link, address, custom, redirect, custom post type
6
  Requires at least: 2.6
7
  Tested up to: 4.8
8
+ Stable tag: 1.2.3
9
  License: GPLv2 or later
10
  License URI: http://www.gnu.org/licenses/gpl-2.0.html
11
 
31
  If you want to exclude some Permalink to processed with the plugin so, just add the filter looks like this:
32
  `
33
  function check_xml_sitemap_url( $permalink ) {
34
+ if ( false !== strpos( $permalink, 'sitemap.xml' )) {
35
  return '__true';
36
  }
37
  return;
47
 
48
  == Changelog ==
49
 
50
+ = 1.2.3 =
51
+
52
+ * Fixed PHP Notice on Edit Post Page
53
+
54
  = 1.2.2 =
55
 
56
  * Fixed Typo of Class Object for term on Admin Page