Keep up to date with Gravity PDF

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

Jump To Section

Description #description

If you extend Gravity PDF, this methods allows you to easily display a message or error to the user in the WP Admin area. When using this class you’ll need to trigger the message/error before the admin_notices or network_admin_notices WordPress hooks.

Version #version

This method was introduced in Gravity PDF 4.0.

Return #return

\GFPDF\Helper\Helper_Notices | object
The notices class

Usage #usage

The following snippet shows you the usage of our notice class in a basic admin action your plugin might implement:

add_action( 'admin_init', function() {
    if ( class_exists( 'GPDFAPI' ) ) {
        /* Get Gravity PDF notice class */
        $notice = GPDFAPI::get_notice_class();

        /* Listen for one of your plugin's actions and verify the current user can perform it */
        if ( isset( $_POST['prefix_plugin_action'] ) ) {

            /* Verify the current user has the correct capabilities to run the action */
            if ( ! current_user_can( 'activate_plugins' ) ) {
                $notice->add_error( __( 'Access denied', 'prefix-text-domain' ) );

            /* Check the nonce to prevent XSS attacks */
            if ( ! wp_verify_nonce( $_POST['prefix_plugin_action'], 'prefix_plugin_action' ) ) {
                $notice->add_error( __( 'There was a problem processing the action.', 'prefix-text-domain' ) );

            /* User passed all authentication checks so lets process the action */
            // Include any action code here

            /* Action was successful so lets tell the user */
            $notice->add_notice( __( 'Action successful.', 'prefix-text-domain' ) );

} );

Source Code #source-code

This method is located in api.php and the notice class can be found in src/helper/Helper_Notices.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