PluginProbe
Forumax – AI Powered Advanced Community Forum Plugin / 2.4.3
Forumax – AI Powered Advanced Community Forum Plugin v2.4.3
2.4.4 2.4.3 2.4.2 2.4.1 2.4.0 trunk 1.0.8 1.1.0 1.2.1 1.2.2 1.2.3 1.2.4 1.2.5 1.2.6 1.2.7 1.2.8 1.2.9 1.3.0 1.3.1 1.3.2 1.3.3 1.4.0 1.4.1 2.0.0 2.1.0 All 29 releases
bbp-core / widgets / Forumax_Topic_Info.php

Forumax_Topic_Info.php in Forumax – AI Powered Advanced Community Forum Plugin 2.4.3, at widgets/Forumax_Topic_Info.php

98 lines 3.9 KB
No matching file
Up and down to move Enter to open Esc to close
Raw Download Zip
1 <?php
2 namespace Forumax\WpWidgets;
3 use WP_Widget;
4 use WP_Query;
5
6 // Creating the widget
7 class Forumax_Topic_Info extends WP_Widget
8 {
9 function __construct()
10 {
11 parent::__construct(
12 'bbpress_forum_topic_info_widget', // Base ID of your widget
13 __('(Forumax) Forum Topic Info', 'forumax'), // Widget name
14 array('description' => __('Displays information about a Forumax forum topic', 'forumax'), ) // Widget description
15 );
16 }
17
18 // Creating widget front-end
19 public function widget($args, $instance)
20 {
21 wp_enqueue_style('bbpc-forum');
22
23 global $post;
24 if (!$post || !isset($post->ID) || $post->post_type != 'topic') {
25 return;
26 }
27
28 $topic_id = $post->ID;
29 $topic = get_post($topic_id);
30
31 if (empty($topic) || $topic->post_type != 'topic') {
32 return;
33 }
34
35 $forum_id = get_post_meta($topic_id, '_bbp_forum_id', true);
36 $forum_url = get_permalink($forum_id);
37 $forum_title = get_the_title($forum_id);
38 $status = bbp_get_topic_status($topic_id);
39 $replies = bbp_get_topic_reply_count($topic_id);
40 $voices = bbp_get_topic_voice_count($topic_id);
41
42 echo wp_kses_post($args['before_widget']);
43
44 if (!empty($instance['title'])) {
45 echo wp_kses_post($args['before_title'] . apply_filters('widget_title', $instance['title']) . $args['after_title']);
46 }
47
48 echo '<ul class="forumax-topic-info-widget">';
49 echo '<li><span class="forumax-topic-info-label">' . esc_html__('Forum:', 'forumax') . '</span><span class="forumax-topic-info-value"><a href="' . esc_url($forum_url) . '">' . esc_html($forum_title) . '</a></span></li>';
50 echo '<li><span class="forumax-topic-info-label">' . esc_html__('Topic:', 'forumax') . '</span><span class="forumax-topic-info-value">' . esc_html($topic->post_title) . '</span></li>';
51 echo '<li><span class="forumax-topic-info-label">' . esc_html__('Author:', 'forumax') . '</span><span class="forumax-topic-info-value">' . esc_html(get_the_author_meta('display_name', $topic->post_author)) . '</span></li>';
52 echo '<li><span class="forumax-topic-info-label">' . esc_html__('Date:', 'forumax') . '</span><span class="forumax-topic-info-value">' . esc_html(get_the_date('', $topic->ID)) . '</span></li>';
53 echo '<li><span class="forumax-topic-info-label">' . esc_html__('Status:', 'forumax') . '</span><span class="forumax-topic-info-value">' . esc_html($status) . '</span></li>';
54 echo '<li><span class="forumax-topic-info-label">' . esc_html__('Replies:', 'forumax') . '</span><span class="forumax-topic-info-value">' . esc_html($replies) . '</span></li>';
55 echo '<li><span class="forumax-topic-info-label">' . esc_html__('Voices:', 'forumax') . '</span><span class="forumax-topic-info-value">' . esc_html($voices) . '</span></li>';
56 echo '</ul>';
57
58 echo wp_kses_post($args['after_widget']);
59 }
60
61 // Widget Backend
62 public function form($instance)
63 {
64 $title = $instance['title'] ?? '';
65 $topic_id = $instance['topic_id'] ?? '';
66 // Widget admin form
67 ?>
68 <p>
69 <label for="<?php echo esc_attr($this->get_field_id('title')); ?>">
70 <?php esc_html_e('Title:', 'forumax'); ?>
71 </label>
72 <input class="widefat" id="<?php echo esc_attr($this->get_field_id('title')); ?>"
73 name="<?php echo esc_attr($this->get_field_name('title')); ?>" type="text"
74 value="<?php echo esc_attr($title); ?>" />
75 </p>
76 <p>
77 <label for="<?php echo esc_attr($this->get_field_id('topic_id')); ?>">
78 <?php esc_html_e('Topic ID:', 'forumax'); ?>
79 </label>
80 <input class="widefat" id="<?php echo esc_attr($this->get_field_id('topic_id')); ?>"
81 name="<?php echo esc_attr($this->get_field_name('topic_id')); ?>" type="text"
82 value="<?php echo esc_attr($topic_id); ?>" />
83 </p>
84 <?php
85 }
86
87 // Updating widget replacing old instances with new
88 public function update($new_instance, $old_instance)
89 {
90 $instance = array();
91 $instance['title'] = isset($new_instance['title']) ? sanitize_text_field($new_instance['title']) : '';
92 $instance['topic_id'] = isset($new_instance['topic_id']) ? absint($new_instance['topic_id']) : '';
93
94 return $instance;
95 }
96 }
97
98