1
|
|
|
<?php |
|
|
|
|
2
|
|
|
/** |
3
|
|
|
* Rentbits.com Average Rental Rates Widget (http://rentbits.com/rb/page/average-rental-rates-widget.html) |
4
|
|
|
* |
5
|
|
|
* @package RE-PRO |
6
|
|
|
*/ |
7
|
|
|
|
8
|
|
|
/* Exit if accessed directly. */ |
9
|
|
|
if ( ! defined( 'ABSPATH' ) ) { exit; } |
10
|
|
|
|
11
|
|
|
/** |
12
|
|
|
* RentbitsAverageRentalRatesWidget class. |
13
|
|
|
* |
14
|
|
|
* @extends WP_Widget |
15
|
|
|
*/ |
16
|
|
|
class RentbitsAverageRentalRatesWidget extends WP_Widget { |
|
|
|
|
17
|
|
|
|
18
|
|
|
/** |
19
|
|
|
* __construct function. |
20
|
|
|
* |
21
|
|
|
* @access public |
22
|
|
|
* @return void |
|
|
|
|
23
|
|
|
*/ |
24
|
|
|
public function __construct() { |
25
|
|
|
|
26
|
|
|
parent::__construct( |
27
|
|
|
'rentbits_avg_rental_rates', |
28
|
|
|
__( 'Rentbits Average Rental Rates', 're-pro' ), |
29
|
|
|
array( |
30
|
|
|
'description' => __( 'Display the current average rental price for any location.', 're-pro' ), |
31
|
|
|
'classname' => 're-pro re-pro-widget rentbits-widget rentbits-avg-rental-rates', |
32
|
|
|
'customize_selective_refresh' => true, |
33
|
|
|
) |
34
|
|
|
); |
35
|
|
|
} |
36
|
|
|
|
37
|
|
|
/** |
38
|
|
|
* Widget function. |
39
|
|
|
* |
40
|
|
|
* @access public |
41
|
|
|
* @param mixed $args Arguments. |
42
|
|
|
* @param mixed $instance Instance. |
43
|
|
|
*/ |
44
|
|
|
public function widget( $args, $instance ) { |
45
|
|
|
|
46
|
|
|
$title = ! empty( $instance['title'] ) ? $instance['title'] : ''; |
47
|
|
|
$location = ! empty( $instance['location'] ) ? $instance['location'] : ''; |
48
|
|
|
|
49
|
|
|
echo $args['before_widget']; |
50
|
|
|
|
51
|
|
|
echo $args['before_title'] . esc_attr( $title ) . $args['after_title']; |
52
|
|
|
|
53
|
|
|
$rentbits_widgets = new RentbitsWidgets(); |
54
|
|
|
|
55
|
|
|
$rentbits_widgets->get_average_rental_rates_widget( $location ); |
56
|
|
|
|
57
|
|
|
echo $args['after_widget']; |
58
|
|
|
} |
59
|
|
|
|
60
|
|
|
/** |
61
|
|
|
* Form function. |
62
|
|
|
* |
63
|
|
|
* @access public |
64
|
|
|
* @param mixed $instance Instance. |
65
|
|
|
* @return void |
66
|
|
|
*/ |
67
|
|
View Code Duplication |
public function form( $instance ) { |
|
|
|
|
68
|
|
|
|
69
|
|
|
// Set default values. |
70
|
|
|
$instance = wp_parse_args( (array) $instance, array( |
71
|
|
|
'title' => '', |
72
|
|
|
'location' => '', |
73
|
|
|
) ); |
74
|
|
|
|
75
|
|
|
// Retrieve an existing value from the database. |
76
|
|
|
$title = ! empty( $instance['title'] ) ? $instance['title'] : ''; |
77
|
|
|
$location = ! empty( $instance['location'] ) ? $instance['location'] : ''; |
78
|
|
|
|
79
|
|
|
// Title. |
80
|
|
|
echo '<p>'; |
81
|
|
|
echo ' <label for="' . $this->get_field_id( 'title' ) . '" class="title-label">' . __( 'Tile:', 're-pro' ) . '</label>'; |
82
|
|
|
echo ' <input id="' . $this->get_field_id( 'title' ) . '" name="' . $this->get_field_name( 'title' ) . '" value="' . $title . '" class="widefat">'; |
83
|
|
|
echo '</p>'; |
84
|
|
|
|
85
|
|
|
// Location. |
86
|
|
|
echo '<p>'; |
87
|
|
|
echo ' <label for="' . $this->get_field_id( 'location' ) . '" class="title-label">' . __( 'Location:', 're-pro' ) . '</label>'; |
88
|
|
|
echo ' <input id="' . $this->get_field_id( 'location' ) . '" name="' . $this->get_field_name( 'location' ) . '" value="' . $location . '" class="widefat">'; |
89
|
|
|
echo '</p>'; |
90
|
|
|
|
91
|
|
|
} |
92
|
|
|
|
93
|
|
|
/** |
94
|
|
|
* Update Widget Instance. |
95
|
|
|
* |
96
|
|
|
* @access public |
97
|
|
|
* @param mixed $new_instance New Instance. |
98
|
|
|
* @param mixed $old_instance Old Instance. |
99
|
|
|
* @return $instance |
|
|
|
|
100
|
|
|
*/ |
101
|
|
|
public function update( $new_instance, $old_instance ) { |
102
|
|
|
|
103
|
|
|
$instance = $old_instance; |
104
|
|
|
|
105
|
|
|
$instance['title'] = ! empty( $new_instance['title'] ) ? strip_tags( $new_instance['title'] ) : ''; |
106
|
|
|
$instance['location'] = ! empty( $new_instance['location'] ) ? strip_tags( $new_instance['location'] ) : ''; |
107
|
|
|
|
108
|
|
|
return $instance; |
109
|
|
|
} |
110
|
|
|
} |
111
|
|
|
|
112
|
|
|
/** |
113
|
|
|
* Register Rentbits.com Rental Comparison Widget. |
114
|
|
|
* |
115
|
|
|
* @access public |
116
|
|
|
* @return void |
117
|
|
|
*/ |
118
|
|
|
function repro_rentbits_avg_rental_rates() { |
119
|
|
|
if ( ! is_ssl() ) { |
120
|
|
|
register_widget( 'RentbitsAverageRentalRatesWidget' ); |
121
|
|
|
} |
122
|
|
|
} |
123
|
|
|
add_action( 'widgets_init', 'repro_rentbits_avg_rental_rates' ); |
124
|
|
|
|
The PSR-1: Basic Coding Standard recommends that a file should either introduce new symbols, that is classes, functions, constants or similar, or have side effects. Side effects are anything that executes logic, like for example printing output, changing ini settings or writing to a file.
The idea behind this recommendation is that merely auto-loading a class should not change the state of an application. It also promotes a cleaner style of programming and makes your code less prone to errors, because the logic is not spread out all over the place.
To learn more about the PSR-1, please see the PHP-FIG site on the PSR-1.