0

I've been using the WordPress Option Page Generator by Jeremy Hixon to help give me a head start with my plugin's option page. I've laid out four different types of checkboxes which the source code can be found here:

https://gist.github.com/factmaven/3896a3aac3888aa5bcddae48d9da5238

However, I'd like to add additional checkboxes in each of the four section that I've made, like so:

Expected result: grouping checkboxes into sections

Based on the generator, it looks like I would need to add another add_settings_field and another callback function to add more checkboxes; but that looks more tedious than I'd imagine just to add more checkboxes under each section. Is it possible to add additional checkboxes underneath the add_settings_field that I've already created? For example:

public function personal_options_0_callback() {
    printf(
        '<input type="checkbox" name="profile_settings_option_name[personal_options_0]" id="personal_options_0" value="personal_options_0" %s> <label for="personal_options_0"> Visual Editor</label>',
        ( isset( $this->profile_settings_options['personal_options_0'] ) && $this->profile_settings_options['personal_options_0'] === 'personal_options_0' ) ? 'checked' : ''
    );
    printf(
        '<input type="checkbox" name="profile_settings_option_name[personal_options_1]" id="personal_options_1" value="personal_options_1" %s> <label for="personal_options_1"> Admin Color Scheme</label>',
        ( isset( $this->profile_settings_options['personal_options_1'] ) && $this->profile_settings_options['personal_options_1'] === 'personal_options_1' ) ? 'checked' : ''
    );
}

Any help or guidance is appreciated. I've never made a plugin options page before, so if there is a simpler way of doing this, I am also open to your recommendation. Thanks.

1 Answer 1

0

As discussed in the WordPress Support Forums, in some instances, it's easier to develop an array which stores the value value.

To group the checkboxes, I simply copied the same format from the Discussion settings page to get my expected result: a group of checkboxes that are formatted using WordPress' native style. Here's a good template to work off of:

<div class="wrap">
    <h1>Profile Settings</h1>

    <form method="post" action="action_here">
        <table class="form-table">
            <tbody>
                <tr>
                    <th scope="row">Personal Options</th>
                    <td>
                        <fieldset>
                            <legend class="screen-reader-text"><span>Personal Options</span></legend>
                            <label for="rich_editing">
                            <input name="rich_editing" type="checkbox" value="rich_editing" />
                            Visual Editor</label>
                            <br>
                            <label for="admin_color">
                            <input name="admin_color" type="checkbox" value="admin_color" />
                            Admin Color Scheme</label>
                            <br>
                            <label for="comment_shortcuts">
                            <input name="comment_shortcuts" type="checkbox" value="comment_shortcuts" />
                            Keyboard Shortcuts</label>
                            <br>
                            <label for="admin_bar_front">
                            <input name="admin_bar_front" type="checkbox" value="admin_bar_front" />
                            Toolbar</label>
                            <br>
                        </fieldset>
                    </td>
                </tr>
                <tr>
                    <th scope="row">Name</th>
                    <td>
                        <fieldset>
                            <legend class="screen-reader-text"><span>Name</span></legend>
                            <label for="first_name">
                            <input name="first_name" type="checkbox" value="first_name" />
                            First Name</label>
                            <br>
                            <label for="last_name">
                            <input name="last_name" type="checkbox" value="last_name" />
                            Last Name</label>
                            <br>
                            <label for="nickname">
                            <input name="nickname" type="checkbox" value="nickname" />
                            Nickname</label>
                            <br>
                            <label for="display_name">
                            <input name="display_name" type="checkbox" value="display_name" />
                            Display Name</label>
                            <br>
                        </fieldset>
                    </td>
                </tr>
            </tbody>
        </table>
        <?php submit_button(); ?>
    </form>
</div>

Result

enter image description here

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge that you have read and understand our privacy policy and code of conduct.

Not the answer you're looking for? Browse other questions tagged or ask your own question.