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

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