/** * Function to display the Filters applied to current request. * * @return string $output display output for the filters panel */ function debug_bar_action_and_filters_addon_display_filters() { global $wp_filter; $output = ''; $output .= '<div class="hooks_listing_container">' . "\n"; $output .= '<h2>List of Filter Hooks (with functions)</h2><br />' . "\n"; $output .= "<ul>\n"; foreach ($wp_filter as $filter_key => $filter_val) { $output .= '<li>'; $output .= '<strong>' . $filter_key . "</strong><br />\n"; $output .= "<ul>\n"; ksort($filter_val); foreach ($filter_val as $priority => $functions) { $output .= '<li>'; $output .= 'Priority: ' . $priority . "<br />\n"; $output .= "<ul>\n"; foreach ($functions as $single_function) { if (!is_string($single_function['function']) && !is_object($single_function['function']) && (!is_array($single_function['function']) || is_array($single_function['function']) && (!is_string($single_function['function'][0]) && !is_object($single_function['function'][0])))) { // Type 1 - not a callback continue; } elseif (dbafa_is_closure($single_function['function'])) { // Type 2 - closure $output .= '<li>[<em>closure</em>]</li>'; } elseif ((is_array($single_function['function']) || is_object($single_function['function'])) && dbafa_is_closure($single_function['function'][0])) { // Type 3 - closure within an array $output .= '<li>[<em>closure</em>]</li>'; } elseif (is_string($single_function['function']) && strpos($single_function['function'], '::') === false) { // Type 4 - simple string function (includes lambda's) $output .= '<li>' . sanitize_text_field($single_function['function']) . '</li>'; } elseif (is_string($single_function['function']) && strpos($single_function['function'], '::') !== false) { // Type 5 - static class method calls - string $output .= '<li>[<em>class</em>] ' . str_replace('::', ' :: ', sanitize_text_field($single_function['function'])) . '</li>'; } elseif (is_array($single_function['function']) && (is_string($single_function['function'][0]) && is_string($single_function['function'][1]))) { // Type 6 - static class method calls - array $output .= '<li>[<em>class</em>] ' . sanitize_text_field($single_function['function'][0]) . ' :: ' . sanitize_text_field($single_function['function'][1]) . '</li>'; } elseif (is_array($single_function['function']) && (is_object($single_function['function'][0]) && is_string($single_function['function'][1]))) { // Type 7 - object method calls $output .= '<li>[<em>object</em>] ' . get_class($single_function['function'][0]) . ' -> ' . sanitize_text_field($single_function['function'][1]) . '</li>'; } else { // Type 8 - undetermined $output .= '<li><pre>' . var_export($single_function, true) . '</pre></li>'; } } $output .= "</ul>\n"; $output .= "</li>\n"; } $output .= "</ul>\n"; $output .= "</li>\n"; } $output .= "</ul>\n"; $output .= "</div>\n"; return $output; }
/** * Function to display the Filters applied to current request. * * @return string $output display output for the filters panel */ function debug_bar_action_and_filters_addon_display_filters() { $wp_filter = $GLOBALS['wp_filter']; ksort($wp_filter); /* Create header row. */ $header_row = ' <tr> <th>' . esc_html__('Hook', 'debug-bar-actions-and-filters-addon') . '</th> <th>' . esc_html__('Priority', 'debug-bar-actions-and-filters-addon') . '</th> <th>' . esc_html__('Registered callbacks', 'debug-bar-actions-and-filters-addon') . '</th> </tr>'; $table = '<table class="debug-bar-table debug-bar-actions-filters"> <thead>' . $header_row . ' </thead> <tfoot>' . $header_row . ' </tfoot> <tbody>'; $hook_in_count = 0; $callbacks_registered = array(); foreach ($wp_filter as $filter_key => $filter_val) { $filter_count = count($filter_val); $rowspan = ''; if ($filter_count > 1) { $rowspan = ' rowspan="' . $filter_count . '"'; } $table .= ' <tr> <th' . $rowspan . '>' . esc_html($filter_key) . '</th>'; if ($filter_count > 0) { ksort($filter_val); $first = true; foreach ($filter_val as $priority => $functions) { if ($first !== true) { $table .= ' <tr>'; } else { $first = false; } $table .= ' <td class="prio">' . intval($priority) . '</td> <td><ul>'; foreach ($functions as $single_function) { $signature = $single_function['function']; if (!is_string($single_function['function']) && !is_object($single_function['function']) && (!is_array($single_function['function']) || is_array($single_function['function']) && (!is_string($single_function['function'][0]) && !is_object($single_function['function'][0])))) { // Type 1 - not a callback continue; } elseif (dbafa_is_closure($single_function['function'])) { // Type 2 - closure $table .= '<li>[<em>' . esc_html__('closure', 'debug-bar-actions-and-filters-addon') . '</em>]</li>'; $signature = get_class($single_function['function']) . $hook_in_count; } elseif ((is_array($single_function['function']) || is_object($single_function['function'])) && dbafa_is_closure($single_function['function'][0])) { // Type 3 - closure within an array $table .= '<li>[<em>' . esc_html__('closure', 'debug-bar-actions-and-filters-addon') . '</em>]</li>'; $signature = get_class($single_function['function']) . $hook_in_count; } elseif (is_string($single_function['function']) && strpos($single_function['function'], '::') === false) { // Type 4 - simple string function (includes lambda's) $signature = sanitize_text_field($single_function['function']); $table .= '<li>' . $signature . '</li>'; } elseif (is_string($single_function['function']) && strpos($single_function['function'], '::') !== false) { // Type 5 - static class method calls - string $signature = str_replace('::', ' :: ', sanitize_text_field($single_function['function'])); $table .= '<li>[<em>' . esc_html__('class', 'debug-bar-actions-and-filters-addon') . '</em>] ' . $signature . '</li>'; } elseif (is_array($single_function['function']) && (is_string($single_function['function'][0]) && is_string($single_function['function'][1]))) { // Type 6 - static class method calls - array $signature = sanitize_text_field($single_function['function'][0]) . ' :: ' . sanitize_text_field($single_function['function'][1]); $table .= '<li>[<em>' . esc_html__('class', 'debug-bar-actions-and-filters-addon') . '</em>] ' . $signature . '</li>'; } elseif (is_array($single_function['function']) && (is_object($single_function['function'][0]) && is_string($single_function['function'][1]))) { // Type 7 - object method calls $signature = esc_html(get_class($single_function['function'][0])) . ' -> ' . sanitize_text_field($single_function['function'][1]); $table .= '<li>[<em>' . esc_html__('object', 'debug-bar-actions-and-filters-addon') . '</em>] ' . $signature . '</li>'; } else { // Type 8 - undetermined $table .= '<li><pre>' . var_export($single_function, true) . '</pre></li>'; } $hook_in_count++; $callbacks_registered[] = $signature; } $table .= '</ul></td> </tr>'; } } else { $table .= '<td> </td><td> </td> </tr>'; } } $table .= ' </tbody> </table>'; $unique_callbacks = count(array_unique($callbacks_registered)); $output = ' <div class="hooks_listing_container"> <h2><span>' . esc_html__('Total hooks with registered actions/filters:', 'debug-bar-actions-and-filters-addon') . '</span>' . count($wp_filter) . '</h2> <h2><span>' . esc_html__('Total registered callbacks:', 'debug-bar-actions-and-filters-addon') . '</span>' . $hook_in_count . '</h2> <h2><span>' . esc_html__('Unique registered callbacks:', 'debug-bar-actions-and-filters-addon') . '</span>' . $unique_callbacks . '</h2> ' . $table . ' </div>'; return $output; }