Check Your Internet Speed

WordPress Plugin Development

The WordPress CMS has changed the face of our Internet and allowed a surge of new ideas to prosper and its open source movement holds a strong presence rooted in software and web development. WordPress is a blogging platform which has the ability to launch into many other scripts such as web forums, job boards, and even a classic webpage Content Management System.
wordpress plugin development
We’ll be going over a few ways to get started in plug-ins development for WordPress. The steps are fairly simple and don’t require a large dedication to study. Rudimentary knowledge of PHP would be useful even with a basic understanding of the WordPress file structure and Administration panel.
In this brief tutorial we’ll be going over the basic steps required to create a simple WordPress plug-in. The functionality will be used to create dynamic excerpts based on the number passed into our function call. You’ll need to upload the plug-in file and activate from the Admin panel, then follow up by calling our function from whatever pages we want the excerpt to appear. Links to completed plug-in source code is already added later in this article :)

Why Develop for WordPress?

Plug-ins are a great way to enhance the functionality of your blog by adding in extra features. These can be placed anywhere inside your template by function hooks. Over time the extensibility of WordPress’ plug-in system has allow tremendous growth and hundreds of developer-submitted pieces of software.
WordPress specifically offers such advanced features in its CMS that unique plug-ins are few and far between. As a developer you hold complete control over the backend specifics of your weblog. Hiring a PHP developer to create a system plugin would cost a lot more than you may imagine and the API is fairly easy enough to work with and learn yourself.
wordpress codes
As a secondary argument, developing over WordPress is great practice for tuning yourself into other areas. Building smaller plugins and sidebar widgets in WordPress will help you develop an understanding of how the backend system really works. This isn’t just limited to WordPress as you’ll gain a deeper understanding of the vast majority of Content Systems.

1. WP Folder Structure

An introduction into the WordPress folder structure will show the basic app directories. Inside wp-content you’ll find a plugins directory. In here is where all of your individual plug-ins will be housed, either single files or properly named sub-directories.
For smaller plug-ins which only require a single .php file you have the option to place this directly into the plug-ins/ directory. However when you start developing more complicated applications it’s much more useful to create a sub directory named after your plug-in. Inside you can house JavaScript, CSS, and HTML includes along with your PHP functions.
Wordpress Directories for Plugins
A readme.txt file can also be useful if you’re planning on offering your plugin for download. This file should include your name and what the plugin does. As the author you may also consider including details about each revision and which updates have come out.

2. Starting your PHP File

When creating a new plugin you’ll need to start with a simple PHP file. This can be named anything but should generally reflect your plug-in’s official name. So for example I have created our base code and have named my file hongkiat-excerpt.phps.
The first lines of your plug-in must be comment information for the parsing engine. This is extremely important as WordPress will be unable to process your file without. Below is an example code snippit you can copy and mold towards your own.
<?php
/*
Plugin Name: Plugin Name here
Plugin URI: http://www.yourpluginurlhere.com/
Version: Current Version
Author: Name please
Description: What does your plugin do and what features does it offer...
*/
?>
The Plugin Name is what will show up in your Admin backend panel when you go to activate. Same with the URI which will be placed in the details pane inside the plug-ins panel. Although it’s not required to include a version or description it does make your plugin look much more professional.

3. WordPress Naming Conventions and Best Practices

There are a few ways to actually structure your plug-in. Many times PHP developers will create an entire class system in order to avoid collisions with functions and variable names. If you are unfamiliar with the advanced OOP functionality of PHP then it’s best to just write your code in sample functions.
So for our example code we will write a single function to house our data. We also need to define a few variables which are key to implement inside our template files. Below is an example bit of code taken from our plugin file with the core logic removed.
Mobile WordPress for iPhone
When writing your sample code it’s best to follow regulations and guides set up by WordPress. Since there are so many internal functions already defined you can avoid duplicates by prefixing a label to all your variables and function names.
<?php
define("exampleVariable", "this is a value");

function hk_content_example_function( $limit ) {
  // some code goes here
}

?>
In the above examples we prefixed all our setting names with hongkiat. This can be replaced with any keyword of your choosing usually related to your plugin name. The above code is just sample settings and shouldn’t pertain to our final plug-in. This is just to give you some insight into how your variable names and function calls should be written.

4. Diving Into Filters and Actions

There is another concept noteworthy of mentioning before we jump into our raw code. Actions and filters are two completely different concepts which relate deeply in the ways they manipulate plugin data.
These two bits of code come standard within the WordPress API. Filters and actions allow for plug-in developers to update bits of code throughout the WordPress admin panel pertaining to your new plug-in. This means you could add a new tab in the sidebar or additional settings links for your Plug-in options.
CodeLobster PHP IDE

Source:hongkiat.com

0 comments:

Post a Comment

Websites Resources | Blogging | Technology News | Softwares - i Developments