Skip to content

Commit df94038

Browse files
dshanskesnarfed
authored andcommitted
Add syndication hook
1 parent 2595903 commit df94038

File tree

4 files changed

+31
-3
lines changed

4 files changed

+31
-3
lines changed

micropub.php

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -346,7 +346,9 @@ public static function post_handler( $user_id ) {
346346
} else {
347347
static::error( 400, 'unknown action ' . $action );
348348
}
349-
349+
if ( ! empty( $synd_requested ) ) {
350+
do_action( 'micropub_syndication', $args['ID'], $synd_requested );
351+
}
350352
do_action( 'after_micropub', static::$input, $args );
351353
static::respond( $status, null, $args );
352354
}

readme.md

Lines changed: 6 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -39,12 +39,16 @@ Called to generate the list of `syndicate-to` targets to return in response to a
3939

4040
$resp defaults to null. If the return value is non-null, it should be an associative array that is encoded as JSON and will be returned in place of the normal micropub response.
4141

42-
...and one hook:
42+
...and two hooks:
4343

4444
`after_micropub( $input, $wp_args = null)`
4545

4646
Called after handling a Micropub request. Not called if the request fails (ie doesn't return HTTP 2xx).
4747

48+
`micropub_syndication( $ID, $syndicate_to )`
49+
50+
Called only if there are syndication targets $syndicate_to for post $ID. $syndicate_to will be an array of UIDs that are verified as one or more of the UIDs added using the `micropub_syndicate-to` filter.
51+
4852
Arguments:
4953

5054
* `$input`: associative array, the Micropub request in [JSON format](http://micropub.net/draft/index.html#json-syntax). If the request was form-encoded or a multipart file upload, it's converted to JSON format.
@@ -174,6 +178,7 @@ into markdown and saved to readme.md.
174178
* MICROPUB_LOCAL_AUTH now disables adding auth headers to the page.
175179
* Fix post status issue by checking for valid defaults
176180
* Add configuration option under writing settings to set default post status
181+
* Add `micropub_syndication` hook that only fires on a request to syndicate to make it easier for third-party plugins to hook in
177182
178183
179184
### 1.3 (2017-12-31)

readme.txt

Lines changed: 6 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -46,12 +46,16 @@ Called to generate the list of `syndicate-to` targets to return in response to a
4646

4747
$resp defaults to null. If the return value is non-null, it should be an associative array that is encoded as JSON and will be returned in place of the normal micropub response.
4848

49-
...and one hook:
49+
...and two hooks:
5050

5151
`after_micropub( $input, $wp_args = null)`
5252

5353
Called after handling a Micropub request. Not called if the request fails (ie doesn't return HTTP 2xx).
5454

55+
`micropub_syndication( $ID, $syndicate_to )`
56+
57+
Called only if there are syndication targets $syndicate_to for post $ID. $syndicate_to will be an array of UIDs that are verified as one or more of the UIDs added using the `micropub_syndicate-to` filter.
58+
5559
Arguments:
5660

5761
* `$input`: associative array, the Micropub request in [JSON format](http://micropub.net/draft/index.html#json-syntax). If the request was form-encoded or a multipart file upload, it's converted to JSON format.
@@ -171,6 +175,7 @@ into markdown and saved to readme.md.
171175
* MICROPUB_LOCAL_AUTH now disables adding auth headers to the page.
172176
* Fix post status issue by checking for valid defaults
173177
* Add configuration option under writing settings to set default post status
178+
* Add `micropub_syndication` hook that only fires on a request to syndicate to make it easier for third-party plugins to hook in
174179

175180
= 1.3 (2017-12-31) =
176181
* Saves [access token response](https://tokens.indieauth.com/) in a post meta field `micropub_auth_response`.

tests/test_micropub.php

Lines changed: 16 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -406,6 +406,22 @@ function test_create_with_unsupported_syndicate_to() {
406406
$this->check( 400, 'Unknown mp-syndicate-to targets: facebook' );
407407
}
408408

409+
function syndicate_trigger( $id, $syns ) {
410+
add_post_meta( $id, 'testing', $syns );
411+
}
412+
413+
function test_create_syn_hook() {
414+
add_filter( 'micropub_syndicate-to', array( $this, 'syndications' ) );
415+
add_action( 'micropub_syndication', array( $this, 'syndicate_trigger' ), 10, 2 );
416+
Recorder::$request_headers = array( 'content-type' => 'application/json; charset=utf-8' );
417+
Recorder::$input = static::$mf2;
418+
Recorder::$input['properties']['mp-syndicate-to'] = array( 'twitter' );
419+
Recorder::$micropub_auth_response = static::$micropub_auth_response;
420+
$post = self::check_create();
421+
$this->assertEquals( array( 'twitter' ), get_post_meta( $post->ID, 'testing', true ) );
422+
}
423+
424+
409425
function test_create_content_html_post() {
410426
$_POST = array(
411427
'h' => 'entry',

0 commit comments

Comments
 (0)