PluginProbe
Redirection / 2.8
Redirection v2.8
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.8, at modules/wordpress.php

133 lines 3.5 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 const MODULE_ID = 1;
5
6 private $matched = false;
7
8 public function get_id() {
9 return self::MODULE_ID;
10 }
11
12 public function get_name() {
13 return 'WordPress';
14 }
15
16 public function start() {
17 // Setup the various filters and actions that allow Redirection to happen
18 add_action( 'init', array( $this, 'init' ) );
19 add_action( 'send_headers', array( $this, 'send_headers' ) );
20 add_filter( 'permalink_redirect_skip', array( $this, 'permalink_redirect_skip' ) );
21 add_filter( 'wp_redirect', array( $this, 'wp_redirect' ), 1, 2 );
22 add_action( 'template_redirect', array( $this, 'template_redirect' ) );
23 add_action( 'redirection_visit', array( $this, 'redirection_visit' ), 10, 3 );
24
25 // Remove WordPress 2.3 redirection
26 remove_action( 'template_redirect', 'wp_old_slug_redirect' );
27 remove_action( 'edit_form_advanced', 'wp_remember_old_slug' );
28 }
29
30 public function redirection_visit( $redirect, $url, $target ) {
31 $redirect->visit( $url, $target );
32 }
33
34 public function init() {
35 $url = apply_filters( 'redirection_url_source', Redirection_Request::get_request_url() );
36
37 // Make sure we don't try and redirect something essential
38 if ( $url && ! $this->protected_url( $url ) && $this->matched === false ) {
39 do_action( 'redirection_first', $url, $this );
40
41 $redirects = Red_Item::get_for_url( $url, 'wp' );
42
43 foreach ( (array) $redirects as $item ) {
44 if ( $item->matches( $url ) ) {
45 $this->matched = $item;
46 break;
47 }
48 }
49
50 do_action( 'redirection_last', $url, $this );
51 }
52 }
53
54 private function protected_url( $url ) {
55 return false;
56 }
57
58 public function template_redirect() {
59 if ( is_404() ) {
60 $options = red_get_options();
61
62 if ( isset( $options['expire_404'] ) && $options['expire_404'] >= 0 ) {
63 RE_404::create( Redirection_Request::get_request_url(), Redirection_Request::get_user_agent(), Redirection_Request::get_ip(), Redirection_Request::get_referrer() );
64 }
65 }
66 }
67
68 public function status_header( $status ) {
69 // Fix for incorrect headers sent when using FastCGI/IIS
70 if ( substr( php_sapi_name(), 0, 3 ) === 'cgi' ) {
71 return str_replace( 'HTTP/1.1', 'Status:', $status );
72 }
73
74 return $status;
75 }
76
77 public function send_headers( $obj ) {
78 if ( ! empty( $this->matched ) && $this->matched->match->action_code === '410' ) {
79 add_filter( 'status_header', array( &$this, 'set_header_410' ) );
80 }
81 }
82
83 public function set_header_410() {
84 return 'HTTP/1.1 410 Gone';
85 }
86
87 public function wp_redirect( $url, $status ) {
88 global $wp_version, $is_IIS;
89
90 if ( $is_IIS ) {
91 header( "Refresh: 0;url=$url" );
92 return $url;
93 } elseif ( $status === 301 && php_sapi_name() === 'cgi-fcgi' ) {
94 $servers_to_check = array( 'lighttpd', 'nginx' );
95
96 foreach ( $servers_to_check as $name ) {
97 if ( stripos( $_SERVER['SERVER_SOFTWARE'], $name ) !== false ) {
98 status_header( $status );
99 header( "Location: $url" );
100 exit( 0 );
101 }
102 }
103 } elseif ( $status == 307 ) {
104 status_header( $status );
105 header( "Cache-Control: no-cache, must-revalidate, max-age=0" );
106 header( "Expires: Sat, 26 Jul 1997 05:00:00 GMT" );
107 return $url;
108 }
109
110 status_header( $status );
111 return $url;
112 }
113
114 public function update( array $data ) {
115 return false;
116 }
117
118 protected function load( $options ) {
119 }
120
121 protected function flush_module() {
122 }
123
124 public function permalink_redirect_skip( $skip ) {
125 // only want this if we've matched using redirection
126 if ( $this->matched ) {
127 $skip[] = $_SERVER['REQUEST_URI'];
128 }
129
130 return $skip;
131 }
132 }
133