Custom Permalinks - Version 0.7.9

Version Description

  • Support for custom post types, by Balzs Nmeth
Download this release

Release Info

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

Code changes from version 0.7.8 to 0.7.9

Files changed (2) hide show
  1. custom-permalinks.php +26 -22
  2. readme.txt +4 -0
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.8
8
  Author: Michael Tyson
9
  Author URI: http://atastypixel.com/blog
10
  */
@@ -106,7 +106,7 @@ function custom_permalinks_redirect() {
106
  if ( is_single() || is_page() ) {
107
  $post = $wp_query->post;
108
  $custom_permalink = get_post_meta( $post->ID, 'custom_permalink', true );
109
- $original_permalink = ( $post->post_type == 'post' ? custom_permalinks_original_post_link( $post->ID ) : custom_permalinks_original_page_link( $post->ID ) );
110
  } else if ( is_tag() || is_category() ) {
111
  $theTerm = $wp_query->get_queried_object();
112
  $custom_permalink = custom_permalinks_permalink_for_term($theTerm->term_id);
@@ -158,14 +158,15 @@ function custom_permalinks_request($query) {
158
 
159
  if ( !$request ) return $query;
160
 
161
- $sql = "SELECT $wpdb->posts.ID, $wpdb->postmeta.meta_value, $wpdb->posts.post_type FROM $wpdb->posts ".
162
- " LEFT JOIN $wpdb->postmeta ON ($wpdb->posts.ID = $wpdb->postmeta.post_id) WHERE ".
163
- " meta_key = 'custom_permalink' AND ".
164
- " meta_value != '' AND ".
165
- " ( meta_value = LEFT('".mysql_escape_string($request_noslash)."', LENGTH(meta_value)) OR ".
166
- " meta_value = LEFT('".mysql_escape_string($request_noslash."/")."', LENGTH(meta_value)) ) ".
167
- " ORDER BY LENGTH(meta_value) DESC";
168
-
 
169
  $posts = $wpdb->get_results($sql);
170
 
171
  if ( $posts ) {
@@ -175,11 +176,11 @@ function custom_permalinks_request($query) {
175
  if ( $request_noslash == trim($posts[0]->meta_value,'/') )
176
  $_CPRegisteredURL = $request;
177
 
178
- $originalUrl = preg_replace('@/+@', '/', str_replace( trim($posts[0]->meta_value,'/'),
179
- ( $posts[0]->post_type == 'post' ?
180
- custom_permalinks_original_post_link($posts[0]->ID)
181
- : custom_permalinks_original_page_link($posts[0]->ID) ),
182
- $request_noslash ));
183
  }
184
 
185
  if ( !$originalUrl ) {
@@ -279,13 +280,13 @@ function custom_permalink_get_sample_permalink_html($html, $id, $new_title, $new
279
 
280
  ob_start();
281
  ?>
282
- <?php custom_permalinks_form($permalink, ($post->post_type == "post" ? custom_permalinks_original_post_link($id) : custom_permalinks_original_page_link($id)), false); ?>
283
  <?php
284
  $content = ob_get_contents();
285
  ob_end_clean();
286
 
287
  if ( 'publish' == $post->post_status ) {
288
- $view_post = 'post' == $post->post_type ? __('View Post') : __('View Page');
289
  }
290
 
291
  if ( preg_match("@view-post-btn.*?href='([^']+)'@s", $html, $matches) ) {
@@ -618,8 +619,8 @@ function custom_permalinks_admin_rows() {
618
 
619
  // List posts/pages
620
  global $wpdb;
621
- $query = "SELECT $wpdb->posts.* FROM $wpdb->posts LEFT JOIN $wpdb->postmeta ON ($wpdb->posts.ID = $wpdb->postmeta.post_id) WHERE ".
622
- "$wpdb->postmeta.meta_key = 'custom_permalink' AND $wpdb->postmeta.meta_value != ''";
623
  $posts = $wpdb->get_results($query);
624
  foreach ( $posts as $post ) {
625
  $row = array();
@@ -642,9 +643,11 @@ function custom_permalinks_admin_rows() {
642
  * @since 0.1
643
  */
644
  function custom_permalinks_original_post_link($post_id) {
645
- remove_filter( 'post_link', 'custom_permalinks_post_link', 10, 2 );
646
- $originalPermalink = ltrim(str_replace(get_home_url(), '', get_permalink( $post_id )), '/');
647
- add_filter( 'post_link', 'custom_permalinks_post_link', 10, 2 );
 
 
648
  return $originalPermalink;
649
  }
650
 
@@ -727,6 +730,7 @@ $v = explode('.', get_bloginfo('version'));
727
 
728
  add_action( 'template_redirect', 'custom_permalinks_redirect', 5 );
729
  add_filter( 'post_link', 'custom_permalinks_post_link', 10, 2 );
 
730
  add_filter( 'page_link', 'custom_permalinks_page_link', 10, 2 );
731
  add_filter( 'tag_link', 'custom_permalinks_term_link', 10, 2 );
732
  add_filter( 'category_link', 'custom_permalinks_term_link', 10, 2 );
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.9
8
  Author: Michael Tyson
9
  Author URI: http://atastypixel.com/blog
10
  */
106
  if ( is_single() || is_page() ) {
107
  $post = $wp_query->post;
108
  $custom_permalink = get_post_meta( $post->ID, 'custom_permalink', true );
109
+ $original_permalink = ( $post->post_type == 'page' ? custom_permalinks_original_page_link( $post->ID ) : custom_permalinks_original_post_link( $post->ID ) );
110
  } else if ( is_tag() || is_category() ) {
111
  $theTerm = $wp_query->get_queried_object();
112
  $custom_permalink = custom_permalinks_permalink_for_term($theTerm->term_id);
158
 
159
  if ( !$request ) return $query;
160
 
161
+ $sql = "SELECT $wpdb->posts.ID, $wpdb->postmeta.meta_value, $wpdb->posts.post_type FROM $wpdb->posts ".
162
+ "LEFT JOIN $wpdb->postmeta ON ($wpdb->posts.ID = $wpdb->postmeta.post_id) WHERE ".
163
+ " meta_key = 'custom_permalink' AND ".
164
+ " meta_value != '' AND ".
165
+ " wp_posts.post_status = 'publish' AND ".
166
+ " ( meta_value = LEFT('".mysql_escape_string($request_noslash)."', LENGTH(meta_value)) OR ".
167
+ " meta_value = LEFT('".mysql_escape_string($request_noslash."/")."', LENGTH(meta_value)) ) ".
168
+ "ORDER BY LENGTH(meta_value) DESC";
169
+
170
  $posts = $wpdb->get_results($sql);
171
 
172
  if ( $posts ) {
176
  if ( $request_noslash == trim($posts[0]->meta_value,'/') )
177
  $_CPRegisteredURL = $request;
178
 
179
+ $originalUrl = preg_replace( '@/+@', '/', str_replace( trim( $posts[0]->meta_value,'/' ),
180
+ ( $posts[0]->post_type == 'page' ?
181
+ custom_permalinks_original_page_link($posts[0]->ID)
182
+ : custom_permalinks_original_post_link($posts[0]->ID) ),
183
+ $request_noslash ) );
184
  }
185
 
186
  if ( !$originalUrl ) {
280
 
281
  ob_start();
282
  ?>
283
+ <?php custom_permalinks_form($permalink, ($post->post_type == "page" ? custom_permalinks_original_page_link($id) : custom_permalinks_original_post_link($id)), false); ?>
284
  <?php
285
  $content = ob_get_contents();
286
  ob_end_clean();
287
 
288
  if ( 'publish' == $post->post_status ) {
289
+ $view_post = 'page' == $post->post_type ? __('View Page') : __('View Post');
290
  }
291
 
292
  if ( preg_match("@view-post-btn.*?href='([^']+)'@s", $html, $matches) ) {
619
 
620
  // List posts/pages
621
  global $wpdb;
622
+ $query = "SELECT $wpdb->posts.* FROM $wpdb->posts LEFT JOIN $wpdb->postmeta ON ($wpdb->posts.ID = $wpdb->postmeta.post_id) WHERE
623
+ $wpdb->postmeta.meta_key = 'custom_permalink' AND $wpdb->postmeta.meta_value != '';";
624
  $posts = $wpdb->get_results($query);
625
  foreach ( $posts as $post ) {
626
  $row = array();
643
  * @since 0.1
644
  */
645
  function custom_permalinks_original_post_link($post_id) {
646
+ remove_filter( 'post_link', 'custom_permalinks_post_link', 10, 2 ); // original hook
647
+ remove_filter( 'post_type_link', 'custom_permalinks_post_link', 10, 2 );
648
+ $originalPermalink = ltrim(str_replace(get_option('home'), '', get_permalink( $post_id )), '/');
649
+ add_filter( 'post_link', 'custom_permalinks_post_link', 10, 2 ); // original hook
650
+ add_filter( 'post_type_link', 'custom_permalinks_post_link', 10, 2 );
651
  return $originalPermalink;
652
  }
653
 
730
 
731
  add_action( 'template_redirect', 'custom_permalinks_redirect', 5 );
732
  add_filter( 'post_link', 'custom_permalinks_post_link', 10, 2 );
733
+ add_filter( 'post_type_link', 'custom_permalinks_post_link', 10, 2 );
734
  add_filter( 'page_link', 'custom_permalinks_page_link', 10, 2 );
735
  add_filter( 'tag_link', 'custom_permalinks_term_link', 10, 2 );
736
  add_filter( 'category_link', 'custom_permalinks_term_link', 10, 2 );
readme.txt CHANGED
@@ -29,6 +29,10 @@ within that category.
29
 
30
  == Changelog ==
31
 
 
 
 
 
32
  = 0.7.8 =
33
 
34
  * Support for non-ASCII characters in URLs
29
 
30
  == Changelog ==
31
 
32
+ = 0.7.9 =
33
+
34
+ * Support for custom post types, by Balázs Németh
35
+
36
  = 0.7.8 =
37
 
38
  * Support for non-ASCII characters in URLs