Description
The gform_entry_detail_meta_boxes filter can be used to add custom meta boxes to the entry detail page.
Usage
add_filter( 'gform_entry_detail_meta_boxes', 'your_function_name', 10, 3 );
Parameters
| Parameter | Type | Description |
|---|---|---|
$meta_boxes | array | The properties for the meta boxes. The default array is defined like so: |
$entry | Entry Object | The entry currently being viewed/edited. |
$form | Form Object | The form object used to process the current entry. |
$meta_boxes = array(
'submitdiv' => array(
'title' => esc_html__( 'Entry', 'gravityforms' ),
'callback' => array( 'GFEntryDetail', 'meta_box_entry_info' ),
'context' => 'side',
),
'notifications' => array(
'title' => esc_html__( 'Notifications', 'gravityforms' ),
'callback' => array( 'GFEntryDetail', 'meta_box_notifications' ),
'context' => 'side',
),
);
If the user has the gravityforms_view_entry_notes capability then it will also contain the following:
$meta_boxes['notes'] = array(
'title' => esc_html__( 'Notes', 'gravityforms' ),
'callback' => array( 'GFEntryDetail', 'meta_box_notes' ),
'context' => 'normal',
);
If the entry has been processed by a payment add-on and the payment_status property is not empty then it will also contain the following:
$meta_boxes['payment'] = array(
'title' => $entry['transaction_type'] == 2 ? esc_html__( 'Subscription Details', 'gravityforms' ) : esc_html__( 'Payment Details', 'gravityforms' ),
'callback' => array( 'GFEntryDetail', 'meta_box_payment_details' ),
'context' => 'side',
'callback_args' => array( $entry, $form ),
);
Examples
Enable the Payment Details.
This example shows how you can enable the payment details panel when the form isn’t being used with a payment add-on.
add_filter( 'gform_entry_detail_meta_boxes', 'add_payment_details_meta_box', 10, 3 );
function add_payment_details_meta_box( $meta_boxes, $entry, $form ) {
if ( ! isset( $meta_boxes['payment'] ) ) {
$meta_boxes['payment'] = array(
'title' => esc_html__( 'Payment Details', 'gravityforms' ),
'callback' => array( 'GFEntryDetail', 'meta_box_payment_details' ),
'context' => 'side',
'callback_args' => array( $entry, $form ),
);
}
return $meta_boxes;
}
Add a User Registration Add-On meta box.
This example shows how you can add a meta box to the entry detail page to display the details of the user which was created from the entry. If a user does not exist for the entry it will show a button enabling feed processing to be triggered.
/**
* Add the meta box to the entry detail page.
*
* @param array $meta_boxes The properties for the meta boxes.
* @param array $entry The entry currently being viewed/edited.
* @param array $form The form object used to process the current entry.
*
* @return array
*/
function register_ur_meta_box( $meta_boxes, $entry, $form ) {
// If the add-on is active and the form has an active feed, add the meta box.
if ( function_exists( 'gf_user_registration' ) && gf_user_registration()->get_active_feeds( $form['id'] ) ) {
if ( gf_pending_activations()->is_entry_pending_activation( $entry ) ) {
return $meta_boxes;
}
$meta_boxes[ 'gf_user_registration' ] = array(
'title' => 'User Registration',
'callback' => 'add_ur_details_meta_box',
'context' => 'side',
);
}
return $meta_boxes;
}
add_filter( 'gform_entry_detail_meta_boxes', 'register_ur_meta_box', 10, 3 );
/**
* The callback used to echo the content to the meta box.
*
* @param array $args An array containing the form and entry objects.
*/
function add_ur_details_meta_box( $args ) {
$form = $args['form'];
$entry = $args['entry'];
$html = '';
$action = 'gf_user_registration_process_feeds';
// Retrieve the user from the current entry, if available.
$user = gf_user_registration()->get_user_by_entry_id( $entry['id'] );
if ( ! $user && rgpost( 'action' ) == $action ) {
check_admin_referer( 'gforms_save_entry', 'gforms_save_entry' );
// Because the entry doesn't already have a user and the 'Process Feeds' button was clicked process the feeds.
gf_user_registration()->maybe_process_feed( $entry, $form );
// Retrieve the user
$user = gf_user_registration()->get_user_by_entry_id( $entry['id'] );
$html .= 'Feeds Processed.</br></br>';
}
if ( ! $user ) {
// Add the 'Process Feeds' button.
$html .= sprintf( '<input type="submit" value="%s" class="button" onclick="jQuery(\'#action\').val(\'%s\');" />', 'Process Feeds', $action );
} else {
// Display some user details.
$html .= 'Username: ' . $user->user_login . '</br></br>';
$html .= 'User ID: ' . $user->ID;
}
echo $html;
}
Add a Partial Entries Add-On meta box.
This example shows how you can add a meta box to the entry detail page to display a button enabaling the partial entry to be marked as completed.
/**
* Add the meta box to the entry detail page and process the complete request.
*
* @param array $meta_boxes The properties for the meta boxes.
* @param array $entry The entry currently being viewed/edited.
* @param array $form The form object used to process the current entry.
*
* @return array
*/
function register_partial_entries_box( $meta_boxes, $entry, $form ) {
if ( class_exists( 'GF_Partial_Entries' ) ) {
$add_on = GF_Partial_Entries::get_instance();
if ( ! $add_on->is_enabled( $form['id'] ) ) {
return $meta_boxes;
}
$partial_entry_id = rgar( $entry, 'partial_entry_id' );
$action = 'gf_partial_entries_complete_entry';
if ( $partial_entry_id && rgpost( 'action' ) == $action ) {
check_admin_referer( 'gforms_save_entry', 'gforms_save_entry' );
$entry_id = $entry['id'];
gform_delete_meta( $entry_id, 'partial_entry_id' );
gform_delete_meta( $entry_id, 'date_saved' );
gform_delete_meta( $entry_id, 'resume_url' );
gform_delete_meta( $entry_id, 'resume_token' );
$entry = GFAPI::get_entry( $entry_id );
GFEntryDetail::set_current_entry( $entry );
return $meta_boxes;
}
if ( $partial_entry_id ) {
$meta_boxes['gf_partial_entries'] = array(
'title' => 'Partial Entries',
'callback' => 'add_partial_entries_meta_box',
'context' => 'side',
);
}
}
return $meta_boxes;
}
add_filter( 'gform_entry_detail_meta_boxes', 'register_partial_entries_box', 10, 3 );
/**
* The callback used to echo the content to the meta box.
*
* @param array $args An array containing the form and entry objects.
*/
function add_partial_entries_meta_box( $args ) {
$action = 'gf_partial_entries_complete_entry';
$html = sprintf( '<input type="submit" value="%s" class="button" onclick="jQuery(\'#action\').val(\'%s\');" />', 'Complete Entry', $action );
echo $html;
}
Placement
This code can be used in the functions.php file of the active theme, a custom functions plugin, a custom add-on, or with a code snippets plugin.
See also the PHP section in this article: Where Do I Put This Code?
Source Code
This filter is located in GFEntryDetail::add_meta_boxes() in entry_detail.php.
Since
This filter was added in Gravity Forms 2.0-beta-3.