mirror of
https://gh.wpcy.net/https://github.com/elementor/one-click-accessibility.git
synced 2026-04-21 09:56:44 +08:00
* [APP-1401] clear cache on update * [APP-1401] clear cache on update * [APP-1401] clear cache on update * [APP-1401] clear cache on update
53 lines
1.4 KiB
PHP
53 lines
1.4 KiB
PHP
<?php
|
|
|
|
namespace EA11y\Modules\Remediation\Components;
|
|
|
|
use EA11y\Modules\Remediation\Database\Page_Entry;
|
|
|
|
if ( ! defined( 'ABSPATH' ) ) {
|
|
exit; // Exit if accessed directly
|
|
}
|
|
|
|
/**
|
|
* Class Cache_Cleaner
|
|
*/
|
|
class Cache_Cleaner {
|
|
public function clean_taxonomy_cache( $term_id, $tt_id, $taxonomy ) {
|
|
// Only for public taxonomies
|
|
if ( ! in_array( $taxonomy, get_taxonomies( [ 'public' => true ] ), true ) ) {
|
|
return;
|
|
}
|
|
|
|
$term = get_term( $term_id, $taxonomy );
|
|
$term_url = get_term_link( $term );
|
|
|
|
if ( is_wp_error( $term_url ) ) {
|
|
return;
|
|
}
|
|
|
|
$url_trimmed = rtrim( $term_url, '/' );
|
|
Page_Entry::clear_cache( $url_trimmed );
|
|
}
|
|
|
|
public function clean_post_cache( $post_ID, $post, $update ) {
|
|
// Only on publish post for public post type
|
|
$post_type_object = get_post_type_object( $post->post_type );
|
|
if (
|
|
( defined( 'DOING_AUTOSAVE' ) && DOING_AUTOSAVE ) ||
|
|
( ! $post_type_object || ! $post_type_object->public ) ||
|
|
'publish' !== $post->post_status
|
|
) {
|
|
return;
|
|
}
|
|
|
|
$post_url = get_permalink( $post_ID );
|
|
$url_trimmed = rtrim( $post_url, '/' );
|
|
Page_Entry::clear_cache( $url_trimmed );
|
|
}
|
|
|
|
public function __construct() {
|
|
add_action( 'created_term', [ $this, 'clean_taxonomy_cache' ], 10, 3 );
|
|
add_action( 'edited_term', [ $this, 'clean_taxonomy_cache' ], 10, 3 );
|
|
add_action( 'save_post', [ $this, 'clean_post_cache' ], 10, 3 );
|
|
}
|
|
}
|