PluginProbe
Redirection / 2.3.8
Redirection v2.3.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.3.8, at modules/wordpress.php

123 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 remove_action( 'template_redirect', 'wp_old_slug_redirect' );
18 remove_action( 'edit_form_advanced', 'wp_remember_old_slug' );
19 }
20
21 function init() {
22 global $redirection;
23
24 $url = $_SERVER['REQUEST_URI'];
25
26 // Make sure we don't try and redirect something essential
27 if ( !$this->protected_url( $url ) && !$redirection->hasMatched() ) {
28 do_action( 'redirection_first', $url, $this );
29
30 $redirects = Red_Item::get_for_url( $url, 'wp' );
31
32 foreach ( (array)$redirects AS $item ) {
33 if ( $item->matches( $url ) ) {
34 $redirection->setMatched( true );
35 $this->matched = $item;
36 break;
37 }
38 }
39
40 do_action( 'redirection_last', $url, $this );
41 }
42 }
43
44 function protected_url( $url )
45 {
46 global $redirection;
47 $part = explode( '?', $url );
48
49 if ( $part[0] == str_replace( get_bloginfo( 'url' ), '', $redirection->url() ).'/ajax.php' || strpos($url, 'wp-cron.php' ) !== false )
50 return true;
51 return false;
52 }
53
54 function status_header( $status )
55 {
56 // Fix for incorrect headers sent when using FastCGI/IIS
57 if ( substr( php_sapi_name(), 0, 3 ) == 'cgi' )
58 return str_replace( 'HTTP/1.1', 'Status:', $status );
59 return $status;
60 }
61
62 function send_headers( $obj ) {
63 if ( !empty( $this->matched ) && $this->matched->match->action_code == '410' ) {
64 add_filter( 'status_header', array( &$this, 'set_header_410' ) );
65 }
66 }
67
68 function set_header_410() {
69 return 'HTTP/1.1 410 Gone';
70 }
71
72 function wp_redirect( $url, $status ) {
73 global $wp_version, $is_IIS;
74
75 if ( $is_IIS ) {
76 header( "Refresh: 0;url=$url" );
77 return $url;
78 }
79 elseif ( $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 function save( $data ) {
95 return array();
96 }
97
98 function permalink_redirect_skip( $skip ) {
99 // only want this if we:ve matched using redirection
100 if ( $this->matched )
101 $skip[] = $_SERVER['REQUEST_URI'];
102 return $skip;
103 }
104
105 function is_valid()
106 {
107 $perm = get_option( 'permalink_structure' );
108 if ( $perm === false || $perm == '' )
109 return false;
110 return true;
111 }
112
113 function options()
114 {
115 if ( !$this->is_valid() )
116 echo __( '<strong>Disabled: You must enable <a href="options-permalink.php">permalinks</a> before using this</strong>', 'redirection' );
117 }
118
119 public function get_type_string() {
120 return __( 'WordPress', 'redirection' );
121 }
122 }
123