From d66a9f7eceb8eaec2e2bf16f969b7266c301a30a Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Pablo=20dos=20Santos=20Gon=C3=A7alves=20Pacheco?= Date: Thu, 4 Oct 2018 01:24:07 -0300 Subject: [PATCH] Create a subsection field Now it will be possible to create a subsection field improving the organization ``` array( 'name' => 'subsection', 'label' => __( 'My subsection', 'remove-special-characters-from-permalinks' ), 'desc' => __( 'Now we can have a subsection description too ;)', 'remove-special-characters-from-permalinks' ), 'type' => 'subsection' ) ``` --- src/class.settings-api.php | 102 ++++++++++++++++++++++++++++++++++++- 1 file changed, 100 insertions(+), 2 deletions(-) diff --git a/src/class.settings-api.php b/src/class.settings-api.php index 7cfe4b3..16cd23c 100755 --- a/src/class.settings-api.php +++ b/src/class.settings-api.php @@ -521,7 +521,7 @@ function show_navigation() { } /** - * Show the section settings forms + * Show the section settings forms using a custom do_settings_sections() * * This function displays every sections in a different form */ @@ -534,7 +534,7 @@ function show_forms() { do_settings_sections( $form['id'] ); do_action( 'wsa_form_bottom_' . $form['id'], $form ); if ( isset( $this->settings_fields[ $form['id'] ] ) ): ?> @@ -652,6 +652,104 @@ function _style_fix() { '; + $this->do_settings_fields( $page, $section['id'] ); + echo ''; + } + } + + /** + * If there is a type == subsection, just call the call_user_func() instead of creating the tr + * + * @see \do_settings_fields() from template.php + * @param $page + * @param $section + */ + function do_settings_fields( $page, $section ) { + global $wp_settings_fields; + + if ( ! isset( $wp_settings_fields[ $page ][ $section ] ) ) { + return; + } + + foreach ( (array) $wp_settings_fields[ $page ][ $section ] as $field ) { + $class = ''; + + if ( $field['args']['type'] != 'subsection' ) { + if ( ! empty( $field['args']['class'] ) ) { + $class = ' class="' . esc_attr( $field['args']['class'] ) . '"'; + } + + echo ""; + + if ( ! empty( $field['args']['label_for'] ) ) { + echo ''; + } else { + echo '' . $field['title'] . ''; + } + + echo ''; + call_user_func( $field['callback'], $field['args'] ); + echo ''; + echo ''; + } else { + call_user_func( $field['callback'], $field['args'] ); + } + } + } + + /** + * Displays the html for a subsection field + * + * @param array $args settings field args + * @return string + */ + public function callback_subsection( $args ) { + if ( ! isset( $args['name'] ) ) { + return; + } + $subection = $args['name']; + if ( empty( $subection ) ) { + return; + } + if ( isset( $args['desc'] ) ) { + $desc = $args['desc']; + } + + ?> + +

+ +

+ + + +