diff options
Diffstat (limited to 'plugins/jetpack/modules/shortlinks.php')
-rw-r--r-- | plugins/jetpack/modules/shortlinks.php | 47 |
1 files changed, 47 insertions, 0 deletions
diff --git a/plugins/jetpack/modules/shortlinks.php b/plugins/jetpack/modules/shortlinks.php index 54e30b94..cd06f43d 100644 --- a/plugins/jetpack/modules/shortlinks.php +++ b/plugins/jetpack/modules/shortlinks.php @@ -87,3 +87,50 @@ function wpme_get_shortlink( $id = 0, $context = 'post', $allow_slugs = true ) { function wpme_get_shortlink_handler( $shortlink, $id, $context, $allow_slugs ) { return wpme_get_shortlink( $id, $context, $allow_slugs ); } + +/** + * Add Shortlinks to the REST API Post response. + * + * @since 6.9.0 + * + * @action rest_api_init + * @uses register_rest_field, wpme_rest_get_shortlink + */ +function wpme_rest_register_shortlinks() { + register_rest_field( + 'post', + 'jetpack_shortlink', + array( + 'get_callback' => 'wpme_rest_get_shortlink', + 'update_callback' => null, + 'schema' => null, + ) + ); +} + +/** + * Get the shortlink of a post. + * + * @since 6.9.0 + * + * @param array $object Details of current post. + * + * @uses wpme_get_shortlink + * + * @return string + */ +function wpme_rest_get_shortlink( $object ) { + return wpme_get_shortlink( $object['id'], array() ); +} + +// Add shortlinks to the REST API Post response. +add_action( 'rest_api_init', 'wpme_rest_register_shortlinks' ); + +/** + * Set the Shortlink Gutenberg extension as available. + */ +function wpme_set_extension_available() { + Jetpack_Gutenberg::set_extension_available( 'jetpack/shortlinks' ); +} + +add_action( 'init', 'wpme_set_extension_available' ); |