2, 'title' => __( 'AddSynapse Search', 'addsynapse-search-filter' ), 'category' => 'widgets', 'icon' => 'search', 'description' => __( 'Smart product search field.', 'addsynapse-search-filter' ), 'attributes' => array( 'placeholder' => array( 'type' => 'string', 'default' => '', ), 'className' => array( 'type' => 'string', 'default' => '', ), ), 'editor_script' => 'addsynapse-search-block-editor', 'render_callback' => array( __CLASS__, 'render' ), ) ); } /** * Server-side render — απλά ανακατευθύνει στο shortcode ώστε να υπάρχει * μία μόνο πηγή αλήθειας για το markup. * * @param array $attributes Block attributes. * @return string */ public static function render( $attributes ) { if ( ! class_exists( 'Addsynapse_Search_Shortcode' ) ) { return ''; } $sc_atts = array(); if ( ! empty( $attributes['placeholder'] ) ) { $sc_atts['placeholder'] = sanitize_text_field( $attributes['placeholder'] ); } if ( ! empty( $attributes['className'] ) ) { $sc_atts['class'] = sanitize_html_class( $attributes['className'] ); } return Addsynapse_Search_Shortcode::render( $sc_atts ); } /** * Inline editor script (wp.blocks.registerBlockType). Δεν αγγίζει το * frontend· τρέχει μόνο μέσα στον block editor. * * @return string */ protected static function editor_script() { $title = esc_js( __( 'AddSynapse Search', 'addsynapse-search-filter' ) ); $description = esc_js( __( 'Smart product search field.', 'addsynapse-search-filter' ) ); $panel_title = esc_js( __( 'Search settings', 'addsynapse-search-filter' ) ); $field_label = esc_js( __( 'Placeholder', 'addsynapse-search-filter' ) ); $preview = esc_js( __( 'AddSynapse Search — preview available on the frontend', 'addsynapse-search-filter' ) ); return " ( function( blocks, element, blockEditor, components ) { if ( ! blocks || ! element || ! blockEditor ) { return; } var el = element.createElement; var InspectorControls = blockEditor.InspectorControls; var useBlockProps = blockEditor.useBlockProps; var PanelBody = components.PanelBody; var TextControl = components.TextControl; blocks.registerBlockType( 'addsynapse-search/search', { title: '{$title}', description: '{$description}', icon: 'search', category: 'widgets', attributes: { placeholder: { type: 'string', default: '' }, className: { type: 'string', default: '' } }, edit: function( props ) { var attributes = props.attributes; var setAttributes = props.setAttributes; var blockProps = useBlockProps ? useBlockProps() : {}; return el( 'div', blockProps, el( InspectorControls, {}, el( PanelBody, { title: '{$panel_title}' }, el( TextControl, { label: '{$field_label}', value: attributes.placeholder || '', onChange: function( value ) { setAttributes( { placeholder: value } ); } } ) ) ), el( 'div', { className: 'wosearch-block-editor-placeholder' }, el( 'span', { className: 'dashicons dashicons-search' } ), el( 'span', {}, ' {$preview}' ) ) ); }, save: function() { return null; } } ); } )( window.wp && window.wp.blocks, window.wp && window.wp.element, window.wp && window.wp.blockEditor, window.wp && window.wp.components ); "; } }