This commit is contained in:
Javier Casares 2026-06-08 18:01:39 +00:00
commit b6a55a7f04
27 changed files with 2221 additions and 45 deletions

View file

@ -222,6 +222,40 @@ class Settings {
return in_array( $raw, self::TAB_KEYS, true ) ? $raw : 'general';
}
/**
* Returns the effective settings for the current context.
*
* In Multisite central mode, reads from the shared network site option so that
* all providers and scanners pick up network-wide API credentials and filter
* lists without changing per-site DB records.
*
* @return array<string, mixed>
*/
public static function get_effective_settings(): array {
if ( is_multisite() && 'central' === get_site_option( 'robotstxt_mediaaudit_network_mode', 'per_site' ) ) {
$raw = get_site_option( 'robotstxt_mediaaudit_network_settings', array() );
} else {
$raw = get_option( self::OPTION_NAME, array() );
}
return is_array( $raw ) ? $raw : array();
}
/**
* Sanitizes a settings array for the network admin, merging against $current.
*
* Mirrors the tab-based logic of sanitize() but accepts the existing values
* as a parameter rather than reading from get_option(), so it can be used
* for both per-site and network site options.
*
* @param array<string, mixed> $input Raw POST input (must include '_tab').
* @param array<string, mixed> $current Existing option values to merge against.
*
* @return array<string, mixed>
*/
public function sanitize_for_network( array $input, array $current ): array {
return $this->sanitize_with_base( $input, $current );
}
/**
* Registers all settings, sections, and fields via the WordPress Settings API.
*
@ -367,7 +401,19 @@ class Settings {
public function sanitize( $input ): array {
$raw = get_option( self::OPTION_NAME, array() );
$current = is_array( $raw ) ? $raw : array();
$output = $current;
return $this->sanitize_with_base( $input, $current );
}
/**
* Core tab-based sanitization logic shared by sanitize() and sanitize_for_network().
*
* @param mixed $input Raw POST input.
* @param array<string, mixed> $current Existing values to merge against.
*
* @return array<string, mixed>
*/
private function sanitize_with_base( $input, array $current ): array {
$output = $current;
if ( ! is_array( $input ) ) {
return $output;
@ -430,11 +476,18 @@ class Settings {
}
/**
* Sanitises a newline-separated list of hostnames into a deduplicated array.
* Public proxy for sanitize_hostname_list(), used by Network\Settings.
*
* Accepts plain hostnames (example.com) and explicit wildcard prefixes
* (*.example.com). A plain hostname implicitly covers all its subdomains
* at match time.
* @param mixed $raw Raw textarea value.
*
* @return list<string>
*/
public function sanitize_hostname_list_public( mixed $raw ): array {
return $this->sanitize_hostname_list( $raw );
}
/**
* Sanitises a newline-separated hostname list into a deduplicated sorted array.
*
* @param mixed $raw Raw textarea value.
*