Quick Page/Post Redirect Plugin - Version 2.1

Version Description

  • Fix Bug - Open in New Window would not work unless Show Link URL was also selected. (3/12/2010)
  • Fix Bug - Add rel=nofollow would not work if Open in a New Window was not selected. (3/13/2010)
  • Fix Bug - Show Link, Add nofollow and Open in New Window would still work when redirect not active. (3/13/2010)
  • Added new preg_match_all and preg_replace calls to add target and nofollow links - more effecient and accuarte - noticed some cases where old funtion would add the items if a redirect link had the same URL. (3/13/2010)
Download this release

Release Info

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

Code changes from version 2.0 to 2.1

Files changed (3) hide show
  1. page_post_redirect_plugin.php +55 -34
  2. readme.txt +8 -4
  3. screenshot-1.jpg +0 -0
page_post_redirect_plugin.php CHANGED
@@ -5,9 +5,13 @@ Plugin URI: http://fischercreativemedia.com/wordpress-plugins/quick-pagepost-red
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.0
9
10
Version info:
11
2.0 - Code Cleanup. (2/28/2010)
12
- Fix WARNING and NOTICE messages that some people may have been receiving about objects and undefined variables. (2/28/2010)
13
1.9 - Add 'Open in New Window' Feature. (2/20/2010)
@@ -192,20 +196,27 @@ Version info:
192
// used to get the meta_value and ID of a post with specific meta_key.
193
function ppr_get_metavalfromkey($key) {
194
global $wpdb;
195
- return $wpdb->get_results( $wpdb->prepare( "SELECT post_id, meta_value FROM $wpdb->postmeta WHERE meta_key = %s", $key ) );
196
}
197
198
//clean up the Custom Fields to make it prettier on the Edit Page
199
function ppr_init_metaclean() {
200
- if ( get_option('ppr_version') != '1.9' ) {
201
global $wpdb;
202
- $wpdb->query( "UPDATE $wpdb->postmeta SET meta_key = '_pprredirect_active' WHERE meta_key = 'pprredirect_active'" );
203
- $wpdb->query( "UPDATE $wpdb->postmeta SET meta_key = '_pprredirect_newwindow' WHERE meta_key = 'pprredirect_newwindow'" );
204
- $wpdb->query( "UPDATE $wpdb->postmeta SET meta_key = '_pprredirect_relnofollow' WHERE meta_key = 'pprredirect_relnofollow'" );
205
- $wpdb->query( "UPDATE $wpdb->postmeta SET meta_key = '_pprredirect_type' WHERE meta_key = 'pprredirect_type'" );
206
- $wpdb->query( "UPDATE $wpdb->postmeta SET meta_key = '_pprredirect_url' WHERE meta_key = 'pprredirect_url'" );
207
wp_cache_flush();
208
- update_option( 'ppr_version', '1.9' );
209
}
210
}
211
@@ -244,21 +255,24 @@ Version info:
244
return $link;
245
}
246
247
- function ppr_linktometa () {
248
global $wpdb, $ppr_cache, $blog_id;
249
- if (!isset($ppr_cache[$blog_id])){
250
- $links_to = ppr_get_metavalfromkey('_pprredirect_url');
251
- }else{
252
return $ppr_cache[$blog_id];
253
}
254
- if (!$links_to) {
255
- $ppr_cache[$blog_id] = false;
256
- return false;
257
- }
258
- foreach((array) $links_to as $link){
259
- $ppr_cache[$blog_id][$link->post_id] = $link->meta_value;
260
- }
261
- return $ppr_cache[$blog_id];
262
}
263
264
function ppr_linktotarget () {
@@ -466,8 +480,7 @@ Version info:
466
$ppr_cache = ppr_linktometa();
467
$ppr_target = ppr_linktotarget();
468
$ppr_norel = ppr_linktonorel();
469
-
470
- if (!$ppr_cache && !$ppr_target){
471
return $pages;
472
}
473
@@ -477,32 +490,40 @@ Version info:
477
478
foreach ((array) $ppr_cache as $id => $page ) {
479
if (isset( $ppr_target[$id])){
480
- $targets[$page] = $ppr_target[$id];
481
}
482
if (isset( $ppr_norel[$id])){
483
- $norels[$page] = $id;
484
- //$norels[$id] = $ppr_norel[$id];
485
}
486
}
487
488
if(count($norels)>=1) {
489
- foreach($norels as $rel => $relid){
490
- if(strpos($pages,' href="'.$rel.'" rel="nofollow" ')>0) {
491
$pages = $pages; //do nothing 'cause it is already a rel=nofollow.
492
}else{
493
- $pages = str_replace(' href="'.$rel.'"',' href="'.$rel.'" rel="nofollow" ', $pages); //add no follow.
494
}
495
}
496
}
497
498
if(count($targets)>=1) {
499
foreach($targets as $p => $t){
500
- $p = esc_url($p);
501
- $t = esc_attr($t);
502
- if(strpos($pages,' href="'.$p.'" target="'.$t.'" ')>0){
503
- $pages = $pages; //already has a target
504
}else{
505
- $pages = str_replace(' href="'.$p.'" ',' href="'.$p.'" target="'.$t.'" ', $pages);
506
}
507
}
508
}
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)
14
+ - Added new preg_match_all and preg_replace calls to add target and nofollow links - more effecient and accuarte - noticed some cases where old funtion would add the items if a redirect link had the same URL. (3/13/2010)
15
2.0 - Code Cleanup. (2/28/2010)
16
- Fix WARNING and NOTICE messages that some people may have been receiving about objects and undefined variables. (2/28/2010)
17
1.9 - Add 'Open in New Window' Feature. (2/20/2010)
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
212
+ $wpdb->query( "UPDATE $wpdb->postmeta SET meta_key = '_pprredirect_active' WHERE meta_key = 'pprredirect_active'" );
213
+ $wpdb->query( "UPDATE $wpdb->postmeta SET meta_key = '_pprredirect_newwindow' WHERE meta_key = 'pprredirect_newwindow'" );
214
+ $wpdb->query( "UPDATE $wpdb->postmeta SET meta_key = '_pprredirect_relnofollow' WHERE meta_key = 'pprredirect_relnofollow'" );
215
+ $wpdb->query( "UPDATE $wpdb->postmeta SET meta_key = '_pprredirect_type' WHERE meta_key = 'pprredirect_type'" );
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
255
return $link;
256
}
257
258
+ function ppr_linktometa() {
259
global $wpdb, $ppr_cache, $blog_id;
260
+ if(isset($ppr_cache[$blog_id])){
261
return $ppr_cache[$blog_id];
262
+ }else{
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{
272
+ $ppr_cache[$blog_id] = false;
273
+ return false;
274
+ }
275
}
276
}
277
278
function ppr_linktotarget () {
480
$ppr_cache = ppr_linktometa();
481
$ppr_target = ppr_linktotarget();
482
$ppr_norel = ppr_linktonorel();
483
+ if (!$ppr_cache && !$ppr_target && !$ppr_rel){
484
return $pages;
485
}
486
490
491
foreach ((array) $ppr_cache as $id => $page ) {
492
if (isset( $ppr_target[$id])){
493
+ $targets[$id] = $ppr_cache[$id];
494
}
495
if (isset( $ppr_norel[$id])){
496
+ $norels[$id] = $ppr_cache[$id];
497
}
498
}
499
500
if(count($norels)>=1) {
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
}
513
514
if(count($targets)>=1) {
515
foreach($targets as $p => $t){
516
+ $p = esc_attr($p);
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
}
readme.txt CHANGED
@@ -1,10 +1,10 @@
1
=== Quick Page/Post Redirect ===
2
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
5
Requires at least: 2.5
6
Tested up to: 2.9.2
7
- Stable tag: 2.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,7 +12,6 @@ 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
- *2.0 NOTE:* - Version 2.0 is just a code cleanup version. It removes the Warning and Notice messages that some people may receive - it does not add any new features. It is not necessary to upgrade to 2.0 unless you have been getting WARNING and NOTICE messages.
16
*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).
17
*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).
18
@@ -22,7 +21,7 @@ PLEASE NOTE: At this time, the a new page or post needs to be Published in order
22
23
This plugin is also not compatible with WordPress versions less than 2.5.
24
25
- Tested in MU 2.8.4a (9/8/2009)
26
27
= TROUBLESHOOTING: =
28
* 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').
@@ -100,6 +99,11 @@ Yes, you can, but you do not always need to. If you are redirecting to an extern
100
3. Menu for the Quick 301 Redirects page - located in the settings menu.
101
102
== Changelog ==
103
= 2.0 =
104
* Cosmetic code cleanup. (2/28/2010)
105
* Remove warning and error messages created in 1.9 (2/28/2010)
1
=== Quick Page/Post Redirect ===
2
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
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
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').
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)
105
+ * Fix Bug - Show Link, Add nofollow and Open in New Window would still work when redirect not active. (3/13/2010)
106
+ * Added new preg_match_all and preg_replace calls to add target and nofollow links - more effecient and accuarte - noticed some cases where old funtion would add the items if a redirect link had the same URL. (3/13/2010)
107
= 2.0 =
108
* Cosmetic code cleanup. (2/28/2010)
109
* Remove warning and error messages created in 1.9 (2/28/2010)
screenshot-1.jpg CHANGED
Binary file