Fix the PHP notice that is displaying when running commands like shop_coupon list that accept no ID arguments.

This commit is contained in:
Justin Shreve 2017-03-01 13:22:02 -08:00
parent 7b2be1d62f
commit e8754eafcb
1 changed files with 9 additions and 5 deletions

View File

@ -333,17 +333,21 @@ EOT;
* @return string
*/
private function get_filled_route( $args = array() ) {
$parent_id_matched = false;
$supported_id_matched = false;
$route = $this->route;
foreach ( $this->get_supported_ids() as $id_name => $id_desc ) {
if ( strpos( $route, '<' . $id_name . '>' ) !== false && ! empty( $args ) ) {
$route = str_replace( '(?P<' . $id_name . '>[\d]+)', $args[0], $route );
$parent_id_matched = true;
$supported_id_matched = true;
}
}
$route = str_replace( array( '(?P<id>[\d]+)', '(?P<id>[\w-]+)' ), ( $parent_id_matched && ! empty( $args[1] ) ? $args[1] : $args[0] ), $route );
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 );
}