*/ public function get( string $post_type ): array { $stored = get_option( self::option_name( $post_type ), array() ); return wp_parse_args( is_array( $stored ) ? $stored : array(), self::defaults() ); } /** * @param array $settings */ public function update( string $post_type, array $settings ): bool { $sanitized = self::sanitize( wp_parse_args( $settings, self::defaults() ) ); return update_option( self::option_name( $post_type ), $sanitized ); } private static function option_name( string $post_type ): string { return self::OPTION_PREFIX . sanitize_key( $post_type ); } /** * @return array */ private static function defaults(): array { return array( 'schema_enabled' => true, // 'schema_type' used to sit here as an early-scaffold default that was // never read anywhere — removed in M66; the per-POST override // (MetaFields::SCHEMA_TYPE_OVERRIDE) is the real mechanism now. 'title_template' => '%post_title% %sep% %site_name%', 'description_template' => '%post_excerpt%', 'robots_index' => true, 'robots_follow' => true, 'author_schema_enabled' => true, 'og_image_id' => 0, 'og_acf_field' => '', ); } /** * @param array $settings * * @return array */ private static function sanitize( array $settings ): array { return array( 'schema_enabled' => (bool) $settings['schema_enabled'], 'title_template' => \AcezSeo\Support\TemplateSanitizer::sanitize_line( $settings['title_template'] ), // NOT sanitize_text_field — it eats %hex pairs like the %ac in %acf: (M49) 'description_template' => \AcezSeo\Support\TemplateSanitizer::sanitize_multiline( $settings['description_template'] ), 'robots_index' => (bool) $settings['robots_index'], 'robots_follow' => (bool) $settings['robots_follow'], 'author_schema_enabled' => (bool) $settings['author_schema_enabled'], 'og_image_id' => absint( $settings['og_image_id'] ), // NOT sanitize_text_field — this field holds an ACF token like // "%acf:my_field%" and core would eat "%ac" as a percent-encoded octet (M49). 'og_acf_field' => \AcezSeo\Support\TemplateSanitizer::sanitize_line( $settings['og_acf_field'] ?? '' ), ); } }