Quick Page/Post Redirect Plugin - Version 3.2

Version Description

  • remove functions ppr_linktotarget, ppr_linktonorel, ppr_redirectto and ppr_linktometa.(12/10/2010)
  • re-write functions to consolidate queries. (12/10/2010)
  • added new filters for New menu structure to filter wp_nav_menu menus as well as old wp_page_menus functions. (12/10/2010)
  • cleaned up new window and nofollow code to work more consistently. (12/10/2010)
Download this release

Release Info

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

Code changes from version 3.1 to 3.2

Files changed (2) hide show
  1. page_post_redirect_plugin.php +168 -166
  2. readme.txt +18 -13
page_post_redirect_plugin.php CHANGED
@@ -2,12 +2,17 @@
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: 3.1
9
10
Version info:
11
3.1 - Re-issue of 2.1 for immediate fix of issue with the 3.0 version.(6/21/2010)
12
3.0 - Enhance Filter to reduce number of DB calls. (06/20/10)
13
2.1 - Fix Bug - Open in New Window would not work unless Show Link URL was also selected. (3/12/2010)
@@ -49,9 +54,13 @@ Version info:
49
You should have received a copy of the GNU General Public License
50
along with this program. If not, see <http://www.gnu.org/licenses/>.
51
*/
52
53
//=======================================
54
- // Redirect Class (for non oage post redirects).
55
// Original Simple 301 Redirects Class created by Scott Nelle (http://www.scottnelle.com/)
56
//=======================================
57
if (!class_exists("quick_page_post_redirects")) {
@@ -95,6 +104,7 @@ Version info:
95
</p>
96
</form>
97
</div>
98
<?php
99
} // end of function options_page
100
@@ -163,155 +173,149 @@ Version info:
163
// Call the 301 class (for non-existant 301 redirects)
164
$redirect_plugin = new quick_page_post_redirects();
165
166
- // Actions
167
//----------
168
add_action('admin_menu', 'add_edit_box_ppr');
169
add_action('save_post', 'ppr_save_postdata', 1, 2); // save the custom fields
170
- //add_action('wp','ppr_do_redirect', 1, 2);
171
add_action('template_redirect','ppr_do_redirect', 1, 2);
172
add_action('init', 'ppr_init_metaclean', 1);
173
- //add_action( 'template_redirect', 'ppr_redirecto');
174
- add_filter('page_link','ppr_filter_pages',20, 2 );
175
- add_filter('post_link','ppr_filter_pages',20, 2 );
176
- add_filter('wp_list_pages','ppr_fix_targetsandrels', 9);
177
-
178
if (isset($redirect_plugin)) {
179
add_action('init', array($redirect_plugin,'redirect'), 1); // add the redirect action, high priority
180
add_action('admin_menu', array($redirect_plugin,'create_menu')); // create the menu
181
if (isset($_POST['submit_301'])) {$redirect_plugin->save_redirects($_POST['quickppr_redirects']);} //if submitted, process the data
182
}
183
-
184
-
185
- // Variables
186
- //----------
187
- global $wpdb;
188
- global $wp_query;
189
190
// Functions
191
//----------
192
// For WordPress < 2.8 function compatibility
193
if (!function_exists('esc_attr')) {
194
function esc_attr($attr){return attribute_escape( $attr );}
195
function esc_url($url){return clean_url( $url );}
196
}
197
198
- // used to get the meta_value and ID of a post with specific meta_key.
199
- function ppr_get_metavalfromkey($key) {
200
- global $wpdb;
201
- 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 ) );
202
- }
203
-
204
//clean up the Custom Fields to make it prettier on the Edit Page
205
function ppr_init_metaclean() {
206
$thepprversion = get_option('ppr_version');
207
- if ($thepprversion=='3.1') {
208
- //nothing;
209
- }else if ($thepprversion == '1.9' || $thepprversion == '2.0' || $thepprversion == '2.1' || $thepprversion == '3.0') {
210
- update_option( 'ppr_version', '3.1' );
211
}else{
212
global $wpdb;
213
//want to make sure older version upgrading still
214
$wpdb->query( "UPDATE $wpdb->postmeta SET meta_key = '_pprredirect_active' WHERE meta_key = 'pprredirect_active'" );
215
$wpdb->query( "UPDATE $wpdb->postmeta SET meta_key = '_pprredirect_newwindow' WHERE meta_key = 'pprredirect_newwindow'" );
216
$wpdb->query( "UPDATE $wpdb->postmeta SET meta_key = '_pprredirect_relnofollow' WHERE meta_key = 'pprredirect_relnofollow'" );
217
$wpdb->query( "UPDATE $wpdb->postmeta SET meta_key = '_pprredirect_type' WHERE meta_key = 'pprredirect_type'" );
218
$wpdb->query( "UPDATE $wpdb->postmeta SET meta_key = '_pprredirect_url' WHERE meta_key = 'pprredirect_url'" );
219
- wp_cache_flush();
220
- //end remove
221
- update_option( 'ppr_version', '3.1' );
222
- }
223
- }
224
-
225
- function ppr_redirectto() {//alternate redirect function - old version
226
- global $wp_query;
227
- if (!is_single()&&!is_page()){
228
- return;
229
- }
230
- $link = get_post_meta($wp_query->post->ID, '_pprredirect_url', true);
231
- if(!$link){
232
- return;
233
}
234
- $redirect_type = get_post_meta( $wp_query->post->ID, '_pprredirect_type', true );
235
- $redirect_type = ( $redirect_type = '302' ) ? '302' : '301';
236
- wp_redirect( $link, $redirect_type );
237
- exit;
238
}
239
240
function ppr_filter_pages ($link, $post) {
241
- $ppr_cache = ppr_linktometa();
242
if(isset($post->ID)){
243
$id = $post->ID;
244
}else{
245
$id = $post;
246
}
247
- $ppr_rewrite = get_post_meta($id,'_pprredirect_rewritelink',true);
248
- if (isset($ppr_cache[$id]) ){
249
- if($ppr_rewrite==='1'){ //only change the link if they want - otherwise, we will redirect the old way.
250
- 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){
251
- $link = esc_url( $ppr_cache[$id] );
252
}else{
253
- $link = esc_url( get_bloginfo('url').'/'. $ppr_cache[$id] );
254
}
255
}
256
}
257
return $link;
258
}
259
260
- function ppr_linktometa() {
261
- global $wpdb, $ppr_cache, $blog_id;
262
- if(isset($ppr_cache[$blog_id])){
263
- return $ppr_cache[$blog_id];
264
- }else{
265
- $links_to = ppr_get_metavalfromkey('_pprredirect_url');
266
- if(count($links_to)>0){
267
- foreach((array) $links_to as $link){
268
- //if(get_post_meta($link->post_id,'_pprredirect_active',true)!=''){
269
- $ppr_cache[$blog_id][$link->post_id] = $link->meta_value;
270
- //}
271
- }
272
- return $ppr_cache[$blog_id];
273
- }else{
274
- $ppr_cache[$blog_id] = false;
275
- return false;
276
- }
277
- }
278
- }
279
-
280
- function ppr_linktotarget () {
281
- global $wpdb, $ppr_target, $blog_id;
282
- if (!isset( $ppr_target[$blog_id])){
283
- $links_to = ppr_get_metavalfromkey('_pprredirect_newwindow');
284
- }else{
285
- return $ppr_target[$blog_id];
286
- }
287
- if (!$links_to) {
288
- $ppr_target[$blog_id] = false;
289
- return false;
290
- }
291
- foreach ((array) $links_to as $link){
292
- $ppr_target[$blog_id][$link->post_id] = $link->meta_value;
293
- }
294
- return $ppr_target[$blog_id];
295
- }
296
-
297
- function ppr_linktonorel () {
298
- global $wpdb, $ppr_norel, $blog_id;
299
- if (!isset($ppr_norel[$blog_id])){
300
- $links_to = ppr_get_metavalfromkey('_pprredirect_relnofollow');
301
- }else{
302
- return $ppr_norel[$blog_id];
303
- }
304
- if (!$links_to) {
305
- $ppr_norel[$blog_id] = false;
306
- return false;
307
- }
308
- foreach((array) $links_to as $link){
309
- $ppr_norel[$blog_id][$link->post_id] = $link->meta_value;
310
- }
311
- //print_r($ppr_norel[$blog_id]);
312
- return $ppr_norel[$blog_id];
313
- }
314
-
315
function addmetatohead_theme(){
316
global $ppr_url;
317
$meta_code = '<meta http-equiv="refresh" content="0; URL='.$ppr_url.'" />';
@@ -320,47 +324,62 @@ Version info:
320
}
321
322
function ppr_do_redirect(){
323
- global $post,$wp_query,$ppr_url,$ppr_active,$ppr_url,$ppr_type;
324
- if($wp_query->is_single || $wp_query->is_page ):
325
- $thisidis_current= $post->ID;
326
- $ppr_active = get_post_meta($thisidis_current,'_pprredirect_active',true);
327
- $ppr_url = get_post_meta($thisidis_current,'_pprredirect_url',true);
328
- $ppr_type = get_post_meta($thisidis_current,'_pprredirect_type',true);
329
330
- if( $ppr_active==1 && $ppr_url!='' ):
331
- if($ppr_type===0){$ppr_type='200';}
332
- if($ppr_type===''){$ppr_type='302';}
333
- if($ppr_type=='meta'):
334
//metaredirect
335
add_action('wp_head', "addmetatohead_theme",1);
336
- elseif($ppr_url!=''):
337
//check for http:// - as full url - then we can just redirect if it is //
338
- if( strpos($ppr_url, 'http://')=== 0 || strpos($ppr_url, 'https://')=== 0){
339
- $offsite=$ppr_url;
340
- header('Status: '.$ppr_type);
341
- header('Location: '.$offsite, true, $ppr_type);
342
exit; //stop loading page
343
- }elseif(strpos($ppr_url, 'www')=== 0){ // check if they have full url but did not put http://
344
- $offsite='http://'.$ppr_url;
345
- header("Status: $ppr_type");
346
- header("Location: $offsite", true, $ppr_type);
347
exit; //stop loading page
348
- }elseif(is_numeric($ppr_url)){ // page/post number
349
if($ppr_postpage=='page'){ //page
350
$onsite=get_bloginfo('url').'/?page_id='.$ppr_url;
351
- header("Status: $ppr_type");
352
- header("Location: $onsite", true, $ppr_type);
353
exit; //stop loading page
354
}else{ //post
355
- $onsite=get_bloginfo('url').'/?p='.$ppr_url;
356
- header("Status: $ppr_type");
357
- header("Location: $onsite", true, $ppr_type);
358
exit; //stop loading page
359
}
360
//check permalink or local page redirect
361
}else{ // we assume they are using the permalink / page name??
362
- $onsite=get_bloginfo('url'). $ppr_url;
363
- header("Location: $onsite", true, $ppr_type);
364
exit; //stop loading page
365
}
366
@@ -426,12 +445,11 @@ Version info:
426
}
427
428
// When the post is saved, saves our custom data
429
- function ppr_save_postdata($post_id, $post) {
430
431
if(isset($_REQUEST['pprredirect_noncename']) && (isset($_POST['pprredirect_active']) || isset($_POST['pprredirect_url']) || isset($_POST['pprredirect_type']) || isset($_POST['pprredirect_newwindow']) || isset($_POST['pprredirect_relnofollow']))):
432
// verify authorization
433
if(isset($_POST['pprredirect_noncename'])){
434
- //if ( !wp_verify_nonce( $_POST['pprredirect_noncename'], plugin_basename(__FILE__) )) {
435
if ( !wp_verify_nonce( $_REQUEST['pprredirect_noncename'], 'pprredirect_noncename' )) {
436
return $post->ID;
437
}
@@ -478,54 +496,38 @@ Version info:
478
}
479
480
function ppr_fix_targetsandrels($pages) {
481
- global $post;
482
- $ppr_cache = ppr_linktometa();
483
- $ppr_target = ppr_linktotarget();
484
- $ppr_norel = ppr_linktonorel();
485
- if (!$ppr_cache && !$ppr_target && !$ppr_rel){
486
return $pages;
487
}
488
489
$this_url = 'http://' . $_SERVER['HTTP_HOST'] . $_SERVER['REQUEST_URI'];
490
- $targets = array();
491
- $norels = array();
492
493
- foreach ((array) $ppr_cache as $id => $page ) {
494
- if (isset( $ppr_target[$id])){
495
- $targets[$id] = $ppr_cache[$id];
496
- }
497
- if (isset( $ppr_norel[$id])){
498
- $norels[$id] = $ppr_cache[$id];
499
- }
500
- }
501
-
502
- if(count($norels)>=1) {
503
- foreach($norels as $relid => $rel){
504
- $validexp="/page-item-".$relid."\"><a(?:.*)rel=\"nofollow\"(?:.*?)>/i";
505
$found = preg_match_all($validexp, $pages, $matches);
506
- //if(strpos($pages,'page-item-'.$relid.'">a href="'.$rel.'" rel="nofollow" ')>0) {
507
if($found!=0){
508
$pages = $pages; //do nothing 'cause it is already a rel=nofollow.
509
}else{
510
- $pages = preg_replace('/page-item-'.$relid.'"><a(.*?)>/i', 'page-item-'.$relid.'"><a\1 rel="nofollow">', $pages);
511
- //$pages = str_replace(' href="'.$rel.'"',' href="'.$rel.'" rel="nofollow" ', $pages); //add no follow.
512
}
513
}
514
}
515
516
- if(count($targets)>=1) {
517
- foreach($targets as $p => $t){
518
- $p = esc_attr($p);
519
- $t = esc_url($t);
520
- $validexp="/page-item-".$p."\"><a(?:.*)target=\"_blank\"(?:.*?)>/i";
521
$found = preg_match_all($validexp, $pages, $matches);
522
- //if(strpos($pages,' href="'.$t.'" target="'.$p.'" ')>0){
523
- //$pages = $pages; //already has a target
524
if($found!=0){
525
$pages = $pages; //do nothing 'cause it is already a rel=nofollow.
526
}else{
527
- $pages = preg_replace('/page-item-'.$p.'"><a(.*?)>/i', 'page-item-'.$p.'"><a\1 target="_blank">', $pages);
528
- //$pages = str_replace(' href="'.$p.'" ',' href="'.$p.'" target="'.$t.'" ', $pages);
529
}
530
}
531
}
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 page or post or external 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. 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
+ Donate link: http://www.fischercreativemedia.com/wordpress-plugins/donate/
9
+ Version: 3.2
10
11
Version info:
12
+ 3.2 - remove functions ppr_linktotarget, ppr_linktonorel, ppr_redirectto and ppr_linktometa.(12/10/2010)
13
+ - re-write functions to consolidate queries. (12/10/2010)
14
+ - added new filters for New menu structure to filter wp_nav_menu menus as well as old wp_page_menus functions. (12/10/2010)
15
+ - cleaned up new window and nofollow code to work more consistently. (12/10/2010)
16
3.1 - Re-issue of 2.1 for immediate fix of issue with the 3.0 version.(6/21/2010)
17
3.0 - Enhance Filter to reduce number of DB calls. (06/20/10)
18
2.1 - Fix Bug - Open in New Window would not work unless Show Link URL was also selected. (3/12/2010)
54
You should have received a copy of the GNU General Public License
55
along with this program. If not, see <http://www.gnu.org/licenses/>.
56
*/
57
+ ini_set('display_errors', 0);
58
+ ini_set('log_errors', 1);
59
+ ini_set('error_log', dirname(__FILE__) . '/error_log.txt');
60
+ error_reporting( E_ALL & ~E_NOTICE );
61
62
//=======================================
63
+ // Redirect Class (for non page post redirects).
64
// Original Simple 301 Redirects Class created by Scott Nelle (http://www.scottnelle.com/)
65
//=======================================
66
if (!class_exists("quick_page_post_redirects")) {
104
</p>
105
</form>
106
</div>
107
+
108
<?php
109
} // end of function options_page
110
173
// Call the 301 class (for non-existant 301 redirects)
174
$redirect_plugin = new quick_page_post_redirects();
175
176
+ // Variables
177
+ //----------
178
+ global $wpdb;
179
+ global $wp_query;
180
+ global $ppr_nofollow;
181
+ global $ppr_newindow;
182
+ global $ppr_url;
183
+ global $ppr_url_rewrite;
184
+ global $ppr_type;
185
+
186
+ // Actions & Filters
187
//----------
188
add_action('admin_menu', 'add_edit_box_ppr');
189
add_action('save_post', 'ppr_save_postdata', 1, 2); // save the custom fields
190
add_action('template_redirect','ppr_do_redirect', 1, 2);
191
add_action('init', 'ppr_init_metaclean', 1);
192
+ add_action('wp','ppr_new_nav_menu');
193
if (isset($redirect_plugin)) {
194
add_action('init', array($redirect_plugin,'redirect'), 1); // add the redirect action, high priority
195
add_action('admin_menu', array($redirect_plugin,'create_menu')); // create the menu
196
if (isset($_POST['submit_301'])) {$redirect_plugin->save_redirects($_POST['quickppr_redirects']);} //if submitted, process the data
197
}
198
199
// Functions
200
//----------
201
+ function ppr_new_nav_menu($items){
202
+ global $ppr_nofollow;
203
+ global $ppr_newindow;
204
+ global $ppr_url;
205
+ global $ppr_url_rewrite;
206
+ global $ppr_type;
207
+ add_filter( 'wp_get_nav_menu_items','ppr_new_nav_menu_fix',1,1);
208
+ add_filter( 'wp_list_pages','ppr_fix_targetsandrels');
209
+ add_filter( 'page_link','ppr_filter_pages',20, 2 );
210
+ add_filter( 'post_link','ppr_filter_pages',20, 2 );
211
+ return $items;
212
+ }
213
+
214
+ function ppr_new_nav_menu_fix($ppr){
215
+ global $ppr_nofollow;
216
+ global $ppr_newindow;
217
+ global $ppr_url;
218
+ global $ppr_url_rewrite;
219
+ global $ppr_type;
220
+ global $wpdb;
221
+ $thefirstppr = array();
222
+ $select_tiems = $wpdb->get_results("SELECT post_id,meta_key,meta_value FROM $wpdb->postmeta WHERE (meta_key='_pprredirect_type' OR meta_key='_pprredirect_url' OR meta_key='_pprredirect_rewritelink' OR meta_key = '_pprredirect_active' OR meta_key='_pprredirect_newwindow' OR meta_key='_pprredirect_relnofollow') AND meta_value!='' ORDER BY post_id ASC;");
223
+ foreach($select_tiems as $pprs){
224
+ $thefirstppr[$pprs->post_id][$pprs->meta_key] = $pprs->meta_value;
225
+ $thefirstppr[$pprs->post_id]['post_id'] = $pprs->post_id;
226
+ }
227
+ foreach($thefirstppr as $ppitems){
228
+ if(isset($ppitems['_pprredirect_active']) && isset($ppitems['_pprredirect_newwindow'])){
229
+ $ppr_newindow[] = $ppitems['post_id'];
230
+ }
231
+ if(isset($ppitems['_pprredirect_active']) && isset($ppitems['_pprredirect_relnofollow'])){
232
+ $ppr_nofollow[] = $ppitems['post_id'];
233
+ }
234
+ if(isset($ppitems['_pprredirect_active']) && isset($ppitems['_pprredirect_rewritelink']) && isset($ppitems['_pprredirect_url'])){
235
+ $ppr_url_rewrite[] = $ppitems['post_id'];
236
+ $ppr_url[$ppitems['post_id']]['URL'] = $ppitems['_pprredirect_url'];
237
+ }
238
+ if(isset($ppitems['_pprredirect_active']) && isset($ppitems['_pprredirect_type'])){
239
+ $ppr_type[$ppitems['post_id']]['type'] = $ppitems['_pprredirect_type'];
240
+ }
241
+
242
+ }
243
+
244
+ $newmenu = array();
245
+ foreach($ppr as $ppd){
246
+ if(in_array($ppd->object_id,$ppr_newindow)){
247
+ $ppd->target = '_blank';
248
+ $ppd->classes[] = 'ppr-new-window';
249
+ }
250
+ if(in_array($ppd->object_id,$ppr_nofollow)){
251
+ $ppd->xfn = 'nofollow';
252
+ $ppd->classes[] = 'ppr-nofollow';
253
+ }
254
+ if(in_array($ppd->object_id,$ppr_url_rewrite)){
255
+ $ppd->url = $ppr_url[$ppd->object_id]['URL'];
256
+ }
257
+ $newmenu[] = $ppd;
258
+ }
259
+ return $newmenu;
260
+ }
261
+
262
// For WordPress < 2.8 function compatibility
263
if (!function_exists('esc_attr')) {
264
function esc_attr($attr){return attribute_escape( $attr );}
265
function esc_url($url){return clean_url( $url );}
266
}
267
268
//clean up the Custom Fields to make it prettier on the Edit Page
269
function ppr_init_metaclean() {
270
$thepprversion = get_option('ppr_version');
271
+ //echo $thepprversion;
272
+ if ($thepprversion=='3.2') {
273
+ update_option( 'ppr_version', '3.2' );
274
+ }else if(in_array($thepprversion,array('1.9','2.0','2.1','3.0','3.1'))) {
275
+ update_option( 'ppr_version', '3.2' );
276
}else{
277
global $wpdb;
278
//want to make sure older version upgrading still
279
+ /* //not needed any more
280
$wpdb->query( "UPDATE $wpdb->postmeta SET meta_key = '_pprredirect_active' WHERE meta_key = 'pprredirect_active'" );
281
$wpdb->query( "UPDATE $wpdb->postmeta SET meta_key = '_pprredirect_newwindow' WHERE meta_key = 'pprredirect_newwindow'" );
282
$wpdb->query( "UPDATE $wpdb->postmeta SET meta_key = '_pprredirect_relnofollow' WHERE meta_key = 'pprredirect_relnofollow'" );
283
$wpdb->query( "UPDATE $wpdb->postmeta SET meta_key = '_pprredirect_type' WHERE meta_key = 'pprredirect_type'" );
284
$wpdb->query( "UPDATE $wpdb->postmeta SET meta_key = '_pprredirect_url' WHERE meta_key = 'pprredirect_url'" );
285
+ wp_cache_flush();
286
+ */
287
+
288
+ update_option( 'ppr_version', '3.2' );
289
}
290
}
291
292
function ppr_filter_pages ($link, $post) {
293
+ global $ppr_nofollow;
294
+ global $ppr_newindow;
295
+ global $ppr_url;
296
+ global $ppr_url_rewrite;
297
+ global $ppr_type;
298
+ global $wpdb;
299
+
300
if(isset($post->ID)){
301
$id = $post->ID;
302
}else{
303
$id = $post;
304
}
305
+ if(is_array($ppr_url_rewrite)){
306
+ if(in_array($id, $ppr_url_rewrite)){
307
+ $newURL = $ppr_url[$id]['URL'];
308
+ if(strpos($newURL,get_bloginfo('url'))>=0 || strpos($newURL,'www.')>=0 || strpos($newURL,'http://')>=0 || strpos($newURL,'https://')>=0){
309
+ $link = esc_url( $newURL );
310
}else{
311
+ $link = esc_url( get_bloginfo('url').'/'. $newURL );
312
}
313
}
314
}
315
+
316
return $link;
317
}
318
319
function addmetatohead_theme(){
320
global $ppr_url;
321
$meta_code = '<meta http-equiv="refresh" content="0; URL='.$ppr_url.'" />';
324
}
325
326
function ppr_do_redirect(){
327
+ global $post,$wp_query,$ppr_active,$wpdb;
328
+ $select_tiems = $wpdb->get_results("SELECT post_id,meta_key,meta_value FROM $wpdb->postmeta WHERE (meta_key='_pprredirect_type' OR meta_key='_pprredirect_url' OR meta_key = '_pprredirect_active') AND meta_value!='' ORDER BY post_id ASC;");
329
+ foreach($select_tiems as $pprs){
330
+ $thefirstppr[$pprs->post_id][$pprs->meta_key] = $pprs->meta_value;
331
+ $thefirstppr[$pprs->post_id]['post_id'] = $pprs->post_id;
332
+ }
333
+ foreach($thefirstppr as $ppitems){
334
+ if(isset($ppitems['_pprredirect_active']) && isset($ppitems['_pprredirect_url'])){
335
+ $ppr_url_rewrite[] = $ppitems['post_id'];
336
+ $ppr_url[$ppitems['post_id']]['URL'] = $ppitems['_pprredirect_url'];
337
+ }
338
+ if(isset($ppitems['_pprredirect_active']) && isset($ppitems['_pprredirect_type'])){
339
+ $ppr_type[$ppitems['post_id']]['type'] = $ppitems['_pprredirect_type'];
340
+ }
341
342
+ }
343
+
344
+ if($wp_query->is_single || $wp_query->is_page ):
345
+ $thisidis_current = $post->ID;
346
+ if(isset($ppr_type[$thisidis_current]['type'])){$ppr_types = $ppr_type[$thisidis_current]['type'];}else{$ppr_types = '';}
347
+ if(isset($ppr_url[$thisidis_current]['URL'])){$ppr_urls = $ppr_url[$thisidis_current]['URL'];}else{$ppr_urls='';}
348
+
349
+ if( $ppr_urls!=''):
350
+ if($ppr_types===0){$ppr_types='200';}
351
+ if($ppr_types===''){$ppr_types='302';}
352
+ if($ppr_types=='meta'):
353
//metaredirect
354
add_action('wp_head', "addmetatohead_theme",1);
355
+ else:
356
//check for http:// - as full url - then we can just redirect if it is //
357
+ if( strpos($ppr_urls, 'http://')=== 0 || strpos($ppr_urls, 'https://')=== 0){
358
+ $offsite=$ppr_urls;
359
+ header('Status: '.$ppr_types);
360
+ header('Location: '.$offsite, true, $ppr_types);
361
exit; //stop loading page
362
+ }elseif(strpos($ppr_urls, 'www')=== 0){ // check if they have full url but did not put http://
363
+ $offsite='http://'.$ppr_urls;
364
+ header("Status: $ppr_types");
365
+ header("Location: $offsite", true, $ppr_types);
366
exit; //stop loading page
367
+ }elseif(is_numeric($ppr_urls)){ // page/post number
368
if($ppr_postpage=='page'){ //page
369
$onsite=get_bloginfo('url').'/?page_id='.$ppr_url;
370
+ header("Status: $ppr_types");
371
+ header("Location: $onsite", true, $ppr_types);
372
exit; //stop loading page
373
}else{ //post
374
+ $onsite=get_bloginfo('url').'/?p='.$ppr_urls;
375
+ header("Status: $ppr_types");
376
+ header("Location: $onsite", true, $ppr_types);
377
exit; //stop loading page
378
}
379
//check permalink or local page redirect
380
}else{ // we assume they are using the permalink / page name??
381
+ $onsite=get_bloginfo('url'). $ppr_urls;
382
+ header("Location: $onsite", true, $ppr_types);
383
exit; //stop loading page
384
}
385
445
}
446
447
// When the post is saved, saves our custom data
448
449
+ function ppr_save_postdata($post_id, $post) {
450
if(isset($_REQUEST['pprredirect_noncename']) && (isset($_POST['pprredirect_active']) || isset($_POST['pprredirect_url']) || isset($_POST['pprredirect_type']) || isset($_POST['pprredirect_newwindow']) || isset($_POST['pprredirect_relnofollow']))):
451
// verify authorization
452
if(isset($_POST['pprredirect_noncename'])){
453
if ( !wp_verify_nonce( $_REQUEST['pprredirect_noncename'], 'pprredirect_noncename' )) {
454
return $post->ID;
455
}
496
}
497
498
function ppr_fix_targetsandrels($pages) {
499
+ global $post;
500
+ global $ppr_nofollow;
501
+ global $ppr_newindow;
502
+ global $ppr_url;
503
+ global $ppr_url_rewrite;
504
+
505
+ if (!$ppr_url && !$ppr_newindow && !$ppr_nofollow){
506
return $pages;
507
}
508
509
$this_url = 'http://' . $_SERVER['HTTP_HOST'] . $_SERVER['REQUEST_URI'];
510
511
+ if(count($ppr_nofollow)>=1) {
512
+ foreach($ppr_nofollow as $relid){
513
+ $validexp="@\<li(?:.*?)".$relid."(?:.*?)\>\<a(?:.*?)rel\=\"nofollow\"(?:.*?)\>@i";
514
$found = preg_match_all($validexp, $pages, $matches);
515
if($found!=0){
516
$pages = $pages; //do nothing 'cause it is already a rel=nofollow.
517
}else{
518
+ $pages = preg_replace('@<li(.*?)-'.$relid.'(.*?)\>\<a(.*?)\>@i', '<li\1-'.$relid.'\2><a\3 rel="nofollow">', $pages);
519
}
520
}
521
}
522
523
+ if(count($ppr_newindow)>=1) {
524
+ foreach($ppr_newindow as $p){
525
+ $validexp="@\<li(?:.*?)".$p."(?:.*?)\>\<a(?:.*?)target\=(?:.*?)\>@i";
526
$found = preg_match_all($validexp, $pages, $matches);
527
if($found!=0){
528
$pages = $pages; //do nothing 'cause it is already a rel=nofollow.
529
}else{
530
+ $pages = preg_replace('@<li(.*?)-'.$p.'(.*?)\>\<a(.*?)\>@i', '<li\1-'.$p.'\2><a\3 target="_blank">', $pages);
531
}
532
}
533
}
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, 404
5
Requires at least: 2.5
6
- Tested up to: 3.1 alpha
7
- Stable tag: 3.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,11 +12,12 @@ 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
- = 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,7 +25,6 @@ PLEASE NOTE: At this time, the a new page or post needs to be Published in order
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').
30
* If your browser tells you that your are in an infinite loop, check to make sure you do not have pages redirecting to another page that redirects back to the initial page. That WILL cause an infinate loop.
@@ -38,13 +38,13 @@ This plugin is also not compatible with WordPress versions less than 2.5.
38
* Upload `quick_page_post_redirect` folder to the `/wp-content/plugins/` directory
39
* Activate the plugin through the 'Plugins' menu in WordPress
40
* Once Activated, you can add a redirect by entering the correct information in the `Quick Page/Post Redirect` box in the edit section of a page or post
41
- * Additionally, with 1.8, you can create a redirect with the 'Redirects' option located in the Admin Settings menu.
42
43
= If you install this plugin through WordPress 2.8+ plugin search interface: =
44
* Click Install `Quick Page/Post Redirect Plugin`
45
* Activate the plugin through the 'Plugins' menu in WordPress
46
* Once Activated, you can add a redirect by entering the correct information in the `Quick Page/Post Redirect` box in the edit section of a page or post
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? =
@@ -62,13 +62,13 @@ If you had a link on a site that went to http://yoursite.com/aboutme.html you ca
62
The new fuctionality is located in the Admin under Settings/Quick Redirects. The olde URL goes in the Request field and the to new URL goes in the Destination field. Simple and Quick!
63
64
= Can I add 'rel="nofollow" attribute to the redirect link? =
65
- YES! New in 1.9, you can now add a ' rel="nofollow" ' attribute for the redirect link. Simply check the "add rel=nofollow" box when setting up the redirect on the page/post edit page. Note - this option is not available for the Quick Redirects method.
66
67
= Can I make the redirect open in a new window? =
68
- YES! New in 1.9, you can now make the redirect link open in a new window. Simply check the "Open in a new window" box when setting up the redirect on the page/post edit page. Note - this option is not available for the Quick Redirects method.
69
70
= I want to just have the link for the redirecting page/post show the new redirect link in the link, not the old one, can I do that? =
71
- YES! New in 1.9, you can now hide the original page link and have it replaced with the redirect link. Any place the theme calls either "wp_page_links", "post_links" or "page_links" functions, the plugin can replace the original link with the new one. Simply check the "Show Redirect URL" box when setting up the redirect on the page/post edit page. Note - this option is not available for the Quick Redirects method.
72
73
= I have Business Cards/Postcards/Ads that say my website is http://something.com/my-name/ or http://something.com/my-product/, can I set that up with this? =
74
YES! Just set up a redirect (see above) and set the Request field to /my-name/ or /my-product/ and the Destination field to the place you want it to go. The destination doesn't even need to be on the same site - it can go anywhere you want it to go!
@@ -109,6 +109,11 @@ Yes, you can, but you do not always need to. If you are redirecting to an extern
109
3. Menu for the Quick 301 Redirects page - located in the settings menu.
110
111
== Changelog ==
112
= 3.1 =
113
* Re-issue of 2.1 for immediate fix of issue with the 3.0 version.(6/21/2010)
114
= 3.0 =
1
=== Quick Page/Post Redirect ===
2
Contributors: Don Fischer
3
+ Donate link: http://www.fischercreativemedia.com/wordpress-plugins/donate/
4
+ Tags: redirect, 301, 302, meta, post, plugin, page, forward, re-direct, nofollow, wpmu, menu links, posts, pages, admin, 404
5
Requires at least: 2.5
6
+ Tested up to: 3.1 beta
7
+ Stable tag: 3.2
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
+ = Features: =
16
+ * 1. you can 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. You can redirect without needing to create a Page or Post. 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
+ * 5. Works with new WordPress menus as of plugin version 3.2
21
22
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.
23
25
26
This plugin is also not compatible with WordPress versions less than 2.5.
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').
30
* If your browser tells you that your are in an infinite loop, check to make sure you do not have pages redirecting to another page that redirects back to the initial page. That WILL cause an infinate loop.
38
* Upload `quick_page_post_redirect` folder to the `/wp-content/plugins/` directory
39
* Activate the plugin through the 'Plugins' menu in WordPress
40
* Once Activated, you can add a redirect by entering the correct information in the `Quick Page/Post Redirect` box in the edit section of a page or post
41
+ * You can create a redirect with the 'Quick Redirects' option located in the Admin Settings menu.
42
43
= If you install this plugin through WordPress 2.8+ plugin search interface: =
44
* Click Install `Quick Page/Post Redirect Plugin`
45
* Activate the plugin through the 'Plugins' menu in WordPress
46
* Once Activated, you can add a redirect by entering the correct information in the `Quick Page/Post Redirect` box in the edit section of a page or post
47
+ * You can create a redirect with the 'Quick 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? =
62
The new fuctionality is located in the Admin under Settings/Quick Redirects. The olde URL goes in the Request field and the to new URL goes in the Destination field. Simple and Quick!
63
64
= Can I add 'rel="nofollow" attribute to the redirect link? =
65
+ YES! Since version 1.9, you can add a ' rel="nofollow" ' attribute for the redirect link. Simply check the "add rel=nofollow" box when setting up the redirect on the page/post edit page. Note - this option is not available for the Quick Redirects method.
66
67
= Can I make the redirect open in a new window? =
68
+ YES! Since version 1.9, you can make the redirect link open in a new window. Simply check the "Open in a new window" box when setting up the redirect on the page/post edit page. Note - this option is not available for the Quick Redirects method.
69
70
= I want to just have the link for the redirecting page/post show the new redirect link in the link, not the old one, can I do that? =
71
+ YES! Since version 1.9, you can hide the original page link and have it replaced with the redirect link. Any place the theme calls either "wp_page_links", "post_links" or "page_links" functions, the plugin can replace the original link with the new one. Simply check the "Show Redirect URL" box when setting up the redirect on the page/post edit page. Note - this option is not available for the Quick Redirects method.
72
73
= I have Business Cards/Postcards/Ads that say my website is http://something.com/my-name/ or http://something.com/my-product/, can I set that up with this? =
74
YES! Just set up a redirect (see above) and set the Request field to /my-name/ or /my-product/ and the Destination field to the place you want it to go. The destination doesn't even need to be on the same site - it can go anywhere you want it to go!
109
3. Menu for the Quick 301 Redirects page - located in the settings menu.
110
111
== Changelog ==
112
+ = 3.2 =
113
+ * remove functions ppr_linktotarget, ppr_linktonorel, ppr_redirectto and ppr_linktometa.(12/10/2010)
114
+ * re-write functions to consolidate queries. (12/10/2010)
115
+ * added new filters for New menu structure to filter wp_nav_menu menus as well as old wp_page_menus functions. (12/10/2010)
116
+ * cleaned up new window and nofollow code to work more consistently. (12/10/2010)
117
= 3.1 =
118
* Re-issue of 2.1 for immediate fix of issue with the 3.0 version.(6/21/2010)
119
= 3.0 =