Merge pull request #29002 from n3f/fix/webhook_loading_limit

Respect the $limit parameter (0)
This commit is contained in:
Jorge A. Torres 2022-03-02 16:42:22 -03:00 committed by GitHub
commit 9658b3a59c
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
2 changed files with 8 additions and 4 deletions

View File

@ -164,13 +164,13 @@ function wc_load_webhooks( $status = '', $limit = null ) {
$loaded = 0;
foreach ( $webhooks as $webhook_id ) {
$webhook = new WC_Webhook( $webhook_id );
$webhook->enqueue();
$loaded ++;
if ( ! is_null( $limit ) && $loaded >= $limit ) {
break;
}
$webhook = new WC_Webhook( $webhook_id );
$webhook->enqueue();
$loaded ++;
}
return 0 < $loaded;

View File

@ -172,6 +172,10 @@ class WC_Tests_Webhook_Functions extends WC_Unit_Test_Case {
$webhook_one = $this->create_webhook( 'action.woocommerce_one_test' );
$webhook_two = $this->create_webhook( 'action.woocommerce_two_test' );
$this->assertFalse( wc_load_webhooks( '', 0 ) );
$this->assertFalse( isset( $wp_filter['woocommerce_one_test'] ) );
$this->assertFalse( isset( $wp_filter['woocommerce_two_test'] ) );
$this->assertTrue( wc_load_webhooks( '', 1 ) );
$this->assertFalse( isset( $wp_filter['woocommerce_one_test'] ) );
$this->assertTrue( isset( $wp_filter['woocommerce_two_test'] ) );