Make WordPress Core

Ticket #41: 0000041-apply_filters.html

File 0000041-apply_filters.html, 1.9 KB (added by Agent Orange, 21 years ago)
Line 
1<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN">
2
3<html>
4<head>
5 <title>link_pages()</title>
6</head>
7
8<body>
9<a name="original"><h3>apply_filters() original:</h3></a>
10<pre>function apply_filters($tag, $string) {
11 global $wp_filter;
12 if (isset($wp_filter['all'])) {
13 foreach ($wp_filter['all'] as $priority => $functions) {
14 if (isset($wp_filter[$tag][$priority]))
15 $wp_filter[$tag][$priority] = array_merge($wp_filter['all'][$priority], $wp_filter[$tag][$priority]);
16 else
17 $wp_filter[$tag][$priority] = array_merge($wp_filter['all'][$priority], array());
18 $wp_filter[$tag][$priority] = array_unique($wp_filter[$tag][$priority]);
19 }
20
21 }
22
23 if (isset($wp_filter[$tag])) {
24 ksort($wp_filter[$tag]);
25 foreach ($wp_filter[$tag] as $priority => $functions) {
26 <span style="color: red;">foreach($functions as $function)</span> {
27 $string = $function($string);
28 }
29 }
30 }
31 return $string;
32}</pre>
33
34<a name="fixed"><h3>apply_filters() fixed:</h3></a>
35<pre>function apply_filters($tag, $string) {
36 global $wp_filter;
37 if (isset($wp_filter['all'])) {
38 foreach ($wp_filter['all'] as $priority => $functions) {
39 if (isset($wp_filter[$tag][$priority]))
40 $wp_filter[$tag][$priority] = array_merge($wp_filter['all'][$priority], $wp_filter[$tag][$priority]);
41 else
42 $wp_filter[$tag][$priority] = array_merge($wp_filter['all'][$priority], array());
43 $wp_filter[$tag][$priority] = array_unique($wp_filter[$tag][$priority]);
44 }
45
46 }
47
48 if (isset($wp_filter[$tag])) {
49 ksort($wp_filter[$tag]);
50 foreach ($wp_filter[$tag] as $priority => $functions) {
51 <span style="color: green; font-weight: bold;">if (!is_null($functions)) {</span>
52 foreach($functions as $function) {
53 $string = $function($string);
54 }
55 <span style="color: green; font-weight: bold;">}</span>
56 }
57 }
58 return $string;
59} </pre>
60
61
62</body>
63</html>