Custom Permalinks - Version 0.7.8

Version Description

  • Support for non-ASCII characters in URLs
    • Fixed bug where adding a new tag when saving a post with a custom permalink attaches that permalink to the new tag
    • Some compatibility fixes for WP 3.2.1
Download this release

Release Info

Developer michaeltyson
Plugin Icon Custom Permalinks
Version 0.7.8
Comparing to
See all releases

Code changes from version 0.7.7 to 0.7.8

Files changed (2) hide show
  1. custom-permalinks.php +14 -14
  2. readme.txt +13 -1
custom-permalinks.php CHANGED
@@ -4,7 +4,7 @@ Plugin Name: Custom Permalinks
4
  Plugin URI: http://atastypixel.com/blog/wordpress/plugins/custom-permalinks/
5
  Donate link: http://atastypixel.com/blog/wordpress/plugins/custom-permalinks/
6
  Description: Set custom permalinks on a per-post basis
7
- Version: 0.7.7
8
  Author: Michael Tyson
9
  Author URI: http://atastypixel.com/blog
10
  */
@@ -211,7 +211,7 @@ function custom_permalinks_request($query) {
211
  }
212
 
213
  if ( $originalUrl ) {
214
- $originalUrl = str_replace('//', '/', urldecode($originalUrl));
215
 
216
  if ( ($pos=strpos($_SERVER['REQUEST_URI'], '?')) !== false ) {
217
  $queryVars = substr($_SERVER['REQUEST_URI'], $pos+1);
@@ -220,8 +220,8 @@ function custom_permalinks_request($query) {
220
 
221
  // Now we have the original URL, run this back through WP->parse_request, in order to
222
  // parse parameters properly. We set $_SERVER variables to fool the function.
223
- $oldPathInfo = $_SERVER['PATH_INFO']; $oldRequestUri = $_SERVER['REQUEST_URI']; $oldQueryString = $_SERVER['QUERY_STRING'];
224
- $_SERVER['REQUEST_URI'] = $_SERVER['PATH_INFO'] = '/'.ltrim($originalUrl,'/');
225
  $_SERVER['QUERY_STRING'] = (($pos=strpos($originalUrl, '?')) !== false ? substr($originalUrl, $pos+1) : '');
226
  parse_str($_SERVER['QUERY_STRING'], $queryArray);
227
  $oldValues = array();
@@ -239,7 +239,7 @@ function custom_permalinks_request($query) {
239
  add_filter( 'request', 'custom_permalinks_request', 10, 1 );
240
 
241
  // Restore values
242
- $_SERVER['PATH_INFO'] = $oldPathInfo; $_SERVER['REQUEST_URI'] = $oldRequestUri; $_SERVER['QUERY_STRING'] = $oldQueryString;
243
  foreach ( $oldValues as $key => $value ) {
244
  $_REQUEST[$key] = $value;
245
  }
@@ -392,7 +392,7 @@ function custom_permalinks_term_options($object) {
392
  function custom_permalinks_form($permalink, $original="", $renderContainers=true) {
393
  ?>
394
  <input value="true" type="hidden" name="custom_permalinks_edit" />
395
- <input value="<?php echo htmlspecialchars($permalink) ?>" type="hidden" name="custom_permalink" id="custom_permalink" />
396
 
397
  <?php if ( $renderContainers ) : ?>
398
  <table class="form-table" id="custom_permalink_form">
@@ -401,10 +401,10 @@ function custom_permalinks_form($permalink, $original="", $renderContainers=true
401
  <td>
402
  <?php endif; ?>
403
  <?php echo get_home_url() ?>/
404
- <input type="text" class="text" value="<?php echo htmlspecialchars($permalink ? $permalink : $original) ?>"
405
  style="width: 250px; <?php if ( !$permalink ) echo 'color: #ddd;' ?>"
406
  onfocus="if ( this.style.color = '#ddd' ) { this.style.color = '#000'; }"
407
- onblur="document.getElementById('custom_permalink').value = this.value; if ( this.value == '' || this.value == '<?php echo htmlspecialchars($original) ?>' ) { this.value = '<?php echo htmlspecialchars($original) ?>'; this.style.color = '#ddd'; }"/>
408
  <?php if ( $renderContainers ) : ?>
409
  <br />
410
  <small><?php _e('Leave blank to disable', 'custom-permalink') ?></small>
@@ -432,7 +432,7 @@ function custom_permalinks_save_post($id) {
432
  $permalink_structure = get_option('permalink_structure');
433
 
434
  if ( $_REQUEST['custom_permalink'] && $_REQUEST['custom_permalink'] != $original_link ) {
435
- add_post_meta( $id, 'custom_permalink', ltrim(stripcslashes($_REQUEST['custom_permalink']),"/") );
436
  }
437
  }
438
 
@@ -444,14 +444,14 @@ function custom_permalinks_save_post($id) {
444
  * @since 0.1
445
  */
446
  function custom_permalinks_save_tag($id) {
447
- if ( !isset($_REQUEST['custom_permalinks_edit']) ) return;
448
  $newPermalink = ltrim(stripcslashes($_REQUEST['custom_permalink']),"/");
449
 
450
  if ( $newPermalink == custom_permalinks_original_tag_link($id) )
451
  $newPermalink = '';
452
 
453
  $term = get_term($id, 'post_tag');
454
- custom_permalinks_save_term($term, $newPermalink);
455
  }
456
 
457
  /**
@@ -461,14 +461,14 @@ function custom_permalinks_save_tag($id) {
461
  * @since 0.1
462
  */
463
  function custom_permalinks_save_category($id) {
464
- if ( !isset($_REQUEST['custom_permalinks_edit']) ) return;
465
  $newPermalink = ltrim(stripcslashes($_REQUEST['custom_permalink']),"/");
466
 
467
  if ( $newPermalink == custom_permalinks_original_category_link($id) )
468
  $newPermalink = '';
469
 
470
  $term = get_term($id, 'category');
471
- custom_permalinks_save_term($term, $newPermalink);
472
  }
473
 
474
  /**
@@ -578,7 +578,7 @@ function custom_permalinks_options_page() {
578
  <td><strong><a class="row-title" href="<?php echo htmlspecialchars($row['editlink']) ?>"><?php echo htmlspecialchars($row['title']) ?></a></strong></td>
579
  <td><?php echo htmlspecialchars($row['type']) ?></td>
580
  <td><a href="<?php echo $row['permalink'] ?>" target="_blank" title="Visit <?php echo htmlspecialchars($row['title']) ?>">
581
- <?php echo htmlspecialchars($row['permalink']) ?>
582
  </a>
583
  </td>
584
  </tr>
4
  Plugin URI: http://atastypixel.com/blog/wordpress/plugins/custom-permalinks/
5
  Donate link: http://atastypixel.com/blog/wordpress/plugins/custom-permalinks/
6
  Description: Set custom permalinks on a per-post basis
7
+ Version: 0.7.8
8
  Author: Michael Tyson
9
  Author URI: http://atastypixel.com/blog
10
  */
211
  }
212
 
213
  if ( $originalUrl ) {
214
+ $originalUrl = str_replace('//', '/', $originalUrl);
215
 
216
  if ( ($pos=strpos($_SERVER['REQUEST_URI'], '?')) !== false ) {
217
  $queryVars = substr($_SERVER['REQUEST_URI'], $pos+1);
220
 
221
  // Now we have the original URL, run this back through WP->parse_request, in order to
222
  // parse parameters properly. We set $_SERVER variables to fool the function.
223
+ $oldRequestUri = $_SERVER['REQUEST_URI']; $oldQueryString = $_SERVER['QUERY_STRING'];
224
+ $_SERVER['REQUEST_URI'] = '/'.ltrim($originalUrl,'/');
225
  $_SERVER['QUERY_STRING'] = (($pos=strpos($originalUrl, '?')) !== false ? substr($originalUrl, $pos+1) : '');
226
  parse_str($_SERVER['QUERY_STRING'], $queryArray);
227
  $oldValues = array();
239
  add_filter( 'request', 'custom_permalinks_request', 10, 1 );
240
 
241
  // Restore values
242
+ $_SERVER['REQUEST_URI'] = $oldRequestUri; $_SERVER['QUERY_STRING'] = $oldQueryString;
243
  foreach ( $oldValues as $key => $value ) {
244
  $_REQUEST[$key] = $value;
245
  }
392
  function custom_permalinks_form($permalink, $original="", $renderContainers=true) {
393
  ?>
394
  <input value="true" type="hidden" name="custom_permalinks_edit" />
395
+ <input value="<?php echo htmlspecialchars(urldecode($permalink)) ?>" type="hidden" name="custom_permalink" id="custom_permalink" />
396
 
397
  <?php if ( $renderContainers ) : ?>
398
  <table class="form-table" id="custom_permalink_form">
401
  <td>
402
  <?php endif; ?>
403
  <?php echo get_home_url() ?>/
404
+ <input type="text" class="text" value="<?php echo htmlspecialchars($permalink ? urldecode($permalink) : urldecode($original)) ?>"
405
  style="width: 250px; <?php if ( !$permalink ) echo 'color: #ddd;' ?>"
406
  onfocus="if ( this.style.color = '#ddd' ) { this.style.color = '#000'; }"
407
+ onblur="document.getElementById('custom_permalink').value = this.value; if ( this.value == '' || this.value == '<?php echo htmlspecialchars(urldecode($original)) ?>' ) { this.value = '<?php echo htmlspecialchars(urldecode($original)) ?>'; this.style.color = '#ddd'; }"/>
408
  <?php if ( $renderContainers ) : ?>
409
  <br />
410
  <small><?php _e('Leave blank to disable', 'custom-permalink') ?></small>
432
  $permalink_structure = get_option('permalink_structure');
433
 
434
  if ( $_REQUEST['custom_permalink'] && $_REQUEST['custom_permalink'] != $original_link ) {
435
+ add_post_meta( $id, 'custom_permalink', str_replace('%2F', '/', urlencode(ltrim(stripcslashes($_REQUEST['custom_permalink']),"/"))) );
436
  }
437
  }
438
 
444
  * @since 0.1
445
  */
446
  function custom_permalinks_save_tag($id) {
447
+ if ( !isset($_REQUEST['custom_permalinks_edit']) || isset($_REQUEST['post_ID']) ) return;
448
  $newPermalink = ltrim(stripcslashes($_REQUEST['custom_permalink']),"/");
449
 
450
  if ( $newPermalink == custom_permalinks_original_tag_link($id) )
451
  $newPermalink = '';
452
 
453
  $term = get_term($id, 'post_tag');
454
+ custom_permalinks_save_term($term, str_replace('%2F', '/', urlencode($newPermalink)));
455
  }
456
 
457
  /**
461
  * @since 0.1
462
  */
463
  function custom_permalinks_save_category($id) {
464
+ if ( !isset($_REQUEST['custom_permalinks_edit']) || isset($_REQUEST['post_ID']) ) return;
465
  $newPermalink = ltrim(stripcslashes($_REQUEST['custom_permalink']),"/");
466
 
467
  if ( $newPermalink == custom_permalinks_original_category_link($id) )
468
  $newPermalink = '';
469
 
470
  $term = get_term($id, 'category');
471
+ custom_permalinks_save_term($term, str_replace('%2F', '/', urlencode($newPermalink)));
472
  }
473
 
474
  /**
578
  <td><strong><a class="row-title" href="<?php echo htmlspecialchars($row['editlink']) ?>"><?php echo htmlspecialchars($row['title']) ?></a></strong></td>
579
  <td><?php echo htmlspecialchars($row['type']) ?></td>
580
  <td><a href="<?php echo $row['permalink'] ?>" target="_blank" title="Visit <?php echo htmlspecialchars($row['title']) ?>">
581
+ <?php echo htmlspecialchars(urldecode($row['permalink'])) ?>
582
  </a>
583
  </td>
584
  </tr>
readme.txt CHANGED
@@ -4,7 +4,7 @@ Donate link: http://atastypixel.com/blog/wordpress/plugins/custom-permalinks/
4
  Tags: permalink, url, link, address, custom, redirect
5
  Requires at least: 2.6
6
  Tested up to: 3.2.1
7
- Stable tag: 0.7.7
8
 
9
  Set custom permalinks on a per-post, per-tag or per-category basis.
10
 
@@ -14,6 +14,12 @@ Lay out your site the way *you* want it. Set the URL of any post, page, tag or c
14
  Old permalinks will redirect properly to the new address. Custom Permalinks gives you ultimate control
15
  over your site structure.
16
 
 
 
 
 
 
 
17
 
18
  == Installation ==
19
 
@@ -23,6 +29,12 @@ over your site structure.
23
 
24
  == Changelog ==
25
 
 
 
 
 
 
 
26
  = 0.7.7 =
27
 
28
  * Minor change to permalink saving routine to fix some possible issues
4
  Tags: permalink, url, link, address, custom, redirect
5
  Requires at least: 2.6
6
  Tested up to: 3.2.1
7
+ Stable tag: 0.7.8
8
 
9
  Set custom permalinks on a per-post, per-tag or per-category basis.
10
 
14
  Old permalinks will redirect properly to the new address. Custom Permalinks gives you ultimate control
15
  over your site structure.
16
 
17
+ Be warned: *This plugin is not a replacement for WordPress's built-in permalink system*. Check your WordPress
18
+ administration's "Permalinks" settings page first, to make sure that this doesn't already meet your needs.
19
+
20
+ This plugin is only useful for assigning custom permalinks for *individual* posts, pages, tags or categories.
21
+ It will not apply whole permalink structures, or automatically apply a category's custom permalink to the posts
22
+ within that category.
23
 
24
  == Installation ==
25
 
29
 
30
  == Changelog ==
31
 
32
+ = 0.7.8 =
33
+
34
+ * Support for non-ASCII characters in URLs
35
+ * Fixed bug where adding a new tag when saving a post with a custom permalink attaches that permalink to the new tag
36
+ * Some compatibility fixes for WP 3.2.1
37
+
38
  = 0.7.7 =
39
 
40
  * Minor change to permalink saving routine to fix some possible issues