| 1 |
<?php |
| 2 |
|
| 3 |
namespace Yoast\WP\SEO\Conditionals; |
| 4 |
|
| 5 |
/** |
| 6 |
* Conditional that is only met when on the front end or Yoast file editor page. |
| 7 |
*/ |
| 8 |
class Robots_Txt_Conditional implements Conditional { |
| 9 |
|
| 10 |
/** |
| 11 |
* Holds the Front_End_Conditional instance. |
| 12 |
* |
| 13 |
* @var Front_End_Conditional |
| 14 |
*/ |
| 15 |
protected $front_end_conditional; |
| 16 |
|
| 17 |
/** |
| 18 |
* Constructs the class. |
| 19 |
* |
| 20 |
* @param Front_End_Conditional $front_end_conditional The front end conditional. |
| 21 |
*/ |
| 22 |
public function __construct( Front_End_Conditional $front_end_conditional ) { |
| 23 |
$this->front_end_conditional = $front_end_conditional; |
| 24 |
} |
| 25 |
|
| 26 |
/** |
| 27 |
* Returns whether or not this conditional is met. |
| 28 |
* |
| 29 |
* @return bool Whether or not the conditional is met. |
| 30 |
*/ |
| 31 |
public function is_met() { |
| 32 |
return $this->front_end_conditional->is_met() || $this->is_file_editor_page(); |
| 33 |
} |
| 34 |
|
| 35 |
/** |
| 36 |
* Returns whether the current page is the file editor page. |
| 37 |
* |
| 38 |
* This checks for two locations: |
| 39 |
* - Multisite network admin file editor page |
| 40 |
* - Single site file editor page (under tools) |
| 41 |
* |
| 42 |
* @return bool |
| 43 |
*/ |
| 44 |
protected function is_file_editor_page() { |
| 45 |
global $pagenow; |
| 46 |
|
| 47 |
if ( $pagenow !== 'admin.php' ) { |
| 48 |
return false; |
| 49 |
} |
| 50 |
|
| 51 |
// phpcs:ignore WordPress.Security.NonceVerification -- This is not a form. |
| 52 |
if ( isset( $_GET['page'] ) && $_GET['page'] === 'wpseo_files' && \is_multisite() && \is_network_admin() ) { |
| 53 |
return true; |
| 54 |
} |
| 55 |
|
| 56 |
// phpcs:ignore WordPress.Security.NonceVerification -- This is not a form. |
| 57 |
if ( ! ( isset( $_GET['page'] ) && $_GET['page'] === 'wpseo_tools' ) ) { |
| 58 |
return false; |
| 59 |
} |
| 60 |
|
| 61 |
// phpcs:ignore WordPress.Security.NonceVerification -- This is not a form. |
| 62 |
if ( isset( $_GET['tool'] ) && $_GET['tool'] === 'file-editor' ) { |
| 63 |
return true; |
| 64 |
} |
| 65 |
|
| 66 |
return false; |
| 67 |
} |
| 68 |
} |
| 69 |
|