';
echo $this->get_field_description( $args );
}
/**
* Displays a file upload field for a settings field
*
* @param array $args settings field args
*/
public function callback_file( $args ) {
$value = esc_attr( $this->get_option( $args['id'], $args['section'], $args['std'] ) );
$size = isset( $args['size'] ) && ! is_null( $args['size'] ) ? $args['size'] : 'regular';
$id = $args['section'] . '[' . $args['id'] . ']';
$label = isset( $args['options']['button_label'] ) ? $args['options']['button_label'] : __( 'Choose File' );
$html = sprintf( '', $size, $args['section'], $args['id'], $value );
$html .= '';
$html .= $this->get_field_description( $args );
echo $html;
}
/**
* Displays a image upload field for a settings field
*
* @param array $args settings field args
*/
public function callback_image( $args ) {
$value = esc_attr( $this->get_option( $args['id'], $args['section'], $args['std'] ) );
$size = isset( $args['size'] ) && ! is_null( $args['size'] ) ? $args['size'] : 'regular';
$id = $args['section'] . '[' . $args['id'] . ']';
$label = isset( $args['options']['button_label'] ) ? $args['options']['button_label'] : __( 'Choose Image' );
$label_remove = isset( $args['options']['button_remove_label'] ) ? $args['options']['button_remove_label'] : __( 'Remove Image' );
$img = wp_get_attachment_image_src( $value, $args['size'] ? $args['size'] : 'thumbnail' );
$img_url = $img ? $img[0] : '';
$html = sprintf( '', $size, $id, $value );
$html .= '';
$html .= '';
$html .= '';
$html .= $this->get_field_description( $args );
echo $html;
}
/**
* Displays a password field for a settings field
*
* @param array $args settings field args
*/
public function callback_password( $args ) {
$value = esc_attr( $this->get_option( $args['id'], $args['section'], $args['std'] ) );
$size = isset( $args['size'] ) && ! is_null( $args['size'] ) ? $args['size'] : 'regular';
$html = sprintf( '', $size, $args['section'], $args['id'], $value );
$html .= $this->get_field_description( $args );
echo $html;
}
/**
* Displays a color picker field for a settings field
*
* @param array $args settings field args
*/
public function callback_color( $args ) {
$value = esc_attr( $this->get_option( $args['id'], $args['section'], $args['std'] ) );
$size = isset( $args['size'] ) && ! is_null( $args['size'] ) ? $args['size'] : 'regular';
$html = sprintf( '', $size, $args['section'], $args['id'], $value, $args['std'] );
$html .= $this->get_field_description( $args );
echo $html;
}
/**
* Displays a select box for creating the pages select box
*
* @param array $args settings field args
*/
public function callback_pages( $args ) {
$dropdown_args = array(
'selected' => esc_attr( $this->get_option( $args['id'], $args['section'], $args['std'] ) ),
'name' => $args['section'] . '[' . $args['id'] . ']',
'id' => $args['section'] . '[' . $args['id'] . ']',
'echo' => 0,
);
$html = wp_dropdown_pages( $dropdown_args );
echo $html;
}
/**
* Displays a toggle field for a settings field
*
* @param array $args settings field args.
*/
public function callback_toggle( $args ) {
$value = esc_attr( $this->get_option( $args['id'], $args['section'], $args['std'] ) );
$html = sprintf( '', $args['desc'] );
echo $html;
}
/**
* Displays a range field for a settings field
*
* @param array $args settings field args.
*/
public function callback_range( $args ) {
$value = esc_attr( $this->get_option( $args['id'], $args['section'], $args['std'] ) );
$size = isset( $args['size'] ) && ! is_null( $args['size'] ) ? $args['size'] : 'regular';
$type = isset( $args['type'] ) ? $args['type'] : 'range';
$placeholder = empty( $args['placeholder'] ) ? '' : ' placeholder="' . $args['placeholder'] . '"';
$min = empty( $args['min'] ) ? '' : ' min="' . $args['min'] . '"';
$max = empty( $args['max'] ) ? '' : ' max="' . $args['max'] . '"';
$step = empty( $args['max'] ) ? '' : ' step="' . $args['step'] . '"';
?>
',
esc_attr( $type ),
esc_attr( $size ),
esc_attr( $args['section'] ),
esc_attr( $args['id'] ),
esc_attr( $value ),
esc_attr( $placeholder ),
esc_attr( $min ),
esc_attr( $max ),
esc_attr( $step )
);
echo sprintf(
'',
esc_attr( $args['section'] ),
esc_attr( $args['id'] ),
esc_attr( $value ),
esc_attr( $placeholder ),
esc_attr( $min ),
esc_attr( $max ),
esc_attr( $step )
);
echo wp_kses_post( $this->get_field_description( $args ) );
?>
get_option( $args['id'], $args['section'], $args['std'] ) );
$size = isset( $args['size'] ) && ! is_null( $args['size'] ) ? $args['size'] : 'regular';
$type = isset( $args['type'] ) ? $args['type'] : 'hidden';
$placeholder = empty( $args['placeholder'] ) ? '' : ' placeholder="' . $args['placeholder'] . '"';
echo sprintf(
'',
esc_attr( $type ),
esc_attr( $size ),
esc_attr( $args['section'] ),
esc_attr( $args['id'] ),
esc_attr( $value ),
esc_attr( $placeholder )
);
echo wp_kses_post( $this->get_field_description( $args ) );
}
/**
* Sanitize callback for Settings API
*
* @return mixed
*/
public function sanitize_options( $options ) {
if ( ! $options ) {
return $options;
}
foreach ( $options as $option_slug => $option_value ) {
$sanitize_callback = $this->get_sanitize_callback( $option_slug );
// If callback is set, call it
if ( $sanitize_callback ) {
$options[ $option_slug ] = call_user_func( $sanitize_callback, $option_value );
continue;
}
}
return $options;
}
/**
* Get sanitization callback for given option slug
*
* @param string $slug option slug
*
* @return mixed string or bool false
*/
public function get_sanitize_callback( $slug = '' ) {
if ( empty( $slug ) ) {
return false;
}
// Iterate over registered fields and see if we can find proper callback
foreach ( $this->settings_fields as $section => $options ) {
foreach ( $options as $option ) {
if ( $option['name'] != $slug ) {
continue;
}
// Return the callback name
return isset( $option['sanitize_callback'] ) && is_callable( $option['sanitize_callback'] ) ? $option['sanitize_callback'] : false;
}
}
return false;
}
/**
* Get the value of a settings field
*
* @param string $option settings field name
* @param string $section the section name this field belongs to
* @param string $default default text if it's not found
* @return string
*/
public function get_option( $option, $section, $default = '' ) {
$options = get_option( $section );
if ( isset( $options[ $option ] ) ) {
return $options[ $option ];
}
return $default;
}
/**
* Show navigations as tab
*
* Shows all the settings section labels as tab
*/
public function show_navigation() {
$html = '
';
$count = count( $this->settings_sections );
// don't show the navigation if only one section exists
if ( $count === 1 ) {
return;
}
foreach ( $this->settings_sections as $tab ) {
$html .= sprintf( '%2$s%3$s', $tab['id'], isset( $tab['icon'] ) ? $tab['icon'] : '', $tab['title'] );
}
$html .= '
';
echo $html;
}
/**
* Tabbable JavaScript codes & Initiate Color Picker
*
* This code uses localstorage for displaying active tabs
*/
public function script() {
?>
script();
}
/**
* Prints out all settings sections added to a particular settings page
*
* Part of the Settings API. Use this in a settings page callback function
* to output all the sections and fields that were added to that $page with
* add_settings_section() and add_settings_field()
*
* @global array $wp_settings_sections Storage array of all settings sections added to admin pages.
* @global array $wp_settings_fields Storage array of settings fields and info about their pages/sections.
*
* @param string $page The slug name of the page whose settings sections you want to output.
*/
public function do_settings_sections( $page ) {
global $wp_settings_sections, $wp_settings_fields;
if ( ! isset( $wp_settings_sections[ $page ] ) ) {
return;
}
foreach ( (array) $wp_settings_sections[ $page ] as $section ) {
if ( $section['callback'] ) {
call_user_func( $section['callback'], $section );
}
if ( ! isset( $wp_settings_fields ) || ! isset( $wp_settings_fields[ $page ] ) || ! isset( $wp_settings_fields[ $page ][ $section['id'] ] ) ) {
continue;
}
echo '
';
}
}
/**
* Get the section settings form.
* This function return displays detailed section in a each of forms.
*
* @param array $form - Form item.
* @return string
*/
public function get_form( $form ) {
ob_start();
?>