options_inputs = $inputs;
}
/**
* Generates the HTML output of an input control, based on the passed options.
*
* @param array $options The options to base the input on.
* @param string $parent_option The parent option, used for grouped inputs. Optional.
*
* @return string The HTML output.
*/
public function generate_options_input( array $options, $parent_option = '' ) {
$output = '';
foreach ( $options as $option => $option_values ) {
// Skip empty options.
if ( empty( $option_values ) ) {
continue;
}
// Check for support of the current WordPress version.
if ( \array_key_exists( 'version', $option_values ) && \version_compare( \get_bloginfo( 'version' ), $option_values['version'] ) < 0 ) {
continue;
}
if ( \array_key_exists( 'sub_options', $option_values ) ) {
$output .= $this->generate_options_input( $option_values['sub_options'], $option );
continue;
}
// If callback, call it.
if ( \array_key_exists( 'callback', $option_values ) ) {
$output .= $this->{$option_values['callback']}();
continue;
}
if ( ! \array_key_exists( 'type', $option_values ) ) {
continue;
}
$id = ( \array_key_exists( 'id', $option_values ) ? $option_values['id'] : $this->prepare_input_id( $option ) );
if ( $parent_option !== '' ) {
$id = \sprintf( '%s-%s', $this->prepare_input_id( $parent_option ), $id );
$option = \sprintf( '%s[%s]', $parent_option, $option );
}
switch ( $option_values['type'] ) {
case 'checkbox':
$output .= $this->options_inputs->checkbox(
$option,
$option_values['value'],
$id,
$this->is_checked( $option, $option_values, $parent_option )
);
$output .= \sprintf( '', $id, \esc_html( $option_values['label'] ) );
break;
case 'text':
$output .= $this->options_inputs->text( $option, $option_values['value'], $id );
break;
case 'number':
$output .= $this->options_inputs->number( $option, $option_values['value'], $id );
break;
}
if ( \array_key_exists( 'description', $option_values ) ) {
$output .= ' ' . $this->extract_description( $option_values['description'], $id );
}
$output .= ' ';
}
return $output;
}
/**
* Sorts taxonomy objects based on being public, followed by being private
* and when the visibility is equal, on the taxonomy public name (case-sensitive).
*
* @param WP_Taxonomy $taxonomy1 First taxonomy object.
* @param WP_Taxonomy $taxonomy2 Second taxonomy object.
*
* @return int An integer less than, equal to, or greater than zero indicating respectively
* the first taxonomy should be sorted before, at the same level or after the second taxonomy.
*/
public function sort_taxonomy_objects( $taxonomy1, $taxonomy2 ) {
if ( $taxonomy1->public === true && $taxonomy2->public === false ) {
return -1;
}
elseif ( $taxonomy1->public === false && $taxonomy2->public === true ) {
return 1;
}
// Same visibility, sort by name.
return \strnatcmp( $taxonomy1->labels->name, $taxonomy2->labels->name );
}
/**
* Extracts and formats the description associated with the input field.
*
* @param string|array $description The description string. Can be an array of strings.
* @param string $id The ID of the input field.
*
* @return string The description HTML for the input.
*/
public function extract_description( $description, $id ) {
if ( ! \is_array( $description ) ) {
return \sprintf( '(%s)', $id, \esc_html( $description ) );
}
return \sprintf( '