Divider.php
79 lines
| 1 | <?php |
| 2 | /** |
| 3 | * Customizer Control: kirki-divider. |
| 4 | * |
| 5 | * @package kirki-divider |
| 6 | * @since 1.0 |
| 7 | */ |
| 8 | |
| 9 | namespace Kirki\Control; |
| 10 | |
| 11 | use Kirki\Control\Base; |
| 12 | |
| 13 | // Exit if accessed directly. |
| 14 | if ( ! defined( 'ABSPATH' ) ) { |
| 15 | exit; |
| 16 | } |
| 17 | |
| 18 | /** |
| 19 | * Divider control |
| 20 | */ |
| 21 | class Divider extends Base { |
| 22 | |
| 23 | /** |
| 24 | * The control type. |
| 25 | * |
| 26 | * @since 1.0 |
| 27 | * @var string |
| 28 | */ |
| 29 | public $type = 'kirki-divider'; |
| 30 | |
| 31 | /** |
| 32 | * The version. Used in scripts & styles for cache-busting. |
| 33 | * |
| 34 | * @since 1.0 |
| 35 | * @var string |
| 36 | */ |
| 37 | public static $control_ver = '1.0'; |
| 38 | |
| 39 | /** |
| 40 | * Refresh the parameters passed to the JavaScript via JSON. |
| 41 | * |
| 42 | * @access public |
| 43 | * @since 1.0 |
| 44 | * @see WP_Customize_Control::to_json() |
| 45 | * @return void |
| 46 | */ |
| 47 | public function to_json() { |
| 48 | |
| 49 | // Get the basics from the parent class. |
| 50 | parent::to_json(); |
| 51 | |
| 52 | $border_top_color = isset( $this->choices ) && isset( $this->choices['color'] ) ? esc_attr( $this->choices['color'] ) : '#ccc'; |
| 53 | $border_bottom_color = '#f8f8f8'; |
| 54 | |
| 55 | $this->json['choices']['borderTopColor'] = $border_top_color; |
| 56 | $this->json['choices']['borderBottomColor'] = $border_bottom_color; |
| 57 | |
| 58 | } |
| 59 | |
| 60 | /** |
| 61 | * An Underscore (JS) template for this control's content (but not its container). |
| 62 | * |
| 63 | * Class variables for this control class are available in the `data` JS object; |
| 64 | * export custom variables by overriding {@see WP_Customize_Control::to_json()}. |
| 65 | * |
| 66 | * @see WP_Customize_Control::print_template() |
| 67 | * @since 1.0 |
| 68 | */ |
| 69 | protected function content_template() { |
| 70 | ?> |
| 71 | |
| 72 | <hr style="border-top: 1px solid {{ data.choices.borderTopColor }}; border-bottom: 1px solid {{ data.choices.borderBottomColor }}" /> |
| 73 | |
| 74 | <?php |
| 75 | |
| 76 | } |
| 77 | |
| 78 | } |
| 79 |