|
1
|
|
|
<?php |
|
2
|
|
|
|
|
3
|
|
|
// For adding hooks before loading WP |
|
4
|
|
|
function tests_add_filter($tag, $function_to_add, $priority = 10, $accepted_args = 1) { |
|
5
|
|
|
global $wp_filter, $merged_filters; |
|
6
|
|
|
|
|
7
|
|
|
$idx = _test_filter_build_unique_id($tag, $function_to_add, $priority); |
|
8
|
|
|
$wp_filter[$tag][$priority][$idx] = array('function' => $function_to_add, 'accepted_args' => $accepted_args); |
|
9
|
|
|
unset( $merged_filters[ $tag ] ); |
|
10
|
|
|
return true; |
|
11
|
|
|
} |
|
12
|
|
|
|
|
13
|
|
|
function _test_filter_build_unique_id($tag, $function, $priority) { |
|
|
|
|
|
|
14
|
|
|
global $wp_filter; |
|
15
|
|
|
static $filter_id_count = 0; |
|
16
|
|
|
|
|
17
|
|
|
if ( is_string($function) ) |
|
18
|
|
|
return $function; |
|
19
|
|
|
|
|
20
|
|
|
if ( is_object($function) ) { |
|
21
|
|
|
// Closures are currently implemented as objects |
|
22
|
|
|
$function = array( $function, '' ); |
|
23
|
|
|
} else { |
|
24
|
|
|
$function = (array) $function; |
|
25
|
|
|
} |
|
26
|
|
|
|
|
27
|
|
|
if (is_object($function[0]) ) { |
|
28
|
|
|
return spl_object_hash($function[0]) . $function[1]; |
|
29
|
|
|
} else if ( is_string($function[0]) ) { |
|
30
|
|
|
// Static Calling |
|
31
|
|
|
return $function[0].$function[1]; |
|
32
|
|
|
} |
|
33
|
|
|
} |
|
34
|
|
|
|
|
35
|
|
|
function _delete_all_posts() { |
|
36
|
|
|
global $wpdb; |
|
37
|
|
|
|
|
38
|
|
|
$all_posts = $wpdb->get_col("SELECT ID from {$wpdb->posts}"); |
|
39
|
|
|
if ($all_posts) { |
|
40
|
|
|
foreach ($all_posts as $id) |
|
41
|
|
|
wp_delete_post( $id, true ); |
|
42
|
|
|
} |
|
43
|
|
|
} |
|
44
|
|
|
|
|
45
|
|
|
class Basic_Object { |
|
46
|
|
|
private $foo = 'bar'; |
|
|
|
|
|
|
47
|
|
|
|
|
48
|
|
|
public function __get( $name ) { |
|
49
|
|
|
return $this->$name; |
|
50
|
|
|
} |
|
51
|
|
|
|
|
52
|
|
|
public function __set( $name, $value ) { |
|
53
|
|
|
return $this->$name = $value; |
|
54
|
|
|
} |
|
55
|
|
|
|
|
56
|
|
|
public function __isset( $name ) { |
|
57
|
|
|
return isset( $this->$name ); |
|
58
|
|
|
} |
|
59
|
|
|
|
|
60
|
|
|
public function __unset( $name ) { |
|
61
|
|
|
unset( $this->$name ); |
|
62
|
|
|
} |
|
63
|
|
|
|
|
64
|
|
|
public function __call( $name, $arguments ) { |
|
65
|
|
|
return call_user_func_array( array( $this, $name ), $arguments ); |
|
66
|
|
|
} |
|
67
|
|
|
|
|
68
|
|
|
private function callMe() { |
|
69
|
|
|
return 'maybe'; |
|
70
|
|
|
} |
|
71
|
|
|
} |
|
72
|
|
|
|
|
73
|
|
|
class Basic_Subclass extends Basic_Object {} |
|
74
|
|
|
|
|
75
|
|
|
function _wp_die_handler( $message, $title = '', $args = array() ) { |
|
76
|
|
|
if ( !$GLOBALS['_wp_die_disabled'] ) { |
|
77
|
|
|
_wp_die_handler_txt( $message, $title, $args); |
|
78
|
|
|
} else { |
|
|
|
|
|
|
79
|
|
|
//Ignore at our peril |
|
80
|
|
|
} |
|
81
|
|
|
} |
|
82
|
|
|
|
|
83
|
|
|
function _disable_wp_die() { |
|
84
|
|
|
$GLOBALS['_wp_die_disabled'] = true; |
|
85
|
|
|
} |
|
86
|
|
|
|
|
87
|
|
|
function _enable_wp_die() { |
|
88
|
|
|
$GLOBALS['_wp_die_disabled'] = false; |
|
89
|
|
|
} |
|
90
|
|
|
|
|
91
|
|
|
function _wp_die_handler_filter() { |
|
92
|
|
|
return '_wp_die_handler'; |
|
93
|
|
|
} |
|
94
|
|
|
|
|
95
|
|
|
function _wp_die_handler_txt( $message, $title, $args ) { |
|
96
|
|
|
echo "\nwp_die called\n"; |
|
97
|
|
|
echo "Message : $message\n"; |
|
98
|
|
|
echo "Title : $title\n"; |
|
99
|
|
|
if ( ! empty( $args ) ) { |
|
100
|
|
|
echo "Args: \n"; |
|
101
|
|
|
foreach( $args as $k => $v ){ |
|
102
|
|
|
echo "\t $k : $v\n"; |
|
103
|
|
|
} |
|
104
|
|
|
} |
|
105
|
|
|
} |
|
106
|
|
|
|
|
107
|
|
|
/** |
|
108
|
|
|
* Set a permalink structure. |
|
109
|
|
|
* |
|
110
|
|
|
* Hooked as a callback to the 'populate_options' action, we use this function to set a permalink structure during |
|
111
|
|
|
* `wp_install()`, so that WP doesn't attempt to do a time-consuming remote request. |
|
112
|
|
|
* |
|
113
|
|
|
* @since 4.2.0 |
|
114
|
|
|
*/ |
|
115
|
|
|
function _set_default_permalink_structure_for_tests() { |
|
116
|
|
|
update_option( 'permalink_structure', '/%year%/%monthnum%/%day%/%postname%/' ); |
|
117
|
|
|
} |
|
118
|
|
|
|
This check looks from parameters that have been defined for a function or method, but which are not used in the method body.