| 1 |
<?php |
| 2 |
|
| 3 |
namespace WPAdminify\Inc\Modules\ActivityLogs\Hooks; |
| 4 |
|
| 5 |
use WPAdminify\Inc\Modules\ActivityLogs\Inc\Hooks_Base; |
| 6 |
|
| 7 |
// no direct access allowed |
| 8 |
if (!defined('ABSPATH')) exit; |
| 9 |
|
| 10 |
class WP_Adminify_Logs_Taxonomy extends Hooks_Base |
| 11 |
{ |
| 12 |
public function __construct() |
| 13 |
{ |
| 14 |
parent::__construct(); |
| 15 |
add_action('created_term', [$this, 'hooks_created_edited_deleted_term'], 10, 3); |
| 16 |
add_action('edited_term', [$this, 'hooks_created_edited_deleted_term'], 10, 3); |
| 17 |
add_action('delete_term', [$this, 'hooks_created_edited_deleted_term'], 10, 4); |
| 18 |
} |
| 19 |
|
| 20 |
|
| 21 |
public function hooks_created_edited_deleted_term($term_id, $tt_id, $taxonomy, $deleted_term = null) |
| 22 |
{ |
| 23 |
// Make sure do not action nav menu taxonomy. |
| 24 |
if ('nav_menu' === $taxonomy) |
| 25 |
return; |
| 26 |
|
| 27 |
if ('delete_term' === current_filter()) |
| 28 |
$term = $deleted_term; |
| 29 |
else |
| 30 |
$term = get_term($term_id, $taxonomy); |
| 31 |
|
| 32 |
if ($term && !is_wp_error($term)) { |
| 33 |
if ('edited_term' === current_filter()) { |
| 34 |
$action = 'updated'; |
| 35 |
} elseif ('delete_term' === current_filter()) { |
| 36 |
$action = 'deleted'; |
| 37 |
$term_id = ''; |
| 38 |
} else { |
| 39 |
$action = 'created'; |
| 40 |
} |
| 41 |
|
| 42 |
adminify_activity_logs(array( |
| 43 |
'action' => $action, |
| 44 |
'object_type' => 'Taxonomy', |
| 45 |
'object_subtype' => $taxonomy, |
| 46 |
'object_id' => $term_id, |
| 47 |
'object_name' => $term->name, |
| 48 |
)); |
| 49 |
} |
| 50 |
} |
| 51 |
} |
| 52 |
|