Skip to content
Merged
Show file tree
Hide file tree
Changes from 1 commit
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
18 changes: 9 additions & 9 deletions includes/Abilities/CustomPostTypes.php
Original file line number Diff line number Diff line change
Expand Up @@ -152,9 +152,9 @@ private function register_abilities(): void {
'execute_callback' => function ( $input ) {
$post = get_post( intval( $input['id'] ) );
if ( ! $post || $post->post_type !== $input['post_type'] ) {
return new \WP_Error( 'post_not_found', 'Post not found' );
return array('message' => 'Post not found');
}
return $post;
return array( $post );
},
'permission_callback' => fn() => current_user_can( 'edit_posts' ),
'meta' => array(
Expand Down Expand Up @@ -218,10 +218,10 @@ private function register_abilities(): void {

$post_id = wp_insert_post( $post_data );
if ( is_wp_error( $post_id ) ) {
return $post_id;
return array('message' => 'Failed to create post');
}

return get_post( $post_id );
return array( get_post( $post_id ) );
},
'permission_callback' => fn() => current_user_can( 'edit_posts' ),
'meta' => array(
Expand Down Expand Up @@ -274,7 +274,7 @@ private function register_abilities(): void {
'execute_callback' => function ( $input ) {
$post = get_post( intval( $input['id'] ) );
if ( ! $post || $post->post_type !== $input['post_type'] ) {
return new \WP_Error( 'post_not_found', 'Post not found' );
return array('message' => 'Post not found');
}

$post_data = array(
Expand All @@ -299,10 +299,10 @@ private function register_abilities(): void {

$post_id = wp_update_post( $post_data );
if ( is_wp_error( $post_id ) ) {
return $post_id;
return array('message' => 'Failed to update post');
}

return get_post( $post_id );
return array( get_post( $post_id ) );
},
'permission_callback' => fn() => current_user_can( 'edit_posts' ),
'meta' => array(
Expand Down Expand Up @@ -339,12 +339,12 @@ private function register_abilities(): void {
'execute_callback' => function ( $input ) {
$post = get_post( intval( $input['id'] ) );
if ( ! $post || $post->post_type !== $input['post_type'] ) {
return new \WP_Error( 'post_not_found', 'Post not found' );
return array('message' => 'Post not found');
}

$result = wp_delete_post( $post->ID, true );
if ( ! $result ) {
return new \WP_Error( 'delete_failed', 'Failed to delete post' );
return array('message' => 'Failed to delete post');
}

return array( 'success' => true );
Expand Down
8 changes: 4 additions & 4 deletions includes/Abilities/Media.php
Original file line number Diff line number Diff line change
Expand Up @@ -130,7 +130,7 @@ private function register_abilities(): void {
}

if ( ! file_exists( $file_path ) ) {
return new \WP_Error( 'size_not_found', 'Requested size not found' );
return array( 'message' => 'Requested size not found' );
}

$mime_type = get_post_mime_type( $id );
Expand Down Expand Up @@ -195,7 +195,7 @@ private function register_abilities(): void {

$file_data = base64_decode( $base64_data, true );
if ( false === $file_data ) {
return new \WP_Error( 'invalid_file', 'Invalid base64 data' );
return array( 'message', 'Invalid base64 data' );
}

// Detect mime type
Expand All @@ -208,7 +208,7 @@ private function register_abilities(): void {
$upload = wp_upload_bits( $filename, null, $file_data );

if ( $upload['error'] ) {
return new \WP_Error( 'upload_failed', $upload['error'] );
return array( 'message' => $upload['error'] );
}

// Create attachment
Expand All @@ -229,7 +229,7 @@ private function register_abilities(): void {
update_post_meta( $attach_id, '_wp_attachment_image_alt', $input['alt_text'] );
}

return get_post( $attach_id );
return array( get_post( $attach_id ) );
},
'permission_callback' => fn() => current_user_can( 'upload_files' ),
'meta' => array(
Expand Down
4 changes: 2 additions & 2 deletions includes/Abilities/RestApiCrud.php
Original file line number Diff line number Diff line change
Expand Up @@ -104,7 +104,7 @@ private function register_abilities(): void {
$routes = rest_get_server()->get_routes();

if ( ! isset( $routes[ $route ] ) ) {
return new \WP_Error( 'route_not_found', 'Route not found' );
return array( 'message' => 'Route not found' );
}

foreach ( $routes[ $route ] as $endpoint ) {
Expand All @@ -113,7 +113,7 @@ private function register_abilities(): void {
}
}

return new \WP_Error( 'method_not_found', 'Method not found for this route' );
return array( 'message' => 'Method not found for this route' );
},
'permission_callback' => fn() => current_user_can( 'edit_posts' ),
'meta' => array(
Expand Down