| 1 |
<?php |
| 2 |
|
| 3 |
/** |
| 4 |
* Handle the save and deletion of terms data. |
| 5 |
*/ |
| 6 |
function taxopress_process_terms() |
| 7 |
{ |
| 8 |
|
| 9 |
if (wp_doing_ajax()) { |
| 10 |
return; |
| 11 |
} |
| 12 |
|
| 13 |
if (!is_admin()) { |
| 14 |
return; |
| 15 |
} |
| 16 |
|
| 17 |
if(!current_user_can('simple_tags')){ |
| 18 |
return; |
| 19 |
} |
| 20 |
|
| 21 |
if (empty($_GET)) { |
| 22 |
return; |
| 23 |
} |
| 24 |
|
| 25 |
if (!isset($_GET['page'])) { |
| 26 |
return; |
| 27 |
} |
| 28 |
if ('st_terms' !== $_GET['page']) { |
| 29 |
return; |
| 30 |
} |
| 31 |
|
| 32 |
if (isset($_REQUEST['action']) && $_REQUEST['action'] === 'taxopress-delete-terms') { |
| 33 |
$nonce = sanitize_text_field($_REQUEST['_wpnonce']); |
| 34 |
if (wp_verify_nonce($nonce, 'terms-action-request-nonce')) { |
| 35 |
$term = get_term(sanitize_text_field($_REQUEST['taxopress_terms'])); |
| 36 |
wp_delete_term( $term->term_id, $term->taxonomy ); |
| 37 |
} |
| 38 |
add_action('admin_notices', "taxopress_term_delete_success_admin_notice"); |
| 39 |
add_filter('removable_query_args', 'taxopress_delete_terms_filter_removable_query_args'); |
| 40 |
} |
| 41 |
} |
| 42 |
add_action('admin_init', 'taxopress_process_terms', 8); |
| 43 |
|
| 44 |
/** |
| 45 |
* Successful deleted callback. |
| 46 |
*/ |
| 47 |
function taxopress_term_delete_success_admin_notice() |
| 48 |
{ |
| 49 |
// phpcs:ignore WordPress.Security.EscapeOutput.OutputNotEscaped |
| 50 |
echo taxopress_admin_notices_helper(esc_html__('Term deleted successfully.', 'simple-tags'), false); |
| 51 |
} |
| 52 |
|
| 53 |
/** |
| 54 |
* Filters the list of query arguments which get removed from admin area URLs in WordPress. |
| 55 |
* |
| 56 |
* @link https://core.trac.wordpress.org/ticket/23367 |
| 57 |
* |
| 58 |
* @param string[] $args Array of removable query arguments. |
| 59 |
* @return string[] Updated array of removable query arguments. |
| 60 |
*/ |
| 61 |
function taxopress_delete_terms_filter_removable_query_args(array $args) |
| 62 |
{ |
| 63 |
return array_merge($args, [ |
| 64 |
'action', |
| 65 |
'taxopress_terms', |
| 66 |
'_wpnonce', |
| 67 |
]); |
| 68 |
} |