getViewId(); } // If we cannot determine the View ID, fail closed (no link). if ( $view_id <= 0 ) { return preg_replace( '/\{gview_edit_entry_link(?::[^}]*)?\}/', '', $text ); } // Replace ALL occurrences, supporting optional :Link Text. return preg_replace_callback( '/\{gview_edit_entry_link(?::([^}]+))?\}/', function ( $m ) use ( $entry, $view_id, $esc_html, $format ) { $link_text = isset( $m[1] ) && '' !== $m[1] ? trim( $m[1] ) : 'Edit Entry'; // Build the secure Edit Entry URL (includes nonce). $href = GravityView_Edit_Entry::get_edit_link( $entry, $view_id ); if ( empty( $href ) ) { return ''; } // Respect context. In "url" contexts, return only the URL. if ( 'url' === $format ) { return $href; } // Escape output safely. $href_esc = esc_url( $href ); // For HTML contexts, allow link text as plain text only. $text_esc = $esc_html ? esc_html( $link_text ) : wp_kses_post( $link_text ); return sprintf( '%s', $href_esc, $text_esc ); }, $text ); }, 10, 7 ); /** * Optional: Add the merge tag to Gravity Forms merge-tag dropdowns. * (This only affects GF UIs; GravityView Custom Content fields usually accept manual tags anyway.) */ add_filter( 'gform_custom_merge_tags', function ( $merge_tags ) { $merge_tags[] = [ 'label' => 'GravityView Edit Entry Link', 'tag' => '{gview_edit_entry_link}', ]; return $merge_tags; } );