namespace, '/' . $this->rest_base, array( 'methods' => WP_REST_Server::CREATABLE, 'callback' => array( $this, 'update_item' ), 'permission_callback' => array( $this, 'update_item_permissions_check' ), 'args' => array( 'remove_data' => array( 'description' => 'Whether to remove all plugin data when the plugin is deleted.', 'type' => 'boolean', 'required' => true, 'sanitize_callback' => 'rest_sanitize_boolean', ), ), ) ); } /** * Permission check for updating the retention preference. * * @param WP_REST_Request $request Request object. * @return bool */ public function update_item_permissions_check( $request ) { if ( is_multisite() ) { return current_user_can( 'manage_network_options' ); } return current_user_can( 'manage_options' ); } /** * Store the retention preference. * * @param WP_REST_Request $request Request object. * @return WP_REST_Response */ public function update_item( $request ) { $remove = (bool) $request->get_param( 'remove_data' ); Gregius_Data_Uninstaller::set_retention_flag( $remove ); return rest_ensure_response( array( 'remove_data' => $remove ) ); } }