Created
November 19, 2015 16:14
-
-
Save n7studios/f0b3ce229fa686ea0184 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
<?php | |
/** | |
* Plugin Name: Gravity Forms: Move Progress Bar to Bottom of Form | |
* Plugin URI: http://www.n7studios.co.uk | |
* Version: 1.0.0 | |
* 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 | |
* | |
* @since 1.0.0 | |
* | |
* @param string $form_string Form HTML | |
* @param array $form Gravity Form Configuration | |
* @return string Form HTML | |
*/ | |
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); | |
// 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', array( $this, '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
@decaySmash thank you for your comment
In my case works, when changing line 35 to