Home › Forums › Front End PM PRO › Revive deleted string
- This topic has 7 replies, 2 voices, and was last updated 8 years, 3 months ago by Craig Tucker.
- AuthorPosts
- September 13, 2017 at 9:43 pm #6438Craig TuckerParticipant
I have mentioned that I want the ability to revive a deleted string if one side has not deleted the string and has posted again on the string. What hook would I use to add an action before the message is posted to do something like this:
$query ="SELECT meta_id FROM wp_postmeta WHERE post_id = %s and <code>meta_key</code> = '_fep_delete_by_%s'"; $queryp1 = $wpdb->prepare($query, array($post->post_parent, $post->post_author)); if (!empty($queryp1)) { delete_post_meta($queryp1,'_fep_delete_by_' . $post->post_author); } $queryp2 = $wpdb->prepare($query, array($post->post_parent, $post->ID)); if (!empty($queryp2)) { delete_post_meta($queryp2,'_fep_delete_by_' . $post->ID); }I think that would do it. So is there a hook that I can use to facilitate this?
September 13, 2017 at 9:44 pm #6441Craig TuckerParticipantI said string when I should have said thread but I think you can get the idea.
September 13, 2017 at 10:46 pm #6452Craig TuckerParticipantA better method perhaps:
$participants = fep_get_participants( $post->post_parent ); foreach( $participants as $participant ) { $query ="SELECT meta_id FROM wp_postmeta WHERE post_id = %s and <code>meta_key</code> = '_fep_delete_by_%s'"; $queryp1 = $wpdb->prepare($query, array($post->post_parent, $participant)); if (!empty($queryp1)) { delete_post_meta($queryp1,'_fep_delete_by_' . $participant); } }September 14, 2017 at 12:13 pm #6454Craig TuckerParticipantThis works to refresh the thread and revive the deleted participants if placed in functions.php
add_action('save_post', 'undelete_thread'); function undelete_thread($post_id) { $post = get_post($post_id); if ($post->post_type = 'fep_message'){ $participants = fep_get_participants( $post->post_parent ); foreach( $participants as $participant ) { delete_post_meta($post->post_parent,'_fep_delete_by_'. $participant ); } } }September 14, 2017 at 1:06 pm #6459Shamim HasanKeymasterYou can change
if ($post->post_type = 'fep_message'){withif ($post->post_type == 'fep_message' && $post->post_parent){
This way it will not run unnecessarily for parent messageSeptember 14, 2017 at 1:30 pm #6461Craig TuckerParticipantI suppose you mean:
if ($post->post_type = ‘fep_message’ && $post->post_parent != 0){
That will be better. Thanks.
September 14, 2017 at 2:08 pm #6463Shamim HasanKeymasterPlease use following
add_action('save_post', 'undelete_thread'); function undelete_thread($post_id) { $post = get_post($post_id); if ($post->post_type == 'fep_message' && $post->post_parent){ $participants = fep_get_participants( $post->ID ); foreach( $participants as $participant ) { delete_post_meta($post->post_parent,'_fep_delete_by_'. $participant ); } } }September 16, 2017 at 4:15 pm #6506Craig TuckerParticipantThat does it thanks.
- AuthorPosts
You need to purchase ‘Front End PM PRO’ to create topic in this support forum.
If you already purchased ‘Front End PM PRO’ please LOGIN.