Skip to content

Commit 10f44e8

Browse files
committed
Add function to send a Micropub Delete Entry
1 parent a726d16 commit 10f44e8

File tree

1 file changed

+39
-0
lines changed

1 file changed

+39
-0
lines changed

includes/micropub/class-synprovider-micropub.php

Lines changed: 39 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -238,6 +238,45 @@ public function post_micropub( $post, $endpoint, $headers = null ) {
238238
return $response;
239239
}
240240

241+
/**
242+
* Post JSON from a remote endpoint.
243+
*
244+
* @param string $url URL to Delete.
245+
* @param string $endpoint Micropub Endpoint
246+
* @param array $headers Headers.
247+
* @return WP_Error|array Either the associated array response or error.
248+
*
249+
*/
250+
public function delete_micropub( $url, $endpoint, $headers = null ) {
251+
$args = array(
252+
'headers' => array(
253+
'Content-type' => 'application/json',
254+
),
255+
'body' => wp_json_encode(
256+
array(
257+
'action' => 'delete',
258+
'url' => $url,
259+
)
260+
),
261+
'timeout' => 10,
262+
'limit_response_size' => 1048576,
263+
// Use an explicit user-agent for Syndication Links.
264+
'user-agent' => 'Syndication Links for WordPress',
265+
266+
);
267+
268+
if ( is_array( $headers ) ) {
269+
$args['headers'] = array_merge( $args['headers'], $headers );
270+
}
271+
272+
if ( ! array_key_exists( 'Authorization', $args['headers'] ) && ! empty( $this->token ) ) {
273+
$args['headers']['Authorization'] = 'Bearer ' . $this->token;
274+
}
275+
276+
$response = wp_remote_post( $endpoint, $args );
277+
return $response;
278+
}
279+
241280
/**
242281
* Given a post try to POSSE it to a given network
243282
*

0 commit comments

Comments
 (0)