' . esc_html__( 'Hivenza help centre: set its address in Settings, Hivenza.', 'hivenza' ) . '
' : ''; } $base = hivenza_origin() . '/help/' . rawurlencode( $slug ); if ( isset( $args['mode'] ) && 'link' === $args['mode'] ) { $label = ! empty( $args['label'] ) ? $args['label'] : __( 'Visit our help centre', 'hivenza' ); return '' . esc_html( $label ) . ''; } $placeholder = ! empty( $args['placeholder'] ) ? $args['placeholder'] : __( 'Search the help centre', 'hivenza' ); $button = ! empty( $args['button'] ) ? $args['button'] : __( 'Search', 'hivenza' ); $id = wp_unique_id( 'hivenza-help-q-' ); ob_start(); ?> '', 'mode' => 'search', 'placeholder' => '', 'button' => '', 'label' => '', ), $atts, 'hivenza_help' ); $atts['mode'] = 'link' === $atts['mode'] ? 'link' : 'search'; $atts['placeholder'] = sanitize_text_field( $atts['placeholder'] ); $atts['button'] = sanitize_text_field( $atts['button'] ); $atts['label'] = sanitize_text_field( $atts['label'] ); hivenza_help_styles(); return hivenza_help_html( $atts ); } add_shortcode( 'hivenza_help', 'hivenza_help_shortcode' ); /** * A few lines of CSS, printed once and only when a form is on the page. */ function hivenza_help_styles() { static $done = false; if ( $done ) { return; } $done = true; wp_register_style( 'hivenza-help', false, array(), HIVENZA_VERSION ); wp_enqueue_style( 'hivenza-help' ); wp_add_inline_style( 'hivenza-help', '.hivenza-help-search{display:flex;gap:.5rem;max-width:32rem}.hivenza-help-search input[type=search]{flex:1;min-width:0}' ); } /** * Register the block (rendered on the server). */ function hivenza_register_block() { register_block_type( HIVENZA_DIR . 'blocks/help-search', array( 'render_callback' => 'hivenza_render_help_block', ) ); wp_set_script_translations( 'hivenza-help-search-editor-script', 'hivenza' ); } add_action( 'init', 'hivenza_register_block' ); /** * Block output. * * @param array $attributes Block attributes. * @return string */ function hivenza_render_help_block( $attributes ) { $args = array( 'slug' => isset( $attributes['slug'] ) ? sanitize_text_field( $attributes['slug'] ) : '', 'placeholder' => isset( $attributes['placeholder'] ) ? sanitize_text_field( $attributes['placeholder'] ) : '', 'button' => isset( $attributes['button'] ) ? sanitize_text_field( $attributes['button'] ) : '', 'mode' => 'search', ); hivenza_help_styles(); return '