Quick Page/Post Redirect Plugin - Version 3.0

Version Description

  • Enhance filter function in main class to reduce Database calls. (06/20/2010)
Download this release

Release Info

Developer prophecy2040
Plugin Icon 128x128 Quick Page/Post Redirect Plugin
Version 3.0
Comparing to
See all releases

Code changes from version 2.1 to 3.0

Files changed (2) hide show
  1. page_post_redirect_plugin.php +21 -18
  2. readme.txt +17 -5
page_post_redirect_plugin.php CHANGED
@@ -2,12 +2,13 @@
2
  /*
3
  Plugin Name: Quick Page/Post Redirect
4
  Plugin URI: http://fischercreativemedia.com/wordpress-plugins/quick-pagepost-redirct-plugin/
5
- Description: Redirect Pages or Posts to another location quickly. Adds a redirect box to the page or post edit page where you can specify the redirect Location and type which can be to another WordPress page/post or an external URL. Additional 301 Redirects can also be added for non-existant posts or pages - helpful for sites converted to WordPress. Version 1.9 and up allows for redirects to open in a new window as well as giving you the ability to add the rel=nofollow to redirected links.
6
  Author: Don Fischer
7
  Author URI: http://www.fischercreativemedia.com/
8
- Version: 2.1
9
 
10
  Version info:
 
11
  2.1 - Fix Bug - Open in New Window would not work unless Show Link URL was also selected. (3/12/2010)
12
  - Fix Bug - Add rel=nofollow would not work if Open in a New Window was not selected. (3/13/2010)
13
  - Fix Bug - Show Link, Add nofollow and Open in New Window would still work when redirect not active. (3/13/2010)
@@ -184,6 +185,9 @@ Version info:
184
  //----------
185
  global $wpdb;
186
  global $wp_query;
 
 
 
187
 
188
  // Functions
189
  //----------
@@ -195,17 +199,20 @@ Version info:
195
 
196
  // used to get the meta_value and ID of a post with specific meta_key.
197
  function ppr_get_metavalfromkey($key) {
198
- global $wpdb;
199
- return $wpdb->get_results( $wpdb->prepare( "SELECT post_id, meta_value FROM $wpdb->postmeta WHERE meta_key=%s and post_id in (SELECT post_id FROM $wpdb->postmeta WHERE meta_key='_pprredirect_active')", $key ) );
 
 
 
200
  }
201
 
202
  //clean up the Custom Fields to make it prettier on the Edit Page
203
  function ppr_init_metaclean() {
204
  $thepprversion = get_option('ppr_version');
205
- if ($thepprversion!='2.1') {
206
  //nothing;
207
- }else if ($thepprversion == '1.9' || $thepprversion == '2.0') {
208
- update_option( 'ppr_version', '2.1' );
209
  }else{
210
  global $wpdb;
211
  //want to make sure older version upgrading still
@@ -216,7 +223,7 @@ Version info:
216
  $wpdb->query( "UPDATE $wpdb->postmeta SET meta_key = '_pprredirect_url' WHERE meta_key = 'pprredirect_url'" );
217
  wp_cache_flush();
218
  //end remove
219
- update_option( 'ppr_version', '2.1' );
220
  }
221
  }
222
 
@@ -242,7 +249,12 @@ Version info:
242
  }else{
243
  $id = $post;
244
  }
245
- $ppr_rewrite = get_post_meta($id,'_pprredirect_rewritelink',true);
 
 
 
 
 
246
  if (isset($ppr_cache[$id]) ){
247
  if($ppr_rewrite==='1'){ //only change the link if they want - otherwise, we will redirect the old way.
248
  if(strpos($ppr_cache[$id],get_bloginfo('url'))>=0 || strpos($ppr_cache[$id],'www.')>=0 || strpos($ppr_cache[$id],'http://')>=0 || strpos($ppr_cache[$id],'https://')>=0){
@@ -252,7 +264,6 @@ Version info:
252
  }
253
  }
254
  }
255
- return $link;
256
  }
257
 
258
  function ppr_linktometa() {
@@ -263,9 +274,7 @@ Version info:
263
  $links_to = ppr_get_metavalfromkey('_pprredirect_url');
264
  if(count($links_to)>0){
265
  foreach((array) $links_to as $link){
266
- //if(get_post_meta($link->post_id,'_pprredirect_active',true)!=''){
267
  $ppr_cache[$blog_id][$link->post_id] = $link->meta_value;
268
- //}
269
  }
270
  return $ppr_cache[$blog_id];
271
  }else{
@@ -306,7 +315,6 @@ Version info:
306
  foreach((array) $links_to as $link){
307
  $ppr_norel[$blog_id][$link->post_id] = $link->meta_value;
308
  }
309
- //print_r($ppr_norel[$blog_id]);
310
  return $ppr_norel[$blog_id];
311
  }
312
 
@@ -501,12 +509,10 @@ Version info:
501
  foreach($norels as $relid => $rel){
502
  $validexp="/page-item-".$relid."\"><a(?:.*)rel=\"nofollow\"(?:.*?)>/i";
503
  $found = preg_match_all($validexp, $pages, $matches);
504
- //if(strpos($pages,'page-item-'.$relid.'">a href="'.$rel.'" rel="nofollow" ')>0) {
505
  if($found!=0){
506
  $pages = $pages; //do nothing 'cause it is already a rel=nofollow.
507
  }else{
508
  $pages = preg_replace('/page-item-'.$relid.'"><a(.*?)>/i', 'page-item-'.$relid.'"><a\1 rel="nofollow">', $pages);
509
- //$pages = str_replace(' href="'.$rel.'"',' href="'.$rel.'" rel="nofollow" ', $pages); //add no follow.
510
  }
511
  }
512
  }
@@ -517,13 +523,10 @@ Version info:
517
  $t = esc_url($t);
518
  $validexp="/page-item-".$p."\"><a(?:.*)target=\"_blank\"(?:.*?)>/i";
519
  $found = preg_match_all($validexp, $pages, $matches);
520
- //if(strpos($pages,' href="'.$t.'" target="'.$p.'" ')>0){
521
- //$pages = $pages; //already has a target
522
  if($found!=0){
523
  $pages = $pages; //do nothing 'cause it is already a rel=nofollow.
524
  }else{
525
  $pages = preg_replace('/page-item-'.$p.'"><a(.*?)>/i', 'page-item-'.$p.'"><a\1 target="_blank">', $pages);
526
- //$pages = str_replace(' href="'.$p.'" ',' href="'.$p.'" target="'.$t.'" ', $pages);
527
  }
528
  }
529
  }
2
  /*
3
  Plugin Name: Quick Page/Post Redirect
4
  Plugin URI: http://fischercreativemedia.com/wordpress-plugins/quick-pagepost-redirct-plugin/
5
+ Description: Redirect Pages or Posts to another location quickly. Easy to use Edit Page option box allows for new window redirects, rel=nofollow and masked URL additions, redirect types (301, 302, etc) and redirects for internal or external URLs. Additional 301 Redirects can also be added for non-existant posts or pages.
6
  Author: Don Fischer
7
  Author URI: http://www.fischercreativemedia.com/
8
+ Version: 3.0
9
 
10
  Version info:
11
+ 3.0 - Enhance Filter to reduce number of DB calls. (06/20/10)
12
  2.1 - Fix Bug - Open in New Window would not work unless Show Link URL was also selected. (3/12/2010)
13
  - Fix Bug - Add rel=nofollow would not work if Open in a New Window was not selected. (3/13/2010)
14
  - Fix Bug - Show Link, Add nofollow and Open in New Window would still work when redirect not active. (3/13/2010)
185
  //----------
186
  global $wpdb;
187
  global $wp_query;
188
+ global $pprpagemetakeypairs;
189
+ $pprpagemetakeypairs = array();
190
+
191
 
192
  // Functions
193
  //----------
199
 
200
  // used to get the meta_value and ID of a post with specific meta_key.
201
  function ppr_get_metavalfromkey($key) {
202
+ global $wpdb, $pprpagemetakeypairs;
203
+ if(!isset($pprpagemetakeypairs[$key])){ //if object doesnt exist, create
204
+ $pprpagemetakeypairs[$key] = $wpdb->get_results( $wpdb->prepare( "SELECT post_id, meta_value FROM $wpdb->postmeta WHERE meta_key=%s and post_id in (SELECT post_id FROM $wpdb->postmeta WHERE meta_key='_pprredirect_active')", $key ) );
205
+ }
206
+ return $pprpagemetakeypairs[$key];
207
  }
208
 
209
  //clean up the Custom Fields to make it prettier on the Edit Page
210
  function ppr_init_metaclean() {
211
  $thepprversion = get_option('ppr_version');
212
+ if ($thepprversion=='3.0') {
213
  //nothing;
214
+ }else if ($thepprversion == '1.9' || $thepprversion == '2.0' || $thepprversion == '2.1') {
215
+ update_option( 'ppr_version', '3.0' );
216
  }else{
217
  global $wpdb;
218
  //want to make sure older version upgrading still
223
  $wpdb->query( "UPDATE $wpdb->postmeta SET meta_key = '_pprredirect_url' WHERE meta_key = 'pprredirect_url'" );
224
  wp_cache_flush();
225
  //end remove
226
+ update_option( 'ppr_version', '3.0' );
227
  }
228
  }
229
 
249
  }else{
250
  $id = $post;
251
  }
252
+ $ppr_rewrite_temp = ppr_get_metavalfromkey('_pprredirect_rewritelink');
253
+ $pprvals=array();
254
+ foreach($ppr_rewrite_temp as $pprrew){
255
+ $pprvals[$pprrew->post_id] = $pprrew->meta_value;
256
+ }
257
+ $ppr_rewrite = $pprvals[$id];
258
  if (isset($ppr_cache[$id]) ){
259
  if($ppr_rewrite==='1'){ //only change the link if they want - otherwise, we will redirect the old way.
260
  if(strpos($ppr_cache[$id],get_bloginfo('url'))>=0 || strpos($ppr_cache[$id],'www.')>=0 || strpos($ppr_cache[$id],'http://')>=0 || strpos($ppr_cache[$id],'https://')>=0){
264
  }
265
  }
266
  }
 
267
  }
268
 
269
  function ppr_linktometa() {
274
  $links_to = ppr_get_metavalfromkey('_pprredirect_url');
275
  if(count($links_to)>0){
276
  foreach((array) $links_to as $link){
 
277
  $ppr_cache[$blog_id][$link->post_id] = $link->meta_value;
 
278
  }
279
  return $ppr_cache[$blog_id];
280
  }else{
315
  foreach((array) $links_to as $link){
316
  $ppr_norel[$blog_id][$link->post_id] = $link->meta_value;
317
  }
 
318
  return $ppr_norel[$blog_id];
319
  }
320
 
509
  foreach($norels as $relid => $rel){
510
  $validexp="/page-item-".$relid."\"><a(?:.*)rel=\"nofollow\"(?:.*?)>/i";
511
  $found = preg_match_all($validexp, $pages, $matches);
 
512
  if($found!=0){
513
  $pages = $pages; //do nothing 'cause it is already a rel=nofollow.
514
  }else{
515
  $pages = preg_replace('/page-item-'.$relid.'"><a(.*?)>/i', 'page-item-'.$relid.'"><a\1 rel="nofollow">', $pages);
 
516
  }
517
  }
518
  }
523
  $t = esc_url($t);
524
  $validexp="/page-item-".$p."\"><a(?:.*)target=\"_blank\"(?:.*?)>/i";
525
  $found = preg_match_all($validexp, $pages, $matches);
 
 
526
  if($found!=0){
527
  $pages = $pages; //do nothing 'cause it is already a rel=nofollow.
528
  }else{
529
  $pages = preg_replace('/page-item-'.$p.'"><a(.*?)>/i', 'page-item-'.$p.'"><a\1 target="_blank">', $pages);
 
530
  }
531
  }
532
  }
readme.txt CHANGED
@@ -3,8 +3,8 @@ Contributors: Don Fischer
3
  Donate link: http://fischercreativemedia.com/
4
  Tags: redirect, 301, 302, meta, post, plugin, page, forward, re-direct, nofollow, wpmu, menu links, WordPress MU, posts, pages, admin, 404
5
  Requires at least: 2.5
6
- Tested up to: 2.9.2
7
- Stable tag: 2.1
8
 
9
  Redirect Pages/Posts to another page/post or external URL. Adds edit box to admin edit so user can specify the redirect Location and type.
10
 
@@ -12,8 +12,11 @@ Redirect Pages/Posts to another page/post or external URL. Adds edit box to admi
12
  Quick Page/Post Redirect Plugin redirects WordPress Pages or Posts to another location quickly.
13
  It adds an option box to the edit section where you can specify the redirect location and type of redirect that you want, temporary, permanent, or meta. See blow for additional features added in each new version.
14
 
15
- *NEW* - Version 1.9 adds 3 new features: 1. you can now open a redirect link in a new window, 2. You can add a *rel="nofollow"* attribute to the link of a redirect, and 3. You can completely re-write the URL for the redirct so it takes the place of the default page URL (rewrite the href link).
16
- *NEW* - Version 1.8 adds a new feature to allow you to add redirects without needing to create a Page or Post to do so. This is very useful for sites that were converted to WordPress and have old links that create 404 errors (see FAQs for more information).
 
 
 
17
 
18
  The redirect Location can be to another WordPress page/post or any other website with an external URL. It allows the use of a full URL path, the post or page ID, permalink or page-name.
19
 
@@ -21,7 +24,6 @@ PLEASE NOTE: At this time, the a new page or post needs to be Published in order
21
 
22
  This plugin is also not compatible with WordPress versions less than 2.5.
23
 
24
- Tested in MU 2.9.2 (3/13/2010)
25
 
26
  = TROUBLESHOOTING: =
27
  * If you check the box for "Show Redirect URL below" on the edit page, please note that you MUST use the full URL in the Redirect URL box. If you do not, you may experience some odd links and 404 pages, as this option cahnges the Permalink for the page/post to the EXACT URL you eneter in that field. (i.e., if you enter '2' in the field, it will redirect to 'http://2' which is not the same as 'http://yoursite.com/?p=2').
@@ -45,6 +47,14 @@ Tested in MU 2.9.2 (3/13/2010)
45
  * Additionally, with 1.8, you can create a redirect with the 'Redirects' option located in the Admin Settings menu.
46
 
47
  == Frequently Asked Questions ==
 
 
 
 
 
 
 
 
48
  = Do I need to have a Page or Post Created to redirect? =
49
  Not any more! With 1.8, a new feature was added that allows you to create a redirect for any URL on your site. This is VERY helpful when you move an old site to WordPress and have old links that need to go some place new. For example,
50
  If you had a link on a site that went to http://yoursite.com/aboutme.html you can now redirect that to http://yoursite.com/about/ without needing to edit the htaccess file. You simply add the old URL (/aboutme.html) and tell it you want to go to the new one (/about/). Simple as that.
@@ -99,6 +109,8 @@ Yes, you can, but you do not always need to. If you are redirecting to an extern
99
  3. Menu for the Quick 301 Redirects page - located in the settings menu.
100
 
101
  == Changelog ==
 
 
102
  = 2.1 =
103
  * Fix Bug - Open in New Window would not work unless Show Link URL was also selected. (3/12/2010)
104
  * Fix Bug - Add rel=nofollow would not work if Open in a New Window was not selected. (3/13/2010)
3
  Donate link: http://fischercreativemedia.com/
4
  Tags: redirect, 301, 302, meta, post, plugin, page, forward, re-direct, nofollow, wpmu, menu links, WordPress MU, posts, pages, admin, 404
5
  Requires at least: 2.5
6
+ Tested up to: 3.1 alpha
7
+ Stable tag: 3.0
8
 
9
  Redirect Pages/Posts to another page/post or external URL. Adds edit box to admin edit so user can specify the redirect Location and type.
10
 
12
  Quick Page/Post Redirect Plugin redirects WordPress Pages or Posts to another location quickly.
13
  It adds an option box to the edit section where you can specify the redirect location and type of redirect that you want, temporary, permanent, or meta. See blow for additional features added in each new version.
14
 
15
+ = Added features: =
16
+ * 1. you can now open a redirect link in a new window
17
+ * 2. You can add a *rel="nofollow"* attribute to the link of a redirect
18
+ * 3. You can completely re-write the URL for the redirct so it takes the place of the default page URL (rewrite the href link)
19
+ * 4. Add redirects without needing to create a Page or Post to do so. This is very useful for sites that were converted to WordPress and have old links that create 404 errors (see FAQs for more information).
20
 
21
  The redirect Location can be to another WordPress page/post or any other website with an external URL. It allows the use of a full URL path, the post or page ID, permalink or page-name.
22
 
24
 
25
  This plugin is also not compatible with WordPress versions less than 2.5.
26
 
 
27
 
28
  = TROUBLESHOOTING: =
29
  * If you check the box for "Show Redirect URL below" on the edit page, please note that you MUST use the full URL in the Redirect URL box. If you do not, you may experience some odd links and 404 pages, as this option cahnges the Permalink for the page/post to the EXACT URL you eneter in that field. (i.e., if you enter '2' in the field, it will redirect to 'http://2' which is not the same as 'http://yoursite.com/?p=2').
47
  * Additionally, with 1.8, you can create a redirect with the 'Redirects' option located in the Admin Settings menu.
48
 
49
  == Frequently Asked Questions ==
50
+ = With 3.0s new menu structure, isn't your plugin now obsolete? =
51
+ Yes, and No. Mostly No.
52
+ Here is why - with WordPress 3.0, comes the new menu stucture, but only a handful of themes actually have the menu structure already integrated into theme. This means that there are tons of themes out there that still need to use the the old way until they can update their theme template pages and functions to turn on the menu capability.
53
+ Additionally, the Quick Redirects option still allows you to create redirects for any url on your site, so that is very much not obsolete (until WP makes somthing to do that as well). And as a final note, the plugin is still compatible with WP's new menu functionality using the standard page/post creations - only custom menu items will be out of the plugin's realm of redirects - and you could set the URL in the new WP menu anyway, so that would be covered.
54
+
55
+ = I still can't get the OPEN IN NEW WINDOW option to work... why? =
56
+ Some thems put custom links in the menu, like RSS and other similar items. Many times (an this is usually the main reason why), they do not use the WP hook to add the menu item to the list - they literally just put it there. Unless the theme uses the internal WordPress hooks to call the menu, redirects, open in a new window and rel=nofollow features just will not work.
57
+
58
  = Do I need to have a Page or Post Created to redirect? =
59
  Not any more! With 1.8, a new feature was added that allows you to create a redirect for any URL on your site. This is VERY helpful when you move an old site to WordPress and have old links that need to go some place new. For example,
60
  If you had a link on a site that went to http://yoursite.com/aboutme.html you can now redirect that to http://yoursite.com/about/ without needing to edit the htaccess file. You simply add the old URL (/aboutme.html) and tell it you want to go to the new one (/about/). Simple as that.
109
  3. Menu for the Quick 301 Redirects page - located in the settings menu.
110
 
111
  == Changelog ==
112
+ = 3.0 =
113
+ * Enhance filter function in main class to reduce Database calls. (06/20/2010)
114
  = 2.1 =
115
  * Fix Bug - Open in New Window would not work unless Show Link URL was also selected. (3/12/2010)
116
  * Fix Bug - Add rel=nofollow would not work if Open in a New Window was not selected. (3/13/2010)