Tabs.php
115 lines
| 1 | <?php // phpcs:disable PHPCompatibility.FunctionDeclarations.NewClosure |
| 2 | /** |
| 3 | * Override field methods |
| 4 | * |
| 5 | * @package kirki-tabs |
| 6 | * @since 1.0 |
| 7 | */ |
| 8 | |
| 9 | namespace Kirki\Field; |
| 10 | |
| 11 | use Kirki\Field; |
| 12 | |
| 13 | /** |
| 14 | * Field overrides. |
| 15 | * |
| 16 | * @since 1.0 |
| 17 | */ |
| 18 | class Tabs extends Field { |
| 19 | |
| 20 | /** |
| 21 | * The field type. |
| 22 | * |
| 23 | * @since 1.0 |
| 24 | * @var string |
| 25 | */ |
| 26 | public $type = 'kirki-tab'; |
| 27 | |
| 28 | /** |
| 29 | * The control class-name. |
| 30 | * |
| 31 | * @since 1.0 |
| 32 | * @var string |
| 33 | */ |
| 34 | protected $control_class = '\Kirki\Control\Tabs'; |
| 35 | |
| 36 | /** |
| 37 | * Whether we should register the control class for JS-templating or not. |
| 38 | * |
| 39 | * @access protected |
| 40 | * @since 1.0 |
| 41 | * @var bool |
| 42 | */ |
| 43 | protected $control_has_js_template = true; |
| 44 | |
| 45 | /** |
| 46 | * Array of tabs collection. |
| 47 | * |
| 48 | * @since 1.0.0 |
| 49 | * @var array |
| 50 | */ |
| 51 | public static $tabs = []; |
| 52 | |
| 53 | /** |
| 54 | * Constructor. |
| 55 | * Registers any hooks we need to run. |
| 56 | * |
| 57 | * @since 1.0.0 |
| 58 | * @param array $args The field arguments. |
| 59 | */ |
| 60 | public function __construct( $args ) { |
| 61 | |
| 62 | parent::__construct( $args ); |
| 63 | |
| 64 | self::$tabs[ $args['section'] ] = $args['choices']['tabs']; |
| 65 | |
| 66 | } |
| 67 | |
| 68 | /** |
| 69 | * Filter arguments before creating the setting. |
| 70 | * |
| 71 | * @since 1.0 |
| 72 | * |
| 73 | * @param array $args The field arguments. |
| 74 | * @param WP_Customize_Manager $wp_customize The customizer instance. |
| 75 | * |
| 76 | * @return array |
| 77 | */ |
| 78 | public function filter_setting_args( $args, $wp_customize ) { |
| 79 | |
| 80 | if ( $args['settings'] === $this->args['settings'] ) { |
| 81 | $args = parent::filter_setting_args( $args, $wp_customize ); |
| 82 | |
| 83 | // Set the sanitize-callback if none is defined. |
| 84 | if ( ! isset( $args['sanitize_callback'] ) || ! $args['sanitize_callback'] ) { |
| 85 | $args['sanitize_callback'] = '__return_null'; |
| 86 | } |
| 87 | } |
| 88 | |
| 89 | return $args; |
| 90 | |
| 91 | } |
| 92 | |
| 93 | /** |
| 94 | * Filter arguments before creating the control. |
| 95 | * |
| 96 | * @since 0.1 |
| 97 | * |
| 98 | * @param array $args The field arguments. |
| 99 | * @param WP_Customize_Manager $wp_customize The customizer instance. |
| 100 | * |
| 101 | * @return array |
| 102 | */ |
| 103 | public function filter_control_args( $args, $wp_customize ) { |
| 104 | |
| 105 | if ( $args['settings'] === $this->args['settings'] ) { |
| 106 | $args = parent::filter_control_args( $args, $wp_customize ); |
| 107 | $args['type'] = 'kirki-tab'; |
| 108 | } |
| 109 | |
| 110 | return $args; |
| 111 | |
| 112 | } |
| 113 | } |
| 114 | |
| 115 |