Skip to content

Commit

Permalink
Extension: Allow moz-extension as a URL protocol (#477)
Browse files Browse the repository at this point in the history
  • Loading branch information
akirk authored Feb 24, 2025
1 parent b09921d commit 7f6c100
Showing 1 changed file with 15 additions and 0 deletions.
15 changes: 15 additions & 0 deletions includes/class-rest.php
Original file line number Diff line number Diff line change
Expand Up @@ -44,6 +44,21 @@ private function register_hooks() {
add_action( 'wp_trash_post', array( $this, 'notify_remote_friend_post_deleted' ) );
add_action( 'before_delete_post', array( $this, 'notify_remote_friend_post_deleted' ) );
add_action( 'set_user_role', array( $this, 'notify_remote_friend_request_accepted' ), 20, 3 );
add_action( 'rest_pre_serve_request', array( $this, 'send_rest_origin' ), 20, 3 );
}

public function send_rest_origin( $ret, $response, $request ) {
if ( strpos( $request->get_route(), '/' . self::PREFIX . '/extension' ) !== 0 ) {
return $ret;
}

if ( $request->get_header( 'origin' ) ) {
$scheme = wp_parse_url( $request->get_header( 'origin' ), PHP_URL_SCHEME );
if ( 'moz-extension' === $scheme ) {
header( 'access-control-allow-origin: ' . $request->get_header( 'origin' ) );
}
}
return $ret;
}

/**
Expand Down

0 comments on commit 7f6c100

Please sign in to comment.