PluginProbe
Redirection / 2.2.2
Redirection v2.2.2
5.10.0 5.9.0 5.8.1 5.8.0 3.7.2 3.7.3 4.0 4.0.1 4.1 4.1.1 4.2 4.2.1 4.2.2 4.2.3 4.3 4.3.1 4.3.2 4.3.3 4.4 4.4.1 4.4.2 4.5 4.5.1 4.6.2 4.7.1 All 130 releases
redirection / modules / wordpress.php

wordpress.php in Redirection 2.2.2, at modules/wordpress.php

120 lines 3.2 KB
No matching file
Up and down to move Enter to open Esc to close
Raw Download Zip
1 <?php
2
3 class WordPress_Module extends Red_Module {
4 var $canonical = 'default';
5 var $strip_index = 'default';
6 var $time_limit = 0;
7 var $matched;
8
9 function start() {
10 // Setup the various filters and actions that allow Redirection to h appen
11 add_action( 'init', array( &$this, 'init' ) );
12 add_action( 'send_headers', array( &$this, 'send_headers' ) );
13 add_filter( 'permalink_redirect_skip', array( &$this, 'permalink_redirect_skip' ) );
14 add_filter( 'wp_redirect', array( &$this, 'wp_redirect' ), 1, 2 );
15
16 // Remove WordPress 2.3 redirection
17 // XXX still needed?
18 remove_action( 'template_redirect', 'wp_old_slug_redirect' );
19 remove_action( 'edit_form_advanced', 'wp_remember_old_slug' );
20 }
21
22 function init() {
23 global $redirection;
24
25 $url = $_SERVER['REQUEST_URI'];
26
27 // Make sure we don't try and redirect something essential
28 if ( !$this->protected_url( $url ) && !$redirection->hasMatched() ) {
29 do_action( 'redirection_first', $url, $this );
30
31 $redirects = Red_Item::get_for_url( $url, 'wp' );
32
33 foreach ( (array)$redirects AS $key => $item ) {
34 if ( $item->matches( $url ) ) {
35 $redirection->setMatched( true );
36 $this->matched = $item;
37 break;
38 }
39 }
40
41 do_action( 'redirection_last', $url, $this );
42 }
43 }
44
45 function protected_url( $url )
46 {
47 global $redirection;
48 $part = explode( '?', $url );
49
50 if ( $part[0] == str_replace( get_bloginfo( 'url' ), '', $redirection->url() ).'/ajax.php' || strpos($url, 'wp-cron.php' ) !== false )
51 return true;
52 return false;
53 }
54
55 function status_header( $status )
56 {
57 // Fix for incorrect headers sent when using FastCGI/IIS
58 if ( substr( php_sapi_name(), 0, 3 ) == 'cgi' )
59 return str_replace( 'HTTP/1.1', 'Status:', $status );
60 return $status;
61 }
62
63 function send_headers( $obj )
64 {
65 if ( !empty($this->matched ) && $this->matched->type == '410' )
66 status_header( 410 );
67 }
68
69 function wp_redirect( $url, $status )
70 {
71 global $wp_version, $is_IIS;
72 if ( $wp_version < '2.1' ) {
73 status_header( $status );
74 return $url;
75 } elseif ( $is_IIS ) {
76 header( "Refresh: 0;url=$url" );
77 return $url;
78 } else {
79 if ( $status == 301 && php_sapi_name() == 'cgi-fcgi' ) {
80 $servers_to_check = array( 'lighttpd', 'nginx' );
81 foreach ( $servers_to_check as $name ) {
82 if ( stripos( $_SERVER['SERVER_SOFTWARE'], $name ) !== false ) {
83 status_header( $status );
84 header( "Location: $url" );
85 exit( 0 );
86 }
87 }
88 }
89
90 status_header( $status );
91 return $url;
92 }
93 }
94
95 function save( $data ) {
96 return array();
97 }
98
99 function permalink_redirect_skip( $skip ) {
100 // only want this if we:ve matched using redirection
101 if ( $this->matched )
102 $skip[] = $_SERVER['REQUEST_URI'];
103 return $skip;
104 }
105
106 function is_valid()
107 {
108 $perm = get_option( 'permalink_structure' );
109 if ( $perm === false || $perm == '' )
110 return false;
111 return true;
112 }
113
114 function options()
115 {
116 if ( !$this->is_valid() )
117 echo __( '<strong>Disabled: You must enable <a href="options-permalink.php">permalinks</a> before using this</strong>', 'redirection' );
118 }
119 }
120