PluginProbe
WebberZone Top 10 — Popular Posts / 4.5.1
WebberZone Top 10 — Popular Posts v4.5.1
4.5.1 4.5.0 4.4.3 4.4.2 4.4.1 4.4.0 4.3.4 4.3.3 4.3.2 4.3.1 4.3.0 trunk 1.0 1.0.1 1.1 1.2 1.3 1.4 1.4.1 1.5 1.5.1 1.5.2 1.5.3 1.6 1.6.1 All 117 releases
top-10 / includes / frontend / widgets / class-count-widget.php

class-count-widget.php in WebberZone Top 10 — Popular Posts 4.5.1, at includes/frontend/widgets/class-count-widget.php

105 lines 2.8 KB
No matching file
Up and down to move Enter to open Esc to close
Raw Download Zip
1 <?php
2 /**
3 * Count Widget class.
4 *
5 * @package WebberZone\Top_Ten\Frontend\Widgets
6 */
7
8 namespace WebberZone\Top_Ten\Frontend\Widgets;
9
10 if ( ! defined( 'WPINC' ) ) {
11 die;
12 }
13
14 /**
15 * Widget to display the overall count.
16 *
17 * @since 3.3.0
18 */
19 class Count_Widget extends \WP_Widget {
20
21 /**
22 * Register widget with WordPress.
23 */
24 public function __construct() {
25 parent::__construct(
26 'widget_tptn_count', // Base ID.
27 __( 'Overall count [Top 10]', 'top-10' ), // Name.
28 array(
29 'description' => __( 'Display overall count', 'top-10' ),
30 'customize_selective_refresh' => true,
31 'classname' => 'tptn_posts_count_widget',
32 )
33 );
34 }
35
36 /**
37 * Back-end widget form.
38 *
39 * @see WP_Widget::form()
40 *
41 * @param array $instance Previously saved values from database.
42 */
43 public function form( $instance ) {
44 $title = isset( $instance['title'] ) ? esc_attr( $instance['title'] ) : '';
45
46 ?>
47 <p>
48 <label for="<?php echo esc_attr( $this->get_field_id( 'title' ) ); ?>">
49 <?php esc_html_e( 'Title', 'top-10' ); ?>: <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 ); ?>" />
50 </label>
51 </p>
52
53 <?php
54 /** This action is documented in includes/frontend/widgets/class-posts-widget.php */
55 do_action( 'tptn_widget_options_after', $instance );
56 ?>
57
58 <?php
59 } //ending form creation
60
61 /**
62 * Sanitize widget form values as they are saved.
63 *
64 * @see WP_Widget::update()
65 *
66 * @param array $new_instance Values just sent to be saved.
67 * @param array $old_instance Previously saved values from database.
68 *
69 * @return array Updated safe values to be saved.
70 */
71 public function update( $new_instance, $old_instance ) {
72 $instance = $old_instance;
73 $instance['title'] = wp_strip_all_tags( $new_instance['title'] );
74
75 /** This action is documented in includes/frontend/widgets/class-posts-widget.php */
76 return apply_filters( 'tptn_widget_options_update', $instance );
77 } //ending update
78
79 /**
80 * Front-end display of widget.
81 *
82 * @see WP_Widget::widget()
83 *
84 * @param array $args Widget arguments.
85 * @param array $instance Saved values from database.
86 */
87 public function widget( $args, $instance ) {
88
89 $title = apply_filters( 'widget_title', empty( $instance['title'] ) ? '' : $instance['title'] );
90
91 $output = $args['before_widget'];
92 if ( ! empty( $title ) ) {
93 $output .= $args['before_title'] . $title . $args['after_title'];
94 }
95
96 $output .= '<div class="textwidget tptn-text-only">';
97 $output .= \WebberZone\Top_Ten\Counter::get_post_count_only( 1, 'overall', 0 );
98 $output .= '</div>';
99
100 $output .= $args['after_widget'];
101
102 echo $output; // phpcs:ignore WordPress.Security.EscapeOutput.OutputNotEscaped
103 } //ending function widget
104 }
105