Here are some test assignments for any PHP programmer who want’s to learn WordPress programming. It’s not a step by step guide, but something we used for our junior programmers. Basic programming skills and advanced Googling skills are a prerequisite.
Part 0.: Install your own localhost web hosting environment
- Grab XAMPP (Windows) or MAMP (OS X), see where your web root is and how to connect to database.
- Install your WordPress.
- Import the test content by following step 1. and 2. here: Theme Unit Test on WordPress.org
Part I.: Template programming
- Use add_action to add some HTML to your site footer. Use the functions.php file of your theme.
- Add a new function to your template which will list all the articles with a specific post meta. Use WP_Query to do it. You can simply output it in header.
- Add code to show the featured images for the articles in archives.
Part II.: Processing posts
So you have your site with a couple of posts now. It’s time to try processing the data by some simple scripts. This is something you might need a lot whenever you work on some site conversion or change the structure of the website.
- Create an external script which loads wp-load.php and then uses WordPress functions to do a string replace in each post content. The script should not be a plugin, just create a PHP file where wp-load.php is, include it and then you can use global $wpdb; and all the WordPress functions and so on.
- Create an external script which assigns a given category to each post. Make sure you use WP API calls and not SQL.
Part III.: Build a plugin screen from scratch
You might build a plugin sooner or later, this might come handy:
- Start by creating a new plugin. Wrap it all into some class.
- Use all the WP API functions to create a new WP Admin Dashboard menu item which will show your own screen.
- Put a simple form which stores a wp_option to this screen. Make sure you follow WordPress HTML when you build the form – get inspired on Settings -> General screen.
- Use WP nonce security for checking of the form submission.
Part IV.: Get to know jQuery
Go through the jQuery lessons, for example here: jQuery Tutorial on w3school.com
Also have a look at the left-hand menu which covers different aspects:
- jQuery Effects
- jQuery HTML
- jQuery Traversing
- jQuery AJAX
You only need to know basics of each of these. Once you get the basic idea, it’s easy to dive into it when needed and figure it out.
You can use all that knowledge in WordPress, with exception that jQuery is called via “jQuery” and not “$”.
Also the jQuery is enqueued in a different way. You don’t put <script src=”…jquery.min.js”></script> into header, but you use wp_enqueue_script(‘jquery’);
That topic is covered here: wp_enqueue_script() Code Reference on WordPress.org
Part V.: Template programming – AJAX
- First create a two-level hierarchical category structure on your website.
- Then create a drop down where you select a category (you can surely find the right WP function to do that). Selecting a category there should load another drop down next to it, where you will be able to choose any of its subcategories.
- Use wp_ajax_ hooks for the AJAX handling.
Leave a Reply