PluginProbe
ThinkRank AI SEO – AI SEO Plugin for WordPress: Schema, XML Sitemaps, Meta Tags, Search Console & Local SEO / 1.10.0
ThinkRank AI SEO – AI SEO Plugin for WordPress: Schema, XML Sitemaps, Meta Tags, Search Console & Local SEO v1.10.0
2.7.0 2.6.0 2.5.0 2.4.0 2.3.0 2.2.0 2.1.1 2.1.0 2.0.2 2.0.1 2.0.0 1.32.0 1.31.0 1.30.0 1.29.0 1.28.0 1.27.0 1.26.0 1.25.0 trunk 1.0.0 1.0.1 1.0.2 1.1.0 1.10.0 All 48 releases
thinkrank / thinkrank.php

thinkrank.php in ThinkRank AI SEO – AI SEO Plugin for WordPress: Schema, XML Sitemaps, Meta Tags, Search Console & Local SEO 1.10.0, at thinkrank.php

297 lines 7.3 KB
No matching file
Up and down to move Enter to open Esc to close
Raw Download Zip
1 <?php
2
3 /**
4 * Plugin Name: ThinkRank
5 * Plugin URI: https://thinkrank.ai/wordpress-plugin
6 * Description: AI-native SEO plugin for WordPress. Automate and enhance your SEO with cutting-edge AI while maintaining editorial control.
7 * Version: 1.10.0
8 * Author: rupok
9 * Author URI: https://thinkrank.ai
10 * License: GPL v2 or later
11 * License URI: https://www.gnu.org/licenses/gpl-2.0.html
12 * Text Domain: thinkrank
13 * Domain Path: /languages
14 * Requires at least: 6.0
15 * Tested up to: 6.9
16 * Requires PHP: 8.0
17 *
18 * @package ThinkRank
19 * @version 1.10.0
20 * @since 1.0.0
21 */
22
23 declare(strict_types=1);
24
25 // Prevent direct access
26 if (!defined('ABSPATH')) {
27 exit;
28 }
29
30 // Define plugin constants
31 define('THINKRANK_VERSION', '1.10.0');
32 define('THINKRANK_PLUGIN_FILE', __FILE__);
33 define('THINKRANK_PLUGIN_DIR', plugin_dir_path(__FILE__));
34 define('THINKRANK_PLUGIN_URL', plugin_dir_url(__FILE__));
35 define('THINKRANK_PLUGIN_BASENAME', plugin_basename(__FILE__));
36
37 // Minimum requirements check
38 if (version_compare(PHP_VERSION, '8.0', '<')) {
39 add_action('admin_notices', function () {
40 echo '<div class="notice notice-error"><p>';
41 echo esc_html__('ThinkRank requires PHP 8.0 or higher. Please upgrade your PHP version.', 'thinkrank');
42 echo '</p></div>';
43 });
44 return;
45 }
46
47 if (version_compare(get_bloginfo('version'), '6.0', '<')) {
48 add_action('admin_notices', function () {
49 echo '<div class="notice notice-error"><p>';
50 echo esc_html__('ThinkRank requires WordPress 6.0 or higher. Please upgrade your WordPress installation.', 'thinkrank');
51 echo '</p></div>';
52 });
53 return;
54 }
55
56 // Autoloader
57 require_once THINKRANK_PLUGIN_DIR . 'includes/class-autoloader.php';
58
59 /**
60 * Main ThinkRank Plugin Class
61 *
62 * Follows Single Responsibility Principle - only handles plugin initialization
63 *
64 * @since 1.0.0
65 */
66 final class ThinkRank {
67
68 /**
69 * Plugin instance (Singleton Pattern)
70 *
71 * @var ThinkRank|null
72 */
73 private static ?ThinkRank $instance = null;
74
75 /**
76 * Plugin components
77 *
78 * @var array
79 */
80 private array $components = [];
81
82 /**
83 * Get plugin instance (Singleton Pattern)
84 *
85 * @return ThinkRank
86 */
87 public static function get_instance(): ThinkRank {
88 if (null === self::$instance) {
89 self::$instance = new self();
90 }
91 return self::$instance;
92 }
93
94 /**
95 * Private constructor to prevent direct instantiation
96 */
97 private function __construct() {
98 $this->init_autoloader();
99 $this->init_hooks();
100 }
101
102 /**
103 * Prevent cloning
104 */
105 private function __clone() {
106 }
107
108 /**
109 * Prevent unserialization
110 */
111 public function __wakeup() {
112 throw new \Exception('Cannot unserialize singleton');
113 }
114
115 /**
116 * Initialize autoloader
117 *
118 * @return void
119 */
120 private function init_autoloader(): void {
121 ThinkRank\Core\Autoloader::register();
122 }
123
124 /**
125 * Initialize WordPress hooks
126 *
127 * @return void
128 */
129 private function init_hooks(): void {
130 register_activation_hook(__FILE__, [$this, 'activate']);
131 register_deactivation_hook(__FILE__, [$this, 'deactivate']);
132
133 add_action('plugins_loaded', [$this, 'init']);
134 }
135
136 /**
137 * Initialize plugin components
138 *
139 * @return void
140 */
141 public function init(): void {
142 try {
143 $this->load_components();
144 $this->init_components();
145 $this->load_template_functions();
146
147 do_action('thinkrank_loaded');
148 } catch (\Exception $e) {
149 $this->handle_error($e);
150 }
151 }
152
153 /**
154 * Load plugin components (Dependency Injection Container pattern)
155 *
156 * @return void
157 */
158 private function load_components(): void {
159 $this->components = [
160 'database' => new ThinkRank\Core\Database(),
161 'settings' => new ThinkRank\Core\Settings(),
162 'security_headers' => new ThinkRank\Core\Security_Headers(),
163 'asset_optimizer' => new ThinkRank\Core\Asset_Optimizer(),
164 'api' => new ThinkRank\API\Manager(),
165 'admin' => new ThinkRank\Admin\Manager(),
166 'ai' => new ThinkRank\AI\Manager(),
167 'frontend_seo' => new ThinkRank\Frontend\SEO_Manager(),
168 'seo_notice' => new ThinkRank\Admin\SEO_Notice(),
169 'integrations' => new ThinkRank\Integrations\Manager(),
170 'performance_collector' => new ThinkRank\SEO\Performance_Data_Collector(),
171 'instant_indexing' => new ThinkRank\SEO\Instant_Indexing_Manager(),
172 'author_archives' => new ThinkRank\SEO\Author_Archives_Manager(),
173 ];
174 }
175
176 /**
177 * Initialize all components
178 *
179 * @return void
180 */
181 private function init_components(): void {
182 foreach ($this->components as $component) {
183 if (method_exists($component, 'init')) {
184 $component->init();
185 }
186 }
187 }
188
189 /**
190 * Load template functions for themes
191 *
192 * @return void
193 */
194 private function load_template_functions(): void {
195 require_once THINKRANK_PLUGIN_DIR . 'includes/frontend/template-functions.php';
196 }
197
198 /**
199 * Get component instance
200 *
201 * @param string $component Component name
202 * @return object|null
203 */
204 public function get_component(string $component): ?object {
205 return $this->components[$component] ?? null;
206 }
207
208 /**
209 * Plugin activation
210 *
211 * @return void
212 */
213 public function activate(): void {
214 try {
215 $activator = new ThinkRank\Core\Activator();
216 $activator->activate();
217
218 // Flush rewrite rules
219 flush_rewrite_rules();
220 } catch (\Exception $e) {
221 $this->handle_error($e);
222 wp_die(
223 esc_html__('ThinkRank activation failed. Please check your server logs.', 'thinkrank'),
224 esc_html__('Plugin Activation Error', 'thinkrank'),
225 ['back_link' => true]
226 );
227 }
228 }
229
230 /**
231 * Plugin deactivation
232 *
233 * @return void
234 */
235 public function deactivate(): void {
236 try {
237 $deactivator = new ThinkRank\Core\Deactivator();
238 $deactivator->deactivate();
239
240 // Flush rewrite rules
241 flush_rewrite_rules();
242 } catch (\Exception $e) {
243 $this->handle_error($e);
244 }
245 }
246
247 /**
248 * Handle errors consistently
249 *
250 * @param \Exception $e Exception to handle
251 * @return void
252 */
253 private function handle_error(\Exception $e): void {
254 // Error handling without debug output
255 error_log($e->getMessage());
256 }
257
258 /**
259 * Get plugin version
260 *
261 * @return string
262 */
263 public function get_version(): string {
264 return THINKRANK_VERSION;
265 }
266
267 /**
268 * Get plugin directory path
269 *
270 * @return string
271 */
272 public function get_plugin_dir(): string {
273 return THINKRANK_PLUGIN_DIR;
274 }
275
276 /**
277 * Get plugin URL
278 *
279 * @return string
280 */
281 public function get_plugin_url(): string {
282 return THINKRANK_PLUGIN_URL;
283 }
284 }
285
286 /**
287 * Initialize the plugin
288 *
289 * @return ThinkRank
290 */
291 function thinkrank(): ThinkRank {
292 return ThinkRank::get_instance();
293 }
294
295 // Start the plugin
296 thinkrank();
297