From 0c7ec149189b75b27f63e1fc4bad7b2e04aa8d18 Mon Sep 17 00:00:00 2001 From: "prab.ch" Date: Sat, 17 Sep 2022 19:29:57 +0530 Subject: [PATCH] Added support for WordPress built in functions when creating hooks Currently a hook defined as below would throw an error under Php 8 $this->loader->add_filter( 'woocommerce_single_product_zoom_enabled', null, '__return_false' ); This change let someone set the hook component as null, thus making built in WordPress functions accessible within the plugin using $this->loader->add_action or $this->loader->add_filter methods --- plugin-name/includes/class-plugin-name-loader.php | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/plugin-name/includes/class-plugin-name-loader.php b/plugin-name/includes/class-plugin-name-loader.php index 634ec4757..d878e98fc 100644 --- a/plugin-name/includes/class-plugin-name-loader.php +++ b/plugin-name/includes/class-plugin-name-loader.php @@ -117,11 +117,11 @@ private function add( $hooks, $hook, $component, $callback, $priority, $accepted public function run() { foreach ( $this->filters as $hook ) { - add_filter( $hook['hook'], array( $hook['component'], $hook['callback'] ), $hook['priority'], $hook['accepted_args'] ); + add_filter( $hook['hook'], ($hook['component'] ? array( $hook['component'], $hook['callback'] ) : $hook['callback']), $hook['priority'], $hook['accepted_args'] ); } foreach ( $this->actions as $hook ) { - add_action( $hook['hook'], array( $hook['component'], $hook['callback'] ), $hook['priority'], $hook['accepted_args'] ); + add_action( $hook['hook'], ($hook['component'] ? array( $hook['component'], $hook['callback'] ) : $hook['callback']), $hook['priority'], $hook['accepted_args'] ); } }