PluginProbe
Forumax – AI Powered Advanced Community Forum Plugin / 2.2.0
Forumax – AI Powered Advanced Community Forum Plugin v2.2.0
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.2.0, at widgets/Forumax_Topic_Info.php

97 lines 3.4 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 bbPress forum topic', 'forumax'), ) // Widget description
15 );
16 }
17
18 // Creating widget front-end
19 public function widget($args, $instance)
20 {
21 global $post;
22
23 if (!$post || !isset($post->ID) || $post->post_type != 'topic') {
24 return;
25 }
26
27 $topic_id = $post->ID;
28 $topic = get_post($topic_id);
29
30 if (empty($topic) || $topic->post_type != 'topic') {
31 return;
32 }
33
34 $forum_id = get_post_meta($topic_id, '_bbp_forum_id', true);
35 $forum_url = get_permalink($forum_id);
36 $forum_title = get_the_title($forum_id);
37 $status = bbp_get_topic_status($topic_id);
38 $replies = bbp_get_topic_reply_count($topic_id);
39 $voices = bbp_get_topic_voice_count($topic_id);
40
41 echo wp_kses_post($args['before_widget']);
42
43 if (!empty($instance['title'])) {
44 echo wp_kses_post($args['before_title'] . apply_filters('widget_title', $instance['title']) . $args['after_title']);
45 }
46
47 echo '<ul>';
48 echo '<li><strong>' . esc_html__('Forum:', 'forumax') . '</strong> <a href="' . esc_url($forum_url) . '">' . esc_html($forum_title) . '</a></li>';
49 echo '<li><strong>' . esc_html__('Topic:', 'forumax') . '</strong> ' . esc_html($topic->post_title) . '</li>';
50 echo '<li><strong>' . esc_html__('Author:', 'forumax') . '</strong> ' . esc_html(get_the_author_meta('display_name', $topic->post_author)) . '</li>';
51 echo '<li><strong>' . esc_html__('Date:', 'forumax') . '</strong> ' . esc_html(get_the_date('', $topic->ID)) . '</li>';
52 echo '<li><strong>' . esc_html__('Status:', 'forumax') . '</strong> ' . esc_html($status) . '</li>';
53 echo '<li><strong>' . esc_html__('Replies:', 'forumax') . '</strong> ' . esc_html($replies) . '</li>';
54 echo '<li><strong>' . esc_html__('Voices:', 'forumax') . '</strong> ' . esc_html($voices) . '</li>';
55 echo '</ul>';
56
57 echo wp_kses_post($args['after_widget']);
58 }
59
60 // Widget Backend
61 public function form($instance)
62 {
63 $title = $instance['title'] ?? '';
64 $topic_id = $instance['topic_id'] ?? '';
65 // Widget admin form
66 ?>
67 <p>
68 <label for="<?php echo esc_attr($this->get_field_id('title')); ?>">
69 <?php esc_html_e('Title:', 'forumax'); ?>
70 </label>
71 <input class="widefat" id="<?php echo esc_attr($this->get_field_id('title')); ?>"
72 name="<?php echo esc_attr($this->get_field_name('title')); ?>" type="text"
73 value="<?php echo esc_attr($title); ?>" />
74 </p>
75 <p>
76 <label for="<?php echo esc_attr($this->get_field_id('topic_id')); ?>">
77 <?php esc_html_e('Topic ID:', 'forumax'); ?>
78 </label>
79 <input class="widefat" id="<?php echo esc_attr($this->get_field_id('topic_id')); ?>"
80 name="<?php echo esc_attr($this->get_field_name('topic_id')); ?>" type="text"
81 value="<?php echo esc_attr($topic_id); ?>" />
82 </p>
83 <?php
84 }
85
86 // Updating widget replacing old instances with new
87 public function update($new_instance, $old_instance)
88 {
89 $instance = array();
90 $instance['title'] = isset($new_instance['title']) ? sanitize_text_field($new_instance['title']) : '';
91 $instance['topic_id'] = isset($new_instance['topic_id']) ? absint($new_instance['topic_id']) : '';
92
93 return $instance;
94 }
95 }
96
97