Taxonomy.php
1 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
<?php
namespace ACP\Editing\BulkDelete\RequestHandler;
use ACP\Editing\BulkDelete\RequestHandler;
use RuntimeException;
use WP_Error;
class Taxonomy extends RequestHandler {
/**
* @var string
*/
private $taxonomy;
public function __construct( string $taxonomy ) {
$this->taxonomy = $taxonomy;
}
protected function delete( $id, array $args = [] ): void {
$id = (int) $id;
if ( ! current_user_can( 'manage_categories' ) || ! current_user_can( 'delete_term', $id ) ) {
throw new RuntimeException( __( 'You have no permission to delete this item.', 'codepress-admin-columns' ) );
}
$result = wp_delete_term( $id, $this->taxonomy );
if ( false === $result ) {
throw new RuntimeException( __( 'Term does not exists.', 'codepress-admin-columns' ) );
}
if ( 0 === $result ) {
throw new RuntimeException( __( 'A default term can not be deleted.', 'codepress-admin-columns' ) );
}
if ( $result instanceof WP_Error ) {
throw new RuntimeException( $result->get_error_message() );
}
}
}