From codex.wordpress.org
Plugins are ways to extend and add to the functionality that already exists in WordPress.
The core of WordPress is designed to be lean and lightweight, to maximize flexibility and minimize code bloat. Plugins then offer custom functions and features so that each user can tailor their site to their specific needs.
You have to choose a unique name for your plugin to avoid problems with other plugins you may need to use.
Use a consistent naming convention for your organisation, with a descriptive part.
Example: napier-newsletter {organisation}-{feature}
Plugins can be contained in a single file {plugin-name}.php
Do not use extensively as maintenance is almost impossible, prefer creating more files as requirements can change and your code can get more complicated.
Example: Smashing Magazine: how to create a WordPress plugin
You can create a plugin with multiple files. The directory name and the main plugin file should be called the same for it to work.
Example:
/wp-content/plugins/napier-newsletter/napier-newsletter.php
<?php
/*
Plugin Name: Awesomeness Creator
Plugin URI: http://my-awesomeness-emporium.com
Description: a plugin to create awesomeness and spread joy
Version: 1.2
Author: Mr. Awesome
Author URI: http://mrtotallyawesome.com
License: GPL2
*/
?>
Only the name is required. This has to be in the main file.
A plugin hook is a function you can use to register a specific function to be executed at a specific time in the dispatch loop.
add_action(
'hook_name',
'your_function_name',
[priority],
[accepted_args]
);
add_action ( 'publish_post', 'email_friends' );
A template tag is PHP function used to generate and display information dynamically. This function is defined in the global namespace and can therefore be used in any template file (because of the dispatch loop, plugins are loaded before executing templates).
Example:
function bloginfo('test');
Because the function name is already in use in WordPress, this can be use to override its behaviour.
Never use
wp-content/plugins/
use
plugin_dir_path
or
plugins_url
Never hardcode the table prefix
wp_
use
$wpdb->prefix
Use
wp_enqueue_script()
and
wp_enqueue_style()
to load scripts and css
A shortcode is a small code surrounded by squared brackets that the end user can use when editing content on WordPress, in order to use advanced features or styles.
https://generatewp.com/shortcodes/?clone=video-embed-shortcode
WordPress Widgets add additional content and features to your WordPress site’s sidebars. Examples are the default widgets that come with WordPress — like those for archives, post categories, search bars and custom menus.
You need to create a form where visitors can enter their email address.
Once the address has been validated, store it into your database.
If the address does not validate, display the form again with the email provided in the email field and an error message.
Please version or backup your code, we will reuse this example for the security practical.
Create an administration interface to display the list of addresses.
Create the form as a shortcode embeddable in any post.