Generate dynamic hook docs

Closes #10393
This commit is contained in:
Mike Jolley 2016-02-22 14:41:14 +00:00
parent fc3474f255
commit bd7072a8dc
2 changed files with 40 additions and 1 deletions

View File

@ -122,6 +122,45 @@ class WC_HookFinder {
case 'filter' :
case 'action' :
$hook = trim( $token[1], "'" );
$loop = 0;
if ( '_' === substr( $hook, '-1', 1 ) ) {
$hook .= '{';
$open = true;
// Keep adding to hook until we find a comma or colon
while ( 1 ) {
$loop ++;
$next_hook = trim( trim( is_string( $tokens[ $index + $loop ] ) ? $tokens[ $index + $loop ] : $tokens[ $index + $loop ][1], '"' ), "'" );
if ( in_array( $next_hook, array( '.', '{', '}', '"', "'", ' ' ) ) ) {
continue;
}
$hook_first = substr( $next_hook, 0, 1 );
$hook_last = substr( $next_hook, -1, 1 );
if ( in_array( $next_hook, array( ',', ';' ) ) ) {
if ( $open ) {
$hook .= '}';
$open = false;
}
break;
}
if ( '_' === $hook_first ) {
$next_hook = '}' . $next_hook;
$open = false;
}
if ( '_' === $hook_last ) {
$next_hook .= '{';
$open = true;
}
$hook .= $next_hook;
}
}
if ( isset( self::$custom_hooks_found[ $hook ] ) ) {
self::$custom_hooks_found[ $hook ]['file'][] = self::$current_file;
} else {

View File

@ -906,7 +906,7 @@ if ( ! function_exists( 'woocommerce_template_single_add_to_cart' ) ) {
*/
function woocommerce_template_single_add_to_cart() {
global $product;
do_action( 'woocommerce_' . $product->product_type . '_add_to_cart' );
do_action( 'woocommerce_' . $product->product_type . '_add_to_cart' );
}
}
if ( ! function_exists( 'woocommerce_simple_add_to_cart' ) ) {