Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Create a WordPress style theme for the CMB2 options page. #35

Closed
krugazul opened this issue Mar 13, 2020 · 1 comment · Fixed by #40
Closed

Create a WordPress style theme for the CMB2 options page. #35

krugazul opened this issue Mar 13, 2020 · 1 comment · Fixed by #40
Assignees
Labels
enhancement New feature or request

Comments

@krugazul
Copy link
Contributor

Requirements

We need to style the CMB2 options page in the same style as the WordPress Theme Pages. We would also like the individual boxes to act like "tabs" as the appearance page does.

All functionality needs to be contained in 1 class in lsx-business-directory/classes/admin/class-settings-theme.php, as it will need to be ported over to the LSX Health Plan plugin afterwards.

The SCSS can be in a module of its own as well, included in the admin dashboard.

Development

1:) This is only to apply to the settings page, so you need to make sure you test the to make sure the current screen is the options_page.
lsx-business-directory/vendor/CMB2/includes/CMB2.php
do_action( 'cmb2_before_form', $this->cmb_id, $object_id, $object_type, $this );
OR
do_action( "cmb2_before_{$object_type}_form_{$this->cmb_id}", $object_id, $this );

You can also test for these URL params as they are unique edit.php?post_type=business-directory&page=lsx-business-directory-settings

2:) Use the above actions to run through the fields for output, and create a tabbed navigation Div, this will containt the links to trigger the tabs. Using the appearance of the tabbed navigation.

3:) Before the "title" field type output an opening div, which will house the "tab ID", and the opening div for the tab.
Action Location - lsx-business-directory/vendor/CMB2/includes/CMB2_Field.php - 834
do_action( 'cmb2_before_field_row', $this );
OR
do_action( "cmb2_before_{$field_type}_field_row", $this );

4a:) Lastly you will need to close each of the tab content divs. The easiest way to do this is to add a custom CMB2 field, which only outputs a ` 'title_close' which you can test for.

4b:) You will need to add the title_close to the end of all the settings, to mark where you want the box to "wrap". See the locations below, where you need to add in the title_close field.

5:) You will then need to add in the CSS for the navigation links (tabs headers) and the fields.

6:) You will need to add in some JS to handle the tab switching, this can be added to the admin_head action, as just a <script> output. We do not need an entire JS file just for that.

@jlaguma
Copy link

jlaguma commented Mar 16, 2020

Pull request for this enhancement: #40

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
enhancement New feature or request
Projects
None yet
2 participants