Successfully reported this slideshow.
We use your LinkedIn profile and activity data to personalize ads and to show you more relevant ads. You can change your ad preferences anytime.

Here Be Dragons - Debugging WordPress

1,190 views

Published on

Have you ever cried yourself to sleep unable to find the cause of a horrendous bug in your WordPress site? Cry no more, your tears will be reshaped as blinding swords as we explore uncharted territories laced with mystical creatures.

Debugging is an often avoided topic due to the uncertainty of how best to accomplish it and the lack of powerful introspective tools. This talk will explore new territory and showcase tools that help you debug complex and difficult issues in your WordPress site.

Published in: Engineering
  • Be the first to comment

Here Be Dragons - Debugging WordPress

  1. 1. Rami Sayar - @ramisayar Technical Evangelist Microsoft Canada
  2. 2. • Types of Errors in WordPress • Frequent Locations of Errors in WordPress • Taming WP_DEBUG • Using Debugging Plugins • Remote Debugging Front-End JavaScript
  3. 3. • Working knowledge of PHP, JS and WordPress. Note: Slides will be made available.
  4. 4. • The White Screen of Death • Plugin compatibility Errors • Theme Errors • Internal Server Errors • Trouble with PHP Host (Apache, Nginx) • Trouble with Server Networking or Load Balancing • Database Errors • Can’t Connect to Database • Can’t Create Tables, Write Rows, Read Rows, etc…
  5. 5. • Server Layer • Incorrectly Configured Server Host or Networking • WordPress/PHP Layer • Problem with Themes or Plugins • Database Layer • Incorrectly Configured Database or Connection
  6. 6. Using WordPress built-in debugging mechanisms
  7. 7. • WP_DEBUG is a PHP constant used to trigger “debug” mode. • In your wp-config.php file, change: define('WP_DEBUG', true); //define('WP_DEBUG', false); • Do not enable WP_DEBUG in production. • Always enable WP_DEBUG during development of themes or plugins.
  8. 8. • All PHP errors, notices and warnings are shown. • Deprecated functions or arguments within WordPress in use by your site will also be shown.
  9. 9. • WP_DEBUG_LOG tells WordPress to write all error messages to a debug.log log file inside the /wp-content/ directory. define('WP_DEBUG_LOG', true); • WP_DEBUG must be true for the log to work. • Your plugins and themes can use the built-in error_log() function to write to the debug.log.
  10. 10. • Debug messages are shown inside the HTML of pages. • define('WP_DEBUG_DISPLAY', false); • WP_DEBUG must be true for the display to work.
  11. 11. • SCRIPT_DEBUG is a related constant that will force WordPress to use the "dev" versions of core CSS and JavaScript files rather than the minified versions that are normally loaded. define('SCRIPT_DEBUG', true); • The SAVEQUERIES definition saves the database queries to an array and that array can be displayed to help analyze those queries. define('SAVEQUERIES', true);
  12. 12. // Enable WP_DEBUG mode define('WP_DEBUG', true); // Enable Debug logging to the /wp-content/debug.log file define('WP_DEBUG_LOG', true); // Disable display of errors and warnings define('WP_DEBUG_DISPLAY', false); @ini_set('display_errors',0); // Use dev versions of core JS and CSS files (only needed if you are modifying these core files) define('SCRIPT_DEBUG', true);
  13. 13. “Adds a debug menu to the admin bar that shows query, cache, and other helpful debugging information.” https://wordpress.org/plugins/debug-bar/
  14. 14. “Logs the usage of deprecated files, functions, and function arguments, and identifies where the deprecated functionality is being used.” “This plugin also logs incorrect function usage, which WordPress started reporting in 3.1.” https://wordpress.org/plugins/log-deprecated-notices/
  15. 15. “Query Monitor has some advanced features including automatic AJAX debugging and the ability to narrow down things by plugin or theme.” https://wordpress.org/plugins/query-monitor/
  16. 16. “This plugin helps troubleshoot issues with the infamous WordPress WSOD (White Screen of Death).” https://github.com/stracker-phil/wp-no-white-screen/ Note: Don’t forget to remove this file after debugging.
  17. 17. “BlackBox is a plugin for plugin and theme developers. It collects and displays useful debug information (errors, executed queries, globals, profiler).” https://wordpress.org/plugins/blackbox-debug-bar/
  18. 18. “Core Control is a set of plugin modules which can be used to control certain aspects of the WordPress control. Currently, Core Control features modules for managing Filesystem Access, Managing plugin/theme/core updates, Managing HTTP Transports & External HTTP Request logging.” https://wordpress.org/plugins/core-control/
  19. 19. Who hasn’t heard that one or a variant before?
  20. 20. Wait… what! You can do that?
  21. 21. • An open source, extensible, platform-agnostic tool for remotely debugging and testing your JavaScript. • Plugins: • Console: View logs and errors for your application. • Modernizr: View a list of supported and unsupported features. • DOM Explorer: Inspect the DOM tree and its corresponding styles. • Object Explorer: Display the living JavaScript variables tree. • XHR Panel: View XHR calls information sent by your devices. • ngInspector: Inspect your Angular.js scopes • Network Monitor: View network activities (XHR & resources loading). • Resources Explorer: Inspect local resources such as localStorage or cookoes.
  22. 22. $ npm i -g vorlon $ vorlon Add to your code. <script src="http://localhost:1337/vorlon.js"></script> Open http://localhost:1337
  23. 23. • Deploy Vorlon.JS to a public server/PaaS/wtv. • As simple as a Git push • Add this to your public beta website: <script src="http://web.com/vorlon.js"></script>
  24. 24. Note: Don’t do this in production with SSL and authentication setup. Better yet, only do this in staging/beta.
  25. 25. • From Andrew Nacin • There’s an ‘all’ hook that fires for all actions and filters. add_action( 'all', create_function( '', 'var_dump( current_filter() );' ) );
  26. 26. • WordPress loads the functions from all the plugins together into the same execution space. • There is no namespacing. • You should give each function a unique name to avoid collisions.
  27. 27. bloginfo(‘wpurl’) == “WordPress address (URL)” bloginfo(‘url’) == “Site address (URL)” • These may evaluate to different URLs depending on the WordPress installation.
  28. 28. • Types & Locations of Errors in WordPress • How to Use WP_DEBUG & Other Settings • Using Debugging Plugins Including • Debug Bar & Console • Query Monitor • Core Control • Remote Debugging Front-End JavaScript with Vorlon.JS
  29. 29. tw: @ramisayar | gh: @sayar slideshare.net/ramisayar
  30. 30. • Debugging in WordPress • Ten Things Every WordPress Plugin Developer Should Know • 10 WordPress Debugging Tools to Find Errors and Warnings • 3 Reasons Why You Should Be Using WP_DEBUG_LOG In Your WordPress Development • Debugging WordPress: How to Use WP_DEBUG
  31. 31. ©2013 Microsoft Corporation. All rights reserved. Microsoft, Windows, Office, Azure, System Center, Dynamics and other product names are or may be registered trademarks and/or trademarks in the U.S. and/or other countries. The information herein is for informational purposes only and represents the current view of Microsoft Corporation as of the date of this presentation. Because Microsoft must respond to changing market conditions, it should not be interpreted to be a commitment on the part of Microsoft, and Microsoft cannot guarantee the accuracy of any information provided after the date of this presentation. MICROSOFT MAKES NO WARRANTIES, EXPRESS, IMPLIED OR STATUTORY, AS TO THE INFORMATION IN THIS PRESENTATION.

×