Skip to content

Instantly share code, notes, and snippets.

@kurozumi
Last active February 16, 2016 07:39
Show Gist options
  • Save kurozumi/4a02bb6931c6bb01b564 to your computer and use it in GitHub Desktop.
Save kurozumi/4a02bb6931c6bb01b564 to your computer and use it in GitHub Desktop.
【ワードプレス】ウィジット作成のテンプレート
<?php
add_action('widgets_init', function () {
register_widget("My_Widget");
class My_Widget extends WP_Widget
{
/**
* PHP5 constructor.
*
* @since 2.8.0
* @access public
*
* @param string $id_base Optional Base ID for the widget, lowercase and unique. If left empty,
* a portion of the widget's class name will be used Has to be unique.
* @param string $name Name for the widget displayed on the configuration page.
* @param array $widget_options Optional. Widget options. See {@see wp_register_sidebar_widget()} for
* information on accepted arguments. Default empty array.
* @param array $control_options Optional. Widget control options. See {@see wp_register_widget_control()}
* for information on accepted arguments. Default empty array.
*/
public function __construct()
{
parent::__construct(
'id_base',
'name',
array('widget_options'),
array('control_options')
);
}
/**
* Echo the widget content.
*
* Subclasses should over-ride this function to generate their widget code.
*
* @since 2.8.0
* @access public
*
* @param array $args Display arguments including before_title, after_title,
* before_widget, and after_widget.
* @param array $instance The settings for the particular instance of the widget.
*/
public function widget($args, $instance) {
// $instance['title];
}
/**
* Update a particular instance.
*
* This function should check that $new_instance is set correctly. The newly-calculated
* value of `$instance` should be returned. If false is returned, the instance won't be
* saved/updated.
*
* @since 2.8.0
* @access public
*
* @param array $new_instance New settings for this instance as input by the user via
* {@see WP_Widget::form()}.
* @param array $old_instance Old settings for this instance.
* @return array Settings to save or bool false to cancel saving.
*/
public function update($new_instance, $old_instance){}
/**
* Output the settings update form.
*
* @since 2.8.0
* @access public
*
* @param array $instance Current settings.
* @return string Default return is 'noform'.
*/
public function form($instance){
// $this->get_field_name('title');
}
}
});
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment