| 1 |
<?php |
| 2 |
|
| 3 |
namespace Yoast\WP\SEO\Conditionals; |
| 4 |
|
| 5 |
/** |
| 6 |
* Conditional that is only met when in the admin dashboard, update or Yoast SEO pages. |
| 7 |
*/ |
| 8 |
class Yoast_Admin_And_Dashboard_Conditional implements Conditional { |
| 9 |
|
| 10 |
/** |
| 11 |
* Returns `true` when on the admin dashboard, update or Yoast SEO pages. |
| 12 |
* |
| 13 |
* @return bool `true` when on the admin dashboard, update or Yoast SEO pages. |
| 14 |
*/ |
| 15 |
public function is_met() { |
| 16 |
global $pagenow; |
| 17 |
|
| 18 |
// Do not output on plugin / theme upgrade pages or when WordPress is upgrading. |
| 19 |
if ( ( \defined( 'IFRAME_REQUEST' ) && \IFRAME_REQUEST ) || $this->on_upgrade_page() || \wp_installing() ) { |
| 20 |
return false; |
| 21 |
} |
| 22 |
|
| 23 |
if ( $pagenow === 'admin.php' && isset( $_GET['page'] ) && \strpos( $_GET['page'], 'wpseo' ) === 0 ) { |
| 24 |
return true; |
| 25 |
} |
| 26 |
|
| 27 |
$target_pages = [ |
| 28 |
'index.php', |
| 29 |
'plugins.php', |
| 30 |
'update-core.php', |
| 31 |
'options-permalink.php', |
| 32 |
]; |
| 33 |
|
| 34 |
return \in_array( $pagenow, $target_pages, true ); |
| 35 |
} |
| 36 |
|
| 37 |
/** |
| 38 |
* Checks if we are on a theme or plugin upgrade page. |
| 39 |
* |
| 40 |
* @return bool Whether we are on a theme or plugin upgrade page. |
| 41 |
*/ |
| 42 |
private function on_upgrade_page() { |
| 43 |
/* |
| 44 |
* IFRAME_REQUEST is not defined on these pages, |
| 45 |
* though these action pages do show when upgrading themes or plugins. |
| 46 |
*/ |
| 47 |
$actions = [ 'do-theme-upgrade', 'do-plugin-upgrade', 'do-core-upgrade', 'do-core-reinstall' ]; |
| 48 |
return isset( $_GET['action'] ) && \in_array( $_GET['action'], $actions, true ); |
| 49 |
} |
| 50 |
} |
| 51 |
|