1 | <?php |
||
17 | class TruliaRssListingWidget 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 | 'trulia_rss_listing_widget', |
||
30 | __( 'Trulia Listings RSS', 're-pro' ), |
||
31 | array( |
||
32 | 'description' => __( 'Display listings from Trulia via a RSS Feed.', 're-pro' ), |
||
33 | 'classname' => 're-pro re-pro-widget trulia-widget trulia-rss-listings-widget', |
||
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 | |||
53 | echo $args['before_widget']; |
||
54 | |||
55 | echo $args['before_title'] . esc_attr( $title ) . $args['after_title']; |
||
56 | |||
57 | |||
58 | $rss = fetch_feed( get_trulia_rss_listing_feed( 'for_sale', 'Sacramento', 'CA' ) ); |
||
59 | |||
60 | /* Sometimes the feed has errors so we must use SimplePie ForceFeed. */ |
||
61 | add_action('wp_feed_options', 'trulia_force_feed' , 10, 1); |
||
62 | function trulia_force_feed($rss) { |
||
67 | |||
68 | // echo get_trulia_rss_listing_feed( 'for_sale', 'Sacramento', 'CA'); |
||
96 | |||
97 | /** |
||
98 | * Form function. |
||
99 | * |
||
100 | * @access public |
||
101 | * @param mixed $instance Instance. |
||
102 | * @return void |
||
103 | */ |
||
104 | public function form( $instance ) { |
||
105 | |||
106 | // Set default values. |
||
107 | $instance = wp_parse_args( (array) $instance, array( |
||
108 | 'title' => '', |
||
109 | |||
110 | )); |
||
111 | |||
112 | // Retrieve an existing value from the database. |
||
113 | $title = ! empty( $instance['title'] ) ? $instance['title'] : ''; |
||
114 | |||
115 | |||
116 | // Title. |
||
117 | echo '<p>'; |
||
118 | echo ' <label for="' . $this->get_field_id( 'title' ) . '" class="title-label">' . __( 'Tile:', 're-pro' ) . '</label>'; |
||
119 | echo ' <input id="' . $this->get_field_id( 'title' ) . '" name="' . $this->get_field_name( 'title' ) . '" value="' . $title . '" class="widefat">'; |
||
120 | echo '</p>'; |
||
121 | |||
122 | |||
123 | } |
||
124 | |||
125 | /** |
||
126 | * Update. |
||
127 | * |
||
128 | * @access public |
||
129 | * @param mixed $new_instance New Instance. |
||
130 | * @param mixed $old_instance Old Instance. |
||
131 | * @return $instance |
||
132 | */ |
||
133 | public function update( $new_instance, $old_instance ) { |
||
141 | } |
||
142 | |||
154 |
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.