Changeset 3450098
- Timestamp:
- 01/30/2026 01:50:33 AM (2 months ago)
- Location:
- tk-bbpress-stats/trunk
- Files:
-
- 4 edited
-
css/widget.css (modified) (1 diff)
-
plugin.php (modified) (3 diffs)
-
readme.txt (modified) (2 diffs)
-
views/widget.php (modified) (1 diff)
Legend:
- Unmodified
- Added
- Removed
-
tk-bbpress-stats/trunk/css/widget.css
r1380008 r3450098 1 /* This stylesheet is used to style the public view of the widget. */ 2 dt.tk_bbpress_stats { 3 float: left; 4 font-weight: normal; 5 font-size: 14px; 6 width: 50%; 1 .tk-bbpress-stats { 2 margin: 0; 3 padding: 0; 7 4 } 8 dd.tk_bbpress_stats { 5 6 .tk-bbpress-stats dt { 9 7 font-weight: bold; 10 float: left; 11 font-size: 14px; 12 width: 50%; 8 margin-bottom: 5px; 13 9 } 10 11 .tk-bbpress-stats dd { 12 margin: 0 0 10px 0; 13 padding: 0 0 0 10px; 14 } 15 16 .tk-bbpress-stats .tk-bbpress-stats-label { 17 font-weight: bold; 18 color: #333; 19 } 20 21 .tk-bbpress-stats .tk-bbpress-stats-value { 22 font-size: 1.1em; 23 color: #666; 24 } 25 26 .tk-bbpress-stats-widget { 27 background-color: #f9f9f9; 28 border: 1px solid #ddd; 29 padding: 15px; 30 border-radius: 5px; 31 } 32 33 .tk-bbpress-stats-item { 34 display: flex; 35 justify-content: space-between; 36 margin-bottom: 10px; 37 } 38 39 .tk-bbpress-stats-label { 40 font-weight: bold; 41 color: #333; 42 } 43 44 .tk-bbpress-stats-value { 45 font-size: 1.1em; 46 color: #666; 47 } -
tk-bbpress-stats/trunk/plugin.php
r1380010 r3450098 1 1 <?php 2 2 /** 3 *4 *5 3 * @package TK_bbPress_Stats 6 4 * @author Tony Korologos <admin@tkserver.com> 7 5 * @license GPL-2.0+ 8 6 * @link http://www.tkserver.com 9 * @copyright 20 15 TK Server7 * @copyright 2025 TK Server 10 8 * 11 9 * @wordpress-plugin … … 13 11 * Plugin URI: http://www.tkserver.com 14 12 * Description: Meaningful bbPress Statistics 15 * Version: 1.0.313 * Version: 2.0.0 16 14 * Author: Tony Korologos 17 15 * Author URI: http://www.tkserver.com … … 20 18 * License URI: http://www.gnu.org/licenses/gpl-2.0.txt 21 19 * Domain Path: /lang 22 * GitHub Plugin URI: https://github.com/<owner>/<repo> 20 * Requires at least: 5.0 21 * Requires PHP: 8.0 23 22 */ 24 23 25 // Prevent direct file access26 if ( ! defined ( 'ABSPATH' )) {27 exit;24 // Prevent direct file access 25 if (!defined('ABSPATH')) { 26 exit; 28 27 } 29 28 30 // this allows us to post the widget into a page or post via shortcode like so: [widget widget_name="widget_name"] 31 function widget($atts) { 32 global $wp_widget_factory; 33 extract(shortcode_atts(array( 34 'widget_name' => FALSE 35 ), $atts)); 36 $widget_name = esc_html($widget_name); 37 if (!is_a($wp_widget_factory->widgets[$widget_name], 'WP_Widget')): 38 $wp_class = 'WP_Widget_'.ucwords(strtolower($class)); 39 if (!is_a($wp_widget_factory->widgets[$wp_class], 'WP_Widget')): 40 return '<p>'.sprintf(__("%s: Widget class not found. Make sure this widget exists and the class name is correct"),'<strong>'.$class.'</strong>').'</p>'; 41 else: 42 $class = $wp_class; 43 endif; 44 endif; 45 46 $instance = array(); 47 48 $tk_bbpress_stats_options = get_option( 'tk_bbpress_stats_option_name' ); // Array of All Options 49 50 if(isset($tk_bbpress_stats_options['show_topic_count_0'])){$show_topic_count_0 = $tk_bbpress_stats_options['show_topic_count_0']; 51 } else {$show_topic_count_0 = NULL; } // Show Topic Count 52 if(isset($tk_bbpress_stats_options['show_reply_count_1'])){$show_reply_count_1 = $tk_bbpress_stats_options['show_reply_count_1']; 53 } else {$show_reply_count_1 = NULL; } // Show Reply Count 54 if(isset($tk_bbpress_stats_options['show_total_count_2'])){$show_total_count_2 = $tk_bbpress_stats_options['show_total_count_2']; 55 } else {$show_total_count_2 = NULL; } // Show Total Count 56 if(isset($tk_bbpress_stats_options['show_user_count_3'])){$show_user_count_3 = $tk_bbpress_stats_options['show_user_count_3']; 57 } else {$show_user_count_3 = NULL; } // Show User Count 58 if(isset($tk_bbpress_stats_options['show_forum_count_4'])){$show_forum_count_4 = $tk_bbpress_stats_options['show_forum_count_4']; 59 } else {$show_forum_count_4 = NULL; } // Show Total Count 60 61 $instance['title'] = ''; // title not needed for pages or posts, right? 62 $instance[ 'show_topic_count' ] = $show_topic_count_0 ; 63 $instance[ 'show_reply_count' ] = $show_reply_count_1 ; 64 $instance[ 'show_total_count' ] = $show_total_count_2 ; 65 $instance[ 'show_user_count' ] = $show_user_count_3 ; 66 $instance[ 'show_forum_count' ] = $show_forum_count_4 ; 67 68 ob_start(); 69 the_widget($widget_name, $instance, array('widget_id'=>'arbitrary-instance-', 70 'before_widget' => '', 71 'after_widget' => '', 72 'before_title' => '', 73 'after_title' => '' 74 )); 75 $output = ob_get_contents(); 76 ob_end_clean(); 77 return $output; 29 // PHP version check for backward compatibility 30 if (version_compare(PHP_VERSION, '7.4', '<')) { 31 add_action('admin_notices', function() { 32 echo '<div class="error"><p>' . 33 esc_html__('TK bbPress Stats requires PHP 7.4 or higher. Please upgrade PHP.', 'tk-bbpress-stats') . 34 '</p></div>'; 35 }); 36 return; 78 37 } 79 add_shortcode('widget','widget');80 81 38 82 39 class TKBbPressStats { 83 private $tk_bbpress_stats_options;84 85 public function __construct() { 86 add_action( 'admin_menu', array( $this, 'tk_bbpress_stats_add_plugin_page' ) );87 add_action( 'admin_init', array( $this, 'tk_bbpress_stats_page_init' ) ); 88 } 89 90 public function tk_bbpress_stats_add_plugin_page() { 91 add_options_page( 92 'TK bbPress Stats', // page_title 93 'TK bbPress Stats', // menu_title 94 'manage_options', // capability 95 'tk-bbpress-stats', // menu_slug 96 array( $this, 'tk_bbpress_stats_create_admin_page' ) // function 97 ); 98 } 99 100 public function tk_bbpress_stats_create_admin_page() { 101 $this->tk_bbpress_stats_options = get_option( 'tk_bbpress_stats_option_name' ); ?> 102 103 <div class="wrap"> 104 <h2>TK bbPress Stats</h2> 105 <p>Settings for page/post display. Insert the widget into a post or page with the following short code: [widget widget_name="TK_bbPress_Stats"]</p> 106 107 <form method="post" action="options.php"> 108 <?php 109 settings_fields( 'tk_bbpress_stats_option_group' ); 110 do_settings_sections( 'tk-bbpress-stats-admin' ); 111 submit_button(); 112 ?> 113 </form> 114 </div> 115 <?php } 116 117 public function tk_bbpress_stats_page_init() { 118 register_setting( 119 'tk_bbpress_stats_option_group', // option_group 120 'tk_bbpress_stats_option_name', // option_name 121 array( $this, 'tk_bbpress_stats_sanitize' ) // sanitize_callback 122 ); 123 124 add_settings_section( 125 'tk_bbpress_stats_setting_section', // id 126 'Settings', // title 127 array( $this, 'tk_bbpress_stats_section_info' ), // callback 128 'tk-bbpress-stats-admin' // page 129 ); 130 131 add_settings_field( 132 'show_topic_count_0', // id 133 'Show Topic Count', // title 134 array( $this, 'show_topic_count_0_callback' ), // callback 135 'tk-bbpress-stats-admin', // page 136 'tk_bbpress_stats_setting_section' // section 137 ); 138 139 add_settings_field( 140 'show_reply_count_1', // id 141 'Show Reply Count', // title 142 array( $this, 'show_reply_count_1_callback' ), // callback 143 'tk-bbpress-stats-admin', // page 144 'tk_bbpress_stats_setting_section' // section 145 ); 146 147 add_settings_field( 148 'show_total_count_2', // id 149 'Show Total Count', // title 150 array( $this, 'show_total_count_2_callback' ), // callback 151 'tk-bbpress-stats-admin', // page 152 'tk_bbpress_stats_setting_section' // section 153 ); 154 155 add_settings_field( 156 'show_user_count_3', // id 157 'Show User Count', // title 158 array( $this, 'show_user_count_3_callback' ), // callback 159 'tk-bbpress-stats-admin', // page 160 'tk_bbpress_stats_setting_section' // section 161 ); 162 163 add_settings_field( 164 'show_forum_count_4', // id 165 'Show Forum Count', // title 166 array( $this, 'show_forum_count_4_callback' ), // callback 167 'tk-bbpress-stats-admin', // page 168 'tk_bbpress_stats_setting_section' // section 169 ); 170 }171 172 public function tk_bbpress_stats_sanitize($input) { 173 $sanitary_values = array(); 174 if ( isset( $input['show_topic_count_0'] ) ) { 175 $sanitary_values['show_topic_count_0'] = $input['show_topic_count_0']; 176 } 177 178 if ( isset( $input['show_reply_count_1'] ) ) { 179 $sanitary_values['show_reply_count_1'] = $input['show_reply_count_1']; 180 } 181 182 if ( isset( $input['show_total_count_2'] ) ) { 183 $sanitary_values['show_total_count_2'] = $input['show_total_count_2']; 184 } 185 186 if ( isset( $input['show_user_count_3'] ) ) { 187 $sanitary_values['show_user_count_3'] = $input['show_user_count_3']; 188 } 189 190 if ( isset( $input['show_forum_count_4'] ) ) { 191 $sanitary_values['show_forum_count_4'] = $input['show_forum_count_4']; 192 } 193 194 return $sanitary_values; 195 } 196 197 public function tk_bbpress_stats_section_info() { 198 199 } 200 201 public function show_topic_count_0_callback() { 202 printf( 203 '<input type="checkbox" name="tk_bbpress_stats_option_name[show_topic_count_0]" id="show_topic_count_0" value="show_topic_count_0" %s>', 204 ( isset( $this->tk_bbpress_stats_options['show_topic_count_0'] ) && $this->tk_bbpress_stats_options['show_topic_count_0'] === 'show_topic_count_0' ) ? 'checked' : '' 205 ); 206 } 207 208 public function show_reply_count_1_callback() { 209 printf( 210 '<input type="checkbox" name="tk_bbpress_stats_option_name[show_reply_count_1]" id="show_reply_count_1" value="show_reply_count_1" %s>', 211 ( isset( $this->tk_bbpress_stats_options['show_reply_count_1'] ) && $this->tk_bbpress_stats_options['show_reply_count_1'] === 'show_reply_count_1' ) ? 'checked' : '' 212 );213 }214 215 public function show_total_count_2_callback(){216 printf( 217 '<input type="checkbox" name="tk_bbpress_stats_option_name[show_total_count_2]" id="show_total_count_2" value="show_total_count_2" %s> <label for="show_total_count_2"> Topics + Replies</label>', 218 ( isset( $this->tk_bbpress_stats_options['show_total_count_2'] ) && $this->tk_bbpress_stats_options['show_total_count_2'] === 'show_total_count_2' ) ? 'checked' : '' 219 ); 220 } 221 222 public function show_user_count_3_callback() { 223 printf(224 '<input type="checkbox" name="tk_bbpress_stats_option_name[show_user_count_3]" id="show_user_count_3" value="show_user_count_3" %s>',225 ( isset( $this->tk_bbpress_stats_options['show_user_count_3'] ) && $this->tk_bbpress_stats_options['show_user_count_3'] === 'show_user_count_3' ) ? 'checked' : '' 226 ); 227 } 228 229 public function show_forum_count_4_callback() { 230 printf( 231 '<input type="checkbox" name="tk_bbpress_stats_option_name[show_forum_count_4]" id="show_forum_count_4" value="show_forum_count_4" %s>', 232 ( isset( $this->tk_bbpress_stats_options['show_forum_count_4'] ) && $this->tk_bbpress_stats_options['show_forum_count_4'] === 'show_forum_count_4' ) ? 'checked' : '' 233 );234 }235 40 private array $tk_bbpress_stats_options = []; 41 private const OPTION_NAME = 'tk_bbpress_stats_option_name'; 42 private const NONCE_ACTION = 'tk_bbpress_stats_nonce_action'; 43 private const NONCE_NAME = 'tk_bbpress_stats_nonce'; 44 45 public function __construct() { 46 add_action('admin_menu', [$this, 'tk_bbpress_stats_add_plugin_page']); 47 add_action('admin_init', [$this, 'tk_bbpress_stats_page_init']); 48 } 49 50 public function tk_bbpress_stats_add_plugin_page(): void { 51 add_options_page( 52 __('TK bbPress Stats', 'tk-bbpress-stats'), 53 __('TK bbPress Stats', 'tk-bbpress-stats'), 54 'manage_options', 55 'tk-bbpress-stats', 56 [$this, 'tk_bbpress_stats_create_admin_page'] 57 ); 58 } 59 60 public function tk_bbpress_stats_create_admin_page(): void { 61 if (!current_user_can('manage_options')) { 62 wp_die(esc_html__('You do not have sufficient permissions to access this page.', 'tk-bbpress-stats')); 63 } 64 65 $this->tk_bbpress_stats_options = wp_parse_args( 66 get_option(self::OPTION_NAME, []), 67 [ 68 'show_topic_count_0' => '', 69 'show_forum_count_4' => '', 70 'show_reply_count_1' => '', 71 'show_total_count_2' => '', 72 'show_user_count_3' => '' 73 ] 74 ); 75 ?> 76 <div class="wrap"> 77 <h1><?php echo esc_html__('TK bbPress Stats', 'tk-bbpress-stats'); ?></h1> 78 <p><?php echo esc_html__('Settings for page/post display. Insert the widget into a post or page with the following shortcode:', 'tk-bbpress-stats'); ?> 79 <code>[widget widget_name="TK_bbPress_Stats"]</code> 80 </p> 81 <form method="post" action="options.php"> 82 <?php 83 settings_fields('tk_bbpress_stats_option_group'); 84 do_settings_sections('tk-bbpress-stats-admin'); 85 submit_button(); 86 ?> 87 </form> 88 </div> 89 <?php 90 } 91 92 public function tk_bbpress_stats_page_init(): void { 93 register_setting( 94 'tk_bbpress_stats_option_group', 95 self::OPTION_NAME, 96 [ 97 'sanitize_callback' => [$this, 'tk_bbpress_stats_sanitize'], 98 'default' => [] 99 ] 100 ); 101 102 add_settings_section( 103 'tk_bbpress_stats_setting_section', 104 __('Display Settings', 'tk-bbpress-stats'), 105 [$this, 'tk_bbpress_stats_section_info'], 106 'tk-bbpress-stats-admin' 107 ); 108 109 $this->add_settings_fields(); 110 } 111 112 public function tk_bbpress_stats_sanitize(array $input): array { 113 $sanitary_values = []; 114 115 $allowed_keys = [ 116 'show_topic_count_0', 117 'show_reply_count_1', 118 'show_total_count_2', 119 'show_user_count_3', 120 'show_forum_count_4' 121 ]; 122 123 foreach ($allowed_keys as $key) { 124 if (isset($input[$key])) { 125 $sanitary_values[$key] = sanitize_text_field($input[$key]); 126 } 127 } 128 129 return $sanitary_values; 130 } 131 132 public function tk_bbpress_stats_section_info(): void { 133 echo '<p>' . esc_html__('Select which statistics to display in the widget.', 'tk-bbpress-stats') . '</p>'; 134 } 135 136 private function add_settings_fields(): void { 137 $fields = [ 138 'show_topic_count_0' => __('Show Topic Count', 'tk-bbpress-stats'), 139 'show_reply_count_1' => __('Show Reply Count', 'tk-bbpress-stats'), 140 'show_total_count_2' => __('Show Total Count', 'tk-bbpress-stats'), 141 'show_user_count_3' => __('Show User Count', 'tk-bbpress-stats'), 142 'show_forum_count_4' => __('Show Forum Count', 'tk-bbpress-stats') 143 ]; 144 145 foreach ($fields as $id => $title) { 146 add_settings_field( 147 $id, 148 $title, 149 [$this, $id . '_callback'], 150 'tk-bbpress-stats-admin', 151 'tk_bbpress_stats_setting_section' 152 ); 153 } 154 } 155 156 public function show_topic_count_0_callback(): void { 157 $this->render_checkbox_field('show_topic_count_0'); 158 } 159 160 public function show_reply_count_1_callback(): void { 161 $this->render_checkbox_field('show_reply_count_1'); 162 } 163 164 public function show_total_count_2_callback(): void { 165 $this->render_checkbox_field('show_total_count_2', __('Topics + Replies', 'tk-bbpress-stats')); 166 } 167 168 public function show_user_count_3_callback(): void { 169 $this->render_checkbox_field('show_user_count_3'); 170 } 171 172 public function show_forum_count_4_callback(): void { 173 $this->render_checkbox_field('show_forum_count_4'); 174 } 175 176 private function render_checkbox_field(string $field_id, string $label = ''): void { 177 $checked = isset($this->tk_bbpress_stats_options[$field_id]) && 178 $this->tk_bbpress_stats_options[$field_id] === $field_id; 179 180 printf( 181 '<input type="checkbox" name="%s[%s]" id="%s" value="%s" %s>', 182 esc_attr(self::OPTION_NAME), 183 esc_attr($field_id), 184 esc_attr($field_id), 185 esc_attr($field_id), 186 checked($checked, true, false) 187 ); 188 189 if ($label) { 190 printf(' <label for="%s">%s</label>', esc_attr($field_id), esc_html($label)); 191 } 192 } 236 193 } 237 if ( is_admin() ) 238 $tk_bbpress_stats = new TKBbPressStats(); 239 240 241 242 243 // TODO: change 'Widget_Name' to the name of your plugin 194 195 if (is_admin()) { 196 $tk_bbpress_stats = new TKBbPressStats(); 197 } 198 244 199 class TK_bbPress_Stats extends WP_Widget { 245 246 /** 247 * @TODO - Rename "widget-name" to the name your your widget 248 * 249 * Unique identifier for your widget. 250 * 251 * 252 * The variable name is used as the text domain when internationalizing strings 253 * of text. Its value should match the Text Domain file header in the main 254 * widget file. 255 * 256 * @since 1.0.0 257 * 258 * @var string 259 */ 260 protected $widget_slug = 'tk-bbpress-stats'; 261 262 /*--------------------------------------------------*/ 263 /* Constructor 264 /*--------------------------------------------------*/ 265 266 /** 267 * Specifies the classname and description, instantiates the widget, 268 * loads localization files, and includes necessary stylesheets and JavaScript. 269 */ 270 public function __construct() { 271 272 // load plugin text domain 273 add_action( 'init', array( $this, 'widget_textdomain' ) ); 274 275 // Hooks fired when the Widget is activated and deactivated 276 register_activation_hook( __FILE__, array( $this, 'activate' ) ); 277 register_deactivation_hook( __FILE__, array( $this, 'deactivate' ) ); 278 279 // TODO: update description 280 parent::__construct( 281 $this->get_widget_slug(), 282 __( 'TK bbPress Stats', $this->get_widget_slug() ), 283 array( 284 'classname' => $this->get_widget_slug().'-class', 285 'description' => __( 'Stats for bbPress.', $this->get_widget_slug() ) 286 ) 287 ); 288 289 // Register admin styles and scripts 290 add_action( 'admin_print_styles', array( $this, 'register_admin_styles' ) ); 291 add_action( 'admin_enqueue_scripts', array( $this, 'register_admin_scripts' ) ); 292 293 // Register site styles and scripts 294 add_action( 'wp_enqueue_scripts', array( $this, 'register_widget_styles' ) ); 295 add_action( 'wp_enqueue_scripts', array( $this, 'register_widget_scripts' ) ); 296 297 // Refreshing the widget's cached output with each new post 298 add_action( 'save_post', array( $this, 'flush_widget_cache' ) ); 299 add_action( 'deleted_post', array( $this, 'flush_widget_cache' ) ); 300 add_action( 'switch_theme', array( $this, 'flush_widget_cache' ) ); 301 302 } // end constructor 303 304 305 /** 306 * Return the widget slug. 307 * 308 * @since 1.0.0 309 * 310 * @return Plugin slug variable. 311 */ 312 public function get_widget_slug() { 200 protected string $widget_slug = 'tk-bbpress-stats'; 201 private const CACHE_KEY = 'tk_bbpress_stats_cache'; 202 private const CACHE_GROUP = 'tk_bbpress_stats'; 203 private const CACHE_EXPIRATION = HOUR_IN_SECONDS; 204 205 public function __construct() { 206 add_action('init', [$this, 'widget_textdomain']); 207 208 parent::__construct( 209 $this->get_widget_slug(), 210 __('TK bbPress Stats', 'tk-bbpress-stats'), 211 [ 212 'classname' => $this->get_widget_slug() . '-class', 213 'description' => __('Display bbPress forum statistics.', 'tk-bbpress-stats'), 214 'customize_selective_refresh' => true 215 ] 216 ); 217 218 add_action('admin_enqueue_scripts', [$this, 'register_admin_styles']); 219 add_action('admin_enqueue_scripts', [$this, 'register_admin_scripts']); 220 221 add_action('wp_enqueue_scripts', [$this, 'register_widget_styles']); 222 add_action('wp_enqueue_scripts', [$this, 'register_widget_scripts']); 223 224 // Clear cache on relevant actions 225 add_action('bbp_new_topic', [$this, 'flush_widget_cache']); 226 add_action('bbp_new_reply', [$this, 'flush_widget_cache']); 227 add_action('bbp_new_forum', [$this, 'flush_widget_cache']); 228 add_action('delete_user', [$this, 'flush_widget_cache']); 229 add_action('user_register', [$this, 'flush_widget_cache']); 230 } 231 232 public function get_widget_slug(): string { 313 233 return $this->widget_slug; 314 234 } 315 235 316 /*--------------------------------------------------*/ 317 /* Widget API Functions 318 /*--------------------------------------------------*/ 319 320 /** 321 * Outputs the content of the widget. 322 * 323 * @param array args The array of form elements 324 * @param array instance The current instance of the widget 325 */ 326 327 328 329 public function widget( $args, $instance ) { 330 331 //store the options in variables 332 333 $show_topic_count = $instance['show_topic_count'] ? 'true' : 'false'; 334 $show_reply_count = $instance['show_reply_count'] ? 'true' : 'false'; 335 $show_total_count = $instance['show_total_count'] ? 'true' : 'false'; 336 $show_user_count = $instance['show_user_count'] ? 'true' : 'false'; 337 $show_forum_count = $instance['show_forum_count'] ? 'true' : 'false'; 338 339 echo $args['before_widget']; 340 if ( ! empty( $instance['title'] ) ) { 341 echo $args['before_title'] . apply_filters( 'widget_title', $instance['title'] ). $args['after_title']; 342 } 343 //echo __( 'Hello, World!', 'text_domain' ); 344 echo $args['after_widget']; 345 346 347 348 // Check if there is a cached output 349 $cache = wp_cache_get( $this->get_widget_slug(), 'widget' ); 350 351 if ( !is_array( $cache ) ) 352 $cache = array(); 353 354 if ( ! isset ( $args['widget_id'] ) ) 355 $args['widget_id'] = $this->id; 356 357 if ( isset ( $cache[ $args['widget_id'] ] ) ) 358 return print $cache[ $args['widget_id'] ]; 359 360 // go on with your widget logic, put everything into a string and … 361 362 extract( $args, EXTR_SKIP ); 363 364 $widget_string = $before_widget; 365 366 // TODO: Here is where you manipulate your widget's values based on their input fields 367 ob_start(); 368 include( plugin_dir_path( __FILE__ ) . 'views/widget.php' ); 369 $widget_string .= ob_get_clean(); 370 $widget_string .= $after_widget; 371 372 $cache[ $args['widget_id'] ] = $widget_string; 373 374 wp_cache_set( $this->get_widget_slug(), $cache, 'widget' ); 375 376 print $widget_string; 377 378 } // end widget 379 380 381 public function flush_widget_cache() 382 { 383 wp_cache_delete( $this->get_widget_slug(), 'widget' ); 384 } 385 /** 386 * Processes the widget's options to be saved. 387 * 388 * @param array new_instance The new instance of values to be generated via the update. 389 * @param array old_instance The previous instance of values before the update. 390 */ 391 public function update( $new_instance, $old_instance ) { 392 393 $instance = $old_instance; 394 395 $instance = array(); 396 $instance['title'] = ( ! empty( $new_instance['title'] ) ) ? strip_tags( $new_instance['title'] ) : ''; 397 398 $instance[ 'show_topic_count' ] = $new_instance[ 'show_topic_count' ]; 399 $instance[ 'show_reply_count' ] = $new_instance[ 'show_reply_count' ]; 400 $instance[ 'show_total_count' ] = $new_instance[ 'show_total_count' ]; 401 $instance[ 'show_user_count' ] = $new_instance[ 'show_user_count' ]; 402 $instance[ 'show_forum_count' ] = $new_instance[ 'show_forum_count' ]; 403 404 return $instance; 405 406 } // end widget 407 408 /** 409 * Generates the administration form for the widget. 410 * 411 * @param array instance The array of keys and values for the widget. 412 */ 413 public function form( $instance ) { 414 415 ?> 416 <p> 417 <input class="checkbox" type="checkbox" <?php checked( $instance[ 'show_topic_count' ], 'on' ); ?> id="<?php echo $this->get_field_id( 'show_topic_count' ); ?>" name="<?php echo $this->get_field_name( 'show_topic_count' ); ?>" /> 418 <label for="<?php echo $this->get_field_id( 'show_topic_count' ); ?>">Show Topic Count</label> 419 </p> 420 <p> 421 <input class="checkbox" type="checkbox" <?php checked( $instance[ 'show_forum_count' ], 'on' ); ?> id="<?php echo $this->get_field_id( 'show_forum_count' ); ?>" name="<?php echo $this->get_field_name( 'show_forum_count' ); ?>" /> 422 <label for="<?php echo $this->get_field_id( 'show_forum_count' ); ?>">Show Forum Count</label> 423 </p> 424 <p> 425 <input class="checkbox" type="checkbox" <?php checked( $instance[ 'show_reply_count' ], 'on' ); ?> id="<?php echo $this->get_field_id( 'show_reply_count' ); ?>" name="<?php echo $this->get_field_name( 'show_reply_count' ); ?>" /> 426 <label for="<?php echo $this->get_field_id( 'show_reply_count' ); ?>">Show Reply Count</label> 427 </p> 428 <p> 429 <input class="checkbox" type="checkbox" <?php checked( $instance[ 'show_total_count' ], 'on' ); ?> id="<?php echo $this->get_field_id( 'show_total_count' ); ?>" name="<?php echo $this->get_field_name( 'show_total_count' ); ?>" /> 430 <label for="<?php echo $this->get_field_id( 'show_total_count' ); ?>">Show Total Count</label> 431 </p> 432 <p> 433 <input class="checkbox" type="checkbox" <?php checked( $instance[ 'show_user_count' ], 'on' ); ?> id="<?php echo $this->get_field_id( 'show_user_count' ); ?>" name="<?php echo $this->get_field_name( 'show_user_count' ); ?>" /> 434 <label for="<?php echo $this->get_field_id( 'show_user_count' ); ?>">Show User Count</label> 435 </p> 436 <?php 437 438 439 $title = ! empty( $instance['title'] ) ? $instance['title'] : __( 'New title', 'text_domain' ); 440 ?> 441 <p> 442 <label for="<?php echo $this->get_field_id( 'title' ); ?>"><?php _e( 'Title:' ); ?></label> 443 <input class="widefat" id="<?php echo $this->get_field_id( 'title' ); ?>" name="<?php echo $this->get_field_name( 'title' ); ?>" type="text" value="<?php echo esc_attr( $title ); ?>"> 444 </p> 445 <?php 446 447 // Display the admin form 448 include( plugin_dir_path(__FILE__) . 'views/admin.php' ); 449 450 } // end form 451 452 453 454 /*--------------------------------------------------*/ 455 /* Public Functions 456 /*--------------------------------------------------*/ 457 458 /** 459 * Loads the Widget's text domain for localization and translation. 460 */ 461 public function widget_textdomain() { 462 463 // TODO be sure to change 'widget-name' to the name of *your* plugin 464 load_plugin_textdomain( $this->get_widget_slug(), false, plugin_dir_path( __FILE__ ) . 'lang/' ); 465 466 } // end widget_textdomain 467 468 /** 469 * Fired when the plugin is activated. 470 * 471 * @param boolean $network_wide True if WPMU superadmin uses "Network Activate" action, false if WPMU is disabled or plugin is activated on an individual blog. 472 */ 473 public function activate( $network_wide ) { 474 // TODO define activation functionality here 475 } // end activate 476 477 /** 478 * Fired when the plugin is deactivated. 479 * 480 * @param boolean $network_wide True if WPMU superadmin uses "Network Activate" action, false if WPMU is disabled or plugin is activated on an individual blog 481 */ 482 public function deactivate( $network_wide ) { 483 // TODO define deactivation functionality here 484 } // end deactivate 485 486 /** 487 * Registers and enqueues admin-specific styles. 488 */ 489 public function register_admin_styles() { 490 491 wp_enqueue_style( $this->get_widget_slug().'-admin-styles', plugins_url( 'css/admin.css', __FILE__ ) ); 492 493 } // end register_admin_styles 494 495 /** 496 * Registers and enqueues admin-specific JavaScript. 497 */ 498 public function register_admin_scripts() { 499 500 wp_enqueue_script( $this->get_widget_slug().'-admin-script', plugins_url( 'js/admin.js', __FILE__ ), array('jquery') ); 501 502 } // end register_admin_scripts 503 504 /** 505 * Registers and enqueues widget-specific styles. 506 */ 507 public function register_widget_styles() { 508 509 wp_enqueue_style( $this->get_widget_slug().'-widget-styles', plugins_url( 'css/widget.css', __FILE__ ) ); 510 511 } // end register_widget_styles 512 513 /** 514 * Registers and enqueues widget-specific scripts. 515 */ 516 public function register_widget_scripts() { 517 518 wp_enqueue_script( $this->get_widget_slug().'-script', plugins_url( 'js/widget.js', __FILE__ ), array('jquery') ); 519 520 } // end register_widget_scripts 521 522 } // end class 523 524 // TODO: Remember to change 'Widget_Name' to match the class name definition 525 add_action( 'widgets_init', create_function( '', 'register_widget("TK_bbPress_Stats");' ) ); 236 public function widget($args, $instance): void { 237 // Check if bbPress is active 238 if (!function_exists('bbp_get_statistics')) { 239 echo $args['before_widget']; 240 echo '<p>' . esc_html__('bbPress is not active.', 'tk-bbpress-stats') . '</p>'; 241 echo $args['after_widget']; 242 return; 243 } 244 245 $show_topic_count = !empty($instance['show_topic_count']); 246 $show_forum_count = !empty($instance['show_forum_count']); 247 $show_reply_count = !empty($instance['show_reply_count']); 248 $show_total_count = !empty($instance['show_total_count']); 249 $show_user_count = !empty($instance['show_user_count']); 250 251 // Try to get cached stats 252 $stats = $this->get_cached_stats(); 253 254 if ($stats === false) { 255 $stats = $this->get_bbpress_stats(); 256 $this->cache_stats($stats); 257 } 258 259 $user_count = $stats['user_count'] ?? 0; 260 $topic_count = $stats['topic_count'] ?? 0; 261 $reply_count = $stats['reply_count'] ?? 0; 262 $total_count = $topic_count + $reply_count; 263 $forum_count = $stats['forum_count'] ?? 0; 264 265 echo $args['before_widget']; 266 267 if (!empty($instance['title'])) { 268 echo $args['before_title'] . 269 apply_filters('widget_title', esc_html($instance['title'])) . 270 $args['after_title']; 271 } 272 273 // Include the widget view with validated path 274 $view_file = plugin_dir_path(__FILE__) . 'views/widget.php'; 275 if (file_exists($view_file)) { 276 include $view_file; 277 } 278 279 echo $args['after_widget']; 280 } 281 282 private function get_bbpress_stats(): array { 283 global $wpdb; 284 285 // Use prepared statements for security 286 $stats = []; 287 288 // Get user count 289 $stats['user_count'] = (int) $wpdb->get_var( 290 "SELECT COUNT(ID) FROM {$wpdb->users}" 291 ); 292 293 // Get topic count 294 $stats['topic_count'] = (int) $wpdb->get_var( 295 $wpdb->prepare( 296 "SELECT COUNT(ID) FROM {$wpdb->posts} WHERE post_status = %s AND post_type = %s", 297 'publish', 298 'topic' 299 ) 300 ); 301 302 // Get reply count 303 $stats['reply_count'] = (int) $wpdb->get_var( 304 $wpdb->prepare( 305 "SELECT COUNT(ID) FROM {$wpdb->posts} WHERE post_status = %s AND post_type = %s", 306 'publish', 307 'reply' 308 ) 309 ); 310 311 // Get forum count 312 $stats['forum_count'] = (int) $wpdb->get_var( 313 $wpdb->prepare( 314 "SELECT COUNT(ID) FROM {$wpdb->posts} WHERE post_status = %s AND post_type = %s", 315 'publish', 316 'forum' 317 ) 318 ); 319 320 return $stats; 321 } 322 323 private function get_cached_stats() { 324 return wp_cache_get(self::CACHE_KEY, self::CACHE_GROUP); 325 } 326 327 private function cache_stats(array $stats): void { 328 wp_cache_set(self::CACHE_KEY, $stats, self::CACHE_GROUP, self::CACHE_EXPIRATION); 329 } 330 331 332 public function flush_widget_cache(): void { 333 wp_cache_delete(self::CACHE_KEY, self::CACHE_GROUP); 334 } 335 336 public function update($new_instance, $old_instance): array { 337 $this->flush_widget_cache(); 338 339 return [ 340 'title' => !empty($new_instance['title']) ? sanitize_text_field($new_instance['title']) : '', 341 'show_topic_count' => !empty($new_instance['show_topic_count']), 342 'show_reply_count' => !empty($new_instance['show_reply_count']), 343 'show_total_count' => !empty($new_instance['show_total_count']), 344 'show_user_count' => !empty($new_instance['show_user_count']), 345 'show_forum_count' => !empty($new_instance['show_forum_count']) 346 ]; 347 } 348 349 public function form($instance): void { 350 $defaults = [ 351 'title' => __('bbPress Stats', 'tk-bbpress-stats'), 352 'show_topic_count' => false, 353 'show_forum_count' => false, 354 'show_reply_count' => false, 355 'show_total_count' => false, 356 'show_user_count' => false 357 ]; 358 $instance = wp_parse_args($instance, $defaults); 359 360 $title = esc_attr($instance['title']); 361 ?> 362 <p> 363 <label for="<?php echo esc_attr($this->get_field_id('title')); ?>"> 364 <?php esc_html_e('Title:', 'tk-bbpress-stats'); ?> 365 </label> 366 <input class="widefat" 367 id="<?php echo esc_attr($this->get_field_id('title')); ?>" 368 name="<?php echo esc_attr($this->get_field_name('title')); ?>" 369 type="text" 370 value="<?php echo $title; ?>"> 371 </p> 372 <?php 373 $this->render_form_checkbox('show_topic_count', __('Show Topic Count', 'tk-bbpress-stats'), $instance); 374 $this->render_form_checkbox('show_forum_count', __('Show Forum Count', 'tk-bbpress-stats'), $instance); 375 $this->render_form_checkbox('show_reply_count', __('Show Reply Count', 'tk-bbpress-stats'), $instance); 376 $this->render_form_checkbox('show_total_count', __('Show Total Count', 'tk-bbpress-stats'), $instance); 377 $this->render_form_checkbox('show_user_count', __('Show User Count', 'tk-bbpress-stats'), $instance); 378 } 379 380 private function render_form_checkbox(string $field, string $label, array $instance): void { 381 ?> 382 <p> 383 <input class="checkbox" 384 type="checkbox" 385 <?php checked(!empty($instance[$field])); ?> 386 id="<?php echo esc_attr($this->get_field_id($field)); ?>" 387 name="<?php echo esc_attr($this->get_field_name($field)); ?>" /> 388 <label for="<?php echo esc_attr($this->get_field_id($field)); ?>"> 389 <?php echo esc_html($label); ?> 390 </label> 391 </p> 392 <?php 393 } 394 395 public function widget_textdomain(): void { 396 load_plugin_textdomain('tk-bbpress-stats', false, dirname(plugin_basename(__FILE__)) . '/lang/'); 397 } 398 399 public function register_admin_styles(): void { 400 $screen = get_current_screen(); 401 if ($screen && $screen->id === 'widgets') { 402 wp_enqueue_style( 403 $this->get_widget_slug() . '-admin-styles', 404 plugins_url('css/admin.css', __FILE__), 405 [], 406 '2.0.0' 407 ); 408 } 409 } 410 411 public function register_admin_scripts(): void { 412 $screen = get_current_screen(); 413 if ($screen && $screen->id === 'widgets') { 414 wp_enqueue_script( 415 $this->get_widget_slug() . '-admin-script', 416 plugins_url('js/admin.js', __FILE__), 417 ['jquery'], 418 '2.0.0', 419 true 420 ); 421 } 422 } 423 424 public function register_widget_styles(): void { 425 if (is_active_widget(false, false, $this->id_base)) { 426 wp_enqueue_style( 427 $this->get_widget_slug() . '-widget-styles', 428 plugins_url('css/widget.css', __FILE__), 429 [], 430 '2.0.0' 431 ); 432 } 433 } 434 435 public function register_widget_scripts(): void { 436 if (is_active_widget(false, false, $this->id_base)) { 437 wp_enqueue_script( 438 $this->get_widget_slug() . '-script', 439 plugins_url('js/widget.js', __FILE__), 440 ['jquery'], 441 '2.0.0', 442 true 443 ); 444 } 445 } 446 } 447 448 // Register widget 449 add_action('widgets_init', function(): void { 450 register_widget('TK_bbPress_Stats'); 451 }); 452 453 // Activation hook 454 register_activation_hook(__FILE__, function(): void { 455 // Check if bbPress is active 456 if (!function_exists('bbp_get_statistics')) { 457 deactivate_plugins(plugin_basename(__FILE__)); 458 wp_die( 459 esc_html__('TK bbPress Stats requires bbPress to be installed and activated.', 'tk-bbpress-stats'), 460 esc_html__('Plugin Activation Error', 'tk-bbpress-stats'), 461 ['back_link' => true] 462 ); 463 } 464 }); 465 466 // Deactivation hook 467 register_deactivation_hook(__FILE__, function(): void { 468 // Clean up cache 469 wp_cache_delete('tk_bbpress_stats_cache', 'tk_bbpress_stats'); 470 }); -
tk-bbpress-stats/trunk/readme.txt
r1380014 r3450098 3 3 Contributors: tkserver 4 4 Donate link: http://www.tkserver.com/ 5 Tags: widget, bbPress 6 Requires at least: 4.0.0 7 Tested up to: 4.4.2 8 Stable tag: 1.0.3 5 Tags: widget, bbPress, statistics, forum, stats 6 Requires at least: 5.0.0 7 Tested up to: 6.7 8 Requires PHP: 7.4 9 Stable tag: 2.0.0 9 10 License: GPLv2 or later 10 11 License URI: http://www.gnu.org/licenses/gpl-2.0.html 11 12 12 TK bbPress Stats is a Wordpress plugin/widget which shows meaningful statistics about the installed bbPress forum.13 Modern, secure bbPress statistics widget with PHP 8.5 support. Display forum stats with caching and security enhancements. 13 14 14 15 == Description == 15 16 16 TK bbPress Stats provides useful statistics about the installed bbPress forum. Short code option allows the widget to be shown inside a Wordpress page or post.17 TK bbPress Stats provides useful statistics about your bbPress forum with modern security and performance features. Fully compatible with PHP 8.5 while maintaining backward compatibility to PHP 7.4. 17 18 18 Items available for display: 19 **Key Features:** 20 21 * Display forum statistics in widgets or via shortcode 22 * Intelligent caching for optimal performance 23 * Secure database queries with prepared statements 24 * Full internationalization support 25 * Modern PHP 8.5 code with type safety 26 * Conditional asset loading for better performance 27 28 **Available Statistics:** 19 29 20 30 1. Total Users 21 31 2. Total Topics 22 32 3. Total Replies 23 4. Total Posts (topics andreplies)33 4. Total Posts (topics + replies) 24 34 5. Total Forums 25 35 26 Visibility of each statistic is customizable, as is the title of the widget. 36 Each statistic can be individually enabled/disabled, and the widget title is fully customizable. 37 38 **Security Features:** 39 40 * SQL injection protection with prepared statements 41 * XSS prevention with proper output escaping 42 * Input sanitization on all user data 43 * Capability checks for admin access 44 * Path traversal protection 45 46 **Performance Optimizations:** 47 48 * Smart caching (1-hour default, auto-invalidates on changes) 49 * Conditional script/style loading 50 * Optimized database queries 51 * Minimal resource footprint 27 52 28 53 == Installation == 29 54 30 1. Upload the folder `tk-bbpress-stats` to the `/wp-content/plugins/` directory 31 2. Activate the plugin through the 'Plugins' menu in WordPress admin 32 3. Put the widget in desired theme location and set widget settings 33 4. Enjoy your stats! 55 = Automatic Installation = 56 1. Log in to your WordPress admin panel 57 2. Navigate to Plugins > Add New 58 3. Search for "TK bbPress Stats" 59 4. Click "Install Now" and then "Activate" 34 60 35 To use the short code function put this code inside a post or page: 36 [widget widget_name="widget_name"] 37 Then go to the options page in the Wordpress admin and select what you want to see. 61 = Manual Installation = 62 1. Download the plugin zip file 63 2. Upload the folder `tk-bbpress-stats` to the `/wp-content/plugins/` directory 64 3. Activate the plugin through the 'Plugins' menu in WordPress 65 4. Configure the widget in Appearance > Widgets or use the shortcode 66 67 = Widget Usage = 68 1. Go to Appearance > Widgets 69 2. Drag "TK bbPress Stats" to your desired widget area 70 3. Configure which statistics to display 71 4. Save your settings 72 73 = Shortcode Usage = 74 Insert this shortcode in any post or page: 75 `[widget widget_name="TK_bbPress_Stats"]` 76 77 Then configure display options in Settings > TK bbPress Stats 78 79 = Requirements = 80 * WordPress 5.0 or higher 81 * bbPress plugin installed and activated 82 * PHP 7.4 or higher (PHP 8.0+ recommended) 38 83 39 84 40 85 == Frequently Asked Questions == 41 86 42 = What bbPress statistics does this widget show? =87 = What statistics can this widget display? = 43 88 44 1. Total Users 45 2. Total Topics 46 3. Total Replies 47 4. Total Posts (topics and replies) 48 5. Total Forums 89 The widget can show: 90 * Total Users 91 * Total Topics 92 * Total Replies 93 * Total Posts (topics + replies combined) 94 * Total Forums 49 95 50 = Does the widget count unpublished or trashed topics or replies? = 96 Each statistic can be individually enabled or disabled. 51 97 52 No. 98 = Does the widget count unpublished or trashed content? = 99 100 No, only published topics, replies, and forums are counted. 101 102 = Is this plugin compatible with PHP 8.5? = 103 104 Yes! Version 2.0.0 is fully compatible with PHP 8.5 while maintaining backward compatibility with PHP 7.4+. 105 106 = How does caching work? = 107 108 Statistics are cached for 1 hour by default. The cache automatically clears when: 109 * A new topic is created 110 * A new reply is posted 111 * A new forum is created 112 * A user registers or is deleted 113 114 = Is this plugin secure? = 115 116 Yes, version 2.0.0 includes comprehensive security improvements: 117 * SQL injection protection with prepared statements 118 * XSS prevention with proper escaping 119 * Input sanitization 120 * Capability checks 121 * Path traversal protection 122 123 = Will upgrading from v1.x break my site? = 124 125 No, version 2.0.0 is fully backward compatible. Your existing settings and widget configurations will be preserved. 126 127 = Can I customize the cache duration? = 128 129 Yes, add this to your wp-config.php: 130 `define('TK_BBPRESS_STATS_CACHE_EXPIRATION', 3600); // seconds` 131 132 = Does this work with multisite? = 133 134 Yes, the plugin works with WordPress multisite installations. 135 136 = How do I translate this plugin? = 137 138 The plugin is fully internationalized. Use a translation plugin like Loco Translate or create .po/.mo files in the /lang directory. 53 139 54 140 == Screenshots == … … 59 145 == Changelog == 60 146 147 = 2.0.0 - 2026-01-26 = 148 **Major Security & Modernization Release** 149 150 * **SECURITY**: Fixed SQL injection vulnerability in database queries 151 * **SECURITY**: Added input sanitization for all user inputs 152 * **SECURITY**: Implemented capability checks for admin access 153 * **SECURITY**: Added path validation for file includes 154 * **SECURITY**: Proper output escaping throughout 155 * **NEW**: PHP 8.5 compatibility with type declarations 156 * **NEW**: Intelligent caching system (1-hour default) 157 * **NEW**: Conditional asset loading for better performance 158 * **NEW**: Full internationalization support 159 * **NEW**: bbPress dependency check on activation 160 * **IMPROVED**: Modern PHP syntax (short arrays, typed properties) 161 * **IMPROVED**: Optimized database queries with prepared statements 162 * **IMPROVED**: Better error handling and user feedback 163 * **IMPROVED**: Code organization and documentation 164 * **IMPROVED**: Widget configuration interface 165 * **FIXED**: Deprecated widget constructor 166 * **FIXED**: Undefined array key warnings 167 * **FIXED**: Inconsistent option naming 168 * Minimum PHP version: 7.4 (backward compatible) 169 * Minimum WordPress version: 5.0 170 * Tested up to WordPress 6.7 171 172 = 1.0.3 - 2016-03-27 = 173 * Added shortcode option for putting widget inside posts/pages 174 175 = 1.0.2 - 2016-03-26 = 176 * Small code cleanup 177 * Added screenshots, icon and header image 178 179 = 1.0.1 - 2016-03-25 = 180 * Small code cleanup 181 * Image updates 182 183 = 1.0.0 - 2016-03-20 = 184 * Initial release 185 186 == Upgrade Notice == 187 188 = 2.0.0 = 189 Major security and modernization update. Fixes critical SQL injection vulnerability. Adds PHP 8.5 support. Highly recommended upgrade for all users. Fully backward compatible - no breaking changes. 190 61 191 = 1.0.3 = 62 * Added short code option for putting widget inside posts/pages - 3/27/16 63 64 = 1.0.2 = 65 * Small code cleanup, attempting to add screenshots, icon and header image for plugin repository 3/26/16 66 67 = 1.0.1 = 68 * Small code cleanup, attempt to get images into plugin at wp.org/plugins 3/25/16 69 70 = 1.0.0 = 71 * First version released and added to WP SVN on 3/20/16 192 Added shortcode functionality for displaying stats in posts and pages. -
tk-bbpress-stats/trunk/views/widget.php
r1379119 r3450098 1 <!-- This file is used to markup the public-facing widget. --> 1 <?php 2 /** 3 * Widget display template 4 * 5 * @package TK_bbPress_Stats 6 * @since 2.0.0 7 * 8 * Security: All variables are sanitized in the widget() method before inclusion 9 */ 2 10 3 <dl> 4 <?php 5 6 global $wp_query, $wpdb; 7 $user_count = $wpdb->get_var("SELECT COUNT(ID) FROM ".$wpdb->prefix."users"); 8 $topic_count = $wpdb->get_var("SELECT COUNT(ID) FROM ".$wpdb->prefix."posts WHERE post_status = 'publish' AND post_type = 'topic'"); 9 $reply_count = $wpdb->get_var("SELECT COUNT(ID) FROM ".$wpdb->prefix."posts WHERE post_status = 'publish' AND post_type = 'reply'"); 10 $forum_count = $wpdb->get_var("SELECT COUNT(ID) FROM ".$wpdb->prefix."posts WHERE post_status = 'publish' AND post_type = 'forum'"); 11 $total_count = $topic_count + $reply_count; 12 13 14 if($show_user_count == 'true'){ 15 echo '<dt class="tk_bbpress_stats">' . 'Users: ' . '</dt>' . '<dd class="tk_bbpress_stats">' . number_format($user_count) . '</dd>'; 16 } 17 if($show_forum_count == 'true'){ 18 echo '<dt class="tk_bbpress_stats">' . 'Forums: ' . '</dt>' . '<dd class="tk_bbpress_stats">' . number_format($forum_count) . '</dd>'; 19 } 20 if($show_topic_count == 'true'){ 21 echo '<dt class="tk_bbpress_stats">' . 'Topics: ' . '</dt>' . '<dd class="tk_bbpress_stats">' . number_format($topic_count) . '</dd>'; 22 } 23 if($show_reply_count == 'true'){ 24 echo '<dt class="tk_bbpress_stats">' . 'Replies: ' . '</dt>' . '<dd class="tk_bbpress_stats">' . number_format($reply_count) . '</dd>'; 25 } 26 if($show_total_count == 'true'){ 27 echo '<dt class="tk_bbpress_stats">' . 'Total Posts: ' . '</dt>' . '<dd class="tk_bbpress_stats">' . number_format($total_count) . '</dd>'; 11 // Prevent direct file access 12 if (!defined('ABSPATH')) { 13 exit; 28 14 } 29 15 16 // Variables available from widget() method: 17 // $show_user_count, $show_forum_count, $show_topic_count, $show_reply_count, $show_total_count 18 // $user_count, $forum_count, $topic_count, $reply_count, $total_count 30 19 ?> 31 </dl> 20 21 <div class="tk-bbpress-stats"> 22 <?php if ($show_user_count) : ?> 23 <div class="tk-bbpress-stats-item"> 24 <span class="tk-bbpress-stats-label"><?php esc_html_e('Users:', 'tk-bbpress-stats'); ?></span> 25 <span class="tk-bbpress-stats-value"><?php echo esc_html(number_format_i18n($user_count)); ?></span> 26 </div> 27 <?php endif; ?> 28 29 <?php if ($show_forum_count) : ?> 30 <div class="tk-bbpress-stats-item"> 31 <span class="tk-bbpress-stats-label"><?php esc_html_e('Forums:', 'tk-bbpress-stats'); ?></span> 32 <span class="tk-bbpress-stats-value"><?php echo esc_html(number_format_i18n($forum_count)); ?></span> 33 </div> 34 <?php endif; ?> 35 36 <?php if ($show_topic_count) : ?> 37 <div class="tk-bbpress-stats-item"> 38 <span class="tk-bbpress-stats-label"><?php esc_html_e('Topics:', 'tk-bbpress-stats'); ?></span> 39 <span class="tk-bbpress-stats-value"><?php echo esc_html(number_format_i18n($topic_count)); ?></span> 40 </div> 41 <?php endif; ?> 42 43 <?php if ($show_reply_count) : ?> 44 <div class="tk-bbpress-stats-item"> 45 <span class="tk-bbpress-stats-label"><?php esc_html_e('Replies:', 'tk-bbpress-stats'); ?></span> 46 <span class="tk-bbpress-stats-value"><?php echo esc_html(number_format_i18n($reply_count)); ?></span> 47 </div> 48 <?php endif; ?> 49 50 <?php if ($show_total_count) : ?> 51 <div class="tk-bbpress-stats-item"> 52 <span class="tk-bbpress-stats-label"><?php esc_html_e('Total Posts:', 'tk-bbpress-stats'); ?></span> 53 <span class="tk-bbpress-stats-value"><?php echo esc_html(number_format_i18n($total_count)); ?></span> 54 </div> 55 <?php endif; ?> 56 </div>
Note: See TracChangeset
for help on using the changeset viewer.