PluginProbe
CryptX / 4.0.2
CryptX v4.0.2
4.2.0 4.1.1 trunk 1.0 1.1 1.2 1.3 1.4 1.5 1.6 1.7 1.9 2.0 2.1 2.2 2.3 2.3.1 2.3.2 2.3.3 2.4.0 2.4.1 2.4.2 2.4.3 2.4.4 2.4.5 All 92 releases
cryptx / cryptx.php

cryptx.php in CryptX 4.0.2, at cryptx.php

184 lines 6.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: CryptX
4 * Plugin URI: https://wordpress.org/plugins/cryptx/
5 * Description: CryptX encrypts email addresses in your posts, pages, comments, and text widgets to protect them from spam bots while keeping them readable for your visitors.
6 * Version: 4.0.2
7 * Requires at least: 6.7
8 * Tested up to: 6.8
9 * Requires PHP: 8.1
10 * Author: Ralf Weber
11 * Author URI: https://weber-nrw.de/
12 * License: GPL v2 or later
13 * License URI: https://www.gnu.org/licenses/gpl-2.0.html
14 * Text Domain: cryptx
15 * Domain Path: /languages
16 * Network: false
17 * Update URI: https://wordpress.org/plugins/cryptx/
18 *
19 * CryptX is free software: you can redistribute it and/or modify
20 * it under the terms of the GNU General Public License as published by
21 * the Free Software Foundation, either version 2 of the License, or
22 * any later version.
23 *
24 * CryptX is distributed in the hope that it will be useful,
25 * but WITHOUT ANY WARRANTY; without even the implied warranty of
26 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
27 * GNU General Public License for more details.
28 *
29 * You should have received a copy of the GNU General Public License
30 * along with CryptX. If not, see https://www.gnu.org/licenses/gpl-2.0.html.
31 *
32 * @package CryptX
33 * @since 1.0.0
34 */
35
36 // Prevent direct access
37 if (!defined('ABSPATH')) {
38 exit;
39 }
40
41 // Plugin constants
42 define('CRYPTX_VERSION', '4.0.1');
43 define('CRYPTX_PLUGIN_FILE', __FILE__);
44 define('CRYPTX_PLUGIN_BASENAME', plugin_basename(__FILE__));
45 define('CRYPTX_BASENAME', plugin_basename(__FILE__)); // Add this missing constant
46 define('CRYPTX_DIR_PATH', plugin_dir_path(__FILE__));
47 define('CRYPTX_DIR_URL', plugin_dir_url(__FILE__));
48 define('CRYPTX_BASEFOLDER', dirname(CRYPTX_PLUGIN_BASENAME));
49
50 // Minimum requirements check
51 if (version_compare(PHP_VERSION, '8.1.0', '<')) {
52 add_action('admin_notices', function() {
53 echo '<div class="notice notice-error"><p>';
54 printf(
55 /* translators: %1$s: Required PHP version, %2$s: Current PHP version */
56 __('CryptX requires PHP version %1$s or higher. You are running version %2$s. Please update PHP.', 'cryptx'),
57 '8.1.0',
58 PHP_VERSION
59 );
60 echo '</p></div>';
61 });
62 return;
63 }
64
65 // WordPress version check
66 global $wp_version;
67 if (version_compare($wp_version, '6.7', '<')) {
68 add_action('admin_notices', function() {
69 echo '<div class="notice notice-error"><p>';
70 printf(
71 /* translators: %1$s: Required WordPress version, %2$s: Current WordPress version */
72 __('CryptX requires WordPress version %1$s or higher. You are running version %2$s. Please update WordPress.', 'cryptx'),
73 '5.0',
74 $GLOBALS['wp_version']
75 );
76 echo '</p></div>';
77 });
78 return;
79 }
80
81 // Autoloader for plugin classes
82 spl_autoload_register(function ($class) {
83 // Check if the class belongs to our namespace
84 if (strpos($class, 'CryptX\\') !== 0) {
85 return;
86 }
87
88 // Remove namespace prefix
89 $class = substr($class, 7);
90
91 // Convert namespace separators to directory separators
92 $class = str_replace('\\', DIRECTORY_SEPARATOR, $class);
93
94 // Build the full path
95 $file = CRYPTX_DIR_PATH . 'classes' . DIRECTORY_SEPARATOR . $class . '.php';
96
97 // Include the file if it exists
98 if (file_exists($file)) {
99 require_once $file;
100 }
101 });
102
103 // Initialize the plugin
104 add_action('plugins_loaded', function() {
105 // Check if all required classes can be loaded
106 $requiredClasses = [
107 'CryptX\\CryptX',
108 'CryptX\\Config',
109 'CryptX\\CryptXSettingsTabs',
110 'CryptX\\SecureEncryption',
111 'CryptX\\Admin\\ChangelogSettingsTab',
112 'CryptX\\Admin\\GeneralSettingsTab',
113 'CryptX\\Admin\\PresentationSettingsTab',
114 'CryptX\\Util\\DataSanitizer',
115 ];
116
117 $missingClasses = [];
118 foreach ($requiredClasses as $class) {
119 if (!class_exists($class)) {
120 $missingClasses[] = $class;
121 }
122 }
123
124 if (!empty($missingClasses)) {
125 add_action('admin_notices', function() use ($missingClasses) {
126 echo '<div class="notice notice-error"><p>';
127 echo esc_html__('CryptX: Missing required classes: ', 'cryptx') . implode(', ', $missingClasses);
128 echo '</p></div>';
129 });
130 return;
131 }
132
133 // Initialize the main plugin class
134 try {
135 $cryptx_instance = CryptX\CryptX::get_instance();
136 $cryptx_instance->startCryptX();
137 } catch (Exception $e) {
138 add_action('admin_notices', function() use ($e) {
139 echo '<div class="notice notice-error"><p>';
140 echo esc_html__('CryptX initialization failed: ', 'cryptx') . esc_html($e->getMessage());
141 echo '</p></div>';
142 });
143 }
144 });
145
146 // Remove the strict activation requirements - let the plugin handle fallbacks
147 register_activation_hook(__FILE__, function() {
148 // Just flush rewrite rules
149 flush_rewrite_rules();
150 });
151
152 // Plugin deactivation hook
153 register_deactivation_hook(__FILE__, function() {
154 // Clean up any transients or cached data
155 global $wpdb;
156 $wpdb->query("DELETE FROM {$wpdb->options} WHERE option_name LIKE '_transient_cryptx_%'");
157 $wpdb->query("DELETE FROM {$wpdb->options} WHERE option_name LIKE '_transient_timeout_cryptx_%'");
158 });
159
160 // Add plugin action links - updated to match the settings page slug
161 add_filter('plugin_action_links_' . plugin_basename(__FILE__), function($links) {
162 $settings_link = '<a href="' . admin_url('options-general.php?page=cryptx') . '">' .
163 esc_html__('Settings', 'cryptx') . '</a>';
164 array_unshift($links, $settings_link);
165 return $links;
166 });
167
168 /**
169 * Encrypts the given content using the CryptX library and wraps it with a shortcode.
170 *
171 * @param string $content The content to be encrypted.
172 * @param array|null $args Optional arguments to customize the encryption process.
173 *
174 * @return string The encrypted content wrapped in the appropriate shortcode.
175 */
176 if (!function_exists('encryptx')) {
177 function encryptx(string $content, ?array $args = []): string {
178 $cryptXInstance = Cryptx\CryptX::get_instance();
179 $attributesString = $cryptXInstance->convertArrayToArgumentString($args);
180 $shortcode = '[cryptx' . $attributesString . ']' . $content . '[/cryptx]';
181
182 return do_shortcode($shortcode);
183 }
184 }