Ticket #40748: 40748.2.diff
File 40748.2.diff, 6.5 KB (added by , 8 years ago) |
---|
-
src/wp-admin/admin-ajax.php
64 64 'parse-media-shortcode', 'destroy-sessions', 'install-plugin', 'update-plugin', 'press-this-save-post', 65 65 'press-this-add-category', 'crop-image', 'generate-password', 'save-wporg-username', 'delete-plugin', 66 66 'search-plugins', 'search-install-plugins', 'activate-plugin', 'update-theme', 'delete-theme', 67 'install-theme', 'get-post-thumbnail-html', 'get-community-events',67 'install-theme', 'get-post-thumbnail-html', 68 68 ); 69 69 70 70 // Deprecated -
src/wp-admin/includes/ajax-actions.php
297 297 } 298 298 299 299 /** 300 * Handles AJAX requests for community events301 *302 * @since 4.8.0303 */304 function wp_ajax_get_community_events() {305 require_once( ABSPATH . 'wp-admin/includes/class-wp-community-events.php' );306 307 check_ajax_referer( 'community_events' );308 309 $search = isset( $_POST['location'] ) ? wp_unslash( $_POST['location'] ) : '';310 $timezone = isset( $_POST['timezone'] ) ? wp_unslash( $_POST['timezone'] ) : '';311 $user_id = get_current_user_id();312 $saved_location = get_user_option( 'community-events-location', $user_id );313 $events_client = new WP_Community_Events( $user_id, $saved_location );314 $events = $events_client->get_events( $search, $timezone );315 316 if ( is_wp_error( $events ) ) {317 wp_send_json_error( array(318 'error' => $events->get_error_message(),319 ) );320 } else {321 if ( isset( $events['location'] ) ) {322 // Store the location network-wide, so the user doesn't have to set it on each site.323 update_user_option( $user_id, 'community-events-location', $events['location'], true );324 }325 326 wp_send_json_success( $events );327 }328 }329 330 /**331 300 * Ajax handler for dashboard widgets. 332 301 * 333 302 * @since 3.4.0 -
src/wp-admin/includes/dashboard.php
144 144 $events_client = new WP_Community_Events( $user_id, $user_location ); 145 145 146 146 $script_data = array( 147 'nonce' => wp_create_nonce( 'community_events' ), 148 'cache' => $events_client->get_cached_events(), 147 'nonce' => wp_create_nonce( 'wp_rest' ), 148 'cache' => $events_client->get_cached_events(), 149 'apiUrl' => rest_url( 'dashboard/v1/community-events' ), 149 150 150 151 'l10n' => array( 151 152 'enter_closest_city' => __( 'Enter your closest city to find nearby events.' ), -
src/wp-admin/includes/rest-endpoints.php
1 <?php 2 /** 3 * Administration API: REST API handlers 4 * 5 * @package WordPress 6 * @subpackage Administration 7 * @since 4.8.0 8 */ 9 10 /** 11 * Register REST endpoints for the dashboard/v1 namespace. 12 * 13 * @since 4.8.0 14 */ 15 function wp_dashboard_rest_register() { 16 // Community Events Dashboard Widget. 17 register_rest_route( 'dashboard/v1', 'community-events', array( 18 'methods' => WP_REST_Server::EDITABLE, 19 'callback' => 'wp_dashboard_rest_get_community_events', 20 'permission_callback' => 'is_user_logged_in', 21 'args' => array( 22 'location' => array( 23 'type' => 'string', 24 'default' => '', 25 ), 26 'timezone' => array( 27 'type' => 'string', 28 'default' => '', 29 ), 30 ), 31 ) ); 32 } 33 34 /** 35 * Handles AJAX requests for community events 36 * 37 * @since 4.8.0 38 */ 39 function wp_dashboard_rest_get_community_events( WP_REST_Request $request ) { 40 require_once( ABSPATH . 'wp-admin/includes/class-wp-community-events.php' ); 41 42 $user_id = get_current_user_id(); 43 $saved_location = get_user_option( 'community-events-location', $user_id ); 44 $events_client = new WP_Community_Events( $user_id, $saved_location ); 45 $events = $events_client->get_events( $request['location'], $request['timezone'] ); 46 47 if ( is_wp_error( $events ) ) { 48 return $events; 49 } 50 51 if ( isset( $events['location'] ) ) { 52 // Store the location network-wide, so the user doesn't have to set it on each site. 53 update_user_option( $user_id, 'community-events-location', $events['location'], true ); 54 } 55 56 return $events; 57 } -
src/wp-admin/js/dashboard.js
288 288 getEvents: function( requestParams ) { 289 289 var initiatedBy, 290 290 app = this, 291 $spinner = $( '.community-events-form' ).children( '.spinner' ); 291 $spinner = $( '.community-events-form' ).children( '.spinner' ), 292 request; 292 293 293 294 requestParams = requestParams || {}; 294 295 requestParams._wpnonce = communityEventsData.nonce; … … 298 299 299 300 $spinner.addClass( 'is-active' ); 300 301 301 wp.ajax.post( 'get-community-events', requestParams ) 302 request = { 303 type: 'POST', 304 url: communityEventsData.apiUrl, 305 data: requestParams, 306 }; 307 $.ajax( request ) 302 308 .always( function() { 303 309 $spinner.removeClass( 'is-active' ); 304 310 }) -
src/wp-includes/default-filters.php
389 389 add_action( 'rest_api_init', 'rest_api_default_filters', 10, 1 ); 390 390 add_action( 'rest_api_init', 'register_initial_settings', 10 ); 391 391 add_action( 'rest_api_init', 'create_initial_rest_routes', 99 ); 392 add_action( 'rest_api_init', 'wp_dashboard_rest_register', 99 ); 392 393 add_action( 'parse_request', 'rest_api_loaded' ); 393 394 394 395 /** -
src/wp-settings.php
239 239 require( ABSPATH . WPINC . '/rest-api/fields/class-wp-rest-post-meta-fields.php' ); 240 240 require( ABSPATH . WPINC . '/rest-api/fields/class-wp-rest-term-meta-fields.php' ); 241 241 require( ABSPATH . WPINC . '/rest-api/fields/class-wp-rest-user-meta-fields.php' ); 242 require( ABSPATH . 'wp-admin/includes/rest-endpoints.php' ); 242 243 243 244 $GLOBALS['wp_embed'] = new WP_Embed(); 244 245