Skip to content
Merged
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
39 changes: 0 additions & 39 deletions app/main/controllers/api/RTMediaJsonApi.php
Original file line number Diff line number Diff line change
Expand Up @@ -161,10 +161,6 @@ public function __construct() {

add_action( 'wp_ajax_nopriv_rtmedia_api', array( $this, 'rtmedia_api_process_request' ) );
add_action( 'wp_ajax_rtmedia_api', array( $this, 'rtmedia_api_process_request' ) );

if ( defined( 'RTMEDIA_GODAM_ACTIVE' ) && RTMEDIA_GODAM_ACTIVE ) {
add_action( 'rest_api_init', [ $this, 'register_rest_pre_dispatch_filter' ] );
}
}

/**
Expand Down Expand Up @@ -1473,39 +1469,4 @@ public function api_new_media_upload_dir( $args ) {
return $args;
}
}

/**
* Registers the rest_pre_dispatch filter during rest_api_init.
*/
public function register_rest_pre_dispatch_filter() {
add_filter( 'rest_pre_dispatch', [ $this, 'handle_rest_pre_dispatch' ], 10, 3 );
}

/**
* Callback for rest_pre_dispatch filter.
*
* @param mixed $result Result to return instead of the request. Default null to continue with request.
* @param WP_REST_Server $server Server instance.
* @param WP_REST_Request $request Request object.
*
* @return mixed Modified result or original $result.
*/
public function handle_rest_pre_dispatch( $result, $server, $request ) {
$route = $request->get_route();
$method = $request->get_method();

if ( 'GET' === $method && preg_match( '#^/wp/v2/media/(\d+)$#', $route, $matches ) ) {
$media_id = (int) $matches[1];
$post = get_post( $media_id );

if ( $post && 'attachment' === $post->post_type ) {
$controller = new WP_REST_Attachments_Controller( 'attachment' );
$response = $controller->prepare_item_for_response( $post, $request );

return rest_ensure_response( $response );
}
}

return $result;
}
}
Loading