{"id":497,"date":"2012-11-16T12:00:37","date_gmt":"2012-11-16T11:00:37","guid":{"rendered":"https:\/\/wprealm.com\/?p=497"},"modified":"2012-11-16T12:00:37","modified_gmt":"2012-11-16T11:00:37","slug":"debugging-tips-in-the-wordpress-context","status":"publish","type":"post","link":"http:\/\/wprealm.local\/debugging-tips-in-the-wordpress-context\/","title":{"rendered":"Debugging Tips for WordPress"},"content":{"rendered":"
Recently I’ve had several discussions with colleagues asking me for the debugging practices that I use. I try to constantly enhance my workflow, resources and improve the quality of my work by speeding up the process of narrowing down the possible reasons for a bug or a feature limitation. Speaking WordPress-wise, I’ll list a couple of things that I consider important. Some of them are more than obvious, but somehow people misuse them or forget about them at a moment of crisis (so to speak).<\/p>\n
Before you start:\u00a0always do backups<\/strong>. Debug your web application locally, test properly and ensure that everything is on set before deploying to the real server. Best practices teach that a local server -> staging\/dev server -> production server is a good setup to prevent the obvious error of hitting the live website.<\/p>\n <\/p>\n I’ve been using plain text editors (vim included) for a while, but usually only for remote\/small changes. I rely on a IDE for better control over the codebase and the relations. I’m an\u00a0Eclipse<\/a>\u00a0user (naturally evolved after several years in the Java world) but you could also check out NetBeans, Sublime, PhpStorm, Komodo or anything else with more capabilities. Using an IDE helps you to set up an easy connection between the codebase and a version control, debugger, (S)FTP and use a number of function suggestions and PHPDoc comments while developing and browsing the code. Xdebug<\/a>\u00a0or the Zend debugger are also a crucial part. Debugging with echo or\u00a0var_dump<\/em>\u00a0(or\u00a0console.log<\/em>\/alert<\/em>) is a quickie for one-liners, but a serious workflow iteration processing requires a debugger.<\/p>\n I have an article about setting\u00a0Eclipse with Xdebug for Linux<\/a>. I’m also using\u00a0Chrome<\/a>. Safari or Firefox will do the trick too, and for some bugs you need to run several browsers and check if there is a browser-specific bug. For some browser-app attempts such as IE you could nail a large variety of specifics due to their boxing model or JavaScript unique interpretation specifics.<\/p>\n I’ve been using a number of separate plugins, most of which are already listed on the\u00a0Developer<\/a>\u00a0plugin by\u00a0Automattic<\/a>, along with other best practices. It reminds you about setting\u00a0WP_DEBUG<\/strong>\u00a0and other constants in your wp-config file, as well as install environment testing plugins. In addition to the plugins listed over there, I you may also find the following useful:<\/p>\n Scribu has made a good job of outlining the workflow for troubleshooting<\/a>. You need to limit the options for a bug to happen. Normally it narrows down to 2 steps, iterated and expressed depending on the scenario:<\/p>\n Sooner or later the problem disappears when plugins are disabled or the theme is gone. If that’s not the case, you should consider whether anything you have done directly on the database (custom changes) or the file structure (like manually editing WP-files or updating the core) is causing the issue. Sometimes WordPress core updates introduce new changes and\u00a0deprecates<\/strong>\u00a0existing functions so a theme\/plugin could be affected by that.<\/p>\n Once you have figured out what is causing the problem, you will have to find the reason for the bug.<\/p>\n Themes have a good process for a proper and painless interaction with WordPress core. However, some theme authors intentionally (or rather not) include custom implementations for their specific scenario that doesn’t behave well with all common cases. A common example is using\u00a0timthumb<\/em>\u00a0for image management – not only is it insecure and heavy, but it’s inflexible.<\/p>\n <\/a><\/p>\n Knowing the template hierarchy, try the following:<\/p>\n For Apache and nginx there are so many configurations that could make a difference.<\/p>\n Google is your best friend<\/strong>. Use it. If you don’t know how, it’s time to learn. And no, it’s not always straightforward. You need to learn how to select the proper phrase for searching (think about the results you’re trying to find) and eventually limit the results by the\u00a0advanced filters<\/strong>, like: limit by location, by date, use some wildcard like site:\u00a0intitle:<\/em>\u00a0inurl:<\/em>\u00a0filetype:<\/em>\u00a0or anything that could help you limit the billions of results. StackOverflow<\/a>\u00a0and the\u00a0WordPress StackExchange<\/a>\u00a0are super helpful. Don’t forget the\u00a0WordPress.org forums<\/a> nettuts+<\/a>,\u00a0WPCandy<\/a>\u00a0or other WP-specific sources might help for WP-related troubles.<\/p>\n","protected":false},"excerpt":{"rendered":" Recently I’ve had several discussions with colleagues asking me for the debugging practices that I use. I try to constantly enhance my workflow, resources and improve the quality of my work by speeding up the process of narrowing down the possible reasons for a bug or a feature limitation. Speaking WordPress-wise, I’ll list a couple […]<\/p>\n","protected":false},"author":27,"featured_media":523,"comment_status":"open","ping_status":"open","sticky":false,"template":"","format":"standard","meta":{"_genesis_hide_title":false,"_genesis_hide_breadcrumbs":false,"_genesis_hide_singular_image":false,"_genesis_hide_footer_widgets":false,"_genesis_custom_body_class":"","_genesis_custom_post_class":"","_genesis_layout":"","footnotes":""},"categories":[14],"tags":[46,157],"people":[],"company":[],"events":[],"acf":[],"yoast_head":"\nEnvironment<\/h2>\n
WordPress setup<\/h2>\n
\n
Workflow<\/h2>\n
\n
Plugins<\/h3>\n
\n
Themes<\/h3>\n
\n
\n
Servers<\/h3>\n
\n
Websites<\/h2>\n