| 1 |
<?php |
| 2 |
|
| 3 |
if ( ! defined( 'ABSPATH' ) ) { |
| 4 |
exit; // Exit if accessed directly |
| 5 |
} |
| 6 |
|
| 7 |
class PH_Elementor { |
| 8 |
|
| 9 |
public function __construct() |
| 10 |
{ |
| 11 |
add_action( 'plugins_loaded', array( $this, 'setup_propertyhive_elementor_functionality' ) ); |
| 12 |
} |
| 13 |
|
| 14 |
public function setup_propertyhive_elementor_functionality() |
| 15 |
{ |
| 16 |
add_filter( 'elementor_pro/utils/get_public_post_types', array( $this, 'register_public_post_type' ) ); |
| 17 |
|
| 18 |
add_action( 'elementor/elements/categories_registered', array( $this, 'add_elementor_widget_category' ) ); |
| 19 |
|
| 20 |
add_action( 'elementor/preview/enqueue_scripts', array( 'PH_Frontend_Scripts', 'load_scripts' ) ); |
| 21 |
add_action( 'elementor/preview/enqueue_scripts', array( $this, 'load_elementor_scripts' ) ); |
| 22 |
|
| 23 |
if ( did_action( 'elementor/loaded' ) ) |
| 24 |
{ |
| 25 |
// Widgets |
| 26 |
add_action( 'init', array( $this, 'register_widgets' ) ); |
| 27 |
} |
| 28 |
} |
| 29 |
|
| 30 |
public function load_elementor_scripts() |
| 31 |
{ |
| 32 |
$suffix = ''; |
| 33 |
$assets_path = str_replace( array( 'http:', 'https:' ), '', PH()->plugin_url() ) . '/assets/'; |
| 34 |
|
| 35 |
wp_enqueue_script( 'propertyhive_fancybox' ); |
| 36 |
wp_enqueue_style( 'propertyhive_fancybox_css' ); |
| 37 |
|
| 38 |
wp_enqueue_script( 'flexslider', $assets_path . 'js/flexslider/jquery.flexslider' . $suffix . '.js', array( 'jquery' ), '2.2.2', true ); |
| 39 |
wp_enqueue_script( 'flexslider-init', $assets_path . 'js/flexslider/jquery.flexslider.init' . $suffix . '.js', array( 'jquery','flexslider' ), PH_VERSION, true ); |
| 40 |
wp_enqueue_style( 'flexslider_css', $assets_path . 'css/flexslider.css' ); |
| 41 |
|
| 42 |
$api_key = get_option('propertyhive_google_maps_api_key'); |
| 43 |
wp_register_script('googlemaps', '//maps.googleapis.com/maps/api/js?' . ( ( $api_key != '' && $api_key !== FALSE ) ? 'key=' . $api_key : '' ), false, '3'); |
| 44 |
wp_enqueue_script('googlemaps'); |
| 45 |
|
| 46 |
wp_enqueue_script( 'propertyhive_elementor', $assets_path . 'js/elementor/elementor.js', array( 'jquery','flexslider' ), PH_VERSION, true ); |
| 47 |
} |
| 48 |
|
| 49 |
public function add_elementor_widget_category( $elements_manager ) |
| 50 |
{ |
| 51 |
$elements_manager->add_category( |
| 52 |
'property-hive', |
| 53 |
[ |
| 54 |
'title' => __( 'Property Hive', 'propertyhive' ), |
| 55 |
'icon' => 'fa fa-home', |
| 56 |
] |
| 57 |
); |
| 58 |
} |
| 59 |
|
| 60 |
public function register_widgets() |
| 61 |
{ |
| 62 |
$widgets = array( |
| 63 |
'Property Price', |
| 64 |
'Property Images', |
| 65 |
'Property Features', |
| 66 |
'Property Summary Description', |
| 67 |
'Property Full Description', |
| 68 |
'Property Actions', |
| 69 |
'Property Meta', |
| 70 |
'Property Availability', |
| 71 |
'Property Type', |
| 72 |
'Property Bedrooms', |
| 73 |
'Property Bathrooms', |
| 74 |
'Property Reception Rooms', |
| 75 |
'Property Map', |
| 76 |
'Property Street View', |
| 77 |
); |
| 78 |
|
| 79 |
$widgets = apply_filters( 'propertyhive_elementor_widgets', $widgets ); |
| 80 |
|
| 81 |
foreach ( $widgets as $widget ) |
| 82 |
{ |
| 83 |
if ( file_exists( dirname(__FILE__) . "/elementor-widgets/" . sanitize_title($widget) . ".php" ) ) |
| 84 |
{ |
| 85 |
require_once( dirname(__FILE__) . "/elementor-widgets/" . sanitize_title($widget) . ".php" ); |
| 86 |
$class_name = '\Elementor_' . str_replace(" ", "_", $widget) . '_Widget'; |
| 87 |
\Elementor\Plugin::instance()->widgets_manager->register_widget_type( new $class_name() ); |
| 88 |
} |
| 89 |
} |
| 90 |
} |
| 91 |
|
| 92 |
public function register_public_post_type( $post_types ) { |
| 93 |
|
| 94 |
if ( isset($post_types['property']) ) |
| 95 |
{ |
| 96 |
return $post_types; |
| 97 |
} |
| 98 |
|
| 99 |
$post_types['property'] = __( 'Property', 'propertyhive' ); |
| 100 |
|
| 101 |
return $post_types; |
| 102 |
} |
| 103 |
|
| 104 |
} |
| 105 |
|
| 106 |
new PH_Elementor(); |