Give_Donor_Wall_Widget::widget()   A
last analyzed

Complexity

Conditions 3
Paths 3

Size

Total Lines 26

Duplication

Lines 0
Ratio 0 %

Importance

Changes 0
Metric Value
cc 3
nc 3
nop 2
dl 0
loc 26
rs 9.504
c 0
b 0
f 0
1
<?php
2
/**
3
 * Donors Gravatars
4
 *
5
 * @package     Give
6
 * @subpackage  Classes/Give_Donors_Gravatars
7
 * @copyright   Copyright (c) 2016, GiveWP
8
 * @license     https://opensource.org/licenses/gpl-license GNU Public License
9
 * @since       1.0
10
 */
11
12
// Exit if accessed directly.
13
if ( ! defined( 'ABSPATH' ) ) {
14
	exit;
15
}
16
17
/**
18
 * Give_Donor_Wall_Widget Class
19
 *
20
 * This class handles donors gravatars
21
 *
22
 * @since 1.0
23
 */
24
class Give_Donor_Wall_Widget extends WP_Widget {
25
26
	/**
27
	 * Widget constructor
28
	 *
29
	 * @since  1.0
30
	 * @access public
31
	 */
32
	public function __construct() {
33
34
		// widget settings
35
		$widget_ops = array(
36
			'classname'   => 'give-donors-gravatars',
37
			'description' => esc_html__( 'Displays gravatars of people who have donated using your your form. Will only show on the single form page.', 'give' ),
38
		);
39
40
		// widget control settings
41
		$control_ops = array(
42
			'width'   => 250,
43
			'height'  => 350,
44
			'id_base' => 'give_gravatars_widget'
45
		);
46
47
		// create the widget
48
		parent::__construct(
49
			'give_donors_gravatars_widget',
50
			esc_html__( 'Give Donors Gravatars', 'give' ),
51
			$widget_ops,
52
			$control_ops
53
		);
54
55
	}
56
57
	/**
58
	 * Donors gravatars widget content
59
	 *
60
	 * Outputs the content of the widget
61
	 *
62
	 * @since  1.0
63
	 * @access public
64
	 *
65
	 * @param  array $args     Display arguments including 'before_title', 'after_title', 'before_widget', and 'after_widget'.
66
	 * @param  array $instance Settings for the current Links widget instance.
67
	 *
68
	 * @return void
69
	 */
70
	public function widget( $args, $instance ) {
71
72
		//@TODO: Don't extract it!!!
73
		extract( $args );
0 ignored issues
show
introduced by
extract() usage is highly discouraged, due to the complexity and unintended issues it might cause.
Loading history...
74
75
		if ( ! is_singular( 'give_forms' ) ) {
76
			return;
77
		}
78
79
		// Variables from widget settings
80
		$title = apply_filters( 'widget_title', $instance['title'] );
81
82
		// Used by themes. Opens the widget
83
		echo $before_widget;
0 ignored issues
show
introduced by
Expected next thing to be a escaping function, not '$before_widget'
Loading history...
84
85
		// Display the widget title
86
		if ( $title ) {
87
			echo $before_title . $title . $after_title;
0 ignored issues
show
introduced by
Expected next thing to be a escaping function, not '$before_title'
Loading history...
introduced by
Expected next thing to be a escaping function, not '$title'
Loading history...
introduced by
Expected next thing to be a escaping function, not '$after_title'
Loading history...
88
		}
89
90
		echo Give_Donor_Wall::get_instance()->gravatars( get_the_ID(), null ); // remove title
0 ignored issues
show
Bug introduced by
The method gravatars() does not seem to exist on object<Give_Donor_Wall>.

This check looks for calls to methods that do not seem to exist on a given type. It looks for the method on the type itself as well as in inherited classes or implemented interfaces.

This is most likely a typographical error or the method has been renamed.

Loading history...
introduced by
Expected a sanitizing function (see Codex for 'Data Validation'), but instead saw 'Give_Donor_Wall'
Loading history...
91
92
		// Used by themes. Closes the widget
93
		echo $after_widget;
0 ignored issues
show
introduced by
Expected next thing to be a escaping function, not '$after_widget'
Loading history...
94
95
	}
96
97
	/**
98
	 * Update donors gravatars
99
	 *
100
	 * Processes widget options to be saved.
101
	 *
102
	 * @since  1.0
103
	 * @access public
104
	 *
105
	 * @param  array $new_instance New settings for this instance as input by the user via WP_Widget::form().
106
	 * @param  array $old_instance Old settings for this instance.
107
	 *
108
	 * @return array Updated settings to save.
109
	 */
110
	public function update( $new_instance, $old_instance ) {
111
112
		$instance = $old_instance;
113
114
		$instance['title'] = strip_tags( $new_instance['title'] );
115
116
		return $instance;
117
118
	}
119
120
	/**
121
	 * Output donors
122
	 *
123
	 * Displays the actual form on the widget page.
124
	 *
125
	 * @since  1.0
126
	 * @access public
127
	 *
128
	 * @param  array $instance Current settings.
129
	 *
130
	 * @return void
131
	 */
132
	public function form( $instance ) {
133
134
		// Set up some default widget settings.
135
		$defaults = array(
136
			'title' => '',
137
		);
138
139
		$instance = wp_parse_args( (array) $instance, $defaults ); ?>
140
141
		<!-- Title -->
142
		<p>
143
			<label for="<?php echo $this->get_field_id( 'title' ); ?>"><?php esc_html_e( 'Title:', 'give' ) ?></label>
0 ignored issues
show
introduced by
Expected next thing to be a escaping function, not '$this'
Loading history...
144
			<input class="widefat" id="<?php echo $this->get_field_id( 'title' ); ?>" name="<?php echo $this->get_field_name( 'title' ); ?>" type="text" value="<?php echo $instance['title']; ?>" />
0 ignored issues
show
introduced by
Expected next thing to be a escaping function, not '$this'
Loading history...
introduced by
Expected next thing to be a escaping function, not '$instance'
Loading history...
145
		</p>
146
147
		<?php
148
	}
149
150
	/**
151
	 * Register the widget
152
	 *
153
	 * @return void
154
	 */
155
	function widget_init(){
0 ignored issues
show
Best Practice introduced by
It is generally recommended to explicitly declare the visibility for methods.

Adding explicit visibility (private, protected, or public) is generally recommend to communicate to other developers how, and from where this method is intended to be used.

Loading history...
156
		register_widget( $this->self );
157
	}
158
159
}
160
161
162
163