WordPress.org

Make WordPress Core

Opened 17 months ago

Last modified 2 weeks ago

#50074 new enhancement

Add filter on post/etc action links in the REST API

Reported by: rmccue Owned by:
Milestone: Future Release Priority: normal
Severity: normal Version: 4.9.8
Component: REST API Keywords: good-first-bug has-patch
Focuses: Cc:

Description

With Gutenberg increasingly using more action links to control behaviour in the block editor, having a filter to adjust these links would be super useful. This allows developers to avoid a shotgun approach of hacking Gutenberg's UI, or using the very low-level filters to remove these actions.

This is probably useful to have as a general API to also add additional actions; e.g. for implementing something similar to Gutenberg's actions.

Attachments (2)

schema_links_added_filter.PNG (60.4 KB) - added by muhammadfaizanhaidar 4 weeks ago.
Added filter to get schema links function
removed_space_schema_links_filter.PNG (65.8 KB) - added by muhammadfaizanhaidar 4 weeks ago.
Removed space to pass phpcs test

Download all attachments as: .zip

Change History (7)

#1 @TimothyBlynJacobs
17 months ago

  • Keywords good-first-bug added
  • Milestone changed from Awaiting Review to Future Release
  • Type changed from defect (bug) to enhancement
  • Version set to 4.9.8

This makes sense to me. We'd probably also want a filter on get_schema_links.

#2 @patopaiar
9 months ago

@TimothyBlynJacobs I would like to contribute with this ticket, but I am not 100% sure of which links exactly would be the ones that need a filter added.

For your comment it is clearer, in get_schema_links function line 2452, instead of

$schema_links = $this->get_schema_links();

We can do

$schema_links = apply_filters( "rest_{$this->post_type}_item_schema_links" , $this->get_schema_links() );

But for the action links, how can I figure out which ones to add filters to?

This ticket was mentioned in PR #1616 on WordPress/wordpress-develop by MuhammadFaizanHaidar.


5 weeks ago

  • Keywords has-patch added; needs-patch removed

added filter to get_schema_links() function call
Trac ticket: https://core.trac.wordpress.org/ticket/50074
File details
wp-includes/rest-api/endpoints/class-wp-rest-posts-controller.php line 2529.

Trac ticket:

#4 in reply to: ↑ description @muhammadfaizanhaidar
5 weeks ago

@TimothyBlynJacobs I would like to contribute with this ticket.
For your comment it is clearer, in get_schema_links() function line 2528, 2529 wp-includes/rest-api/endpoints/class-wp-rest-posts-controller.php, instead of

<?php
$schema_links = $this->get_schema_links();

// I have added.

$schema_links = $this->get_schema_links();
$schema_links = apply_filters( "rest_{$this->post_type}_item_schema_links" , $schema_links );
Last edited 5 weeks ago by muhammadfaizanhaidar (previous) (diff)

@muhammadfaizanhaidar
4 weeks ago

Added filter to get schema links function

@muhammadfaizanhaidar
4 weeks ago

Removed space to pass phpcs test

This ticket was mentioned in Slack in #core-editor by muhammadfaizanhaidar. View the logs.


2 weeks ago

Note: See TracTickets for help on using tickets.