Skip to content
Permalink
Browse files

Hook doc update

  • Loading branch information...
mikejolley committed May 2, 2018
1 parent 6ccf5b1 commit 06ef8c8589352ee4632dea4443547776dff6c663
@@ -58,34 +58,42 @@ private static function get_hook_link( $hook, $details = array() ) {
}
public static function process_hooks() {
// If we have one, get the PHP files from it.
$template_files = self::get_files( '*.php', GLOB_MARK, '../templates/' );
$template_files[] = '../includes/wc-template-functions.php';
$template_files[] = '../includes/wc-template-hooks.php';
$shortcode_files = self::get_files( '*.php', GLOB_MARK, '../includes/shortcodes/' );
$widget_files = self::get_files( '*.php', GLOB_MARK, '../includes/widgets/' );
$admin_files = self::get_files( '*.php', GLOB_MARK, '../includes/admin/' );
$class_files = self::get_files( '*.php', GLOB_MARK, '../includes/' );
$other_files = array(
'../woocommerce.php'
self::$files_to_scan = array();
self::$files_to_scan['Template Files'] = self::get_files( '*.php', GLOB_MARK, '../templates/' );
self::$files_to_scan['Template Functions'] = array( '../includes/wc-template-functions.php', '../includes/wc-template-hooks.php' );
self::$files_to_scan['Shortcodes'] = self::get_files( '*.php', GLOB_MARK, '../includes/shortcodes/' );
self::$files_to_scan['Widgets'] = self::get_files( '*.php', GLOB_MARK, '../includes/widgets/' );
self::$files_to_scan['Data Stores'] = self::get_files( '*.php', GLOB_MARK, '../includes/data-stores' );
self::$files_to_scan['Core Classes'] = array_merge(
self::get_files( '*.php', GLOB_MARK, '../includes/' ),
self::get_files( '*.php', GLOB_MARK, '../includes/abstracts/' ),
self::get_files( '*.php', GLOB_MARK, '../includes/customizer/' ),
self::get_files( '*.php', GLOB_MARK, '../includes/emails/' ),
self::get_files( '*.php', GLOB_MARK, '../includes/export/' ),
self::get_files( '*.php', GLOB_MARK, '../includes/gateways/' ),
self::get_files( '*.php', GLOB_MARK, '../includes/import/' ),
self::get_files( '*.php', GLOB_MARK, '../includes/shipping/' )
);
self::$files_to_scan = array(
'Template Hooks' => $template_files,
'Shortcode Hooks' => $shortcode_files,
'Widget Hooks' => $widget_files,
'Class Hooks' => $class_files,
'Admin Hooks' => $admin_files,
'Other Hooks' => $other_files,
);
self::$files_to_scan = array_filter( self::$files_to_scan );
$scanned = array();
ob_start();
$index = array();
foreach ( self::$files_to_scan as $heading => $files ) {
$index[] = '<a href="#hooks-' . str_replace( ' ', '-', strtolower( $heading ) ) . '">' . $heading . '</a>';
}
echo '<div id="content">';
echo '<h1>Action and Filter Hook Reference</h1>';
echo '<div class="description">
<p>This is simply a list of action and filter hooks found within WooCommerce files. View the source to see supported params and usage.</p>
<p>' . implode( ', ', $index ) . '</p>
</div>';
foreach ( self::$files_to_scan as $heading => $files ) {
self::$custom_hooks_found = array();
@@ -125,43 +133,36 @@ public static function process_hooks() {
case 'filter' :
case 'action' :
$hook = trim( $token[1], "'" );
$hook = str_replace( '_FUNCTION_', strtoupper( $current_function ), $hook );
$hook = str_replace( '_CLASS_', strtoupper( $current_class ), $hook );
$hook = str_replace( '$this', strtoupper( $current_class ), $hook );
$hook = str_replace( array( '.', '{', '}', '"', "'", ' ', ')', '(' ), '', $hook );
$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;
// Keep adding to hook until we find a comma or colon
while ( 1 ) {
$loop ++;
$prev_hook = is_string( $tokens[ $index + $loop - 1 ] ) ? $tokens[ $index + $loop - 1 ] : $tokens[ $index + $loop - 1 ][1];
$next_hook = is_string( $tokens[ $index + $loop ] ) ? $tokens[ $index + $loop ] : $tokens[ $index + $loop ][1];
if ( in_array( $next_hook, array( '.', '{', '}', '"', "'", ' ', ')', '(' ) ) ) {
continue;
}
if ( in_array( $next_hook, array( ',', ';' ) ) ) {
break;
}
$hook_first = substr( $next_hook, 0, 1 );
$hook_last = substr( $next_hook, -1, 1 );
if ( '{' === $hook_first || '}' === $hook_last || '$' === $hook_first || ')' === $hook_last || '>' === substr( $prev_hook, -1, 1 ) ) {
$next_hook = strtoupper( $next_hook );
}
$next_hook = str_replace( array( '.', '{', '}', '"', "'", ' ', ')', '(' ), '', $next_hook );
$hook .= $next_hook;
}
if ( isset( self::$custom_hooks_found[ $hook ] ) ) {
@@ -185,14 +186,14 @@ public static function process_hooks() {
foreach ( self::$custom_hooks_found as $hook => $details ) {
if ( ! strstr( $hook, 'woocommerce' ) && ! strstr( $hook, 'product' ) && ! strstr( $hook, 'wc_' ) ) {
unset( self::$custom_hooks_found[ $hook ] );
//unset( self::$custom_hooks_found[ $hook ] );
}
}
ksort( self::$custom_hooks_found );
if ( ! empty( self::$custom_hooks_found ) ) {
echo '<div class="panel panel-default"><div class="panel-heading"><h2>' . $heading . '</h2></div>';
echo '<div class="panel panel-default"><div class="panel-heading"><h2 id="hooks-' . str_replace( ' ', '-', strtolower( $heading ) ) . '">' . $heading . '</h2></div>';
echo '<table class="summary table table-bordered table-striped"><thead><tr><th>Hook</th><th>Type</th><th>File(s)</th></tr></thead><tbody>';
@@ -98,7 +98,9 @@ public function settings_page_init() {
$current_section = empty( $_REQUEST['section'] ) ? '' : sanitize_title( wp_unslash( $_REQUEST['section'] ) ); // WPCS: input var okay, CSRF ok.
// Save settings if data has been posted.
if ( apply_filters( '' !== $current_section ? "woocommerce_save_settings_{$current_tab}_{$current_section}" : "woocommerce_save_settings_{$current_tab}", ! empty( $_POST ) ) ) { // WPCS: input var okay, CSRF ok.
if ( '' !== $current_section && apply_filters( "woocommerce_save_settings_{$current_tab}_{$current_section}", ! empty( $_POST ) ) ) { // WPCS: input var okay, CSRF ok.
WC_Admin_Settings::save();
} elseif ( apply_filters( "woocommerce_save_settings_{$current_tab}", ! empty( $_POST ) ) ) { // WPCS: input var okay, CSRF ok.
WC_Admin_Settings::save();
}
@@ -74,7 +74,8 @@ public static function do_wc_ajax() {
if ( $action ) {
self::wc_ajax_headers();
do_action( 'wc_ajax_' . sanitize_text_field( $action ) );
$action = sanitize_text_field( $action );
do_action( 'wc_ajax_' . $action );
wp_die();
}
}
@@ -158,7 +158,8 @@ public static function install_actions() {
WC_Admin_Notices::add_notice( 'update' );
}
if ( ! empty( $_GET['force_update_woocommerce'] ) ) { // WPCS: input var ok, CSRF ok.
do_action( 'wp_' . get_current_blog_id() . '_wc_updater_cron' );
$blog_id = get_current_blog_id();
do_action( 'wp_' . $blog_id . '_wc_updater_cron' );
wp_safe_redirect( admin_url( 'admin.php?page=wc-settings' ) );
exit;
}
@@ -611,11 +611,19 @@ protected function handle_updated_props( &$product ) {
}
if ( in_array( 'stock_quantity', $this->updated_props, true ) ) {
do_action( $product->is_type( 'variation' ) ? 'woocommerce_variation_set_stock' : 'woocommerce_product_set_stock', $product );
if ( $product->is_type( 'variation' ) ) {
do_action( 'woocommerce_variation_set_stock', $product );
} else {
do_action( 'woocommerce_product_set_stock', $product );
}
}
if ( in_array( 'stock_status', $this->updated_props, true ) ) {
do_action( $product->is_type( 'variation' ) ? 'woocommerce_variation_set_stock_status' : 'woocommerce_product_set_stock_status', $product->get_id(), $product->get_stock_status(), $product );
if ( $product->is_type( 'variation' ) ) {
do_action( 'woocommerce_variation_set_stock_status', $product->get_id(), $product->get_stock_status(), $product );
} else {
do_action( 'woocommerce_product_set_stock_status', $product->get_id(), $product->get_stock_status(), $product );
}
}
// Trigger action so 3rd parties can deal with updated props.
@@ -84,12 +84,12 @@ public function get_default_heading( $paid = false ) {
public function get_subject() {
if ( $this->object->has_status( array( 'completed', 'processing' ) ) ) {
$subject = $this->get_option( 'subject_paid', $this->get_default_subject( true ) );
$action = 'woocommerce_email_subject_customer_invoice_paid';
} else {
$subject = $this->get_option( 'subject', $this->get_default_subject() );
$action = 'woocommerce_email_subject_customer_invoice';
return apply_filters( 'woocommerce_email_subject_customer_invoice_paid', $this->format_string( $subject ), $this->object );
}
return apply_filters( $action, $this->format_string( $subject ), $this->object );
$subject = $this->get_option( 'subject', $this->get_default_subject() );
return apply_filters( 'woocommerce_email_subject_customer_invoice', $this->format_string( $subject ), $this->object );
}
/**
@@ -101,12 +101,11 @@ public function get_subject() {
public function get_heading() {
if ( $this->object->has_status( wc_get_is_paid_statuses() ) ) {
$heading = $this->get_option( 'heading_paid', $this->get_default_heading( true ) );
$action = 'woocommerce_email_heading_customer_invoice_paid';
} else {
$heading = $this->get_option( 'heading', $this->get_default_heading() );
$action = 'woocommerce_email_heading_customer_invoice';
return apply_filters( 'woocommerce_email_heading_customer_invoice_paid', $this->format_string( $heading ), $this->object );
}
return apply_filters( $action, $this->format_string( $heading ), $this->object );
$heading = $this->get_option( 'heading', $this->get_default_heading() );
return apply_filters( 'woocommerce_email_heading_customer_invoice', $this->format_string( $heading ), $this->object );
}
/**
@@ -46,7 +46,11 @@ function wc_update_product_stock( $product, $stock_quantity = null, $operation =
$product_with_stock->set_date_modified( current_time( 'timestamp', true ) );
$product_with_stock->save();
do_action( $product_with_stock->is_type( 'variation' ) ? 'woocommerce_variation_set_stock' : 'woocommerce_product_set_stock', $product_with_stock );
if ( $product_with_stock->is_type( 'variation' ) ) {
do_action( 'woocommerce_variation_set_stock', $product_with_stock );
} else {
do_action( 'woocommerce_product_set_stock', $product_with_stock );
}
return $product_with_stock->get_stock_quantity();
}
@@ -45,7 +45,13 @@
do_action( 'woocommerce_after_shipping_rate', $method, $index );
?>
<?php elseif ( WC()->customer->has_calculated_shipping() ) : ?>
<?php echo apply_filters( is_cart() ? 'woocommerce_cart_no_shipping_available_html' : 'woocommerce_no_shipping_available_html', wpautop( __( 'There are no shipping methods available. Please ensure that your address has been entered correctly, or contact us if you need any help.', 'woocommerce' ) ) ); ?>
<?php
if ( is_cart() ) {
echo apply_filters( 'woocommerce_cart_no_shipping_available_html', wpautop( __( 'There are no shipping methods available. Please ensure that your address has been entered correctly, or contact us if you need any help.', 'woocommerce' ) ) );
} else {
echo apply_filters( 'woocommerce_no_shipping_available_html', wpautop( __( 'There are no shipping methods available. Please ensure that your address has been entered correctly, or contact us if you need any help.', 'woocommerce' ) ) );
}
?>
<?php elseif ( ! is_cart() ) : ?>
<?php echo wpautop( __( 'Enter your full address to see shipping costs.', 'woocommerce' ) ); ?>
<?php endif; ?>

0 comments on commit 06ef8c8

Please sign in to comment.
You can’t perform that action at this time.