array( * 'label' => __( 'Padding left', 'so-widgets-bundle' ), * 'units' => array( 'px', 'rem', 'em', '%' ), * ), * 'padding_right' => __( 'Padding right', 'so-widgets-bundle' ), * 'padding_bottom' => __( 'Padding bottom', 'so-widgets-bundle' ), * 'padding_top' => __( 'Padding top', 'so-widgets-bundle' ), * )` * * The 'units' property is optional and defaults to the list returned by `siteorigin_widgets_get_measurements_list`. * * @access protected * @var array */ protected $measurements; /** * String separator for the measurements. Default is an empty space. * * @access protected * @var string */ protected $separator; /** * Whether to automatically fill the rest of the inputs when the first value is entered. * Default is false. * * @access protected * @var boolean */ protected $autofill; protected function get_default_options() { return array( 'separator' => ' ', 'autofill' => false, ); } protected function render_field( $value, $instance ) { ?>
measurements as $name => $measurement_config ) { if ( is_array( $measurement_config ) ) { $label = empty( $measurement_config['label'] ) ? '' : $measurement_config['label']; } else { $label = $measurement_config; } $units = empty( $measurement_config['units'] ) ? siteorigin_widgets_get_measurements_list() : $measurement_config['units']; $input_id = $this->element_id . '-' . $name; ?>
separator, $value ); $any_values = false; foreach ( $values as $index => $measurement ) { $any_values = $any_values || ! empty( $measurement ); preg_match('/(\d+\.?\d*)([a-z%]+)*/', $measurement, $matches); $num_matches = count( $matches ); $val = $num_matches > 1 ? $matches[1] : '0'; $unit = $num_matches > 2 ? $matches[2] : 'px'; $measurement = $val . $unit; $values[ $index ] = $measurement; } // If all values are empty, just return an empty string. return $any_values ? implode( $this->separator, $values ) : ''; } }