| 1 |
<?php |
| 2 |
|
| 3 |
if ( ! defined( 'ABSPATH' ) ) { |
| 4 |
exit; |
| 5 |
} |
| 6 |
|
| 7 |
if( ! class_exists( 'MywpDeveloperAbstractModule' ) ) { |
| 8 |
return false; |
| 9 |
} |
| 10 |
|
| 11 |
if ( ! class_exists( 'MywpDeveloperModuleMywpError' ) ) : |
| 12 |
|
| 13 |
final class MywpDeveloperModuleMywpError extends MywpDeveloperAbstractModule { |
| 14 |
|
| 15 |
static protected $id = 'mywp_error'; |
| 16 |
|
| 17 |
static protected $priority = 10; |
| 18 |
|
| 19 |
protected static function after_init() { |
| 20 |
|
| 21 |
add_action( 'admin_footer' , array( __CLASS__ , 'show_error_count' ) ); |
| 22 |
|
| 23 |
} |
| 24 |
|
| 25 |
public static function show_error_count() { |
| 26 |
|
| 27 |
add_filter( 'mywp_debug_types' , array( __CLASS__ , 'mywp_debug_types_show_error_count' ) , 100 ); |
| 28 |
|
| 29 |
add_filter( 'mywp_debug_renders' , array( __CLASS__ , 'mywp_debug_renders_show_error_count' ) , 100 ); |
| 30 |
|
| 31 |
} |
| 32 |
|
| 33 |
public static function mywp_debug_types_show_error_count( $debug_types ) { |
| 34 |
|
| 35 |
$errors = self::get_errors(); |
| 36 |
|
| 37 |
if( empty( $errors ) ) { |
| 38 |
|
| 39 |
return $debug_types; |
| 40 |
|
| 41 |
} |
| 42 |
|
| 43 |
if( isset( $debug_types['mywp'] ) ) { |
| 44 |
|
| 45 |
$debug_types['mywp'] .= ' (error) '; |
| 46 |
|
| 47 |
} |
| 48 |
|
| 49 |
return $debug_types; |
| 50 |
|
| 51 |
} |
| 52 |
|
| 53 |
public static function mywp_debug_renders_show_error_count( $debug_renders ) { |
| 54 |
|
| 55 |
$errors = self::get_errors(); |
| 56 |
|
| 57 |
if( empty( $errors ) ) { |
| 58 |
|
| 59 |
return $debug_renders; |
| 60 |
|
| 61 |
} |
| 62 |
|
| 63 |
if( isset( $debug_renders[ self::$id ] ) ) { |
| 64 |
|
| 65 |
$debug_renders[ self::$id ]['title'] .= sprintf( ' (%s) ' , count( $errors ) ); |
| 66 |
|
| 67 |
} |
| 68 |
|
| 69 |
return $debug_renders; |
| 70 |
|
| 71 |
} |
| 72 |
|
| 73 |
public static function mywp_debug_renders( $debug_renders ) { |
| 74 |
|
| 75 |
$debug_renders[ self::$id ] = array( |
| 76 |
'debug_type' => 'mywp', |
| 77 |
'title' => sprintf( '%s Error' , MYWP_NAME ), |
| 78 |
); |
| 79 |
|
| 80 |
return $debug_renders; |
| 81 |
|
| 82 |
} |
| 83 |
|
| 84 |
private static function get_errors() { |
| 85 |
|
| 86 |
$errors = MywpApi::get_errors(); |
| 87 |
|
| 88 |
return $errors; |
| 89 |
|
| 90 |
} |
| 91 |
|
| 92 |
protected static function mywp_developer_debug() { |
| 93 |
|
| 94 |
$errors = self::get_errors(); |
| 95 |
|
| 96 |
echo 'Mywp error = '; |
| 97 |
|
| 98 |
if( empty( $errors ) ) { |
| 99 |
|
| 100 |
return false; |
| 101 |
|
| 102 |
} |
| 103 |
|
| 104 |
foreach( $errors as $key => $val ) { |
| 105 |
|
| 106 |
echo esc_html( $val ) . "\n"; |
| 107 |
|
| 108 |
} |
| 109 |
|
| 110 |
} |
| 111 |
|
| 112 |
protected static function mywp_debug_render() { |
| 113 |
|
| 114 |
$errors = self::get_errors(); |
| 115 |
|
| 116 |
if( empty( $errors ) ) { |
| 117 |
|
| 118 |
printf( '<p>%s</p>' , __( 'No errors.' , 'my-wp' ) ); |
| 119 |
|
| 120 |
} else { |
| 121 |
|
| 122 |
echo '<ul>'; |
| 123 |
|
| 124 |
foreach( $errors as $error ) { |
| 125 |
|
| 126 |
printf( '<li>%s</li>' , esc_html( $error ) ); |
| 127 |
|
| 128 |
} |
| 129 |
|
| 130 |
echo '</ul>'; |
| 131 |
|
| 132 |
} |
| 133 |
|
| 134 |
} |
| 135 |
|
| 136 |
} |
| 137 |
|
| 138 |
MywpDeveloperModuleMywpError::init(); |
| 139 |
|
| 140 |
endif; |
| 141 |
|