@@ -223,8 +223,9 @@ public function nginx_helper_toolbar_purge_link( $wp_admin_bar ) {
223223
224224 $ purge_url = add_query_arg (
225225 array (
226- 'nginx_helper_action ' => 'purge ' ,
227- 'nginx_helper_urls ' => $ nginx_helper_urls ,
226+ 'nginx_helper_action ' => 'purge ' ,
227+ 'nginx_helper_urls ' => $ nginx_helper_urls ,
228+ 'nginx_helper_dismiss ' => get_transient ( 'rt_wp_nginx_helper_suggest_purge_notice ' ),
228229 )
229230 );
230231
@@ -975,6 +976,80 @@ public function nginx_helper_update_role_caps() {
975976 }
976977 }
977978
979+ /**
980+ * Automatically purges Nginx cache on any WordPress core, plugin, or theme update if enabled.
981+ *
982+ * @param WP_Upgrader $upgrader_object WP_Upgrader instance.
983+ * @param array $options Array of bulk item update data.
984+ */
985+ public function nginx_helper_auto_purge_on_any_update ( $ upgrader_object , $ options ) {
986+
987+ if ( ! isset ( $ options ['action ' ], $ options ['type ' ] )
988+ || 'update ' !== $ options ['action ' ]
989+ || ! in_array ( $ options ['type ' ], array ( 'core ' , 'plugin ' , 'theme ' ), true ) ) {
990+ return ;
991+ }
992+ if ( ! defined ( 'NGINX_HELPER_AUTO_PURGE_ON_ANY_UPDATE ' ) || ! NGINX_HELPER_AUTO_PURGE_ON_ANY_UPDATE ) {
993+ set_transient ( 'rt_wp_nginx_helper_suggest_purge_notice ' , true , HOUR_IN_SECONDS );
994+ return ;
995+ }
996+ global $ nginx_purger ;
997+
998+ $ nginx_purger ->purge_all ();
999+ }
1000+
1001+ /**
1002+ * Displays an admin notice suggesting the user to purge cache after a WordPress update.
1003+ */
1004+ public function suggest_purge_after_update () {
1005+
1006+ if ( ! get_transient ( 'rt_wp_nginx_helper_suggest_purge_notice ' ) ) {
1007+ return ;
1008+ }
1009+
1010+ $ setting_page = is_network_admin () ? 'settings.php ' : 'options-general.php ' ;
1011+ $ settings_link = network_admin_url ( $ setting_page . '?page=nginx ' );
1012+ $ dismiss_url = wp_nonce_url ( add_query_arg ( 'nginx_helper_dismiss ' , 'true ' ), 'nginx_helper_dismiss_notice ' );
1013+ ?>
1014+ <div class="notice notice-info">
1015+ <p>
1016+ <?php
1017+ esc_html_e ( 'A WordPress update was detected. It is recommended to purge the cache to ensure your site displays the latest changes. ' , 'nginx-helper ' );
1018+ ?>
1019+ <a href="<?php echo esc_url ( $ settings_link ); ?> "><?php esc_html_e ( 'Go & Purge Cache ' , 'nginx-helper ' ); ?> </a>
1020+ |
1021+ <a href="<?php echo esc_url ( $ dismiss_url ); ?> ">
1022+ <?php esc_html_e ( 'Dismiss ' , 'nginx-helper ' ); ?>
1023+ </a>
1024+ </p>
1025+ </div>
1026+ <?php
1027+ }
1028+
1029+ /**
1030+ * Dismisses the "suggest purge" admin notice when the user clicks the dismiss link.
1031+ */
1032+ public function dismiss_suggest_purge_after_update () {
1033+
1034+ if ( ! isset ( $ _GET ['nginx_helper_dismiss ' ] ) || ! isset ( $ _GET ['_wpnonce ' ] ) ) {
1035+ return ;
1036+ }
1037+
1038+ $ dismiss = sanitize_text_field ( wp_unslash ( $ _GET ['nginx_helper_dismiss ' ] ) );
1039+ $ nonce = sanitize_text_field ( wp_unslash ( $ _GET ['_wpnonce ' ] ) );
1040+
1041+ // Verify the correct nonce depending on whether this is a purge+dismiss or dismiss-only request.
1042+ $ has_purge_params = isset ( $ _GET ['nginx_helper_action ' ], $ _GET ['nginx_helper_urls ' ] );
1043+ $ nonce_verified = $ has_purge_params ? wp_verify_nonce ( $ nonce , 'nginx_helper-purge_all ' ) : wp_verify_nonce ( $ nonce , 'nginx_helper_dismiss_notice ' );
1044+
1045+ if ( $ dismiss && $ nonce_verified ) {
1046+
1047+ delete_transient ( 'rt_wp_nginx_helper_suggest_purge_notice ' );
1048+ wp_safe_redirect ( remove_query_arg ( array ( 'nginx_helper_dismiss ' , '_wpnonce ' ) ) );
1049+ exit ;
1050+ }
1051+ }
1052+
9781053 /**
9791054 * Initialize WooCommerce hooks if enabled.
9801055 *
0 commit comments