trey (owner)

Revisions

gist: 178309 Download_button fork
public
Description:
WordPress widget TextMate snippet: http://markjaquith.wordpress.com/2009/08/31/textmate-wordpress-widget-snippet/
Public Clone URL: git://gist.github.com/178309.git
Embed All Files: show embed
PHP #
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
class ${1:PREFIX_Name}_Widget extends WP_Widget {
function $1_Widget() {
\$widget_ops = array( 'classname' => '${2:CSS class name}', 'description' => '${3:Description}' );
\$this->WP_Widget( '$2', '${4:Title}', \$widget_ops );
}
function widget( \$args, \$instance ) {
extract( \$args, EXTR_SKIP );
echo \$before_widget;
echo \$before_title;
echo '$4'; // Can set this with a widget option, or omit altogether
echo \$after_title;
//
// Widget display logic goes here
//
echo \$after_widget;
}
function update( \$new_instance, \$old_instance ) {
// update logic goes here
\$updated_instance = \$new_instance;
return \$updated_instance;
}
function form( \$instance ) {
\$instance = wp_parse_args( (array) \$instance, array( ${5:array of option_name => value pairs} ) );
// display field names here using:
// \$this->get_field_id('option_name') - the CSS ID
// \$this->get_field_name('option_name') - the HTML name
// \$instance['option_name'] - the option value
}
}
add_action( 'widgets_init', create_function( '', "register_widget('$1_Widget');" ) );