PluginProbe
WebberZone Top 10 — Popular Posts / 4.3.4
WebberZone Top 10 — Popular Posts v4.3.4
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.3.4, at includes/frontend/widgets/class-count-widget.php

117 lines 2.9 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', 'where-did-they-go-from-here' ),
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 /**
55 * Fires after Top 10 widget options.
56 *
57 * @since 2.0.0
58 *
59 * @param array $instance Widget options array
60 */
61 do_action( 'tptn_widget_options_after', $instance );
62 ?>
63
64 <?php
65 } //ending form creation
66
67 /**
68 * Sanitize widget form values as they are saved.
69 *
70 * @see WP_Widget::update()
71 *
72 * @param array $new_instance Values just sent to be saved.
73 * @param array $old_instance Previously saved values from database.
74 *
75 * @return array Updated safe values to be saved.
76 */
77 public function update( $new_instance, $old_instance ) {
78 $instance = $old_instance;
79 $instance['title'] = wp_strip_all_tags( $new_instance['title'] );
80
81 /**
82 * Filters Update widget options array.
83 *
84 * @since 2.0.0
85 *
86 * @param array $instance Widget options array
87 */
88 return apply_filters( 'tptn_widget_options_update', $instance );
89 } //ending update
90
91 /**
92 * Front-end display of widget.
93 *
94 * @see WP_Widget::widget()
95 *
96 * @param array $args Widget arguments.
97 * @param array $instance Saved values from database.
98 */
99 public function widget( $args, $instance ) {
100
101 $title = apply_filters( 'widget_title', empty( $instance['title'] ) ? '' : $instance['title'] );
102
103 $output = $args['before_widget'];
104 if ( ! empty( $title ) ) {
105 $output .= $args['before_title'] . $title . $args['after_title'];
106 }
107
108 $output .= '<div class="textwidget tptn-text-only">';
109 $output .= \WebberZone\Top_Ten\Counter::get_post_count_only( 1, 'overall', 0 );
110 $output .= '</div>';
111
112 $output .= $args['after_widget'];
113
114 echo $output; // phpcs:ignore WordPress.Security.EscapeOutput.OutputNotEscaped
115 } //ending function widget
116 }
117