| 1 |
<?php |
| 2 |
|
| 3 |
// phpcs:disable Yoast.NamingConventions.NamespaceName.TooLong -- Needed in the folder structure. |
| 4 |
namespace Yoast\WP\SEO\Abilities\User_Interface; |
| 5 |
|
| 6 |
use Yoast\WP\SEO\Abilities\Domain\Ability_Interface; |
| 7 |
use Yoast\WP\SEO\Conditionals\Abilities_API_Conditional; |
| 8 |
use Yoast\WP\SEO\Integrations\Integration_Interface; |
| 9 |
|
| 10 |
/** |
| 11 |
* Integration that registers Yoast SEO abilities with the WordPress Abilities API. |
| 12 |
*/ |
| 13 |
class Abilities_Integration implements Integration_Interface { |
| 14 |
|
| 15 |
/** |
| 16 |
* The abilities to register. |
| 17 |
* |
| 18 |
* @var Ability_Interface[] |
| 19 |
*/ |
| 20 |
private $abilities; |
| 21 |
|
| 22 |
/** |
| 23 |
* Returns the conditionals based on which this loadable should be active. |
| 24 |
* |
| 25 |
* @return array<string> The conditionals. |
| 26 |
*/ |
| 27 |
public static function get_conditionals() { |
| 28 |
return [ Abilities_API_Conditional::class ]; |
| 29 |
} |
| 30 |
|
| 31 |
/** |
| 32 |
* Constructor. |
| 33 |
* |
| 34 |
* @param Ability_Interface ...$abilities The abilities to register. |
| 35 |
*/ |
| 36 |
public function __construct( Ability_Interface ...$abilities ) { |
| 37 |
$this->abilities = $abilities; |
| 38 |
} |
| 39 |
|
| 40 |
/** |
| 41 |
* Registers hooks with WordPress. |
| 42 |
* |
| 43 |
* @return void |
| 44 |
*/ |
| 45 |
public function register_hooks() { |
| 46 |
\add_action( 'wp_abilities_api_init', [ $this, 'register_abilities' ] ); |
| 47 |
} |
| 48 |
|
| 49 |
/** |
| 50 |
* Registers the available Yoast SEO abilities. |
| 51 |
* |
| 52 |
* @return void |
| 53 |
*/ |
| 54 |
public function register_abilities() { |
| 55 |
foreach ( $this->abilities as $ability ) { |
| 56 |
if ( ! $ability->is_available() ) { |
| 57 |
continue; |
| 58 |
} |
| 59 |
|
| 60 |
\wp_register_ability( $ability->get_name(), $ability->get_args() ); |
| 61 |
} |
| 62 |
} |
| 63 |
|
| 64 |
/** |
| 65 |
* Checks whether the current user can manage Yoast SEO. |
| 66 |
* |
| 67 |
* @deprecated 28.6 |
| 68 |
* @codeCoverageIgnore |
| 69 |
* |
| 70 |
* @return bool Whether the current user can manage Yoast SEO. |
| 71 |
*/ |
| 72 |
public function can_manage_seo(): bool { |
| 73 |
\_deprecated_function( __METHOD__, 'Yoast SEO 28.6', 'Abstract_Score_Ability::can_manage_seo' ); |
| 74 |
|
| 75 |
return \YoastSEO()->helpers->capability->current_user_can( 'wpseo_manage_options' ); |
| 76 |
} |
| 77 |
|
| 78 |
/** |
| 79 |
* Checks whether the current user can edit advanced SEO metadata. |
| 80 |
* |
| 81 |
* @deprecated 28.6 |
| 82 |
* @codeCoverageIgnore |
| 83 |
* |
| 84 |
* @return bool Whether the current user can edit advanced SEO metadata. |
| 85 |
*/ |
| 86 |
public function can_edit_advanced_metadata(): bool { |
| 87 |
\_deprecated_function( __METHOD__, 'Yoast SEO 28.6', 'Abstract_Post_SEO_Data_Ability::can_edit_advanced_metadata' ); |
| 88 |
|
| 89 |
return \YoastSEO()->helpers->capability->current_user_can( 'wpseo_edit_advanced_metadata' ); |
| 90 |
} |
| 91 |
|
| 92 |
/** |
| 93 |
* Checks whether the current user can read scores. |
| 94 |
* |
| 95 |
* @deprecated 28.2 |
| 96 |
* @codeCoverageIgnore Because of deprecation. |
| 97 |
* |
| 98 |
* @return bool Whether the current user can read scores. |
| 99 |
*/ |
| 100 |
public function can_read_scores(): bool { |
| 101 |
\_deprecated_function( __METHOD__, 'Yoast SEO 28.2', 'Abstract_Score_Ability::can_manage_seo' ); |
| 102 |
|
| 103 |
return \YoastSEO()->helpers->capability->current_user_can( 'wpseo_manage_options' ); |
| 104 |
} |
| 105 |
} |
| 106 |
|