WordPress.org

Make WordPress Core

Ticket #10334: synonym_filters.php

File synonym_filters.php, 2.5 KB (added by dcole07, 6 years ago)

Every synonym shares hooked functions with each other.

Line 
1<?php
2// Author: Dan Cole
3// username: dcole07
4// Data: July 13, 2009
5
6/**
7 * Combine the filters that are synonyms
8 *
9 * This functions shares all functions under the hook names that represent the same location.
10 *
11 * @global array $synonym_filters Stores all of the synonym 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_synonym_filters() {
16  global $synonym_filters, $wp_filter, $wp_current_filter, $merged_filters;
17  $tag = current($wp_current_filter);
18  if (isset($synonym_filters[$tag]) && !isset($merged_filters[$tag])) {
19    if ($synonym_filters[$tag] != FALSE) {
20      foreach ((array)$synonym_filters[$tag] as $synonym) {
21        if (isset($wp_filter[$synonym])) {
22          foreach ((array)$wp_filter[$synonym] as $priority => $the_) {
23            $wp_filter[$tag][$priority] = $the_;
24          }
25        }
26      }
27    }
28  }
29}
30add_action('all', 'merge_synonym_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 synonyms
36 *
37 * @global array $synonym_filters Stores all of the synonym filter names
38 * @global array $merged_filters Tracks the tags that need to be merged for later.
39 *
40 * @param string $tags The names of the filters that are synonyms.
41 */
42function add_filter_synonyms($tags) {
43  global $synonym_filters, $merged_filters;
44  foreach ($tags as $tag) {
45    if (isset($synonym_filters[$tag])) {
46      $tags = array_merge((array)$tags, (array)$synonym_filters[$tag]);
47    }
48  }
49  foreach ($tags as $tag) {
50    foreach ($tags as $synonym) {
51      if ($tag != $synonym) {
52        $synonym_filters[$tag][$synonym] = $synonym;
53      }
54    }
55    unset($merged_filters[$tag]);
56  }
57  return true;
58}
59/**
60 * Example usage:
61 * add_filter_synonyms(array('thematic_header', 'hybrid_header', 'prodigy_header', 'th_header', 'theme_header'));
62 */
63
64/**
65 * Makes a list of actions names that share the same location
66 *
67 * This function is a synonym for add_filter_synonyms
68 *
69 * @uses add_filter_synonyms() Adds an action. Parameter list and functionality are the same.
70 *
71 * @global array $synonym_filters Stores all of the synonym filter names
72 * @global array $merged_filters Tracks the tags that need to be merged for later.
73 *
74 * @param string $tags The names of the filters that are synonyms.
75 */
76function add_action_synonyms($tags) {
77  return add_filter_synonyms($tags);
78}
79?>