AJAX
2 years ago
Date_Range
2 years ago
Interval
3 years ago
Menu_Bar_Stats
2 years ago
Migrations
2 years ago
Models
2 years ago
Queries
2 years ago
Statistics
2 years ago
Tables
2 years ago
Utils
2 years ago
Campaign_Builder.php
2 years ago
Capability_Manager.php
3 years ago
Chart.php
3 years ago
Chart_Geo.php
2 years ago
Chart_SVG.php
3 years ago
City_To_Country_Converter.php
3 years ago
Dashboard_Options.php
2 years ago
Dashboard_Widget.php
3 years ago
Email_Chart.php
2 years ago
Email_Reports.php
2 years ago
Env.php
2 years ago
Filters.php
2 years ago
Geo_Database_Background_Job.php
2 years ago
Geo_Database_Downloader.php
2 years ago
Geoposition.php
2 years ago
Icon_Directory.php
2 years ago
Icon_Directory_Factory.php
2 years ago
Illuminate_Builder.php
3 years ago
Independent_Analytics.php
2 years ago
Interrupt.php
2 years ago
Known_Referrers.php
3 years ago
Plugin_Conflict_Detector.php
2 years ago
Query.php
2 years ago
Quick_Stats.php
2 years ago
REST_API.php
2 years ago
Real_Time.php
2 years ago
Reset_Database.php
3 years ago
Resource_Identifier.php
3 years ago
Settings.php
2 years ago
Sort_Configuration.php
3 years ago
Track_Resource_Changes.php
3 years ago
View.php
2 years ago
View_Counter.php
2 years ago
WP_Option_Cache_Bust.php
2 years ago
WooCommerce_Order.php
2 years ago
Track_Resource_Changes.php
61 lines
| 1 | <?php |
| 2 | |
| 3 | namespace IAWP_SCOPED\IAWP; |
| 4 | |
| 5 | use IAWP_SCOPED\IAWP\Models\Page_Author_Archive; |
| 6 | use IAWP_SCOPED\IAWP\Models\Page_Post_Type_Archive; |
| 7 | use IAWP_SCOPED\IAWP\Models\Page_Singular; |
| 8 | use IAWP_SCOPED\IAWP\Models\Page_Term_Archive; |
| 9 | class Track_Resource_Changes |
| 10 | { |
| 11 | public function __construct() |
| 12 | { |
| 13 | \add_action('post_updated', [$this, 'handle_updated_post']); |
| 14 | \add_action('profile_update', [$this, 'handle_updated_author']); |
| 15 | \add_action('registered_post_type', [$this, 'handle_registered_post_type']); |
| 16 | \add_action('edit_term', [$this, 'handle_updated_term']); |
| 17 | } |
| 18 | public function handle_updated_post($post_id) |
| 19 | { |
| 20 | $post = \get_post($post_id); |
| 21 | if (isset($post) && $post->post_status != 'trash') { |
| 22 | $row = (object) ['resource' => 'singular', 'singular_id' => $post_id]; |
| 23 | $page = new Page_Singular($row); |
| 24 | $page->update_cache(); |
| 25 | } |
| 26 | } |
| 27 | public function handle_updated_author($user_id) |
| 28 | { |
| 29 | $row = (object) ['resource' => 'author', 'author_id' => $user_id]; |
| 30 | $page = new Page_Author_Archive($row); |
| 31 | $page->update_cache(); |
| 32 | } |
| 33 | public function handle_registered_post_type($post_type) |
| 34 | { |
| 35 | $post_type_object = \get_post_type_object($post_type); |
| 36 | if ($post_type_object->_builtin == \false) { |
| 37 | $row = (object) ['resource' => 'post_type_archive', 'post_type' => $post_type]; |
| 38 | $page = new Page_Post_Type_Archive($row); |
| 39 | $page->update_cache(); |
| 40 | } |
| 41 | } |
| 42 | // Works for tag, categories, and custom taxonomies. Keep in mind that terms for custom taxonomies might just |
| 43 | // disappear if the custom taxonomy is not registered the next time around. |
| 44 | public function handle_updated_term($term_id) |
| 45 | { |
| 46 | global $wpdb; |
| 47 | // Term must be cleared from the cache in order to use the new term data |
| 48 | \clean_term_cache($term_id); |
| 49 | $row = (object) ['term_id' => $term_id]; |
| 50 | $page = new Page_Term_Archive($row); |
| 51 | $page->update_cache(); |
| 52 | $posts = \get_posts(['post_type' => \get_post_types(), 'category' => $term_id, 'numberposts' => -1]); |
| 53 | // Update cache for all singulars associated with a given term |
| 54 | foreach ($posts as $post) { |
| 55 | $row = (object) ['resource' => 'singular', 'singular_id' => $post->ID]; |
| 56 | $page = new Page_Singular($row); |
| 57 | $page->update_cache(); |
| 58 | } |
| 59 | } |
| 60 | } |
| 61 |