Making WordPress.org

Changeset 8004


Ignore:
Timestamp:
12/20/2018 11:34:12 PM (8 years ago)
Author:
coreymckrill
Message:

WordCamp Post Types: Enhance session data returned by REST API

  • Add a new field session_date_time that shows the session's date and time rendered into a human-readable string, formatted for the site's locale.
  • Include more data about sessions that are embedded in the speaker data returned by the REST API.
File:
1 edited

Legend:

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

    r8003 r8004  
    114114                );
    115115        } // End if().
     116
     117        /**
     118         * Session date and time
     119         */
     120        register_rest_field(
     121                'wcb_session',
     122                'session_date_time',
     123                [
     124                        'get_callback' => function ( $object ) {
     125                                $object = (object) $object;
     126                                $raw    = absint( get_post_meta( $object->id, '_wcpt_session_time', true ) );
     127                                $return = [
     128                                        'date' => '',
     129                                        'time' => '',
     130                                ];
     131
     132                                if ( $raw ) {
     133                                        $return['date'] = date_i18n( get_option( 'date_format' ), $raw );
     134                                        $return['time'] = date_i18n( get_option( 'time_format' ), $raw );
     135                                }
     136
     137                                return $return;
     138                        },
     139                        'schema'       => [
     140                                'description' => __( 'Date and time of the session', 'wordcamporg' ),
     141                                'type'        => 'object',
     142                                'context'     => array( 'embed', 'view' ),
     143                                'readonly'    => true,
     144                                'properties'  => [
     145                                        'date' => [
     146                                                'type'    => 'string',
     147                                                'context' => array( 'embed', 'view' ),
     148                                        ],
     149                                        'time' => [
     150                                                'type'    => 'string',
     151                                                'context' => array( 'embed', 'view' ),
     152                                        ],
     153                                ],
     154                        ],
     155                ]
     156        );
    116157}
    117158
    … …  
    196237                $response->add_link(
    197238                        'sessions',
    198                         get_rest_url( null, "/wp/v2/sessions/$session_id" ),
     239                        add_query_arg(
     240                                [
     241                                        // Ensure that taxonomy data gets included in the embed.
     242                                        '_embed'  => true,
     243                                        'context' => 'view',
     244                                ],
     245                                get_rest_url( null, "/wp/v2/sessions/$session_id" )
     246                        ),
    199247                        array( 'embeddable' => true )
    200248                );
Note: See TracChangeset for help on using the changeset viewer.