.enabled`, so every module section carries that flag. * * @return bool True when enabled. */ public function is_enabled(): bool { return (bool) Options::get( $this->slug() . '.enabled', true ); } /** * Audit checks contributed by this module. * * @return array List of checks. */ public function checks(): array { return []; } /** * Reacts to a settings save: drops the cache, and asks for a rewrite flush * when the module's own section changed. * * A module's section holds its `enabled` flag, and a switched off module * registers no file — so its rewrite rule has to go with it, and come back * when it is switched on again. Anything else the section holds can change * a file's contents, which the cache version bump takes care of. * * The per-request memos go too. `Options` keeps the settings in sync with * itself when they are saved, but it cannot know that `Data\SiteData`, * `Data\ContentData` and `Detect\Environment` are each holding an answer * derived from the settings it just replaced — so a settings screen that * saves and then re-renders would otherwise show the values from before * the save. * * Public because WordPress invokes hook callbacks from outside the class. * * @param string $section Settings section that changed, or `*` for all of them. * @return void */ public function on_settings_updated( string $section = '*' ): void { Cache::invalidate_all(); SiteData::reset(); ContentData::reset(); Environment::reset(); if ( '' === $section || '*' === $section || $this->slug() === $section ) { update_option( 'acid_aeo_flush_needed', 1 ); } } /** * Whether a post that just changed can appear in what this module publishes. * * An autosave, a revision and a post type that is not published anywhere * cannot change a generated file, and each of them would cost a cache * version bump on every keystroke the editor sends. * * @param int $post_id Post ID. * @param mixed $post Post object, when the hook passed one. A deleted post is * gone from the database, so its type is read from here. * @return bool True when a change to this post is worth a cache bump. */ protected function is_listed_post( int $post_id, $post = null ): bool { if ( $post_id <= 0 || wp_is_post_autosave( $post_id ) || wp_is_post_revision( $post_id ) ) { return false; } $type = $post instanceof WP_Post ? (string) $post->post_type : (string) get_post_type( $post_id ); if ( '' === $type ) { return false; } $object = get_post_type_object( $type ); return null !== $object && ! empty( $object->public ); } }