Documentation
Documentation
Graphic_Data_Tutorial_Content
in package
Class Graphic_Data_Tutorial_Content
Defines methods that creates or deletes tutorial content.
Tags
Table of Contents
Methods
- copy_files_to_data_folder() : string|false
- Copies a pair of .json and .csv files from the plugin directory to a per-post data folder.
- copy_image_to_media_library() : string|false
- Copies an image file from the plugin directory to the WordPress media library.
- create_blank_array() : array<string|int, mixed>
- Build a blank key-value array for a single accordion link slot.
- create_graphic_data_settings_content() : array<string|int, mixed>
- Populate tutorial default values for Graphic Data settings options.
- create_playground_tutorial_content() : mixed
- Create tutorial content within a WordPress playground context.
- create_tutorial_about_page() : void
- Create an example about page for the tutorial, if such a page does not already exist.
- create_tutorial_figures() : void
- Create example figures for the tutorial.
- create_tutorial_instance_types() : void
- Create example instance type taxonomy terms for the tutorial.
- create_tutorial_instances() : void
- Create example instances for the tutorial.
- create_tutorial_modals() : void
- Create example modals for the tutorial.
- create_tutorial_scenes() : void
- Create example scenes for the tutorial.
- delete_data_json_files() : mixed
- Delete the data/figure_postID folders and contents inside for each folder in the figures.
- delete_graphic_data_settings_content() : array<string|int, mixed>
- Clear tutorial default values from Graphic Data settings options.
- delete_tutorial_images() : void
- Deletes all tutorial images from the media library.
- delete_tutorial_instance_types() : void
- Deletes all tutorial instance type terms from the database.
- delete_tutorial_posts() : void
- Deletes all tutorial posts.
- write_modals_to_database() : void
- Creates tutorial modal posts and writes their metadata to the database.
Methods
copy_files_to_data_folder()
Copies a pair of .json and .csv files from the plugin directory to a per-post data folder.
public
copy_files_to_data_folder(string $file_path, int $post_id) : string|false
Creates wp-content/data/ and wp-content/data/figure_{$post_id}/ if they do not already exist. For each extension (.json, .csv), appends the extension to $file_path to resolve the source file and copies it to the figure folder. Skips any file that already exists at the destination. Returns false immediately if any copy operation fails. On success, records the post ID in the 'graphic_data_tutorial_figure_post_ids' option.
Parameters
- $file_path : string
-
Relative path (without extension) to the source file within the plugin directory (e.g. 'example_files/tutorial/data').
- $post_id : int
-
ID of the post whose figure folder will receive the copied files.
Return values
string|false —The absolute destination path shared by both files (e.g. '.../data/figure_42/data') on success, or false if a copy fails.
copy_image_to_media_library()
Copies an image file from the plugin directory to the WordPress media library.
public
copy_image_to_media_library(string $plugin_relative_path, int $tutorial_id) : string|false
This method takes an image file from within the plugin's directory structure, uploads it to the WordPress media library, generates the necessary attachment metadata (including image sizes), and associates it with a tutorial ID for later reference or cleanup.
Parameters
- $plugin_relative_path : string
-
The relative path to the image file from the plugin's includes directory. Example: '../example_files/tutorial/image.jpg'
- $tutorial_id : int
-
The tutorial ID to associate with this media library item. This is stored in post meta to keep track of tutorial media.
Tags
Return values
string|false —The URL of the uploaded attachment on success, false on failure. Failure can occur if the source file doesn't exist or if the upload process encounters an error.
create_blank_array()
Build a blank key-value array for a single accordion link slot.
public
create_blank_array(string $array_key) : array<string|int, mixed>
All link slots for the scene/modal info and photo accordions must have entries in the post meta table (even empty ones) for any slot to be visible. Normal form submissions populate these automatically; tutorial content must construct them manually, which this helper does.
Parameters
- $array_key : string
-
Meta key ending in a numeric index (e.g.
scene_info_link1).
Return values
array<string|int, mixed> —Associative array of blank sibling meta keys ready for insertion.
create_graphic_data_settings_content()
Populate tutorial default values for Graphic Data settings options.
public
create_graphic_data_settings_content(array<string|int, mixed> $options) : array<string|int, mixed>
Sets the intro text, sitewide footer title, sitewide footer body, and front page code block to pre-written tutorial content. These values are normally configured by the user on the Graphic Data Settings page.
Parameters
- $options : array<string|int, mixed>
-
Existing options array to populate with tutorial content.
Return values
array<string|int, mixed> —The options array with tutorial content values added.
create_playground_tutorial_content()
Create tutorial content within a WordPress playground context.
public
create_playground_tutorial_content() : mixed
This method is only called by the blueprint json file to autopopulate the WordPress Playground used as a demo/tutorial for Graphic Data.
@ return void
create_tutorial_about_page()
Create an example about page for the tutorial, if such a page does not already exist.
public
create_tutorial_about_page(int $current_user_id) : void
Parameters
- $current_user_id : int
-
The ID of the user to set as post author.
create_tutorial_figures()
Create example figures for the tutorial.
public
create_tutorial_figures(int $current_user_id) : void
Parameters
- $current_user_id : int
-
The ID of the user to set as post author.
create_tutorial_instance_types()
Create example instance type taxonomy terms for the tutorial.
public
create_tutorial_instance_types() : void
Creates two sample instance type terms with predefined names, slugs, and descriptions. Sets appropriate term meta including display order and navbar names.
Tags
create_tutorial_instances()
Create example instances for the tutorial.
public
create_tutorial_instances(int $current_user_id) : void
Parameters
- $current_user_id : int
-
The ID of the user to set as post author.
create_tutorial_modals()
Create example modals for the tutorial.
public
create_tutorial_modals(int $current_user_id) : void
Parameters
- $current_user_id : int
-
The ID of the user to set as post author.
create_tutorial_scenes()
Create example scenes for the tutorial.
public
create_tutorial_scenes(int $current_user_id) : void
Parameters
- $current_user_id : int
-
The ID of the user to set as post author.
delete_data_json_files()
Delete the data/figure_postID folders and contents inside for each folder in the figures.
public
delete_data_json_files() : mixed
Deletes all files inside the data/tutorial/ directory within the plugin directory, then removes the tutorial/ directory itself.
@ return void
delete_graphic_data_settings_content()
Clear tutorial default values from Graphic Data settings options.
public
delete_graphic_data_settings_content(array<string|int, mixed> $options) : array<string|int, mixed>
Resets the intro text, sitewide footer title, sitewide footer body, and front page code block to empty strings, effectively removing the tutorial content from the Graphic Data settings.
Parameters
- $options : array<string|int, mixed>
-
Existing options array to clear tutorial content from.
Return values
array<string|int, mixed> —The options array with tutorial content values emptied.
delete_tutorial_images()
Deletes all tutorial images from the media library.
public
delete_tutorial_images() : void
Tags
delete_tutorial_instance_types()
Deletes all tutorial instance type terms from the database.
public
delete_tutorial_instance_types() : void
Finds all taxonomy terms that have the 'tutorial_instance_type_id' meta key and removes them along with their associated metadata. Uses wp_delete_term() which handles cleanup of wp_terms, wp_term_taxonomy, and wp_termmeta tables.
Tags
delete_tutorial_posts()
Deletes all tutorial posts.
public
delete_tutorial_posts() : void
Tags
write_modals_to_database()
Creates tutorial modal posts and writes their metadata to the database.
public
write_modals_to_database(array<string|int, mixed> $modal_array, int $current_user_id) : void
Iterates over a structured array of modal data and inserts each entry as a WordPress post of type 'modal'. For each successfully created post, sets post meta fields based on the keys present in $modal_array.
Parameters
- $modal_array : array<string|int, mixed>
-
Associative array of modal field data, keyed by field name with indexed sub-arrays per modal entry. Expected keys include: 'post_title', 'tutorial_id', 'modal_location', 'modal_scene', 'modal_icons', 'modal_icon_order', 'icon_function', 'icon_scene_out'.
- $current_user_id : int
-
The WordPress user ID to set as the post author.