Blocks
2 weeks ago
Assets.php
2 weeks ago
Configuration.php
2 weeks ago
Configuration_Interface.php
2 weeks ago
Meta.php
2 weeks ago
Meta_Interface.php
2 weeks ago
Provider.php
2 weeks ago
Utils.php
2 weeks ago
Configuration.php
112 lines
| 1 | <?php |
| 2 | |
| 3 | /** |
| 4 | * Class Tribe__Editor__Configuration |
| 5 | * |
| 6 | * setup the configuration variables used on the editor |
| 7 | * |
| 8 | * @since 4.8 |
| 9 | */ |
| 10 | class Tribe__Editor__Configuration implements Tribe__Editor__Configuration_Interface { |
| 11 | |
| 12 | /** |
| 13 | * Localize variables that are part of common |
| 14 | * |
| 15 | * @since 4.8 |
| 16 | * |
| 17 | * @return array |
| 18 | */ |
| 19 | public function localize() { |
| 20 | /** |
| 21 | * @var Tribe__Languages__Locations $languages_locations |
| 22 | */ |
| 23 | $languages_locations = tribe( 'languages.locations' ); |
| 24 | $editor_config = [ |
| 25 | 'common' => [ |
| 26 | 'adminUrl' => admin_url(), |
| 27 | 'timeZone' => [ |
| 28 | 'showTimeZone' => false, |
| 29 | 'label' => $this->get_timezone_label(), |
| 30 | ], |
| 31 | 'rest' => [ |
| 32 | 'url' => get_rest_url(), |
| 33 | 'nonce' => [ |
| 34 | 'wp_rest' => wp_create_nonce( 'wp_rest' ), |
| 35 | ], |
| 36 | 'namespaces' => [ |
| 37 | 'core' => 'wp/v2', |
| 38 | ], |
| 39 | ], |
| 40 | 'dateSettings' => $this->get_date_settings(), |
| 41 | 'constants' => [ |
| 42 | 'hideUpsell' => ( defined( 'TRIBE_HIDE_UPSELL' ) && TRIBE_HIDE_UPSELL ), |
| 43 | ], |
| 44 | 'countries' => $languages_locations->get_countries( true ), |
| 45 | 'usStates' => Tribe__View_Helpers::loadStates(), |
| 46 | ], |
| 47 | 'blocks' => [], |
| 48 | ]; |
| 49 | |
| 50 | /** |
| 51 | * Filter the default configuration used to localize variables |
| 52 | * |
| 53 | * @since 4.8 |
| 54 | * |
| 55 | * array $editor_config An associative array with the configuration to be send into the client |
| 56 | */ |
| 57 | return apply_filters( 'tribe_editor_config', $editor_config ); |
| 58 | } |
| 59 | |
| 60 | |
| 61 | /** |
| 62 | * Returns the site timezone as a string |
| 63 | * |
| 64 | * @since 4.8 |
| 65 | * |
| 66 | * @return string |
| 67 | */ |
| 68 | public function get_timezone_label() { |
| 69 | return class_exists( 'Tribe__Timezones' ) |
| 70 | ? Tribe__Timezones::wp_timezone_string() |
| 71 | : get_option( 'timezone_string', 'UTC' ); |
| 72 | } |
| 73 | |
| 74 | /** |
| 75 | * Get Localization data for Date settings |
| 76 | * |
| 77 | * @since 4.8 |
| 78 | * |
| 79 | * @return array |
| 80 | */ |
| 81 | public function get_date_settings() { |
| 82 | global $wp_locale; |
| 83 | |
| 84 | return [ |
| 85 | 'l10n' => [ |
| 86 | 'locale' => get_user_locale(), |
| 87 | 'months' => array_values( $wp_locale->month ), |
| 88 | 'monthsShort' => array_values( $wp_locale->month_abbrev ), |
| 89 | 'weekdays' => array_values( $wp_locale->weekday ), |
| 90 | 'weekdaysShort' => array_values( $wp_locale->weekday_abbrev ), |
| 91 | 'meridiem' => (object) $wp_locale->meridiem, |
| 92 | 'relative' => [ |
| 93 | /* translators: %s: duration */ |
| 94 | 'future' => __( '%s from now', 'default' ), |
| 95 | /* translators: %s: duration */ |
| 96 | 'past' => __( '%s ago', 'default' ), |
| 97 | ], |
| 98 | ], |
| 99 | 'formats' => [ |
| 100 | 'time' => get_option( 'time_format', __( 'g:i a', 'default' ) ), |
| 101 | 'date' => get_option( 'date_format', __( 'F j, Y', 'default' ) ), |
| 102 | 'dateNoYear' => __( 'F j', 'default' ), |
| 103 | 'datetime' => get_option( 'date_format', __( 'F j, Y', 'default' ) ) . ' ' . get_option( 'time_format', __( 'g:i a', 'default' ) ), |
| 104 | ], |
| 105 | 'timezone' => [ |
| 106 | 'offset' => get_option( 'gmt_offset', 0 ), |
| 107 | 'string' => $this->get_timezone_label(), |
| 108 | ], |
| 109 | ]; |
| 110 | } |
| 111 | } |
| 112 |