PluginProbe
BetterDocs – AI Documentation, Knowledge Base, MCP Server, Docs, Wikis, FAQ & Chatbot / 2.3.5
BetterDocs – AI Documentation, Knowledge Base, MCP Server, Docs, Wikis, FAQ & Chatbot v2.3.5
4.9.1 4.9.0 4.8.2 4.8.1 4.8.0 4.7.0 4.6.2 4.6.1 4.6.0 4.5.6 4.5.5 4.5.4 4.5.3 4.5.2 4.5.1 4.5.0 4.4.1 4.4.0 3.3.4 3.4.0 3.4.1 3.4.2 3.5.0 3.5.1 3.5.2 All 199 releases
betterdocs / includes / gutenberg / blocks / searchbox.php

searchbox.php in BetterDocs – AI Documentation, Knowledge Base, MCP Server, Docs, Wikis, FAQ & Chatbot 2.3.5, at includes/gutenberg/blocks/searchbox.php

86 lines 2.3 KB
No matching file
Up and down to move Enter to open Esc to close
Raw Download Zip
1 <?php
2
3 /**
4 * Functions to register client-side assets (scripts and stylesheets) for the
5 * Gutenberg block.
6 *
7 * @package betterdocs
8 */
9
10 /**
11 * Registers all block assets so that they can be enqueued through Gutenberg in
12 * the corresponding context.
13 *
14 * @see https://wordpress.org/gutenberg/handbook/designers-developers/developers/tutorials/block-tutorial/applying-styles-with-stylesheets/
15 */
16 function betterdocs_searchbox_block_init()
17 {
18 // Skip block registration if Gutenberg is not enabled/merged.
19 if (!function_exists('register_block_type')) {
20 return;
21 }
22 $dir = dirname(__FILE__);
23
24 $index_js = 'searchbox/index.js';
25 wp_register_script(
26 'betterdocs-searchbox-block-editor',
27 plugins_url($index_js, __FILE__),
28 array(
29 'wp-blocks',
30 'wp-i18n',
31 'wp-element',
32 'wp-editor',
33 'wp-block-editor',
34 'betterdocs-blocks-edit-post'
35 ),
36 filemtime("$dir/$index_js")
37 );
38
39 $editor_style = 'searchbox/style.css';
40 wp_register_style(
41 'betterdocs-searchbox-block-editor',
42 plugins_url($editor_style, __FILE__),
43 array(),
44 filemtime("$dir/$editor_style"),
45 'all'
46 );
47
48 register_block_type(__DIR__ . '/searchbox', array(
49 'editor_script' => 'betterdocs-searchbox-block-editor',
50 'editor_style' => 'betterdocs-searchbox-block-editor',
51 'render_callback' => 'betterdocs_searchbox_server_side_render'
52 ));
53 }
54 add_action('init', 'betterdocs_searchbox_block_init');
55
56 /**
57 * Search Box Server Side Render
58 */
59 function betterdocs_searchbox_server_side_render($attributes)
60 {
61
62 if (!is_admin()) {
63 wp_enqueue_style('betterdocs-searchbox-block-editor');
64 }
65
66 $attributes = wp_parse_args(
67 $attributes,
68 [
69 'blockId' => '',
70 'placeholderText' => esc_html__('Search', 'betterdocs'),
71 ]
72 );
73
74 $blockId = $attributes['blockId'];
75 $placeholderText = $attributes['placeholderText'];
76
77
78 $html = '';
79 $html .= '<div class="' . $blockId . ' betterdocs-searchbox-wrapper">';
80 $shortcode = sprintf('[betterdocs_search_form placeholder="' . $placeholderText . '"]', apply_filters('betterdocs_search_form_atts', []));
81 $html .= do_shortcode(shortcode_unautop($shortcode));
82 $html .= '</div>';
83
84 return $html;
85 }
86