Keep up to date with Gravity PDF

  • This field is for validation purposes and should be left unchanged.

Jump To Section

Description #description

The Gravity PDF data class is a simple storage device for Gravity PDF data during the current PHP call – it’s not persistent like a database. It uses PHP’s class overloading feature to dynamically set and get variables that we can access throughout all classes in our plugin.

Version #version

This method was introduced in Gravity PDF 4.0.

Return #return

\GFPDF\Helper\Helper_Data | object
The data class

Usage #usage

This snippet shows how to access any data Gravity PDF stored in our data class:

add_action( 'init', function() {
    if ( class_exists( 'GPDFAPI' ) ) {
        /* Get Gravity PDF data class */
        $data = GPDFAPI::get_data_class();

        /* Access the PDF working directory (i.e where the user template files are stored) */
        $working_directory_path = $data->template_location;
        $working_directory_url  = $data->template_location_url;
    }
} );

You can also store your own data and use it later:

add_action( 'init', function() {
    if ( class_exists( 'GPDFAPI' ) ) {
        /* Get Gravity PDF data class */
        $data = GPDFAPI::get_data_class();

        /* Set our own plugin data */
        $data->prefix_custom_field       = 'My Custom Field Info';
        $data->prefix_custom_field_array = array( 1, 2, 3 );
        $data->prefix_custom_field_class = new StdClass();
    }
} );

Source Code #source-code

This method is located in api.php and the data class can be found in src/helper/Helper_Data.php

Signup for the latest Gravity PDF news, tips and updates

  • This field is for validation purposes and should be left unchanged.
Scroll To Top