1
|
|
|
<?php |
|
|
|
|
2
|
|
|
/** |
3
|
|
|
* Homes.com Mortgage Calculator (http://www.homes.com/widget/mortgage-calculator/) |
4
|
|
|
* |
5
|
|
|
* @package RE-PRO |
6
|
|
|
*/ |
7
|
|
|
|
8
|
|
|
/* Exit if accessed directly. */ |
9
|
|
|
if ( ! defined( 'ABSPATH' ) ) { exit; } |
10
|
|
|
|
11
|
|
|
/** |
12
|
|
|
* HomesMortgageCalculatorWidget class. |
13
|
|
|
* |
14
|
|
|
* @extends WP_Widget |
15
|
|
|
*/ |
16
|
|
|
class HomesMortgageCalculatorWidget 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
|
|
|
'homes_mortgage_calc', |
28
|
|
|
__( 'Homes Mortgage Calculator', 're-pro' ), |
29
|
|
|
array( |
30
|
|
|
'description' => __( 'Display a mortgage calculator from Homes.com', 're-pro' ), |
31
|
|
|
'classname' => 're-pro re-pro-widget homes-widget homes-mortgage-calc', |
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
|
|
View Code Duplication |
public function widget( $args, $instance ) { |
|
|
|
|
45
|
|
|
|
46
|
|
|
$iframe_id = ! empty( $args['widget_id'] ) ? $args['widget_id'] : ''; |
47
|
|
|
$title = ! empty( $instance['title'] ) ? $instance['title'] : ''; |
48
|
|
|
$color = ! empty( $instance['color'] ) ? $instance['color'] : ''; |
49
|
|
|
|
50
|
|
|
echo $args['before_widget']; |
51
|
|
|
|
52
|
|
|
echo $args['before_title'] . esc_attr( $title ) . $args['after_title']; |
53
|
|
|
|
54
|
|
|
$homes_widgets = new HomesWidgets(); |
55
|
|
|
|
56
|
|
|
$homes_widgets->get_mortgage_calc( $iframe_id, $color ); |
57
|
|
|
|
58
|
|
|
echo $args['after_widget']; |
59
|
|
|
} |
60
|
|
|
|
61
|
|
|
/** |
62
|
|
|
* Form function. |
63
|
|
|
* |
64
|
|
|
* @access public |
65
|
|
|
* @param mixed $instance Instance. |
66
|
|
|
* @return void |
67
|
|
|
*/ |
68
|
|
View Code Duplication |
public function form( $instance ) { |
|
|
|
|
69
|
|
|
|
70
|
|
|
// Set default values. |
71
|
|
|
$instance = wp_parse_args( (array) $instance, array( |
72
|
|
|
'title' => '', |
73
|
|
|
'color' => '0054a0', |
74
|
|
|
) ); |
75
|
|
|
|
76
|
|
|
// Retrieve an existing value from the database. |
77
|
|
|
$title = ! empty( $instance['title'] ) ? $instance['title'] : ''; |
78
|
|
|
$color = ! empty( $instance['color'] ) ? $instance['color'] : ''; |
79
|
|
|
|
80
|
|
|
// Title. |
81
|
|
|
echo '<p>'; |
82
|
|
|
echo ' <label for="' . $this->get_field_id( 'title' ) . '" class="title-label">' . __( 'Tile:', 're-pro' ) . '</label>'; |
83
|
|
|
echo ' <input id="' . $this->get_field_id( 'title' ) . '" name="' . $this->get_field_name( 'title' ) . '" value="' . $title . '" class="widefat">'; |
84
|
|
|
echo '</p>'; |
85
|
|
|
|
86
|
|
|
// Color. |
87
|
|
|
echo '<p>'; |
88
|
|
|
echo ' <label for="' . $this->get_field_id( 'color' ) . '" class="title-label">' . __( 'Color:', 're-pro' ) . '</label>'; |
89
|
|
|
echo ' <input id="' . $this->get_field_id( 'color' ) . '" name="' . $this->get_field_name( 'color' ) . '" value="' . $color . '" class="widefat">'; |
90
|
|
|
echo '</p>'; |
91
|
|
|
|
92
|
|
|
} |
93
|
|
|
|
94
|
|
|
/** |
95
|
|
|
* Update Widget Instance. |
96
|
|
|
* |
97
|
|
|
* @access public |
98
|
|
|
* @param mixed $new_instance New Instance. |
99
|
|
|
* @param mixed $old_instance Old Instance. |
100
|
|
|
* @return $instance |
|
|
|
|
101
|
|
|
*/ |
102
|
|
|
public function update( $new_instance, $old_instance ) { |
103
|
|
|
|
104
|
|
|
$instance = $old_instance; |
105
|
|
|
|
106
|
|
|
$instance['title'] = ! empty( $new_instance['title'] ) ? strip_tags( $new_instance['title'] ) : ''; |
107
|
|
|
$instance['color'] = ! empty( $new_instance['color'] ) ? strip_tags( $new_instance['color'] ) : ''; |
108
|
|
|
|
109
|
|
|
return $instance; |
110
|
|
|
} |
111
|
|
|
} |
112
|
|
|
|
113
|
|
|
/** |
114
|
|
|
* Register Homes.com Featured Listings Widget. |
115
|
|
|
* |
116
|
|
|
* @access public |
117
|
|
|
* @return void |
118
|
|
|
*/ |
119
|
|
|
function repro_homes_com_mortgage_calc() { |
120
|
|
|
if ( ! is_ssl() ) { |
121
|
|
|
register_widget( 'HomesMortgageCalculatorWidget' ); |
122
|
|
|
} |
123
|
|
|
} |
124
|
|
|
add_action( 'widgets_init', 'repro_homes_com_mortgage_calc' ); |
125
|
|
|
|
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.