Last active
September 14, 2015 18:47
-
-
Save thiagolcks/c4458330cc3b0d22ad96 to your computer and use it in GitHub Desktop.
Class to help create fields with WP Settings API
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
<?php | |
if ( ! class_exists( 'Z_Settings_Fields' ) ) { | |
class Z_Settings_Fields { | |
public function text( $args = array() ) { | |
$value = esc_attr( get_option( $args['id'] ) ); | |
// Note the ID and the name attribute of the element should match that of the ID in the call to add_settings_field | |
$html = '<input type="text" class="regular-text" id="' . $args['id'] . '" name="' . $args['id'] . '" value="' . $value . '" />'; | |
if ( $args['description'] ) $html .= '<p class="description"> ' . $args['description'] . '</p>'; | |
echo $html; | |
} | |
public function textarea( $args = array() ) { | |
$value = esc_textarea( get_option( $args['id'] ) ); | |
// Note the ID and the name attribute of the element should match that of the ID in the call to add_settings_field | |
$html = '<textarea class="large-text code" id="' . $args['id'] . '" name="' . $args['id'] . '" rows="10">' . $value . '</textarea>'; | |
if ( $args['description'] ) $html .= '<p class="description"> ' . $args['description'] . '</p>'; | |
echo $html; | |
} | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment