WordPress.org

Make WordPress Core

Ticket #10334: alias_filters.php

File alias_filters.php, 2.2 KB (added by dcole07, 5 years ago)

There is one master hook name and other alias names.

Line 
1<?php
2// Author: Dan Cole
3// username: dcole07
4// Data: July 13, 2009
5
6/**
7 * Combine the filters that are aliass
8 *
9 * This functions shares all functions under the hook names that represent the same location.
10 *
11 * @global array $alias_filters Stores all of the alias filter names
12 * @global array $wp_filter Stores all of the filters
13 * @global array $wp_current_filter stores the list of current filters with the current one last
14 */
15function merge_alias_filters() {
16  global $alias_filters, $wp_filter, $wp_current_filter, $merged_filters;
17  $tag = current($wp_current_filter);
18  if (isset($alias_filters[$tag]) && !isset($merged_filters[$tag])) {
19    if ($alias_filters[$tag] != FALSE) {
20      foreach ((array)$alias_filters[$tag] as $alias) {
21        if (isset($wp_filter[$alias])) {
22          foreach ((array)$wp_filter[$alias] as $priority => $the_) {
23            $wp_filter[$tag][$priority] = $the_;
24          }
25        }
26      }
27    }
28  }
29}
30add_action('all', 'merge_alias_filters');
31
32/**
33 * Makes a list of filter names that share the same location
34 *
35 * This function makes a multi-demensional list of filter names that are aliass
36 *
37 * @global array $alias_filters Stores all of the alias filter names
38 * @global array $merged_filters Tracks the tags that need to be merged for later.
39 *
40 * @param string $hook the main name.
41 * @param string $tags The names of the filters that are alias.
42 */
43function add_filter_alias($hook, $tags) {
44  global $alias_filters, $merged_filters;
45  if (!is_array($tags)) {
46    $tags = array($tags);
47  }
48  foreach ($tags as $tag) {
49    $alias_filters[$hook][$tag] = $tag;
50  }
51  unset($merged_filters[$hook]);
52  return true;
53}
54/**
55 * Example usage:
56 * add_filter_alias('theme_header', array('thematic_header', 'hybrid_header', 'prodigy_header', 'th_header'));
57 */
58
59/**
60 * Makes a list of actions names that share the same location
61 *
62 * This function is a alias for add_filter_aliass
63 *
64 * @uses add_filter_alias() Adds an action. Parameter list and functionality are the same.
65 *
66 * @param string $hook the main name.
67 * @param array or string $tags The names of the filters that are alias.
68 */
69function add_action_alias($hook, $tags) {
70  return add_filter_alias($hook, $tags);
71}
72?>