Support » Plugin: Seamless Donations is Sunset » Ordering fields in the form

  • Resolved nikdow

    (@nikdow)


    Writing my customisation plugin, any new fields I add to the array end up at the bottom.
    This is not convenient (e.g. “middle name”).
    So I have added this code:

    /*
         * order the supplied fields (so we can insert our new fields where we want)
         */
        $donor_section['elements']['donation_header']['order'] = 0;
        $donor_section['elements']['_dgx_donate_donor_first_name']['order'] = 1;
        $donor_section['elements']['_dgx_donate_donor_last_name']['order'] = 3;
        $donor_section['elements']['_dgx_donate_donor_email']['order'] = 4;
        $donor_section['elements']['_dgx_donate_add_to_mailing_list']['order'] = 55;
        $donor_section['elements']['_dgx_donate_donor_phone']['order'] = 6;
         /*
         * Fields we want to add
         */
        $donor_section['elements']['acp_donor_middle_name'] = array(
            'type'          => 'text',
            'size'          => 20,
            'before'        => 'Middle Name:',
            'order'         => 2,
        );
         /*
         * sort the fields
         */
        uasort($donor_section['elements'], function( $a, $b ){
            if ( $a['order'] === $b['order'] ) return 0;
            return ( $a['order'] < $b['order'] ? -1 : 1);
        });

    Is there a better way?

    https://wordpress.org/plugins/seamless-donations/

Viewing 1 replies (of 1 total)
  • Plugin Author David Gewirtz

    (@dgewirtz)

    In coding, there is always a better way. Usually, that’s an exercise for the programmer. Seriously, though, the key is to make sure you understand that when you reorder fields, you might be mucking with the field-associated CSS and that future updates to the plugin might make changes you’ll need to work around or update to accommodate.

    Finally, make sure that code is in a plugin and uses the callback hook so it doesn’t get nuked the next time I issue a plugin update.

    –David

Viewing 1 replies (of 1 total)
  • The topic ‘Ordering fields in the form’ is closed to new replies.