Easy Digital Downloads
  • Package
  • Function
  • Tree

Packages

  • EDD
    • Admin
      • Actions
      • Add-ons
      • Dashboard
      • Discounts
      • Downloads
      • Export
      • Notices
      • Pages
      • Payments
      • Reports
      • Settings
      • System
      • Upgrades
      • Upload
      • Welcome
    • Cart
    • Checkout
    • Classes
      • API
      • Fees
      • HTML
      • Roles
      • Session
    • Emails
    • Functions
      • AJAX
      • Compatibility
      • Errors
      • Formatting
      • Install
      • Login
      • Taxes
      • Templates
    • Gateways
    • Logging
    • Payments
    • Shortcodes
    • Widgets

Functions

  • edd_clear_errors
  • edd_get_errors
  • edd_print_errors
  • edd_set_error
  • edd_unset_error
  1 <?php
  2 /**
  3  * Error Tracking
  4  *
  5  * @package     EDD
  6  * @subpackage  Functions/Errors
  7  * @copyright   Copyright (c) 2013, Pippin Williamson
  8  * @license     http://opensource.org/licenses/gpl-2.0.php GNU Public License
  9  * @since       1.0
 10  */
 11 
 12 // Exit if accessed directly
 13 if ( ! defined( 'ABSPATH' ) ) exit;
 14 
 15 
 16 /**
 17  * Print Errors
 18  *
 19  * Prints all stored errors. For use during checkout.
 20  * If errors exist, they are returned.
 21  *
 22  * @since 1.0
 23  * @uses edd_get_errors()
 24  * @uses edd_clear_errors()
 25  * @return void
 26  */
 27 function edd_print_errors() {
 28     $errors = edd_get_errors();
 29     if ( $errors ) {
 30         $classes = apply_filters( 'edd_error_class', array(
 31             'edd_errors'
 32         ) );
 33         echo '<div class="' . implode( ' ', $classes ) . '">';
 34             // Loop error codes and display errors
 35            foreach ( $errors as $error_id => $error ){
 36                 echo '<p class="edd_error" id="edd_error_' . $error_id . '"><strong>' . __('Error', 'edd') . '</strong>: ' . $error . '</p>';
 37            }
 38         echo '</div>';
 39         edd_clear_errors();
 40     }
 41 }
 42 add_action( 'edd_payment_mode_bottom', 'edd_print_errors' );
 43 add_action( 'edd_before_purchase_form', 'edd_print_errors' );
 44 add_action( 'edd_before_checkout_register_form', 'edd_print_errors' );
 45 add_action( 'edd_ajax_checkout_errors', 'edd_print_errors' );
 46 
 47 /**
 48  * Get Errors
 49  *
 50  * Retrieves all error messages stored during the checkout process.
 51  * If errors exist, they are returned.
 52  *
 53  * @since 1.0
 54  * @uses EDD_Session::get()
 55  * @return mixed array if errors are present, false if none found
 56  */
 57 function edd_get_errors() {
 58     return EDD()->session->get( 'edd_errors' );
 59 }
 60 
 61 /**
 62  * Set Error
 63  *
 64  * Stores an error in a session var.
 65  *
 66  * @since 1.0
 67  * @uses EDD_Session::get()
 68  * @param int $error_id ID of the error being set
 69  * @param string $error_message Message to store with the error
 70  * @return void
 71  */
 72 function edd_set_error( $error_id, $error_message ) {
 73     $errors = edd_get_errors();
 74     if ( ! $errors ) {
 75         $errors = array();
 76     }
 77     $errors[ $error_id ] = $error_message;
 78     EDD()->session->set( 'edd_errors', $errors );
 79 }
 80 
 81 /**
 82  * Clears all stored errors.
 83  *
 84  * @since 1.0
 85  * @uses EDD_Session::set()
 86  * @return void
 87  */
 88 function edd_clear_errors() {
 89     EDD()->session->set( 'edd_errors', null );
 90 }
 91 
 92 /**
 93  * Removes (unsets) a stored error
 94  *
 95  * @since 1.3.4
 96  * @uses EDD_Session::set()
 97  * @param int $error_id ID of the error being set
 98  * @return void
 99  */
100 function edd_unset_error( $error_id ) {
101     $errors = edd_get_errors();
102     if ( $errors ) {
103         unset( $errors[ $error_id ] );
104         EDD()->session->set( 'edd_errors', $errors );
105     }
106 }
Easy Digital Downloads API documentation generated by ApiGen 2.8.0