Guest User

Untitled

a guest
Aug 18th, 2018
65
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 2.30 KB | None | 0 0
  1. <?php
  2. /**
  3. * Wordpress "Theme Errors API"
  4. *
  5. * @package Wordpress
  6. * @subpackage Theme Errors API
  7. * @since 3.4
  8. * @uses WP_Error
  9. */
  10.  
  11. /**
  12. * Adds theme specific messages to the global theme WP_Error object.
  13. *
  14. * Takes the theme name as $code for the WP_Error object.
  15. * Merges old $data and new $data arrays @uses wp_parse_args().
  16. *
  17. * @param (string) $message
  18. * @param (mixed) $data_key
  19. * @param (mixed) $data_value
  20. * @return void
  21. */
  22. function add_theme_error( $message, $data_key = '', $data_value = '' )
  23. {
  24. global $wp_theme_error, $wp_theme_error_code;
  25.  
  26. if ( ! isset( $wp_theme_error_code ) )
  27. {
  28. $theme_data = get_theme_data( get_stylesheet_uri() );
  29. $name = str_replace( ' ', '', strtolower( $theme_data['Name'] ) );
  30. $wp_theme_error_code = preg_replace( "/[^a-zA-Z0-9\s]/", '', $name );
  31. }
  32.  
  33. if ( ! is_wp_error( $wp_theme_error ) || ! $wp_theme_error )
  34. {
  35. $data[ $data_key ] = $data_value;
  36. $wp_theme_error = new WP_Error( $wp_theme_error_code, $message, $data );
  37. return $wp_theme_error;
  38. }
  39.  
  40. // merge old and new data
  41. $old_data = $wp_theme_error->get_error_data( $wp_theme_error_code );
  42. $new_data[ $data_key ] = $data_value;
  43. $data = wp_parse_args( $new_data, $old_data );
  44.  
  45. return $wp_theme_error->add( $wp_theme_error_code, $message, $data );
  46. }
  47.  
  48.  
  49. /**
  50. * Prints the error messages added to the global theme specific WP_Error object
  51. *
  52. * Only displays for users that have 'manage_options' capability,
  53. * needs WP_DEBUG & WP_DEBUG_DISPLAY constants set to true.
  54. * Doesn't output anything if there's no error object present.
  55. *
  56. * Adds the output to the 'shutdown' hook to render after the theme viewport is output.
  57. *
  58. * @return
  59. */
  60. function print_theme_errors()
  61. {
  62. global $wp_theme_error, $wp_theme_error_code;
  63.  
  64. if ( ! current_user_can( 'manage_options' ) || ! is_wp_error( $wp_theme_error ) )
  65. return;
  66.  
  67. # >>>> don't know what to do here
  68. $messages = $wp_theme_error->get_error_messages( $wp_theme_error_code );
  69. $data = $wp_theme_error->get_error_data( $wp_theme_error_code );
  70. $errors = array_merge( $errors, $data );
  71. $output = '';
  72. foreach ( $errors as $error )
  73. $output .= "{$error}\n";
  74. # <<<< don't know what to do here
  75.  
  76. if ( defined( 'WP_DEBUG' ) && WP_DEBUG && defined( 'WP_DEBUG_DISPLAY' ) && WP_DEBUG_DISPLAY )
  77. return var_dump( $output );
  78. return;
  79. }
  80. add_action( 'shutdown', 'print_theme_errors', 9999 );
Add Comment
Please, Sign In to add comment