PluginProbe
Redirection / 5.8.1
Redirection v5.8.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 / redirection.php

redirection.php in Redirection 5.8.1, at redirection.php

149 lines 4.3 KB
No matching file
Up and down to move Enter to open Esc to close
Raw Download Zip
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: 5.8.1
7 Author: John Godley
8 Text Domain: redirection
9 Requires PHP: 7.4
10 Requires at least: 6.6
11 ============================================================================================================
12 For full license details see license.txt
13 ============================================================================================================
14 */
15
16 define( 'REDIRECTION_DB_VERSION', '4.2' ); // DB schema version. Only change if DB needs changing
17 define( 'REDIRECTION_FILE', __FILE__ );
18
19 if ( ! defined( 'REDIRECTION_FLYING_SOLO' ) ) {
20 define( 'REDIRECTION_FLYING_SOLO', apply_filters( 'redirection_flying_solo', true ) );
21 }
22
23 // This file must support PHP < 7.4 so as not to crash
24 if ( version_compare( PHP_VERSION, '7.4' ) < 0 ) {
25 add_filter( 'plugin_action_links_' . basename( dirname( REDIRECTION_FILE ) ) . '/' . basename( REDIRECTION_FILE ), 'red_deprecated_php' );
26
27 /**
28 * @param array<string> $links
29 * @return array<string>
30 */
31 function red_deprecated_php( array $links ): array {
32 /* translators: 1: server PHP version. 2: required PHP version. */
33 array_unshift( $links, '<a href="https://redirection.me/support/problems/php-version/" style="color: red; text-decoration: underline">' . sprintf( __( 'Disabled! Detected PHP %1$s, need PHP %2$s+', 'redirection' ), phpversion(), '7.4' ) . '</a>' );
34 return $links;
35 }
36
37 return;
38 }
39
40 require_once __DIR__ . '/build/redirection-version.php';
41 require_once __DIR__ . '/redirection-settings.php';
42 require_once __DIR__ . '/models/options.php';
43 require_once __DIR__ . '/models/redirect/redirect.php';
44 require_once __DIR__ . '/models/url/url.php';
45 require_once __DIR__ . '/models/regex.php';
46 require_once __DIR__ . '/models/module.php';
47 require_once __DIR__ . '/models/log/log.php';
48 require_once __DIR__ . '/models/flusher.php';
49 require_once __DIR__ . '/models/match.php';
50 require_once __DIR__ . '/models/action.php';
51 require_once __DIR__ . '/models/request.php';
52 require_once __DIR__ . '/models/header.php';
53 require_once __DIR__ . '/models/group.php';
54
55 /**
56 * Clear PHP opcache when plugin is updated. This is to help with mid-update errors.
57 *
58 * @param object $upgrader The upgrader object.
59 * @param array{action: string, type: string, plugins?: string[]} $options The upgrade options.
60 * @return void
61 */
62 function redirection_clear_opcache_on_upgrade( $upgrader, $options ) {
63 if ( $options['action'] !== 'update' || $options['type'] !== 'plugin' ) {
64 return;
65 }
66
67 $plugin_basename = plugin_basename( REDIRECTION_FILE );
68 $plugins = $options['plugins'] ?? [];
69
70 if ( ! in_array( $plugin_basename, $plugins, true ) ) {
71 return;
72 }
73
74 if ( function_exists( 'opcache_reset' ) ) {
75 // Suppress warnings if opcache_reset is restricted by server configuration
76 @opcache_reset(); // phpcs:ignore WordPress.PHP.NoSilencedErrors.Discouraged
77 }
78 }
79
80 add_action( 'upgrader_process_complete', 'redirection_clear_opcache_on_upgrade', 10, 2 );
81
82 /**
83 * @return bool
84 */
85 function red_is_wpcli() {
86 if ( defined( 'WP_CLI' ) && WP_CLI ) {
87 return true;
88 }
89
90 return false;
91 }
92
93 /**
94 * Detect a plain PHP CLI context (e.g., a cron script that loads wp-load.php
95 * directly). Distinct from red_is_wpcli(), which is only true under WP-CLI.
96 * Used to skip front-end redirect enforcement that would otherwise call die()
97 * and silently terminate the CLI process.
98 *
99 * @return bool
100 */
101 function red_is_cli() {
102 return PHP_SAPI === 'cli';
103 }
104
105 /**
106 * @return bool
107 */
108 function red_is_admin() {
109 if ( is_admin() ) {
110 return true;
111 }
112
113 return false;
114 }
115
116 /**
117 * @return void
118 */
119 function red_start_rest() {
120 require_once __DIR__ . '/redirection-admin.php';
121 require_once __DIR__ . '/api/api.php';
122
123 Redirection_Api::init();
124 Redirection_Admin::init();
125
126 remove_action( 'rest_api_init', 'red_start_rest' );
127 }
128
129 /**
130 * @return void
131 */
132 function redirection_locale() {
133 load_plugin_textdomain( 'redirection', false, dirname( plugin_basename( REDIRECTION_FILE ) ) . '/locale/' );
134 }
135
136 if ( red_is_admin() || red_is_wpcli() ) {
137 require_once __DIR__ . '/redirection-admin.php';
138 require_once __DIR__ . '/api/api.php';
139 } else {
140 require_once __DIR__ . '/redirection-front.php';
141 }
142
143 if ( red_is_wpcli() ) {
144 require_once __DIR__ . '/redirection-cli.php';
145 }
146
147 add_action( 'rest_api_init', 'red_start_rest' );
148 add_action( 'init', 'redirection_locale' );
149