TermSync
extends TaxonomyCLICommands
in package
TermSync class.
Table of Contents
Properties
- $notices : array<string|int, array{type: string, message: string}>
- WP CLI notices.
- $upload_path : string
- Upload path
- $upload_url : string
- Upload URL
- $log_dir : string
- The directory where the log file will be created.
- $log_name : string
- The name of the log file to write to.
Methods
- add_notice() : void
- Adds a notice to be displayed at the end of the command.
- bulk() : mixed
- Bulk sync terms using CSV file
- display_notices() : void
- Display the notices. The output is WP_CLI.
- get_notices() : array<string|int, array{type: string, message: string}>
- Get all notices.
- get_upload_path() : string
- Get the upload path.
- get_upload_url() : string
- Get the upload URL.
- invalid_taxonomy() : void|false
- Handles invalid taxonomy errors by logging and adding notices.
- list_terms() : mixed
- List terms in a taxonomy for reference
- log() : void
- Logs a message to a specified log file, creating the log directory if it does not exist.
- match() : mixed
- Match and sync terms between taxonomies
- reset_notices() : void
- Reset all notices.
- set_log_name() : void
- Sets the name of the log file to write to.
- set_upload_path() : void
- Set the upload path.
- set_upload_url() : void
- Set the upload URL.
- validate_post_type() : string|WP_Error
- Validates the given post type.
- validate_taxonomy() : string|WP_Error
- Validates the given taxonomy string.
- dry_run_result() : void
- Outputs a dry run message for a merge command.
- export_csv() : void
- Create and write to a CSV file
- get_log_file_path() : string
- Gets the full path to the log file.
- has_required_fields() : bool
- Checks if the given data array contains all required fields.
- is_term_valid() : WP_Term|false
- Validates a term by name or slug within a given taxonomy.
- validate_command_args() : bool
- Validate the number of command arguments.
- validate_headers() : bool
- Validates that the given array of CSV headers contains all required fields.
- add_term_to_post() : mixed
- find_existing_term() : mixed
- get_posts_with_term() : mixed
- get_terms_to_process() : mixed
Properties
$notices
WP CLI notices.
public
array<string|int, array{type: string, message: string}>
$notices
= array()
$upload_path
Upload path
public
string
$upload_path
$upload_url
Upload URL
public
string
$upload_url
$log_dir
The directory where the log file will be created.
protected
string
$log_dir
= BCM_UPLOADS_PATH
$log_name
The name of the log file to write to.
protected
string
$log_name
= 'default.log'
Methods
add_notice()
Adds a notice to be displayed at the end of the command.
public
add_notice([string $message = '' ][, string $type = 'log' ]) : void
Parameters
- $message : string = ''
-
The message to display.
- $type : string = 'log'
-
The type of notice. One of 'log', 'success', 'warning', 'error'. Default is 'log'.
bulk()
Bulk sync terms using CSV file
public
bulk(array<string|int, mixed> $args, array<string|int, mixed> $assoc_args) : mixed
OPTIONS
--csv-file=
--post-type=<post_type> : Post type to process
[--dry-run] : Show what would be done without making changes
EXAMPLES
wp boomi taxonomies term-sync bulk --csv-file=sync.csv --post-type=post
Parameters
- $args : array<string|int, mixed>
- $assoc_args : array<string|int, mixed>
display_notices()
Display the notices. The output is WP_CLI.
public
display_notices() : void
get_notices()
Get all notices.
public
get_notices() : array<string|int, array{type: string, message: string}>
Return values
array<string|int, array{type: string, message: string}> —The array of notices.
get_upload_path()
Get the upload path.
public
get_upload_path() : string
Return values
string —The full path.
get_upload_url()
Get the upload URL.
public
get_upload_url() : string
Return values
string —The full URL.
invalid_taxonomy()
Handles invalid taxonomy errors by logging and adding notices.
public
invalid_taxonomy(WP_Taxonomy|WP_Error $taxonomy[, int|null $row_num = null ]) : void|false
Parameters
- $taxonomy : WP_Taxonomy|WP_Error
-
The taxonomy or error object.
- $row_num : int|null = null
-
Optional. The row number for logging purposes. Defaults to null.
Return values
void|false —Returns false if row number is provided, otherwise void.
list_terms()
List terms in a taxonomy for reference
public
list_terms(array<string|int, mixed> $args, array<string|int, mixed> $assoc_args) : mixed
OPTIONS
--taxonomy=
[--search=
EXAMPLES
wp boomi taxonomies term-sync list-terms --taxonomy=blog_posts
wp boomi taxonomies term-sync list-terms --taxonomy=products --search="API"
Parameters
- $args : array<string|int, mixed>
- $assoc_args : array<string|int, mixed>
log()
Logs a message to a specified log file, creating the log directory if it does not exist.
public
log(string $message[, string $type = 'info' ][, string|null $log_name = null ]) : void
Parameters
- $message : string
-
The message to log.
- $type : string = 'info'
-
Optional. The type of log message. Default is 'info'.
- $log_name : string|null = null
-
Optional. The name of the log file to write to. If null, the default log file name is used.
match()
Match and sync terms between taxonomies
public
match(array<string|int, mixed> $args, array<string|int, mixed> $assoc_args) : mixed
OPTIONS
--source=
--target=
--post-type=<post_type> : Post type to process
[--term=<term_name>] : Specific term to match (optional, if not provided will match all terms)
[--dry-run] : Show what would be done without making changes
[--batch-size=
EXAMPLES
wp boomi taxonomies term-sync match --source=blog_posts --target=products --post-type=post
wp boomi taxonomies term-sync match --source=blog_posts --target=products,topics --post-type=custom_post --term="API Management"
Parameters
- $args : array<string|int, mixed>
- $assoc_args : array<string|int, mixed>
reset_notices()
Reset all notices.
public
reset_notices() : void
set_log_name()
Sets the name of the log file to write to.
public
set_log_name(string $name) : void
Parameters
- $name : string
-
The name of the log file.
set_upload_path()
Set the upload path.
public
set_upload_path([string $path = '' ]) : void
If the path is a directory, it will create it if it does not exist.
Parameters
- $path : string = ''
-
The complete path to use.
set_upload_url()
Set the upload URL.
public
set_upload_url([string $url = '' ]) : void
Parameters
- $url : string = ''
-
The full URL to use.
validate_post_type()
Validates the given post type.
public
validate_post_type(string $post_type[, int|null $row_num = null ]) : string|WP_Error
Checks if the provided post type is a string and if it exists. Returns a WP_Error if the validation fails.
Parameters
- $post_type : string
-
The post type to validate.
- $row_num : int|null = null
-
The row number in the CSV file (optional).
Return values
string|WP_Error —The post type if valid, or a WP_Error on failure.
validate_taxonomy()
Validates the given taxonomy string.
public
validate_taxonomy(string $taxonomy[, int|null $row_num = null ]) : string|WP_Error
Checks if the provided taxonomy is a string and if it exists. Returns a WP_Error if the taxonomy is invalid.
Parameters
- $taxonomy : string
-
The taxonomy to validate.
- $row_num : int|null = null
-
The row number in the CSV file (optional).
Return values
string|WP_Error —Returns the taxonomy if valid, otherwise a WP_Error object.
dry_run_result()
Outputs a dry run message for a merge command.
protected
dry_run_result(string $taxonomy, array<string|int, string> $from_terms, string $to_term, int $row_num) : void
Parameters
- $taxonomy : string
-
The taxonomy.
- $from_terms : array<string|int, string>
-
The terms to merge.
- $to_term : string
-
The term to merge into.
- $row_num : int
-
The row number.
export_csv()
Create and write to a CSV file
protected
export_csv(string $filename, array<int|string, mixed> $rows[, array<int|string, string> $headers = array() ]) : void
Parameters
- $filename : string
-
the full name of the file.
- $rows : array<int|string, mixed>
-
array of data.
- $headers : array<int|string, string> = array()
-
(default: array()).
get_log_file_path()
Gets the full path to the log file.
protected
get_log_file_path(string $log_name) : string
Parameters
- $log_name : string
-
The log file name.
Return values
string —The full path to the log file.
has_required_fields()
Checks if the given data array contains all required fields.
protected
has_required_fields(array<string, mixed> $data, array<string|int, string> $required[, int $row_num = 0 ]) : bool
Parameters
- $data : array<string, mixed>
-
The data array to check.
- $required : array<string|int, string>
-
The list of required field keys.
- $row_num : int = 0
-
The row number for logging purposes. Defaults to 0.
Return values
bool —Returns true if all required fields are present, false otherwise.
is_term_valid()
Validates a term by name or slug within a given taxonomy.
protected
is_term_valid(string $term_name, string $taxonomy[, int $row_num = 0 ]) : WP_Term|false
Parameters
- $term_name : string
-
The term name or slug.
- $taxonomy : string
-
The taxonomy to look in.
- $row_num : int = 0
-
The row number in the CSV file.
Return values
WP_Term|false —If the term is valid, returns the term object. Otherwise, returns false.
validate_command_args()
Validate the number of command arguments.
protected
validate_command_args(array<string|int, string> $args[, int $min_args = 0 ][, int $max_args = 0 ]) : bool
Parameters
- $args : array<string|int, string>
-
The command arguments.
- $min_args : int = 0
-
The minimum number of arguments allowed. Default 0.
- $max_args : int = 0
-
The maximum number of arguments allowed. Default 0.
Return values
bool —True if valid, false otherwise.
validate_headers()
Validates that the given array of CSV headers contains all required fields.
protected
validate_headers(array<string|int, string> $headers, array<string|int, string> $required) : bool
Parameters
- $headers : array<string|int, string>
-
The array of CSV headers.
- $required : array<string|int, string>
-
The list of required field keys.
Return values
bool —Returns true if all required fields are present, false otherwise.
add_term_to_post()
private
add_term_to_post(mixed $post_id, mixed $term_id, mixed $taxonomy[, mixed $dry_run = false ]) : mixed
Parameters
- $post_id : mixed
- $term_id : mixed
- $taxonomy : mixed
- $dry_run : mixed = false
find_existing_term()
private
find_existing_term(mixed $term_name, mixed $taxonomy) : mixed
Parameters
- $term_name : mixed
- $taxonomy : mixed
get_posts_with_term()
private
get_posts_with_term(mixed $post_type, mixed $taxonomy, mixed $term_id, mixed $batch_size) : mixed
Parameters
- $post_type : mixed
- $taxonomy : mixed
- $term_id : mixed
- $batch_size : mixed
get_terms_to_process()
private
get_terms_to_process(mixed $taxonomy[, mixed $specific_term = null ]) : mixed
Parameters
- $taxonomy : mixed
- $specific_term : mixed = null