Making WordPress.org

Changeset 3016


Ignore:
Timestamp:
04/26/2016 07:47:23 PM (11 years ago)
Author:
ocean90
Message:

Translate: Add a DELETE endpoint for jobs.

See #1636.

File:
1 edited

Legend:

Unmodified
Added
Removed
  • sites/trunk/wordpress.org/public_html/wp-content/plugins/wporg-gp-customizations/inc/rest-api/endpoints/class-jobs-controller.php

    r3014 r3016  
    3232                                                'sanitize_callback' => 'sanitize_text_field',
    3333                                                'validate_callback' => [ $this, 'validate_recurrence' ],
     34                                        ],
     35                                        'hook'       => [
     36                                                'required'          => true,
     37                                                'sanitize_callback' => 'sanitize_text_field',
     38                                        ],
     39                                        'args'       => [
     40                                                'default' => [],
     41                                                'validate_callback' => [ $this, 'validate_args' ],
     42                                        ],
     43                                ],
     44                        ],
     45                        [
     46                                'methods'             => WP_REST_Server::DELETABLE,
     47                                'callback'            => [ $this, 'delete_item' ],
     48                                'permission_callback' => [ $this, 'permission_check_internal_api_bearer' ],
     49                                'args'                => [
     50                                        'timestamp'  => [
     51                                                'required'          => true,
     52                                                'sanitize_callback' => 'absint',
     53                                                'validate_callback' => [ $this, 'validate_timestamp' ],
    3454                                        ],
    3555                                        'hook'       => [
    … …  
    95115
    96116        /**
     117         * Delete one job from the collection.
     118         *
     119         * @param \WP_REST_Request $request Full data about the request.
     120         * @return \WP_Error|bool WP_Error on failure, true on success.
     121         */
     122        public function delete_item( $request ) {
     123                $result = wp_unschedule_event( $request['timestamp'], $request['hook'], $request['args'] );
     124                if ( false === $result ) {
     125                        return new WP_Error( 'insert_failed' );
     126                }
     127
     128                return true;
     129        }
     130
     131        /**
    97132         * Validates a timestamp.
    98133         *
Note: See TracChangeset for help on using the changeset viewer.