-
Notifications
You must be signed in to change notification settings - Fork 0
/
plugin.php
161 lines (122 loc) · 4.76 KB
/
plugin.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
if ( ! defined( 'ABSPATH' ) ) {
exit( 'Press Enter to proceed...' );
}
class MPHBElementor {
const SLUG = 'mphb-elementor';
const WIDGET_CATEGORY_NAME = 'motopress-hotel-booking';
private static $instance = null;
private function __construct() {
add_action( 'plugins_loaded', array( $this, 'loadTextdomain' ) );
// Check if the MotoPress Hotel Booking is active
if ( ! class_exists( 'HotelBookingPlugin' ) ) {
return;
}
// Check if the Elementor is active
if ( ! did_action( 'elementor/loaded' ) ) {
return;
}
// Check required version
if ( ! version_compare( ELEMENTOR_VERSION, '3.5.0', '>=' ) ) {
return;
}
add_filter( 'elementor/elements/categories_registered', array( $this, 'registerCategories' ), 10, 1 );
add_filter( 'elementor/widgets/register', array( $this, 'registerWidgets' ), 10, 1 );
add_action( 'elementor/init', array( $this, 'addAvailableRoomsData' ) );
add_action( 'elementor/preview/enqueue_styles', array( $this, 'enqueuePreviewStyles' ) );
}
public function loadTextdomain() {
global $wp_version;
$isWp47 = version_compare( $wp_version, '4.7', '>=' );
$locale = $isWp47 ? get_user_locale() : get_locale();
$locale = apply_filters( 'plugin_locale', $locale, self::SLUG );
// wp-content/languages/mphb-elementor/mphb-elementor-{lang}_{locale}.mo
$moFile = sprintf( '%1$s/%2$s/%2$s-%3$s.mo', WP_LANG_DIR, self::SLUG, $locale );
load_textdomain( self::SLUG, $moFile );
load_plugin_textdomain( self::SLUG, false, self::SLUG . '/languages' );
}
/**
* Note that the categories are displayed in the widgets panel, only if they
* have widgets assigned to them.
* @param \Elementor\Elements_Manager
*/
public function registerCategories( $elementsManager ) {
$elementsManager->add_category(
self::WIDGET_CATEGORY_NAME,
array(
'title' => __( 'MotoPress Hotel Booking', 'mphb-elementor' ),
'icon' => 'fa fa-plug',
)
);
}
protected function widgets() {
require __DIR__ . '/widgets/abstract-widget.php';
require __DIR__ . '/widgets/abstract-gallery-widget.php';
require __DIR__ . '/widgets/abstract-calendar-widget.php';
require __DIR__ . '/widgets/search-form-widget.php';
require __DIR__ . '/widgets/search-results-widget.php';
require __DIR__ . '/widgets/rooms-widget.php';
require __DIR__ . '/widgets/room-widget.php';
require __DIR__ . '/widgets/services-widget.php';
require __DIR__ . '/widgets/rates-widget.php';
require __DIR__ . '/widgets/availability-widget.php';
require __DIR__ . '/widgets/booking-confirmation-widget.php';
require __DIR__ . '/widgets/checkout-widget.php';
require __DIR__ . '/widgets/availability-calendar-widget.php';
require __DIR__ . '/widgets/accommodation/abstract-accommodation-widget.php';
require __DIR__ . '/widgets/accommodation/featured-image-widget.php';
require __DIR__ . '/widgets/accommodation/attribute-widget.php';
require __DIR__ . '/widgets/accommodation/attributes-widget.php';
require __DIR__ . '/widgets/accommodation/content-widget.php';
require __DIR__ . '/widgets/accommodation/gallery-widget.php';
require __DIR__ . '/widgets/accommodation/price-widget.php';
require __DIR__ . '/widgets/accommodation/title-widget.php';
return array(
new \mphbe\widgets\SearchFormWidget(),
new \mphbe\widgets\SearchResultsWidget(),
new \mphbe\widgets\RoomsWidget(),
new \mphbe\widgets\RoomWidget(),
new \mphbe\widgets\ServicesWidget(),
new \mphbe\widgets\RatesWidget(),
new \mphbe\widgets\AvailabilityWidget(),
new \mphbe\widgets\BookingConfirmationWidget(),
new \mphbe\widgets\CheckoutWidget(),
new \mphbe\widgets\AvailabilityCalendarWidget(),
new \mphbe\widgets\AccommodationFeaturedImageWidget(),
new \mphbe\widgets\AccommodationAttributeWidget(),
new \mphbe\widgets\AccommodationAttributesWidget(),
new \mphbe\widgets\AccommodationContentWidget(),
new \mphbe\widgets\AccommodationGalleryWidget(),
new \mphbe\widgets\AccommodationPriceWidget(),
new \mphbe\widgets\AccommodationTitleWidget(),
);
}
/**
* @param \Elementor\Widgets_Manager
*/
public function registerWidgets( $widgetsManager ) {
foreach ( $this->widgets() as $widget ) {
$widgetsManager->register( $widget );
}
}
public function enqueuePreviewStyles() {
wp_enqueue_style( 'mphb-flexslider-css' );
}
public function addAvailableRoomsData() {
$readableStatuses = array( 'publish' );
if ( current_user_can( 'read_private_posts' ) ) {
$readableStatuses[] = 'private';
}
$roomTypes = MPHB()->getRoomTypePersistence()->getPosts(
array(
'post_status' => $readableStatuses,
)
);
array_walk( $roomTypes, array( MPHB()->getPublicScriptManager(), 'addRoomTypeData' ) );
}
public static function create() {
if ( is_null( self::$instance ) ) {
self::$instance = new self();
}
}
}