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.
UPDATE
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() {
ob_start();
?>
// a form here
<?php
return ob_get_clean();
}
}
new Post_From_Front;
The full code can be seen here: https://gist.github.com/iuriemalai/5bad5e05c92b1cec10db
handleForm()
function, but I suspect it's because thetemplate_redirect
action hook doesn't pass any variables. – Pat J Dec 18 '15 at 22:02handleForm()
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:09if
condition on the requests wherehandleForm
is called? what happens if you also add the action inside thatif
condition? does it get successfully added and called? – Milo Dec 18 '15 at 22:18template_redirect
action hook inside theif
condition but it doesn't get called. – Iurie Malai Dec 18 '15 at 22:26if
condition doesn't get called, then the postID will be empty – czerspalace Dec 18 '15 at 22:35