| 1 |
<?php |
| 2 |
|
| 3 |
if ( ! function_exists( 'leaky_paywall_errors' ) ) { |
| 4 |
/** |
| 5 |
* Stores error messages |
| 6 |
* |
| 7 |
* @since 1.0 |
| 8 |
*/ |
| 9 |
function leaky_paywall_errors() { |
| 10 |
static $wp_error; // Will hold global variable safely. |
| 11 |
return isset( $wp_error ) ? $wp_error : ( $wp_error = new WP_Error( null, null, null ) ); |
| 12 |
} |
| 13 |
} |
| 14 |
|
| 15 |
/** |
| 16 |
* Retrieves the HTML for error messages |
| 17 |
* |
| 18 |
* @access public |
| 19 |
* @since 4.0.0 |
| 20 |
*/ |
| 21 |
function leaky_paywall_get_error_messages_html( $error_id = '' ) { |
| 22 |
|
| 23 |
$html = ''; |
| 24 |
$errors = leaky_paywall_errors()->get_error_codes(); |
| 25 |
|
| 26 |
if ( $errors ) { |
| 27 |
|
| 28 |
$html .= '<div class="leaky_paywall_message error">'; |
| 29 |
// Loop error codes and display errors. |
| 30 |
foreach ( $errors as $code ) { |
| 31 |
|
| 32 |
if ( leaky_paywall_errors()->get_error_data( $code ) == $error_id ) { |
| 33 |
|
| 34 |
$message = leaky_paywall_errors()->get_error_message( $code ); |
| 35 |
|
| 36 |
$html .= '<p class="leaky_paywall_error ' . esc_attr( $code ) . '"><span>' . $message . '</span></p>'; |
| 37 |
|
| 38 |
} |
| 39 |
} |
| 40 |
|
| 41 |
$html .= '</div>'; |
| 42 |
|
| 43 |
} |
| 44 |
|
| 45 |
return apply_filters( 'leaky_paywall_error_messages_html', $html, $errors ); |
| 46 |
|
| 47 |
} |
| 48 |
|
| 49 |
/** |
| 50 |
* Displays the HTML for error messages |
| 51 |
* |
| 52 |
* @access public |
| 53 |
* @since 4.0.0 |
| 54 |
* |
| 55 |
* @param string $error_id The error id. |
| 56 |
*/ |
| 57 |
function leaky_paywall_show_error_messages( $error_id = '' ) { |
| 58 |
|
| 59 |
if ( leaky_paywall_errors()->get_error_codes() ) { |
| 60 |
|
| 61 |
do_action( 'leaky_paywall_errors_before' ); |
| 62 |
echo wp_kses_post( leaky_paywall_get_error_messages_html( $error_id ) ); |
| 63 |
do_action( 'leaky_paywall_errors_after' ); |
| 64 |
|
| 65 |
} |
| 66 |
} |
| 67 |
|