option_group, $this->option_name );
}
/**
* Render fields.
*
* @param string $page Page to be rendered fields for.
* @param string $section_id ID of the section to render fields for.
* @param array $fields List of fields to render.
*
* @return bool True on success, false on failure.
*/
public function render_fields( $page, $section_id, $fields ) {
if ( empty( $fields ) ) {
return false;
}
foreach ( $fields as $field ) {
$args = isset( $field['args'] ) ? $field['args'] : [];
if ( ! isset( $args['label_for'] ) ) {
$args['label_for'] = $field['id'];
}
if ( ! isset( $args['description'] ) ) {
$args['description'] = $field['description'];
}
if ( isset( $field['options'] ) ) {
$args['options'] = $field['options'];
}
add_settings_field(
$field['id'],
$field['title'],
[ $this, $field['callback'] ],
$page,
$section_id,
$args
);
}
return true;
}
/**
* Helper to render select.
*
* @param array $args List of passed arguments.
*/
public function input_select( $args ) {
?>
= $args['description'] ?>
getOption( $args['label_for'] ) !== null ? 'checked="checked"' : '' ?>>
= $args['description'] ?>
= $args['description'] ?>
= $args['description'] ?>
alert_key, 'anycomment_message', __( 'Settings Saved', 'anycomment' ), 'updated' );
}
settings_errors( $this->alert_key );
?>
getOptions();
if ( $options === null ) {
return false;
}
$nonEmptyCount = 0;
foreach ( $options as $key => $optionValue ) {
if ( ! empty( $optionValue ) ) {
$nonEmptyCount ++;
}
}
return $nonEmptyCount > 0;
}
/**
* Get single option.
*
* @param string $name Options name to search for.
*
* @return mixed|null
*/
public function getOption( $name ) {
$options = $this->getOptions();
$optionValue = isset( $options[ $name ] ) ? trim( $options[ $name ] ) : null;
return ! empty( $optionValue ) ? $optionValue : null;
}
/**
* Get list of social options.
* @return array|null
*/
public function getOptions() {
if ( $this->options === null ) {
$this->options = get_option( $this->option_name, null );
}
if ( ! empty( $this->default_options ) ) {
foreach ( $this->default_options as $key => $optionValue ) {
$setDefault = ! isset( $this->options[ $key ] ) || isset( $this->options[ $key ] ) && empty( $this->options[ $key ] );
if ( $setDefault ) {
$this->options[ $key ] = $optionValue;
}
}
}
return $this->options;
}
/**
* Get instance of currently running class.
* @return self
*/
public static function instance() {
$className = get_called_class();
if ( ! isset( self::$_instances[ $className ] ) ) {
self::$_instances[ $className ] = new $className( false );
}
return self::$_instances[ $className ];
}
}
endif;