Posts
12
Comments
54
Trackbacks
0
WordPress 101 - Plugins!

This blog series covers just a few of the many features of WordPress from a developer's perspective.



"WordPress powers over 25% of the internet..."

If you've never heard of WordPress, you can think of it as the king of content management systems (CMS), allowing individuals and businesses to build and maintain robust websites with relative ease and with very little to no developer experience required. WordPress has a very flexible framework that allows for 3rd party developers to create "themes" and "plugins" that website owners can download and install with most freely available. Themes allow you to completely change the look and feel of your website with the click of a button and Plugins add functionality ranging from full blown online stores to hooking into Google Analytics... really just about anything you can think of.

This article will focus on creating a simple plugin that will display a modal dialog when a user first visits your WordPress site.

NOTE: You may want to download the full sample to be able to more easily follow along.

http://www.holisticstg.com/HolisticsTG_WP_Plugin.zip

What is a WordPress plugin?

"A WordPress Plugin is a program or a set of one or more functions written in the PHP scripting language, that adds a specific set of features or services to the WordPress site. You can seamlessly integrate a plugin with the site using access points and methods provided by the WordPress Plugin API."

From a traditional developer view, what this really means is that this gives us the ability to hook into the framework and extend the base functionality to do nearly anything we want. 

So for example, say you have a client that needs to have their Google Analytics data displayed on an admin area of their website for the regional managers to review. Lucky for you there's a wonderful plugin already created for that and all you have to do is click a few buttons to install/configure and now you're looking like a boss! 

Or say your client tells you they want to capture more leads by asking site visitors to register with their newsletter when they first come to their site. Well I'm sure there's already a plugin that exists to do exactly that, however we'll use this requirement as the basis for our example (minus the newsletter part).

If you have downloaded the sample plugin, let's go ahead and get that installed on your development instance of WordPress, otherwise you can skip ahead to the "Files and Locations" section.

In WordPress, click on the "Plugins" option, or hover and then select "Add New"


Then click "Choose File" and navigate to where you downloaded the sample .zip file and then click "Install Now"


After a few moments, you'll see the following message... let's go ahead and activate the plugin while we're here


Now you'll see our new plugin listed




Files and Locations

All WordPress plugins and associated files are located in the wp-content/plugins/ folder.  For our example, you'll find our files in wp-content\plugins\holisticsTG. In there you'll find one file and one directory that contains 2 more files.

  • holisticsTG.php - our main 'entry point' file if you will for our plugin
  • includes/settings.php - handles saving the options that our plugin uses
  • includes/showpopup.php - does the work of displaying the modal dialog

holisticsTG.php

This file contains the required documentation/metadata as well as the initial code to get our plugin up and running. You'll notice at the top of the file, in the comments section, there is various information that is required by WordPress.


WordPress allows developers to wire into existing "actions", which are simply PHP functions that are executed at specific points throughout the page load/life-cycle. For example there is an action ("wp_footer") that allows you to "hook" into the action so that you can have your own custom function execute when footer information is being displayed.

So the first thing going on here is that the "__construct()" method, which is always called while our plugin is active, is where we are wiring up our functions to hook into existing actions.

So for our example, we need to be able to 1.) display a link in the admin section to allow for customization of our plugin and 2.) add our code that displays the modal dialog when users first visit the site. To display a customization link in the admin menu, we will hook into the "admin_menu" action and for our modal dialog we'll hook into the "wp_loaded" action which essentially allows our modal dialog code to run once WordPress is fully loaded. 

The 'htg_add_menu' function creates a link within the admin section that, when clicked, displays a page that is driven by our "settings.php" file.

The 'htg_wp_loaded' function tells WordPress to execute our "showpopup.php" file every time a page is loaded and WordPress has been fully loaded and ready.

settings.php




showpopup.php




Now that we have our proper files in place, you'll see a link in the admin menu:


Clicking this will display our settings page where the user can configure the text to be displayed in the modal dialog as well as set the plugin to be active or not.



That's it! So now our modal dialog will be displayed only once for each site visit.



For more detailed information visit the WordPress.org support site.



posted on Wednesday, June 21, 2017 7:45 AM Print
Comments
Gravatar
# re: WordPress 101 - Plugins!
Jacob
6/23/2017 6:50 AM
amazing sharing. Thank you for sharing it.
Gravatar
# re: WordPress 101 - Plugins!
Terry Coetez
6/23/2017 9:44 AM
Nice Post.
https://www.snaptubeappz.com/snaptube-for-pc/
Gravatar
# re: WordPress 101 - Plugins!
<a href="https://192168-ll.com/"
6/23/2017 10:58 PM
Nice share! You can seamlessly integrate a plugin with the site using access points and methods
Gravatar
# re: WordPress 101 - Plugins!
UAN Activation Process
6/26/2017 2:40 AM
very nice plugin. can someone tell me how to use it on my website
UAN Activation Process
Gravatar
# HAITSTYLES
anuj
7/3/2017 3:37 AM

Mens haircuts
THANKU
Gravatar
# re: WordPress 101 - Plugins!
Daniel
7/4/2017 6:37 AM
i have question
how can we hide our source page from others
Mcafee Helpline Number
Gravatar
# re: WordPress 101 - Plugins!
Hair Cuts Eugene
7/11/2017 1:44 AM
This seriously is amazing and will be used for my business website lol
Gravatar
# re: WordPress 101 - Plugins!
Sania Khan
7/14/2017 2:26 AM
Thanks for sharing this post
Check Hollywood 18+ Movie
Gravatar
# re: WordPress 101 - Plugins!
MPSC ASO PSI STI 16/7/ 2017
7/19/2017 1:37 AM
visit here
MPSC ASO PSI STI 16/7/ 2017
Gravatar
# For Epson Printers|1-844-653-8777|Epson Printer support
Epson Support Number
8/11/2017 3:12 AM
Thanks for sharing your valuable features and other relevant information.
Epson Support
Epson Support Number
Gravatar
# re: WordPress 101 - Plugins!
anuj
8/16/2017 3:00 AM

[url=http://printablecalendarpro.com/september-2017-printable-calendar-for-free/]september 2017 printable calendar[/url]

Post Comment

Title *
Name *
Email
Comment *  
Verification
Coding strategies for the Java and .Net developer...