curiouswebster
asked on
WordPress/PHP has me stuck with no logging...
When I check the debug.log, I see:
Step 1
Step 2
Here is the code:
1) error_log() does not work in an action
2) The code does not enter the function, ajax_test()
Is there a plug-in needed for logging inside of an action? Will this one help?
https://wordpress.org/plugins/aryo-activity-log/
Is there another way to log data, besides error_log()? Please let me know...
Thanks.
Step 1
Step 2
Here is the code:
error_log("Step 1", 0);
add_action( 'save_post', 'ajax_test' );
function ajax_test() {
error_log( "ajax_test entered", 0);
}
error_log("Step 2", 0);
So, this means EITHER:1) error_log() does not work in an action
2) The code does not enter the function, ajax_test()
Is there a plug-in needed for logging inside of an action? Will this one help?
https://wordpress.org/plugins/aryo-activity-log/
Is there another way to log data, besides error_log()? Please let me know...
Thanks.
ASKER CERTIFIED SOLUTION
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
SOLUTION
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
1) How do I know if the logging is Failing or the function is Not getting entered?
Based on your debug.log file contents, logging appears to be working.
2) What is required to have an action?
save_post only files when you save or update a post, not on page visits.
3) Is there something key missing aside from just calling add_action()?
Your code looks correct.
4) Is the Action WordPress?
Unsure exactly what this might mean.
Yes... you're running inside WordPress, so the "Action" is "WordPress".
5) Does it have requirements for a function declared as 'save_post'?
No.
Your code above looks correct, just make sure you're actually creating a new post or saving to an existing post after an edit.
Based on your debug.log file contents, logging appears to be working.
2) What is required to have an action?
save_post only files when you save or update a post, not on page visits.
3) Is there something key missing aside from just calling add_action()?
Your code looks correct.
4) Is the Action WordPress?
Unsure exactly what this might mean.
Yes... you're running inside WordPress, so the "Action" is "WordPress".
5) Does it have requirements for a function declared as 'save_post'?
No.
Your code above looks correct, just make sure you're actually creating a new post or saving to an existing post after an edit.
ASKER
The following is the insert statement. Is this a post?
add_action( 'save_post', 'ajax_signup_insert_contact' );
function ajax_signup_insert_contact() {
die('INSIDE THE FUNCTION');
write_log('Entered ajax_signup_insert_contact()');
global $wp_query;
$page_id = $wp_query->post->ID;
$page_name = $wp_query->post->post_title;
/*if(isset($page_title) === false || $page_title === '') {
// The title is empty, so Throw a Fatal Error()
}*/
error_log( "Step 20", 0);
if(is_page()){ //Check if we are viewing sign up page
write_log( "Step 30");
if($page_id === 37){
write_log("Step 40");
global $wpdb;
$fname = 'C';
$lname = 'D';
$table_name = "ps_contacts";
if ( $wpdb->insert(
$table_name,
array(
'fname' => $fname,
'lname' => $lname,
)
) == false)
{
write_log( "FAILED");
}
}
}
}
ASKER
Open in new window
The output from the debug.log looks thusly, and shows the function was not entered...
Open in new window
The die() function, I assume, would have meant the final "Exit PHP script" message not to show. I will close this question and open another one on the add_action() problem. Thanks.