'std' doesn't work in settings page

Support General 'std' doesn't work in settings page

Viewing 3 posts - 1 through 3 (of 3 total)
  • Author
    Posts
  • #6972
    BBBB
    Participant

    When the value is set, it displays properly. But when I delete the value, std value doesn't work as expected. Please help.

    /**
     * Register Settings Pages
     */
    add_filter( 'mb_settings_pages', 'prefix_options_pages' );
    function prefix_options_pages( $settings_pages ) {
    	$settings_pages[] = array(
    		'id'            => 'my-options',
    		'option_name'   => 'my_options',
    		'menu_title'    => __( 'Theme Options', 'textdomain' ),
    		'submenu_title' => __( 'General', 'textdomain' ),
    	);
    }
    
    /**
     * Register Fields
     */
    add_filter( 'rwmb_meta_boxes', 'prefix_options_meta_boxes' );
    function prefix_options_meta_boxes( $meta_boxes ) {
    	$meta_boxes[] = array(
    		'id'             => 'general', // Metabox ID
    		'title'          => __( 'General', 'textdomain' ), // Metabox Title
    		'settings_pages' => 'my-options', // Settings Page ID
    		'fields'         => array(
    			array(
    				'id'    => 'test', // Field ID
    				'name'  => __( 'Test', 'liberstart' ), // Field Name
    				'type'  => 'text', // Field Type
    				'clone' => false,
    				'std'   => array( 'std test' ),
    			),
    		),
    	);
    }
    #6985
    Anh TranAnh Tran
    Keymaster

    Hi,

    The 'std' value works only the first time, e.g. when you haven't save any settings. In your case, if you delete the field value, then the plugin should "remember" your choice - whatever you did - which is the empty value in this case. It would be much confused if it shows the 'std' value, because two things: 1) you wonder where it comes from and 2) you can't actually save an empty value.

    #6993
    BBBB
    Participant

    Dear Anh,

    Thank you for your explanation, I have already built my own helper function to set a fallback value in case the field is empty.

    Br,
    Ba

Viewing 3 posts - 1 through 3 (of 3 total)
  • The topic ‘'std' doesn't work in settings page’ is closed to new replies.