O slideshow foi denunciado.
Utilizamos seu perfil e dados de atividades no LinkedIn para personalizar e exibir anúncios mais relevantes. Altere suas preferências de anúncios quando desejar.

WordCamp SF 2011: Debugging in WordPress

9.281 visualizações

Publicada em

The slides for my Debugging in WordPress talk at WordCamp San Francisco, on August 13, 2011.

Publicada em: Negócios, Tecnologia
  • DOWNLOAD THAT BOOKS INTO AVAILABLE FORMAT (2019 Update) ......................................................................................................................... ......................................................................................................................... Download Full PDF EBOOK here { http://bit.ly/2m77EgH } ......................................................................................................................... Download Full EPUB Ebook here { http://bit.ly/2m77EgH } ......................................................................................................................... Download Full doc Ebook here { http://bit.ly/2m77EgH } ......................................................................................................................... Download PDF EBOOK here { http://bit.ly/2m77EgH } ......................................................................................................................... Download EPUB Ebook here { http://bit.ly/2m77EgH } ......................................................................................................................... Download doc Ebook here { http://bit.ly/2m77EgH } ......................................................................................................................... ......................................................................................................................... ................................................................................................................................... eBook is an electronic version of a traditional print book that can be read by using a personal computer or by using an eBook reader. (An eBook reader can be a software application for use on a computer such as Microsoft's free Reader application, or a book-sized computer that is used solely as a reading device such as Nuvomedia's Rocket eBook.) Users can purchase an eBook on diskette or CD, but the most popular method of getting an eBook is to purchase a downloadable file of the eBook (or other reading material) from a Web site (such as Barnes and Noble) to be read from the user's computer or reading device. Generally, an eBook can be downloaded in five minutes or less ......................................................................................................................... .............. Browse by Genre Available eBooks .............................................................................................................................. Art, Biography, Business, Chick Lit, Children's, Christian, Classics, Comics, Contemporary, Cookbooks, Manga, Memoir, Music, Mystery, Non Fiction, Paranormal, Philosophy, Poetry, Psychology, Religion, Romance, Science, Science Fiction, Self Help, Suspense, Spirituality, Sports, Thriller, Travel, Young Adult, Crime, Ebooks, Fantasy, Fiction, Graphic Novels, Historical Fiction, History, Horror, Humor And Comedy, ......................................................................................................................... ......................................................................................................................... .....BEST SELLER FOR EBOOK RECOMMEND............................................................. ......................................................................................................................... Blowout: Corrupted Democracy, Rogue State Russia, and the Richest, Most Destructive Industry on Earth,-- The Ride of a Lifetime: Lessons Learned from 15 Years as CEO of the Walt Disney Company,-- Call Sign Chaos: Learning to Lead,-- StrengthsFinder 2.0,-- Stillness Is the Key,-- She Said: Breaking the Sexual Harassment Story That Helped Ignite a Movement,-- Atomic Habits: An Easy & Proven Way to Build Good Habits & Break Bad Ones,-- Everything Is Figureoutable,-- What It Takes: Lessons in the Pursuit of Excellence,-- Rich Dad Poor Dad: What the Rich Teach Their Kids About Money That the Poor and Middle Class Do Not!,-- The Total Money Makeover: Classic Edition: A Proven Plan for Financial Fitness,-- Shut Up and Listen!: Hard Business Truths that Will Help You Succeed, ......................................................................................................................... .........................................................................................................................
       Responder 
    Tem certeza que deseja  Sim  Não
    Insira sua mensagem aqui
  • DOWNLOAD FULL BOOKS, INTO AVAILABLE FORMAT ......................................................................................................................... ......................................................................................................................... 1.DOWNLOAD FULL. PDF EBOOK here { https://tinyurl.com/y3nhqquc } ......................................................................................................................... 1.DOWNLOAD FULL. EPUB Ebook here { https://tinyurl.com/y3nhqquc } ......................................................................................................................... 1.DOWNLOAD FULL. doc Ebook here { https://tinyurl.com/y3nhqquc } ......................................................................................................................... 1.DOWNLOAD FULL. PDF EBOOK here { https://tinyurl.com/y3nhqquc } ......................................................................................................................... 1.DOWNLOAD FULL. EPUB Ebook here { https://tinyurl.com/y3nhqquc } ......................................................................................................................... 1.DOWNLOAD FULL. doc Ebook here { https://tinyurl.com/y3nhqquc } ......................................................................................................................... ......................................................................................................................... ......................................................................................................................... .............. Browse by Genre Available eBooks ......................................................................................................................... Art, Biography, Business, Chick Lit, Children's, Christian, Classics, Comics, Contemporary, Cookbooks, Crime, Ebooks, Fantasy, Fiction, Graphic Novels, Historical Fiction, History, Horror, Humor And Comedy, Manga, Memoir, Music, Mystery, Non Fiction, Paranormal, Philosophy, Poetry, Psychology, Religion, Romance, Science, Science Fiction, Self Help, Suspense, Spirituality, Sports, Thriller, Travel, Young Adult,
       Responder 
    Tem certeza que deseja  Sim  Não
    Insira sua mensagem aqui
  • @batmoo Ive used something similar that adds a few extra options http://wordpress.org/extend/plugins/debugwp/
       Responder 
    Tem certeza que deseja  Sim  Não
    Insira sua mensagem aqui
  • The Debug Bar Extender plugin is also a must: http://wordpress.org/extend/plugins/debug-bar-extender/
       Responder 
    Tem certeza que deseja  Sim  Não
    Insira sua mensagem aqui

WordCamp SF 2011: Debugging in WordPress

  1. 1. Debugging in WordPressWordCamp San Francisco 2011August 13, 2011
  2. 2. Andrew NacinCore Developer of WordPressTech Ninja at Audrey Capitalnacin@wordpress.org@nacin on Twitter
  3. 3. var_dump( $data ); die( ); // fin.
  4. 4. “I love suppressing errormessages!” — no one, ever.
  5. 5. So lets start withWP_DEBUGdefine( WP_DEBUG, true );
  6. 6. What WP_DEBUG does:— Sets the error reporting level toinclude PHP notices— Bypasses some error suppression— Triggers notices for deprecatedusage (more on that later)
  7. 7. You can change its output:// A default of true forces on display_errors.define( WP_DEBUG_DISPLAY, true );// Setting it to false will let PHP (php.ini) decide.define( WP_DEBUG_DISPLAY, false );// So, if your php.ini has display_errors on, youll also need to turn it off:ini_set( display_errors, 0 );
  8. 8. Likely being simplified in 3.3:// A default of true forces on display_errors.define( WP_DEBUG_DISPLAY, true );// False forces off display_errors.define( WP_DEBUG_DISPLAY, false );// Null will let PHP (php.ini) decide.define( WP_DEBUG_DISPLAY, null );
  9. 9. You can specify an error log:// wp-content/debug.logdefine( WP_DEBUG_LOG, true );// New in 3.3! (Likely.)define( WP_DEBUG_LOG, /tmp/php-errors );// Follow ticket #18391, created last night.
  10. 10. Debug admin CSS & JS withSCRIPT_DEBUGdefine( SCRIPT_DEBUG, true );
  11. 11. SCRIPT_DEBUG preventsminification and concatenation ofcore scripts and styles.load-scripts.php?c=1&load=global,wp-admin,ms…versus global.dev.css, wp-admin.dev.css, ms.dev.css
  12. 12. SCRIPT_DEBUG is good for:— Finding bugs in your admin screens— Studying the admin theme— Contributing to core
  13. 13. Debug queries withSAVEQUERIESdefine( SAVEQUERIES, true );
  14. 14. SAVEQUERIES stores query data in$wpdb->queries.(OMG BBQ:This is NOT for production.)
  15. 15. Query: SELECT * FROM wp_usersWHERE user_login = nacinBacktrace: WP->init,wp_get_current_user,get_currentuserinfo,wp_validate_auth_cookie,get_user_byExecution time: 0.4ms
  16. 16. On using these in production:WP_DEBUG— Dont display errors— Dont log to wp-content/error.logSCRIPT_DEBUG— Bad idea.SAVEQUERIES— Barry will hunt you down.
  17. 17. Plugins
  18. 18. Your new best friend:The Debug BarIt’s like Firebug for your WordPress.
  19. 19. Debug Bar ConsoleA Firebug-like console forPHP and MySQL (really)
  20. 20. Whats stopping you frombuilding your own DebugBar extension?Nothing.
  21. 21. Log Deprecated Notices— Logs the usage of deprecated files,functions, and function arguments.— Pinpoints where the deprecatedfunctionality is being used.— NEVER use in production.
  22. 22. Theme Check— Test your theme for the latestWordPress standards and practices.— Required for the theme directory.
  23. 23. Common functions whendebugging— error_log and var_export / print_r— var_dump and sometimes die— debug_backtrace
  24. 24. Tracking it down
  25. 25. Step 1Disable pluginsSwitch to default theme
  26. 26. What might be left behind?Cron, Rewrites,Roles/Capabilities
  27. 27. Drop-ins— advanced-cache.php— db.php— object-cache.php— mu-plugins
  28. 28. Whats going on?Query vars set properly?Main query SQL look right?Rewrite rule matched?
  29. 29. Funny redirect?Confirm its canonical.remove_action( template_redirect, redirect_canonical );
  30. 30. Testing multisite?I leave this in my config:// define( MULTISITE, true );
  31. 31. Dig into the codebase.Your friends are phpxref, grep.Learn the stack.Learn what things call what.
  32. 32. Some common traps
  33. 33. Step 1Is your code even running?(Spell the hook right?)die( wtf ); or error_log( )
  34. 34. White screen on thefrontend, no errors?Appearance > Themes
  35. 35. User interface doesnt work?Check the browsers JS consolefor an error, usually a conflict.
  36. 36. Internal server errors?Infinite redirects. Check:— home and siteurl— then .htaccess— then canonical
  37. 37. Widgets got moved around?Do the sidebars have IDs?Otherwise, its the order in whichregister_sidebar() is called.
  38. 38. Lots of pages? Slow site?My next Q: Whats yourpermalink structure?No longer an issue in 3.3!
  39. 39. Weird Bug #1Somewhere deep in style.css:“Template: home.php”Miscalculated as a multisite bug:activated on single site beforestyle.css had the headers.
  40. 40. Weird Bug #2The admin looked weird
  41. 41. Weird Bug #2The admin looked weirdTrigger: Upgrade from 2.5 to 3.1
  42. 42. Weird Bug #2The admin looked weirdTrigger: Upgrade from 2.5 to 3.1Problem: No MySQL ALTERpermissions
  43. 43. Weird Bug #3Some bbPress rewritesfailed after activation
  44. 44. Weird Bug #3Some bbPress rewritesfailed after activationProblem: Custom post typerewrites arent registered onactivation
  45. 45. // Say you have:add_action( generate_rewrite_rules, function( $wp_rewrite ) { … } );// And:register_activation_hook( __FILE__, function() { flush_rewrite_rules( );} );// But! This wont work for CPTs. Try this:add_action( init, my_register_post_types );register_activation_hook( __FILE__, function( ) { my_register_post_types( ); flush_rewrite_rules( );} );
  46. 46. Local Development
  47. 47. /etc/hosts127.0.0.1 andrewnacin.comConfigure virtual hostsInstall local WordPress
  48. 48. Replace links with anoutput buffer fordevelopment or stagingenvironments
  49. 49. // Run this on development or staging.// A development wp-config.php or local-config.php is fine.ob_start( nacin_dev_urls );function nacin_dev_urls( $buffer ) { $live = http://andrewnacin.com; $dev = http://dev.andrewnacin.com; return str_replace( $live, $dev, $buffer );}
  50. 50. URLs are more portablewhen theyre absolute.Really.*The serialized stuff is lame though.
  51. 51. Start of a conversationXdebug (backtraces, profiling)KCacheGrind (visualization)Using an IDEUnit testing
  52. 52. And finally, remember:Friends dont let friendsdevelop withoutWP_DEBUG.
  53. 53. Thanks! Questions?@nacin

×