ID ); } } /** * @param int $post_id Post ID. * @param \WP_Post $after Post after the update. * @param \WP_Post $before Post before the update. */ public function slug_changed( $post_id, $after, $before ) { if ( $after->post_name !== $before->post_name ) { CacheBackend::bump_generation( ABLOCKS_LINK_GUARD_GENERATION_OPTION ); } } /** * A deleted target makes its links dead, the same as unpublishing it. * * @param int $post_id Deleted post. */ public function deleted( $post_id ) { self::announce( $post_id ); } /** * Posts whose content links to a post. * * @param int $target_id Linked post. * @return int[] */ public static function linking_posts( $target_id ) { global $wpdb; // phpcs:ignore WordPress.DB.DirectDatabaseQuery.DirectQuery, WordPress.DB.DirectDatabaseQuery.NoCaching $ids = $wpdb->get_col( $wpdb->prepare( "SELECT DISTINCT post_id FROM {$wpdb->postmeta} WHERE meta_key = %s AND meta_value = %s", Frontend::TARGET_META, (string) (int) $target_id ) ); return array_map( 'intval', $ids ); } private static function announce( $target_id ) { $ids = self::linking_posts( $target_id ); if ( ! $ids ) { return; } foreach ( $ids as $id ) { clean_post_cache( $id ); } /** * Posts whose rendered content changed because a post they link to was * published, unpublished or deleted. Purge these from any page cache. * * @param int[] $post_ids Linking posts. * @param int $target_id The post whose status changed. */ do_action( 'ablocks/link_guard/linking_posts_changed', $ids, (int) $target_id ); } }