Blog

Fix 404 errors, Not Found, and Server Errors on WordPress/Woocommerce Site

According to wikipedia “The 404 or Not Found error message is a Hypertext Transfer Protocol (HTTP) standard response code, in computer network communications, to indicate that the client was able to communicate with a given server, but the server could not find what was requested.”

What happen is that the server could not find the file that are requested by the server. There are a few causes for these and these can be easily fixed.

There are common few fixes like refreshing browser, clear cache and cookie or amending .htaccess file.

For woocommerce site, I have found the cause in 99% of the case to be cause by Permalinks. Just by matching the Url in the browser and the setting of your Permalinks under WordPress–Settings>>>Permalinks, should fix the error.

Customising Woocommerce Report

Creating a simple plugin to generate a woocommerce report that suits your need. All woocommerce sites are different, the way they sell are different. Many plugins available are able to generate reports and customise them. Still I get a lot of request on customising reports for woocommerce.

I use the WC_Admin_Report class from woocommerce to accomplish this. With WC_Admin_Report, you organise all your required fields and condition in an array and pass it over. Write the results in a CSV, comma delimited file, using fputcsv and you are done. Throw in some nice jQuery and you get a really slick reporting system.

Using WP-CLI to check your wordpress core integrity

A very useful trick to check your wordpress core integrity with wp-cli.
wp core verify-checksums – Verify WordPress files against WordPress.org’s checksums.

# Verify checksums
$ wp core verify-checksums
Success: WordPress install verifies against checksums.

# Verify checksums for given WordPress version
$ wp core verify-checksums –version=4.0
Success: WordPress install verifies against checksums.

# Verify checksums for given locale
$ wp core verify-checksums –locale=en_US
Success: WordPress install verifies against checksums.

# Verify checksums for given locale
$ wp core verify-checksums --locale=ja
Warning: File doesn't verify against checksum: wp-includes/version.php
Warning: File doesn't verify against checksum: readme.html
Warning: File doesn't verify against checksum: wp-config-sample.php
Error: WordPress install doesn't verify against checksums.
GLOBAL PARAMETERS
--path= Path to the WordPress files.
--ssh=[@][:][]
Perform operation against a remote server over SSH.
--http=
Perform operation against a remote WordPress install over HTTP.
--url=
Pretend request came from given URL. In multisite, this argument is how the target site is specified.
--user=
Set the WordPress user.
--skip-plugins[=]
Skip loading all or some plugins. Note: mu-plugins are still loaded.
--skip-themes[=]
Skip loading all or some themes.
--skip-packages
Skip loading all installed packages.
--require= Load PHP file before running the command (may be used more than once).
--[no-]color
Whether to colorize the output.
--debug[=]
Show all PHP errors; add verbosity to WP-CLI bootstrap.
--prompt
Prompt the user to enter values for all command arguments.
--quiet
Suppress informational messages.

Learn more here wp-cli doc

WordPress Virus/Malware removal

Most of us who owns wordpress site will, at certain point of time, experience a hack. I will not cover the basics of such hack or basic common techniques used to remove them.

One of the technique I been using recently that would well, is to enable the debug mode.

The following code, inserted in your wp-config.php file, will log all errors, notices, and warnings to a file called debug.log in the wp-content directory. It will also hide the errors so they do not interrupt page generation.


// 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 );

By simply enabling the debug mode, you be able to catch an error ‘headers already sent’, which also points to the file that the code are injected.

Warning: Cannot modify header information - headers already sent by (output started at /some/file.php:12) in /some/file.php on line 23

Since most code are injected on top of your files, you be able to catch the error sent out just by enabling the debug mode.