Wordpress Logo

If you use a large amount of categories on your WordPress site, you will find that things get very very messy with a huge amount of categories showing up in the input box. One brilliant way to resolve this is to use a plugin called Intuitive Category Checklist. The good side, is the plugin creates a collapsible tree for all of your categories, the bad side is that you cannot add new categories when using the newer versions of wordpress. The plugin has been abandoned for over 2 years now, so its unlikely that we are going to get an update for this. We are going to have ot take matters into our own hands to maintain this awesome plugin!

Before making any changes to the live file, please make a backup in the event that something goes wrong. Go to your plugin directory and open up the file called “intuative-category-checklist.php” inside the plugin folder. Replace the entire contents of the file with the code below and it should resolve the issue with not being able to add new categories in the edit page.

Adding new categories, will show up at the top of the category box. While they do appear to have ignored the hierarchy of the categories, everything is fine. Its a visual issue, if you refresh the page everything will show up correctly. If anyone wants to work on a fix for this let me know in the comments below and i will update this post.

 

Wordpress Logo

Most guides on how to add a custom PHP page in WordPress will explain how to do it using a template in a theme, but this is a restrictive method of adding a custom PHP page to WordPress. It’s actually quite easy, perhaps slightly inefficient, to dynamically create a custom template for a WordPress theme. If you add a custom PHP page to wordpress using a plugin you only need to write the code once and it works for every theme.

The main goal here is to create a PHP page where you can generate any content you like. For this I wanted to pull data from a database outside of WordPress and I didn’t want to create a theme template for dozens of themes. By adding it in the plugin level you can create the page once and call the theme to render the content. There are some rules that you need to follow in order to do this and there may be some further tweaks that need to be made to cover all kinds of themes. I have tested this and it works with all of the themes that I have tested. Some of the steps here might seem unneeded, but I had to add them in order to make the code work with all themes that i tested with.

 

The first thing you need to do is have a plugin to use. Create a file in this plugin called test.php. The page does not need to be a part of the plugin at all, it just needs to be in the plugin directory so you can easily move it around to other WordPress installs. By default your theme will have a default query. Some themes will just pull a random post and others will generate a post feed. There is no way to prevent this, so instead we need to override the global variables to change it. This is the part that’s a little inefficient, but as you probably know, breaking the WordPress loop isn’t something you want to dig into.

The code below will call the blog header. This will start the loop and leave you with some global variables that contain data that your theme will then display. You need to override this data with your own custom data. This sort of acts like data injection. If anything this is like a custom hook. Once you get the global variables needed, you can do whatever you like with them.

If we override all of the relevant data within these variables we can let our theme do all the hard work of rendering the content correctly. This allows us to produce content that matches the look and feel of our website without having to write css for each theme we want to support. To see what is inside each variable you can use a var_dump();

The first thing and most obvious is to override the $post variable. Put whatever you want inside these variables. Hard code them, pull them from an API or get the data from a different DB. Doesnt matter where it comes from, so long as it overrides the existing data.

We have now overridden the global $post variable with our own custom content. This is normally enough for most themes. The theme will display this post and you wont need to do any additional work. Unfortunately the default method of displaying a post, which a lot of themes use, will first print this post and then also display a bunch of other recent posts.

Some themes will use the $wp_query objects via the have_posts() and get_post() methods. This will get the content for $post from $wp_query. We are going to have to override this variable if we want to stop the list of posts from displaying. The following code will override any arrays and variables that contain multiple objects.

This should be everything that you need to make themes display the posts correctly. If you find there are themes that need extra work please post in the comments and i will update the post.

The final thing to do, now that we have armed all of the global variables, is to call the default page.php to display our content. We want this to be dynamic so we will get the current theme directory from WordPress. All themes will contain a page.php, so we can be confident that this will work for us.

All of the code above will allow you to add a custom php page to WordPress using a plugin that is completely dynamic. You will not have to modify a theme at all, this code will handle everything through the plugin. Please post any issues or suggestions below so I can make this post as efficient as possible.

Wordpress Logo

Content filters are used to display some data at a specific location in a post. For example, if you wanted to display some data at the end of every single post on your blog, you could use a content filter and it would allow you to do this. You will need to be able to write PHP code in order to do this. If you follow my full WordPress Plugin Tutorial you should be able to build an entire plugin from start to finish without too much trouble.

So to start off, you will need to have your own custom plugin created. If you do not know how to do this, follow my guide on creating a WordPress plugin template. A plugin is very simple to create, so don’t worry if you aren’t particularly strong at programming in PHP.

Step 1 – Register The Content Filter In The Main Plugin File

Open up your plugin and go to the main php file (usually the same name as the plugin itself) and you can add the filter that will use “the_content” as the data that will be filtered. This means that when wordpress is loading the page and it comes to the point where it loads the content of the post, it will check to see if there are any filters that have been added. If it finds a filter for “the_content” it will run the function that is defined in the filter.

The following code will add a filter that is triggered when WordPress is loading the post content and it will then call a function called myinfo_filter().

Step 2 – Create The Filters Function

In order to make this code work we are going to need to create a function called myinfo_filter. The function is just a standard PHP function that will have 2 simple requirements. It must accept a variable that contains the content of the entire post and it must also return the content for the post.

When WordPress reads the code above it will call a function called myinfo_filter and it will give this function all of the content from the post. If you do not return any data the post will show up blank. If you do not add the function you will get a fatal exception. So lets add a simple function that will append some data onto the end of the post.

This function will accept the content from the post and if this is a single page ie. a post. it will add ” CUSTOM CONTENT!” onto the end of the post. This will show up for every single post on your blog. You can add some more advanced logic here to append something more substantial to the end of the post.

You could also append the data to the start of the post by doing the exact same thing except putting the data at the start.

 

Save the file and your filter should now be adding content to the end of your post.

Creating a wordpress plugin is a lot easier than it might first seem. As long as you know how to write PHP code (or any similar language) you should be able to get a plugin together pretty quickly. The aim of this tutorial is to show you how to create a basic template for a plugin that will show up in the WordPress plugin menu.

Start by navigating to the plugins directory for your WordPress install. This directory is located at “wp-content/plugins/”. In this directory create a new folder named after the plugin that you want to create. E.g. “plugin-test”. Inside this directory create a php file with the same name, so “plugin-test.php”. Open up this php file and add the following code.

Save this file and that is it. You now have a plugin template created. You don’t need to do any additional work to register this plugin with your WordPress install. If you open your web browser and log into your WordPress install. Go to the plugins tab and you will see that the test plugin that you just created now shows up on this list. You can activate the plugin, but it will not do anything as you have not added any code to the plugin.

Now that you have an active plugin registered within your WordPress install, you can start adding any custom features that you want.

Had a look around online and couldnt find any decent SMTP plugin for sending and receiving emails through wordpress. Seems like it makes a lot of people angry for wordpress to do such a thing which seemed odd, so I decided to start working on one myself.

The goal of this plugin is to add the following functionality to the wordpress dashboard.

  • Send Emails
  • Receive Emails
  • Log into any user inbox using SMTP servers user authentication.
  • Create WP database to log emails and better manage them.
  • Parse and display any email information.
  • Setup email blasts for newsletters.
  • Basic spam filter
  • Adminbar notifications for unread emails.

The wordpress side of things is the easy part so I have put the effort into extracting the emails from the IMAP server from a wordpress plugin. It took quite a bit of work to get this to display any useful information, but after a while I started to make some good progress on this. Using a linux server with postfix and dovecot installed as the SMTP and IMAP servers I was able to use PHP to pull the latest emails for an individual user.

Here is the base inbox page that lists the latest emails. This is going to need major touch ups to style, but I want to get the functionality working smooth before making it look pretty.

Wordpress Email Inbox

WordPress Email Inbox

 

This inbox page is a bit messy, but its working! The next thing was to be able to view the actual email body. This is also crazy messy, but it works and thats all that matters for the moment. I have listed the emails and dumped the email body below. Attachments still don’t show up, but the core components are correctly displaying.

Received Emails With Body

Received Emails With Body

The next stage to this would be making this a little more user friendly so emails can be read much better. I will create individual “view email” pages that will display the email and hopefully any attachments. I will work on adding controls to this page that will allow for replies, forwarding, attachments etc.

I do see some potential issues in the future with this. While it is working perfectly on my server, I am not confident its going to work straight up on another server that’s running a different operating system/mail server. Once i have a stable version of the plugin I will try to get a few people to test this out on various servers. I will work on creating a quick setup tool that will try to test various config options in order to determine what one will work best for the particular system. The install of php-imap and mail servers are requirements in order to make this work.

I’m very surprised this hasn’t been done in the past. WordPress is a CMS, but with the evolution of the web I for one would like to have everything related to my website kept in one area. Why go to a roundcube install or anything else when you can just do everything that you need to do within wordpress?