Changeset 1215633
- Timestamp:
- 08/08/2015 10:34:56 AM (11 years ago)
- Location:
- shorter-links/trunk
- Files:
-
- 2 edited
-
readme.txt (modified) (2 diffs)
-
shorter_links.php (modified) (3 diffs)
Legend:
- Unmodified
- Added
- Removed
-
shorter-links/trunk/readme.txt
r1215504 r1215633 5 5 Requires at least: 3.0 6 6 Tested up to: 4.3 7 Stable tag: 2. 0.67 Stable tag: 2.1.0 8 8 License: New-BSD 9 9 License URI: http://akrabat.com/license/new-bsd … … 62 62 63 63 64 **2.1.0 - 8 August 2015** 65 Rework to look for the shorter link after WordPress has done its processing. This 66 means that a shorterlink that represents a date won't affect an archive list. 67 64 68 **2.0.6 - 8 August 2015** 65 69 Ensure that the short_link is correct when using a post id. -
shorter-links/trunk/shorter_links.php
r1215555 r1215633 4 4 Plugin URI: http://wordpress.org/extend/plugins/shorter-links/ 5 5 Description: Overrides WordPress' shortlink functionality to allow custom shortcodes per post. 6 Version: 2. 0.66 Version: 2.1.0 7 7 Author: Rob Allen 8 8 Author URI: http://akrabat.com … … 14 14 const META_FIELD_NAME='Shorter link'; 15 15 16 public function request($query_vars) 16 /** 17 * Redirect to a shorter link if we can. This hook is called after WP has done 18 * its processing, so we can check if we have a 404 to determine if we need to 19 * look for a shorter link. 20 * 21 * @param WP $wp 22 * @return null 23 */ 24 public function redirectToShorterLink(WP $wp) 17 25 { 18 // check if pagename or category_name matches a short link 19 $shortLink = ''; 20 if (array_key_exists('pagename', $query_vars)) { 21 $shortLink = $query_vars['pagename']; 22 } 23 if (array_key_exists('category_name', $query_vars)) { 24 $shortLink = $query_vars['category_name']; 25 } 26 if (array_key_exists('year', $query_vars)) { 27 $shortLink = $query_vars['year']; 28 } 29 if(empty($shortLink) && isset($_SERVER['REQUEST_URI'])) { 30 $shortLink = trim($_SERVER['REQUEST_URI'], '/'); 31 } 32 if (empty($shortLink)) { 33 return $query_vars; 34 } 26 if (is_404()) { 27 // WordPress didn't find anything to display, so look for a shortlink 28 $shortLink = $wp->request; 29 // $shortLink = preg_replace('#/.*#i', "", $WP->request); // only need first segment 35 30 36 // try for permalink first 37 if (is_numeric($shortLink)) { 38 $post = get_post( $shortLink); 39 if ($post->post_status == 'publish') { 40 $link = get_permalink($shortLink); 41 if ($link) { 42 wp_redirect($link); 31 // if it's a number, then test for a post id first 32 if (is_numeric($shortLink)) { 33 $post = get_post( $shortLink); 34 if ($post->post_status == 'publish') { 35 $link = get_permalink($shortLink); 36 if ($link) { 37 wp_redirect($link); 38 exit; 39 } 40 } 41 } 42 43 // Look up the post or page with this shorter link 44 $query = array('meta_key' => self::META_FIELD_NAME, 'meta_value' => $shortLink); 45 $posts = get_posts($query); 46 if (count($posts) > 0) { 47 wp_redirect(get_permalink($posts[0]), 301); 48 exit; 49 } else { 50 $pages = get_pages($query); 51 if (count($pages) > 0) { 52 wp_redirect(get_permalink($pages[0]), 301); 43 53 exit; 44 54 } 45 55 } 46 56 } 47 48 // Look up the post or page with this shorter link49 $query = array('meta_key' => self::META_FIELD_NAME, 'meta_value' => $shortLink);50 $posts = get_posts($query);51 if (count($posts) > 0) {52 wp_redirect(get_permalink($posts[0]), 301);53 exit;54 } else {55 $pages = get_pages($query);56 if (count($pages) > 0) {57 wp_redirect(get_permalink($pages[0]), 301);58 exit;59 }60 }61 62 return $query_vars;63 57 } 64 58 … … 128 122 129 123 $akrabatShorterLinks = new AkrabatShorterLinks(); 130 add_filter(' request', array(&$akrabatShorterLinks, 'request'));131 add_ filter('pre_get_shortlink', array(&$akrabatShorterLinks, 'pre_get_shortlink'), 10, 4);132 add_action('save_post', array( &$akrabatShorterLinks, 'save_post'), 10, 2);133 add_action('admin_menu', array( &$akrabatShorterLinks, 'admin_menu'));134 add_action('admin_init', array( &$akrabatShorterLinks, 'admin_init'));124 add_filter('pre_get_shortlink', array($akrabatShorterLinks, 'pre_get_shortlink'), 10, 4); 125 add_action('wp', array($akrabatShorterLinks, 'redirectToShorterLink')); 126 add_action('save_post', array($akrabatShorterLinks, 'save_post'), 10, 2); 127 add_action('admin_menu', array($akrabatShorterLinks, 'admin_menu')); 128 add_action('admin_init', array($akrabatShorterLinks, 'admin_init')); 135 129 136 130 // vim: set filetype=php expandtab tabstop=4 shiftwidth=4 autoindent smartindent:
Note: See TracChangeset
for help on using the changeset viewer.