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