PluginProbe
Easy Hotel – Powerful Hotel Booking / trunk
Easy Hotel – Powerful Hotel Booking vtrunk
2.0.8 2.0.7 2.0.6 2.0.5 2.0.4 2.0.3 2.0.2 2.0.1 2.0.0 1.9.9 1.9.8 1.9.7 1.9.6 1.9.5 1.9.4 1.9.3 1.9.2 1.8.1 1.8.2 1.8.3 1.8.4 1.8.5 1.8.6 1.8.7 1.8.8 All 110 releases
easy-hotel / class.easy-hotel.php

class.easy-hotel.php in Easy Hotel – Powerful Hotel Booking trunk, at class.easy-hotel.php

202 lines 6.5 KB
No matching file
Up and down to move Enter to open Esc to close
Raw Download Zip
1 <?php
2 if ( ! defined( 'ABSPATH' ) ) exit; // Exit if accessed directly.
3 class ESHB_MAIN {
4
5 private static $_instance = null;
6
7 public static function instance() {
8
9 if ( is_null( self::$_instance ) ) {
10 self::$_instance = new self();
11 }
12 return self::$_instance;
13
14 }
15
16 /**
17 * Constructor
18 *
19 * @since 1.0.0
20 *
21 * @access public
22 */
23 public function __construct() {
24 add_action( 'init', [ $this, 'includes' ], 11 );
25 $this->init();
26 add_action( 'init', [$this, 'enable_elementor_for_custom_post_type'] );
27 add_filter( 'admin_body_class', [$this, 'add_admin_body_class'] );
28 add_action( 'phpmailer_init', [$this, 'enable_local_mail'] );
29 add_action( 'pre_get_posts', [$this, 'eshb_archive_posts_query_modify'] );
30 }
31
32
33
34 /**
35 * Initialize the plugin
36 *
37 * Load the plugin only after Elementor (and other plugins) are loaded.
38 * Checks for basic plugin requirements, if one check fail don't continue,
39 * if all check have passed load the files required to run the plugin.
40 *
41 * Fired by `plugins_loaded` action hook.
42 *
43 * @since 1.0.0
44 *
45 * @access public
46 */
47 public function includes(){
48 include 'class.session-manager.php';
49 include 'public/includes/plugin-scripts.php';
50 include 'public/includes/classes/class.view.php';
51 include 'public/includes/dynamic-css.php';
52 include 'admin/includes/woocommerce-filters.php';
53 }
54
55 public function init() {
56 // Add Plugin actions
57 add_filter( 'plugin_action_links_' . ESHB_PLUGIN_BASE, [ $this, 'easy_hotel_plugin_action_links' ], 10, 4 );
58 add_filter( 'plugin_row_meta', [ $this, 'easy_hotel_plugin_row_meta' ], 10, 2 );
59 add_action( 'init', [$this, 'eshb_add_image_sizes'] );
60 add_filter( 'image_size_names_choose', [$this, 'eshb_add_image_size_to_media_library'] );
61 }
62
63 /**
64 * External links used on the plugins list table row.
65 *
66 * @return array
67 */
68 public function eshb_plugin_links() {
69 return array(
70 'settings' => admin_url( 'edit.php?post_type=eshb_accomodation&page=easy-hotel-settings' ),
71 'support' => 'https://wordpress.org/support/plugin/easy-hotel/',
72 );
73 }
74
75 /**
76 * Action links shown under the plugin name: Settings | Deactivate.
77 *
78 * @param array $plugin_actions Existing action links.
79 * @param string $plugin_file Plugin file path.
80 * @param array $plugin_data Plugin header data.
81 * @param string $context Current plugins list context.
82 *
83 * @return array
84 */
85 public function easy_hotel_plugin_action_links( $plugin_actions, $plugin_file, $plugin_data, $context ) {
86 $links = $this->eshb_plugin_links();
87
88 $before = array(
89 'easy_hotel_plugin_actions_setting' => sprintf(
90 '<a href="%s">%s</a>',
91 esc_url( $links['settings'] ),
92 esc_html__( 'Settings', 'easy-hotel' )
93 ),
94 );
95
96 return array_merge( $before, $plugin_actions );
97 }
98
99 /**
100 * Extra meta links shown next to the plugin description: Community support.
101 *
102 * @param array $plugin_meta Existing meta links.
103 * @param string $plugin_file Plugin file path.
104 *
105 * @return array
106 */
107 public function easy_hotel_plugin_row_meta( $plugin_meta, $plugin_file ) {
108 if ( ESHB_PLUGIN_BASE !== $plugin_file ) {
109 return $plugin_meta;
110 }
111
112 $links = $this->eshb_plugin_links();
113
114 $plugin_meta[] = sprintf(
115 '<a href="%s" target="_blank" rel="noopener noreferrer">%s</a>',
116 esc_url( $links['support'] ),
117 esc_html__( 'Community support', 'easy-hotel' )
118 );
119
120 return $plugin_meta;
121 }
122
123 public function eshb_add_image_sizes() {
124 // Register a new image size
125 add_image_size( 'eshb_thumbnail', 533, 533, true );
126 }
127 public function eshb_add_image_size_to_media_library( $sizes ) {
128 return array_merge( $sizes, array(
129 'eshb_thumbnail' => 'Easy Hotel Thumbnail',
130 ) );
131 }
132
133 public function custom_oembed_autoplay($html, $url, $args) {
134 if (strpos($url, 'youtube.com') !== false || strpos($url, 'youtu.be') !== false) {
135 $html = str_replace('?feature=oembed', '?feature=oembed&autoplay=1&mute=1', $html);
136 } elseif (strpos($url, 'vimeo.com') !== false) {
137 $html = str_replace('"', '?autoplay=1&muted=1"', $html);
138 }
139 return $html;
140 }
141
142 public function enable_elementor_for_custom_post_type (){
143 add_post_type_support( 'eshb_accomodation', 'elementor' );
144 }
145
146 public function add_admin_body_class ($classes) {
147 $plugin_screens = [
148 'edit-eshb_booking',
149 'eshb_booking',
150 'edit-eshb_accomodation',
151 'eshb_accomodation',
152 'edit-eshb_payment',
153 'eshb_payment',
154 'edit-eshb_service',
155 'eshb_service',
156 'edit-eshb_session',
157 'eshb_session',
158 'edit-eshb_coupon',
159 'eshb_coupon',
160 'admin_page_view_booking_data',
161 'edit-eshb_email_template',
162 ];
163 $screen = get_current_screen();
164 if ( isset($screen->id) && in_array($screen->id, $plugin_screens) ) {
165 $classes .= ' eshb-plugin-page ';
166 }
167 return $classes;
168 }
169
170 public function enable_local_mail($phpmailer){
171 // Check if running on localhost
172 if (
173 !empty($_SERVER['HTTP_HOST']) &&
174 strpos(sanitize_text_field( wp_unslash($_SERVER['HTTP_HOST'] ) ), 'localhost') !== false ||
175 strpos(sanitize_text_field( wp_unslash($_SERVER['HTTP_HOST'] ) ), '127.0.0.1') !== false
176 ) {
177 $phpmailer->isSMTP();
178 $phpmailer->Host = 'localhost';
179 $phpmailer->Port = 1025;
180 }
181 }
182
183 public function eshb_archive_posts_query_modify($query){
184 if(!is_admin() && $query->is_main_query() && $query->is_post_type_archive('eshb_accomodation')){
185 $eshb_settings = get_option( 'eshb_settings' );
186 $posts_per_page = isset($eshb_settings['accomodation_posts_per_page']) && !empty($eshb_settings['accomodation_posts_per_page']) ? $eshb_settings['accomodation_posts_per_page'] : 6;
187 $posts_order_by = isset($eshb_settings['accomodation_posts_order_by']) && !empty($eshb_settings['accomodation_posts_order_by']) ? $eshb_settings['accomodation_posts_order_by'] : 'id';
188 $posts_order = isset($eshb_settings['accomodation_posts_order']) && !empty($eshb_settings['accomodation_posts_order']) ? $eshb_settings['accomodation_posts_order'] : 'DESC';
189 $query->set( 'post_type', 'eshb_accomodation' );
190 $query->set( 'posts_per_page', $posts_per_page );
191 $query->set( 'orderby', $posts_order_by );
192 $query->set( 'order', $posts_order );
193 }
194 }
195 }
196
197 add_action( 'init', 'eshb_add_image_sizes' );
198 function eshb_add_image_sizes() {
199 // Register a new image size
200 add_image_size( 'eshb_thumbnail', 533, 533, true );
201 }
202