Plugin Development Flashcards
function update_option
Used to create or update a new key in wp_options table
Accepts name of key to create or update, and the vale that needs to be stored in it
init action hook
Fires after Wordpress finished loading but before any headers are sent
Accepts name of custom function to callback
Good stage to set values needed for the plugin to work, like custom post types and taxonomies.
What is a text domain
Unique identifier that helps Wordpress to distinguish between different translations of this plugin.
Domain name should be the name of main plugin file without extension.
Must use dashes, not underscores
Function __()
Used to demote text elements that can be translated into other languages.
Function register_post_type
Used to register new post type
Should be called within init action hook
Its value is stored wp_posts post_type field
Accepts name of the post type and arguments / settings.
admin_menu action hook
Used to add menu pages to admin
Accepts name of the callback function that will be called to create the menu
Function add_options_page
Adds submenu item under dashboard > settings
Accepts page title tag, menu item’s anchor text, user capability, slug, callback to output HTML form of the settings page
Function get_option
A safe way of getting value of a saved option from wp_options table
Accepts name of the key whose value to retrieve
Function _e()
Same as __(), but in addition to making it translatable, outputs the vale to screen
Function settings_fields
Accepts name of settings group
Should be called before register_setting functions
Is called inside of options html form
Tells register_setting that once submitted the group name should be matched with group name in register setting! and if matched values should be saved in the right option key.
Function esc_attr()
Should be used to sanitize vales of HTML attributes
Function sanitize_text_field()
Does the same as esc_atts, but is used for the actual values that come from input tags. Good to use before display and before querying the database.
add_meta_boxes action hook
Runs whe edit post screen is loaded
Used to construct custom meta fields for a post
Function add_meta_box()
Allows plugin developers to add meta boxes to edit / create post screen
Should be called from add_meta_boxes action hook
Accepts ID attribute name of wrapping element, section heading, callback that prints the HTML form, screen - name of post type, context - section of the page
Function get_post_meta
Retrieve post meta fields
Requires ID of the post
Returns either all meta associated with post, or just meta of specific key
Data is pulled from wp_postmeta
Function wp_nonce_field
Used to ensure that data sent for saving comes from the actual form and not somewhere else.
Accepts action name that describes what this form does, and nonce name, which can be anything
Function selected()
Used in select options, checks two values given, and if they match selected attribute is added.
save_post action hook
Runs when a post or a page is created or updated
The callback function gets ID of the last saved post
Function get_post_type
Retrieves the post type of the current or given post
Returns a string that matched post_type field of wp_posts table.
Function wp_verify_nonce
Checks if data sent comes from the actual site and form, and not somewhere else. Should be passed action and name set earlier by wp_nonce_field.
Function array_map()
Accepts call back function that will be applied on each value of the array passed to it, such as sanitize_text_field. Returns array with values sanitized.
Function update_post_meta
Queries database
Either creates or updates wp_postmeta table
Accepts post ID, name of the key, and value
What is a shortcode
Placeholder you add to content that is replaced by Wordpress with other content. Can be with or without attributes
Function add_shortcode
Used to add replace code macros with the actual content
Accepts tag and callback function
What’s a widget
Widget is a small program that allows users to easily add plugin info into sidebar or any other widgetized area.
widgets_init action hook
Triggered right after all default widgets are built
Function wp_parse_args()
Merges user defined arguments into $defaults array, and returns updated array with default keys overwritten.
function register_activation_hook
Is run when plugin activated
Says which function to call upon activation
Accepts full path to main plugin file and name of the custom function to run