WordPress.org

Make WordPress Core

Opened 5 years ago

Closed 5 years ago

#10232 closed enhancement (invalid)

Add new hooks called after template parts are loaded

Reported by: sirzooro Owned by:
Milestone: Priority: normal
Severity: normal Version: 2.8
Component: Template Keywords: has-patch
Focuses: Cc:

Description

At this moment functions get_header() and other similar ones do actions get_header, etc. at the beginning. I have changed them (see attached patch) to also do post_get_header, etc. actions at the end.

In particular I need post_get_sidebar action for my plugin, to distinguish cases when loop_start/loop_end actions are called for main post list from these in sidebar widgets.

Attachments (2)

comment-template.php.diff (298 bytes) - added by sirzooro 5 years ago.
general-template.php.diff (804 bytes) - added by sirzooro 5 years ago.

Download all attachments as: .zip

Change History (10)

comment:1 Denis-de-Bernardy5 years ago

  • Milestone 2.8.1 deleted
  • Resolution set to invalid
  • Status changed from new to closed

use the loop_start and loop_end hooks.

comment:2 Denis-de-Bernardy5 years ago

in them, verify that wp_query === wp_the_query. if true you're in the main loop.

comment:3 dd325 years ago

sirzooro: Do you have any objections to the idea of using loop_start? Do you have a specific use which would make sense for extra hooks? (If so, reopen)

comment:4 Denis-de-Bernardy5 years ago

My understanding of his report is he's love to use loop_start/loop_end, but didn't know how to check whether we're in the main loop or not. Maybe we should document this somewhere in the codex or the php docs.

comment:5 sirzooro5 years ago

@Denis: you are right. I will check your suggestion later today. Hope it will work as expected :)

comment:6 sirzooro5 years ago

  • Milestone set to 2.8.1
  • Resolution invalid deleted
  • Status changed from closed to reopened

I have checked following code but it does not work as expected - test string was displayed above posts and above entries in recent post list. Could you check this?

function loop_start_handler() {
    global $wp_query, $wp_the_query;
    if ( $wp_query === $wp_the_query ) {
        echo '<p style="color:red">TEST</p>';
    }
}

comment:7 Denis-de-Bernardy5 years ago

try this instead:

function loop_start_handler(&$wp_query) {
    global $wp_the_query;
    if ( $wp_query === $wp_the_query ) {
        echo '<p style="color:red">TEST</p>';
    }
}

I've a few plugins that look for the main loop only, and it's working great on my end.

comment:8 sirzooro5 years ago

  • Milestone 2.8.1 deleted
  • Resolution set to invalid
  • Status changed from reopened to closed

It works now, thanks! :)

Note: See TracTickets for help on using tickets.