In this example we explain how the oik-mshot plugin extends the custom field types, adding the mshot
field type.
Example mshot
This is an example of an “mshot”… produced using the [bw_mshot] shortcode.
This plugin uses the WordPress mshots service to obtain these screen captures.
The [bw_mshot] shortcode will dynamically display the latest (cached) image.
The “mshot” field type is used to store the required URL, then perform “mshots” processing when the field is required to be displayed.
In the current version there is no local cacheing of the image.
Initial load
When the oik-mshot plugin is loaded the following is executed:
You appear to be a bot. Output may be restricted
oikms_plugin_loaded();
This function attaches action and filter hooks.
You appear to be a bot. Output may be restricted
function oikms_plugin_loaded() { // "oik-fields" hooks add_action( "oik_pre_form_field", "oikms_pre_form_field" ); add_action( "oik_pre_theme_field", "oikms_pre_theme_field" ); // other "oik" hooks add_action( "oik_query_field_types", "oikms_query_field_types" ); add_action( "oik_loaded", "oikms_loaded" ); add_action( "admin_notices", "oikms_activation" ); add_action( "oik_admin_menu", "oikms_admin_menu" ); }
Click on the links to visit each action / filter hook or the implementing APIs. Note: We’re showing all of the code here. The first two hooks are needed to allow a plugin to extend the supported field types. Below is a brief explanation of each action / filter.
Action hook advising plugins that it’s time to provide the functions to display the input form fields for any supported fields types. This hook is only invoked once – when it’s time to display form fields.
You appear to be a bot. Output may be restricted
/** * Implement "oik_pre_form_field" for oik-mshot */ function oikms_pre_form_field() { oik_require( "includes/oik-mshot.inc", "oik-mshot" ); }
oik-mshot simply loads the file that implements the functions. In the current implementation these are dynamically named hook functions.
Action hook advising plugins that it’s time to provide the functions to theme any supported field types. This hook is only invoked one – when it’s time to theme fields.
The following hooks are not part of oik-fields processing.
Note: This is actually a filter hook invoked by oik-types It requests plugins to identify the field types that they support, so that the end user can define a field of this type.
Tells the plugin that the oik base plugin has been loaded. It’s therefore safe to define the [bw_mshot] shortcode as a lazy smart shortcode – using bw_register_shortcode().
Used by this plugin to call oik_register_plugin_server() – advising the oik base plugin that this plugin’s updates do not come from wordpress.org but elsewhere.