Hot File

11 Powerful Tips and Techniques in wordpress

View: 170    Dowload: 0   Comment: 0   Post by: hanhga  
Author: none   Category: WordPress template   Fields: Other

0 point/0 review File has been tested

Debugging is an essential skill for any developer. This tutorial will show you 11 powerful ways to debug WordPress and PHP errors.

Introduction

Debugging is an essential skill for any developer. This tutorial will show you 11 powerful ways to debug WordPress and PHP errors.

The first item in the list is the famous WP_Debug, then we’ll jump into some more advanced methods.

First, let’s list the types of common PHP errors:

A – Notice: This is the least important error message you will see with PHP. It does not necessarily mean something is wrong, but there is possible improvement suggested.

Example: null element passed to a function that expect a string.

B – Warning: It’s a more severe error, but does not cause script termination.

Example: giving include() a file that does not exist.

C – Fatal error: This is a dangerous indicator of something going really wrong, and the script terminated.

Example: calling a non-existing function.

1 – WP_DEBUG

WordPress has a global constant to specify the needed level of debugging: WP_DEBUG. Along with this constant, comes two another important ones: WP_DEUBG_DISPLAY, and WP_DEBUG_LOG.

WP_DEBUG is used to set the debugging mode on or off. WP_DEUBG_DISPLAY shows errors or hides them. Finally, WP_DEBUG_LOG saves your error messages in wp-content/debug.log.

The three global constants can be set to true or false in wp-config.php, like this:

define("WP_DEBUG", true);

define("WP_DEBUG_DISPLAY", true);

define("WP_DEBUG_LOG", true);

2 – is_wp_error()

Another WordPress built-in tool for debugging is is_wp_error();. It is a method to check if a certain result is of type WP_Error. WP_Error is actually the returned object you should receive if a WordPress method fails.

Example:

$post = array(
    'post_title'    => 'Test post',
    'post_content'  => 'This is my post.',
    'post_status'   => 'publish',
    'post_author'   => 1
);
$result = wp_insert_post( $my_post );

if(is_wp_error($result)){
    echo $return->get_error_message();
}

The above code will try adding a new post using wp_insert_post(). If this method fails, it will return WP_Error object. You can then catch and get the error message.

3 – Debug Bar

Another useful tool for debugging WordPress errors is the Debug Bar. It is a very handy tool for getting useful information about every page in your website.

After installing it, you will find a new Debug button. When you click on it, an analysis of the queries, templates, PHP installation, and many other useful information.

4 – Test Website

It is of the utmost importance to separate the live website from your tests and development. I usually have two installs of WordPress on my websites. This is important because you don’t want your scripts terminating when you turn on error reporting.

5 – Simply Show Hooks

Simply Show Hooks is a nice plugin for showing every hook that is running on any page. If you encounter a situation where all error reporting ideas are not working, and you will, then comes the time for fetching out every and all running hooks.

This plugin will tell you what action or filter hooks that run on any page. You can then start analyzing and debugging each hook code. You can also see the attached methods to every hook. And even find out the priority of each.

6 – WPDB Error Reporting

If you use the wpdb class for dealing with your database, then you will always need error reporting. Whether it is for making sure that your queries run correctly, or for showing up error messages for debugging.

Example:

global $wpdb;
// Before running your query:
$wpdb->show_errors = TRUE;
$result = $wpdb->get_results("SELECT field_value FROM table_name");
if(! $result){
    $wpdb->print_error();
    // Or you can choose to show the last tried query.
    echo $wpdb->last_query;
}

7 – Server Error Logs

At some points, neither WordPress or PHP will be able to catch some coding errors. For example, if your script exceeded the maximum allowed run time, you won’t get a PHP error message. Rather, Apache (or your server installed system) will pop up something like ‘Internal Server Error.’

This is the time when you should go to your error log, and see what if your PHP code, or a certain part of your WordPress installation did something wrong.

You can consult your web hosting provided on where the logging is stored. Usually it is something under logs folder.

8 – PHP Error Logging

PHP has its own level of error reporting to store the issues resolving beyond WordPress. This is extremely useful, especially if something outside of WordPress running and causing some problem.

You can start by configuring your php.ini file to turn on error reporting, and then choosing where to store such messages.

error_reporting = E_ALL | E_STRICT 
error_log = /var/log/php_error.log

Setting the above two lines will turn on error reporting, and set the errors to be saved at the specified path.

Also, you can run phpinfo(); and check the error_log option.

9 – PHP Syntax Checker

If your hosting provider limits access to php.ini file, or you can’t access error logs, things can be a bit harder. But, there are many tools to overcome a situation when you get only a blank page with no error message. One quick tool is PHP Code Checker.

PHP Code Checker is a syntax errors checking tool. It is really useful if you missed a semi-colon or a curly brace, and can’t find where did you miss it.

10 – PHP IDE

If PHP Code Checker didn’t find a syntax error, then you will need a more powerful tool. A powerful IDE like PhpStorm will be the answer for more advanced debugging, and breaking down your code into parts.

In a situation like, when you store a string in a variable, and try printing it, but nothing happens. Using an IDE can find out you are doing something wrong like, overriding this variable later in your code. This is why it is highly recommended to rely on a powerful IDE like PhpStorm, Eclipse, or any tool you prefer.

11 – Disabling Browser Cache

If you are working on the front-end side of your website, then you need to disable browser cache. This is necessary because if you are working on your JavaScript code, and it’s not updating, or even worse, updating but not showing new errors, then you need to disable cache.

Disabling the cache means you ask your browser to stop working on old stored files of your website. This includes CSS and JavaScript files.

To disable Google Chrome browser cache, open the DevTools by right-clicking of any web element. Then, click on Network tab in toolbar. Finally, check the Disable Cache checkbox at the top.

11 Powerful Tips and Techniques in wordpress

11 Powerful Tips and Techniques in wordpress Posted on 20-10-2016  Debugging is an essential skill for any developer. This tutorial will show you 11 powerful ways to debug WordPress and PHP errors. 5/10 170

Comment:

To comment you must be logged in members.

Files with category

  • 11 Powerful Tips and Techniques in wordpress

    View: 170    Download: 0   Comment: 0   Author: none  

    11 Powerful Tips and Techniques in wordpress

    Category: WordPress template
    Fields: Other

    0/0 review
    Debugging is an essential skill for any developer. This tutorial will show you 11 powerful ways to debug WordPress and PHP errors.

  • MH Edition Lite Responsive WordPress Theme 2017 Free

    View: 215    Download: 1   Comment: 0   Author: none  

    MH Edition Lite Responsive WordPress Theme 2017 Free

    Category: WordPress template
    Fields: Other

    0/0 review
    MH Edition lite is a flexible and visually sophisticated WordPress theme for technology and news magazines. This magazine theme can transform your current WordPress website into a powerful and yet lightweight online magazine or dynamic news website...

  • Morning Monday Lite Responsive WordPress Theme Free

    View: 223    Download: 3   Comment: 0   Author: none  

    Morning Monday Lite Responsive WordPress Theme Free

    Category: WordPress template
    Fields: Other

    2.25/2 review
    Morning Monday Lite theme is designed for magazine with flexible layout. The theme is based on KOPATHEME layout manager technique that will let you flexibility choose layout options of every pages within your site.

  • How to Translate a WordPress Plugin Description

    View: 240    Download: 0   Comment: 0   Author: none  

    How to Translate a WordPress Plugin Description

    Category: WordPress template
    Fields: Other

    0.020325203252033/246 review
    If you’ve developed a useful plugin for WordPress, that’s great – but it’s even better if you make your plugin accessible to users speaking other languages.

  • Lovecraft Responsive WordPress Theme Free

    View: 206    Download: 0   Comment: 0   Author: none  

    Lovecraft Responsive WordPress Theme Free

    Category: WordPress template
    Fields: Other

    2/2 review
    Lovecraft is a beautiful two-column theme for bloggers. It features a responsive design, great typography, a full-width header image

  • Ascent Theme is a fully responsive WordPress theme

    View: 4797    Download: 0   Comment: 0   Author: none  

    Ascent Theme is a fully responsive WordPress theme

    Category: WordPress template
    Fields: Other

    4.5/1 review
    Ascent Theme is a fully responsive WordPress theme that looks elegant on any devices. It is simple, clean and lightweight WordPress theme based on the most modern technologies like HTML5 and CSS3.

  • Photolab Responsive WordPress Theme Free

    View: 284    Download: 0   Comment: 0   Author: none  

    Photolab Responsive WordPress Theme Free

    Category: WordPress template
    Fields: Other

    4/1 review
    Photolab theme echoes a flat design approach and a modern clean look perfect for creating an engaging blog. Its layout inspired by the latest trends underlines visual excellence of the theme without distracting from the content.

  • ZeroGravity is a simple and light WordPress theme

    View: 282    Download: 0   Comment: 0   Author: none  

    ZeroGravity is a simple and light WordPress theme

    Category: WordPress template
    Fields: Other

    4.5/1 review
    ZeroGravity is a simple and light WordPress theme with a clear and neat design. Some its features are: left sidebar or right, custom theme color (blue, green, orange, red, pink, yellow or purple), custom favicon, six different Google Fonts,...

 
Newsletter Email

File suggestion for you

File top downloads

logo codetitle
Codetitle.com - library source code to share, download the file to the community
Copyright © 2015. All rights reserved. codetitle.com Develope by Vinagon .Ltd