Validate your WordPress blog using WordPress XML-RPC API, Php Tidy and Nu HTML Checker

Posted on 11-04-2017 by Nadir Latif

Introduction

WordPress is a very popular platform for hosting websites. Over 74 million websites are based on WordPress. WordPress is also increasingly being used to develop complex web based applications.

There is a need for a testing system that allows testing applications and websites based on WordPress. Recently I had the opportunity of setting up a simple testing system for WordPress that validates WordPress blogs using the WordPress XML-RPC API, Php Tidy and the online Nu HTML Checker. I will describe my experience in this blog post. I will also briefly describe a couple of ways in which you can test server side code of your WordPress plugins.

What is the importance of Validating your website

Its a good idea to ensure that your WordPress blog conforms to W3C standards. The World Wide Web Consortium (W3C) is the main international standards organization for the World Wide Web. The W3C standard is recognized by all major search engines. Websites that conform to its standards can be understood by search engines and web browses more easily.

Such websites have fewer performance problems and function more reliably across multiple devices. They are also sure to receive a higher ranking on the major search engines.

Validating your blog using Nu HTML Checker

The W3C validation website contains several tools that you can use to validate your website pages.  These tools include:

The Nu HTML checker can be used to check any website for compliance with the new Html 5 standard. I created a Php script that uses the WordPress XML-RPC API for getting list of all pages, posts, custom posts on my blog. The XML-RPC API is very useful and you can use it to easily get list of all pages on your blog. Once you have the list of pages, you can test each page against different W3C standards.

For each post the script validates the post html using the PHP Tidy extension and the Nu HTML Checker. The PHP Tidy extension is a popular extension for Php that allows repairing and formatting your html code. It supports Html 4 validation but does not support Html 5.

If a post cannot be validated the test ends with an error. I ran this script with PhpUnit and added it to Jenkins Continuous Integration Server. I scheduled the script to run every day, so the script tests all pages automatically and sends me an email if any of the tests fail. Setting up projects in Jenkins is quite simple. You can refer to my earlier blog post titled Continuous integration and Project Management with Jenkins and Redmine for more information on how to add scripts to Jenkins.

Testing Server Side code of your plugins

Testing a WordPress website using PhpUnit is different from testing websites based on other platforms. WordPress has its own authentication system which prevents testing WordPress plugins and themes like normal php scripts. There are 2 main options for testing the server side code of your plugins:

  1. WP-CLI. WP-CLI is a command line interface to WordPress. It can be used along with PhpUnit to unit test your WordPress plugins. The WP-CLI website has some useful documentation on how to test WordPress plugins.
  2. Extend the WordPress XML-RPC interface inside your plugins. This method allows you to test your plugins using WordPress XML-RPC interface. Basically it allows you to call your test functions using WordPress XML-RPC interface.

Conclusion

WordPress is a very popular platform for websites. It is important to have a testing system in place that makes it easy to test WordPress based websites.

Ensuring that your website conforms to W3C standards is very useful. It not only improves your SEO score but also ensures compatibility of your website across different devices and browsers


Leave a Comment: