PluginProbe
Booktics – Appointment Booking Calendar for Service Businesses / 1.0.23
Booktics – Appointment Booking Calendar for Service Businesses v1.0.23
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.23, at core/assets/localize.php

84 lines 2.9 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 if ( ! defined( 'ABSPATH' ) ) exit;
5
6 /**
7 * Manage all localize data
8 */
9 class Localize {
10
11 /**
12 * Get admin localize data
13 *
14 * @return array Collection localize data
15 */
16 public static function get_admin() {
17 $current_user = wp_get_current_user();
18 $user_roles = [];
19 if ( isset( $current_user->roles ) && is_array( $current_user->roles) ) {
20 foreach( $current_user->roles as $role) {
21 $user_roles[] = $role;
22 }
23 }
24
25 $data = [
26 'site_url' => site_url(),
27 'admin_url' => admin_url(),
28 'nonce' => wp_create_nonce( 'wp_rest' ),
29 'date_format' => get_option( 'date_format' ),
30 'date_format_string' => date_i18n( get_option( 'date_format' ) ),
31 'time_format' => get_option( 'time_format' ),
32 'time_format_string' => date_i18n( get_option( 'time_format' ) ),
33 'start_of_week' => get_option( 'start_of_week', 0 ),
34 'current_user_id' => get_current_user_id(),
35 'currency_list' => booktics_get_currencies(),
36 'bookticsPro' => class_exists('BookticsPro'),
37 'user_role' => (array) $user_roles,
38 'doc_links' => self::get_doc_links(),
39 ];
40
41 return apply_filters( 'booktics_admin_localize', $data );
42 }
43
44 /**
45 * Build a slug => doc_link map from the module registry.
46 *
47 * Single source of truth for documentation URLs: both the addon card
48 * (PHP `doc_link`) and the React configure modals read from this list,
49 * so a doc URL is only ever defined once in booktics_modules_list().
50 *
51 * @return array<string, string>
52 */
53 private static function get_doc_links() {
54 $doc_links = [];
55
56 foreach ( booktics_modules_list() as $module ) {
57 if ( ! empty( $module['slug'] ) && ! empty( $module['doc_link'] ) ) {
58 $doc_links[ $module['slug'] ] = $module['doc_link'];
59 }
60 }
61
62 return $doc_links;
63 }
64
65 /**
66 * Get frontend localize data
67 *
68 * @return array Collection localize data
69 */
70 public static function get_frontend() {
71 $data = [
72 'site_url' => site_url(),
73 'nonce' => wp_create_nonce( 'wp_rest' ),
74 'date_format' => get_option( 'date_format' ),
75 'time_format' => get_option( 'time_format' ),
76 'current_user_id' => get_current_user_id(),
77 'start_of_week' => get_option( 'start_of_week', 0 ),
78 'locale_name' => strtolower( str_replace( '_', '-', get_locale() ) ),
79 'currency_list' => booktics_get_currencies(),
80 ];
81
82 return apply_filters( 'booktics_frontend_localize', $data );
83 }
84 }