Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Shortlinks: Register as REST API post field and Gutenberg plugin #10981

Merged
merged 3 commits into from
Dec 17, 2018
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
1 change: 1 addition & 0 deletions class.jetpack-gutenberg.php
Original file line number Diff line number Diff line change
Expand Up @@ -76,6 +76,7 @@ class Jetpack_Gutenberg {
// PLUGINS
private static $default_plugins = array(
'publicize',
'shortlinks',
);
/**
* @var array Array of plugins information.
Expand Down
43 changes: 43 additions & 0 deletions modules/shortlinks.php
Original file line number Diff line number Diff line change
Expand Up @@ -87,3 +87,46 @@ 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.
if ( function_exists( 'register_rest_field' ) ) {
add_action( 'rest_api_init', 'wpme_rest_register_shortlinks' );
}

// Register Gutenberg plugin
jetpack_register_plugin( 'shortlinks' );