Documentation
Documentation
graphic_data_plugin.php
The plugin bootstrap file
This file is read by WordPress to generate the plugin information in the plugin admin area. This file also includes all of the dependencies used by the plugin, registers the activation and deactivation functions, and defines a function that starts the plugin.
Tags
Table of Contents
Constants
- GRAPHIC_DATA_DATA_DIR : mixed = \WP_CONTENT_DIR . '/data'
- The data directory inside of wp-content
- GRAPHIC_DATA_DATA_URL : mixed = \content_url('data')
- GRAPHIC_DATA_IS_ACTIVE_THEME : mixed = \get_template() === 'graphic_data_theme'
- Determine whether the Graphic Data Theme is the active theme.
- GRAPHIC_DATA_PLUGIN_DIR : mixed = \plugin_dir_path(__FILE__)
- The directory path of the plugin.
- GRAPHIC_DATA_PLUGIN_VERSION : mixed = $graphic_data_plugin_data['Version']
Functions
- graphic_data_activate() : mixed
- Plugin activation callback.
- graphic_data_deactivate() : mixed
- Plugin deactivation callback.
- graphic_data_ensure_public_data_dir() : void
- Ensure the public data directory exists with correct permissions.
- graphic_data_register_blocks() : mixed
- Register the blocks in the plugin.
- graphic_data_register_figure_block_meta() : mixed
- Register the figure fields for posts.
- graphic_data_register_figure_block_routes() : void
- Registers REST API routes for the figure block.
- graphic_data_get_figure_block_meta() : WP_REST_Response|WP_Error
- Retrieves figure block meta fields for a given post via the REST API.
- graphic_data_plugin_run() : mixed
- Begins execution of the plugin.
Constants
GRAPHIC_DATA_DATA_DIR
The data directory inside of wp-content
public
mixed
GRAPHIC_DATA_DATA_DIR
= \WP_CONTENT_DIR . '/data'
GRAPHIC_DATA_DATA_URL
public
mixed
GRAPHIC_DATA_DATA_URL
= \content_url('data')
GRAPHIC_DATA_IS_ACTIVE_THEME
Determine whether the Graphic Data Theme is the active theme.
public
mixed
GRAPHIC_DATA_IS_ACTIVE_THEME
= \get_template() === 'graphic_data_theme'
GRAPHIC_DATA_PLUGIN_DIR
The directory path of the plugin.
public
mixed
GRAPHIC_DATA_PLUGIN_DIR
= \plugin_dir_path(__FILE__)
GRAPHIC_DATA_PLUGIN_VERSION
public
mixed
GRAPHIC_DATA_PLUGIN_VERSION
= $graphic_data_plugin_data['Version']
Functions
graphic_data_activate()
Plugin activation callback.
graphic_data_activate() : mixed
Ensures the public data directory exists when the plugin is activated. Creates figure, modal, and scene publishing capabilities for the Author role.
Tags
graphic_data_deactivate()
Plugin deactivation callback.
graphic_data_deactivate() : mixed
Removes figure, modal, and scene publishing capabilities from the Author role that were granted on activation.
Tags
graphic_data_ensure_public_data_dir()
Ensure the public data directory exists with correct permissions.
graphic_data_ensure_public_data_dir() : void
Creates GRAPHIC_DATA_DATA_DIR if it does not already exist, sets directory permissions to 0755, and drops an index.php guard file to prevent directory browsing while still allowing direct file access.
On failure the error is persisted to the 'graphic_data_data_dir_error' option so it can be surfaced via admin notices; on success that option is deleted.
Tags
graphic_data_register_blocks()
Register the blocks in the plugin.
graphic_data_register_blocks() : mixed
Ensures the public data directory exists when the plugin is activated.
Tags
graphic_data_register_figure_block_meta()
Register the figure fields for posts.
graphic_data_register_figure_block_meta() : mixed
Ensures the public data directory exists when the plugin is activated.
Tags
graphic_data_register_figure_block_routes()
Registers REST API routes for the figure block.
graphic_data_register_figure_block_routes() : void
Registers a route at graphic-data/v1/figure/<id> supporting:
- GET: retrieves figure block meta via graphic_data_get_figure_block_meta()
- POST/PUT/PATCH: saves figure block meta via graphic_data_save_figure_block_meta()
Both endpoints require the current user to have edit_post capability for the
requested post ID.
Hooked to rest_api_init.
graphic_data_get_figure_block_meta()
Retrieves figure block meta fields for a given post via the REST API.
graphic_data_get_figure_block_meta(WP_REST_Request $request) : WP_REST_Response|WP_Error
Handles GET requests to graphic-data/v1/figure/<id>. Returns a flat object
of all figure-related post meta, including fields from the figure_science_info
and figure_data_info Exopite fieldsets which are unpacked into top-level keys
for easier consumption by React.
Parameters
- $request : WP_REST_Request
-
The REST request. Must contain a numeric
idparam matching a post of typefigure.
Return values
WP_REST_Response|WP_Error —Response containing figure meta on success, or a
400 WP_Error if the post is not of type figure.
graphic_data_plugin_run()
Begins execution of the plugin.
graphic_data_plugin_run() : mixed
Since everything within the plugin is registered via hooks, then kicking off the plugin from this point in the file does not affect the page life cycle.