I have a class with a private property/variable named $postID that I can pass successfully (this was tested) to every function within this class except one named handleForm(). When it is passed to this function it becomes empty. Why this happens? I suspect that this is because of the template_redirect action hook, but I am not sure. The class schematically looks as below. To understand this class better you can look at the original code: https://wordpress.stackexchange.com/a/210662/25187.


For more understanding: I added to a front end posting form the editing functionality, but I want to solve some issues, although this form already works.

class Post_From_Front {
    private $postID;

    function __construct() {
        if( 'POST' == $_SERVER['REQUEST_METHOD'] && isset( $_POST['postid'] ) ) {
            $this->postID = $_POST['postid'];
        // Listen for the form submit & process before headers output
        add_action( 'template_redirect',  array( $this, 'handleForm' ) );

    function post_shortcode() {

    function handleForm() {

    function getForm() {

           // a form here
        return ob_get_clean();


new Post_From_Front;

The full code can be seen here: https://gist.github.com/iuriemalai/5bad5e05c92b1cec10db

  • 1
    It might help to see the code in your handleForm() function, but I suspect it's because the template_redirect action hook doesn't pass any variables. – Pat J Dec 18 '15 at 22:02
  • @pat-j The handleForm() function is a bigger one, but you can look at the original code to understand this class better: wordpress.stackexchange.com/a/210662/25187 – Iurie Malai Dec 18 '15 at 22:09
  • have you verified that it enters the if condition on the requests where handleForm is called? what happens if you also add the action inside that if condition? does it get successfully added and called? – Milo Dec 18 '15 at 22:18
  • @milo I am not sure if I understood you correctly. I moved the template_redirect action hook inside the if condition but it doesn't get called. – Iurie Malai Dec 18 '15 at 22:26
  • What does your form look like? If the if condition doesn't get called, then the postID will be empty – czerspalace Dec 18 '15 at 22:35

Your Answer

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

Browse other questions tagged or ask your own question.