config
5 years ago
includes
1 day ago
languages
5 years ago
media
5 years ago
scripts
1 day ago
static
4 years ago
styles
1 day ago
divi_amelia.php
1 day ago
package-lock.json
6 months ago
package.json
6 months ago
divi_amelia.php
168 lines
| 1 | <?php |
| 2 | |
| 3 | /* |
| 4 | Plugin Name: Divi Amelia |
| 5 | Plugin URI: |
| 6 | Description: |
| 7 | Version: 1.0.0 |
| 8 | Author: |
| 9 | Author URI: |
| 10 | License: GPL2 |
| 11 | License URI: https://www.gnu.org/licenses/gpl-2.0.html |
| 12 | Text Domain: divi-divi_amelia |
| 13 | Domain Path: /languages |
| 14 | |
| 15 | Divi Amelia is free software: you can redistribute it and/or modify |
| 16 | it under the terms of the GNU General Public License as published by |
| 17 | the Free Software Foundation, either version 2 of the License, or |
| 18 | any later version. |
| 19 | |
| 20 | Divi Amelia is distributed in the hope that it will be useful, |
| 21 | but WITHOUT ANY WARRANTY; without even the implied warranty of |
| 22 | MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the |
| 23 | GNU General Public License for more details. |
| 24 | |
| 25 | You should have received a copy of the GNU General Public License |
| 26 | along with Divi Amelia. If not, see https://www.gnu.org/licenses/gpl-2.0.html. |
| 27 | */ |
| 28 | |
| 29 | use AmeliaBooking\Domain\Services\Settings\SettingsService; |
| 30 | use AmeliaBooking\Infrastructure\WP\SettingsService\SettingsStorage; |
| 31 | use AmeliaBooking\Infrastructure\WP\ShortcodeService\ShortcodeAliasService; |
| 32 | use AmeliaBooking\Infrastructure\WP\Translations\BackendStrings; |
| 33 | |
| 34 | if (! function_exists('divi_initialize_extension_amelia')) : |
| 35 | /** |
| 36 | * Creates the extension's main class instance. |
| 37 | * |
| 38 | * @since 1.0.0 |
| 39 | */ |
| 40 | function divi_initialize_extension_amelia() |
| 41 | { |
| 42 | require_once plugin_dir_path(__FILE__) . 'includes/DiviAmelia.php'; |
| 43 | |
| 44 | wp_register_style('wpamelia-divi', plugins_url('styles/divi-amelia.css', __FILE__), [], AMELIA_VERSION); |
| 45 | wp_enqueue_style('wpamelia-divi'); |
| 46 | |
| 47 | $settingsService = new SettingsService(new SettingsStorage()); |
| 48 | $useNeutral = ShortcodeAliasService::shouldUseNeutralShortcodes($settingsService); |
| 49 | |
| 50 | // Divi Visual Builder (frontend iframe) does not use admin_body_class. |
| 51 | if ($useNeutral) { |
| 52 | wp_register_script('amelia-divi-white-label', false, [], AMELIA_VERSION, false); |
| 53 | wp_enqueue_script('amelia-divi-white-label'); |
| 54 | wp_add_inline_script( |
| 55 | 'amelia-divi-white-label', |
| 56 | '(function(){var c="amelia-white-label-active";document.documentElement.classList.add(c);' |
| 57 | . 'function a(){if(document.body){document.body.classList.add(c)}}' |
| 58 | . 'document.body?a():document.addEventListener("DOMContentLoaded",a);})();' |
| 59 | ); |
| 60 | |
| 61 | // Custom image uploaded: replace Amelia logo in the module picker only. |
| 62 | // Canvas shortcode display stays logo-free (same as default Amelia logo behaviour). |
| 63 | $pluginImage = ShortcodeAliasService::getWhiteLabelPluginImage($settingsService); |
| 64 | if ($pluginImage !== '') { |
| 65 | wp_register_style('amelia-white-label-builders', false, ['wpamelia-divi'], AMELIA_VERSION); |
| 66 | wp_enqueue_style('amelia-white-label-builders'); |
| 67 | |
| 68 | $moduleSelectors = [ |
| 69 | '.divi_customer:before', |
| 70 | '.divi_employee:before', |
| 71 | '.divi_step_booking:before', |
| 72 | '.divi_catalog_booking:before', |
| 73 | '.divi_events_list_booking:before', |
| 74 | '.divi_events_calendar_booking:before', |
| 75 | '.divi_booking:before', |
| 76 | '.divi_catalog:before', |
| 77 | '.divi_events:before', |
| 78 | '.divi_search:before', |
| 79 | ]; |
| 80 | $selectors = []; |
| 81 | foreach ($moduleSelectors as $moduleSelector) { |
| 82 | $selectors[] = 'html.amelia-white-label-active .et-fb-modules-list ' . $moduleSelector; |
| 83 | $selectors[] = 'body.amelia-white-label-active .et-fb-modules-list ' . $moduleSelector; |
| 84 | } |
| 85 | $css = implode(', ', $selectors) . '{' |
| 86 | . 'content:""!important;' |
| 87 | . 'display:block!important;' |
| 88 | . 'background-image:url(' . esc_url_raw($pluginImage) . ')!important;' |
| 89 | . 'background-repeat:no-repeat!important;' |
| 90 | . 'background-position:center center!important;' |
| 91 | . 'background-size:contain!important;' |
| 92 | . 'height:20px!important;' |
| 93 | . 'margin:0 auto 1px!important;' |
| 94 | . '}'; |
| 95 | wp_add_inline_style('amelia-white-label-builders', $css); |
| 96 | } |
| 97 | } |
| 98 | |
| 99 | add_filter('admin_body_class', static function ($classes) use ($useNeutral) { |
| 100 | if ($useNeutral) { |
| 101 | $classes .= ' amelia-white-label-active'; |
| 102 | } |
| 103 | |
| 104 | return $classes; |
| 105 | }); |
| 106 | |
| 107 | add_filter('body_class', static function ($classes) use ($useNeutral) { |
| 108 | if ($useNeutral) { |
| 109 | $classes[] = 'amelia-white-label-active'; |
| 110 | } |
| 111 | |
| 112 | return $classes; |
| 113 | }); |
| 114 | } |
| 115 | add_action('divi_extensions_init', 'divi_initialize_extension_amelia'); |
| 116 | endif; |
| 117 | |
| 118 | /** |
| 119 | * Localize white-label shortcode data for Divi 4 Visual Builder. |
| 120 | * Helpers live in includes/neutral-labels.js and must load before the builder bundle. |
| 121 | */ |
| 122 | if (! function_exists('divi_amelia_add_white_label_data')) : |
| 123 | function divi_amelia_add_white_label_data() |
| 124 | { |
| 125 | static $printed = false; |
| 126 | |
| 127 | if ($printed) { |
| 128 | return; |
| 129 | } |
| 130 | |
| 131 | $isBuilder = (function_exists('et_core_is_fb_enabled') && et_core_is_fb_enabled()) |
| 132 | || (function_exists('et_fb_is_enabled') && et_fb_is_enabled()) |
| 133 | || (is_admin() && (!empty($_GET['et_fb']) || !empty($_GET['et_pb_preview']))); |
| 134 | |
| 135 | if (!$isBuilder) { |
| 136 | return; |
| 137 | } |
| 138 | |
| 139 | $printed = true; |
| 140 | |
| 141 | $settingsService = new SettingsService(new SettingsStorage()); |
| 142 | |
| 143 | $localize = 'window.wpAmeliaLabels = window.wpAmeliaLabels || ' . wp_json_encode(BackendStrings::getAllStrings()) . ';' |
| 144 | . 'window.wpAmeliaUseNeutralShortcodes = ' . wp_json_encode(ShortcodeAliasService::shouldUseNeutralShortcodes($settingsService)) . ';' |
| 145 | . 'window.wpAmeliaShortcodeAliases = ' . wp_json_encode(ShortcodeAliasService::getAliases()) . ';' |
| 146 | . 'window.wpAmeliaPluginName = ' . wp_json_encode(ShortcodeAliasService::getWhiteLabelPluginName($settingsService)) . ';' |
| 147 | . 'window.wpAmeliaBuilderBrandName = ' . wp_json_encode(ShortcodeAliasService::getBuilderBrandName($settingsService)) . ';' |
| 148 | . 'window.wpAmeliaPluginImage = ' . wp_json_encode(ShortcodeAliasService::getWhiteLabelPluginImage($settingsService)) . ';'; |
| 149 | |
| 150 | wp_register_script( |
| 151 | 'amelia-divi-neutral-labels', |
| 152 | plugins_url('includes/neutral-labels.js', __FILE__), |
| 153 | [], |
| 154 | AMELIA_VERSION, |
| 155 | false |
| 156 | ); |
| 157 | wp_add_inline_script('amelia-divi-neutral-labels', $localize, 'before'); |
| 158 | wp_enqueue_script('amelia-divi-neutral-labels'); |
| 159 | } |
| 160 | // Enqueue early so helpers exist before the Divi builder bundle runs. |
| 161 | add_action('wp_enqueue_scripts', 'divi_amelia_add_white_label_data', 1); |
| 162 | add_action('admin_enqueue_scripts', 'divi_amelia_add_white_label_data', 1); |
| 163 | // VB iframe / late boot paths. |
| 164 | add_action('wp_head', 'divi_amelia_add_white_label_data', 1); |
| 165 | add_action('admin_head', 'divi_amelia_add_white_label_data', 1); |
| 166 | add_action('et_fb_framework_loaded', 'divi_amelia_add_white_label_data'); |
| 167 | endif; |
| 168 |