| 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 |
]; |
| 39 |
|
| 40 |
return apply_filters( 'booktics_admin_localize', $data ); |
| 41 |
} |
| 42 |
|
| 43 |
/** |
| 44 |
* Get frontend localize data |
| 45 |
* |
| 46 |
* @return array Collection localize data |
| 47 |
*/ |
| 48 |
public static function get_frontend() { |
| 49 |
$data = [ |
| 50 |
'site_url' => site_url(), |
| 51 |
'nonce' => wp_create_nonce( 'wp_rest' ), |
| 52 |
'date_format' => get_option( 'date_format' ), |
| 53 |
'time_format' => get_option( 'time_format' ), |
| 54 |
'current_user_id' => get_current_user_id(), |
| 55 |
'start_of_week' => get_option( 'start_of_week', 0 ), |
| 56 |
'locale_name' => strtolower( str_replace( '_', '-', get_locale() ) ), |
| 57 |
'currency_list' => booktics_get_currencies(), |
| 58 |
]; |
| 59 |
|
| 60 |
return apply_filters( 'booktics_frontend_localize', $data ); |
| 61 |
} |
| 62 |
} |