| 1 |
<?php |
| 2 |
// phpcs:disable Yoast.NamingConventions.NamespaceName.MaxExceeded |
| 3 |
// phpcs:disable Yoast.NamingConventions.NamespaceName.TooLong -- Needed in the folder structure. |
| 4 |
|
| 5 |
namespace Yoast\WP\SEO\MyYoast_Client\User_Interface; |
| 6 |
|
| 7 |
/** |
| 8 |
* Single source of truth for the HTTP-boundary check that gates managing the |
| 9 |
* site's MyYoast connection. |
| 10 |
* |
| 11 |
* Deliberately a user-interface concern, not an application one: the WP-CLI |
| 12 |
* entry point (`wp yoast auth`) is trusted by virtue of shell access and runs |
| 13 |
* with no logged-in user, so the capability check must live at the HTTP |
| 14 |
* boundary and never leak into `MyYoast_Client` or the application layer. |
| 15 |
* Pushing it down would break CLI usage or force a `--user=` flag on every |
| 16 |
* command. |
| 17 |
*/ |
| 18 |
class Connection_Permission { |
| 19 |
|
| 20 |
/** |
| 21 |
* The capability required to manage the MyYoast connection over HTTP. |
| 22 |
* |
| 23 |
* @var string |
| 24 |
*/ |
| 25 |
private const MANAGE_CAPABILITY = 'wpseo_manage_options'; |
| 26 |
|
| 27 |
/** |
| 28 |
* Whether the current HTTP user may manage the MyYoast connection. |
| 29 |
* |
| 30 |
* @return bool |
| 31 |
*/ |
| 32 |
public function can_manage(): bool { |
| 33 |
return \current_user_can( self::MANAGE_CAPABILITY ); |
| 34 |
} |
| 35 |
} |
| 36 |
|