-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathlittle-hotelier-booking-widget.php
161 lines (141 loc) · 4.8 KB
/
little-hotelier-booking-widget.php
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
<?php
/**
* Plugin Name: LH Booking Widget
* Version: 1.2.1
* Plugin URI: https://carl.alber2.com/
* Description: This is a Booking Widget used for Little Hotelier. Please get your channel code from the official site: http://www.littlehotelier.com/
* Author: Carl Alberto
* Author URI: https://carl.alber2.com/
* Requires at least: 4.0
* Tested up to: 6.0.3
*
* Text Domain: little-hotelier-booking-widget
* Domain Path: /lang/
*
* @package WordPress
* @author Carl Alberto
* @since 1.0.0
*/
if ( ! defined( 'ABSPATH' ) ) {
exit;
}
add_action( 'widgets_init', 'lhw_register_widget' );
/**
* Function that registers the LH Booking Widget.
*
* @version 1.0.0
* @since 1.0.0
* @package LH Booking Widget
* @author Carl Alberto
*/
function lhw_register_widget() {
register_widget( 'lhw_widget' );
}
/**
* Main LH Booking Widget Class.
*
* @class HelpHub_Post_Types
* @version 1.0.0
* @since 1.0.0
* @package LH_Booking_Widget
* @author Carl Alberto
*/
class Lhw_Widget extends WP_Widget {
/**
* Constructor
*
* @version 1.0.0
* @since 1.0.0
* @package LH Booking Widget
* @author Carl Alberto
*/
public function __construct() {
parent::__construct(
'lhw_widget',
__( 'Little Hotelier Booking Widget', 'little-hotelier-booking-widget' ),
array(
'classname' => 'lhw_widget widget_recent_entries',
'description' => __( 'This will list post by ', 'little-hotelier-booking-widget' ),
)
);
}
/**
* Widget Constructor
*
* @version 1.0.0
* @since 1.0.0
* @param array $instance form instance.
* @package LH Booking Widget
* @author Carl Alberto
*/
public function form( $instance ) {
$defaults = array(
'title' => '',
'mychannelcode' => '',
'height' => 5,
'width' => '',
'frameborder' => '',
'scrolling' => 'no',
'allowtransparency' => 'true',
);
$instance = wp_parse_args( (array) $instance, $defaults );
$title = $instance['title'];
$mychannelcode = $instance['mychannelcode'];
$gridmode = $instance['gridmode'];
$number = $instance['number'];
$height = $instance['height'];
$width = $instance['width'];
$frameborder = $instance['frameborder'];
$scrolling = $instance['scrolling'];
$allowtransparency = $instance['allowtransparency'];
?>
<p>
<label for="lhw_widget_title"><?php esc_html_e( 'Title' ); ?>:</label>
<input type="text" class="widefat" id="lhw_widget_title" name="<?php echo esc_html_e( 'widget-lhw_widget[2][title]' ) ?>" value="<?php echo esc_attr( $title ); ?>" />
</p>
<p>
<input type="radio" name="<?php echo esc_html_e( 'widget-lhw_widget[2][gridmode]' ) ?>" value="simple" <?php echo ( 'simple' === $gridmode ) ? 'checked' : '' ?> > Simple
<input type="radio" name="<?php echo esc_html_e( 'widget-lhw_widget[2][gridmode]' ) ?>" value="availabilitygrid" <?php echo ( 'availabilitygrid' === $gridmode ) ? 'checked' : '' ?> > Availability Grid<br>
</p>
<p>
<label for="lhw_widget_title"><?php echo esc_html_e( 'MYCHANNELCODE' ); ?>:</label>
<input type="text" class="lhw_channel" id="lhw_widget_mychannelcode" name="<?php echo esc_html_e( 'widget-lhw_widget[2][mychannelcode]' ) ?>" value="<?php echo esc_attr( $mychannelcode ); ?>" />
</p>
<?php
}
/**
* Outputs the widget in the frontend.
*
* @version 1.0.0
* @since 1.0.0
* @param array $args args for the instance.
* @param array $instance form instance.
*/
public function widget( $args, $instance ) {
$title = apply_filters( 'widget_title', $instance['title'], $instance, $this->id_base );
$mychannelcode = apply_filters( 'widget_title', $instance['mychannelcode'], $instance, $this->id_base );
$gridmode = apply_filters( 'widget_title', $instance['gridmode'], $instance, $this->id_base );
if ( 'simple' === $gridmode ) {
echo '<iframe src="https://app.littlehotelier.com/properties/' . esc_html( $mychannelcode ) . '/booking_widget" height="200" width="210" frameborder="0" scrolling="no" allowtransparency="true"></iframe>';
} else {
echo '<iframe src="https://app.littlehotelier.com/properties/' . esc_html( $mychannelcode ) . '/widget?number_of_days=14" height="300" width="720" frameborder="0" scrolling="no" allowtransparency="true"></iframe>';
}
}
/**
* Widget update function.
*
* @version 1.0.0
* @since 1.0.0
* @param array $new_instance array of the new values for update usage.
* @param array $old_instance array of the old values.
* @return array of the updated widget values.
*/
public function update( $new_instance, $old_instance ) {
$instance = $old_instance;
$instance['title'] = wp_strip_all_tags( $new_instance['title'] );
$instance['mychannelcode'] = wp_strip_all_tags( $new_instance['mychannelcode'] );
$instance['gridmode'] = wp_strip_all_tags( $new_instance['gridmode'] );
return $instance;
}
}
?>