Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -142,7 +142,7 @@ public function get_items( $request ) {
* @return WP_REST_Response|WP_Error Response object on success, or WP_Error object on failure.
*/
public function get_item( $request ) {
$category = wp_get_ability_category( $request['slug'] );
$category = wp_has_ability_category( $request['slug'] ) ? wp_get_ability_category( $request['slug'] ) : null;
if ( ! $category ) {
return new WP_Error(
'rest_ability_category_not_found',
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -156,7 +156,7 @@ public function get_items( $request ) {
* @return WP_REST_Response|WP_Error Response object on success, or WP_Error object on failure.
*/
public function get_item( $request ) {
$ability = wp_get_ability( $request['name'] );
$ability = wp_has_ability( $request['name'] ) ? wp_get_ability( $request['name'] ) : null;
if ( ! $ability || ! $ability->get_meta_item( 'show_in_rest' ) ) {
return new WP_Error(
'rest_ability_not_found',
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -80,7 +80,7 @@ public function register_routes(): void {
* @return WP_REST_Response|WP_Error Response object on success, or WP_Error object on failure.
*/
public function execute_ability( $request ) {
$ability = wp_get_ability( $request['name'] );
$ability = wp_has_ability( $request['name'] ) ? wp_get_ability( $request['name'] ) : null;
if ( ! $ability ) {
return new WP_Error(
'rest_ability_not_found',
Expand Down Expand Up @@ -141,7 +141,7 @@ public function validate_request_method( string $request_method, array $annotati
* @return true|WP_Error True if the request has execution permission, WP_Error object otherwise.
*/
public function check_ability_permissions( $request ) {
$ability = wp_get_ability( $request['name'] );
$ability = wp_has_ability( $request['name'] ) ? wp_get_ability( $request['name'] ) : null;
if ( ! $ability || ! $ability->get_meta_item( 'show_in_rest' ) ) {
return new WP_Error(
'rest_ability_not_found',
Expand Down Expand Up @@ -239,7 +239,7 @@ private function get_input_from_request( $request ) {
* @return mixed Coerced input, or the raw input when it cannot be safely coerced.
*/
public function sanitize_input_for_ability( $input, $request ) {
$ability = wp_get_ability( $request['name'] );
$ability = wp_has_ability( $request['name'] ) ? wp_get_ability( $request['name'] ) : null;
if ( ! $ability instanceof WP_Ability ) {
return $input;
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -219,8 +219,7 @@ public function test_get_item_with_selected_fields(): void {
* Test getting a non-existent ability category returns 404.
*
* @ticket 64098
*
* @expectedIncorrectUsage WP_Ability_Categories_Registry::get_registered
* @ticket 65644
*/
public function test_get_item_not_found(): void {
$request = new WP_REST_Request( 'GET', '/wp-abilities/v1/categories/non-existent' );
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -386,8 +386,7 @@ public function test_get_item_with_embed_context(): void {
* Test getting a non-existent ability returns 404.
*
* @ticket 64098
*
* @expectedIncorrectUsage WP_Abilities_Registry::get_registered
* @ticket 65644
*/
public function test_get_item_not_found(): void {
$request = new WP_REST_Request( 'GET', '/wp-abilities/v1/abilities/non/existent' );
Expand Down Expand Up @@ -768,8 +767,7 @@ public function test_ability_name_with_invalid_special_characters( string $name
* Test extremely long ability names.
*
* @ticket 64098
*
* @expectedIncorrectUsage WP_Abilities_Registry::get_registered
* @ticket 65644
*/
public function test_extremely_long_ability_names(): void {
// Create a very long but valid ability name
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -716,8 +716,7 @@ public function test_wp_error_return_handling(): void {
* Test non-existent ability returns 404.
*
* @ticket 64098
*
* @expectedIncorrectUsage WP_Abilities_Registry::get_registered
* @ticket 65644
*/
public function test_execute_non_existent_ability(): void {
$request = new WP_REST_Request( 'POST', '/wp-abilities/v1/abilities/non/existent/run' );
Expand Down
Loading