WC_CLI_REST_Command::get_filled_route
Get the route for this resource
Method of the class: WC_CLI_REST_Command{}
No Hooks.
Returns
String.
Usage
// private - for code of main (parent) class only $result = $this->get_filled_route( $args );
- $args(array)
- Positional arguments passed to the originating WP-CLI command.
Default:array()
WC_CLI_REST_Command::get_filled_route() WC CLI REST Command::get filled route code WC 10.6.2
private function get_filled_route( $args = array() ) {
$supported_id_matched = false;
$route = $this->route;
foreach ( $this->get_supported_ids() as $id_name => $id_desc ) {
if ( 'id' !== $id_name && strpos( $route, '<' . $id_name . '>' ) !== false && ! empty( $args ) ) {
$route = str_replace( array( '(?P<' . $id_name . '>[\d]+)', '(?P<' . $id_name . '>\w[\w\s\-]*)' ), $args[0], $route );
$supported_id_matched = true;
}
}
if ( ! empty( $args ) ) {
$id_replacement = $supported_id_matched && ! empty( $args[1] ) ? $args[1] : $args[0];
$route = str_replace( array( '(?P<id>[\d]+)', '(?P<id>[\w-]+)' ), $id_replacement, $route );
}
return rtrim( $route );
}