PluginProbe
Tag, Category, and Taxonomy Manager – Autotagger Automatically Add Terms / trunk
Tag, Category, and Taxonomy Manager – Autotagger Automatically Add Terms vtrunk
3.53.0 3.52.0 3.51.0 3.50.0 3.45.0 3.38.0 3.4.0 3.4.1 3.4.2 3.4.3 3.4.4 3.4.5 3.40.0 3.40.1 3.41.0 3.42.0 3.43.0 3.44.0 3.5.0 3.5.1 3.5.2 3.5.3 3.6.0 3.6.1 3.6.2 All 177 releases
simple-tags / blocks / tag-clouds.php

tag-clouds.php in Tag, Category, and Taxonomy Manager – Autotagger Automatically Add Terms trunk, at blocks/tag-clouds.php

91 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 * Register our block.
5 */
6 function st_tag_clouds_block_init()
7 {
8 global $post, $pagenow;
9
10 if (!function_exists('register_block_type')) {
11 return;
12 }
13
14 if ($pagenow === 'widgets.php') {
15 return;
16 }
17
18 // Register our block editor script.
19 wp_register_script(
20 'st-block-tag-clouds',
21 STAGS_URL . '/blocks/src/tag-clouds.js',
22 ['wp-blocks', 'wp-element', 'wp-components', 'wp-editor']
23 );
24
25 // Register our block, and explicitly define the attributes we accept.
26 $tagcloud_data = taxopress_get_tagcloud_data();
27
28 $options = [];
29 $default = '';
30 if (count($tagcloud_data) > 0) {
31 $sn = 0;
32 foreach ($tagcloud_data as $key => $value) {
33 $sn++;
34 if ($sn === 1) {
35 $default = $key;
36 }
37 $options[] = ['label' => $value['title'], 'value' => $key];
38 }
39 }
40
41 register_block_type('taxopress/tag-clouds', [
42 'attributes' => [
43 'tagcloud_id' => [
44 'type' => 'string',
45 'default' => $default,
46 ],
47 'post_id' => [
48 'type' => 'string',
49 ],
50 ],
51 'editor_script' => 'st-block-tag-clouds',
52 'render_callback' => 'st_tag_clouds_render',
53 ]);
54
55 $shortcode_page = sprintf(
56 '<a href="%s">%s</a>',
57 add_query_arg(
58 [
59 'page' => 'st_terms_display',
60 ],
61 admin_url('admin.php')
62 ),
63 esc_html__('this page.', 'simple-tags')
64 );
65
66 $select_label = __('Select Terms Display', 'simple-tags');
67 $panel_title = __('Terms Display (TaxoPress)', 'simple-tags');
68
69 wp_localize_script('st-block-tag-clouds', 'ST_TAG_CLOUDS', [
70 'options' => $options,
71 'panel_title' => $panel_title,
72 'select_label' => $select_label,
73 ]);
74 }
75
76 add_action('init', 'st_tag_clouds_block_init');
77
78 /**
79 * Our combined block and shortcode renderer.
80 *
81 * @param array $attributes The attributes that were set on the block or shortcode.
82 */
83 function st_tag_clouds_render($attributes)
84 {
85 global $post;
86 ob_start();
87 echo do_shortcode('[taxopress_termsdisplay id="' . $attributes['tagcloud_id'] . '"]');
88
89 return ob_get_clean();
90 }
91