PluginProbe
Redirection / 2.2.14
Redirection v2.2.14
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.14, at modules/wordpress.php

124 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 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 if ( !empty( $this->matched ) && $this->matched->match->action_code == '410' ) {
65 add_filter( 'status_header', array( &$this, 'set_header_410' ) );
66 }
67 }
68
69 function set_header_410() {
70 return 'HTTP/1.1 410 Gone';
71 }
72
73 function wp_redirect( $url, $status )
74 {
75 global $wp_version, $is_IIS;
76 if ( $wp_version < '2.1' ) {
77 status_header( $status );
78 return $url;
79 } elseif ( $is_IIS ) {
80 header( "Refresh: 0;url=$url" );
81 return $url;
82 } else {
83 if ( $status == 301 && php_sapi_name() == 'cgi-fcgi' ) {
84 $servers_to_check = array( 'lighttpd', 'nginx' );
85 foreach ( $servers_to_check as $name ) {
86 if ( stripos( $_SERVER['SERVER_SOFTWARE'], $name ) !== false ) {
87 status_header( $status );
88 header( "Location: $url" );
89 exit( 0 );
90 }
91 }
92 }
93
94 status_header( $status );
95 return $url;
96 }
97 }
98
99 function save( $data ) {
100 return array();
101 }
102
103 function permalink_redirect_skip( $skip ) {
104 // only want this if we:ve matched using redirection
105 if ( $this->matched )
106 $skip[] = $_SERVER['REQUEST_URI'];
107 return $skip;
108 }
109
110 function is_valid()
111 {
112 $perm = get_option( 'permalink_structure' );
113 if ( $perm === false || $perm == '' )
114 return false;
115 return true;
116 }
117
118 function options()
119 {
120 if ( !$this->is_valid() )
121 echo __( '<strong>Disabled: You must enable <a href="options-permalink.php">permalinks</a> before using this</strong>', 'redirection' );
122 }
123 }
124