• Hello,

    thanks for the fantastic plugin and amazing support.

    I use the plugin for membership database for a non profit organization. I set up 2 separate sets of fields, one which is “main” and the other which is “admin”.

    I also set up a frontend page to edit the records by the admins which contains both sets of fields, however now it seems that there is a request that on renewal the members should have the possibility of updating their records individually.

    I would like to send them a private link which allows editing only the “main” group of fields do not show the “admin” sets of fields. So far the private link brings up the page which is recorded under setting -> Record Form Settings -> Participant record page – which we use on the frontend side.

    Is there any way to use 2 different edit record pages? one for the front end with

    [pdb_record groups=”main,admin”] shortcode and the second for the private link with [pdb_record groups=”main”] shortcode?

Viewing 11 replies - 1 through 11 (of 11 total)
  • Plugin Author xnau webdesign

    (@xnau)

    Generally, this would be done by the admins going to the backend and editing records there.

    It’s easy to set up two different edit pages, you got that part, but the trick is providing different links, and how you do that depends on how you’re providing the link to an editable record to your admins.

    There is a filter you can use to change the link to the “Participant Record Page” and you can use that filter to change it based on whether the user is logged in as an admin or not.

    The filter is pdb-record_edit_page and it passes in the link to the globally-defined edit page, you can change it with a bit of custom code.

    Thread Starter oxxyfx

    (@oxxyfx)

    Thank you for that. I have searched your site back and forth trying to find some information on how can I use the pdb-record_edit_page filter, but I cannot find the right source. Would you be kind enough to point me to the correct direction.

    Plugin Author xnau webdesign

    (@xnau)

    Really very little to it…the filter passes in the URL for the “Participant Record Page” you can create a function to alter that, for example by checking whether the user is logged in. Are you familiar with using WordPress filters?

    Thread Starter oxxyfx

    (@oxxyfx)

    Not really, this is the first time I heard about them. I guess this requires quite a bit more research from my end.

    Would I add this piece of code to the functions.php?

    Plugin Author xnau webdesign

    (@xnau)

    You will certainly need some php skills and familiarity with WordPress functions to get this done, but it’s not master-level stuff. There’s tons of info out there to help.

    What is a Filter?

    WordPress Actions, Filters, and Hooks : A guide for non-developers

    Thread Starter oxxyfx

    (@oxxyfx)

    Thanks for those links. I do not want to overcomplicate this and I sort of came up with the following code snippet. I have to mention that this is my first attempt to write any PHP code, so thank you for being a patient tutor ??

    add_filter( ‘pdb-record_edit_page ‘, ‘change_edit_page_link’ );
    function change_edit_page_link() {

    if ( current_user_can( ‘edit_pages’ ) ) {
    return ‘https://someurl.com/edit_page_for_admin’;
    } else {
    return ‘https://someurl.com/edit_page_for_members’;
    }

    }

    Please don’t laugh….

    Plugin Author xnau webdesign

    (@xnau)

    Well, it will need to be more complicated than than because you need to get the PID code for the actual record. You can’t just hard-code the URL, you need to take the incoming URL al alter it to point to the correct page.

    So, for starters, your function needs to use the $url argument so you know what the requested URL was. So, somthing like

    function change_edit_page_link( $url ) {

    Then you would alter the $url variable to get your final link. Take a look at the structure of a working URL so you know what you’re aiming for.

    Thread Starter oxxyfx

    (@oxxyfx)

    Ok, thank you for that, of course you are right, my lack of experience in programming php and web solutions really shows ?? So after all that, scratching my head around how to do this, I came up with the following code:

    
    add_filter( ‘pdb-record_edit_page ‘, ‘change_edit_page_link’ );
    function change_edit_page_link($url) {
    
    	$urlnew = "https://somewebsite.com/wp/updaterecord/?";
    	$url_array = explode("?", $url);
    	$privateid = $url_array[1];
    
    	if ( current_user_can( ‘edit_pages’ ) ) {
    		return $url;
    	} else {
    		$urlnew .= $privateid;			
    		return $urlnew;
    	}
    
    }
    

    We must be getting closer ??

    Thread Starter oxxyfx

    (@oxxyfx)

    Well, I tried all the variations from above and it did not give me results. So I guess the problem is that I am not reading the incoming url correctly?

    Thread Starter oxxyfx

    (@oxxyfx)

    I got this working, but I do not think it solves my problem. The filter is like this:

    
    add_filter('pdb-record_edit_page', 'change_edit_page_link');
    function change_edit_page_link( $url ) {
    
    	$urlnew = "https://somewebsite.com/wp/update-member/?";
    	$url_array = explode("?", $url);
    	$privateid = $url_array[1];
    
    	if ( current_user_can('administrator')){
    		$record_edit_page = $url;
    	} else {
    		$record_edit_page = $urlnew . $privateid;			
    	}	
    	return $record_edit_page;
    }
    

    I can rewrite the edit_record_page now, and it works great, when the user is logged in and updates the record through the website. However the problem is that if the user requests a private link to edit his own record, he gets an

    https://somewebsite.com/wp/edit-member/?pid=TV8BA

    link. The user is not logged in and the above link does not get overwritten by the filter, because I guess it is a direct typed in – or pasted in link

    Now the question is how do I overwrite that link into:

    https://somewebsite.com/wp/update-member/?pid=TV8BA

    • This reply was modified 4 years, 5 months ago by oxxyfx.
    Plugin Author xnau webdesign

    (@xnau)

    Easiest way to fix that is to set your “Participant Record Page” setting (plugin settings under the Record Form tab) to point to the default page: https://somewebsite.com/wp/update-member

Viewing 11 replies - 1 through 11 (of 11 total)
  • The topic ‘Separate edit record for admins and for members’ is closed to new replies.