Making WordPress.org


Ignore:
Timestamp:
12/13/2017 10:42:47 PM (7 years ago)
Author:
iandunn
Message:

WordCamp Post Types: Add ability for attendees to "favorite" sessions.

This contains the code for emailing the saved sessions to yourself, but the UI for that is temporarily disabled pending a discussion with the Systems team about potential abuse mitigations.

See #2733
Props egmanekki

File:
1 edited

Legend:

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

    r5533 r6268  
    77
    88namespace WordCamp\Post_Types\REST_API;
     9use WP_Rest_Server;
     10
    911defined( 'WPINC' ) || die();
     12
     13require_once( 'favorite-schedule-shortcode.php' );
    1014
    1115/**
     
    112116}
    113117
     118
    114119add_action( 'rest_api_init', __NAMESPACE__ . '\register_additional_rest_fields' );
     120
     121
     122/**
     123 * Register route for sending schedule of favourite sessions via e-mail.
     124 *
     125 * This can be disabled in email_fav_sessions_disabled() from favorite-schedule-shortcode.php.
     126 *
     127 * @return void
     128 */
     129function register_fav_sessions_email(){
     130    register_rest_route(
     131        'wc-post-types/v1',     // REST namespace + API version
     132        '/email-fav-sessions/', // URL slug
     133        array(
     134            'methods'  => WP_REST_Server::CREATABLE,
     135            'callback' => 'send_favourite_sessions_email',
     136            'args'     => array(
     137                'email-address' => array(
     138                    'required' => true,
     139                    'validate_callback' => function( $value, $request, $param ) {
     140                        return is_email( $value );
     141                    },
     142                    'sanitize_callback' => function( $value, $request, $param ) {
     143                        return sanitize_email( $value );
     144                    },
     145                ),
     146
     147                'session-list' => array(
     148                    'required' => true,
     149                    'validate_callback' => function( $value, $request, $param ) {
     150                        $session_ids = explode( ',', $value );
     151                        $session_count = count( $session_ids );
     152                        for ( $i = 0; $i < $session_count; $i++ ) {
     153                            if ( ! is_numeric( $session_ids[ $i ] ) ) {
     154                                return false;
     155                            }
     156                        }
     157                        return true;
     158                    },
     159                    'sanitize_callback' => function( $value, $request, $param ) {
     160                        $session_ids = explode( ',', $value );
     161                        return implode( ',', array_filter( $session_ids, 'is_numeric' ) );
     162                    },
     163                ),
     164            )
     165        )
     166    );
     167}
     168add_action( 'rest_api_init', __NAMESPACE__ . '\register_fav_sessions_email' );
    115169
    116170/**
Note: See TracChangeset for help on using the changeset viewer.