PluginProbe
Tag, Category, and Taxonomy Manager – Autotagger Automatically Add Terms / 3.4.2
Tag, Category, and Taxonomy Manager – Autotagger Automatically Add Terms v3.4.2
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 / related-posts.php

related-posts.php in Tag, Category, and Taxonomy Manager – Autotagger Automatically Add Terms 3.4.2, at blocks/related-posts.php

94 lines 2.4 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_related_posts_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-related-posts', STAGS_URL . '/blocks/src/related-posts.js',
21 ['wp-blocks', 'wp-element', 'wp-components', 'wp-editor']
22 );
23
24 // Register our block, and explicitly define the attributes we accept.
25 $relatedposts_data = taxopress_get_relatedpost_data();
26
27 $options = [];
28 $default = '';
29 if (count($relatedposts_data) > 0) {
30 $sn = 0;
31 foreach ($relatedposts_data as $key => $value) {
32 $sn++;
33 if ($sn === 1) {
34 $default = $key;
35 }
36 $options[] = ['label' => $value['title'], 'value' => $key];
37 }
38 }
39
40 register_block_type('taxopress/related-posts', [
41 'attributes' => [
42 'relatedpost_id' => [
43 'type' => 'string',
44 'default' => $default,
45 ],
46 'post_id' => [
47 'type' => 'string',
48 ],
49 ],
50 'editor_script' => 'st-block-related-posts',
51 'render_callback' => 'st_related_posts_render',
52 ]);
53
54 $shortcode_page = sprintf(
55 '<a href="%s">%s</a>',
56 add_query_arg(
57 [
58 'page' => 'st_related_posts',
59 ],
60 admin_url('admin.php')
61 ),
62 __('this page.', 'simple-tags')
63 );
64
65 $select_desc = __('Related Posts shortcode are added on Related Post screen', 'simple-tags');
66 $select_label = __('Select related post shortcode', 'simple-tags');
67 $panel_title = __('Related Posts (TaxoPress)', 'simple-tags');
68
69 wp_localize_script('st-block-related-posts', 'ST_RELATED_POST', [
70 'options' => $options,
71 'panel_title' => $panel_title,
72 'select_label' => $select_label,
73 'select_desc' => $select_desc
74 ]);
75
76 }
77
78 add_action('init', 'st_related_posts_block_init');
79
80 /**
81 * Our combined block and shortcode renderer.
82 *
83 * @param array $attributes The attributes that were set on the block or shortcode.
84 */
85 function st_related_posts_render($attributes)
86 {
87 global $post;
88 ob_start();
89 echo do_shortcode('[taxopress_relatedposts id="' . $attributes['relatedpost_id'] . '"]');
90
91 return ob_get_clean();
92 }
93
94 ?>