WordPress.org

Make WordPress Core

Ticket #10493: closure_testing.php

File closure_testing.php, 474 bytes (added by scribu, 5 years ago)
Line 
1<?php
2/*
3Plugin Name: Closure Testing
4*/
5
6// Simple example
7add_action('closures_rock', function() {
8        echo "Hi!\n";
9});
10
11// More realistic usage
12$greeting = 'Hello';
13
14add_action('closures_rock', function($first_name, $last_name) use ($greeting) {
15        echo "$greeting, $first_name $last_name!\n";
16}, 10, 2);
17
18// Testing
19add_action('admin_notices', 'closures_rock');
20function closures_rock() {
21        echo "<pre>";
22        do_action('closures_rock', 'Ronald', 'McDonald');
23        echo "</pre>";
24}
25