Word_Count
in package
Handle the word count functionality.
- Count the words in a post and stores the value as post metadata.
- Provide a method to bulk regenerate the word counts for all posts.
Tags
Table of Contents
Constants
- META_KEY = 'pnet_word_count'
- Metadata key for word counts.
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 word counts for all posts.
- set_count() : void
- Sets the word count metadata for a post.
- __construct() : void
- Initialise the class.
- save_metadata() : void
- Save the post word count metadata.
Constants
META_KEY
Metadata key for word counts.
protected
string
META_KEY
= 'pnet_word_count'
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 word counts for all posts.
public
regenerate() : void
- This method is called by a cron job to update the word counts for all posts.
- Used by db-updater to bulk set the word counts for all posts after an update.
Tags
set_count()
Sets the word count metadata for a post.
public
set_count(int $post_id, WP_Post $post[, bool $update = true ]) : void
- Fired by the save_post action hook when a post is saved or updated.
- Check if save is an autosave or revision. If so, do nothing.
Parameters
- $post_id : int
-
ID of post.
- $post : WP_Post
-
Post object.
- $update : bool = true
-
Whether this is an existing post being updated. Default true.
Tags
__construct()
Initialise the class.
protected
__construct() : void
Tags
save_metadata()
Save the post word count metadata.
protected
save_metadata(int $post_id, WP_Post $post[, bool $update = true ]) : void
Parameters
- $post_id : int
-
ID of post.
- $post : WP_Post
-
Post object.
- $update : bool = true
-
Whether this is an existing post being updated.