namespace, '/send-time', array( 'methods' => WP_REST_Server::READABLE, 'callback' => array( $this, 'send_time' ), 'permission_callback' => array( $this, 'check_permission' ), ) ); register_rest_route( $this->namespace, '/contacts/inactive', array( 'methods' => WP_REST_Server::READABLE, 'callback' => array( $this, 'inactive' ), 'permission_callback' => array( $this, 'check_permission' ), ) ); register_rest_route( $this->namespace, '/contacts/inactive/cleanup', array( 'methods' => WP_REST_Server::CREATABLE, 'callback' => array( $this, 'cleanup' ), 'permission_callback' => array( $this, 'check_permission' ), 'args' => array( 'action' => array( 'required' => true, 'type' => 'string', 'enum' => Mailpuff_Inactive::ACTIONS, 'sanitize_callback' => 'sanitize_key', ), 'group_id' => array( 'type' => 'integer', 'sanitize_callback' => 'absint', ), ), ) ); } /** * @return WP_REST_Response */ public function send_time() { return $this->success( Mailpuff_Send_Time::suggest() ); } /** * @return WP_REST_Response */ public function inactive() { return $this->success( Mailpuff_Inactive::summary() ); } /** * @param WP_REST_Request $request Request. * @return WP_REST_Response|WP_Error */ public function cleanup( $request ) { $updated = Mailpuff_Inactive::cleanup( (string) $request->get_param( 'action' ), absint( $request->get_param( 'group_id' ) ) ); if ( is_wp_error( $updated ) ) { return $updated; } return $this->success( array( 'updated' => (int) $updated ) ); } }