-
Notifications
You must be signed in to change notification settings - Fork 3
/
wp-hook-examples.php
45 lines (38 loc) · 1.35 KB
/
wp-hook-examples.php
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
<?php
/**
* Plugin Name: WordPress Hook Examples
* Description: Examples of various ways hooks can be added within plugins. Try to remove them all. DO NOT ACTIVATE ON A LIVE SITE!
*/
// Don't run in the admin.
if ( is_admin() ) {
return;
}
/**
* Helper method to die and display the calling method.
*/
function hookex_die() {
// Don't die if the user doesn't have the 'manage_options' capability.
if ( ! current_user_can( 'manage_options' ) ) {
return;
}
$dbt = debug_backtrace();
$method = empty( $dbt[1]['class'] ) ? '' : $dbt[1]['class'] . '::';
$method .= $dbt[1]['function'] . '()';
wp_die( 'Hookex strikes again!<br><br><code>' . $method . '</code>' );
}
/**
* Include the examples.
*
* Try removing all the hooks preventing your site from displaying.
* @link http://codex.wordpress.org/Function_Reference/remove_action
*/
include( dirname( __FILE__ ) . '/examples/procedural.php' );
include( dirname( __FILE__ ) . '/examples/object.php' );
include( dirname( __FILE__ ) . '/examples/singleton.php' );
include( dirname( __FILE__ ) . '/examples/static-class.php' );
include( dirname( __FILE__ ) . '/examples/mixed-class.php' );
/**
* Examples of hooks that can't be easily manipulated because they're inaccessible.
*/
// include( dirname( __FILE__ ) . '/examples/closure.php' );
// include( dirname( __FILE__ ) . '/examples/inaccessible-object.php' );