Making WordPress.org

Changeset 5222


Ignore:
Timestamp:
03/30/2017 10:48:36 PM (7 years ago)
Author:
iandunn
Message:

WordCamp Post Type: Expose public sesssion meta via the REST API

File:
1 edited

Legend:

Unmodified
Added
Removed
  • sites/trunk/wordcamp.org/public_html/wp-content/plugins/wc-post-types/wc-post-types.php

    r5221 r5222  
    5858
    5959        // REST API
     60        add_action( 'init',                     array( $this, 'expose_public_post_meta'  )        );
    6061        add_filter( 'rest_prepare_wcb_speaker', array( $this, 'link_speaker_to_sessions' ), 10, 2 );
    6162        add_filter( 'rest_prepare_wcb_session', array( $this, 'link_session_to_speakers' ), 10, 2 );
     
    13971398
    13981399        return $content . $sessions_html;
     1400    }
     1401
     1402    /**
     1403     * Add non-sensitive meta fields to the speaker/session REST API endpoints
     1404     *
     1405     * if we ever want to register meta for purposes other than exposing it in the API, then this function will
     1406     * probably need to be re-thought and re-factored.
     1407     */
     1408    public function expose_public_post_meta() {
     1409        $public_session_fields = array(
     1410            '_wcpt_session_time' => array(
     1411                'type'   => 'integer',
     1412                'single' => true,
     1413            ),
     1414
     1415            '_wcpt_session_type' => array(
     1416                'single' => true,
     1417            ),
     1418
     1419            '_wcpt_session_slides' => array(
     1420                'single' => true,
     1421            ),
     1422
     1423            '_wcpt_session_video' => array(
     1424                'single' => true,
     1425            ),
     1426        );
     1427
     1428        wcorg_register_meta_only_on_endpoint( 'post', $public_session_fields, '/wp-json/wp/v2/sessions/' );
    13991429    }
    14001430
     
    19241954            'labels'            => $labels,
    19251955            'rewrite'           => array( 'slug' => 'speaker', 'with_front' => true ),
    1926             'supports'          => array( 'title', 'editor', 'author', 'revisions', 'comments' ),
     1956            'supports'          => array( 'title', 'editor', 'author', 'revisions', 'comments', 'custom-fields' ),
    19271957            'menu_position'     => 20,
    19281958            'public'            => true,
     
    19581988            'labels'            => $labels,
    19591989            'rewrite'           => array( 'slug' => 'session', 'with_front' => false ),
    1960             'supports'          => array( 'title', 'editor', 'author', 'revisions', 'thumbnail' ),
     1990            'supports'          => array( 'title', 'editor', 'author', 'revisions', 'thumbnail', 'custom-fields' ),
    19611991            'menu_position'     => 21,
    19621992            'public'            => true,
Note: See TracChangeset for help on using the changeset viewer.