getInputs() ); $what = $fields ? implode( ', ', $fields ) : 'nothing'; return "Change Timetics cosmetic settings: {$what}"; } public function get_approval_inputs(): array { return $this->getInputs(); } public function __invoke( ?string $business_name = null, ?string $primary_color = null, ?string $secondary_color = null ): array { $check = $this->guard_admin(); if ( $check ) { return $check; } if ( null === $business_name && null === $primary_color && null === $secondary_color ) { return [ 'error' => 'No changes were specified. Provide business_name, primary_color, or secondary_color.' ]; } if ( ! function_exists( 'timetics_update_option' ) ) { return [ 'error' => 'Timetics settings are unavailable.' ]; } $updates = []; if ( null !== $business_name ) { $name = sanitize_text_field( $business_name ); if ( '' === $name ) { return [ 'error' => 'business_name cannot be empty.' ]; } $updates['business_name'] = $name; } foreach ( [ 'primary_color' => $primary_color, 'secondary_color' => $secondary_color, ] as $key => $value ) { if ( null === $value ) { continue; } $color = $this->sanitize_color( $value ); if ( '' === $color ) { return [ 'error' => "{$key} must be a hex colour like \"#4f46e5\"." ]; } $updates[ $key ] = $color; } try { foreach ( $updates as $key => $value ) { timetics_update_option( $key, $value ); } return [ 'success' => true, 'updated' => $updates, 'message' => 'Settings updated: ' . implode( ', ', array_keys( $updates ) ) . '.', ]; } catch ( \Throwable $e ) { Log::error( 'Timetics_Update_Settings_Tool error', [ 'error' => $e->getMessage() ] ); return [ 'error' => 'Failed to update settings: ' . $e->getMessage() ]; } } /** * Normalise a user-supplied colour to a safe hex value. * * Accepts a hex colour with or without a leading `#` and returns the * canonical `#rrggbb`/`#rgb` form, or '' if it is not a valid hex colour. * * @param string $value Raw colour input. * @return string */ private function sanitize_color( string $value ): string { $value = trim( $value ); if ( '' === $value ) { return ''; } if ( '#' !== $value[0] ) { $value = '#' . $value; } return (string) sanitize_hex_color( $value ); } }