Save current user ID or Name in a field
-
Hi,
how to save current user ID or Name in a field?
I tried to put $$USER$$ as a default value for a field, but it doesn’t work.
Is there another way to do it?Or is there a function to call where to insert it, before data are saved to database?
Thank you
-
Hi kentauron,
The plugin currently supports the $$USER$$ variable in the where clause only. This allows you to compare the value of a specific column (e.g. wp_username) with the username of the currently logged in user.
What exactly are you trying to achieve? Can you describe the desired functionality?
Best regards,
PeterI need to know which user added each record, so I’d like to store its name/ID in a field
- This reply was modified 5 years, 5 months ago by kentauron.
Oke, I get it! But I do have some more questions…
– Do you want that field to be visible?
– Or hidden?
– Is the user allowed to changes it?
– Do you want to save a history? A kind of journal table? Otherwise only the last username will be available to you and you might valuable information.Best regards,
PeterHidden, user not allowed to change it, no history needed. Each user edit only his records.
That’s why as a work around I wanted to add it via php, calling a function before data are saved to db.Hi Kentauron,
To store the WP username in a specific column you could edit class WPDA_Simple_Form_Data. Specifically you would need to add your logic in the add_row() and set_row() methods after the loop which sets the column values. Method add_row performs a SQL insert. Method set_row performs and SQL update.
So you CAN do this! BUT… Everytime the plugin is updated, you’ll need to edit class WPDA_Simple_Form_Data. I have planned to add this feature soon, probably this summer.
To disabled editing rows that “belong to other users” you would need to add some logic as well. Server side you’ll need to compare the old and new value of the column containing the WP username and take actions based on that comparison. Both values are already available. Browser side you could add some javascript code that compare the username of the logged in user with the value in the column and then disables or enables editing.
Did I understand your question correctly? This is very specific logic which I haven’t planned, but plans can be changed… ??
Best regards,
PeterPerfect!
About storing, now I can edit each time that file, but it could be useful to add some hook or call to generic dosomething function before and after data are stored.
About editing, common users will see and can edit only their own recs so I can use $$USER$$ where clause.
Thank you for your very fast and valid support
Smart idea to add pre and post save hooks! I have never used my own hooks. I’ll see if I can use this…
I’ll let you know when I added your feature request.
Thank you for your patience and contribution!
Hi Kentauron,
I just released a new version which supports the $$USER$$ environment variable as a default value. The third topic in the “what’s new?” section explains how to use it. Let me know if you need any help.
I have not yet started with your file upload request. Hope to pick that topic up after my holiday.
Best regards,
Peter- This reply was modified 5 years, 4 months ago by Passionate Programmer Peter.
Good news!
Thank you
Hi @peterschulznl,
Thank you for this plugin. I am really impressed by your dedication and support.
However, I think the hooks as suggested by many users will go a long way to improve our experience.
For instance, I would like to join many tables together and call some WordPress functions to generate a table.. How can I do that? without touching your codes!.
Kindly consider bringing in some hooks.
Thanks.
Gbade
Hi @gbade,
I’m not sure if I understand your request correctly. Do you want to join tables and handle them as a view? Or automatically create master detail forms from them? Or otherwise?
Also what functionality do you expect from hooks? Can you tell me more…? I’m interested!
Best regards,
PeterHi @peterschulznl,
Thanks for your prompt reply.
“Do you want to join tables and handle them as a view? ” YES
How can this be achieved currently?
On the Data Publisher module, I wanted to add a WHERE clause. I couldnt achieve it. If there are hooks to modify the original query, I will be loyal follower!!! ??
I think hooks should be able to handle Where, Order by, Group by, MAX, Count e.t.c and a view generated by advanced users or you can have an input box where we can freely write the SQL leveraging on the interface of the application.
Thanks
‘Gbade
I
Hi Gbade,
Interesting!!!
I will add a default where clause to the Data Publisher. The Data Projects tool already supports that feature. This functionality however is not achieved through a hook. A default where can be added in the data entry form for the project page. I like to follow a similar approach for the Data Publisher.
Question:
You want to influence the ordering as well. If you add a default order by however the user will still be able to changed it on the page. Would that be okay? Or do you need to be able to turn that off?I have plans to support the creation and modification of views as well. This will become part of the Data Designer. But development takes time… So please, be patient…
When it comes to hooks, I’m not convinced that hooks will really make a difference within this plugin. I understand that WordPress developers are familiar with hooks and we usually tend to use what we know. But I trully believe the plugin offers the flexibility developers need to build data driven WordPress apps without hooks. I love WordPress because it is for everyone. It doesn’t matter if you are an IT engineer, designer or writer. Hooks is not for everyone. I prefer to give users the possibility to configure their data apps through data entry forms instead of hooks as I believe this will allow all users to be able to build data apps.
One final note. You can use views in the Data Publisher. You’ll just have to write them yourself. You can create them in the Data Explorer and then use them like tables in the Data Publisher. This allows you to use group by, max, count etc. You might give it a try…
Thank you very much for input! ??
Best regards,
Peter
- The topic ‘Save current user ID or Name in a field’ is closed to new replies.