Forked from n7studios/gravity-forms-move-progress-bar-bottom.php
Last active
October 23, 2023 15:32
-
-
Save spivurno/82bc0fd1d9dc88c0c0a5a1019b6ed277 to your computer and use it in GitHub Desktop.
Gravity Forms - Move Progress Bar to Bottom of Form
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
/** | |
* Plugin Name: Gravity Forms: Move Progress Bar to Bottom of Form | |
* Plugin URI: http://www.n7studios.co.uk | |
* Version: 1.0.1 | |
* Author: n7 Studios | |
* Author URI: http://www.n7studios.co.uk | |
* Description: Moves the progress bar from the top to the bottom of the Gravity Form. The Start Paging section of the form MUST have a CSS class = progress-bar-bottom | |
*/ | |
/** | |
* Moves the progress bar from the top to the bottom of the Gravity Form | |
* if the Start Paging section of the form has a CSS class = progress-bar-bottom | |
* | |
* @param string $form_string Form HTML | |
* @param array $form Gravity Form Configuration | |
* | |
* @return string Form HTML | |
* @since 1.0.1 | |
* | |
*/ | |
function gravity_forms_move_progress_bar( $form_string, $form ) { | |
// Check if Pagination is enabled on this form | |
if ( ! is_array( $form['pagination'] ) ) { | |
return $form_string; | |
} | |
if ( empty( $form['pagination']['type'] ) ) { | |
return $form_string; | |
} | |
// Check if the first page CSS class is progress-bar-bottom | |
if ( ! isset( $form['firstPageCssClass'] ) ) { | |
return $form_string; | |
} | |
if ( $form['firstPageCssClass'] != 'progress-bar-bottom' ) { | |
return $form_string; | |
} | |
// If here, the progress bar needs to be at the end of the form | |
// Load form string into DOMDocument | |
$dom = new DOMDocument; | |
@$dom->loadHTML( $form_string ); | |
// Load Xpath | |
$xpath = new DOMXPath( $dom ); | |
// Find Progress Bar | |
$progress_bar = $xpath->query( '//div[@class="gf_progressbar_wrapper"]' )->item( 0 ); | |
if ( ! $progress_bar ) { | |
$progress_bar = $xpath->query( '//div[@class="gf_page_steps"]' )->item( 0 ); | |
} | |
// Find Form | |
$form = $xpath->query( '//form' )->item( 0 ); | |
// Move Progress Bar to end of the Form | |
$form->appendChild( $progress_bar ); | |
// Get HTML string | |
$form_string = $dom->saveHTML(); | |
// Return modified HTML string | |
return $form_string; | |
} | |
add_filter( 'gform_get_form_filter', 'gravity_forms_move_progress_bar', 10, 3 ); |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment