1
|
|
|
<?php |
|
|
|
|
2
|
|
|
|
3
|
|
|
|
4
|
|
|
|
5
|
|
|
/** |
6
|
|
|
* RealtorLogoWidget class. |
7
|
|
|
* |
8
|
|
|
* @extends WP_Widget |
9
|
|
|
*/ |
10
|
|
View Code Duplication |
class RealtorLogoWidget extends WP_Widget { |
|
|
|
|
11
|
|
|
|
12
|
|
|
|
13
|
|
|
/** |
14
|
|
|
* __construct function. |
15
|
|
|
* |
16
|
|
|
* @access public |
17
|
|
|
* @return void |
|
|
|
|
18
|
|
|
*/ |
19
|
|
|
public function __construct() { |
20
|
|
|
|
21
|
|
|
parent::__construct( |
22
|
|
|
'realtor_logo', |
23
|
|
|
__( 'Realtor Logo', 're-pro' ), |
24
|
|
|
array( |
25
|
|
|
'description' => __( 'Display the Realtor Logo.', 're-pro' ), |
26
|
|
|
'classname' => 're-pro realtor', |
27
|
|
|
) |
28
|
|
|
); |
29
|
|
|
|
30
|
|
|
} |
31
|
|
|
|
32
|
|
|
|
33
|
|
|
/** |
34
|
|
|
* Display Realtor Logo Widget. |
35
|
|
|
* |
36
|
|
|
* @access public |
37
|
|
|
* @param mixed $args |
38
|
|
|
* @param mixed $instance |
39
|
|
|
* @return void |
40
|
|
|
*/ |
41
|
|
|
public function widget( $args, $instance ) { |
42
|
|
|
|
43
|
|
|
if ( ! empty( $instance['title'] ) ) { |
44
|
|
|
$title = $instance['title']; |
45
|
|
|
} else { |
46
|
|
|
$title = ''; |
47
|
|
|
} |
48
|
|
|
$logo_size = $instance['logo_size']; |
49
|
|
|
|
50
|
|
|
echo $args['before_widget']; |
51
|
|
|
|
52
|
|
|
echo $args['before_title'] . esc_attr( $title ) . $args['after_title']; |
53
|
|
|
|
54
|
|
|
echo '<img src="'. esc_url( plugins_url( '../../assets/images/realtor/realtor.svg', __FILE__ ) ) .'" alt="'. __( 'Realtor', 're-pro' ) .'" height="' . $logo_size . '" width="' . $logo_size . '" class="re-pro realtor">'; |
55
|
|
|
|
56
|
|
|
echo $args['after_widget']; |
57
|
|
|
|
58
|
|
|
} |
59
|
|
|
|
60
|
|
|
|
61
|
|
|
/** |
62
|
|
|
* Widget Form. |
63
|
|
|
* |
64
|
|
|
* @access public |
65
|
|
|
* @param mixed $instance |
66
|
|
|
* @return void |
67
|
|
|
*/ |
68
|
|
|
public function form( $instance ) { |
69
|
|
|
|
70
|
|
|
// Set default values |
71
|
|
|
$instance = wp_parse_args( (array) $instance, array( |
72
|
|
|
'logo-size' => '32', |
73
|
|
|
'title' => '', |
74
|
|
|
) ); |
75
|
|
|
|
76
|
|
|
// Retrieve an existing value from the database |
77
|
|
|
$title = ! empty( $instance['title'] ) ? $instance['title'] : ''; |
78
|
|
|
$logo_size = ! empty( $instance['logo_size'] ) ? $instance['logo_size'] : ''; |
79
|
|
|
|
80
|
|
|
// Form fields |
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
|
|
|
echo '<p>'; |
87
|
|
|
echo ' <label for="' . $this->get_field_id( 'logo_size' ) . '" class="logo-size-label">' . __( 'Logo Size', 're-pro' ) . '</label>'; |
88
|
|
|
echo ' <select id="' . $this->get_field_id( 'logo_size' ) . '" name="' . $this->get_field_name( 'logo_size' ) . '" class="widefat">'; |
89
|
|
|
echo ' <option value="" ' . selected( $logo_size, '', false ) . '> ' . __( 'Choose', 're-pro' ) . '</option>'; |
90
|
|
|
echo ' <option value="512" ' . selected( $logo_size, '512', false ) . '> ' . __( '512px', 're-pro' ) . '</option>'; |
91
|
|
|
echo ' <option value="256" ' . selected( $logo_size, '256', false ) . '> ' . __( '256px', 're-pro' ) . '</option>'; |
92
|
|
|
echo ' <option value="128" ' . selected( $logo_size, '128', false ) . '> ' . __( '128px', 're-pro' ) . '</option>'; |
93
|
|
|
echo ' <option value="64" ' . selected( $logo_size, '64', false ) . '> ' . __( '64px', 're-pro' ) . '</option>'; |
94
|
|
|
echo ' <option value="32" ' . selected( $logo_size, '32', false ) . '> ' . __( '32px', 're-pro' ) . '</option>'; |
95
|
|
|
echo ' <option value="24" ' . selected( $logo_size, '24', false ) . '> ' . __( '24px', 're-pro' ) . '</option>'; |
96
|
|
|
echo ' <option value="16" ' . selected( $logo_size, '16', false ) . '> ' . __( '16px', 're-pro' ) . '</option>'; |
97
|
|
|
echo ' <option value="14" ' . selected( $logo_size, '14', false ) . '> ' . __( '14px', 're-pro' ) . '</option>'; |
98
|
|
|
echo ' </select>'; |
99
|
|
|
echo ' <span class="description">' . __( 'Choose the size of the logo you want to display.', 're-pro' ) . '</span>'; |
100
|
|
|
echo '</p>'; |
101
|
|
|
|
102
|
|
|
} |
103
|
|
|
|
104
|
|
|
|
105
|
|
|
/** |
106
|
|
|
* Update Widget. |
107
|
|
|
* |
108
|
|
|
* @access public |
109
|
|
|
* @param mixed $new_instance |
110
|
|
|
* @param mixed $old_instance |
111
|
|
|
* @return void |
112
|
|
|
*/ |
113
|
|
|
public function update( $new_instance, $old_instance ) { |
114
|
|
|
|
115
|
|
|
$instance = $old_instance; |
116
|
|
|
|
117
|
|
|
$instance['title'] = ! empty( $new_instance['title'] ) ? strip_tags( $new_instance['title'] ) : ''; |
118
|
|
|
$instance['logo_size'] = ! empty( $new_instance['logo_size'] ) ? strip_tags( $new_instance['logo_size'] ) : ''; |
119
|
|
|
|
120
|
|
|
return $instance; |
121
|
|
|
|
122
|
|
|
} |
123
|
|
|
} |
124
|
|
|
|
125
|
|
|
|
126
|
|
|
/** |
127
|
|
|
* realtor Widget. |
128
|
|
|
* |
129
|
|
|
* @access public |
130
|
|
|
* @return void |
131
|
|
|
*/ |
132
|
|
|
function repro_register_realtorlogo_widget() { |
133
|
|
|
register_widget( 'RealtorLogoWidget' ); |
134
|
|
|
} |
135
|
|
|
add_action( 'widgets_init', 'repro_register_realtorlogo_widget' ); |
136
|
|
|
|
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.