Skip to content

Commit 172ebcf

Browse files
committed
chore: Consolidate the purge REST option
1 parent 672d0ac commit 172ebcf

File tree

2 files changed

+5
-22
lines changed

2 files changed

+5
-22
lines changed

admin/class-nginx-helper-admin.php

Lines changed: 3 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -295,7 +295,6 @@ public function nginx_helper_default_settings() {
295295
'is_cache_preloaded' => 0,
296296
'roles_with_purge_cap' => array(),
297297
'purge_woo_products' => 0,
298-
'purge_woo_rest' => 0,
299298
);
300299

301300
}
@@ -982,19 +981,12 @@ public function nginx_helper_update_role_caps() {
982981
* @since 2.3.5
983982
*/
984983
public function init_woocommerce_hooks() {
985-
if ( ! is_plugin_active( 'woocommerce/woocommerce.php' ) ) {
984+
if ( ! is_plugin_active( 'woocommerce/woocommerce.php' ) || empty( $this->options['purge_woo_products'] ) ) {
986985
return;
987986
}
988987

989-
// Purge on purchase (stock reduction).
990-
if ( ! empty( $this->options['purge_woo_products'] ) ) {
991-
add_action( 'woocommerce_reduce_order_stock', array( $this, 'purge_product_cache_on_purchase' ), 10, 1 );
992-
}
993-
994-
// Purge on product update (Admin, REST, programmatic).
995-
if ( ! empty( $this->options['purge_woo_rest'] ) ) {
996-
add_action( 'woocommerce_update_product', array( $this, 'purge_product_cache_on_update' ), 10, 1 );
997-
}
988+
add_action( 'woocommerce_reduce_order_stock', array( $this, 'purge_product_cache_on_purchase' ), 10, 1 );
989+
add_action( 'woocommerce_update_product', array( $this, 'purge_product_cache_on_update' ), 10, 1 );
998990
}
999991

1000992

admin/partials/nginx-helper-general-options.php

Lines changed: 2 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -49,8 +49,7 @@
4949
'purge_amp_urls',
5050
'preload_cache',
5151
'roles_with_purge_cap',
52-
'purge_woo_products',
53-
'purge_woo_rest'
52+
'purge_woo_products'
5453
);
5554

5655
$all_inputs = array();
@@ -1024,15 +1023,7 @@
10241023
<td>
10251024
<input type="checkbox" value="1" id="purge_woo_products" name="purge_woo_products" <?php checked( $nginx_helper_settings['purge_woo_products'] ?? 0, 1 ); ?> />
10261025
<label for="purge_woo_products">
1027-
<?php esc_html_e( 'Purge product cache on stock change or purchase', 'nginx-helper' ); ?>
1028-
</label>
1029-
</td>
1030-
</tr>
1031-
<tr valign="top">
1032-
<td>
1033-
<input type="checkbox" value="1" id="purge_woo_rest" name="purge_woo_rest" <?php checked( $nginx_helper_settings['purge_woo_rest'] ?? 0, 1 ); ?> />
1034-
<label for="purge_woo_rest">
1035-
<?php esc_html_e( 'Enable product cache purge via REST API updates', 'nginx-helper' ); ?>
1026+
<?php esc_html_e( 'Purge product cache on stock change or purchase or REST API update', 'nginx-helper' ); ?>
10361027
</label>
10371028
</td>
10381029
</tr>

0 commit comments

Comments
 (0)