get_id(), [ $this, 'bump' ], 10, 0 ); add_action( 'update_option_adpresso_settings_' . $tab->get_id(), [ $this, 'bump' ], 10, 0 ); } ); // Public extension point add_action( 'adpresso_invalidate_pipeline_cache', [ $this, 'bump' ], 10, 0 ); } /** * Only bumps if the deleted/trashed/untrashed post is actually one of ours. * * @param int $post_id The post being deleted/trashed/untrashed. * * @return void */ public function maybe_bump_for_post( int $post_id ): void { $post_type = get_post_type( $post_id ); if ( in_array( $post_type, [ Constants::POST_TYPE_AD, Constants::POST_TYPE_GROUP, Constants::POST_TYPE_PLACEMENT ], true ) ) { $this->bump(); } } /** * Current generation. 1 if nothing has bumped it yet this install. * * @return int */ public static function get(): int { return (int) get_option( self::OPTION, 1 ); } /** * Atomically increments the generation, making every cache key built from the previous value irrelevant. * * @return void */ public function bump(): void { global $wpdb; $updated = $wpdb->query( $wpdb->prepare( "UPDATE {$wpdb->options} SET option_value = option_value + 1 WHERE option_name = %s", self::OPTION ) ); if ( ! $updated ) { add_option( self::OPTION, 2, '', 'yes' ); } wp_cache_delete( self::OPTION, 'options' ); } }