Created
June 1, 2022 12:36
-
-
Save MrVibe/ec3f6f3a4a022d0be4820234bf3016fb to your computer and use it in GitHub Desktop.
create a static widget in boilerplate.
This file contains hidden or 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 | |
add_action( 'widgets_init', 'Sample_Widget' ); | |
function Sample_Widget() { | |
register_widget('Sample_Widget'); | |
} | |
class Sample_Widget extends WP_Widget { | |
/** constructor -- name this the same as the class above */ | |
function __construct() { | |
$widget_ops = array( 'classname' => 'Sample_Widget', 'description' => __('Sample Widget', 'wplms-wim') ); | |
$control_ops = array( 'width' => 300, 'height' => 350, 'id_base' => 'Sample_Widget' ); | |
parent::__construct( 'Sample_Widget', __(' DASHBOARD : Sample Widget'), $widget_ops, $control_ops ); | |
} | |
function widget( $args, $instance ) { | |
extract( $args ); | |
global $wpdb; | |
$init = VibeBP_API_Init::init(); | |
$user_id = 0; | |
if(!empty($init->user)){ | |
$user_id=$init->user->id; | |
} | |
$title = apply_filters('widget_title', $instance['title'] ); | |
$width = $instance['width']; | |
echo '<div class="'.$width.'"> | |
<div class="dash-widget">'.$before_widget; | |
if ( $title ) | |
echo $before_title . $title . $after_title; | |
//DO WIDGET THING | |
echo '</div>'; | |
echo $after_widget.' | |
</div>'; | |
return; | |
} | |
/** @see WP_Widget::update -- do not rename this */ | |
function update($new_instance, $old_instance) { | |
$instance = $old_instance; | |
$instance['title'] = strip_tags($new_instance['title']); | |
$instance['width'] = $new_instance['width']; | |
//more params | |
return $instance; | |
} | |
function form($instance) { | |
$defaults = array( | |
'title' => __('Instructor Membership Stats','wplms-wim'), | |
'width' => 'col-md-6 col-sm-12' | |
//more params | |
); | |
$instance = wp_parse_args( (array) $instance, $defaults ); | |
$title = esc_attr($instance['title']); | |
$width = esc_attr($instance['width']); | |
?> | |
<p> | |
<label for="<?php echo $this->get_field_id('title'); ?>"><?php _e('Title:','wplms-wim'); ?></label> | |
<input class="regular_text" id="<?php echo $this->get_field_id('title'); ?>" name="<?php echo $this->get_field_name('title'); ?>" type="text" value="<?php echo $title; ?>" /> | |
</p> | |
<p> | |
<label for="<?php echo $this->get_field_id('width'); ?>"><?php _e('Select Width','wplms-wim'); ?></label> | |
<select id="<?php echo $this->get_field_id('width'); ?>" name="<?php echo $this->get_field_name('width'); ?>"> | |
<option value="col-md-3 col-sm-6" <?php selected('col-md-3 col-sm-6',$width); ?>><?php _e('One Fourth','wplms-wim'); ?></option> | |
<option value="col-md-4 col-sm-6" <?php selected('col-md-4 col-sm-6',$width); ?>><?php _e('One Third','wplms-wim'); ?></option> | |
<option value="col-md-6 col-sm-12" <?php selected('col-md-6 col-sm-12',$width); ?>><?php _e('One Half','wplms-wim'); ?></option> | |
<option value="col-md-8 col-sm-12" <?php selected('col-md-8 col-sm-12',$width); ?>><?php _e('Two Third','wplms-wim'); ?></option> | |
<option value="col-md-8 col-sm-12" <?php selected('col-md-9 col-sm-12',$width); ?>><?php _e('Three Fourth','wplms-wim'); ?></option> | |
<option value="col-md-12" <?php selected('col-md-12',$width); ?>><?php _e('Full','wplms-wim'); ?></option> | |
</select> | |
</p> | |
<?php | |
//more params | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment