LLMS_Widget_Course_Progress
Source Source
File: includes/widgets/class.llms.widget.course.progress.php
class LLMS_Widget_Course_Progress extends LLMS_Widget {
/**
* Register widget with WordPress.
*
* @since 1.0.0
*
* @return void
*/
public function __construct() {
WP_Widget::__construct(
'course_progress',
__( 'Course Progress', 'lifterlms' ),
array(
'description' => __( 'Displays Course Progress on Course or Lesson', 'lifterlms' ),
)
);
}
/**
* Back-end widget form.
*
* @since 3.38.0
*
* @see WP_Widget::form()
*
* @param array $instance Previously saved values from database.
*/
public function form( $instance ) {
// Call widget defaults from parent.
parent::form( $instance );
$check_enrollment = ( isset( $instance['check_enrollment'] ) ) ? $instance['check_enrollment'] : 1;
?>
<p>
<input <?php checked( 1, $check_enrollment ); ?> class="checkbox llms-course-progress-check-enrollment" id="<?php echo $this->get_field_id( 'check_enrollment' ); ?>" name="<?php echo $this->get_field_name( 'check_enrollment' ); ?>" type="checkbox" value="1">
<label for="<?php echo $this->get_field_id( 'check_enrollment' ); ?>">
<?php _e( 'Display to enrolled students only?', 'lifterlms' ); ?><br>
<em><?php _e( 'When checked the course progress bar will be shown only to those students enrolled in the course.', 'lifterlms' ); ?></em>
</label>
</p>
<?php
}
/**
* Front-end display of widget
*
* @since 3.38.0
*
* @see WP_Widget::widget()
*
* @param array $args Widget arguments.
* @param array $instance Saved values from database.
* @return void
*/
public function widget( $args, $instance ) {
$check_enrollment = ( ! isset( $instance['check_enrollment'] ) ) ? 1 : $instance['check_enrollment'];
$course_progress = do_shortcode( '[lifterlms_course_progress check_enrollment=' . $check_enrollment . ']' );
// Do not show the widget title if no progress bar is displayed.
if ( empty( $course_progress ) ) {
return;
}
echo $args['before_widget'];
if ( ! empty( $instance['title'] ) ) {
echo $args['before_title'] . apply_filters( 'widget_title', $instance['title'] ) . $args['after_title'];
}
echo $course_progress;
echo $args['after_widget'];
}
/**
* Sanitize widget form values as they are saved.
*
* @since 3.38.0
*
* @see WP_Widget::update()
*
* @param array $new_instance Values just sent to be saved.
* @param array $old_instance Previously saved values from database.
* @return array Updated safe values to be saved.
*/
public function update( $new_instance, $old_instance ) {
$instance = parent::update( $new_instance, $old_instance );
$instance['check_enrollment'] = ( ! empty( $new_instance['check_enrollment'] ) ) ? 1 : 0;
return $instance;
}
}
Expand full source code Collapse full source code View on GitHub
Methods Methods
- __construct — Register widget with WordPress.
- form — Back-end widget form.
- update — Sanitize widget form values as they are saved.
- widget — Front-end display of widget
- widget_contents — Widget Content — deprecated
Changelog Changelog
| Version | Description |
|---|---|
| 4.0.0 | Remove previously deprecated method LLMS_Widget_Course_Progress::widget_contents(). |
| 3.38.0 | Introduced a new option to display/hide the course progress widget to enrolled students only. Hidden to not enrolled students by default. |
| 1.0.0 | Introduced. |