PluginProbe
Easy Hotel – Powerful Hotel Booking / 2.0.2
Easy Hotel – Powerful Hotel Booking v2.0.2
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 2.0.2, at class.easy-hotel.php

148 lines 5.0 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 add_action( 'plugins_loaded', [ $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_action( 'init', [$this, 'eshb_add_image_sizes'] );
59 add_filter( 'image_size_names_choose', [$this, 'eshb_add_image_size_to_media_library'] );
60 }
61
62
63 public function easy_hotel_plugin_action_links( $plugin_actions, $plugin_file, $plugin_data, $context ) {
64 $new_actions = array();
65 $new_actions['easy_hotel_plugin_actions_setting'] = '<a href="'.admin_url( 'edit.php?post_type=eshb_accomodation&page=easy-hotel-settings' ).'">Settings</a>';
66 return array_merge( $new_actions, $plugin_actions );
67 }
68
69 public function eshb_add_image_sizes() {
70 // Register a new image size
71 add_image_size( 'eshb_thumbnail', 533, 533, true );
72 }
73 public function eshb_add_image_size_to_media_library( $sizes ) {
74 return array_merge( $sizes, array(
75 'eshb_thumbnail' => 'Easy Hotel Thumbnail',
76 ) );
77 }
78
79 public function custom_oembed_autoplay($html, $url, $args) {
80 if (strpos($url, 'youtube.com') !== false || strpos($url, 'youtu.be') !== false) {
81 $html = str_replace('?feature=oembed', '?feature=oembed&autoplay=1&mute=1', $html);
82 } elseif (strpos($url, 'vimeo.com') !== false) {
83 $html = str_replace('"', '?autoplay=1&muted=1"', $html);
84 }
85 return $html;
86 }
87
88 public function enable_elementor_for_custom_post_type (){
89 add_post_type_support( 'eshb_accomodation', 'elementor' );
90 }
91
92 public function add_admin_body_class ($classes) {
93 $plugin_screens = [
94 'edit-eshb_booking',
95 'eshb_booking',
96 'edit-eshb_accomodation',
97 'eshb_accomodation',
98 'edit-eshb_payment',
99 'eshb_payment',
100 'edit-eshb_service',
101 'eshb_service',
102 'edit-eshb_session',
103 'eshb_session',
104 'edit-eshb_coupon',
105 'eshb_coupon',
106 'admin_page_view_booking_data',
107 'edit-eshb_email_template',
108 ];
109 $screen = get_current_screen();
110 if ( isset($screen->id) && in_array($screen->id, $plugin_screens) ) {
111 $classes .= ' eshb-plugin-page ';
112 }
113 return $classes;
114 }
115
116 public function enable_local_mail($phpmailer){
117 // Check if running on localhost
118 if (
119 !empty($_SERVER['HTTP_HOST']) &&
120 strpos(sanitize_text_field( wp_unslash($_SERVER['HTTP_HOST'] ) ), 'localhost') !== false ||
121 strpos(sanitize_text_field( wp_unslash($_SERVER['HTTP_HOST'] ) ), '127.0.0.1') !== false
122 ) {
123 $phpmailer->isSMTP();
124 $phpmailer->Host = 'localhost';
125 $phpmailer->Port = 1025;
126 }
127 }
128
129 public function eshb_archive_posts_query_modify($query){
130 if(!is_admin() && $query->is_main_query() && $query->is_post_type_archive('eshb_accomodation')){
131 $eshb_settings = get_option( 'eshb_settings' );
132 $posts_per_page = isset($eshb_settings['accomodation_posts_per_page']) && !empty($eshb_settings['accomodation_posts_per_page']) ? $eshb_settings['accomodation_posts_per_page'] : 6;
133 $posts_order_by = isset($eshb_settings['accomodation_posts_order_by']) && !empty($eshb_settings['accomodation_posts_order_by']) ? $eshb_settings['accomodation_posts_order_by'] : 'id';
134 $posts_order = isset($eshb_settings['accomodation_posts_order']) && !empty($eshb_settings['accomodation_posts_order']) ? $eshb_settings['accomodation_posts_order'] : 'DESC';
135 $query->set( 'post_type', 'eshb_accomodation' );
136 $query->set( 'posts_per_page', $posts_per_page );
137 $query->set( 'orderby', $posts_order_by );
138 $query->set( 'order', $posts_order );
139 }
140 }
141 }
142
143 add_action( 'init', 'eshb_add_image_sizes' );
144 function eshb_add_image_sizes() {
145 // Register a new image size
146 add_image_size( 'eshb_thumbnail', 533, 533, true );
147 }
148