| 1 |
<?php |
| 2 |
/** |
| 3 |
* Plugin Name: Broken Link Notifier |
| 4 |
* Plugin URI: https://pluginrx.com/plugin/broken-link-notifier/ |
| 5 |
* Description: Get notified when someone loads a page with a broken link |
| 6 |
* Version: 1.3.8 |
| 7 |
* Requires at least: 6.0 |
| 8 |
* Tested up to: 7.0 |
| 9 |
* Requires PHP: 7.4 |
| 10 |
* Author: PluginRx |
| 11 |
* Author URI: https://pluginrx.com/ |
| 12 |
* Discord URI: https://discord.gg/3HnzNEJVnR |
| 13 |
* Text Domain: broken-link-notifier |
| 14 |
* License: GPLv2 or later |
| 15 |
* License URI: http://www.gnu.org/licenses/gpl-2.0.txt |
| 16 |
* Created on: April 7, 2024 |
| 17 |
*/ |
| 18 |
|
| 19 |
|
| 20 |
/** |
| 21 |
* Exit if accessed directly. |
| 22 |
*/ |
| 23 |
if ( !defined( 'ABSPATH' ) ) exit; |
| 24 |
|
| 25 |
|
| 26 |
/** |
| 27 |
* Defines |
| 28 |
*/ |
| 29 |
$plugin_data = get_file_data( __FILE__, [ |
| 30 |
'name' => 'Plugin Name', |
| 31 |
'version' => 'Version', |
| 32 |
'requires_php' => 'Requires PHP', |
| 33 |
'textdomain' => 'Text Domain', |
| 34 |
'author' => 'Author', |
| 35 |
'author_uri' => 'Author URI', |
| 36 |
'discord_uri' => 'Discord URI', |
| 37 |
] ); |
| 38 |
|
| 39 |
// Versions |
| 40 |
define( 'BLNOTIFIER_VERSION', $plugin_data[ 'version' ] ); |
| 41 |
define( 'BLNOTIFIER_SCRIPT_VERSION', time() ); // Use time() for development, change to BLNOTIFIER_VERSION for production |
| 42 |
define( 'BLNOTIFIER_MIN_PHP_VERSION', $plugin_data[ 'requires_php' ] ); |
| 43 |
|
| 44 |
// Names |
| 45 |
define( 'BLNOTIFIER_NAME', $plugin_data[ 'name' ] ); |
| 46 |
define( 'BLNOTIFIER_TEXTDOMAIN', $plugin_data[ 'textdomain' ] ); |
| 47 |
define( 'BLNOTIFIER_AUTHOR_NAME', $plugin_data[ 'author' ] ); |
| 48 |
define( 'BLNOTIFIER_AUTHOR_URL', $plugin_data[ 'author_uri' ] ); |
| 49 |
define( 'BLNOTIFIER_GUIDE_URL', BLNOTIFIER_AUTHOR_URL . 'guide/plugin/' . BLNOTIFIER_TEXTDOMAIN . '/' ); |
| 50 |
define( 'BLNOTIFIER_DOCS_URL', BLNOTIFIER_AUTHOR_URL . 'docs/plugin/' . BLNOTIFIER_TEXTDOMAIN . '/' ); |
| 51 |
define( 'BLNOTIFIER_SUPPORT_URL', BLNOTIFIER_AUTHOR_URL . 'support/plugin/' . BLNOTIFIER_TEXTDOMAIN . '/' ); |
| 52 |
define( 'BLNOTIFIER_DISCORD_URL', $plugin_data[ 'discord_uri' ] ); |
| 53 |
|
| 54 |
// Prevent loading the plugin if PHP version is not minimum |
| 55 |
if ( version_compare( PHP_VERSION, BLNOTIFIER_MIN_PHP_VERSION, '<=' ) ) { |
| 56 |
add_action( 'admin_init', static function() { |
| 57 |
deactivate_plugins( plugin_basename( __FILE__ ) ); |
| 58 |
} ); |
| 59 |
add_action( 'admin_notices', static function() { |
| 60 |
/* translators: 1: Plugin name, 2: Minimum PHP version */ |
| 61 |
$message = sprintf( __( '"%1$s" requires PHP %2$s or newer.', 'broken-link-notifier' ), |
| 62 |
BLNOTIFIER_NAME, |
| 63 |
BLNOTIFIER_MIN_PHP_VERSION |
| 64 |
); |
| 65 |
echo '<div class="notice notice-error"><p>'.esc_html( $message ).'</p></div>'; |
| 66 |
} ); |
| 67 |
return; |
| 68 |
} |
| 69 |
|
| 70 |
// Paths |
| 71 |
define( 'BLNOTIFIER_ADMIN_DIR', str_replace( site_url( '/' ), '', rtrim( admin_url(), '/' ) ) ); //: /wp-admin/ |
| 72 |
define( 'BLNOTIFIER_PLUGIN_DIR', plugins_url( '/'.BLNOTIFIER_TEXTDOMAIN.'/' ) ); //: https://domain.com/wp-content/plugins/broken-link-notifier/ |
| 73 |
define( 'BLNOTIFIER_PLUGIN_INCLUDES_PATH', plugin_dir_path( __FILE__ ).'includes/' ); //: /home/.../public_html/wp-content/plugins/broken-link-notifier/includes/ |
| 74 |
define( 'BLNOTIFIER_PLUGIN_JS_ABSPATH', BLNOTIFIER_PLUGIN_INCLUDES_PATH . 'js/' ); //: /home/.../public_html/wp-content/plugins/broken-link-notifier/includes/js/ |
| 75 |
define( 'BLNOTIFIER_PLUGIN_JS_PATH', str_replace( site_url(), '', BLNOTIFIER_PLUGIN_DIR ).'includes/js/' ); //: /wp-content/plugins/broken-link-notifier/includes/js/ |
| 76 |
define( 'BLNOTIFIER_PLUGIN_CSS_PATH', str_replace( site_url(), '', BLNOTIFIER_PLUGIN_DIR ).'includes/css/' ); //: /wp-content/plugins/broken-link-notifier/includes/css/ |
| 77 |
define( 'BLNOTIFIER_PLUGIN_IMG_PATH', BLNOTIFIER_PLUGIN_DIR.'includes/img/' ); //: https://domain.com/wp-content/plugins/broken-link-notifier/includes/img/ |
| 78 |
|
| 79 |
|
| 80 |
/** |
| 81 |
* Load the files |
| 82 |
*/ |
| 83 |
require BLNOTIFIER_PLUGIN_INCLUDES_PATH . 'loader.php'; |
| 84 |
|
| 85 |
|
| 86 |
/** |
| 87 |
* Initialize the plugin loader |
| 88 |
*/ |
| 89 |
$blnotifier_loader_instance = new BLNOTIFIER_LOADER(); |
| 90 |
|
| 91 |
|
| 92 |
/** |
| 93 |
* Register activation and deactivation hooks for role/capability management. |
| 94 |
* These hooks must be called in the main plugin file and target methods of your plugin instance. |
| 95 |
*/ |
| 96 |
register_activation_hook( __FILE__, [ $blnotifier_loader_instance, 'plugin_activate' ] ); |
| 97 |
register_deactivation_hook( __FILE__, [ $blnotifier_loader_instance, 'plugin_deactivate' ] ); |
| 98 |
|
| 99 |
|
| 100 |
/** |
| 101 |
* Delete the cache table on plugin deactivation or uninstall. |
| 102 |
*/ |
| 103 |
register_deactivation_hook( __FILE__, 'blnotifier_cleanup_on_shutdown' ); |
| 104 |
register_uninstall_hook( __FILE__, 'blnotifier_cleanup_on_shutdown' ); |
| 105 |
function blnotifier_cleanup_on_shutdown() { |
| 106 |
if ( class_exists( 'BLNOTIFIER_CACHE' ) ) { |
| 107 |
$cache = new BLNOTIFIER_CACHE(); |
| 108 |
$cache->delete_cache_table(); |
| 109 |
} |
| 110 |
} // End blnotifier_cleanup_on_shutdown() |