-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathbroken-link-logger.php
More file actions
151 lines (123 loc) · 5.4 KB
/
Copy pathbroken-link-logger.php
File metadata and controls
151 lines (123 loc) · 5.4 KB
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
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
<?php
/**
* Plugin Name: 404 & Broken Link Logger
* Plugin URI: https://github.com/mcglenn07/broken-link-logger
* Description: Logs every 404 hit on your site (URL, referrer, hit count) and lets you redirect any of them to a working URL in one click.
* Version: 1.0.0
* Requires at least: 5.8
* Requires PHP: 7.4
* Author: Mc Glenn Tangalin
* Author URI: https://github.com/mcglenn07
* License: GPL2
* License URI: https://www.gnu.org/licenses/gpl-2.0.html
* Text Domain: broken-link-logger
* Domain Path: /languages
*/
/*
Broken Link Logger is free software: you can redistribute it and/or modify
it under the terms of the GNU General Public License as published by
the Free Software Foundation, either version 2 of the License, or
any later version.
Broken Link Logger is distributed in the hope that it will be useful,
but WITHOUT ANY WARRANTY; without even the implied warranty of
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
GNU General Public License for more details.
You should have received a copy of the GNU General Public License
along with Broken Link Logger. If not, see https://www.gnu.org/licenses/gpl-2.0.html.
*/
if ( ! defined( 'ABSPATH' ) ) {
exit; // Exit if accessed directly.
}
if ( ! class_exists( 'Broken_Link_Logger' ) ) {
class Broken_Link_Logger {
function __construct() {
$this->define_constants();
$this->load_textdomain();
require_once( BLL_PATH . 'functions/functions.php' );
// Table creation / schema upgrades.
require_once( BLL_PATH . 'database/class.bll-db.php' );
$BLL_DB = new BLL_DB();
// Settings (Settings API: Settings > Broken Link Logger).
require_once( BLL_PATH . 'class.bll-settings.php' );
$BLL_Settings = new BLL_Settings();
// Redirect matching + 404 logging, run on every front-end request.
require_once( BLL_PATH . 'loggers/class.bll-redirector.php' );
$BLL_Redirector = new BLL_Redirector();
require_once( BLL_PATH . 'loggers/class.bll-logger.php' );
$BLL_Logger = new BLL_Logger();
// Daily cleanup cron for old, unresolved entries.
require_once( BLL_PATH . 'loggers/class.bll-cron.php' );
$BLL_Cron = new BLL_Cron();
// Admin screen: Tools > Broken Links.
require_once( BLL_PATH . 'admin/class.bll-list-table.php' );
require_once( BLL_PATH . 'admin/class.bll-admin.php' );
$BLL_Admin = new BLL_Admin();
add_action( 'wp_enqueue_scripts', array( $this, 'register_scripts' ) );
add_action( 'admin_enqueue_scripts', array( $this, 'register_admin_scripts' ) );
}
/**
* Define plugin constants.
*/
public function define_constants() {
define( 'BLL_PATH', plugin_dir_path( __FILE__ ) );
define( 'BLL_URL', plugin_dir_url( __FILE__ ) );
define( 'BLL_VERSION', '1.0.0' );
define( 'BLL_TABLE_HITS', 'bll_404_hits' );
define( 'BLL_TABLE_REDIRECTS', 'bll_redirects' );
define( 'BLL_OPTION_SETTINGS', 'bll_settings' );
define( 'BLL_OPTION_DB_VERSION', 'bll_db_version' );
}
public static function activate() {
require_once( plugin_dir_path( __FILE__ ) . 'database/class.bll-db.php' );
BLL_DB::create_tables();
if ( false === get_option( 'bll_settings' ) ) {
require_once( plugin_dir_path( __FILE__ ) . 'class.bll-settings.php' );
update_option( 'bll_settings', BLL_Settings::defaults() );
}
if ( ! wp_next_scheduled( 'bll_daily_cleanup' ) ) {
wp_schedule_event( time() + DAY_IN_SECONDS, 'daily', 'bll_daily_cleanup' );
}
flush_rewrite_rules();
}
public static function deactivate() {
$timestamp = wp_next_scheduled( 'bll_daily_cleanup' );
if ( $timestamp ) {
wp_unschedule_event( $timestamp, 'bll_daily_cleanup' );
}
flush_rewrite_rules();
}
public function load_textdomain() {
load_plugin_textdomain(
'broken-link-logger',
false,
dirname( plugin_basename( __FILE__ ) ) . '/languages/'
);
}
/**
* Enqueue frontend scripts and styles. Currently unused on the
* frontend (the plugin works entirely via server-side redirects),
* kept as a documented extension point for future iterations.
*
* @return void
*/
public function register_scripts() {
// No frontend assets at this time.
}
/**
* Enqueue admin scripts and styles for the plugin's own screens only.
*
* @return void
*/
public function register_admin_scripts( $hook ) {
if ( false === strpos( (string) $hook, 'broken-link-logger' ) ) {
return;
}
wp_enqueue_style( 'bll-admin-css', BLL_URL . 'assets/css/admin.css', array(), BLL_VERSION, 'all' );
}
}
}
if ( class_exists( 'Broken_Link_Logger' ) ) {
register_activation_hook( __FILE__, array( 'Broken_Link_Logger', 'activate' ) );
register_deactivation_hook( __FILE__, array( 'Broken_Link_Logger', 'deactivate' ) );
$broken_link_logger = new Broken_Link_Logger();
}