Skip to content

Instantly share code, notes, and snippets.

@wichaksono
Created January 27, 2018 05:05
Show Gist options
  • Save wichaksono/0a29bd8bb7cbf2ace7bad5a792981a47 to your computer and use it in GitHub Desktop.
Save wichaksono/0a29bd8bb7cbf2ace7bad5a792981a47 to your computer and use it in GitHub Desktop.
<?php
class My_Widget extends WP_Widget {
/**
* Mengatur Nama Widget
*/
public function __construct() {
$widget_ops = array(
'classname' => 'my_widget', // class pada html
'description' => 'My Widget is awesome', // deskripsi tentang widget
);
/**
* parent::__construct($id_widget, $namaWidget, $options);
*/
parent::__construct( 'my_widget', 'My Widget', $widget_ops );
}
/**
* yang akan ditampilkan di website
*/
public function widget( $args, $instance ) {
// code html
}
/**
* akan ditampilkan di halaman admin
*/
public function form( $instance ) {
// code html
}
/**
* perintah simpan dan update
*/
public function update( $new_instance, $old_instance ) {
// code saving
}
}
// implementasi widget
add_action( 'widgets_init', function(){
register_widget( 'My_Widget' );
});
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment