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 / post-tags.php

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

91 lines 2.2 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_post_tags_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-post-tags',
21 STAGS_URL . '/blocks/src/post-tags.js',
22 ['wp-blocks', 'wp-element', 'wp-components', 'wp-editor']
23 );
24
25 // Register our block, and explicitly define the attributes we accept.
26 $posttags_data = taxopress_get_posttags_data();
27
28 $options = [];
29 $default = '';
30 if (count($posttags_data) > 0) {
31 $sn = 0;
32 foreach ($posttags_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/post-tags', [
42 'attributes' => [
43 'posttags_id' => [
44 'type' => 'string',
45 'default' => $default,
46 ],
47 'post_id' => [
48 'type' => 'string',
49 ],
50 ],
51 'editor_script' => 'st-block-post-tags',
52 'render_callback' => 'st_post_tags_render',
53 ]);
54
55 $shortcode_page = sprintf(
56 '<a href="%s">%s</a>',
57 add_query_arg(
58 [
59 'page' => 'st_post_tags',
60 ],
61 admin_url('admin.php')
62 ),
63 esc_html__('Here', 'simple-tags')
64 );
65
66 $select_label = __(' Select current post', 'simple-tags');
67 $panel_title = __('Current Posts (TaxoPress)', 'simple-tags');
68
69 wp_localize_script('st-block-post-tags', 'ST_POST_TAGS', [
70 'options' => $options,
71 'panel_title' => $panel_title,
72 'select_label' => $select_label,
73 ]);
74 }
75
76 add_action('init', 'st_post_tags_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_post_tags_render($attributes)
84 {
85 global $post;
86 ob_start();
87 echo do_shortcode('[taxopress_postterms id="' . $attributes['posttags_id'] . '"]');
88
89 return ob_get_clean();
90 }
91