Show Page Name in Form Editor

Gravity Wiz

Code

Filename: gw-show-page-name-in-form-editor.php

<?php
/**
 * Gravity Wiz // Gravity Forms // Show Page Name in Form Editor
 *
 * Plugin Name: Gravity Wiz - Show Page Name in Form Editor
 * Description: If a page has a name, use it instead of `PAGE BREAK`.
 * Plugin URI:   https://gravitywiz.com/
 * Author:       Gravity Wiz
 * Version:      1.0.1
 * Author URI:   https://gravitywiz.com
 *
 * Installation:
 *  * Install as a plugin or a snippet per https://gravitywiz.com/documentation/how-do-i-install-a-snippet/
 *
 * Limitations:
 *  It does not replace the first page's name as it's not filterable.
 */
add_filter( 'gform_field_content', function ( $field_content, $field, $value, $entry_id, $form_id ) {
	if ( ! GFCommon::is_form_editor() ) {
		return $field_content;
	}

	if ( $field->type !== 'page' ) {
		return $field_content;
	}

	$form        = GFAPI::get_form( $form_id );
	$page_fields = GFAPI::get_fields_by_type( $form, 'page' );

	$page_index = array_search( $field->id, array_column( $page_fields, 'id' ) );
	$page_name  = rgar( $form['pagination']['pages'], $page_index + 1 );

	if ( rgblank( $page_name ) ) {
		return $field_content;
	}

	return str_replace( 'PAGE BREAK', strtoupper( $page_name ), $field_content );
}, 10, 5 );

Leave a Reply

Your email address will not be published. Required fields are marked *

  • Trouble installing this snippet? See our troubleshooting tips.
  • Need to include code? Create a gist and link to it in your comment.
  • Reporting a bug? Provide a URL where this issue can be recreated.

By commenting, I understand that I may receive emails related to Gravity Wiz and can unsubscribe at any time.