-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathredirect-txt.php
128 lines (112 loc) · 2.77 KB
/
redirect-txt.php
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
<?php
/**
* Plugin Name: Redirect.txt
* Description: A simple yet powerful redirection plugin. Provide a simple list of URLs and their destinations, and Redirect.txt will take care of the rest.
* Requires at least: 6.2
* Requires PHP: 7.2
* Version: 0.2.5
* Author: Redirect.txt Team
* License: GPLv2 or later
* License URI: https://www.gnu.org/licenses/gpl-2.0.html
* Text Domain: redirect-txt
*
* @package redirect-txt
*/
if ( ! defined( 'ABSPATH' ) ) {
exit;
}
if ( ! defined( 'REDIRECT_TXT_VERSION' ) ) {
define( 'REDIRECT_TXT_VERSION', '0.2.5' );
}
/**
* Redirect_Txt Class
*/
class Redirect_Txt {
/**
* The single class instance.
*
* @var $instance
*/
private static $instance = null;
/**
* Main Instance
* Ensures only one instance of this class exists in memory at any one time.
*/
public static function instance() {
if ( is_null( self::$instance ) ) {
self::$instance = new self();
self::$instance->init();
}
return self::$instance;
}
/**
* Path to the plugin directory
*
* @var $plugin_path
*/
public $plugin_path;
/**
* URL to the plugin directory
*
* @var $plugin_url
*/
public $plugin_url;
/**
* Redirect_Txt constructor.
*/
public function __construct() {
/* We do nothing here! */
}
/**
* Init options
*/
public function init() {
$this->plugin_path = plugin_dir_path( __FILE__ );
$this->plugin_url = plugin_dir_url( __FILE__ );
// include helper files.
$this->include_dependencies();
// hooks.
add_action( 'init', [ $this, 'init_hook' ] );
}
/**
* Include dependencies
*/
private function include_dependencies() {
require_once $this->plugin_path . 'classes/class-settings.php';
require_once $this->plugin_path . 'classes/class-admin.php';
require_once $this->plugin_path . 'classes/class-assets.php';
require_once $this->plugin_path . 'classes/class-rest.php';
require_once $this->plugin_path . 'classes/class-redirects.php';
require_once $this->plugin_path . 'classes/class-logs.php';
}
/**
* Init Hook
*/
public function init_hook() {
// load textdomain.
load_plugin_textdomain( 'redirect-txt', false, basename( dirname( __FILE__ ) ) . '/languages' );
}
/**
* Activation Hook
*/
public function activation_hook() {
// Nothing here yet.
}
/**
* Deactivation Hook
*/
public function deactivation_hook() {
// Nothing here yet.
}
}
/**
* Function works with the Redirect_Txt class instance
*
* @return object Redirect_Txt
*/
function redirect_txt() {
return Redirect_Txt::instance();
}
add_action( 'plugins_loaded', 'redirect_txt' );
register_activation_hook( __FILE__, [ redirect_txt(), 'activation_hook' ] );
register_deactivation_hook( __FILE__, [ redirect_txt(), 'deactivation_hook' ] );