1

I have following piece of code which I can't modify.

if ( empty($post->comment_status) ) {
            do_action('comment_id_not_found', $comment_post_ID);
            exit;
    }

I can create function called during do_action processing (hooks in wordpress).

function my_function () {
   //do something
}
add_action('comment_id_not_found', 'my_function');

Is it possible to skip the exit; command in the condition?

Thanks

10
  • No, it's obviously going to run as soon as do_action is executed - Why can't you change the code? Commented Jul 18, 2013 at 16:11
  • you can't override exit(), so why not force the comment_status to be non-empty? Commented Jul 18, 2013 at 16:12
  • Or you could throw some exception while having this code run in catch block... Commented Jul 18, 2013 at 16:15
  • @cthulhu that is an ugly solution... but I think it's probably the only one that would work. Commented Jul 18, 2013 at 16:20
  • @cthulhu you should post that as the answer Commented Jul 18, 2013 at 16:20

2 Answers 2

2

One possible solution said to be ugly would be to throw exception in you function while having all code you can't modify run in try block. That is, if you can put it in try-catch.

Sign up to request clarification or add additional context in comments.

Comments

0

exit is a statement, there is no way to get around it and no way to modify it. The only way to avoid it is to make sure that your code doesn't pass by it. (eg. if(FALSE) exit; won't exit but in this: do_something(); exit; do_something_else(); the function do_something_else() will not be called.)

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.