There are different WordPress plugins that warrants for some specific options that the users can set. When you want to disable Facebook Open Graph tags for specific posts or the author email at the time of publishing the posts that have you have written, you can implement these both by using different options.
There are several different ways in which you can create different options for yourself. A few of these options may support the frameworks available as well. There are also a few simple options that are easier to use.
However, you should always follow an object oriented approach but that should be simple at all times. The first thing that you will need to do is create a menu entry in the backend. On this menu entry you should place your settings user interface.
The specific steps that you need to follow in this involve:
- Adding action menu which can be the admin menu or the my plugin menu
- Include the function my plugin menu and
- Add the menu page according to the My Plugin Settings, Plugin Settings, administrator, or dash icons.
You must note here that the WordPress views the admin menu hook as all functions tied to it while building the menu.
The different arguments
You can use the add menu page to create a menu entry at the top level as your digital strategy. This is a special function that will take on different arguments such as:
- Page title: This is used in the title tag of the page that is typically shown in the browser bar when displayed
- Menu title: This is the menu on the left
- Capability: This indicates the user level that is usually allowed to access the page
- Menu slug: This is used for the page in the URL
- Function: This is the name that you will be using in order to output the page content
- Icon: This is the URL to the image or the Dash icons string
- Position: This is where your item will be in the entire menu.
You can create an empty function and add the content of this function. At this stage you will be able to see your new menu entry at the bottom of this menu.
Create the user interface
At this stage you will need to create the user interface that will enable you to manipulate the settings. This is the process that is called registering the settings. For example, if you want to create a place to store all contact information of a few of your key employees who are not a part of the web project such as an accountant, the process that you need to follow includes:
- Adding action
- Function my plugin settings
- Register setting for the name of the accountant
- The phone number and
- The email address.
However, you can add other options but you must stick to the first parameter of adding an option group and the second of adding an actual option. You can use the same option group if you have only a few options.
The WordPress Codex
There may be times when you will not know whether or not you should use an admin in it and in such situations the WordPress Codex will help you a lot of course! There may be times when you will find that using the hook is the most obvious options but at the same time there may be a few instances when you will need to look up for it.
In addition to that, there may be cases when you will have to use different hooks to retain the functionality of the site. In such situations, you are advised to use the search in the Codex before you use a hook.
The next step is to create a form to display your user interface. When you reach this stage there are three specific things that you need to keep in mind. These are:
- Using the settings fields function and adding the option group as your first parameter because this will output the hidden fields WordPress that you can use to save your data
- Using the option names that you have used to define while registering these in the different parameters of the inputs and
- Grabbing the value of a field using the get option function by passing the option name as your first parameter.
With all that done you are ready to go. WordPress will take care of the rest provided you are using the Options API built in it.
While creating WordPress plugins, enabling translation is definitely not a priority but it is always a good idea to get into the habit of it. This will ensure translation readiness of your site which is ideally the best practice for any public plugin.
- The basics here are really very simple. At any time you output some text make sure that you wrap it in either the __() function or the _e() function. If you use the former function it will enable you to return to the string and if you sue the latter, it will help in echoing it.
- The first option will allow the string to translate and on the other hand the second will represent the text domain. However, this should be the same as it is in your plugin slug.
- When you use these specific functions it will allow you as well as the others to translate the plugin into the respective language preferred.
This is ideally a simple process that will help you to translate plugins in the most effective, faster and safer manner.
There are literally a large number of things that you can do WordPress plugins. All you have to know is how to create them and use them just for your benefits. You will need to follow an object oriented approach but there is no harm in experimenting.
You may do whatever you feel like with WordPress plugins as long as you are not creating a product for distribution. There are lots of simple as well as complex methodologies that you can follow but you will need to understand it first.