PluginProbe
Booktics – Appointment Booking Calendar for Service Businesses / 1.0.27
Booktics – Appointment Booking Calendar for Service Businesses v1.0.27
1.0.29 1.0.28 1.0.27 1.0.26 1.0.25 1.0.24 1.0.23 1.0.22 1.0.21 1.0.20 1.0.19 trunk 1.0.0 1.0.1 1.0.10 1.0.11 1.0.12 1.0.13 1.0.14 1.0.15 1.0.16 1.0.17 1.0.18 1.0.2 1.0.3 All 31 releases
booktics / core / assets / localize.php

localize.php in Booktics – Appointment Booking Calendar for Service Businesses 1.0.27, at core/assets/localize.php

115 lines 4.3 KB
No matching file
Up and down to move Enter to open Esc to close
Raw Download Zip
1 <?php
2 namespace Booktics\Assets;
3
4 use Booktics\Admin\Theme_Mode;
5
6 if ( ! defined( 'ABSPATH' ) ) exit;
7
8 /**
9 * Manage all localize data
10 */
11 class Localize {
12
13 /**
14 * Get admin localize data
15 *
16 * @return array Collection localize data
17 */
18 public static function get_admin() {
19 $current_user = wp_get_current_user();
20 $user_roles = [];
21 if ( isset( $current_user->roles ) && is_array( $current_user->roles) ) {
22 foreach( $current_user->roles as $role) {
23 $user_roles[] = $role;
24 }
25 }
26
27 $data = [
28 'site_url' => site_url(),
29 'admin_url' => admin_url(),
30 'nonce' => wp_create_nonce( 'wp_rest' ),
31 'date_format' => get_option( 'date_format' ),
32 'date_format_string' => date_i18n( get_option( 'date_format' ) ),
33 'time_format' => get_option( 'time_format' ),
34 'time_format_string' => date_i18n( get_option( 'time_format' ) ),
35 'start_of_week' => get_option( 'start_of_week', 0 ),
36 'current_user_id' => get_current_user_id(),
37 'current_user_email' => $current_user->user_email,
38 'current_user_name' => $current_user->display_name,
39 'currency_list' => booktics_get_currencies(),
40 'bookticsPro' => class_exists('BookticsPro'),
41 'user_role' => (array) $user_roles,
42 'doc_links' => self::get_doc_links(),
43 'aisentic' => self::get_aisentic_state(),
44 'theme_mode' => Theme_Mode::get_for_user(),
45 'dark_mode_enabled' => Theme_Mode::is_enabled(),
46 ];
47
48 return apply_filters( 'booktics_admin_localize', $data );
49 }
50
51 /**
52 * Build a slug => doc_link map from the module registry.
53 *
54 * Single source of truth for documentation URLs: both the addon card
55 * (PHP `doc_link`) and the React configure modals read from this list,
56 * so a doc URL is only ever defined once in booktics_modules_list().
57 *
58 * @return array<string, string>
59 */
60 private static function get_doc_links() {
61 $doc_links = [];
62
63 foreach ( booktics_modules_list() as $module ) {
64 if ( ! empty( $module['slug'] ) && ! empty( $module['doc_link'] ) ) {
65 $doc_links[ $module['slug'] ] = $module['doc_link'];
66 }
67 }
68
69 return $doc_links;
70 }
71
72 /**
73 * Aisentic connection state for the admin UI.
74 *
75 * The identity comes from booktics_aisentic_identity() so the email rendered on
76 * the consent copy is the same one the register action would send.
77 *
78 * @return array<string, mixed>
79 */
80 private static function get_aisentic_state() {
81 $identity = booktics_aisentic_identity();
82 $integration = get_option( 'aisentic_integration_settings', [] );
83
84 return [
85 'name' => $identity['name'],
86 'email' => $identity['email'],
87 'site_url' => $identity['site_url'],
88 'active' => class_exists( 'Aisentic\Init' ),
89 'registered' => booktics_aisentic_is_registered(),
90 'supports_registration' => class_exists( 'Aisentic\Api\Services\Registration_Service' ),
91 'connected' => isset( $integration['booktics']['status'] )
92 && 'connected' === $integration['booktics']['status'],
93 ];
94 }
95
96 /**
97 * Get frontend localize data
98 *
99 * @return array Collection localize data
100 */
101 public static function get_frontend() {
102 $data = [
103 'site_url' => site_url(),
104 'nonce' => wp_create_nonce( 'wp_rest' ),
105 'date_format' => get_option( 'date_format' ),
106 'time_format' => get_option( 'time_format' ),
107 'current_user_id' => get_current_user_id(),
108 'start_of_week' => get_option( 'start_of_week', 0 ),
109 'locale_name' => strtolower( str_replace( '_', '-', get_locale() ) ),
110 'currency_list' => booktics_get_currencies(),
111 ];
112
113 return apply_filters( 'booktics_frontend_localize', $data );
114 }
115 }