Skip to content

Instantly share code, notes, and snippets.

@paleo9
Last active August 28, 2017 13:27
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save paleo9/481a2cec6303f482aef0 to your computer and use it in GitHub Desktop.
Save paleo9/481a2cec6303f482aef0 to your computer and use it in GitHub Desktop.
Wordpress Plugins

Wordpress Plugins

Plugins are typically PHP files that add functionality. Located under wordpress/wp-content/plugins.

A Minimal plugin

wordpress/wp-content/minimal.php

  <?php
          /*
          Plugin Name: Minimal Plugin
          */
  ?>

The plugin named Minimal would be allowed to be installed from the admin page, the file name need not be the same as the plugin name. Hooks are actions or filters. Actions are events. For example, when WP begins to prepare the <head> section for the admin page, the action 'admin_head' is triggered. Using this we could add anything that belongs in the html <head> section such as style information or SEO related meta data.

Wordpress theme and plugin headers

  • Required for plugins and themes.
  • Only the plugin name is mandatory.
  • Order is not important.
  • Must be in UTF-8

Complete list of hooks and filters

[http://adambrown.info/p/wp_hooks/version/3.9] Shows actions and filters, too many to list here.

[http://codex.wordpress.org/Plugin_API/Filter_Reference] Listed under the following titles:

  • Post, Page, and Attachment (Upload) Filters
  • Comment, Trackback, and Ping Filters
  • Category and Term Filters
  • Link Filters
  • Date and Time Filters
  • Author and User Filters
  • Blogroll Filters
  • Blog Information and Option Filters
  • General Text Filters
  • Administrative Filters
  • Rich Text Editor Filters
  • Template Filters
  • Kubrick Filters
  • Registration & Login Filters
  • Redirect/Rewrite Filters
  • WP_Query Filters
  • Media Filters
  • Advanced WordPress Filters
  • Widgets
  • Admin Bar

Header Specification

[http://codex.wordpress.org/File_Header]

  • Headers are written in a block in the beginning of a PHP or CSS file.
  • A block might be placed in a files comment, like a PHP or CSS comment.
  • The whole header block must be placed inside the first 8 192 bytes of the file.
  • Headers follow up to each other, one on it's own line.
  • A header consists of a name and a value.
  • Name and value are separated by the ':' character.
  • The name has a minimum of one, and a maximum of three words.
  • The minimum length of a word is three, the maximum length is 12 characters.
  • A word consists of the characters a-z and A-Z.
  • Words are separated by a single space
  • A name starts after the beginning of a line or after a whitespace character.
  • A name ends before the ':' character.
  • A value starts after the ':' character.
  • Sometimes the ':' character is suffixed by a space. This space is considered to not be part of the value.
  • A header-value can contain any characters but not a newline.
  • Header values might become filtered before they are used.
  • Header values can but must not contain HTML code in form of certain XHTML Elements or HTML Tags.

Plugin header names

[/usr/share/webapps/wordpress/wp-content/plugins]

  • Author (Plugin)
  • Author URI (Plugin)
  • Description (Plugin)
  • Domain Path (Plugin)
  • Network (Plugin)
  • Plugin Name (Plugin) !! Mandatory !!
  • Plugin URI (Plugin)
  • Site Wide Only (Plugin; deprecated in favor of Network)
  • Text Domain (Plugin)
  • Version (Plugin)

Header related functions

  • get_file_data()
  • wp_get_theme()
  • get_plugin_data()
  • _get_plugin_data_markup_translate()
  • _cleanup_header_comment()

Exercise

  1. In a Wordpress installaton, go to the admin pages and enable the 'Hello' plugin. What does it do?
  2. Locate and open the source for the Hello plugin.
  3. What do these PHP functions do?
  • explode
  • dolly_css
  • add_action( 'admin_head', 'dolly_css')
  1. Create the 'Minimal' plugin shown at the start and find it in the admin pages.
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment