PluginProbe
MLSImport: IDX Plugin & MLS Plugin for Real Estate Listings / 7.1.1
MLSImport: IDX Plugin & MLS Plugin for Real Estate Listings v7.1.1
7.2.1 7.2 7.1.2 7.1.1 7.1 7.0.4 7.0.6 7.0.7 6.3.8 6.3.7 6.3.6 6.3.5 6.3.4 6.3.3 6.3.1 trunk 5.7.3 5.7.5 5.8.1 5.8.2 5.8.3 5.8.4 5.8.6 6.0.4 6.0.5 All 36 releases
mlsimport / includes / standalone / class-mlsimport-customize-sections-control.php

class-mlsimport-customize-sections-control.php in MLSImport: IDX Plugin & MLS Plugin for Real Estate Listings 7.1.1, at includes/standalone/class-mlsimport-customize-sections-control.php

97 lines 3.1 KB
No matching file
Up and down to move Enter to open Esc to close
Raw Download Zip
1 <?php
2 /**
3 * Customizer control for the "arrange sections" fields (the sections type):
4 * property_sections, agent_sections, overview_fields, archive_search_fields.
5 *
6 * Renders two lists — Enabled and Disabled — the user reorders (up/down) and moves
7 * items between. The value is the same {active:[...],inactive:[...]} object the
8 * settings page and front end use, so the arrangers round-trip through the one
9 * option. Defined lazily (on customize_register) because WP_Customize_Control is
10 * only loaded in the Customizer.
11 *
12 * @package Mlsimport
13 */
14
15 if ( ! defined( 'ABSPATH' ) ) {
16 exit;
17 }
18
19 if ( ! class_exists( 'WP_Customize_Control' ) ) {
20 return;
21 }
22
23 /**
24 * A reorder + enable/disable list control backed by a sections-type setting.
25 */
26 class Mlsimport_Customize_Sections_Control extends WP_Customize_Control {
27
28 /**
29 * The JS control type — matches the wp.customize.controlConstructor key.
30 *
31 * @var string
32 */
33 public $type = 'mlsimport_sections';
34
35 /**
36 * The slug => label catalog of every choice this control offers.
37 *
38 * @var array<string,string>
39 */
40 public $catalog = array();
41
42 /**
43 * Hand the catalog and the current value to the JS control.
44 *
45 * @return void
46 */
47 public function to_json() {
48 // Let the base control export label/description/etc first.
49 parent::to_json();
50
51 // Flatten the slug => label catalog into an ordered [{slug,label}] list for JS.
52 $catalog = array();
53 foreach ( $this->catalog as $slug => $label ) {
54 $catalog[] = array( 'slug' => $slug, 'label' => $label );
55 }
56 $this->json['catalog'] = $catalog;
57
58 // Current setting value; decode a JSON string into an array.
59 $value = $this->value();
60 if ( is_string( $value ) ) {
61 $decoded = json_decode( $value, true );
62 $value = is_array( $decoded ) ? $decoded : array();
63 }
64 // Normalise to the {active:[...],inactive:[...]} shape the JS control expects.
65 $this->json['mlsValue'] = array(
66 'active' => isset( $value['active'] ) ? array_values( (array) $value['active'] ) : array(),
67 'inactive' => isset( $value['inactive'] ) ? array_values( (array) $value['inactive'] ) : array(),
68 );
69 }
70
71 /**
72 * The content is drawn by the JS Underscore template; nothing to render here.
73 *
74 * @return void
75 */
76 public function render_content() {}
77
78 /**
79 * The Underscore template for the control. Two labelled lists plus per-item
80 * move/reorder buttons; the JS keeps a hidden input in sync with the setting.
81 *
82 * @return void
83 */
84 public function content_template() {
85 ?>
86 <# if ( data.label ) { #><span class="customize-control-title">{{ data.label }}</span><# } #>
87 <# if ( data.description ) { #><span class="description customize-control-description">{{{ data.description }}}</span><# } #>
88 <div class="mlsimport-arranger">
89 <p class="mlsimport-arranger__heading"><?php esc_html_e( 'Enabled', 'mlsimport' ); ?></p>
90 <ul class="mlsimport-arranger__list mlsimport-arranger__active"></ul>
91 <p class="mlsimport-arranger__heading"><?php esc_html_e( 'Disabled', 'mlsimport' ); ?></p>
92 <ul class="mlsimport-arranger__list mlsimport-arranger__inactive"></ul>
93 </div>
94 <?php
95 }
96 }
97