PluginProbe ʕ •ᴥ•ʔ
Booking for Appointments and Events Calendar – Amelia / 2.4.8
Booking for Appointments and Events Calendar – Amelia v2.4.8
2.4.8 2.4.7 2.4.6 2.4.5 2.4.4 2.4.3 2.4.2 2.4.1 2.4 trunk 1.2.1 1.2.10 1.2.11 1.2.12 1.2.13 1.2.14 1.2.15 1.2.16 1.2.17 1.2.18 1.2.19 1.2.2 1.2.20 1.2.21 1.2.22 1.2.23 1.2.24 1.2.25 1.2.26 1.2.27 1.2.28 1.2.29 1.2.3 1.2.30 1.2.31 1.2.32 1.2.33 1.2.34 1.2.35 1.2.36 1.2.37 1.2.38 1.2.4 1.2.5 1.2.6 1.2.7 1.2.8 1.2.9 2.0 2.0.1 2.0.2 2.1 2.1.1 2.1.2 2.1.3 2.2 2.2.1 2.3
ameliabooking / src / Infrastructure / WP / ButtonService / ButtonService.php
ameliabooking / src / Infrastructure / WP / ButtonService Last commit date
ButtonService.php 5 days ago
ButtonService.php
145 lines
1 <?php
2
3 /**
4 * @copyright © Melograno Ventures. All rights reserved.
5 * @licence See LICENCE.md for license details.
6 */
7
8 namespace AmeliaBooking\Infrastructure\WP\ButtonService;
9
10 use AmeliaBooking\Domain\Services\Settings\SettingsService;
11 use AmeliaBooking\Infrastructure\WP\HelperService\HelperService;
12 use AmeliaBooking\Infrastructure\WP\SettingsService\SettingsStorage;
13 use AmeliaBooking\Infrastructure\WP\ShortcodeService\ShortcodeAliasService;
14 use AmeliaBooking\Infrastructure\WP\Translations\BackendStrings;
15
16 /**
17 * Class ButtonService
18 *
19 * @package AmeliaBooking\Infrastructure\WP\ShortcodeService
20 */
21 class ButtonService
22 {
23 /**
24 * Function that adds shortcode button to WordPress TinyMCE editor on Page and Post pages
25 */
26 public static function renderButton()
27 {
28 global $pagenow;
29
30 if (is_admin() && isset($pagenow) && 'customize.php' === $pagenow) {
31 return;
32 }
33
34 if (!current_user_can('edit_posts') && !current_user_can('edit_pages')) {
35 return;
36 }
37
38 if (get_user_option('rich_editing') !== 'true') {
39 return;
40 }
41
42 add_filter('mce_external_plugins', [self::class, 'addButton']);
43 add_filter('mce_buttons', [self::class, 'registerButton']);
44 // Export JS variables for classic editor
45 add_action('after_wp_tiny_mce', [self::class, 'exportVars']);
46 // Export JS variables for Gutenberg editor
47 add_action('admin_enqueue_scripts', [self::class, 'exportVars']);
48 }
49
50 /**
51 * Function that add buttons for MCE editor
52 *
53 * @param $pluginArray
54 *
55 * @return mixed
56 */
57 public static function addButton($pluginArray)
58 {
59 $pluginArray['ameliaBookingPlugin'] = AMELIA_URL . 'public/js/tinymce/amelia-mce.js';
60
61 return $pluginArray;
62 }
63
64 /**
65 * Function that register buttons for MCE editor
66 *
67 * @param $buttons
68 *
69 * @return mixed
70 */
71 public static function registerButton($buttons)
72 {
73 $buttons[] = 'ameliaButton';
74
75 return $buttons;
76 }
77
78 public static function exportVars()
79 {
80 HelperService::exportJSVar('wpAmeliaPluginURL', AMELIA_URL);
81 HelperService::exportJSVar('wpAmeliaSiteURL', AMELIA_SITE_URL);
82 HelperService::exportJSVar('wpAmeliaPluginStoreURL', AMELIA_STORE_API_URL);
83 HelperService::exportJSVar('wpAmeliaPluginAjaxURL', AMELIA_ACTION_URL);
84
85 wp_enqueue_script('wp-deactivation-amelia', AMELIA_URL . 'public/js/plugins/delete-plugin.js', []);
86
87 wp_enqueue_style('amelia_booking_tinymce_styles', AMELIA_URL . 'public/js/tinymce/amelia-tinymce-styles.css', array(), AMELIA_VERSION);
88
89 $settingsService = new SettingsService(new SettingsStorage());
90 $whiteLabelPluginName = ShortcodeAliasService::getWhiteLabelPluginName($settingsService);
91
92 HelperService::exportJSVar(
93 'wpAmeliaPluginName',
94 $whiteLabelPluginName
95 );
96
97 HelperService::exportJSVar(
98 'wpAmeliaUseNeutralShortcodes',
99 ShortcodeAliasService::shouldUseNeutralShortcodes()
100 );
101
102 HelperService::exportJSVar(
103 'wpAmeliaBuilderBrandName',
104 ShortcodeAliasService::getBuilderBrandName($settingsService)
105 );
106
107 HelperService::exportJSVar(
108 'wpAmeliaPluginImage',
109 ShortcodeAliasService::getWhiteLabelPluginImage($settingsService)
110 );
111
112 HelperService::exportJSVar(
113 'wpAmeliaShortcodeAliases',
114 ShortcodeAliasService::getAliases()
115 );
116
117 HelperService::exportJSVar(
118 'wpAmeliaDeleteSettings',
119 $settingsService->getSetting('activation', 'deleteTables') ? 1 : 0
120 );
121
122 HelperService::exportJSVar(
123 'wpAmeliaNonce',
124 wp_create_nonce('ajax-nonce')
125 );
126
127 HelperService::exportJSVar('wpAmeliaActionURL', AMELIA_ACTION_URL);
128
129 HelperService::exportJSVar(
130 'wpAmeliaLabels',
131 BackendStrings::getAllStrings(),
132 );
133
134 add_filter('admin_body_class', static function ($classes) use ($settingsService) {
135 if (ShortcodeAliasService::shouldUseNeutralShortcodes($settingsService)) {
136 $classes .= ' amelia-white-label-active';
137 }
138
139 return $classes;
140 });
141
142 HelperService::printJSVars();
143 }
144 }
145