Modèle de widget WordPress simple

logo carre@4x

Simple widget qui accepte les options « titre » et « message ».

<?php 
/**
 * Exemple de classe de widget
 */ 
la classe example_widget étend WP_Widget {
 
 
    /** constructeur -- nommez-le de la même manière que la classe ci-dessus */ 
    function example_widget ( )  { 
        parent :: WP_Widget ( false ,  $name  =  'Example Text Widget' ) ; 	
    }
 
    /** @see WP_Widget::widget -- ne renommez pas ce */ 
    function widget ( $args ,  $instance )  { 	
        extract (  $args  ) ; 
        $title  		= apply_filters ( 'widget_title' ,  $instance [ 'title' ] ) ; 
        $message  	=  $instance [ 'message' ] ; 
        ?> 
              <?php  echo  $before_widget ;  ?> 
                  <?php  if  (  $title  ) 
                        echo  $before_title  .  $titre  .  $après_titre ;  ?>
							<ul>
								<li> <?php  echo  $message ;  ?> </li>
							</ul>
              <?php  echo  $after_widget ;  ?> 
        <?php 
    }
 
    /** @see WP_Widget::update -- ne renommez pas cette 
    fonction */ update ( $new_instance ,  $old_instance )  { 		
		$instance  =  $old_instance ; 
		$instance [ 'titre' ]  =  strip_tags ( $new_instance [ 'titre' ] ) ; 
		$instance [ 'message' ]  =  strip_tags ( $new_instance [ 'message' ] ) ; 
        retourner  $instance ; 
    }
 
    /** @see WP_Widget::form -- ne renommez pas ce */ 
    function form ( $instance )  {	
 
        $titre  		= esc_attr ( $instance [ 'titre' ] ) ; 
        $message 	= esc_attr ( $instance [ 'message' ] ) ; 
        ?>
         <p>
          <label for=" <?php  echo  $this -> get_field_id ( 'titre' ) ;  ?> "> <?php _e ( 'Titre :' ) ;  ?> </étiquette>
          <input class="widefat" id=" <?php  echo  $this -> get_field_id ( 'titre' ) ;  ?> " name=" <?php  echo  $this -> get_field_name ( 'titre' ) ;  ?> " type ="text" value=" <?php  echo  $title ;  ?> " />
        </p>
		<p>
          <label for=" <?php  echo  $this -> get_field_id ( 'message' ) ;  ?> "> <?php _e ( 'Simple Message' ) ;  ?> </étiquette>
          <input class="widefat" id=" <?php  echo  $this -> get_field_id ( 'message' ) ;  ?> " name=" <?php  echo  $this -> get_field_name ( 'message' ) ;  ?> " type ="text" value=" <?php  echo  $message ;  ?> " />
        </p>
        <?php  
    }
 
 
}  // fin de la classe example_widget 
add_action ( 'widgets_init' ,  create_function ( '' ,  'return register_widget("example_widget");' ) ) ; 
?>