• Resolved Mathieu Sldts

    (@mathieu-slaedts-generis)


    Hi,

    How could I add a “Unsubscribe” button on the Participant Record Page that removes the participant from the database?

    Thank you in advance,
    Mathieu

    • This topic was modified 5 years, 4 months ago by Mathieu Sldts.
Viewing 8 replies - 1 through 8 (of 8 total)
  • Plugin Author xnau webdesign

    (@xnau)

    The easiest way to do this is to set up a checkbox field that flags the record for deletion and removes it from frontend displays. I’ve published an article that explains how to set this up.

    Giving the User a Way to Delete Their Own Record

    Thread Starter Mathieu Sldts

    (@mathieu-slaedts-generis)

    Hi,
    Thank you very much for this nice solution.

    I created the delete switch and installed the plugin.

    As I understand, when the participant delete his record, he should get a message ‘The record has been deleted’. Am I right? When I do it, the page is reloaded, I get the normal message “Your information has been updated” and all the field are filled with the participant’s datas. On the backside, the participant is well removed from the database.

    have I missed something?

    Thank you very much,
    Mathieu

    Plugin Author xnau webdesign

    (@xnau)

    I’m sorry if this is not explained fully in the tutorial….the code does not delete the record. All it does is flag it for deletion. When you follow all the instructions in the tutorial, what that does is remove the record from frontend displays so it’s no longer visible.

    What you’re meant to do is as an administrator, periodically delete the records that have been flagged.

    The main reason for doing it this way is to prevent accidental data loss and to keep control over the process in the admin’s hands.

    It is possible to do as you suggest, but that would be a very different tutorial.

    Thread Starter Mathieu Sldts

    (@mathieu-slaedts-generis)

    Hi,
    I come back to you concerning this issue.

    Actually, using the plugin “PDB Record Delete Switch” from the second part of the tutorial and the delete_record checkbox, the record is correctly removed from the db. But on the frontend, the participant only get the message “Your information has been updated”.

    Is it possible to redirect the participant that as deleted his own record to another page with a specific message, for ex. “You have unsubscribed. Your informations have been deleted”.

    Thank you in advance,
    Mathieu

    Plugin Author xnau webdesign

    (@xnau)

    You can change the “thanks_page” value of the data array, which will direct the user to that page after the form is submitted. You need to do this using the pdb-after_submit_update filter, which you can add to the plugin in the tutorial.

    Thread Starter Mathieu Sldts

    (@mathieu-slaedts-generis)

    Thank you for your reply,

    I have added “thanks_page” to the data array, with the after_submit_update filter, but I should do it wrong because it does not redirect as expected.

    I tried this:

    add_action( 'pdb-after_submit_update', array($this, 'custom_change_thanks_page') );
    
    function custom_change_thanks_page($record)
    {
    	
    	if ( ! is_admin() ) {
    		
    		if ( isset( $record[$this->delete_switch_field_name] ) && $record[$this->delete_switch_field_name] === 'yes' ) {
    			
    			Participants_Db::write_participant( array( 'thanks_page' => 3871 ), $record['id'] );
    		}
    	}
    }

    and I tried this way as well

    add_action( 'pdb-after_submit_update', array($this, 'custom_change_thanks_page') );
    
    function custom_change_thanks_page($record)
    {
    	
    	if ( ! is_admin() ) {
    		
    		if ( isset( $record[$this->delete_switch_field_name] ) && $record[$this->delete_switch_field_name] === 'yes' ) {
    			
    			$record['thanks_page'] = 3871;
    		}
    	}
    }

    and I was wondering if it is a bad idea to do this:

    
    
    add_action( 'pdb-after_submit_update', array($this, 'custom_change_thanks_page') );
    
    function custom_change_thanks_page($record)
    {
    	
    	if ( ! is_admin() ) {
    		
    		if ( isset( $record[$this->delete_switch_field_name] ) && $record[$this->delete_switch_field_name] === 'yes' ) {
    			
    			wp_redirect( get_permalink( 3871 ) );
    		}
    	}
    }

    Thank you in advance,
    Mathieu

    Plugin Author xnau webdesign

    (@xnau)

    OK, the “thanks_page” value needs to be changed in the posted data, not the record. Also, it has to be done before the data is posted, so you need to use a different filter for that. For example…modifying your code:

    add_filter( 'pdb-before_submit_update', array($this, 'custom_change_thanks_page') );
    
    function custom_change_thanks_page($record)
    {
    	
    	if ( ! is_admin() ) {
    		
    		if ( isset( $record[$this->delete_switch_field_name] ) && $record[$this->delete_switch_field_name] === 'yes' ) {
    			// this should be the slug of the thanks page you want them to go to
    			$record['thanks_page'] = 'delete-thanks';
    		}
    	}
    
            return $record;
    }
    Thread Starter Mathieu Sldts

    (@mathieu-slaedts-generis)

    Ok, geot it. It is working fine!
    Thank you for the nice support.

    Mathieu

Viewing 8 replies - 1 through 8 (of 8 total)
  • The topic ‘Unsubscribe button on the Participant Record’ is closed to new replies.