true, 'destructive' => false, ], $instructions ); } /** * Create ability (e.g. Create Post, Upload Media). * * @since 1.0.0 * * @param string $instructions Optional guidance, surfaced through `get-ability-info`. * * @return array{readonly: bool, destructive: bool, instructions?: string} */ public static function create( string $instructions = '' ): array { return self::with_instructions( [ 'readonly' => false, 'destructive' => false, ], $instructions ); } /** * Update ability (e.g. Update Post, Set Featured Image). * * @since 1.0.0 * * @param string $instructions Optional guidance, surfaced through `get-ability-info`. * * @return array{readonly: bool, destructive: bool, instructions?: string} */ public static function update( string $instructions = '' ): array { return self::with_instructions( [ 'readonly' => false, 'destructive' => false, ], $instructions ); } /** * Delete ability (e.g. Delete Post, Delete Term). * * @since 1.0.0 * * @param string $instructions Optional guidance, surfaced through `get-ability-info`. * * @return array{readonly: bool, destructive: bool, instructions?: string} */ public static function delete( string $instructions = '' ): array { return self::with_instructions( [ 'readonly' => false, 'destructive' => true, ], $instructions ); } /** * Generic action ability (non-destructive side effect). * * @since 1.0.0 * * @param string $instructions Optional guidance, surfaced through `get-ability-info`. * * @return array{readonly: bool, destructive: bool, instructions?: string} */ public static function action( string $instructions = '' ): array { return self::with_instructions( [ 'readonly' => false, 'destructive' => false, ], $instructions ); } /** * Attach guidance to an annotation set, when there is any. * * An empty `instructions` key would be a promise of guidance that is not * there, and `get-ability-info` returns the meta verbatim, so the key is * absent rather than empty. * * @since 1.4.0 * * @param array{readonly: bool, destructive: bool} $annotations The behaviour flags. * @param string $instructions Optional guidance. * * @return array{readonly: bool, destructive: bool, instructions?: string} */ private static function with_instructions( array $annotations, string $instructions ): array { $instructions = trim( $instructions ); if ( $instructions !== '' ) { $annotations['instructions'] = $instructions; } return $annotations; } }