PluginProbe ʕ •ᴥ•ʔ
Pods – Custom Content Types and Fields / 2.8.23.4
Pods – Custom Content Types and Fields v2.8.23.4
2.7.31.4 2.8.23.5 2.9.19.5 3.0.10.5 3.1.4.3 3.2.8.4 3.3.9.2 2.8.23.4 2.9.19.4 3.0.10.4 3.1.4.2 3.2.8.3 3.3.9.1 trunk 1.14.8 2.7.31.3 2.8.23.3 2.9.19.3 3.0.10.3 3.1.4.1 3.2.0 3.2.1 3.2.1.1 3.2.2 3.2.4 3.2.5 3.2.6 3.2.7 3.2.7.1 3.2.8 3.2.8.1 3.2.8.2 3.3.0 3.3.1 3.3.2 3.3.3 3.3.4 3.3.5 3.3.6 3.3.7 3.3.8 3.3.9
pods / tribe-common / src / Tribe / Admin / Live_Date_Preview.php
pods / tribe-common / src / Tribe / Admin Last commit date
Notice 2 weeks ago Activation_Page.php 2 weeks ago Help_Page.php 2 weeks ago Helpers.php 2 weeks ago Live_Date_Preview.php 2 weeks ago Notices.php 2 weeks ago
Live_Date_Preview.php
69 lines
1 <?php
2 /**
3 * Facilitiates live date previews in the Events > Settings > Display admin screen.
4 */
5 class Tribe__Admin__Live_Date_Preview {
6 protected $target_fields = [
7 'dateWithYearFormat',
8 'dateWithoutYearFormat',
9 'monthAndYearFormat',
10 'weekDayFormat',
11 ];
12
13 /**
14 * Static Singleton Holder
15 *
16 * @var self
17 */
18 protected static $instance;
19
20 /**
21 * Static Singleton Factory Method
22 *
23 * @return self
24 */
25 public static function instance() {
26 return self::$instance ? self::$instance : self::$instance = new self;
27 }
28
29 /**
30 * Adds live date previews to the display settings tab (nothing is setup unless
31 * the user is actually on that tab).
32 */
33 public function __construct() {
34 add_action( 'tribe_settings_after_do_tabs', [ $this, 'listen' ] );
35 }
36
37 /**
38 * If the user looking at the Display settings tab, adds live date preview facilities.
39 */
40 public function listen() {
41 // We are only interested in the "Display" tab
42 if ( 'display' !== Tribe__Settings::instance()->currentTab ) {
43 return;
44 }
45
46 /**
47 * Add or remove fields which should have live date/time preview facilities.
48 *
49 * @var array $target_fields
50 */
51 $this->target_fields = (array) apply_filters( 'tribe_settings_date_preview_fields', $this->target_fields );
52
53 add_filter( 'tribe_field_div_end', [ $this, 'setup_date_previews' ], 10, 2 );
54
55 // We are still before `admin_enqueue_scripts` making it safe to use `tribe_asset`
56 tribe_asset( Tribe__Main::instance(), 'tribe-date-live-refresh', 'admin-date-preview.js', [ 'jquery' ], 'admin_enqueue_scripts' );
57 }
58
59 public function setup_date_previews( $html, $field ) {
60 // Not one of the fields we're interested in? Return without modification
61 if ( ! in_array( $field->id, $this->target_fields ) ) {
62 return $html;
63 }
64
65 $preview = esc_html( date_i18n( $field->value ) );
66 return " <code class='live-date-preview'> $preview </code> $html";
67 }
68 }
69