Site icon Hip-Hop Website Design and Development

Choice worth not get saved within the database

I am attempting to place up a easy plugin, however this Settings API would not give me a break.

I’ve one discipline registered within the settings web page, however the values we enter do not get saved to the database.

Right here is the code I’ve put collectively up to now. Any assist is very appreciated

<?php


if(is_admin()){
    add_action( 'admin_menu', 'my_plugin_menu' );
    add_action( 'admin_init', 'register_mysettings' );
}

perform register_mysettings() { 

    register_setting( 'purchase-history-grid', 'num_of_columns' );

    add_settings_section(
        'plugin_section',
        __( 'The Grid', 'wordpress' ),
        'settings_section_callback',
        'purchase-history-grid'
    );

    add_settings_field(
        'num_of_columns',
        'Variety of Columns',
        'show_num_of_cols',
        'purchase-history-grid',
        'plugin_section'
    );

  }



perform my_plugin_menu() {
    add_options_page( 'Buy Historical past Grid', 'Buy Historical past Grid', 'manage_options', 'purchase-history-grid', 'my_plugin_options' );
}


perform my_plugin_options() {
    if ( !current_user_can( 'manage_options' ) )  {
        wp_die( __( 'You would not have ample permissions to entry this web page.' ) );
    }

    ?>
    <div class="wrap">
        <h2>Buy Historical past Grid by SolutionsW3</h2>
        <kind technique="post" motion="options.php"> 

    <?php

        settings_fields( 'purchase-history-grid' );
        do_settings_sections( 'purchase-history-grid' );

        submit_button(); 

    ?>

    </kind> 
    </div>

<?php

}

perform show_num_of_cols() {

    // get the worth of the setting we have registered with register_setting()
    $setting = get_option('num_of_cols');

    // output the sphere
    ?>
    <enter kind="text" id="num_of_cols" identify="num_of_cols" worth="<?php echo isset( $setting ) ? esc_attr( $setting ) : ''; ?>">
    <?php
}

perform settings_section_callback(  ) {
    echo __( 'Please configure the grid right here', 'wordpress' );
}

?>