Revive deleted string


Home Forums Front End PM PRO Revive deleted string

This topic is: Resolved
Viewing 8 posts - 1 through 8 (of 8 total)
  • Author
    Posts
  • #6438
    Craig Tucker
    Participant

    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?

    #6441
    Craig Tucker
    Participant

    I said string when I should have said thread but I think you can get the idea.

    #6452
    Craig Tucker
    Participant

    A 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);	
    				}	
    			}
    
    #6454
    Craig Tucker
    Participant

    This 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 );    
                }
            }
        } 
    
    
    #6459
    shamim
    Keymaster

    You can change if ($post->post_type = 'fep_message'){ with if ($post->post_type == 'fep_message' && $post->post_parent){
    This way it will not run unnecessarily for parent message

    #6461
    Craig Tucker
    Participant

    I suppose you mean:

    if ($post->post_type = ‘fep_message’ && $post->post_parent != 0){

    That will be better. Thanks.

    #6463
    shamim
    Keymaster

    Please 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 );    
                }
            }
        } 
    
    #6506
    Craig Tucker
    Participant

    That does it thanks.

Viewing 8 posts - 1 through 8 (of 8 total)

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.