• Home
  • Pricing
  • Free Resources
  • About
  • Docs
  • Support
  • Account

Gravity Wiz

Magically enhanced tutorials, snippets and plugins for Gravity Forms!

  • Gravity Perks
    • Gravity Perks
    • Pricing
  • Blog
    • Free Resources
    • About
  • Support
    • Docs
    • Support
    • Account

gpqr_file_content

  1. Description
  2. Usage
  3. Parameters
  4. Examples
    1. Customize QR code styling.
  5. Since

Description

Filters the content of the QR code file. This is the raw content of the file and is useful if the file format of the QR code is SVG.

Note: This filter is only available if generating QR code. Filtering the contents of barcodes is not supported at this time. Please reach out if this is something you need!

Usage

Filter generated QR code file contents for all forms.

add_filter( 'gpqr_file_content', 'my_custom_function' );

Filter generated QR code file contents for a specific form.

add_filter( 'gpqr_file_content_FORMID', 'my_custom_function' );

Parameters

  • content string

    File content represented as a UTF-8 string.

  • fg_hex string

    RGB hex to use for the foreground. Defaults to black.

  • bg_hex string

    RGB hex to use for the background. Defaults to white.

  • meta array

    Various meta information used to generate the QR code. Includes properties such as ‘error_correction_level’, ‘size’, ‘format’, and ‘form’.

Examples

Customize QR code styling.

Update QR codes to have rounded blocks and place a small logo in the center. Note, you will need to also use gpqr_params_pre_generate to generate QR codes as SVGs instead of PNGs.

To encode your image as base64, there are a variety of online solutions as well as ways to do it using CLI tools.

// https://gravitywiz.com/documentation/gpqr_params_pre_generate
add_filter( 'gpqr_params_pre_generate', function ( $params, $content ) {
	$params['format'] = 'svg';

        // Increase error correction level to get more reliable scans with a logo present.
	$params['error_correction_level'] = 'q';

	return $params;
}, 10, 2 );

add_filter( 'gpqr_file_content', function ( $content, $fg_hex, $bg_hex, $meta ) {
	if ( rgar( $meta, 'format' ) === 'svg' ) {
		// Overlay a logo on the QR code.
		$logo = '<image 
			x="75" 
			y="75" 
			xlink:href="data:image/png;base64,ENCODE_YOUR_LOGO_AS_BASE64_AND_PUT_IT_HERE" 
			width="50" 
			height="50"/>';

		$content = str_replace( '</svg>', $logo . '</svg>', $content );

		// Round the corners of each block in the QR code.
		$content = str_replace(
			'<rect id="r0" width="6" height="6" fill="' . $fg_hex . '"/>',
			'<rect id="r0" width="5.5" height="5.5" rx="5" ry="5" fill="' . $fg_hex . '"/>',
			$content
		);
	}

	return $content;
}, 10, 4 );

Example output when using this snippet (converted back to PNG):

Gravity Forms QR SVG Customization Example

Since

This filter is available since Gravity Forms QR Code 1.0.5.

All Perks

  • GF Address Autocomplete
  • GF Advanced Calculations
  • GF Advanced Phone Field
  • GF Advanced Save & Continue
  • GF Auto List Field
  • GF Auto Login
  • GF Better User Activation
  • GF Blocklist
  • GF Conditional Logic Dates
  • GF Conditional Pricing
  • GF Copy Cat
  • GF Date Time Calculator
  • GF Disable Entry Creation
  • GF Easy Passthrough
  • GF eCommerce Fields
  • GF Email Users
  • GF Entry Blocks
  • GF Expand Textareas
  • GF File Renamer
  • GF File Upload Pro
  • GF Google Sheets
  • GF Inventory
  • GF Limit Checkboxes
  • GF Limit Choices
  • GF Limit Dates
  • GF Limit Submissions
  • GF Live Preview
  • GF Media Library
  • GF Multi-Page Navigation
  • GF Nested Forms
  • GF Notification Scheduler
  • GF Page Transitions
  • GF Pay Per Word
  • GF PayPal One-time Fee
  • GF Placeholder
  • GF Populate Anything
  • GF Post Content Merge Tags
  • GF Preview Submission
  • GF Price Range
  • GF QR Code
  • GF Randomizer
  • GF Read Only
  • GF Reload Form
  • GF Terms Of Service
  • GF Unique ID
  • GF Word Count

Copyright © 2023 · Powered by WordPress · Gravity Wiz LLC

  • Support
  • Affiliates
  • About
  • Sitemap
  • Terms & Conditions of Use
  • Privacy Policy
  • Cookies Policy