@@ -19,12 +19,51 @@ public static function init() {
1919 // register endpoint
2020 add_action ( 'rest_api_init ' , array ( $ cls , 'register_route ' ) );
2121
22+ // endpoint discovery
23+ add_action ( 'wp_head ' , array ( $ cls , 'micropub_media_html_header ' ), 99 );
24+ add_action ( 'send_headers ' , array ( $ cls , 'micropub_media_http_header ' ) );
25+ add_filter ( 'host_meta ' , array ( $ cls , 'micropub_media_jrd_links ' ) );
26+ add_filter ( 'webfinger_user_data ' , array ( $ cls , 'micropub_media_jrd_links ' ) );
27+
28+ }
29+
30+ public static function get_micropub_media_endpoint () {
31+ return rest_url ( MICROPUB_NAMESPACE . '/media ' );
32+ }
33+
34+ /**
35+ * The micropub autodicovery meta tags
36+ */
37+ public static function micropub_media_html_header () {
38+ // phpcs:ignore
39+ printf ( '<link rel="micropub_media" href="%s" /> ' . PHP_EOL , static ::get_micropub_media_endpoint () );
40+ }
41+
42+ /**
43+ * The micropub autodicovery http-header
44+ */
45+ public static function micropub_media_http_header () {
46+ Micropub_Endpoint::header ( 'Link ' , '< ' . static ::get_micropub_media_endpoint () . '>; rel="micropub_media" ' );
47+ }
48+
49+ /**
50+ * Generates webfinger/host-meta links
51+ */
52+ public static function micropub_media_jrd_links ( $ array ) {
53+ $ array ['links ' ][] = array (
54+ 'rel ' => 'micropub_media ' ,
55+ 'href ' => static ::get_micropub_media_endpoint (),
56+ );
57+ return $ array ;
2258 }
2359
60+
2461 public static function register_route () {
2562 $ cls = get_called_class ();
2663 register_rest_route (
27- MICROPUB_NAMESPACE , '/media ' , array (
64+ MICROPUB_NAMESPACE ,
65+ '/media ' ,
66+ array (
2867 array (
2968 'methods ' => WP_REST_Server::CREATABLE ,
3069 'callback ' => array ( $ cls , 'upload_handler ' ),
@@ -234,8 +273,8 @@ public static function media_sideload_url( $url, $post_id = 0, $title = null ) {
234273 // Attach media to post
235274 wp_update_post (
236275 array (
237- 'post_ID ' => $ id ,
238- 'post_parent ' => $ post_id
276+ 'post_ID ' => $ id ,
277+ 'post_parent ' => $ post_id,
239278 )
240279 );
241280 return $ id ;
0 commit comments