1
|
|
|
<?php |
|
|
|
|
2
|
|
|
|
3
|
|
|
/* Exit if accessed directly. */ |
4
|
|
|
if ( ! defined( 'ABSPATH' ) ) { exit; } |
5
|
|
|
|
6
|
|
|
/** |
7
|
|
|
* Zillow Monthly Payment Calculator Widget (https://www.zillow.com/webtools/widgets/monthly-payment-calculator-widget/) |
8
|
|
|
* |
9
|
|
|
* @package RE-PRO |
10
|
|
|
*/ |
11
|
|
|
|
12
|
|
|
/** |
13
|
|
|
* ZillowMonthlyPaymentCalcWidget class. |
14
|
|
|
* |
15
|
|
|
* @extends WP_Widget |
16
|
|
|
*/ |
17
|
|
View Code Duplication |
class ZillowMonthlyPaymentCalcWidget extends WP_Widget { |
|
|
|
|
18
|
|
|
|
19
|
|
|
|
20
|
|
|
/** |
21
|
|
|
* __construct function. |
22
|
|
|
* |
23
|
|
|
* @access public |
24
|
|
|
* @return void |
|
|
|
|
25
|
|
|
*/ |
26
|
|
|
public function __construct() { |
27
|
|
|
|
28
|
|
|
parent::__construct( |
29
|
|
|
'zillow_monthly_paycalc_widget', |
30
|
|
|
__( 'Zillow Monthly Payment Calculator', 're-pro' ), |
31
|
|
|
array( |
32
|
|
|
'description' => __( 'Display a Monthly Payment Calculator from Zillow.', 're-pro' ), |
33
|
|
|
'classname' => 're-pro re-pro-widget zillow-widget zillow-widget-monthly-payment-calculator', |
34
|
|
|
'customize_selective_refresh' => true, |
35
|
|
|
) |
36
|
|
|
); |
37
|
|
|
} |
38
|
|
|
|
39
|
|
|
/** |
40
|
|
|
* Widget function. |
41
|
|
|
* |
42
|
|
|
* @access public |
43
|
|
|
* @param mixed $args Arguments. |
44
|
|
|
* @param mixed $instance Instance. |
45
|
|
|
* @return void |
46
|
|
|
*/ |
47
|
|
|
public function widget( $args, $instance ) { |
48
|
|
|
|
49
|
|
|
$iframe_id = ! empty( $args['widget_id'] ) ? $args['widget_id'] : ''; |
50
|
|
|
$title = ! empty( $instance['title'] ) ? $instance['title'] : ''; |
51
|
|
|
|
52
|
|
|
echo $args['before_widget']; |
53
|
|
|
|
54
|
|
|
echo $args['before_title'] . esc_attr( $title ) . $args['after_title']; |
55
|
|
|
|
56
|
|
|
$zillow_widgets = new ZillowWidgets(); |
57
|
|
|
|
58
|
|
|
return $zillow_widgets->get_monthlypay_calc_widget( $iframe_id ); |
59
|
|
|
|
60
|
|
|
echo $args['after_widget']; |
|
|
|
|
61
|
|
|
} |
62
|
|
|
|
63
|
|
|
/** |
64
|
|
|
* Form function. |
65
|
|
|
* |
66
|
|
|
* @access public |
67
|
|
|
* @param mixed $instance Instance. |
68
|
|
|
* @return void |
69
|
|
|
*/ |
70
|
|
|
public function form( $instance ) { |
71
|
|
|
|
72
|
|
|
// Set default values. |
73
|
|
|
$instance = wp_parse_args( (array) $instance, array( |
74
|
|
|
'title' => '', |
75
|
|
|
'screenname' => '', |
76
|
|
|
'region' => '', |
77
|
|
|
'textcolor' => '000000', |
78
|
|
|
'zuid' => '', |
79
|
|
|
)); |
80
|
|
|
|
81
|
|
|
// Retrieve an existing value from the database. |
82
|
|
|
$title = ! empty( $instance['title'] ) ? $instance['title'] : ''; |
83
|
|
|
|
84
|
|
|
// Title. |
85
|
|
|
echo '<p>'; |
86
|
|
|
echo ' <label for="' . $this->get_field_id( 'title' ) . '" class="title-label">' . __( 'Tile:', 're-pro' ) . '</label>'; |
87
|
|
|
echo ' <input id="' . $this->get_field_id( 'title' ) . '" name="' . $this->get_field_name( 'title' ) . '" value="' . $title . '" class="widefat">'; |
88
|
|
|
echo '</p>'; |
89
|
|
|
|
90
|
|
|
} |
91
|
|
|
|
92
|
|
|
/** |
93
|
|
|
* Update Widget Instance. |
94
|
|
|
* |
95
|
|
|
* @access public |
96
|
|
|
* @param mixed $new_instance New Instance. |
97
|
|
|
* @param mixed $old_instance Old Instance. |
98
|
|
|
* @return $instance |
|
|
|
|
99
|
|
|
*/ |
100
|
|
|
public function update( $new_instance, $old_instance ) { |
101
|
|
|
|
102
|
|
|
$instance = $old_instance; |
103
|
|
|
|
104
|
|
|
$instance['title'] = ! empty( $new_instance['title'] ) ? strip_tags( $new_instance['title'] ) : ''; |
105
|
|
|
|
106
|
|
|
return $instance; |
107
|
|
|
} |
108
|
|
|
} |
109
|
|
|
|
110
|
|
|
/** |
111
|
|
|
* Register Zillow Monthly Pay Calc Widget. |
112
|
|
|
* |
113
|
|
|
* @access public |
114
|
|
|
* @return void |
115
|
|
|
*/ |
116
|
|
|
/*function repro_zillow_monthly_pay_calc_widget() { |
|
|
|
|
117
|
|
|
|
118
|
|
|
register_widget( 'ZillowMonthlyPaymentCalcWidget' ); |
119
|
|
|
} |
120
|
|
|
add_action( 'widgets_init', 'repro_zillow_monthly_pay_calc_widget' );*/ |
121
|
|
|
|
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.