Potential Supported Features of the Frontity WP Plugin

This is a list of features that our WP Plugin can contain. Bear in mind that these are for the WP.org REST API and don’t include the WP.com REST API.

Features for the REST API

HTML Purifier

When applied, it uses HTML Purifier in the content to sanitize the HTML so html2react receives proper HTML.

Include/Exclude Fields

When exclude is applied, it blacklists those fields in the API response. When include is applied it whitelists those fields (and excludes the others).

Content Attachment Ids

When applied, it searches for the Ids of the attachments found in content and adds a data-attachment-id to the <img> tag. It also adds a content_media field and those attachments to _embedded.

URL Discovery Endpoint

This endpoint accepts a URL and returns the proper content, no matter if it’s a single cp or taxonomy or a list of cpts or taxonomies.

Expose Custom Fields

When applied the selected custom field is exposed in the API response.

Text (or decoded) Fields

When applied it adds text fields (decoded and no HTML tags) for the title and the excerpt.

Lastest

When applied, latest becomes just like another taxonomy in the API. Latest means the latest posts of certain cpt.

Fix Forbidden Media Errors

When applied it detaches any attachment found without permissions so it can be shown in the REST API.

Preview Draft Posts

When applied it includes posts with draft status in the API response.

General WordPress Info Endpoint

This endpoint returns some useful WordPress info like:

{
  locale: "en_US",
  timezone: "",
  gmt_offset: 0,
  per_page: 10,
}

Add CORS

Add CORS headers.

Does it make sense to include a feature to add menus to the API? It would be awesome to be able to change the menu without having to go into Frontity project, and do it in WP admin, as users are used to.

I have seen that just adding this code you create and endpoint for the menu you have selected.

function get_menu() {
    # Change 'menu' to your own navigation slug.
    return wp_get_nav_menu_items('test');
}

add_action( 'rest_api_init', function () {
        register_rest_route( 'menus', '/test', array(
        'methods' => 'GET',
        'callback' => 'get_menu',
    ) );
} );

Maybe it is interesting to let people add menu slugs and create an endpoint for it at /wp-json/menu/{slug}. This way I would be able to create a Component for the menu in Frontity fetching this info, I wouldn’t have to change Frontity settings each time me (or my clients) want to change menu items and I could do it from WP dashboard, right?

2 Likes

That totally makes sense, but it is already in the WP roadmap.

This is the repo:

They need it to be able to release the gutenberg menu block:

I don’t think we should spend time doing it ourselves. Instead, let’s wait until it’s merged use those endpoints for our menus :slight_smile:

Oh, that’s great! Thank you :grin:

1 Like

A few more that were missing here:

Yoast Meta

Add yoast meta data to REST API responses.

REST API Cache

Add REST API cache

Global Redirects

Add global redirection for Headless WP, from the WordPress URL to the frontend URL.