|
<?php |
|
function register_my_setting() { |
|
register_setting( 'my_options_group', 'my_option_name', 'intval' ); |
|
} |
|
add_action( 'admin_init', 'register_my_setting' ); |
|
?> |
|
<?php |
|
add_action( 'admin_menu', 'hub_add_admin_menu' ); |
|
add_action( 'admin_init', 'hub_settings_init' ); |
|
|
|
|
|
function hub_add_admin_menu( ) { |
|
|
|
add_menu_page( 'hub', 'Product Settings', 'manage_options', 'hub', 'hub_options_page','dashicons-tag' ); |
|
|
|
} |
|
|
|
|
|
function hub_settings_init( ) { |
|
|
|
register_setting( 'pluginPage', 'hub_settings' ); |
|
|
|
add_settings_section( |
|
'hub_pluginPage_section', |
|
__( 'Enter Quantity Discounts', 'wordpress' ), |
|
'hub_settings_section_callback', |
|
'pluginPage' |
|
); |
|
|
|
add_settings_field( |
|
'hub_text_field_0', |
|
__( 'Discount Percentage when quantity is 1', 'wordpress' ), |
|
'hub_text_field_0_render', |
|
'pluginPage', |
|
'hub_pluginPage_section' |
|
); |
|
|
|
add_settings_field( |
|
'hub_text_field_1', |
|
__( 'Discount Percentage when quantity is 2', 'wordpress' ), |
|
'hub_text_field_1_render', |
|
'pluginPage', |
|
'hub_pluginPage_section' |
|
); |
|
|
|
add_settings_field( |
|
'hub_text_field_2', |
|
__( 'Discount Percentage when quantity is 3', 'wordpress' ), |
|
'hub_text_field_2_render', |
|
'pluginPage', |
|
'hub_pluginPage_section' |
|
); |
|
|
|
add_settings_field( |
|
'hub_text_field_3', |
|
__( 'Discount Percentage when quantity is 4 or more', 'wordpress' ), |
|
'hub_text_field_3_render', |
|
'pluginPage', |
|
'hub_pluginPage_section' |
|
); |
|
|
|
|
|
} |
|
|
|
|
|
function hub_text_field_0_render( ) { |
|
|
|
$options = get_option( 'hub_settings' ); |
|
?> |
|
<input type='text' name='hub_settings[hub_text_field_0]' value='<?php echo $options['hub_text_field_0']; ?>'> |
|
<?php |
|
|
|
} |
|
|
|
|
|
function hub_text_field_1_render( ) { |
|
|
|
$options = get_option( 'hub_settings' ); |
|
?> |
|
<input type='text' name='hub_settings[hub_text_field_1]' value='<?php echo $options['hub_text_field_1']; ?>'> |
|
<?php |
|
|
|
} |
|
|
|
|
|
function hub_text_field_2_render( ) { |
|
|
|
$options = get_option( 'hub_settings' ); |
|
?> |
|
<input type='text' name='hub_settings[hub_text_field_2]' value='<?php echo $options['hub_text_field_2']; ?>'> |
|
<?php |
|
|
|
} |
|
|
|
|
|
function hub_text_field_3_render( ) { |
|
|
|
$options = get_option( 'hub_settings' ); |
|
?> |
|
<input type='text' name='hub_settings[hub_text_field_3]' value='<?php echo $options['hub_text_field_3']; ?>'> |
|
<?php |
|
|
|
} |
|
|
|
|
|
function hub_settings_section_callback( ) { |
|
|
|
echo __( 'The Discount Amount for each quantity', 'wordpress' ); |
|
|
|
} |
|
|
|
|
|
function hub_options_page( ) { |
|
|
|
?> |
|
<form action='options.php' method='post'> |
|
|
|
<h2>Product Discounts</h2> |
|
|
|
<?php |
|
settings_fields( 'pluginPage' ); |
|
do_settings_sections( 'pluginPage' ); |
|
submit_button(); |
|
?> |
|
</form> |
|
<?php |
|
|
|
} |
|
|
|
?> |