models
4 years ago
queries
4 years ago
utils
4 years ago
chart.php
4 years ago
db.php
4 years ago
delete_data_ajax.php
4 years ago
filters.php
4 years ago
filters_ajax.php
4 years ago
rest_api.php
4 years ago
settings.php
4 years ago
settings_ajax.php
4 years ago
super_secret_content_generator.php
4 years ago
table.php
4 years ago
table_referrers.php
4 years ago
table_views.php
4 years ago
track_resource_changes.php
4 years ago
track_resource_changes.php
53 lines
| 1 | <?php |
| 2 | |
| 3 | namespace IAWP; |
| 4 | |
| 5 | class Track_Resource_Changes |
| 6 | { |
| 7 | public function __construct() |
| 8 | { |
| 9 | add_action('post_updated', [$this, 'handle_post_updated']); |
| 10 | add_action('profile_update', [$this, 'handle_profile_updated']); |
| 11 | add_action('registered_post_type', [$this, 'handle_registered_post_type']); |
| 12 | add_action('pre_delete_term', [$this, 'handle_deleted_term']); |
| 13 | } |
| 14 | |
| 15 | public function handle_post_updated($post_id) |
| 16 | { |
| 17 | $post = get_post($post_id); |
| 18 | |
| 19 | if (isset($post) && $post->post_status != 'trash') { |
| 20 | $row = (object) ['resource' => 'singular', 'singular_id' => $post_id]; |
| 21 | $page = new Page_Singular($row); |
| 22 | $page->update_cache(); |
| 23 | } |
| 24 | } |
| 25 | |
| 26 | public function handle_profile_updated($user_id) |
| 27 | { |
| 28 | $row = (object) ['resource' => 'author', 'author_id' => $user_id]; |
| 29 | $page = new Page_Author_Archive($row); |
| 30 | $page->update_cache(); |
| 31 | } |
| 32 | |
| 33 | public function handle_registered_post_type($post_type) |
| 34 | { |
| 35 | $post_type_object = get_post_type_object($post_type); |
| 36 | |
| 37 | if ($post_type_object->_builtin == false) { |
| 38 | $row = (object) ['resource' => 'post_type_archive', 'post_type' => $post_type]; |
| 39 | $page = new Page_Post_Type_Archive($row); |
| 40 | $page->update_cache(); |
| 41 | } |
| 42 | } |
| 43 | |
| 44 | // Works for tag, categories, and custom taxonomies. Keep in mind that terms for custom taxonomies might just |
| 45 | // disappear if the custom taxonomy is not registered the next time around. |
| 46 | public function handle_deleted_term($term_id) |
| 47 | { |
| 48 | $row = (object) ['term_id' => $term_id]; |
| 49 | $page = new Page_Term_Archive($row); |
| 50 | $page->update_cache(); |
| 51 | } |
| 52 | } |
| 53 |