| 1 |
<?php |
| 2 |
/** |
| 3 |
* Adds Borderless_Widget_Spacer widget. |
| 4 |
*/ |
| 5 |
class Borderless_Widget_Spacer extends WP_Widget { |
| 6 |
|
| 7 |
/** |
| 8 |
* Register widget with WordPress. |
| 9 |
*/ |
| 10 |
function __construct() { |
| 11 |
parent::__construct( |
| 12 |
'borderless_spacer', // Base ID |
| 13 |
__( 'Borderless - Spacer', 'borderless' ), // Name |
| 14 |
array( 'description' => __( 'Blank space with custom height.', 'borderless' ), ) // Args |
| 15 |
); |
| 16 |
} |
| 17 |
|
| 18 |
/** |
| 19 |
* Front-end display of widget. |
| 20 |
* |
| 21 |
* @see WP_Widget::widget() |
| 22 |
* |
| 23 |
* @param array $args Widget arguments. |
| 24 |
* @param array $instance Saved values from database. |
| 25 |
*/ |
| 26 |
public function widget( $args, $instance ) { |
| 27 |
extract( $args ); |
| 28 |
$space = apply_filters('widget_space', $instance['space']); |
| 29 |
|
| 30 |
echo $before_widget; |
| 31 |
|
| 32 |
if ( ! empty( $space ) ) { ?> |
| 33 |
|
| 34 |
<div class="borderless-widget borderless-widget--spacer" style="height:<?php echo $instance['space'] ?>;"></div> |
| 35 |
|
| 36 |
<?php } ?> |
| 37 |
<?php echo $after_widget; |
| 38 |
} |
| 39 |
|
| 40 |
|
| 41 |
/** |
| 42 |
* Back-end widget form. |
| 43 |
* |
| 44 |
* @see WP_Widget::form() |
| 45 |
* |
| 46 |
* @param array $instance Previously saved values from database. |
| 47 |
*/ |
| 48 |
public function form( $instance ) { |
| 49 |
$space = ! empty( $instance['space'] ) ? $instance['space'] : ''; |
| 50 |
?> |
| 51 |
<p> |
| 52 |
<label for="<?php echo $this->get_field_id( 'space' ); ?>"><?php _e( 'Space - CSS measurement units allowed', 'borderless' ); ?></label> |
| 53 |
<input class="widefat" id="<?php echo $this->get_field_id( 'space' ); ?>" name="<?php echo $this->get_field_name( 'space' ); ?>" type="text" value="<?php echo esc_attr( $space ); ?>" /> |
| 54 |
</p> |
| 55 |
<?php } |
| 56 |
|
| 57 |
|
| 58 |
/** |
| 59 |
* Sanitize widget form values as they are saved. |
| 60 |
* |
| 61 |
* @see WP_Widget::update() |
| 62 |
* |
| 63 |
* @param array $new_instance Values just sent to be saved. |
| 64 |
* @param array $old_instance Previously saved values from database. |
| 65 |
* |
| 66 |
* @return array Updated safe values to be saved. |
| 67 |
*/ |
| 68 |
public function update( $new_instance, $old_instance ) { |
| 69 |
$instance = array(); |
| 70 |
$instance['space'] = sanitize_text_field( strip_tags( $new_instance['space'] ) ); |
| 71 |
|
| 72 |
return $instance; |
| 73 |
} |
| 74 |
|
| 75 |
} // class Borderless_Widget_Spacer ends |
| 76 |
|
| 77 |
|
| 78 |
|
| 79 |
// register Borderless_Widget_Spacer widget |
| 80 |
function register_borderless_spacer() { |
| 81 |
register_widget( 'Borderless_Widget_Spacer' ); |
| 82 |
} |
| 83 |
|
| 84 |
add_action( 'widgets_init', 'register_borderless_spacer' ); |