| 1 |
<?php |
| 2 |
/* |
| 3 |
Plugin Name: Redirection |
| 4 |
Plugin URI: https://redirection.me/ |
| 5 |
Description: Manage all your 301 redirects and monitor 404 errors |
| 6 |
Version: 4.2 |
| 7 |
Author: John Godley |
| 8 |
Author URI: https://johngodley.com |
| 9 |
Text Domain: redirection |
| 10 |
Domain Path: /locale |
| 11 |
============================================================================================================ |
| 12 |
This software is provided "as is" and any express or implied warranties, including, but not limited to, the |
| 13 |
implied warranties of merchantibility and fitness for a particular purpose are disclaimed. In no event shall |
| 14 |
the copyright owner or contributors be liable for any direct, indirect, incidental, special, exemplary, or |
| 15 |
consequential damages(including, but not limited to, procurement of substitute goods or services; loss of |
| 16 |
use, data, or profits; or business interruption) however caused and on any theory of liability, whether in |
| 17 |
contract, strict liability, or tort(including negligence or otherwise) arising in any way out of the use of |
| 18 |
this software, even if advised of the possibility of such damage. |
| 19 |
|
| 20 |
For full license details see license.txt |
| 21 |
============================================================================================================ |
| 22 |
*/ |
| 23 |
|
| 24 |
define( 'REDIRECTION_DB_VERSION', '4.1' ); // DB schema version. Only change if DB needs changing |
| 25 |
define( 'REDIRECTION_FILE', __FILE__ ); |
| 26 |
define( 'REDIRECTION_DEV_MODE', false ); |
| 27 |
|
| 28 |
if ( ! defined( 'REDIRECTION_FLYING_SOLO' ) ) { |
| 29 |
define( 'REDIRECTION_FLYING_SOLO', apply_filters( 'redirection_flying_solo', true ) ); |
| 30 |
} |
| 31 |
|
| 32 |
// This file must support PHP < 5.4 so as not to crash |
| 33 |
if ( version_compare( phpversion(), '5.4' ) < 0 ) { |
| 34 |
add_action( 'plugin_action_links_' . basename( dirname( REDIRECTION_FILE ) ) . '/' . basename( REDIRECTION_FILE ), 'red_deprecated_php', 10, 4 ); |
| 35 |
|
| 36 |
function red_deprecated_php( $links ) { |
| 37 |
/* translators: 1: PHP version */ |
| 38 |
array_unshift( $links, '<a href="https://redirection.me/support/problems/php-version/" style="color: red; text-decoration: underline">' . sprintf( __( 'Disabled! Detected PHP %s, need PHP 5.4+', 'redirection' ), phpversion() ) . '</a>' ); |
| 39 |
return $links; |
| 40 |
} |
| 41 |
|
| 42 |
return; |
| 43 |
} |
| 44 |
|
| 45 |
include dirname( __FILE__ ) . '/redirection-version.php'; |
| 46 |
include dirname( __FILE__ ) . '/redirection-settings.php'; |
| 47 |
include dirname( __FILE__ ) . '/models/redirect.php'; |
| 48 |
include dirname( __FILE__ ) . '/models/module.php'; |
| 49 |
include dirname( __FILE__ ) . '/models/log.php'; |
| 50 |
include dirname( __FILE__ ) . '/models/flusher.php'; |
| 51 |
include dirname( __FILE__ ) . '/models/match.php'; |
| 52 |
include dirname( __FILE__ ) . '/models/action.php'; |
| 53 |
include dirname( __FILE__ ) . '/models/request.php'; |
| 54 |
|
| 55 |
function red_is_wpcli() { |
| 56 |
if ( defined( 'WP_CLI' ) && WP_CLI ) { |
| 57 |
return true; |
| 58 |
} |
| 59 |
|
| 60 |
return false; |
| 61 |
} |
| 62 |
|
| 63 |
function red_is_admin() { |
| 64 |
if ( is_admin() ) { |
| 65 |
return true; |
| 66 |
} |
| 67 |
|
| 68 |
return false; |
| 69 |
} |
| 70 |
|
| 71 |
function red_start_rest() { |
| 72 |
include_once dirname( __FILE__ ) . '/redirection-admin.php'; |
| 73 |
include_once dirname( __FILE__ ) . '/redirection-api.php'; |
| 74 |
|
| 75 |
Redirection_Api::init(); |
| 76 |
Redirection_Admin::init(); |
| 77 |
|
| 78 |
remove_action( 'rest_api_init', 'red_start_rest' ); |
| 79 |
} |
| 80 |
|
| 81 |
function redirection_locale() { |
| 82 |
load_plugin_textdomain( 'redirection', false, dirname( plugin_basename( REDIRECTION_FILE ) ) . '/locale/' ); |
| 83 |
} |
| 84 |
|
| 85 |
if ( red_is_admin() || red_is_wpcli() ) { |
| 86 |
include_once dirname( __FILE__ ) . '/redirection-admin.php'; |
| 87 |
include_once dirname( __FILE__ ) . '/redirection-api.php'; |
| 88 |
} else { |
| 89 |
include_once dirname( __FILE__ ) . '/redirection-front.php'; |
| 90 |
} |
| 91 |
|
| 92 |
if ( red_is_wpcli() ) { |
| 93 |
include_once dirname( __FILE__ ) . '/redirection-cli.php'; |
| 94 |
} |
| 95 |
|
| 96 |
add_action( 'rest_api_init', 'red_start_rest' ); |
| 97 |
add_action( 'init', 'redirection_locale' ); |
| 98 |
|
| 99 |
// This is causing a lot of problems with the REST API - disable qTranslate |
| 100 |
add_filter( 'qtranslate_language_detect_redirect', function( $lang, $url ) { |
| 101 |
$url = Redirection_Request::get_request_url(); |
| 102 |
|
| 103 |
if ( strpos( $url, '/wp-json/' ) !== false || strpos( $url, 'index.php?rest_route' ) !== false ) { |
| 104 |
return false; |
| 105 |
} |
| 106 |
|
| 107 |
return $lang; |
| 108 |
}, 10, 2 ); |
| 109 |
|