1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138
<?php
/**
* Error Tracking
*
* @package EPL
* @subpackage Functions/ErrorTracking
* @copyright Copyright (c) 2020, Merv Barrett
* @license http://opensource.org/licenses/gpl-2.0.php GNU Public License
* @since 3.0
*/
// Exit if accessed directly.
if ( ! defined( 'ABSPATH' ) ) {
exit;
}
/**
* Print Errors
*
* @since 3.0
* @uses epl_get_errors()
* @uses epl_clear_errors()
* @return void
*/
function epl_print_errors() {
$errors = epl_get_errors();
if ( $errors ) {
$classes = apply_filters(
'epl_error_class',
array(
'epl_errors',
'epl-alert',
'epl-alert-error',
)
);
echo '<div class="' . wp_kses_post( implode( ' ', $classes ) ) . '">';
// Loop error codes and display errors.
foreach ( $errors as $error_id => $error ) {
echo '<p class="epl_error" id="epl_error_' . esc_attr( $error_id ) . '"><strong>' . esc_html__( 'Error', 'easy-property-listings' ) . '</strong>: ' . wp_kses_post( $error ) . '</p>';
}
echo '</div>';
epl_clear_errors();
}
}
/**
* Get Errors
*
* If errors exist, they are returned.
*
* @since 3.0
* @since 3.1.15 switched to EPL Session class for session handling.
* @return mixed array if errors are present, false if none found
*/
function epl_get_errors() {
$errors = EPL()->session->get( 'epl_errors' );
$errors = apply_filters( 'epl_errors', $errors );
return $errors;
}
/**
* Set Error
*
* Stores an error in a session var.
*
* @since 3.0
* @since 3.1.15 switched to EPL Session class for session handling.
* @param int $error_id ID of the error being set.
* @param string $error_message Message to store with the error.
* @return void
*/
function epl_set_error( $error_id, $error_message ) {
$errors = epl_get_errors();
if ( ! $errors ) {
$errors = array();
}
$errors[ $error_id ] = $error_message;
EPL()->session->set( 'epl_errors', $errors );
}
/**
* Clears all stored errors.
*
* @since 3.0
* @since 3.1.15 switched to EPL Session class for session handling.
* @return void
*/
function epl_clear_errors() {
EPL()->session->set( 'epl_errors', null );
}
/**
* Removes (unsets) a stored error
*
* @since 3.0
* @since 3.1.15 switched to EPL Session class for session handling.
* @param int $error_id ID of the error being set.
*/
function epl_unset_error( $error_id ) {
$errors = epl_get_errors();
if ( $errors ) {
unset( $errors[ $error_id ] );
EPL()->session->set( 'epl_errors', $errors );
}
}
/**
* Pretty var dump
*
* @param string $var ID of the variable.
* @param bool $die Die or not.
* @since 3.0
*/
function epl_var_dump( $var, $die = false ) {
echo '<pre class="epl_var_dump">';
var_dump( $var ); //phpcs:ignore
echo '</pre>';
if ( $die ) {
die();
}
}
/**
* Pretty print_r
*
* @param array $var Array to be printed.
* @param bool $die Die or not.
* @since 3.0
*/
function epl_print_r( $var, $die = false ) {
echo '<pre class="epl_print_r">';
print_r( $var );//phpcs:ignore
echo '</pre>';
if ( $die ) {
die();
}
}