I’ve this code for create setting web page for my plugin.
with this code , i present two subject in plugin setting for change model and set shadow on/off.
In model part i’ve 4 choice and i would like present new part with choices beneath model part if the second choice is chosen. commented in ode to higher perceive :
<?php
class my_Settings_Page {
public perform __construct() {
add_action( 'admin_menu', array( $this, 'my_create_settings' ) );
add_action( 'admin_init', array( $this, 'my_setup_sections' ) );
add_action( 'admin_init', array( $this, 'my_option_fields' ) );
}
public perform my_create_settings() {
$page_title = __('Web page Settings', 'my');
$menu_title = __('my Settings', 'my');
$functionality = 'manage_options';
$slug = 'my-settings';
$callback = array($this, 'my_settings_content');
$place = 2;
add_menu_page($page_title, $menu_title, $functionality, $slug, $callback, $place);
}
public perform my_settings_content() { ?>
<div class="wrap">
<h1 class="my-set"><?php esc_html_e( 'My Settings', 'my' ); ?></h1>
<?php settings_errors(); ?>
<type technique="POST" motion="options.php">
<?php
settings_fields( 'my-settings' );
do_settings_sections( 'my-settings' );
submit_button();
?>
</type>
</div> <?php
}
public perform my_setup_sections() {
add_settings_section( 'my_section', __('Description.', 'my' ), array(), 'my-settings' );
}
public perform my_option_fields() {
$fields = array(
// Fashion part
array(
'part' => 'my_section',
'label' => __('Fashion', 'my'),
'id' => 'stylemy',
'desc' => __('Select model of login web page', 'my'),
'sort' => 'choose',
'choices' => array(
__('Default', 'my'),
__('First', 'my'),
__('Second', 'my'),
__('Third', 'my'),
__('different', 'my'),
)
),
// if choice chosen ( First ) , present New part beneath Fashion part. i would like do that stay with out refresh web page.
// New part
array(
'part' => 'my_section',
'label' => __('Field 1', 'my'),
'id' => 'my-b1',
'desc' => __('This selection Description.', 'my'),
'sort' => 'checkbox',
)
);
foreach( $fields as $subject ){
add_settings_field( $subject['id'], $subject['label'], array( $this, 'my_field_callback' ), 'my-settings', $subject['section'], $subject );
register_setting( 'my-settings', $subject['id'] );
}
}
public perform my_field_callback( $subject ) {
$worth = get_option( $subject['id'] );
$placeholder = '';
if ( isset($subject['placeholder']) ) {
$placeholder = $subject['placeholder'];
}
change ( $subject['type'] ) {
case 'choose':
case 'multiselect':
if( ! empty ( $subject['options'] ) && is_array( $subject['options'] ) ) {
$attr = '';
$choices = '';
foreach( $subject['options'] as $key => $label ) {
$choices.= sprintf('<choice worth="%s" %s>%s</choice>',
$key,
chosen($worth, $key, false),
$label
);
}
if( $subject['type'] === 'multiselect' ){
$attr = ' a number of="multiple" ';
}
printf( '<choose title="%1$s" id="%1$s" %2$s>%3$s</choose>',
$subject['id'],
$attr,
$choices
);
}
break;
case 'checkbox':
printf('<enter %s id="%s" title="%s" sort="checkbox" worth="1">',
$worth === '1' ? 'checked' : '',
$subject['id'],
$subject['id']
);
break;
default:
printf( '<enter title="%1$s" id="%1$s" sort="%2$s" placeholder="%3$s" worth="%4$s" />',
$subject['id'],
$subject['type'],
$placeholder,
$worth
);
}
if( isset($subject['desc']) ) {
if( $desc = $subject['desc'] ) {
printf( '<p class="description">%s </p>', $desc );
}
}
}
}
new my_Settings_Page();
above query like:
https://jsfiddle.internet/masoudnkh/fdnybuo5/