Skip to main content
Version: 5

Gravity PDF API – add_plugin_option()


This method allows you to add a new global Gravity PDF setting. If the option key already exists a WP_Error is returned. Usually you'll want to call GPDFAPI::update_plugin_option() instead.


This method was introduced in Gravity PDF 4.0.


$key | string

  • The global PDF setting ID. Best to prefix this value to prevent conflict.

$value | mixed

  • Whatever value you want to store


boolean | WP_Error

  • True on success, false if database failed to update and WP_Error if the $key already exists.


The following snippet shows you how to add a new PDF global option and correctly handle any errors:

    add_action( 'init', function() {
if ( class_exists( 'GPDFAPI' ) ) {
$option = GPDFAPI::add_plugin_option( 'prefix_option_name', 'My Value' );

if( true === $option ) {
// Option Successfully Added
} elseif( is_wp_error( $option ) ) {
// Option key already exists
} else {
// There was a problem updating the database with your new option
} );

Source Code

This method is located in api.php.