__construct( $vals );
}
/**
* Create our ADAuthInt_Option object
* @param array $vals an associative array of the properties to assign to this object
*/
function __construct( $vals ) {
if( !is_array( $vals ) )
return $vals;
$this->opt_name = $vals['opt_name'];
$this->opt_label = __( $vals['opt_label'], ADAUTHINT_TEXT_DOMAIN );
$this->opt_section = $vals['opt_section'];
if( array_key_exists( 'opt_choices', $vals ) && is_array( $vals['opt_choices'] ) )
$this->opt_choices = $vals['opt_choices'];
if( array_key_exists( 'opt_note', $vals ) && !empty( $vals['opt_note'] ) )
$this->opt_note = $vals['opt_note'];
$this->_format_values( $vals );
} /* __construct function */
function _format_values( $vals=array() ) {
switch( $vals['opt_type'] ) {
case 'int' :
$this->opt_default = (int)$vals['opt_default'];
$this->opt_value = (int)$vals['opt_val'];
$this->opt_type = 'int';
break; /* int */
case 'bool' :
$this->opt_default = (bool)$vals['opt_default'];
$this->opt_value = ( $vals['opt_val'] == 'true' || $vals['opt_val'] === true ) ? true : false;
$this->opt_type = 'bool';
break; /* bool */
case 'select' :
case 'password' :
case 'textarea' :
$this->opt_type = $vals['opt_type'];
default :
if( $vals['opt_val'] == 'NULL' )
$vals['opt_val'] = '';
$this->opt_default = (string)$vals['opt_default'];
$this->opt_value = (string)esc_attr( $vals['opt_val'] );
} /* End switch */
}
/**
* Add a new WordPress settings field for the admin options page
* @uses add_settings_field()
* @deprecated ADAuthInt_Plugin::init_admin performs this task instead
*/
function add_settings_field() {
add_settings_field(
/*$id =*/ $this->opt_name,
/*$title =*/ __( $this->opt_label, ADAUTHINT_TEXT_DOMAIN ),
/*$callback =*/ array( $this, 'build_field' ),
/*$page =*/ ADAUTHINT_OPTIONS_PAGE,
/*$section =*/ $this->opt_section,
/*$args =*/ array( 'label_for' => $this->opt_section . '_' . $this->opt_name )
);
return;
} /* add_settings_field function */
/**
* Build the option input field on our WordPress admin page
*/
function build_field() {
if( ADAI_IS_NETWORK_ACTIVE && is_network_admin() )
$options = get_site_option( $this->opt_section );
else
$options = get_option( $this->opt_section );
$options = maybe_unserialize( $options );
if( array_key_exists( $this->opt_name, $options ) ) {
$this->opt_value = $options[$this->opt_name];
switch( $this->opt_type ) {
case 'int' :
$this->opt_value = (int)$this->opt_value;
break; /* int */
case 'bool' :
$this->opt_value = ( $this->opt_value == 'true' || $this->opt_value === true ) ? true : false;
break; /* bool */
case 'password':
$this->opt_value = base64_decode( $this->opt_value );
case 'textarea':
$this->opt_value = esc_textarea( $this->opt_value );
case 'select' :
default :
if( $this->opt_value == 'NULL' )
$this->opt_value = '';
$this->opt_value = (string)stripslashes_deep( $this->opt_value );
} /* End switch */
}
$rt = '';
switch( $this->opt_type ) {
case 'bool': /* Generate a single checkbox */
$rt .= '
opt_value ) ? ' checked="checked"' : '' ) . '/>';
break;
case 'select': /* Generate a select element */
$rt .= '
';
break;
case 'textarea': /* Generate a textarea element */
$rt .= '
';
break;
default: /* Generate a text field for either an int or string */
$rt .= '
';
}
if( !empty( $this->opt_note ) ) {
$rt .= '