| 1 |
<?php |
| 2 |
/** |
| 3 |
* Handles interactions with SmartCrawl SEO. |
| 4 |
* |
| 5 |
* @package WP_Defender\Integrations |
| 6 |
*/ |
| 7 |
|
| 8 |
namespace WP_Defender\Integrations; |
| 9 |
|
| 10 |
if ( ! defined( 'ABSPATH' ) ) { |
| 11 |
die; |
| 12 |
} |
| 13 |
|
| 14 |
/** |
| 15 |
* SmartCrawl integration module. |
| 16 |
* |
| 17 |
* @since 5.8.0 |
| 18 |
*/ |
| 19 |
class Smartcrawl { |
| 20 |
|
| 21 |
/** |
| 22 |
* Check if SmartCrawl plugin is active. |
| 23 |
* |
| 24 |
* @return bool True if SmartCrawl is active, false otherwise. |
| 25 |
*/ |
| 26 |
public function is_activated(): bool { |
| 27 |
if ( ! function_exists( 'is_plugin_active' ) ) { |
| 28 |
require_once ABSPATH . 'wp-admin/includes/plugin.php'; |
| 29 |
} |
| 30 |
|
| 31 |
return class_exists( '\SmartCrawl\Modules\Advanced\Robots\Controller' ) || |
| 32 |
function_exists( 'smartcrawl_get_robots_url' ) || |
| 33 |
is_plugin_active( 'smartcrawl-seo/wpmu-dev-seo.php' ); |
| 34 |
} |
| 35 |
|
| 36 |
/** |
| 37 |
* Check if we should use SmartCrawl's filter instead of direct injection. |
| 38 |
* |
| 39 |
* SmartCrawl will serve robots.txt only when ALL conditions are met: |
| 40 |
* 1. Plugin is loaded (class exists) |
| 41 |
* 2. Robots.txt module is enabled in settings |
| 42 |
* 3. No physical robots.txt file exists |
| 43 |
* 4. Site is in root directory (not a subdirectory install) |
| 44 |
* |
| 45 |
* @return bool True if SmartCrawl will actually serve robots.txt, false otherwise. |
| 46 |
*/ |
| 47 |
public function should_serve_robots(): bool { |
| 48 |
// Quick check: SmartCrawl controller class must exist. |
| 49 |
if ( ! class_exists( '\SmartCrawl\Modules\Advanced\Robots\Controller' ) ) { |
| 50 |
return false; |
| 51 |
} |
| 52 |
|
| 53 |
// Let SmartCrawl's own logic determine if it will serve robots.txt. |
| 54 |
// This checks: module enabled, no physical file, root directory, etc. |
| 55 |
$sc_controller = \SmartCrawl\Modules\Advanced\Robots\Controller::get(); |
| 56 |
|
| 57 |
return $sc_controller->should_run(); |
| 58 |
} |
| 59 |
|
| 60 |
/** |
| 61 |
* Get SmartCrawl's robots.txt content. |
| 62 |
* |
| 63 |
* @return string The robots.txt content from SmartCrawl, or empty string if unavailable. |
| 64 |
*/ |
| 65 |
public function get_robots_content(): string { |
| 66 |
if ( ! class_exists( '\SmartCrawl\Modules\Advanced\Robots\Controller' ) ) { |
| 67 |
return ''; |
| 68 |
} |
| 69 |
|
| 70 |
$sc_controller = \SmartCrawl\Modules\Advanced\Robots\Controller::get(); |
| 71 |
|
| 72 |
return $sc_controller->get_content(); |
| 73 |
} |
| 74 |
} |
| 75 |
|