PluginProbe
BetterDocs – AI Documentation, Knowledge Base, MCP Server, Docs, Wikis, FAQ & Chatbot / 3.5.3
BetterDocs – AI Documentation, Knowledge Base, MCP Server, Docs, Wikis, FAQ & Chatbot v3.5.3
4.9.2 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 All 200 releases
← All changes | includes/Editors/BlockEditor/Block.php +145 -151 4.5.63.5.3 View file →
@@ -2,9 +2,9 @@
2 2
3 3 namespace WPDeveloper\BetterDocs\Editors\BlockEditor;
4 4
5 5 if ( ! defined( 'ABSPATH' ) ) {
6 - exit; // Exit if accessed directly
6 + exit; // Exit if accessed directly
7 7 }
8 8
9 9 use WPDeveloper\BetterDocs\Utils\Base;
10 10 use WPDeveloper\BetterDocs\Traits\EditorHelper;
@@ -18,194 +18,188 @@
18 18 *
19 19 * @since 2.5.0
20 20 */
21 21 abstract class Block extends Base {
22 - use EditorHelper;
22 + use EditorHelper;
23 23
24 - public $is_pro = false;
24 + public $is_pro = false;
25 25
26 - /**
27 - * Enqueue
28 - * @var Enqueue
29 - */
30 - protected $assets_manager = null;
26 + /**
27 + * Enqueue
28 + * @var Enqueue
29 + */
30 + protected $assets_manager = null;
31 31
32 - protected $dir = '';
32 + protected $dir = '';
33 33
34 - protected $editor_scripts = [ 'betterdocs-blocks-editor' ];
34 + protected $editor_scripts = ['betterdocs-blocks-editor'];
35 35
36 - protected $editor_styles = [ 'betterdocs-blocks-editor' ];
36 + protected $editor_styles = ['betterdocs-blocks-editor'];
37 37
38 - protected $frontend_styles = [];
39 - protected $frontend_scripts = [];
38 + protected $frontend_styles = [];
39 + protected $frontend_scripts = [];
40 40
41 - /**
42 - * unique name of block
43 - * @return string
44 - */
45 - abstract public function get_name();
41 + /**
42 + * unique name of block
43 + * @return string
44 + */
45 + abstract public function get_name();
46 46
47 - /**
48 - * Block can be enabled or not.
49 - *
50 - * Override if needed.
51 - *
52 - * @return bool
53 - */
54 - public function can_enable() {
55 - return true;
56 - }
47 + /**
48 + * Block can be enabled or not.
49 + *
50 + * Override if needed.
51 + *
52 + * @return bool
53 + */
54 + public function can_enable() {
55 + return true;
56 + }
57 57
58 - public function path( $name = '' ) {
59 - if ( empty( $name ) ) {
60 - $name = $this->get_name();
61 - }
58 + public function path( $name = '' ) {
59 + if ( empty( $name ) ) {
60 + $name = $this->get_name();
61 + }
62 62
63 - return BETTERDOCS_BLOCKS_DIRECTORY . $name;
64 - }
63 + return BETTERDOCS_BLOCKS_DIRECTORY . $name;
64 + }
65 65
66 - public function register_block_type( $name, ...$args ) {
67 - return register_block_type(
68 - apply_filters_ref_array( 'betterdocs.blocks.path', [ $this->path( $name ), $name, &$this ] ),
69 - ...$args
70 - );
71 - }
66 + public function register_block_type( $name, ...$args ) {
67 + return register_block_type(
68 + apply_filters_ref_array( 'betterdocs.blocks.path', [ $this->path( $name ), $name, &$this ] ),
69 + ...$args
70 + );
71 + }
72 72
73 - public function load_frontend_styles() {
74 - if ( empty( $this->frontend_styles ) ) {
75 - return;
76 - }
73 + public function load_frontend_styles() {
74 + if ( empty( $this->frontend_styles ) ) {
75 + return;
76 + }
77 77
78 - foreach ( $this->frontend_styles as $handle ) {
79 - wp_enqueue_style( $handle );
80 - }
81 - }
78 + foreach ( $this->frontend_styles as $handle ) {
79 + wp_enqueue_style( $handle );
80 + }
81 + }
82 82
83 - public function load_frontend_scripts() {
84 - if ( empty( $this->frontend_scripts ) ) {
85 - return;
86 - }
83 + public function load_frontend_scripts() {
84 + if ( empty( $this->frontend_scripts ) ) {
85 + return;
86 + }
87 87
88 - foreach ( $this->frontend_scripts as $handle ) {
89 - wp_enqueue_script( $handle );
90 - }
91 - }
88 + foreach ( $this->frontend_scripts as $handle ) {
89 + wp_enqueue_script( $handle );
90 + }
91 + }
92 92
93 - public function load_scripts() {
94 - $this->load_frontend_styles();
95 - $this->load_frontend_scripts();
96 - }
93 + public function load_scripts() {
94 + $this->load_frontend_styles();
95 + $this->load_frontend_scripts();
96 + }
97 97
98 - public function string_to_array( $data = [], $key = 'value' ) {
99 - $_return_val = [];
98 + public function string_to_array( $data = [], $key = 'value' ) {
99 + $_return_val = [];
100 100
101 - if ( is_string( $data ) && ! empty( $data ) ) {
102 - $_return_val = json_decode( $data, true );
103 - $_return_val = array_map(
104 - function ( $item ) use ( &$key ) {
105 - return $item[ $key ];
106 - },
107 - $_return_val == null || empty( $_return_val ) ? [] : $_return_val
108 - );
109 - }
101 + if ( is_string( $data ) && ! empty( $data ) ) {
102 + $_return_val = json_decode( $data, true );
103 + $_return_val = array_map( function ( $item ) use ( &$key ) {
104 + return $item[$key];
105 + }, $_return_val );
106 + }
110 107
111 - return $_return_val;
112 - }
108 + return $_return_val;
109 + }
113 110
114 - public function register( $assets_manager ) {
115 - $this->assets_manager = $assets_manager;
111 + public function register( $assets_manager ) {
112 + $this->assets_manager = $assets_manager;
116 113
117 - $_args = [];
114 + $_args = [];
118 115
119 - if ( method_exists( $this, 'register_scripts' ) ) {
120 - $this->register_scripts();
121 - }
116 + if ( method_exists( $this, 'register_scripts' ) ) {
117 + $this->register_scripts();
118 + }
122 119
123 - if ( method_exists( $this, 'render_callback' ) ) {
124 - $_args['render_callback'] = function ( $attributes, $content ) {
125 - if ( ! is_admin() ) {
126 - $this->load_scripts();
127 - }
128 - return $this->render_callback( $attributes, $content );
129 - };
130 - }
120 + if ( method_exists( $this, 'render_callback' ) ) {
121 + $_args['render_callback'] = function ( $attributes, $content ) {
122 + if ( ! is_admin() ) {
123 + $this->load_scripts();
124 + }
125 + return $this->render_callback( $attributes, $content );
126 + };
127 + }
131 128
132 - if ( ( ! empty( $this->frontend_scripts ) || ! empty( $this->frontend_styles ) ) && ! method_exists( $this, 'render_callback' ) ) {
133 - $_args['render_callback'] = function ( $attributes, $content ) {
134 - if ( ! is_admin() ) {
135 - $this->load_scripts();
136 - }
137 - return $content;
138 - };
139 - }
129 + if ( ( ! empty( $this->frontend_scripts ) || ! empty( $this->frontend_styles ) ) && ! method_exists( $this, 'render_callback' ) ) {
130 + $_args['render_callback'] = function ( $attributes, $content ) {
131 + if ( ! is_admin() ) {
132 + $this->load_scripts();
133 + }
134 + return $content;
135 + };
136 + }
140 137
141 - $_args['editor_script'] = $this->editor_scripts;
142 - $_args['editor_script_handles'] = $this->editor_scripts;
138 + $_args['editor_script'] = $this->editor_scripts;
139 + $_args['editor_script_handles'] = $this->editor_scripts;
143 140
144 - $_args['editor_style'] = $this->editor_styles;
145 - $_args['editor_style_handles'] = $this->editor_styles;
141 + $_args['editor_style'] = $this->editor_styles;
142 + $_args['editor_style_handles'] = $this->editor_styles;
146 143
147 - if ( property_exists( $this, 'attributes' ) ) {
148 - $_args['attributes'] = $this->attributes;
149 - }
144 + if ( property_exists( $this, 'attributes' ) ) {
145 + $_args['attributes'] = $this->attributes;
146 + }
150 147
151 - return $this->register_block_type( $this->get_name(), $_args );
152 - }
148 + return $this->register_block_type( $this->get_name(), $_args );
149 + }
153 150
154 - public function get_default_attributes() {
155 - return [];
156 - }
151 + public function get_default_attributes() {
152 + return [];
153 + }
157 154
158 - abstract public function render( $attributes, $content );
155 + abstract public function render( $attributes, $content );
159 156
160 - public function render_callback( $attributes, $content ) {
161 - $this->attributes = wp_parse_args( $attributes, $this->get_default_attributes() );
162 - $this->attributes = $this->remove_deprecated_attributes( $this->attributes, false, false );
157 + public function render_callback( $attributes, $content ) {
158 + $this->attributes = wp_parse_args( $attributes, $this->get_default_attributes() );
159 + $this->attributes = $this->remove_deprecated_attributes( $this->attributes, false, false );
163 160
164 - do_action_ref_array( 'betterdocs_before_render', [ & $this, 'blocks' ] );
161 + do_action_ref_array( 'betterdocs_before_render', [ & $this, 'blocks'] );
165 162
166 - ob_start();
167 - $this->render( $this->attributes, $content );
168 - $content = ob_get_clean();
163 + ob_start();
164 + $this->render( $this->attributes, $content );
165 + $content = ob_get_clean();
169 166
170 - do_action_ref_array( 'betterdocs_after_render', [ & $this, 'blocks' ] );
167 + do_action_ref_array( 'betterdocs_after_render', [ & $this, 'blocks'] );
171 168
172 - return $content;
173 - }
169 + return $content;
170 + }
174 171
175 - public function normalize_attributes( $attributes, $mixed_settings = [] ) {
176 - $mixed_settings = wp_parse_args(
177 - [
178 - 'prefix' => 'count_prefix',
179 - 'suffix' => 'count_suffix',
180 - 'suffixSingular' => 'count_suffix_singular',
181 - 'showIcon' => 'show_icon',
182 - 'showTitle' => 'show_title',
183 - 'titleTag' => 'title_tag',
184 - 'showCount' => 'show_count',
185 - 'showButton' => 'show_button',
186 - 'showButtonIcon' => 'show_button_icon',
187 - 'buttonIconPosition' => 'button_icon_position',
188 - 'buttonText' => 'button_text',
189 - 'buttonIcon' => 'button_icon',
190 - 'showList' => 'show_list',
191 - 'showHeader' => 'show_header',
192 - 'postsPerPage' => 'post_per_page',
193 - 'postsOrderBy' => 'post_orderby',
194 - 'postsOrder' => 'post_order',
195 - 'enableNestedSubcategory' => 'nested_subcategory'
196 - ],
197 - $mixed_settings
198 - );
172 + public function normalize_attributes( $attributes, $mixed_settings = [] ) {
173 + $mixed_settings = wp_parse_args( [
174 + 'prefix' => 'count_prefix',
175 + 'suffix' => 'count_suffix',
176 + 'suffixSingular' => 'count_suffix_singular',
177 + 'showIcon' => 'show_icon',
178 + 'showTitle' => 'show_title',
179 + 'titleTag' => 'title_tag',
180 + 'showCount' => 'show_count',
181 + 'showButton' => 'show_button',
182 + 'showButtonIcon' => 'show_button_icon',
183 + 'buttonIconPosition' => 'button_icon_position',
184 + 'buttonText' => 'button_text',
185 + 'buttonIcon' => 'button_icon',
186 + 'showList' => 'show_list',
187 + 'showHeader' => 'show_header',
188 + 'postsPerPage' => 'post_per_page',
189 + 'postsOrderBy' => 'post_orderby',
190 + 'postsOrder' => 'post_order',
191 + 'enableNestedSubcategory' => 'nested_subcategory'
192 + ], $mixed_settings );
199 193
200 - $_return_value = [];
194 + $_return_value = [];
201 195
202 - foreach ( $mixed_settings as $key => $old_key ) {
203 - if ( isset( $attributes[ $key ] ) ) {
204 - $_return_value[ $old_key ] = $attributes[ $key ];
205 - unset( $attributes[ $key ] );
206 - }
207 - }
196 + foreach ( $mixed_settings as $key => $old_key ) {
197 + if ( isset( $attributes[$key] ) ) {
198 + $_return_value[$old_key] = $attributes[$key];
199 + unset( $attributes[$key] );
200 + }
201 + }
208 202
209 - return array_merge( $attributes, $_return_value );
210 - }
203 + return array_merge( $attributes, $_return_value );
204 + }
211 205 }