Created
October 8, 2012 16:30
-
-
Save codler/3853432 to your computer and use it in GitHub Desktop.
Startpage Text Widget Wordpress
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
<?php | |
/* | |
Plugin Name: Startpage Text Widget | |
Plugin URI: http://yap.nu/ | |
Description: Custom Description Text on startpage | |
Author: Han Lin Yap | |
Version: 1 (2012-10-08) | |
Author URI: http://yap.nu/ | |
*/ | |
class Startpage_Text_Widget extends WP_Widget { | |
public function __construct() { | |
// widget actual processes | |
parent::__construct( | |
'Startpage_Text_Widget', // Base ID | |
'Startpage_Text_Widget', // Name | |
array( 'description' => 'Startpage text', ) // Args | |
); | |
} | |
public function form( $instance ) { | |
// outputs the options form on admin | |
$description = $instance['description']; | |
?> | |
<p> | |
<label for="<?php echo $this->get_field_id( 'description' ); ?>"><?php _e( 'Description:' ); ?></label> | |
<textarea class="widefat" id="<?php echo $this->get_field_id( 'description' ); ?>" name="<?php echo $this->get_field_name( 'description' ); ?>"><?php echo esc_textarea( $description ); ?></textarea> | |
</p> | |
<?php | |
} | |
public function update( $new_instance, $old_instance ) { | |
// processes widget options to be saved | |
$instance = array(); | |
$instance['description'] = $new_instance['description']; | |
return $instance; | |
} | |
public function widget( $args, $instance ) { | |
// outputs the content of the widget | |
extract( $args ); | |
$description = $instance['description']; | |
echo $before_widget; | |
if ( ! empty( $description ) ) | |
echo $before_title . $description . $after_title; | |
echo $after_widget; | |
} | |
} | |
// register Startpage_Text_Widget widget | |
add_action( 'widgets_init', create_function( '', 'register_widget( "Startpage_Text_Widget" );' ) ); | |
register_sidebar(array( | |
'name' => __( 'Top' ), | |
'id' => 'top', | |
'description' => __( 'Widgets in this area will be shown on top.' ), | |
'before_widget' => '', | |
'after_widget' => '', | |
'before_title' => '', | |
'after_title' => '' | |
)); |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment