Wordpress website plug-ins preliminary design

Disclaimer: This article is a blogger original article, shall not be reproduced without the bloggers allowed. https://blog.csdn.net/leon_zeng0/article/details/88984151

If you are familiar with Wordpress, should be very familiar with the plug-ins (plugins), plug-in extensions and add wordpress functions. We often Wordpress panel installation, activate, deactivate, remove the plug, wordpress there are many, many plug-ins, we can search, but sometimes we need a function is not, or is not, then we need to design their own plug-ins.

Plug-ins Introduction:

WordPress itself consists of a relatively small set of functional components, these features collectively referred to as the "core" of the platform. Plug-ins are downloadable additional components, comprising a core function of the extended or altered files and code. In fact, WordPress philosophy that if a function may be less than 80% of the users, it should be included in the core. Otherwise, it should be a plug-in.

For this reason, a wide range of possibilities provided by the plug is enormous. You can use them to add opt-in form, slider or pop-up window. They can be very simple, e.g. Hello Dolly, it displays the name of the song random row in the dashboard. Or they can be incredibly extensions such as Jetpack plugin, which adds many new features and settings for your site.

This fact means that plug-in is one of the most important functions of WordPress. They can easily add to your site almost any function, without coding or prior knowledge. More importantly, download and install the plug-in is as easy as a few clicks.

The last part is important to remember that. Because WordPress is open source and plug-ins, so their code available for anyone to use and test. For budding developers, this is a good way to understand the work behind the scenes, and participate to create their own plug-ins.

The difference between the plugins and themes


Before we begin to learn, we need to quickly introduce some important groundwork. First, let's talk about the differences between the themes and plug-ins. On the surface, this seems to be a noticeable difference. Of course, a theme just change the look of your site, and a plug-in adds functionality?

However, the fact is more vague than that.

In fact, the theme can also change the functionality of the website, and plug-ins can change its appearance. All functions.php WordPress theme contains a file that contains the code to add functionality to your website. This plugin works very similar. In fact, you can add the same code to the plug-in or functions.php, the same will run on your site.

The difference is that, when you add the code to functions.php, it will be linked to your current theme. If you want to change the theme of some features or want to quickly add functionality without having to write the whole plug-in, which will be very useful. If you want to create a theme and you want to insert custom functions, you can also use this method.

However, if you decide to change the topic, you add the code will no longer be valid. On the other hand, plug-ins are separate entities (usually) does not depend on any particular topic, which means you can switch themes without losing function plug-ins. Instead of using the plug-in themes can also function you want to create easier to maintain and share with others.

Plug-in works: hook, action and filters Introduction


We have already mentioned plug-literally "plug in" to WordPress core. As used herein, 'hooks' completed, a code which allows to interact with another code. Therefore, the hook determine when and where the actual use of plug-ins on your site.

Let's consider an example: Imagine if someone tries to use the wrong password site, you will see an error message that a change of plug-ins. In this case, the error message is a hook. The code plug may be connected to display the message, and change the displayed text.

WordPress can understand both types of hooks. they are:

(actions) actions: These are used to add or change WordPress function.
(Filters) Filters: These filters are used to change the function of the operation.

How to create the first WordPress plugin (four steps)

Now use a minimal amount of coding to create the first plug-in. Therefore, we will insist on some basic things. In the following steps, we will create a plug-in that will display some text after the subscript.

Step 1: Set up a test environment

The development of any content, whether it is to create a plug-in or other changes that may affect the site, you should always use a test environment. This is also called "staging site" or "local environment", depending on the site is on an external server or your own computer stored.

Regardless of the position, the test environment should be a private copy of the site. This allows you to add and edit files and features of the site, the site does not have actual real-time damage. When you use the core files and plug-ins, which is particularly important, because errors may cause permanent damage to your site.

Fortunately, due to the wide variety of tools to help you, so set up a test site it is very simple. To set the local environment, see the  Wordpress website design entry 0 Local Web host installation

Step 2: Create a new plug-in file

To start a new finishing plugin, you need to access the directory of your site. You can use SFTP, you can use Wordpress panel, you need to install plug-in file management, see the  Wordpress website design file manager plug-ins . Commonly used to sftp client FileZilla, because it free and easy to use. If it is a local direct Explorer.

Navigate to the site. After entering, navigate to the folder containing the folder plug, the plug is located in / wp-content / plugins /.

Add a new plug-in, you need to create a new folder in this directory. To do so, and give it a name. Here is veryfirstplugin.

Then build a new file in this directory, named veryfirstplugin.php

Edit the file to read as follows:

<?php
/**
* Plugin Name: Very First Plugin
* Plugin URI: https://www.yourwebsiteurl.com/
* Description: This is the very first plugin I ever created.
* Version: 1.0
* Author: Your Name Here
* Author URI: http://yourwebsiteurl.com/
**/

Before you save the file, change the information herein at any time to meet your exact details. 

Once complete, you can actually see the plug-in management dashboard site. Sign in now and see your plug-in library.

You can continue even now to activate your plugin. Of course, the plug-in does not actually do anything. That's because we did not add any functionality.

Step 3: Add code for the plug

This is a used to display text in the footer of each page after the sample plug-in code for
this plugin hook up wp_footer () action hook, before calling it at the end of each page </ body> tag. And added a function called mfp_Add_Text () of. The content of the function is simply show: After the footer is loaded, my text is addded!

Because it is linked to wp_footer, so that after the subscript display line content. Open any page is displayed foot targets.

Since this is not part of the theme widget so if activated entirely different subject, it will continue to be valid.

// Hook the 'wp_footer' action hook, add the function named 'mfp_Add_Text' to it
add_action("wp_footer", "mfp_Add_Text");
 
// Define 'mfp_Add_Text'
function mfp_Add_Text()
{
  echo "<p style='color: black;'>After the footer is loaded, my text is added!</p>";
}

Step 4: Export and install the plug on the actual site

The new plug-in is now available on the live site. Fortunately, this step is often the simplest. Need to do is to first-first-plugin folder compressed into a ZIP file. If you use the local environment to create plug-ins, you can simply right-click the folder and select "compression."

You can then upload this zip file to your actual site. Open WordPress administration dashboard, navigate to the plug-in, and then click Add New.

wordpress dashboard plugin menu

On the next screen, you can choose to upload the plugin, and then select the plug-in files from your computer.

Of course, our code is not suitable for upload, just an example.

We look at the effect of running the red box is the text we show:

Now and then the entire contents of the documents, posted here, you make a simple reference.

<?php
/**
* Plugin Name: Very First Plugin
* Plugin URI: https://www.yourwebsiteurl.com/
* Description: This is the very first plugin I ever created.
* Version: 1.0
* Author: Your Name Here
* Author URI: http://yourwebsiteurl.com/
**/
// Hook the 'wp_footer' action hook, add the function named 'mfp_Add_Text' to it
add_action("wp_footer", "mfp_Add_Text");
 
// Define 'mfp_Add_Text'
function mfp_Add_Text()
{
  echo "<p style='color: black;'>After the footer is loaded, my text is added!</p>";
}
?>

Reference  https://www.hostinger.com/tutorials/how-to-create-wordpress-plugin , debugging is made.

Guess you like

Origin blog.csdn.net/leon_zeng0/article/details/88984151