* @copyright 2026 webhead GmbH */ declare( strict_types=1 ); namespace Webhead\WP\SearchCloud\Shortcodes; use Webhead\WP\SearchCloud\DTO\Search_Placement; use Webhead\WP\SearchCloud\Frontend\Placement_Config; use Webhead\WP\SearchCloud\Frontend\Search_Surface; use Webhead\WP\SearchCloud\Dependencies\Webhead\WP\Framework\Shortcodes\Abstract_Shortcode; defined( 'ABSPATH' ) || exit; /** * @since 1.4.0 */ final class Search_Shortcode extends Abstract_Shortcode { public const TAG = 'searcio'; public function __construct( private Placement_Config $config, private Search_Surface $surface ) {} public function tag(): string { return self::TAG; } public function description(): string { return __( 'The Searcio search: a magnifier or a search field that opens the search window.', 'searcio' ); } /** * The Placement tab's settings, in the page's language. `shortcode_atts()` * fills an attribute that was left out from these, and drops one this * list does not name. * * @return array */ public function defaults(): array { return $this->config->search()->to_shortcode_defaults() + [ 'class' => '' ]; } /** * @param array $attributes */ public function render( array $attributes = [], ?string $content = null, string $tag = '' ): string { $placement = Search_Placement::from_array( $attributes, $this->config->search() ); $class = is_string( $attributes['class'] ?? null ) ? implode( ' ', array_map( 'sanitize_html_class', preg_split( '/\s+/', trim( $attributes['class'] ) ) ?: [] ) ) : ''; return $this->surface->search( $placement, [ 'className' => trim( $class ) ] ); } }