| @@ 293-328 (lines=36) @@ | ||
| 290 | * @param bool $force true to permanently delete resource, false to move to trash (not supported for `customer`) |
|
| 291 | * @return array|WP_Error |
|
| 292 | */ |
|
| 293 | protected function delete( $id, $type, $force = false ) { |
|
| 294 | ||
| 295 | if ( 'shop_order' === $type || 'shop_coupon' === $type ) |
|
| 296 | $resource_name = str_replace( 'shop_', '', $type ); |
|
| 297 | else |
|
| 298 | $resource_name = $type; |
|
| 299 | ||
| 300 | if ( 'customer' === $type ) { |
|
| 301 | ||
| 302 | $result = wp_delete_user( $id ); |
|
| 303 | ||
| 304 | if ( $result ) |
|
| 305 | return array( 'message' => __( 'Permanently deleted customer', 'woocommerce' ) ); |
|
| 306 | else |
|
| 307 | return new WP_Error( 'woocommerce_api_cannot_delete_customer', __( 'The customer cannot be deleted', 'woocommerce' ), array( 'status' => 500 ) ); |
|
| 308 | ||
| 309 | } else { |
|
| 310 | ||
| 311 | // delete order/coupon/product |
|
| 312 | ||
| 313 | $result = ( $force ) ? wp_delete_post( $id, true ) : wp_trash_post( $id ); |
|
| 314 | ||
| 315 | if ( ! $result ) |
|
| 316 | return new WP_Error( "woocommerce_api_cannot_delete_{$resource_name}", sprintf( __( 'This %s cannot be deleted', 'woocommerce' ), $resource_name ), array( 'status' => 500 ) ); |
|
| 317 | ||
| 318 | if ( $force ) { |
|
| 319 | return array( 'message' => sprintf( __( 'Permanently deleted %s', 'woocommerce' ), $resource_name ) ); |
|
| 320 | ||
| 321 | } else { |
|
| 322 | ||
| 323 | $this->server->send_status( '202' ); |
|
| 324 | ||
| 325 | return array( 'message' => sprintf( __( 'Deleted %s', 'woocommerce' ), $resource_name ) ); |
|
| 326 | } |
|
| 327 | } |
|
| 328 | } |
|
| 329 | ||
| 330 | ||
| 331 | /** |
|
| @@ 353-389 (lines=37) @@ | ||
| 350 | * @param bool $force true to permanently delete resource, false to move to trash (not supported for `customer`) |
|
| 351 | * @return array|WP_Error |
|
| 352 | */ |
|
| 353 | protected function delete( $id, $type, $force = false ) { |
|
| 354 | ||
| 355 | if ( 'shop_order' === $type || 'shop_coupon' === $type ) { |
|
| 356 | $resource_name = str_replace( 'shop_', '', $type ); |
|
| 357 | } else { |
|
| 358 | $resource_name = $type; |
|
| 359 | } |
|
| 360 | ||
| 361 | if ( 'customer' === $type ) { |
|
| 362 | ||
| 363 | $result = wp_delete_user( $id ); |
|
| 364 | ||
| 365 | if ( $result ) { |
|
| 366 | return array( 'message' => __( 'Permanently deleted customer', 'woocommerce' ) ); |
|
| 367 | } else { |
|
| 368 | return new WP_Error( 'woocommerce_api_cannot_delete_customer', __( 'The customer cannot be deleted', 'woocommerce' ), array( 'status' => 500 ) ); |
|
| 369 | } |
|
| 370 | ||
| 371 | } else { |
|
| 372 | ||
| 373 | // delete order/coupon/webhook |
|
| 374 | ||
| 375 | $result = ( $force ) ? wp_delete_post( $id, true ) : wp_trash_post( $id ); |
|
| 376 | ||
| 377 | if ( ! $result ) { |
|
| 378 | return new WP_Error( "woocommerce_api_cannot_delete_{$resource_name}", sprintf( __( 'This %s cannot be deleted', 'woocommerce' ), $resource_name ), array( 'status' => 500 ) ); |
|
| 379 | } |
|
| 380 | ||
| 381 | if ( $force ) { |
|
| 382 | return array( 'message' => sprintf( __( 'Permanently deleted %s', 'woocommerce' ), $resource_name ) ); |
|
| 383 | } else { |
|
| 384 | $this->server->send_status( '202' ); |
|
| 385 | ||
| 386 | return array( 'message' => sprintf( __( 'Deleted %s', 'woocommerce' ), $resource_name ) ); |
|
| 387 | } |
|
| 388 | } |
|
| 389 | } |
|
| 390 | ||
| 391 | ||
| 392 | /** |
|
| @@ 353-389 (lines=37) @@ | ||
| 350 | * @param bool $force true to permanently delete resource, false to move to trash (not supported for `customer`) |
|
| 351 | * @return array|WP_Error |
|
| 352 | */ |
|
| 353 | protected function delete( $id, $type, $force = false ) { |
|
| 354 | ||
| 355 | if ( 'shop_order' === $type || 'shop_coupon' === $type ) { |
|
| 356 | $resource_name = str_replace( 'shop_', '', $type ); |
|
| 357 | } else { |
|
| 358 | $resource_name = $type; |
|
| 359 | } |
|
| 360 | ||
| 361 | if ( 'customer' === $type ) { |
|
| 362 | ||
| 363 | $result = wp_delete_user( $id ); |
|
| 364 | ||
| 365 | if ( $result ) |
|
| 366 | return array( 'message' => __( 'Permanently deleted customer', 'woocommerce' ) ); |
|
| 367 | else |
|
| 368 | return new WP_Error( 'woocommerce_api_cannot_delete_customer', __( 'The customer cannot be deleted', 'woocommerce' ), array( 'status' => 500 ) ); |
|
| 369 | ||
| 370 | } else { |
|
| 371 | ||
| 372 | // delete order/coupon/product/webhook |
|
| 373 | ||
| 374 | $result = ( $force ) ? wp_delete_post( $id, true ) : wp_trash_post( $id ); |
|
| 375 | ||
| 376 | if ( ! $result ) |
|
| 377 | return new WP_Error( "woocommerce_api_cannot_delete_{$resource_name}", sprintf( __( 'This %s cannot be deleted', 'woocommerce' ), $resource_name ), array( 'status' => 500 ) ); |
|
| 378 | ||
| 379 | if ( $force ) { |
|
| 380 | return array( 'message' => sprintf( __( 'Permanently deleted %s', 'woocommerce' ), $resource_name ) ); |
|
| 381 | ||
| 382 | } else { |
|
| 383 | ||
| 384 | $this->server->send_status( '202' ); |
|
| 385 | ||
| 386 | return array( 'message' => sprintf( __( 'Deleted %s', 'woocommerce' ), $resource_name ) ); |
|
| 387 | } |
|
| 388 | } |
|
| 389 | } |
|
| 390 | ||
| 391 | ||
| 392 | /** |
|