This is my first attempt at WP programming, so there's no telling what I'm doing wrong. :-)
First, I added
include_once (TEMPLATEPATH . '/user-functions.php');
into functions.php.
I wasn't seeing anything from my user-functions.php code, so switched from include_once to a simple include
include (TEMPLATEPATH . '/user-functions.php');
thinking that this was an issue of not reloading my code changes, but it made no difference.
I have all kinds of debugging echos in user-functions.php, but I'm not seeing anything. So, my first question is how do you do debugging on functions that happen before a page is rendered? I get the feeling my echos are being emitted too early in the request cycle, so they're being lost. What else can I do to see my debugging output?
But I wouldn't be asking questions about debugging if my hooks were working as I expect. Here's my ugly code (originally based on some code I found in this forum):
add_action("gform_post_submission", "post_submission_handler");
function post_submission_handler($entry){
global $wpdb;
$results = $wpdb->get_results($wpdb->prepare(" SELECT l.*, field_number, value
FROM wp_rg_lead l
INNER JOIN wp_rg_lead_detail ld ON l.id = ld.lead_id
WHERE l.id=%d
ORDER BY l.id, field_number", $entry["id"]));
echo "<h6>Form id: " . $form["id"] . "</h6>";
echo "<h6>Post type: " . $post_data["post_type"] . "</h6>";
echo "<h6>Form id: " . $form->id . "</h6>";
echo "<h6>Post type: " . $post_data->post_type . "</h6>";
echo "<h6>Entry: " . $entry . "</h6>";
echo var_dump($entry);
echo print_r($entry);
foreach($results as $result){
echo "<hr/>Entry Id: " . $result->id . "<br/>";
echo "Field Number: " . $result->field_number . "<br/>";
echo "Field Value: " . $result->value . "<br/>";
}
}
function insert_my_post($note) {
global $user_ID;
$new_post = array(
'post_title' => 'My New Post ' . $note,
'post_content' => 'Lorem ipsum dolor sit amet...',
'post_status' => 'publish',
'post_date' => date('Y-m-d H:i:s'),
'post_author' => $user_ID,
'post_type' => 'post',
'post_category' => array(0) );
$post_id = wp_insert_post($new_post);
}
add_filter("gform_post_data", "set_the_post_type");
function set_the_post_type($post_data, $form){
//-----------------------------------------
//Replace "post_tag" with your taxonomy name
$custom_taxonomy = "post_tag";
//----------------------------------------
$tags = implode(",", $post_data["tags_input"]);
$post_data["tax_input"] = array($custom_taxonomy => $tags);
$post_data["tags_input"] = null;
echo "<h6>Form id: " . $form["id"] . "</h6>";
if($form["id"] == '2'){
echo "<h6>Setting post_type to CPTTest</h6>";
$post_data["post_type"] = "CPTTest";
insert_my_post('2');
}
if($form["id"] == '3'){
echo "<h6>Setting post_type to Review</h6>";
$post_data["post_type"] = "Review";
insert_my_post('3');
}
insert_my_post('ALL');
return $post_data;
}
I can't tell if my hooks are running or not. Is there something obviously wrong in my code? I'm not seeing new posts created. It's like the form submission falls into a black hole. Thanks in advance for any help getting this working.