Forum Replies Created

Viewing 6 posts - 1 through 6 (of 6 total)
  • Author
    Posts
  • stham
    Member

    Thank you so much Steve.

    in reply to: Uploader field only saves one file instead of multiple #8840
    stham
    Member

    Thanks so much, Steve! Works like a dream now.

    stham
    Member

    Solved it! But I’ll explain here in case it might help someone else out. I basically referred to the validate_email function in class-piklist-validate.php (line 992) to do it.

    There are 5 parameters, not 3 – $index, $value, $options, $field, $fields. Based on the documentation, these parameters are:

    @param int $index The field index being checked.
    @param mixed $value The value of the field.
    @param array $options The options.
    @param array $field The field object.
    @param array $fields Collection of fields.

    So my code now looks like this:

    function smm_validate_single_choice( $index, $value, $options, $field, $fields ) {
    
    	if ( is_array( $value ) ) {
    		$value = $value[0];
    	}
    	return ( array_key_exists( (string) $value, $field['choices'] ) ) ? true : __( 'does not have a valid selection.', 'smm' );
    
    }
    stham
    Member

    Hi Steve,

    Thanks for the response. I finally managed to get everything working.

    From within register_activation_hook, I put together an array (based on the same format that I discovered in the wp_option table) and used update_option to save it. The values then showed up perfectly in the settings page.

    $defaults = array(
      'my_addmore_field_1' => array( 'Swimming Pool', 'Gym' ),
      'my_addmore_field_2' => array( 'Lorem', 'Ipsum' )
    );
    update_option( 'my_option', $defaults );

    But the defaults are a good idea too. Will keep that in mind for future reference.

    Thanks again!

    stham
    Member

    Oops! Made a big mistake in my earlier response. The data IS saved with update_option(), not using transients as I previously thought.

    Sorry for the confusion. Been staring at codes for too many hours I think.

    stham
    Member

    Thank you, Jason and bicho44. Those pointers were very helpful.

    After some more digging into the database, here’s what I found (in case it might help someone else):
    1. The add-mores are stored serialized.
    2. The data is stored using set_transient() based on their option_name in the wp_option table.
    3. An array of all the fields is passed through serialize() and md5(), and the resulting string forms part of the transient name.

    I haven’t quite gotten everything to work yet but I hope I’m on the right track.

    Attachments:
    You must be logged in to view attached files.
Viewing 6 posts - 1 through 6 (of 6 total)