Skip to content

Instantly share code, notes, and snippets.

@igmoweb
Created October 6, 2014 14:56
Show Gist options
  • Save igmoweb/0c0352adc47a85331362 to your computer and use it in GitHub Desktop.
Save igmoweb/0c0352adc47a85331362 to your computer and use it in GitHub Desktop.
<?php
class Fictizia_Widget extends WP_Widget {
// El nombre de la clase tiene que coincidir con esta función
function Fictizia_Widget() {
// Argumentos
$args = array( 'classname' => 'fictizia-widget', 'description' => __( 'Fictizia Widget Description', 'fictizia' ) );
// La clase superior es la que se encarga de crear realmente el widget
parent::WP_Widget( false, __( 'Fictizia Widget', 'fictizia' ), $args );
}
function form( $instance ) {
$defaults = array(
'title' => 'Fictizia Widget'
);
$instance = wp_parse_args( $instance, $defaults );
?>
<p>
<label for="<?php echo $this->get_field_id('title'); ?>"><?php _e('Title:'); ?>
<input class="widefat" id="<?php echo $this->get_field_id('title'); ?>" name="<?php echo $this->get_field_name('title'); ?>" type="text" value="<?php echo esc_attr( $instance['title'] ); ?>" />
</label>
</p>
<?php
}
function update( $new_instance, $old_instance ) {
$instance = $old_instance;
$title = sanitize_text_field( $new_instance['title'] );
if ( ! empty( $title ) )
$instance['title'] = $title;
return $instance;
}
function widget( $args, $instance ) {
extract( $args );
$title = apply_filters( 'widget_title', $instance['title'] );
?>
<?php echo $before_widget; ?>
<?php if ( $title )
echo $before_title . $title . $after_title; ?>
Hola, mundo
<?php echo $after_widget; ?>
<?php
}
}
add_action( 'widgets_init', 'fictizia_register_widget' );
function fictizia_register_widget() {
register_widget( 'Fictizia_Widget' );
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment