PluginProbe
ThinkRank AI SEO – AI SEO Plugin for WordPress: Schema, XML Sitemaps, Meta Tags, Search Console & Local SEO / 1.0.1
ThinkRank AI SEO – AI SEO Plugin for WordPress: Schema, XML Sitemaps, Meta Tags, Search Console & Local SEO v1.0.1
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.0.1, at thinkrank.php

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