Explain some common debug techniques and _php techniques in WordPress development

Source: Internet
Author: User

In the development process, debugging code is very important work, and master some of the debugging techniques WordPress, you can better debug. For example, in a local development environment, you may need to export all of your code warning information to make it easier to modify the code in an unreasonable location.

This article will explain all the debugging methods of WordPress, if you are a developer, must master these skills, can greatly improve efficiency.

The opening of debug mode requires some constants to be added to the wp-config.php file in the root directory, so all the code described below is added to the wp-config.php file in the root directory.

Wp_debug

Wp_debug is a WordPress constant, set to True, WordPress will enter the developer mode, it will be all about the development of the prompts to output to the screen.

I highly recommend enabling Wp_debug in a local development environment for easy development.

Enable developer mode
define (' Wp_debug ', true);

Wp_debug_log

If you want to record all the bugs in the WordPress run, you can turn on Wp_debug_log and all the errors will be recorded and stored in the Wp-content/debug.log file.

The premise of recording errors is the need to open Wp_debug mode, only open wp_debug will produce errors.

Turn On Error logging
define (' Wp_debug_log ', true);

Wp_debug_display

If you want to make the error generated by the Wp_debug mode only through the Wp_debug_log record and not on the screen, you can turn on the wp_debug_display when you open Wp_debug_log and Wp_debug.

Prevent errors from appearing on the screen
define (' Wp_debug_display ', true);
Script_debug

By default, WordPress background will use the compressed and merged JS and CSS files.

Sometimes in order to debug, we may not want to use the background compressed CSS and JS files, this can be set to True script_debug.

Disable compressed CSS and JS file
define (' Script_debug ', true);

Savequeries

If you want to optimize the number of database queries, Savequeries is a very important thing, the savequeries set to True,wordpress will record each database query SQL statements and the time spent.

Log database query
define (' Savequeries ', true);

After opening the record, you can use the $WPDB queries variable to get all the data queries, and put the following code in the footer.php file of the topic to see all the database queries.

<pre><?php var_dump ($GLOBALS [' wpdb ']->queries);?></pre>

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.