Diff: STRATO-apps/wordpress_03/app/wp-content/plugins/seo-by-rank-math/rank-math.php
Keine Baseline-Datei – Diff nur gegen leer.
1
-
1
+
<?php // @codingStandardsIgnoreLine
2
+
/**
3
+
* Rank Math SEO Plugin.
4
+
*
5
+
* @package RANK_MATH
6
+
* @copyright Copyright (C) 2019-2023, Rank Math - support@rankmath.com
7
+
* @link https://rankmath.com
8
+
* @since 0.9.0
9
+
*
10
+
* @wordpress-plugin
11
+
* Plugin Name: Rank Math SEO
12
+
* Version: 1.0.263
13
+
* Plugin URI: https://rankmath.com/
14
+
* Description: Rank Math SEO is the Best WordPress SEO plugin with the features of many SEO and AI SEO tools in a single package to help multiply your SEO traffic.
15
+
* Author: Rank Math SEO
16
+
* Author URI: https://rankmath.com/?utm_source=Plugin&utm_medium=Readme%20Author%20URI&utm_campaign=WP
17
+
* License: GPL-3.0+
18
+
* License URI: https://www.gnu.org/licenses/gpl-3.0.txt
19
+
* Text Domain: rank-math
20
+
* Domain Path: /languages
21
+
*/
22
+
23
+
defined( 'ABSPATH' ) || exit;
24
+
25
+
/**
26
+
* RankMath class.
27
+
*
28
+
* @class Main class of the plugin.
29
+
*/
30
+
final class RankMath {
31
+
32
+
/**
33
+
* Plugin version.
34
+
*
35
+
* @var string
36
+
*/
37
+
public $version = '1.0.263';
38
+
39
+
/**
40
+
* Rank Math database version.
41
+
*
42
+
* @var string
43
+
*/
44
+
public $db_version = '1';
45
+
46
+
/**
47
+
* Minimum version of WordPress required to run Rank Math.
48
+
*
49
+
* @var string
50
+
*/
51
+
private $wordpress_version = '6.3';
52
+
53
+
/**
54
+
* Minimum version of PHP required to run Rank Math.
55
+
*
56
+
* @var string
57
+
*/
58
+
private $php_version = '7.4';
59
+
60
+
/**
61
+
* Holds various class instances.
62
+
*
63
+
* @var array
64
+
*/
65
+
private $container = [];
66
+
67
+
/**
68
+
* Hold install error messages.
69
+
*
70
+
* @var array
71
+
*/
72
+
private $messages = [];
73
+
74
+
/**
75
+
* The single instance of the class.
76
+
*
77
+
* @var RankMath
78
+
*/
79
+
protected static $instance = null;
80
+
81
+
/**
82
+
* Magic isset to bypass referencing plugin.
83
+
*
84
+
* @param string $prop Property to check.
85
+
* @return bool
86
+
*/
87
+
public function __isset( $prop ) {
88
+
return isset( $this->{$prop} ) || isset( $this->container[ $prop ] );
89
+
}
90
+
91
+
/**
92
+
* Magic getter method.
93
+
*
94
+
* @param string $prop Property to get.
95
+
* @return mixed Property value or NULL if it does not exists.
96
+
*/
97
+
public function __get( $prop ) {
98
+
if ( array_key_exists( $prop, $this->container ) ) {
99
+
return $this->container[ $prop ];
100
+
}
101
+
102
+
if ( isset( $this->{$prop} ) ) {
103
+
return $this->{$prop};
104
+
}
105
+
106
+
return null;
107
+
}
108
+
109
+
/**
110
+
* Magic setter method.
111
+
*
112
+
* @param mixed $prop Property to set.
113
+
* @param mixed $value Value to set.
114
+
*/
115
+
public function __set( $prop, $value ) {
116
+
if ( property_exists( $this, $prop ) ) {
117
+
$this->$prop = $value;
118
+
return;
119
+
}
120
+
121
+
$this->container[ $prop ] = $value;
122
+
}
123
+
124
+
/**
125
+
* Magic call method.
126
+
*
127
+
* @param string $name Method to call.
128
+
* @param array $arguments Arguments to pass when calling.
129
+
* @return mixed Return value of the callback.
130
+
*/
131
+
public function __call( $name, $arguments ) {
132
+
$hash = [
133
+
'plugin_dir' => RANK_MATH_PATH,
134
+
'plugin_url' => RANK_MATH_URL,
135
+
'includes_dir' => RANK_MATH_PATH . 'includes/',
136
+
'assets' => RANK_MATH_URL . 'assets/front/',
137
+
'admin_dir' => RANK_MATH_PATH . 'includes/admin/',
138
+
];
139
+
140
+
if ( isset( $hash[ $name ] ) ) {
141
+
return $hash[ $name ];
142
+
}
143
+
144
+
return call_user_func_array( $name, $arguments );
145
+
}
146
+
147
+
/**
148
+
* Initialize.
149
+
*/
150
+
public function init() {
151
+
}
152
+
153
+
/**
154
+
* Retrieve main RankMath instance.
155
+
*
156
+
* Ensure only one instance is loaded or can be loaded.
157
+
*
158
+
* @see rank_math()
159
+
* @return RankMath
160
+
*/
161
+
public static function get() {
162
+
if ( is_null( self::$instance ) && ! ( self::$instance instanceof RankMath ) ) {
163
+
self::$instance = new RankMath();
164
+
self::$instance->setup();
165
+
}
166
+
167
+
return self::$instance;
168
+
}
169
+
170
+
/**
171
+
* Instantiate the plugin.
172
+
*/
173
+
private function setup() {
174
+
// Define plugin constants.
175
+
$this->define_constants();
176
+
177
+
if ( ! $this->is_requirements_meet() ) {
178
+
return;
179
+
}
180
+
181
+
// Include required files.
182
+
$this->includes();
183
+
184
+
// Instantiate classes.
185
+
$this->instantiate();
186
+
187
+
// Loaded action.
188
+
do_action( 'rank_math/loaded' );
189
+
}
190
+
191
+
/**
192
+
* Check that the WordPress and PHP setup meets the plugin requirements.
193
+
*
194
+
* @return bool
195
+
*/
196
+
private function is_requirements_meet() {
197
+
198
+
// Check WordPress version.
199
+
if ( version_compare( get_bloginfo( 'version' ), $this->wordpress_version, '<' ) ) {
200
+
/* translators: WordPress Version */
201
+
$this->messages[] = sprintf( esc_html__( 'You are using the outdated WordPress, please update it to version %s or higher.', 'rank-math' ), $this->wordpress_version );
202
+
}
203
+
204
+
// Check PHP version.
205
+
if ( version_compare( phpversion(), $this->php_version, '<' ) ) {
206
+
/* translators: PHP Version */
207
+
$this->messages[] = sprintf( esc_html__( 'Rank Math requires PHP version %s or above. Please update PHP to run this plugin.', 'rank-math' ), $this->php_version );
208
+
}
209
+
210
+
if ( empty( $this->messages ) ) {
211
+
return true;
212
+
}
213
+
214
+
// Auto-deactivate plugin.
215
+
add_action( 'admin_init', [ $this, 'auto_deactivate' ] );
216
+
add_action( 'admin_notices', [ $this, 'activation_error' ] );
217
+
218
+
return false;
219
+
}
220
+
221
+
/**
222
+
* Auto-deactivate plugin if requirements are not met, and display a notice.
223
+
*/
224
+
public function auto_deactivate() {
225
+
deactivate_plugins( plugin_basename( RANK_MATH_FILE ) );
226
+
if ( isset( $_GET['activate'] ) ) { // phpcs:ignore
227
+
unset( $_GET['activate'] ); // phpcs:ignore
228
+
}
229
+
}
230
+
231
+
/**
232
+
* Error notice on plugin activation.
233
+
*/
234
+
public function activation_error() {
235
+
?>
236
+
<div class="notice rank-math-notice notice-error">
237
+
<p>
238
+
<?php echo join( '<br>', $this->messages ); // phpcs:ignore ?>
239
+
</p>
240
+
</div>
241
+
<?php
242
+
}
243
+
244
+
/**
245
+
* Define the plugin constants.
246
+
*/
247
+
private function define_constants() {
248
+
define( 'RANK_MATH_VERSION', $this->version );
249
+
define( 'RANK_MATH_FILE', __FILE__ );
250
+
define( 'RANK_MATH_PATH', dirname( RANK_MATH_FILE ) . '/' );
251
+
define( 'RANK_MATH_URL', plugins_url( '', RANK_MATH_FILE ) . '/' );
252
+
define( 'RANK_MATH_SITE_URL', 'https://rankmath.com' );
253
+
if ( ! defined( 'CONTENT_AI_URL' ) ) {
254
+
define( 'CONTENT_AI_URL', 'https://cai.rankmath.com' );
255
+
}
256
+
}
257
+
258
+
/**
259
+
* Include the required files.
260
+
*/
261
+
private function includes() {
262
+
include __DIR__ . '/vendor/autoload.php';
263
+
264
+
// For Theme Developers:
265
+
// theme-folder/rankmath.php will be loaded automatically.
266
+
$file = get_stylesheet_directory() . '/rank-math.php';
267
+
if ( file_exists( $file ) ) {
268
+
require_once $file;
269
+
}
270
+
}
271
+
272
+
/**
273
+
* Instantiate classes.
274
+
*/
275
+
private function instantiate() {
276
+
new \RankMath\Installer();
277
+
278
+
// Setting Manager.
279
+
$this->container['settings'] = new \RankMath\Settings();
280
+
281
+
// JSON Manager.
282
+
$this->container['json'] = new \RankMath\Json_Manager();
283
+
284
+
// Notification Manager.
285
+
$this->container['notification'] = new \RankMath\Admin\Notifications\Notification_Center( 'rank_math_notifications' );
286
+
287
+
// Product Registration.
288
+
$this->container['registration'] = new \RankMath\Admin\Registration();
289
+
if ( $this->container['registration']->invalid ) {
290
+
return;
291
+
}
292
+
293
+
$this->container['manager'] = new \RankMath\Module\Manager();
294
+
$this->container['variables'] = new \RankMath\Replace_Variables\Manager();
295
+
296
+
// Just init without storing it in the container.
297
+
new \RankMath\Common();
298
+
$this->container['rewrite'] = new \RankMath\Rewrite();
299
+
new \RankMath\Compatibility();
300
+
$this->container['tracking'] = new \RankMath\Tracking();
301
+
302
+
// Frontend SEO Score.
303
+
$this->container['frontend_seo_score'] = new \RankMath\Frontend_SEO_Score();
304
+
$this->load_3rd_party();
305
+
306
+
// Initialize the action and filter hooks.
307
+
$this->init_actions();
308
+
}
309
+
310
+
/**
311
+
* Initialize WordPress action and filter hooks.
312
+
*/
313
+
private function init_actions() {
314
+
// Make sure it is loaded before setup_modules and load_modules.
315
+
add_action( 'after_setup_theme', [ $this, 'localization_setup' ], 1 );
316
+
add_action( 'init', [ $this, 'pass_admin_content' ] );
317
+
318
+
// Add plugin action links.
319
+
add_filter( 'plugin_row_meta', [ $this, 'plugin_row_meta' ], 10, 2 );
320
+
add_filter( 'plugin_action_links_' . plugin_basename( RANK_MATH_FILE ), [ $this, 'plugin_action_links' ] );
321
+
add_action( 'after_plugin_row_' . plugin_basename( RANK_MATH_FILE ), [ $this, 'plugin_row_deactivate_notice' ] );
322
+
323
+
// Booting.
324
+
add_action( 'plugins_loaded', [ $this, 'init' ], 14 );
325
+
add_action( 'rest_api_init', [ $this, 'init_rest_api' ] );
326
+
327
+
// Load admin-related functionality.
328
+
if ( is_admin() ) {
329
+
add_action( 'plugins_loaded', [ $this, 'init_admin' ], 15 );
330
+
}
331
+
332
+
// Frontend-only functionality.
333
+
if ( ! is_admin() || in_array( \RankMath\Helpers\Param::request( 'action' ), [ 'elementor', 'elementor_ajax' ], true ) ) {
334
+
add_action( 'plugins_loaded', [ $this, 'init_frontend' ], 15 );
335
+
}
336
+
337
+
// WP_CLI.
338
+
if ( defined( 'WP_CLI' ) && WP_CLI ) {
339
+
add_action( 'plugins_loaded', [ $this, 'init_wp_cli' ], 20 );
340
+
}
341
+
}
342
+
343
+
/**
344
+
* Load the REST API endpoints.
345
+
*/
346
+
public function init_rest_api() {
347
+
$controllers = [
348
+
new \RankMath\Rest\Admin(),
349
+
new \RankMath\Rest\Front(),
350
+
new \RankMath\Rest\Shared(),
351
+
new \RankMath\Rest\Post(),
352
+
new \RankMath\Rest\Headless(),
353
+
new \RankMath\Rest\Setup_Wizard(),
354
+
];
355
+
356
+
foreach ( $controllers as $controller ) {
357
+
$controller->register_routes();
358
+
}
359
+
}
360
+
361
+
/**
362
+
* Initialize the admin-related functionality.
363
+
* Runs on 'plugins_loaded'.
364
+
*/
365
+
public function init_admin() {
366
+
if ( $this->container['registration']->invalid ) {
367
+
return;
368
+
}
369
+
new \RankMath\Admin\Admin_Init();
370
+
}
371
+
372
+
/**
373
+
* Initialize the frontend functionality.
374
+
* Runs on 'plugins_loaded'.
375
+
*/
376
+
public function init_frontend() {
377
+
if ( $this->container['registration']->invalid ) {
378
+
return;
379
+
}
380
+
$this->container['frontend'] = new \RankMath\Frontend\Frontend();
381
+
}
382
+
383
+
/**
384
+
* Load 3rd party modules.
385
+
*/
386
+
private function load_3rd_party() {
387
+
if ( ! function_exists( 'is_plugin_active' ) ) {
388
+
require_once ABSPATH . 'wp-admin/includes/plugin.php'; // @phpstan-ignore-line
389
+
}
390
+
391
+
// Elementor.
392
+
if ( is_plugin_active( 'elementor/elementor.php' ) ) {
393
+
new \RankMath\Elementor\Elementor();
394
+
}
395
+
396
+
// Loco Translate: initialize inline i18n injector for settings React UI.
397
+
if ( is_plugin_active( 'loco-translate/loco.php' ) ) {
398
+
new \RankMath\ThirdParty\Loco\Loco_I18n_Inline();
399
+
}
400
+
401
+
// WPML.
402
+
if ( is_plugin_active( 'sitepress-multilingual-cms/sitepress.php' ) ) {
403
+
new \RankMath\ThirdParty\WPML();
404
+
}
405
+
406
+
// Divi theme.
407
+
add_action(
408
+
'after_setup_theme',
409
+
function () {
410
+
if ( defined( 'ET_CORE' ) ) {
411
+
new \RankMath\Divi\Divi();
412
+
}
413
+
},
414
+
11
415
+
);
416
+
add_action(
417
+
'current_screen',
418
+
function () {
419
+
if ( defined( 'ET_CORE' ) ) {
420
+
new \RankMath\Divi\Divi_Admin();
421
+
}
422
+
}
423
+
);
424
+
}
425
+
426
+
/**
427
+
* Add our custom WP-CLI commands.
428
+
*/
429
+
public function init_wp_cli() {
430
+
WP_CLI::add_command( 'rankmath sitemap generate', [ '\RankMath\CLI\Commands', 'sitemap_generate' ] );
431
+
}
432
+
433
+
/**
434
+
* Show action links on the plugin screen.
435
+
*
436
+
* @param mixed $links Plugin Action links.
437
+
* @return array
438
+
*/
439
+
public function plugin_action_links( $links ) {
440
+
$options = [
441
+
'options-general' => __( 'Settings', 'rank-math' ),
442
+
'wizard' => __( 'Setup Wizard', 'rank-math' ),
443
+
];
444
+
445
+
if ( $this->container['registration']->invalid ) {
446
+
$options = [
447
+
'registration' => __( 'Setup Wizard', 'rank-math' ),
448
+
];
449
+
}
450
+
451
+
foreach ( $options as $link => $label ) {
452
+
$plugin_links[] = '<a href="' . \RankMath\Helper::get_admin_url( $link ) . '">' . esc_html( $label ) . '</a>';
453
+
}
454
+
455
+
return array_merge( $links, $plugin_links );
456
+
}
457
+
458
+
/**
459
+
* Add a notice when rank_math_clear_data_on_uninstall filter is present in the theme.
460
+
*
461
+
* @param string $file Plugin file.
462
+
*
463
+
* @return void
464
+
*/
465
+
public function plugin_row_deactivate_notice( $file ) {
466
+
if ( false === apply_filters( 'rank_math_clear_data_on_uninstall', false ) ) {
467
+
return;
468
+
}
469
+
470
+
if ( is_multisite() && ! is_network_admin() && is_plugin_active_for_network( $file ) ) {
471
+
return;
472
+
}
473
+
474
+
$wp_list_table = _get_list_table( 'WP_Plugins_List_Table' );
475
+
echo '<tr class="plugin-update-tr active rank-math-deactivate-notice-row" data-slug="" data-plugin="' . esc_attr( $file ) . '" style="position: relative; top: -1px;"><td colspan="' . esc_attr( $wp_list_table->get_column_count() ) . '" class="plugin-update colspanchange"><div class="notice inline notice-error notice-alt"><p>';
476
+
printf(
477
+
/* translators: 1. Bold text 2. Bold text */
478
+
esc_html__( '%1$s A filter to remove the Rank Math data from the database is present. Deactivating & Deleting this plugin will remove everything related to the Rank Math plugin. %2$s', 'rank-math' ),
479
+
'<strong>' . esc_html__( 'CAUTION:', 'rank-math' ) . '</strong>',
480
+
'<br /><strong>' . esc_html__( 'This action is IRREVERSIBLE.', 'rank-math' ) . '</strong>'
481
+
);
482
+
echo '</p></div></td></tr>';
483
+
}
484
+
485
+
/**
486
+
* Add extra links as row meta on the plugin screen.
487
+
*
488
+
* @param mixed $links Plugin Row Meta.
489
+
* @param mixed $file Plugin Base file.
490
+
* @return array
491
+
*/
492
+
public function plugin_row_meta( $links, $file ) {
493
+
if ( plugin_basename( RANK_MATH_FILE ) !== $file ) {
494
+
return $links;
495
+
}
496
+
497
+
$more = [
498
+
'<a href="' . admin_url( '?page=rank-math&view=help' ) . '">' . esc_html__( 'Getting Started', 'rank-math' ) . '</a>',
499
+
'<a href="' . \RankMath\KB::get( 'knowledgebase', 'Plugin Page KB Link' ) . '" target="_blank">' . esc_html__( 'Documentation', 'rank-math' ) . '</a>',
500
+
];
501
+
502
+
return array_merge( $links, $more );
503
+
}
504
+
505
+
/**
506
+
* Initialize plugin for localization.
507
+
*
508
+
* Note: the first-loaded translation file overrides any following ones if the same translation is present.
509
+
*
510
+
* Locales found in:
511
+
* - WP_LANG_DIR/rank-math/rank-math-LOCALE.mo
512
+
* - WP_LANG_DIR/plugins/rank-math-LOCALE.mo
513
+
*/
514
+
public function localization_setup() {
515
+
$locale = get_user_locale();
516
+
$locale = apply_filters( 'plugin_locale', $locale, 'rank-math' ); // phpcs:ignore
517
+
518
+
unload_textdomain( 'rank-math' );
519
+
if ( false === load_textdomain( 'rank-math', WP_LANG_DIR . '/plugins/seo-by-rank-math-' . $locale . '.mo' ) ) {
520
+
load_textdomain( 'rank-math', WP_LANG_DIR . '/seo-by-rank-math/seo-by-rank-math-' . $locale . '.mo' );
521
+
}
522
+
load_plugin_textdomain( 'rank-math', false, rank_math()->plugin_dir() . 'languages/' );
523
+
}
524
+
525
+
/**
526
+
* Localize admin content to JS
527
+
*/
528
+
public function pass_admin_content() {
529
+
if ( is_user_logged_in() && is_admin_bar_showing() ) {
530
+
$this->container['json']->add( 'version', $this->version, 'rankMath' );
531
+
$this->container['json']->add( 'ajaxurl', admin_url( 'admin-ajax.php' ), 'rankMath' );
532
+
$this->container['json']->add( 'adminurl', admin_url( 'admin.php' ), 'rankMath' );
533
+
$this->container['json']->add( 'endpoint', esc_url_raw( rest_url( 'rankmath/v1' ) ), 'rankMath' );
534
+
$this->container['json']->add( 'security', wp_create_nonce( 'rank-math-ajax-nonce' ), 'rankMath' );
535
+
$this->container['json']->add( 'restNonce', ( wp_installing() && ! is_multisite() ) ? '' : wp_create_nonce( 'wp_rest' ), 'rankMath' );
536
+
$this->container['json']->add( 'modules', \RankMath\Helper::get_active_modules(), 'rankMath' );
537
+
}
538
+
}
539
+
}
540
+
541
+
/**
542
+
* Returns the main instance of RankMath to prevent the need to use globals.
543
+
*
544
+
* @return RankMath
545
+
*/
546
+
function rank_math() { // phpcs:ignore -- This is a main function used to initialize the plugin.
547
+
return RankMath::get();
548
+
}
549
+
550
+
// Start it.
551
+
rank_math();
552
+