Instruction_Count
in package
Handle the instruction count functionality.
- Count the instructions in a recipe and store the value as post metadata.
- Provide a method to bulk create or regenerate the instruction counts for all recipes.
Tags
Table of Contents
Constants
- META_KEY : string = 'pfic_instruction_count'
- Metadata key for instruction counts.
- POST_TYPE : string = 'wprm_recipe'
- WP Recipe Maker custom post type.
Properties
- $instances : array<string|int, object>
- The array of instances of this class and sub-classes.
Methods
- get_instance() : object
- Creates and/or returns the instance of this class.
- regenerate() : void
- Regenerate the instruction counts for all recipes.
- set_count() : void
- Sets the instruction count metadata for a recipe.
- __construct() : void
- Initialise the class.
- get_instructions() : int
- Return the number of instructions in the recipe.
- save_metadata() : void
- Save the recipe instruction count as metadata.
Constants
META_KEY
Metadata key for instruction counts.
protected
string
META_KEY
= 'pfic_instruction_count'
Tags
POST_TYPE
WP Recipe Maker custom post type.
protected
string
POST_TYPE
= 'wprm_recipe'
Tags
Properties
$instances
The array of instances of this class and sub-classes.
protected
static array<string|int, object>
$instances
= array()
Tags
Methods
get_instance()
Creates and/or returns the instance of this class.
public
static get_instance() : object
Tags
Return values
object —The instance of this class.
regenerate()
Regenerate the instruction counts for all recipes.
public
regenerate() : void
- This method is called by a cron job to update the instruction counts for all recipes.
- Used by db-updater to bulk set the instruction counts for all recipes after an update.
Tags
set_count()
Sets the instruction count metadata for a recipe.
public
set_count(int $recipe_id, WP_Post $post, bool $update) : void
- Fired by the save_post_{post_type} action hook when a post is saved or updated.
- If is a draft, an autosave or revision do nothing.
Parameters
- $recipe_id : int
-
ID of the WPRM recipe post.
- $post : WP_Post
-
WPRM recipe custom post object.
- $update : bool
-
Whether this is an existing recipe being updated.
Tags
__construct()
Initialise the class.
protected
__construct() : void
Tags
get_instructions()
Return the number of instructions in the recipe.
protected
get_instructions(WP_Post $post) : int
Parameters
- $post : WP_Post
-
WPRM recipe post object.
Tags
Return values
int —The number of instructions in the recipe.
save_metadata()
Save the recipe instruction count as metadata.
protected
save_metadata(int $recipe_id, int $count) : void
Parameters
- $recipe_id : int
-
ID of the WPRM recipe post.
- $count : int
-
The number of instructions in the recipe.