Update settings fields to use types instead of callbacks

This commit is contained in:
Robin Cornett
2019-05-18 15:31:50 -04:00
parent 8ed9cdb9a1
commit f80d4a65c7
6 changed files with 159 additions and 93 deletions
@@ -45,7 +45,7 @@ class Display_Featured_Image_Genesis_Helper extends DisplayFeaturedImageGenesisG
add_settings_field(
$field['id'],
sprintf( '<label for="%s-%s">%s</label>', $this->page, $field['id'], $field['title'] ),
array( $this, $field['callback'] ),
array( $this, 'do_field' ),
$this->page . '_' . $sections[ $field['section'] ]['tab'],
$this->page . '_' . $sections[ $field['section'] ]['id'],
$field
@@ -53,6 +53,40 @@ class Display_Featured_Image_Genesis_Helper extends DisplayFeaturedImageGenesisG
}
}
/**
* Generic field method.
*
* @param $field
*/
public function do_field( $field ) {
$callback = $this->get_callback( $field );
if ( is_callable( $callback ) ) {
call_user_func( $callback, $field );
}
if ( ! empty( $field['description'] ) ) {
$this->do_description( $field );
}
}
/**
* Get the correct method to output the field.
*
* @param $field
*
* @return array|bool
* @since 3.1.0
*/
private function get_callback( $field ) {
$callback = false;
if ( ! empty( $field['type'] ) ) {
$callback = "do_{$field['type']}";
} elseif ( ! empty( $field['callback'] ) ) {
$callback = $field['callback'];
}
return $callback ? array( $this, $callback ) : false;
}
/**
* Set which tab is considered active.
* @return string