PluginProbe
Charitable – Donation & Fundraising Platform (Donation Forms, Recurring Donations & Fundraising Campaigns) / 1.8.11.3
Charitable – Donation & Fundraising Platform (Donation Forms, Recurring Donations & Fundraising Campaigns) v1.8.11.3
1.8.13 1.8.12.3 1.8.12.2 1.8.12.1 1.8.12 1.8.11.3 1.8.11.2 1.8.11.1 1.8.11 1.6.6 1.6.60 1.6.7 1.6.8 1.6.9 1.7.0 1.7.0.1 1.7.0.11 1.7.0.12 1.7.0.14 1.7.0.2 1.7.0.3 1.7.0.5 1.7.0.6 1.7.0.7 1.7.0.9 All 211 releases
charitable / includes / widgets / class-charitable-donation-stats-widget.php

class-charitable-donation-stats-widget.php in Charitable – Donation & Fundraising Platform (Donation Forms, Recurring Donations & Fundraising Campaigns) 1.8.11.3, at includes/widgets/class-charitable-donation-stats-widget.php

118 lines 3.3 KB
No matching file
Up and down to move Enter to open Esc to close
Raw Download Zip
1 <?php
2 /**
3 * Donation stats widget class.
4 *
5 * @package Charitable/Classes/Charitable_Donation_Stats_Widget
6 * @version 1.0.0
7 * @author David Bisset
8 * @copyright Copyright (c) 2023, WP Charitable LLC
9 * @license http://opensource.org/licenses/gpl-2.0.php GNU Public License
10 */
11
12 // Exit if accessed directly.
13 if ( ! defined( 'ABSPATH' ) ) {
14 exit;
15 }
16
17 if ( ! class_exists( 'Charitable_Donation_Stats_Widget' ) ) :
18
19 /**
20 * Charitable_Donation_Stats_Widget class.
21 *
22 * @since 1.0.0
23 */
24 class Charitable_Donation_Stats_Widget extends WP_Widget {
25
26 /**
27 * Instantiate the widget and set up basic configuration.
28 *
29 * @since 1.0.0
30 */
31 public function __construct() {
32 parent::__construct(
33 'charitable_donation_stats_widget',
34 __( 'Donation Stats', 'charitable' ),
35 array(
36 'description' => __( 'Show off your donation statistics.', 'charitable' ),
37 'customize_selective_refresh' => true,
38 )
39 );
40 }
41
42 /**
43 * Display the widget contents on the front-end.
44 *
45 * @since 1.0.0
46 *
47 * @param array $args Display arguments including 'before_title', 'after_title',
48 * 'before_widget', and 'after_widget'.
49 * @param array $instance The settings for the particular instance of the widget.
50 * @return void
51 */
52 public function widget( $args, $instance ) {
53 $view_args = array_merge( $args, $instance );
54
55 if ( ! array_key_exists( 'title', $view_args ) ) {
56 $view_args['title'] = __( 'Donation Statistics', 'charitable' );
57 }
58
59 charitable_template( 'widgets/donation-stats.php', $view_args );
60 }
61
62 /**
63 * Display the widget form in the admin.
64 *
65 * @since 1.0.0
66 *
67 * @param array $instance The current settings for the widget options.
68 * @return void
69 */
70 public function form( $instance ) {
71 $title = isset( $instance['title'] ) ? esc_attr( $instance['title'] ) : '';
72 ?>
73 <p>
74 <label for="<?php echo esc_attr( $this->get_field_id( 'title' ) ); ?>"><?php esc_html_e( 'Title:', 'charitable' ); ?></label>
75 <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 ); ?>" />
76 </p>
77 <?php
78 /**
79 * Add extra settings for the widget.
80 *
81 * @since 1.5.0
82 *
83 * @param array $args Widget instance arguments.
84 * @param Charitable_Donation_Stats_Widget $this This widget instance.
85 */
86 do_action( 'charitable_donation_stats_widget_settings_bottom', $instance, $this );
87 }
88
89 /**
90 * Update the widget settings in the admin.
91 *
92 * @since 1.0.0
93 *
94 * @param array $new_instance The updated settings.
95 * @param array $old_instance The old settings.
96 * @return array
97 */
98 public function update( $new_instance, $old_instance ) {
99 $instance = array(
100 'title' => wp_strip_all_tags( $new_instance['title'] ),
101 );
102
103 /**
104 * Filter the instance arguments.
105 *
106 * @since 1.5.0
107 *
108 * @param array $instance The parsed instance settings.
109 * @param array $new_instance The updated settings.
110 * @param array $old_instance The old settings.
111 * @return array
112 */
113 return apply_filters( 'charitable_donation_stats_widget_update_instance', $instance, $new_instance, $old_instance );
114 }
115 }
116
117 endif;
118