| 1 |
<?php |
| 2 |
|
| 3 |
namespace Yoast\WP\SEO\Integrations; |
| 4 |
|
| 5 |
use Yoast\WP\SEO\Conditionals\XMLRPC_Conditional; |
| 6 |
|
| 7 |
/** |
| 8 |
* Noindexes the xmlrpc.php file and all ways to request it. |
| 9 |
* |
| 10 |
* @phpcs:disable Yoast.NamingConventions.ObjectNameDepth.MaxExceeded -- Known false positive with acronyms. Fix expected in YoastCS 3.x. |
| 11 |
*/ |
| 12 |
class XMLRPC implements Integration_Interface { |
| 13 |
|
| 14 |
/** |
| 15 |
* Returns the conditionals based on which this loadable should be active. |
| 16 |
* |
| 17 |
* In this case when the current request is an XML-RPC request. |
| 18 |
* |
| 19 |
* @return array The conditionals based on which this class should be loaded. |
| 20 |
*/ |
| 21 |
public static function get_conditionals() { |
| 22 |
return [ XMLRPC_Conditional::class ]; |
| 23 |
} |
| 24 |
|
| 25 |
/** |
| 26 |
* Initializes the integration. |
| 27 |
* |
| 28 |
* @return void |
| 29 |
*/ |
| 30 |
public function register_hooks() { |
| 31 |
\add_filter( 'xmlrpc_methods', [ $this, 'robots_header' ] ); |
| 32 |
} |
| 33 |
|
| 34 |
/** |
| 35 |
* Sets a noindex, follow x-robots-tag header on all XMLRPC requests. |
| 36 |
* |
| 37 |
* @codeCoverageIgnore Basically impossible to test from the command line. |
| 38 |
* |
| 39 |
* @param array $methods The methods. |
| 40 |
* |
| 41 |
* @return array The methods. |
| 42 |
*/ |
| 43 |
public function robots_header( $methods ) { |
| 44 |
if ( \headers_sent() === false ) { |
| 45 |
\header( 'X-Robots-Tag: noindex, follow', true ); |
| 46 |
} |
| 47 |
|
| 48 |
return $methods; |
| 49 |
} |
| 50 |
} |
| 51 |
|