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

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