| 1 |
<?php |
| 2 |
/** |
| 3 |
* Shared permission gate for all Templately MCP abilities (FR-007). |
| 4 |
* |
| 5 |
* @package Templately\Modules\McpCore\Support |
| 6 |
*/ |
| 7 |
|
| 8 |
namespace Templately\Modules\McpCore\Support; |
| 9 |
|
| 10 |
class Permissions { |
| 11 |
|
| 12 |
/** |
| 13 |
* `manage_options` gate used by every ability's permission_callback, |
| 14 |
* including the two read-only discovery/detail abilities. |
| 15 |
* |
| 16 |
* @return bool |
| 17 |
*/ |
| 18 |
public static function can_use_abilities(): bool { |
| 19 |
return is_user_logged_in() && current_user_can( 'manage_options' ); |
| 20 |
} |
| 21 |
|
| 22 |
/** |
| 23 |
* Additional gate for the "existing post" import target (FR-008): |
| 24 |
* the acting user must also be able to edit the specific target post. |
| 25 |
* |
| 26 |
* @param int $post_id |
| 27 |
* @return bool |
| 28 |
*/ |
| 29 |
public static function can_edit_post( int $post_id ): bool { |
| 30 |
return get_post( $post_id ) instanceof \WP_Post && current_user_can( 'edit_post', $post_id ); |
| 31 |
} |
| 32 |
} |
| 33 |
|