Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Automate Locating Hooks #24

Closed
salcode opened this issue Apr 5, 2017 · 9 comments
Closed

Automate Locating Hooks #24

salcode opened this issue Apr 5, 2017 · 9 comments
Milestone

Comments

@salcode
Copy link
Contributor

salcode commented Apr 5, 2017

In the Genesis slack genesiswp.slack.com there was a recent discussion about how awesome this plugin is.

It was however pointed out that some of the newer hooks are not included (e.g. #19).

During this conversation, @GaryJones pointed out

Should there not be a way to look for all filters / action hooks, and only do something (show something visual) if the prefix is genesis_? That seems more logical than trying to find and whitelist each one (and would handle dynamically named hooks too).

Thinking this was a good idea, we came up with a proof of concept

add_action( 'all', function() {
	global $wp_actions;
	$filter = current_filter();

	if ( 'genesis_' === substr( $filter, 0, 8 ) ) {
		if ( isset( $wp_actions[ $filter ] ) ) {
			printf('<div style="background-color: #666; border: 1px solid #F89E43; color: #F89E43; margin: 10px; padding: 2px 5px; overflow: hidden; word-wrap: break-word; cursor: help;">%s</div>', $filter );
		}
	}
} );

It is worth noting this technique does drop the hook description currently included in the title attribute, however I'd like to vote that this tradeoff is worthwhile.

@salcode
Copy link
Contributor Author

salcode commented Apr 5, 2017

This code includes hooks in the header that are not originally displayed with this plugin.

New Behavior

screenshot 2017-04-05 14 44 39

Original Behavior

image

@salcode
Copy link
Contributor Author

salcode commented Apr 5, 2017

The genesis_header_right action does not display when using this new code.

New Behavior

screenshot 2017-04-05 14 54 48

Original Behavior

image

@GaryJones
Copy link

re Header Right, of there's no widget, then the hook does not fire, so it doesn't make sense to show it artificially. The same would likely apply if there are no footer widgets too.

There are some filters that are not prefixed with genesis_ which should be checked for:

  • get_the_content_limit
  • get_the_content_limit_more_link
  • get_the_content_limit_allowedtags
  • the_content_limit
  • g_ent (deprecated in 2.0.0)

There are two action hooks which are not prefixed with genesis_, both for wp-admin (so not visually shown on the front-end, but included here for reference):

  • {$this->pagehook}_settings_page_boxes
  • {$this->pagehook}_settings_page_form

GaryJones referenced this issue in srikat/Genesis-Simple-Hook-Guide Apr 6, 2017
@salcode
Copy link
Contributor Author

salcode commented Apr 6, 2017

I'm of two minds regarding displaying hooks where nothing is to be displayed (e.g. genesis_header_right). While I see your point about not displaying it, it is nice to know it is there in case you want to use it.

re Header Right, of there's no widget, then the hook does not fire, so it doesn't make sense to show it artificially. The same would likely apply if there are no footer widgets too.

Currently PR #25, duplicates the current behavior of always showing the genesis_header_right action.

There are some filters that are not prefixed with genesis_ which should be checked for:

This issue and PR focus on actions, see #27 for more discussion on filters.

@GaryJones
Copy link

GaryJones commented Apr 6, 2017

While I see your point about not displaying it, it is nice to know it is there in case you want to use it.

But, unless one either actually adds a widget, or makes use of the action hook in some other way (therefore, one already knows about it), one can't make use of it.

@salcode
Copy link
Contributor Author

salcode commented Apr 6, 2017

But, unless you either actually add a widget, or make use of the filter in some other way (therefore, one already knows about it), one can't make use of it.

The scenario I'm imagining is.

  • currently there is nothing in the genesis_header_right header, so it does not display
  • however, I find myself thinking - "I want to put some content to the right of the title. I wish there were an area there I could hook into."
  • since we're not displaying the hook, there isn't an easy way for me to discover this area

While this may be a small benefit, I don't see a downside to displaying it. @GaryJones, are you concerned displaying that area may throw off the layout of some sites?

@GaryJones
Copy link

however, I find myself thinking - "I want to put some content to the right of the title. I wish there were an area there I could hook into."

👍

@christophercochran
Copy link
Owner

This is a great conversation, and a great idea. Also, though the lost of the description is lost, this could easily be added back through js references to each the hooks generated.

I also do agree with the header right hook. Going to play with this idea this weekend, with auto generated, and hooks that are conditionally shown as per some requirement.

Thanks for all this!

christophercochran pushed a commit that referenced this issue Apr 8, 2017
By using this later hook, we avoid displaying hooks that only appear in
the markup head.

See #25
See #24
christophercochran pushed a commit that referenced this issue Apr 8, 2017
It appears Genesis has code to skip the genesis_header_right action if
no widgets appear in this widget area.  In which case, the hook does not
display.

To avoid this problem, we are hooking into genesis_header_right and
displaying nothing (i.e. an empty string '').  Even though we're
displaying an empty string, this is enough to allow the
genesis_header_right action to occur.

I've not spotted any other actions that behave in this manner but if
there are, we'll need to add them manually, as well.

Specifically, neither the Primary nor Secondary sidebar show this
behavior.

See #25
See #24
@christophercochran
Copy link
Owner

This is now merged into the develop branch. Going to be doing some testing and readying a release with this, so again thank you very much.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

No branches or pull requests

3 participants