Documentation

Graphic_Data_Plugin_Only_Content
in package

Class Graphic_Data_Plugin_Only_Content

Defines methods that content when the Graphic Data plugin is used without the theme.

Tags
since
1.0.0

Table of Contents

Constants

PLACEHOLDERS_READY_OPTION  : string = 'graphic_data_placeholders_ready'
Autoloaded option set once all placeholders exist, so the existence checks can be skipped.

Methods

copy_image_to_media_library()  : string|false
Copies an image file from the plugin directory to the WordPress media library.
create_placeholder_instance()  : void
Create placeholder instance.
create_placeholder_instance_type()  : void
Creates a placeholder instance type term if the Graphic Data theme is not active.
create_placeholder_modal()  : void
Creates tutorial modal posts and writes their metadata to the database.
create_placeholder_scene()  : void
Create example scenes for the placeholder.
placeholder_content_director()  : void
Ensures the placeholder instance type, instance, scene and modal all exist.
reset_placeholders_on_post_delete()  : void
Clears the placeholders-ready flag when a placeholder post is permanently deleted.
reset_placeholders_on_term_delete()  : void
Clears the placeholders-ready flag when the placeholder instance type is deleted.
find_placeholder_post_id()  : int
Finds the post ID of a placeholder post by its `graphic_data_placeholder_id` value.
find_placeholder_term_id()  : int
Finds the term ID of a placeholder term by its `graphic_data_placeholder_id` value.
link_placeholders()  : void
Points every placeholder at the current IDs of the others.

Constants

PLACEHOLDERS_READY_OPTION

Autoloaded option set once all placeholders exist, so the existence checks can be skipped.

public string PLACEHOLDERS_READY_OPTION = 'graphic_data_placeholders_ready'

Methods

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 $placeholder_id, int $instance_id) : string|false

Takes an image file from within the plugin's directory structure, uploads it to the WordPress media library, generates attachment metadata (including image sizes), and tags the resulting attachment with both a placeholder ID and an instance ID for later lookup or cleanup.

Parameters
$plugin_relative_path : string

Relative path to the image file from the plugin root directory. Example: 'example_files/tutorial/image.jpg'

$placeholder_id : int

Placeholder ID stored in attachment post meta under graphic_data_placeholder_id to identify placeholder media.

$instance_id : int

Instance ID stored in attachment post meta under graphic_data_instance_id to associate the media with a specific plugin instance.

If an attachment with the same placeholder ID and title already exists and its file is still on disk, that attachment is reused (and re-tagged with $instance_id) instead of uploading another copy.

Tags
since
1.0.0
Return values
string|false —

URL of the uploaded attachment on success, or false if the source file does not exist or the upload process fails.

create_placeholder_instance()

Create placeholder instance.

public create_placeholder_instance(int $current_user_id) : void

Links to the other placeholders are set afterwards by link_placeholders().

Parameters
$current_user_id : int

The ID of the user to set as post author.

create_placeholder_instance_type()

Creates a placeholder instance type term if the Graphic Data theme is not active.

public create_placeholder_instance_type() : void

Inserts a new term into the instance_type taxonomy with a predefined name, slug, and description. Sets its instance_order to one greater than the current maximum, assigns a navbar name of "Placeholder", and marks it with the graphic_data_instance_type_placeholder_id meta flag.

Tags
global

wpdb $wpdb WordPress database abstraction object.

create_placeholder_modal()

Creates tutorial modal posts and writes their metadata to the database.

public create_placeholder_modal(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. Links to the other placeholders are set afterwards by link_placeholders().

Parameters
$current_user_id : int

The WordPress user ID to set as the post author.

create_placeholder_scene()

Create example scenes for the placeholder.

public create_placeholder_scene(int $current_user_id) : void

Links to the other placeholders are set afterwards by link_placeholders().

Parameters
$current_user_id : int

The ID of the user to set as post author.

placeholder_content_director()

Ensures the placeholder instance type, instance, scene and modal all exist.

public placeholder_content_director() : void

Each placeholder is identified by its graphic_data_placeholder_id meta value: 1 = instance type (termmeta), 2 = instance, 3 = scene, 4 = modal (postmeta). Any placeholder that is missing is created by its create_placeholder_*() method. Runs regardless of whether the Graphic Data theme is active.

When a run finds everything already exists, the PLACEHOLDERS_READY_OPTION flag is set and later calls return immediately. The flag is autoloaded, so checking it costs no extra query. It is cleared when a placeholder is deleted, so the next request recreates what is missing.

reset_placeholders_on_post_delete()

Clears the placeholders-ready flag when a placeholder post is permanently deleted.

public reset_placeholders_on_post_delete(int $post_id) : void

Hooked to before_delete_post, because post meta is already gone by deleted_post. Trashing a placeholder does not trigger this, since the post still exists.

Parameters
$post_id : int

ID of the post being deleted.

reset_placeholders_on_term_delete()

Clears the placeholders-ready flag when the placeholder instance type is deleted.

public reset_placeholders_on_term_delete(int $term_id) : void

Hooked to pre_delete_term, because term meta is already gone by delete_term.

Parameters
$term_id : int

ID of the term being deleted.

find_placeholder_post_id()

Finds the post ID of a placeholder post by its `graphic_data_placeholder_id` value.

private find_placeholder_post_id(int $placeholder_id, string $post_type) : int

The post type is required because placeholder media attachments share marker values with placeholder posts (the scene image is tagged 2, the same as the instance).

Parameters
$placeholder_id : int

Placeholder marker value (2 = instance, 3 = scene, 4 = modal).

$post_type : string

Post type the placeholder must have.

Tags
global

wpdb $wpdb WordPress database abstraction object.

Return values
int —

Post ID, or 0 if not found.

find_placeholder_term_id()

Finds the term ID of a placeholder term by its `graphic_data_placeholder_id` value.

private find_placeholder_term_id(int $placeholder_id) : int
Parameters
$placeholder_id : int

Placeholder marker value (1 = instance type).

Tags
global

wpdb $wpdb WordPress database abstraction object.

Return values
int —

Term ID, or 0 if not found.

Points every placeholder at the current IDs of the others.

private link_placeholders() : void

Safe to run repeatedly: it looks up each placeholder fresh and overwrites the link fields, so a placeholder that survived when another was deleted and recreated is reconnected to the new one.

global

wpdb $wpdb WordPress database abstraction object.

On this page

Search results