pfeifferNet

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
since
6.8.0

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
since
6.8.0

POST_TYPE

WP Recipe Maker custom post type.

protected string POST_TYPE = 'wprm_recipe'
Tags
since
6.8.0

Properties

$instances

The array of instances of this class and sub-classes.

protected static array<string|int, object> $instances = array()
Tags
since
6.8.0

Methods

get_instance()

Creates and/or returns the instance of this class.

public static get_instance() : object
Tags
since
6.8.0
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
since
6.8.0

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
since
6.8.0
see
https://developer.wordpress.org/reference/hooks/save_post_post-post_type/
used-by
set_instruction_count_metadata()

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
since
6.8.0
uses
WPRM_Recipe_Manager::get_recipe()
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.

Tags
since
6.8.0

        
On this page

Search results