Kirki_Scripts_Tooltips::generate_script PHP Method

generate_script() public static method

This works on a per-field basis. Once created, the script is added to the $tooltip_script property.
public static generate_script ( array $args = [] ) : void
$args array The field definition.
return void
        public static function generate_script($args = array())
        {
            /**
             * The following control types already have the "tooltip" argument in them
             * and they don't need an extra implementation in order to be rendered.
             * We're going to ignore these control-types and only process the rest.
             */
            $ready_controls = array('checkbox', 'code', 'color-alpha', 'custom', 'dimension', 'editor', 'multicheck', 'number', 'palette', 'radio-buttonset', 'radio-image', 'radio', 'kirki-radio', 'repeater', 'select', 'kirki-select', 'select2', 'select2-multiple', 'slider', 'sortable', 'spacing', 'switch', 'textarea', 'toggle', 'typography');
            /**
             * Make sure the field-type has been defined.
             * If it has not been defined the we don't know what to do with it and should exit.
             * No error is displayed, we just won't do anything.
             */
            if (isset($args['type']) && in_array($args['type'], $ready_controls)) {
                return;
            }
            $script = '';
            if (isset($args['tooltip']) && !empty($args['tooltip'])) {
                $content = "<a href='#' class='tooltip hint--left' data-hint='" . wp_strip_all_tags($args['tooltip']) . "'><span class='dashicons dashicons-info'></span></a>";
                $script = '$( "' . $content . '" ).prependTo( "#customize-control-' . $args['settings'] . '" );';
            }
            self::$tooltip_script .= $script;
        }

Usage Example

コード例 #1
0
ファイル: class-kirki-init.php プロジェクト: aristath/kirki
 /**
  * Create the settings and controls from the $fields array and register them.
  *
  * @var	object	The WordPress Customizer object
  * @return  void
  */
 public function add_fields()
 {
     global $wp_customize;
     foreach (Kirki::$fields as $args) {
         if (isset($args['type']) && 'background' === $args['type']) {
             continue;
         }
         // Create the settings.
         new Kirki_Settings($args);
         // Check if we're on the customizer.
         // If we are, then we will create the controls, add the scripts needed for the customizer
         // and any other tweaks that this field may require.
         if ($wp_customize) {
             // Create the control.
             new Kirki_Control($args);
             // Create the scripts for tooltips.
             Kirki_Scripts_Tooltips::generate_script($args);
         }
     }
 }