Skip to content

Instantly share code, notes, and snippets.

@matherton
Created June 28, 2013 09:09
Show Gist options
  • Save matherton/5883487 to your computer and use it in GitHub Desktop.
Save matherton/5883487 to your computer and use it in GitHub Desktop.
Worpress OO Plugin template
// http://wp.tutsplus.com/tutorials/plugins/two-ways-to-develop-wordpress-plugins-object-oriented-progamming/
class My_Widget extends WP_Widget {
public function __construct() {
// widget actual processes
}
public function form( $instance ) {
// outputs the options form on admin
}
public function update( $new_instance, $old_instance ) {
// processes widget options to be saved
}
public function widget( $args, $instance ) {
// outputs the content of the widget
}
}
class DemoPlugin {
public function __construct() {
load_plugin_textdomain( 'demo-plugin', false, dirname( plugin_basename( __FILE__ ) ) . '/lang' );
//register hooks using an array with two indexes: the first being $this and the second being the name of the function.
add_action( 'wp_enqueue_scripts', array( $this, 'register_plugin_styles' ) );
add_action( 'wp_enqueue_scripts', array( $this, 'register_plugin_scripts' ) );
add_filter( 'the_content', array( $this, 'append_post_notification' ) );
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment