0

I have a wordpress filter defined in my theme's single.php:

  header( 'X-Filter-1: here' );
  add_filter( 'the_content', function( $content ) use ( $details ) {
    header( 'X-Filter-2: here' );
    /* lots of details removed so I can focus on this problem */
  });

My X-Filter-1 debugging header shows up. My X-Filter-2 debugging header does not show up.

If I add an all action:

  if (array_key_exists('dbg', $_REQUEST) and preg_match('/trace.actions/', $_REQUEST['dbg'])) {
    $staging_trace_debug_tags = array();
    add_action('all', function ($tag) {
          global $staging_trace_debug_tags;
          if (in_array($tag, $staging_trace_debug_tags)) {
              return;
          }
          echo "<pre class=\"dbg-trace\">$tag</pre>";
          $staging_trace_debug_tags[] = $tag;
    });
  }

I can use that to see that the the_content filter is being run. So that much is good.

Has anyone seen this before, where a filter callback instance does not get run?

Are there any stupid things I might be overlooking that could cause this behavior?

How does one isolate a problem of this nature?

  • 2
    By the time the the_content filter runs the headers have already been sent. – Nathan Johnson Jun 1 '18 at 23:30
  • 1
    You should check your PHP error logs for warnings, you should be seeing warnings along the lines of "headers already sent" – Tom J Nowell Jun 2 '18 at 0:33
0

That turned out to be the issue:

My callback was running, it just was not able to insert headers.

(thanks, both of you)

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.