Skip to content

Commit

Permalink
- added 'Actions (active)' option to show only those hooks that are c…
Browse files Browse the repository at this point in the history
…urrently in use.

- updated reference to plugins folder to point to css at all times
- updated styles to make sure hook blocks appear over content that might otherwise obscure them
- updated for WordPress 4.7 WP_Hook class
  • Loading branch information
hughc committed Apr 10, 2017
1 parent 3df4cb5 commit f003a10
Show file tree
Hide file tree
Showing 2 changed files with 45 additions and 5 deletions.
48 changes: 43 additions & 5 deletions g-hooks.php
Original file line number Diff line number Diff line change
Expand Up @@ -50,6 +50,15 @@ function gvhg_admin_bar_links() {
'position' => 10,
)
);
$wp_admin_bar->add_menu(
array(
'id' => 'ghooks_action_active',
'parent' => 'ghooks',
'title' => __( 'Action Hooks (active)', 'gvisualhookguide' ),
'href' => add_query_arg( 'g_hooks_active', 'show' ),
'position' => 10,
)
);
$wp_admin_bar->add_menu(
array(
'id' => 'ghooks_filter',
Expand All @@ -76,6 +85,7 @@ function gvhg_admin_bar_links() {
'href' => remove_query_arg(
array(
'g_hooks',
'g_hooks_active',
'g_filters',
'g_markup',
)
Expand All @@ -89,11 +99,14 @@ function gvhg_admin_bar_links() {
add_action('wp_enqueue_scripts', 'gvhg_hooks_stylesheet');
function gvhg_hooks_stylesheet() {

$gvhg_plugin_url = plugins_url() . '/genesis-visual-hook-guide/';
$gvhg_plugin_url = plugin_dir_url( __FILE__ );

if ( 'show' == isset( $_GET['g_hooks'] ) )
wp_enqueue_style( 'gvhg_styles', $gvhg_plugin_url . 'styles.css' );

if ( 'show' == isset( $_GET['g_hooks_active'] ) )
wp_enqueue_style( 'gvhg_styles', $gvhg_plugin_url . 'styles.css' );

if ( 'show' == isset( $_GET['g_filters'] ) )
wp_enqueue_style( 'gvhg_styles', $gvhg_plugin_url . 'styles.css' );

Expand All @@ -107,7 +120,7 @@ function gvhg_hooks_stylesheet() {
function gvhg_genesis_hooker() {
global $gvhg_genesis_action_hooks;

if ( !('show' == isset( $_GET['g_hooks'] ) ) && !('show' == isset( $_GET['g_filters'] ) ) && !('show' == isset( $_GET['g_markup'] ) ) ) {
if ( !('show' == isset( $_GET['g_hooks_active'] ) ) && !('show' == isset( $_GET['g_hooks'] ) ) && !('show' == isset( $_GET['g_filters'] ) ) && !('show' == isset( $_GET['g_markup'] ) ) ) {
return; // BAIL without hooking into anyhting if not displaying anything
}

Expand Down Expand Up @@ -464,8 +477,9 @@ function gvhg_genesis_action_hook () {
global $gvhg_genesis_action_hooks;

$current_action = current_filter();
$showActive = 'show' == isset( $_GET['g_hooks_active'] );

if ( 'show' == isset( $_GET['g_hooks'] ) ) {
if ( 'show' == isset( $_GET['g_hooks'] ) || $showActive ) {

if ( 'Document Head' == $gvhg_genesis_action_hooks[$current_action]['area'] ) :

Expand All @@ -475,8 +489,32 @@ function gvhg_genesis_action_hook () {

else :

echo '<div class="genesis_hook" title="' . $gvhg_genesis_action_hooks[$current_action]['description'] . '">' . $current_action . '</div>';

if ($showActive) {
global $wp_filter;
$currentHookObj = $wp_filter[$current_action];

if (is_a( $currentHookObj , "WP_Hook")) {
$currentHook = $currentHookObj->callbacks;
} else {
$currentHook = $currentHookObj;
}

if (count($currentHook) > 1) {
// only show if there are hooks active
echo '<div class="genesis_hook" title="' . $gvhg_genesis_action_hooks[$current_action]['description'] . '">' . $current_action;
// echo "got one!";
echo "<ul>";
foreach ($currentHook as $key => $value) {
$action_name = array_keys($value)[0];
if ($action_name != 'gvhg_genesis_action_hook') echo '<li>' . ($key) . ': ' . $action_name . '</li>';
}
echo "</ul>";

};
} else {
echo '<div class="genesis_hook" title="' . $gvhg_genesis_action_hooks[$current_action]['description'] . '">' . $current_action;
}
echo '</div>';
endif;
}

Expand Down
2 changes: 2 additions & 0 deletions styles.css
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,8 @@
overflow: hidden;
word-wrap: break-word;
cursor: help;
position: relative;
z-index: 1000;
}

.wordpress_hook {
Expand Down

0 comments on commit f003a10

Please sign in to comment.