Skip to content

Instantly share code, notes, and snippets.

@Stiofan
Last active April 15, 2021 16:31
Show Gist options
  • Save Stiofan/4e584d43f3980f052c5b65ae4f932625 to your computer and use it in GitHub Desktop.
Save Stiofan/4e584d43f3980f052c5b65ae4f932625 to your computer and use it in GitHub Desktop.
Custom field to enable or disable comments
<?php // <-- you probably dont need this line
add_action('geodir_after_save_listing','_my_update_comment_settings_on_save',10,2);
function _my_update_comment_settings_on_save($last_post_id, $request_info){
global $wpdb;
if(isset($request_info['geodir_allow_comments']) && $request_info['geodir_allow_comments']=='1'){
$wpdb->query($wpdb->prepare("UPDATE $wpdb->posts SET comment_status = 'open' WHERE ID = %d", $last_post_id));
}elseif(isset($request_info['geodir_allow_comments']) && $request_info['geodir_allow_comments']=='0'){
$wpdb->query($wpdb->prepare("UPDATE $wpdb->posts SET comment_status = 'closed' WHERE ID = %d", $last_post_id));
}
}
@leem2209
Copy link

leem2209 commented Apr 8, 2021

does geodir_after_save_listing still work?

@Stiofan
Copy link
Author

Stiofan commented Apr 15, 2021

@leem2209 no, that was for GDv1, in GDv2 it is "geodir_post_saved" and a little different. I don't think we send that godire_allow_comments now so you would need a different trigger https://github.com/AyeCode/geodirectory/blob/master/includes/class-geodir-post-data.php#L702

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment