Prevent extract from polluting hook arguments

This commit is contained in:
Kim Helge Frimanslund 2018-10-28 15:36:13 +01:00
parent d1c90c5972
commit fece37f814
1 changed files with 13 additions and 7 deletions

View File

@ -188,10 +188,6 @@ function wc_get_template_part( $slug, $name = '' ) {
* @param string $default_path Default path. (default: '').
*/
function wc_get_template( $template_name, $args = array(), $template_path = '', $default_path = '' ) {
if ( ! empty( $args ) && is_array( $args ) ) {
extract( $args ); // @codingStandardsIgnoreLine
}
$located = wc_locate_template( $template_name, $template_path, $default_path );
if ( ! file_exists( $located ) ) {
@ -203,14 +199,24 @@ function wc_get_template( $template_name, $args = array(), $template_path = '',
// Allow 3rd party plugin filter template file from their plugin.
$located = apply_filters( 'wc_get_template', $located, $template_name, $args, $template_path, $default_path );
do_action( 'woocommerce_before_template_part', $template_name, $template_path, $located, $args );
$action_args = array(
'template_name' => $template_name,
'template_path' => $template_path,
'located' => $located,
'args' => $args,
);
if ( ! empty( $args ) && is_array( $args ) ) {
extract( $args ); // @codingStandardsIgnoreLine
}
do_action( 'woocommerce_before_template_part', $action_args['template_name'], $action_args['template_path'], $action_args['located'], $action_args['args'] );
include $located;
do_action( 'woocommerce_after_template_part', $template_name, $template_path, $located, $args );
do_action( 'woocommerce_after_template_part', $action_args['template_name'], $action_args['template_path'], $action_args['located'], $action_args['args'] );
}
/**
* Like wc_get_template, but returns the HTML instead of outputting.
*