Creating Simple:Press Plugins: Hello World!

Introduction

This is the first in a series of articles that will cover how to create Simple:Press plugins. It requires that you have some familiarity with creating and deploying standard WordPress plugins. If you understand the WordPress plugin building process then a Simple:Press plugin just requires building upon that knowledge.

Creating a Simple:Press plugin generally requires that you hook into the Simple:Press logic flow to display data or act on data as you need.

So, lets go ahead and build our first Simple:Press plugin!

Getting Started

First, you need to create a text file that forms the basis of your plugin. Lets call it sp-hello-world.php.

In that file you should first add a comment header that is very similar to a regular WordPress plugin header. The format and data in the comments tell Simple:Press and WordPress some critical data that bootstraps the plugin.

/*
Simple:Press Plugin Title: Hello World
Version: 1.0
Plugin URI: https://perftesting01.wpvix.com
Description: A Simple:Press plugin for displaying "Hello World" in specific locations (demo plugin)
Author: Andy Staines & Steve Klasen
Author URI: https://perftesting01.wpvix.com
Simple:Press Versions: 6.0 and above
$LastChangedDate: 2018-08-15 05:57:46 -0700 (Wed, 15 Aug 2018) $
$Rev: 15706 $
*/

With the above sample header, you indicate the user friendly name of the plugin, its version number, a website where the plugin can be found, the description that will be shown in the Simple:Press plugins page and so on.

When Simple press reads this file from the plugins directory, it will register the plugin and make it available for users to activate. Once activated, any code within the plugin will be executed on every page load. If there are no hooks into the WP or SP code rendering, nothing will occur for the plugin execution.

Make It Do Something

Right now all our file does is load up in the Simple:Press system but it doesn’t really do much. So lets make it do something now. Lets make it display HELLO WORLD in various locations around the forum.

First, we will define three places to display the phrase. These are defined using Simple:Press WordPress style action hooks:

add_action('sph_BeforeDisplayStart', 'sp_hello_display'); # before the forum display starts
add_action('sph_HeaderEnd', 'sp_hello_display'); # after the forum header section
add_action('sph_AfterDisplayEnd', 'sp_hello_display'); # after the forum display ends

The first one is used to output our string before the forum display begins. The second one will display the string after we have displayed our standard forum header. And finally the third one will display once all forum display has completed.

The standard WP API add_action() function adds a function to call, sp_hello_display(), when the listed action is fired.  In this case, for all three added actions, we will call our own function sp_hello_display() to write out our string.  This function looks like this:

function sp_hello_display() {
	echo '<p>Hello World...</p>';
}

The Full Plugin

Believe it or not, you have all the components now for a Hello World plugin! Here is the full code – you can copy and paste this into a text file, save it, zip it up and upload it to the Simple:Press Plugins screen!

<?php
/*
Simple:Press Plugin Title: Hello World
Version: 1.0
Plugin URI: https://perftesting01.wpvix.com
Description: A Simple:Press plugin for displaying "Hello World" in specific locations (demo plugin)
Author: Andy Staines & Steve Klasen
Author URI: https://perftesting01.wpvix.com
Simple:Press Versions: 6.0 and above
$LastChangedDate: 2018-08-15 05:57:46 -0700 (Wed, 15 Aug 2018) $
$Rev: 15706 $
*/

# dont allow calling the plugin file directly
if (preg_match('#'.basename(__FILE__).'#', $_SERVER['PHP_SELF'])) die('Access denied - you cannot directly call this file');

# need an action for where we want to hook into in order to display the Hello World string (3 examples)
add_action('sph_BeforeDisplayStart', 'sp_hello_display'); # before the forum display starts
add_action('sph_HeaderEnd', 'sp_hello_display'); # after the forum header section
add_action('sph_AfterDisplayEnd', 'sp_hello_display'); # after the forum display ends

# display Hello World string when actions fire
function sp_hello_display() {
	echo '<p>Hello World...</p>';
}

Wrap Up

There you have it. A very simple plugin to display the phrase Hello World in three locations. By using a standard WP or SP hook, there are literally hundreds of locations this could be done. This plugin simply highlights three of them.

We encourage you to peruse the Simple:Press core plugin code to find more action hooks where you might possibly display the Hello World phrase and add it to this plugin!

Read Next

Did you find this article useful? Or do you use Simple:Press today?  If so, please support Simple:Press with a review on WordPress.org.  Every review goes a long way towards bringing other users on board!

Click here to review Simple:Press on wordpress.org

More From Simple:Press

What’s New In Simple:Press Forums 6.6.0

September 9, 2020

Simple:Press Forums 6.6.0 introduces two new major features and a lot of improvements to one of the existing features. And, of course, some bugs were stomped.

Read More

How We Increased Performance On Our Site By 300%

July 4, 2020

A few days ago we moved our site from Liquid Web to our new FireupWP and WPCloudDeploy project platform. This new platform allows us to use dedicated cloud VMs from places like Digital Ocean, Linode and Vultr. We pay the cost of the VMs with no markup which provides huge savings over regular hosts. We…

Read More

New Simple:Press Forum Theme: Modern 2020

March 5, 2020

A new default theme is coming to Simple:Press Forums with the release of Simple:Press Forums 6.5.0. Features of this theme: More modern looking with larger default font sizes and button sizes. Less use of tiny icons More color customization options Better display on mobile More white space Just like our previous default theme, Barebones, you…

Read More

Now Available: SPMS Version 2.7

January 10, 2020

Version 2.7 of Simple:Press Member Subscriptions is now available. It includes more than two dozen fixes and tweaks.

Read More