| 1 |
<?php |
| 2 |
/** |
| 3 |
* Plugin Name: Titan Anti-spam & Security |
| 4 |
* Plugin URI: http://wordpress.org/plugins/anti-spam/ |
| 5 |
* Description: Titan Security - Anti-spam, Anti-virus, Firewall and Malware Scan |
| 6 |
* Version: 7.5.2 |
| 7 |
* Author: Themeisle |
| 8 |
* Requires PHP: 7.4 |
| 9 |
* WordPress Available: yes |
| 10 |
* Requires License: no |
| 11 |
* Text Domain: anti-spam |
| 12 |
* Author URI: https://themeisle.com |
| 13 |
* License: GPLv3 |
| 14 |
* |
| 15 |
* @package Titan_Security |
| 16 |
*/ |
| 17 |
|
| 18 |
// Exit if accessed directly. |
| 19 |
if ( ! defined( 'ABSPATH' ) ) { |
| 20 |
exit; |
| 21 |
} |
| 22 |
|
| 23 |
if ( version_compare( PHP_VERSION, '7.4', '<' ) ) { |
| 24 |
add_action( |
| 25 |
'admin_notices', |
| 26 |
function () { |
| 27 |
?> |
| 28 |
<div class="notice notice-error"> |
| 29 |
<p><?php esc_html_e( 'Titan Anti-spam & Security requires PHP 7.4 or higher. Please upgrade your PHP version.', 'anti-spam' ); ?></p> |
| 30 |
</div> |
| 31 |
<?php |
| 32 |
} |
| 33 |
); |
| 34 |
|
| 35 |
return; |
| 36 |
} |
| 37 |
|
| 38 |
/** |
| 39 |
* ----------------------------------------------------------------------------- |
| 40 |
* CONSTANTS |
| 41 |
* Install frequently used constants and constants for debugging, which will be |
| 42 |
* removed after compiling the plugin. |
| 43 |
* ----------------------------------------------------------------------------- |
| 44 |
*/ |
| 45 |
|
| 46 |
// This plugin is activated. |
| 47 |
define( 'WTITAN_PLUGIN_ACTIVE', true ); |
| 48 |
define( 'WTITAN_PLUGIN_VERSION', '7.5.2' ); |
| 49 |
define( 'WTITAN_PLUGIN_DIR', __DIR__ ); |
| 50 |
define( 'WTITAN_PLUGIN_BASE', plugin_basename( __FILE__ ) ); |
| 51 |
define( 'WTITAN_PLUGIN_URL', plugins_url( '', __FILE__ ) ); |
| 52 |
define( 'WTITAN_PLUGIN_FILE', __FILE__ ); |
| 53 |
define( 'WTITAN_PLUGIN_SLUG', basename( dirname( WTITAN_PLUGIN_FILE ) ) ); |
| 54 |
define( 'WTITAN_PLUGIN_NAMESPACE', str_replace( '-', '_', strtolower( trim( WTITAN_PLUGIN_SLUG ) ) ) ); |
| 55 |
define( 'WTITAN_UPGRADE', 'https://titansitescanner.com/upgrade' ); |
| 56 |
define( |
| 57 |
'WTITAN_COMPATIBILITY', |
| 58 |
[ |
| 59 |
'sdk' => true, |
| 60 |
] |
| 61 |
); |
| 62 |
|
| 63 |
if ( ! defined( 'WTITAN_PLUGIN_API' ) ) { |
| 64 |
define( 'WTITAN_PLUGIN_API', 'https://api.titansitescanner.com/api/v2/' ); |
| 65 |
} |
| 66 |
|
| 67 |
// START: Related to premium version compatibility check for Titan Security Pro. |
| 68 |
add_action( |
| 69 |
'plugins_loaded', |
| 70 |
function () { |
| 71 |
$premium_plugin_file = 'wp-plugin-titan-premium/titan-premium.php'; |
| 72 |
$premium_plugin_path = WP_PLUGIN_DIR . '/' . $premium_plugin_file; |
| 73 |
|
| 74 |
if ( ! file_exists( $premium_plugin_path ) ) { |
| 75 |
return; |
| 76 |
} |
| 77 |
|
| 78 |
if ( ! function_exists( 'is_plugin_active' ) ) { |
| 79 |
require_once ABSPATH . 'wp-admin/includes/plugin.php'; |
| 80 |
} |
| 81 |
|
| 82 |
if ( ! is_plugin_active( $premium_plugin_file ) ) { |
| 83 |
return; |
| 84 |
} |
| 85 |
|
| 86 |
if ( ! defined( 'WTITANP_COMPATIBILITY' ) ) { |
| 87 |
deactivate_plugins( $premium_plugin_file ); |
| 88 |
set_transient( 'wtitan_premium_version_incompatible', true, WEEK_IN_SECONDS ); |
| 89 |
} |
| 90 |
}, |
| 91 |
5 |
| 92 |
); |
| 93 |
|
| 94 |
add_action( |
| 95 |
'admin_init', |
| 96 |
function () { |
| 97 |
if ( isset( $_GET['wtitan_dismiss_premium_notice'] ) && check_admin_referer( 'wtitan_dismiss_premium_notice' ) ) { |
| 98 |
delete_transient( 'wtitan_premium_version_incompatible' ); |
| 99 |
wp_safe_redirect( remove_query_arg( 'wtitan_dismiss_premium_notice' ) ); |
| 100 |
exit; |
| 101 |
} |
| 102 |
} |
| 103 |
); |
| 104 |
|
| 105 |
add_action( |
| 106 |
'admin_notices', |
| 107 |
function () { |
| 108 |
if ( get_transient( 'wtitan_premium_version_incompatible' ) ) { |
| 109 |
$dismiss_url = wp_nonce_url( |
| 110 |
add_query_arg( 'wtitan_dismiss_premium_notice', '1' ), |
| 111 |
'wtitan_dismiss_premium_notice' |
| 112 |
); |
| 113 |
?> |
| 114 |
<div class="notice notice-error"> |
| 115 |
<p> |
| 116 |
<strong><?php esc_html_e( 'Titan Anti-spam & Security Pro has been deactivated.', 'anti-spam' ); ?></strong> |
| 117 |
</p> |
| 118 |
<p> |
| 119 |
<?php esc_html_e( 'The installed premium version is not compatible with the current version of Titan Anti-spam & Security. Please update the premium plugin to the latest version.', 'anti-spam' ); ?> |
| 120 |
</p> |
| 121 |
<p> |
| 122 |
<a href="<?php echo esc_url( $dismiss_url ); ?>" class="button button-secondary"> |
| 123 |
<?php esc_html_e( 'Dismiss', 'anti-spam' ); ?> |
| 124 |
</a> |
| 125 |
</p> |
| 126 |
</div> |
| 127 |
<?php |
| 128 |
} |
| 129 |
} |
| 130 |
); |
| 131 |
// END: Related to premium version compatibility check for Titan Security Pro. |
| 132 |
|
| 133 |
add_action( |
| 134 |
'plugins_loaded', |
| 135 |
function () { |
| 136 |
load_plugin_textdomain( 'anti-spam', false, dirname( plugin_basename( __FILE__ ) ) . '/languages' ); |
| 137 |
} |
| 138 |
); |
| 139 |
|
| 140 |
require_once WTITAN_PLUGIN_DIR . '/admin/class-activation.php'; |
| 141 |
register_activation_hook( __FILE__, [ 'WBCR\Titan\Activation', 'activate' ] ); |
| 142 |
register_deactivation_hook( __FILE__, [ 'WBCR\Titan\Activation', 'deactivate' ] ); |
| 143 |
|
| 144 |
add_filter( WTITAN_PLUGIN_NAMESPACE . '_about_us_metadata', 'titan_sdk_about_page' ); |
| 145 |
|
| 146 |
/** |
| 147 |
* About page metadata |
| 148 |
* |
| 149 |
* @return array<string, mixed> |
| 150 |
*/ |
| 151 |
function titan_sdk_about_page() { |
| 152 |
$upgrade_url = 'https://titansitescanner.com/upgrade'; |
| 153 |
|
| 154 |
if ( function_exists( 'tsdk_utmify' ) ) { |
| 155 |
$upgrade_url = tsdk_utmify( $upgrade_url, 'admin-menu', 'upgrade' ); |
| 156 |
} |
| 157 |
|
| 158 |
return [ |
| 159 |
'location' => 'titan-security', |
| 160 |
'logo' => WTITAN_PLUGIN_URL . '/admin/assets/img/logo.svg', |
| 161 |
'review_link' => false, |
| 162 |
'has_upgrade_menu' => ! defined( 'WTITANP_PLUGIN_VERSION' ), |
| 163 |
'upgrade_link' => $upgrade_url, |
| 164 |
'upgrade_text' => __( 'Upgrade to Pro', 'anti-spam' ), |
| 165 |
]; |
| 166 |
} |
| 167 |
|
| 168 |
/** |
| 169 |
* Register compatibility using SDK. |
| 170 |
* |
| 171 |
* @param array<string, array<string, string>> $compatibilities All compatibilities. |
| 172 |
* |
| 173 |
* @return array<string, array<string, string>> Registered compatibility. |
| 174 |
*/ |
| 175 |
function titan_sdk_register_compatibility( $compatibilities ) { |
| 176 |
$compatibilities['TitanPro'] = [ |
| 177 |
'basefile' => defined( 'WTITANP_PLUGIN_FILE' ) ? WTITANP_PLUGIN_FILE : '', |
| 178 |
'required' => '1.6.0', |
| 179 |
]; |
| 180 |
|
| 181 |
return $compatibilities; |
| 182 |
} |
| 183 |
|
| 184 |
add_filter( 'themeisle_sdk_compatibilities/' . basename( WTITAN_PLUGIN_DIR ), 'titan_sdk_register_compatibility' ); |
| 185 |
|
| 186 |
/** |
| 187 |
* ----------------------------------------------------------------------------- |
| 188 |
* PLUGIN INIT |
| 189 |
* ----------------------------------------------------------------------------- |
| 190 |
*/ |
| 191 |
require_once WTITAN_PLUGIN_DIR . '/includes/class-http.php'; |
| 192 |
require_once WTITAN_PLUGIN_DIR . '/includes/antispam/functions.php'; |
| 193 |
require_once WTITAN_PLUGIN_DIR . '/includes/helpers.php'; |
| 194 |
require_once WTITAN_PLUGIN_DIR . '/includes/class-titan-security-plugin.php'; |
| 195 |
|
| 196 |
try { |
| 197 |
require_once WTITAN_PLUGIN_DIR . '/vendor/autoload.php'; |
| 198 |
new \WBCR\Titan\Plugin(); |
| 199 |
|
| 200 |
require_once WTITAN_PLUGIN_DIR . '/includes/functions.php'; |
| 201 |
|
| 202 |
// Initialize frontend spam protection. |
| 203 |
add_action( |
| 204 |
'init', |
| 205 |
function () { |
| 206 |
new \WBCR\Titan\Antispam\Protector(); |
| 207 |
new \WBCR\Titan\Antispam\Advanced_Spam_Filter(); |
| 208 |
} |
| 209 |
); |
| 210 |
} catch ( Exception $e ) { |
| 211 |
// Plugin wasn't initialized due to an error. |
| 212 |
define( 'WTITAN_PLUGIN_THROW_ERROR', true ); |
| 213 |
|
| 214 |
$wtitan_plugin_error_func = function () use ( $e ) { |
| 215 |
$error = sprintf( 'Titan Security plugin has stopped. <b>Error:</b> %s Code: %s', $e->getMessage(), $e->getCode() ); |
| 216 |
echo '<div class="notice notice-error"><p>' . esc_html( $error ) . '</p></div>'; |
| 217 |
}; |
| 218 |
|
| 219 |
add_action( 'admin_notices', $wtitan_plugin_error_func ); |
| 220 |
add_action( 'network_admin_notices', $wtitan_plugin_error_func ); |
| 221 |
} |
| 222 |
|