activities_helper.php
3 months ago
agent_helper.php
3 months ago
analytics_helper.php
4 months ago
auth_helper.php
3 months ago
blocks_helper.php
3 months ago
booking_helper.php
3 months ago
bricks_helper.php
3 months ago
bundles_helper.php
3 months ago
calendar_helper.php
3 months ago
carts_helper.php
3 months ago
connector_helper.php
3 months ago
csv_helper.php
3 months ago
customer_helper.php
3 months ago
customer_import_helper.php
3 months ago
database_helper.php
3 months ago
debug_helper.php
3 months ago
defaults_helper.php
3 months ago
elementor_helper.php
3 months ago
email_helper.php
3 months ago
encrypt_helper.php
3 months ago
events_helper.php
3 months ago
form_helper.php
3 months ago
icalendar_helper.php
3 months ago
image_helper.php
3 months ago
invoices_helper.php
3 months ago
license_helper.php
3 months ago
location_helper.php
3 months ago
marketing_systems_helper.php
3 months ago
meeting_systems_helper.php
3 months ago
menu_helper.php
3 months ago
meta_helper.php
3 months ago
migrations_helper.php
3 months ago
money_helper.php
3 months ago
notifications_helper.php
3 months ago
nps_survey_helper.php
3 months ago
order_intent_helper.php
3 months ago
orders_helper.php
3 months ago
otp_helper.php
3 months ago
pages_helper.php
3 months ago
params_helper.php
3 months ago
payments_helper.php
3 months ago
price_breakdown_helper.php
3 months ago
process_jobs_helper.php
3 months ago
processes_helper.php
3 months ago
replacer_helper.php
3 months ago
resource_helper.php
3 months ago
roles_helper.php
3 months ago
router_helper.php
3 months ago
service_helper.php
3 months ago
sessions_helper.php
3 months ago
settings_helper.php
3 months ago
short_links_systems_helper.php
3 months ago
shortcodes_helper.php
3 months ago
sms_helper.php
3 months ago
steps_helper.php
3 months ago
stripe_connect_helper.php
3 months ago
styles_helper.php
3 months ago
support_topics_helper.php
3 months ago
time_helper.php
3 months ago
timeline_helper.php
3 months ago
transaction_helper.php
3 months ago
transaction_intent_helper.php
3 months ago
util_helper.php
3 months ago
version_specific_updates_helper.php
3 months ago
whatsapp_helper.php
3 months ago
work_periods_helper.php
3 months ago
wp_datetime.php
3 months ago
wp_user_helper.php
3 months ago
elementor_helper.php
151 lines
| 1 | <?php |
| 2 | |
| 3 | class OsElementorHelper { |
| 4 | |
| 5 | private static ?OsElementorHelper $_instance = null; |
| 6 | public static string $category = 'latepoint_builder'; |
| 7 | |
| 8 | private string $min_elementor_version = '3.5.0'; |
| 9 | private string $min_php_version = '7.0'; |
| 10 | |
| 11 | private array $widgets = [ |
| 12 | 'book_button', |
| 13 | 'list_of_resources', |
| 14 | 'customer_login', |
| 15 | 'customer_dashboard', |
| 16 | 'calendar', |
| 17 | 'book_form', |
| 18 | ]; |
| 19 | |
| 20 | /** |
| 21 | * Instance |
| 22 | * Ensures only one instance of the class is loaded or can be loaded. |
| 23 | */ |
| 24 | public static function init(): OsElementorHelper { |
| 25 | if ( is_null( self::$_instance ) ) { |
| 26 | self::$_instance = new self(); |
| 27 | } |
| 28 | |
| 29 | return self::$_instance; |
| 30 | } |
| 31 | |
| 32 | |
| 33 | public function __construct() { |
| 34 | if ( $this->check_requirements() ) { |
| 35 | add_action( 'elementor/elements/categories_registered', [ $this, 'register_widgets_category' ] ); |
| 36 | add_action( 'elementor/widgets/register', [ $this, 'register_widgets' ] ); |
| 37 | } |
| 38 | } |
| 39 | |
| 40 | /** |
| 41 | * Check requirements for php and elementor |
| 42 | * @return bool |
| 43 | */ |
| 44 | private function check_requirements(): bool { |
| 45 | // Check if Elementor installed and activated |
| 46 | if ( ! did_action( 'elementor/loaded' ) ) { |
| 47 | return false; |
| 48 | } |
| 49 | |
| 50 | if ( ! $this->check_php_version() ) { |
| 51 | add_action( 'admin_notices', [ $this, 'php_version_error' ] ); |
| 52 | return false; |
| 53 | } |
| 54 | |
| 55 | if ( ! $this->check_elementor_version() ) { |
| 56 | add_action( 'admin_notices', [ $this, 'elementor_version_error' ] ); |
| 57 | return false; |
| 58 | } |
| 59 | |
| 60 | return true; |
| 61 | } |
| 62 | |
| 63 | private function check_php_version(): bool { |
| 64 | return version_compare( PHP_VERSION, $this->min_php_version, '>=' ); |
| 65 | } |
| 66 | |
| 67 | private function check_elementor_version(): bool { |
| 68 | if ( ! defined( 'ELEMENTOR_VERSION' ) ) { |
| 69 | return false; |
| 70 | } |
| 71 | |
| 72 | return version_compare( ELEMENTOR_VERSION, $this->min_elementor_version, '>=' ); |
| 73 | } |
| 74 | |
| 75 | private function php_version_error(): void { |
| 76 | $message = esc_html__( 'Theme requires PHP version', 'latepoint' ) . ' <strong>' . $this->min_php_version . '</strong> ' . esc_html__( 'or greater.', 'latepoint' ); |
| 77 | printf( '<div class="notice notice-warning is-dismissible"><p>%1$s</p></div>', $message ); |
| 78 | } |
| 79 | |
| 80 | private function elementor_version_error(): void { |
| 81 | $message = esc_html__( 'Theme requires Elementor version', 'latepoint' ) . ' <strong>' . $this->min_elementor_version . '</strong> ' . esc_html__( 'or greater.', 'latepoint' ); |
| 82 | printf( '<div class="notice notice-warning is-dismissible"><p>%1$s</p></div>', $message ); |
| 83 | } |
| 84 | |
| 85 | |
| 86 | /** |
| 87 | * @return array |
| 88 | */ |
| 89 | private function get_data_for_blocks(): array { |
| 90 | $result = []; |
| 91 | $localized_vars = OsBlockHelper::localized_vars_for_blocks(); |
| 92 | |
| 93 | $result['selected_agents_options'] = $this->prepare_data_for_select( $localized_vars['selected_agents_options'] ); |
| 94 | $result['selected_services_options'] = $this->prepare_data_for_select( $localized_vars['selected_services_options'] ); |
| 95 | $result['selected_service_categories_options'] = $this->prepare_data_for_select( $localized_vars['selected_service_categories_options'] ); |
| 96 | $result['selected_locations_options'] = $this->prepare_data_for_select( $localized_vars['selected_locations_options'] ); |
| 97 | $result['selected_bundles_options'] = $this->prepare_data_for_select( $localized_vars['selected_bundles_options'] ); |
| 98 | |
| 99 | $result['services'] = array_column( $localized_vars['services'], 'name', 'id' ); |
| 100 | $result['agents'] = array_column( $localized_vars['agents'], 'name', 'id' ); |
| 101 | $result['locations'] = array_column( $localized_vars['locations'], 'name', 'id' ); |
| 102 | $result['location_categories'] = OsLocationHelper::get_location_categories(); |
| 103 | $result['service_categories'] = array_column( $localized_vars['service_categories'], 'name', 'id' ); |
| 104 | $result['bundles'] = array_column( $localized_vars['bundles'], 'name', 'id' ); |
| 105 | return $result; |
| 106 | } |
| 107 | |
| 108 | private function prepare_data_for_select( array $options ): array { |
| 109 | return array_column( $options, 'label', 'value' ); |
| 110 | } |
| 111 | |
| 112 | /** |
| 113 | * Init Widgets - Include widgets files and register them |
| 114 | */ |
| 115 | public function register_widgets(): void { |
| 116 | |
| 117 | $data_for_blocks = $this->get_data_for_blocks(); |
| 118 | |
| 119 | |
| 120 | foreach ( $this->widgets as $widget ) { |
| 121 | $path = LATEPOINT_ABSPATH . 'blocks/elementor/elementor_widget_' . $widget . '.php'; |
| 122 | if ( file_exists( $path ) ) { |
| 123 | include_once $path; |
| 124 | # class name should be in format: Latepoint_Elementor_Widget_Book_Button |
| 125 | $class_name = 'Latepoint_Elementor_Widget_' . str_replace( [ '-', ' ' ], [ '_', '_' ], ucfirst( $widget ) ); |
| 126 | if ( class_exists( $class_name ) ) { |
| 127 | \Elementor\Plugin::instance()->widgets_manager->register( new $class_name( [], $data_for_blocks ) ); |
| 128 | } |
| 129 | } |
| 130 | } |
| 131 | } |
| 132 | |
| 133 | |
| 134 | /** |
| 135 | * Register Widgets Category |
| 136 | * |
| 137 | * @param $elements_manager |
| 138 | * |
| 139 | * @return void |
| 140 | */ |
| 141 | public function register_widgets_category( $elements_manager ): void { |
| 142 | $elements_manager->add_category( |
| 143 | self::$category, |
| 144 | [ |
| 145 | 'title' => __( 'Latepoint', 'latepoint' ), |
| 146 | 'icon' => 'fa fa-plug', |
| 147 | ] |
| 148 | ); |
| 149 | } |
| 150 | } |
| 151 |