add_action( 'wp_enqueue_scripts', 'my_plugin_enqueue_scripts' ); function my_plugin_enqueue_scripts() { wp_enqueue_script( 'my-plugin-script', plugin_dir_url( __FILE__ ) . 'js/my-plugin.js' ); }
class UserController extends Controller { public function __construct() { $this->middleware('auth'); $this->middleware(function ($request, $next) { // Perform some custom behavior return $next($request); }); } }In this code, we’re using the ‘middleware’ function to listen for two hooks in the Laravel framework: ‘auth’ and a custom middleware function. When either of these hooks is triggered, the specified code is executed, allowing us to modify the behavior of the controller. In both of these examples, we’re using built-in hooks that are part of the WordPress and Laravel frameworks. However, there are also numerous third-party hook libraries available for PHP, such as ‘The Hook’ and ‘Hooker’. These libraries provide additional hooks and functionality beyond what is built into the base frameworks, allowing developers to further customize and extend their applications.