Making WordPress.org

Changeset 8945


Ignore:
Timestamp:
06/13/2019 05:51:21 AM (5 years ago)
Author:
tellyworth
Message:

Make sites CPT: allow fetching list of Make sites via API

File:
1 edited

Legend:

Unmodified
Added
Removed
  • sites/trunk/wordpress.org/public_html/wp-content/plugins/wporg-make-sites-cpt/make_sites_cpt.php

    r8722 r8945  
    1111add_action( 'init', 'make_site_register_cpt' );
    1212function make_site_register_cpt() {
    13     error_log( __FUNCTION__ );
    1413    $labels = array(
    1514        'name'               => _x( 'Sites',                   'site', 'make_site_cpt' ),
     
    5049        'can_export'          => true,
    5150        'rewrite'             => true,
    52         'capability_type'     => 'post'
     51        'capability_type'     => 'post',
     52        'show_in_rest'        => true
    5353    );
    5454
    5555    register_post_type( 'make_site', $args );
     56
     57    $make_sites = make_site_get_network_sites();
     58    register_rest_field( 'make_site', 'link', array(
     59        'get_callback' => function( $site ) use ( $make_sites ) {
     60            $make_site_id = get_post_meta( $site['id'], 'make_site_id', true );
     61            return isset( $make_sites[ $make_site_id ] ) ? $make_sites[ $make_site_id ] : '';
     62        },
     63        'update_callback' => null,
     64        'schema' => array(
     65            'description' => __ ('Site link.' ),
     66            'type' => 'string',
     67        ),
     68    ) );
    5669}
    5770
Note: See TracChangeset for help on using the changeset viewer.