Overview

Classes

  • xu
  • Xu\Foundation\Foundation
  • Xu\Foundation\Jsonable
  • Xu\Model\Collection
  • Xu\Model\Model

Functions

  • xu
  • xu_add_option
  • xu_attachment_url_to_postid
  • xu_cache_delete
  • xu_cache_delete_group
  • xu_cache_get
  • xu_cache_key
  • xu_camel_case
  • xu_clean_attachment_cache
  • xu_clean_nav_menu_cache
  • xu_clean_post_cache
  • xu_contains
  • xu_convert_to_string
  • xu_current_attachment_url_to_postid
  • xu_current_url
  • xu_current_url_to_postid
  • xu_dashify
  • xu_delete_option
  • xu_delete_site_transient
  • xu_delete_transient
  • xu_doing_ajax
  • xu_ends_with
  • xu_get_class_name
  • xu_get_model
  • xu_get_option
  • xu_get_option_name
  • xu_get_option_post_id
  • xu_get_posts
  • xu_get_site_transient
  • xu_get_top_parent_post
  • xu_get_top_parent_post_type
  • xu_get_top_parent_post_type_object
  • xu_get_transient
  • xu_is_empty
  • xu_is_http_method
  • xu_is_json
  • xu_is_post_type
  • xu_is_wp
  • xu_is_xml
  • xu_post_exists
  • xu_register_large_option_post_type
  • xu_snake_case
  • xu_starts_with
  • xu_strip_spaces
  • xu_studly_case
  • xu_update_option
  • xu_url_to_postid
  • xu_valid_personnummer
  • xu_wp_get_attachment_image
  • xu_wp_get_attachment_image_sizes
  • xu_wp_get_attachment_image_src
  • xu_wp_get_attachment_image_srcset
  • xu_wp_get_attachment_url
  • xu_wp_nav_menu
  • Overview
  • Class
 1: <?php
 2: 
 3: /**
 4:  * Clean attachment cache.
 5:  *
 6:  * @param  int $post_id
 7:  */
 8: function xu_clean_attachment_cache( $post_id = 0 ) {
 9:     $groups = [
10:         'xu_wp_get_attachment_image',
11:         'xu_wp_get_attachment_image_sizes',
12:         'xu_wp_get_attachment_image_src',
13:         'xu_wp_get_attachment_image_srcset'
14:     ];
15: 
16:     // Delete all group keys for this post.
17:     foreach ( $groups as $group ) {
18:         xu_cache_delete_group( $group, $post_id );
19:     }
20: 
21:     // Cache to delete on save post.
22:     // Order: key (mixed), group (string)
23:     $delete_items = [
24:         [get_permalink( $post_id ), 'xu_attachment_url_to_postid'],
25:         [$post_id, 'xu_wp_get_attachment_url']
26:     ];
27: 
28:     // Delete cache items on save.
29:     foreach ( $delete_items as $item ) {
30:         call_user_func_array( 'xu_cache_delete', $item );
31:     }
32: }
33: add_action( 'clean_attachment_cache', 'xu_clean_attachment_cache' );
34: 
35: /**
36:  * Clean nav menu cache.
37:  */
38: function xu_clean_nav_menu_cache() {
39:     xu_cache_delete_group( 'xu_wp_nav_menu' );
40: }
41: add_action( 'wp_create_nav_menu', 'xu_clean_nav_menu_cache' );
42: add_action( 'wp_update_nav_menu', 'xu_clean_nav_menu_cache' );
43: add_action( 'wp_delete_nav_menu', 'xu_clean_nav_menu_cache' );
44: 
45: /**
46:  * Clean post cache.
47:  *
48:  * @param  int $post_id
49:  */
50: function xu_clean_post_cache( $post_id = 0 ) {
51:     if ( wp_is_post_revision( $post_id ) ) {
52:         return;
53:     }
54: 
55:     if ( ! get_post_status( $post_id ) ) {
56:         return;
57:     }
58: 
59:     $groups = [
60:         'xu_get_posts'
61:     ];
62: 
63:     // Delete all group keys.
64:     foreach ( $groups as $group ) {
65:         xu_cache_delete_group( $group );
66:     }
67: 
68:     // Cache to delete on save post.
69:     // Order: key (mixed), group (string)
70:     $delete_items = [
71:         [get_permalink( $post_id ), 'xu_url_to_postid']
72:     ];
73: 
74:     // Delete cache items on save.
75:     foreach ( $delete_items as $item ) {
76:         call_user_func_array( 'xu_cache_delete', $item );
77:     }
78: }
79: add_action( 'clean_post_cache', 'xu_clean_post_cache' );
80: 
API documentation generated by ApiGen