Give_Donor_Wall_Widget::widget()   A
last analyzed

Complexity

Conditions 3
Paths 3

Size

Total Lines 28

Duplication

Lines 0
Ratio 0 %

Importance

Changes 0
Metric Value
cc 3
nc 3
nop 2
dl 0
loc 28
rs 9.472
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, WordImpress
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
		$gravatars = new Give_Donor_Wall();
91
92
		echo $gravatars->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 next thing to be a escaping function, not '$gravatars'
Loading history...
93
94
		// Used by themes. Closes the widget
95
		echo $after_widget;
0 ignored issues
show
introduced by
Expected next thing to be a escaping function, not '$after_widget'
Loading history...
96
97
	}
98
99
	/**
100
	 * Update donors gravatars
101
	 *
102
	 * Processes widget options to be saved.
103
	 *
104
	 * @since  1.0
105
	 * @access public
106
	 *
107
	 * @param  array $new_instance New settings for this instance as input by the user via WP_Widget::form().
108
	 * @param  array $old_instance Old settings for this instance.
109
	 *
110
	 * @return array Updated settings to save.
111
	 */
112
	public function update( $new_instance, $old_instance ) {
113
114
		$instance = $old_instance;
115
116
		$instance['title'] = strip_tags( $new_instance['title'] );
117
118
		return $instance;
119
120
	}
121
122
	/**
123
	 * Output donors
124
	 *
125
	 * Displays the actual form on the widget page.
126
	 *
127
	 * @since  1.0
128
	 * @access public
129
	 *
130
	 * @param  array $instance Current settings.
131
	 *
132
	 * @return void
133
	 */
134
	public function form( $instance ) {
135
136
		// Set up some default widget settings.
137
		$defaults = array(
138
			'title' => '',
139
		);
140
141
		$instance = wp_parse_args( (array) $instance, $defaults ); ?>
142
143
		<!-- Title -->
144
		<p>
145
			<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...
146
			<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...
147
		</p>
148
149
		<?php
150
	}
151
152
	/**
153
	 * Register the widget
154
	 *
155
	 * @return void
156
	 */
157
	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...
158
		register_widget( $this->self );
159
	}
160
161
}
162
163
164
165