Changeset 469102
- Timestamp:
- 11/29/2011 02:34:33 PM (14 years ago)
- Location:
- custom-permalinks
- Files:
-
- 3 added
- 2 edited
-
tags/0.7.9 (added)
-
tags/0.7.9/custom-permalinks.php (added)
-
tags/0.7.9/readme.txt (added)
-
trunk/custom-permalinks.php (modified) (9 diffs)
-
trunk/readme.txt (modified) (1 diff)
Legend:
- Unmodified
- Added
- Removed
-
custom-permalinks/trunk/custom-permalinks.php
r462757 r469102 5 5 Donate link: http://atastypixel.com/blog/wordpress/plugins/custom-permalinks/ 6 6 Description: Set custom permalinks on a per-post basis 7 Version: 0.7. 87 Version: 0.7.9 8 8 Author: Michael Tyson 9 9 Author URI: http://atastypixel.com/blog … … 107 107 $post = $wp_query->post; 108 108 $custom_permalink = get_post_meta( $post->ID, 'custom_permalink', true ); 109 $original_permalink = ( $post->post_type == 'p ost' ? custom_permalinks_original_post_link( $post->ID ) : custom_permalinks_original_page_link( $post->ID ) );109 $original_permalink = ( $post->post_type == 'page' ? custom_permalinks_original_page_link( $post->ID ) : custom_permalinks_original_post_link( $post->ID ) ); 110 110 } else if ( is_tag() || is_category() ) { 111 111 $theTerm = $wp_query->get_queried_object(); … … 159 159 if ( !$request ) return $query; 160 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 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 169 170 $posts = $wpdb->get_results($sql); 170 171 … … 176 177 $_CPRegisteredURL = $request; 177 178 178 $originalUrl = preg_replace( '@/+@', '/', str_replace( trim($posts[0]->meta_value,'/'),179 ( $posts[0]->post_type == 'post' ?180 custom_permalinks_original_p ost_link($posts[0]->ID)181 : custom_permalinks_original_p age_link($posts[0]->ID) ),182 $request_noslash ) );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 ) ); 183 184 } 184 185 … … 280 281 ob_start(); 281 282 ?> 282 <?php custom_permalinks_form($permalink, ($post->post_type == "p ost" ? custom_permalinks_original_post_link($id) : custom_permalinks_original_page_link($id)), false); ?>283 <?php custom_permalinks_form($permalink, ($post->post_type == "page" ? custom_permalinks_original_page_link($id) : custom_permalinks_original_post_link($id)), false); ?> 283 284 <?php 284 285 $content = ob_get_contents(); … … 286 287 287 288 if ( 'publish' == $post->post_status ) { 288 $view_post = 'post' == $post->post_type ? __('View Post') : __('View Page');289 $view_post = 'page' == $post->post_type ? __('View Page') : __('View Post'); 289 290 } 290 291 … … 619 620 // List posts/pages 620 621 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 != ''";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 != '';"; 623 624 $posts = $wpdb->get_results($query); 624 625 foreach ( $posts as $post ) { … … 643 644 */ 644 645 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 ); 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 ); 648 651 return $originalPermalink; 649 652 } … … 728 731 add_action( 'template_redirect', 'custom_permalinks_redirect', 5 ); 729 732 add_filter( 'post_link', 'custom_permalinks_post_link', 10, 2 ); 733 add_filter( 'post_type_link', 'custom_permalinks_post_link', 10, 2 ); 730 734 add_filter( 'page_link', 'custom_permalinks_page_link', 10, 2 ); 731 735 add_filter( 'tag_link', 'custom_permalinks_term_link', 10, 2 ); -
custom-permalinks/trunk/readme.txt
r463703 r469102 29 29 30 30 == Changelog == 31 32 = 0.7.9 = 33 34 * Support for custom post types, by Balázs Németh 31 35 32 36 = 0.7.8 =
Note: See TracChangeset
for help on using the changeset viewer.