Okay
  Public Ticket #3203067
Placeholders, user ID
Closed

Comments

  • Peter started the conversation

    In the Mariadb table I have columns for timestamp in user_id. In wpDaTatables, there are in placeholder data for %CURRENT_USER_ID% and %CURRENT_DATETIME%.

    When editing the table, I would like at UPDATE or INSERT auto update that fields in edited row with current value from placeholder.

    Basicly we want to build some kind of trace which WP user upadated DB row via wptables on frontend.

    Please dont hesitete to ask for any details.
    Thanks for your help.

  •  1,708
    Miloš replied

    Hi, Peter 

    Thanks for reaching out to us

    I am not sure if i understood your use-case perfectly in all details, but we will try and let me know if it does the goal.


    1. For "catching" the ID of current user that edits rows - this depends on exactly what you need.


    For example, if you simply need to pre-populate new rows with the currently logged user ID,

    you can add a user ID column in a Manual or SQL table with our plugin, and if you activate "Users see and edit only own data" in the Editing tab,

    then each new row will populate with the current User's ID, but in this case each user will only see rows associated with their ID - they won't see other user's rows.

    -

    We can also set a predefined editor value as the "current user ID" placeholder, if you don't wish to Limit users rows,  or in other words if you wish to allow them to see other user's rows,

    but that works only for new rows - we don't have any built-in option to change the "user ID" automatically if another user edits an existing user which someone else already created.

    For example, if user 1  makes a new row ( and we don't limit "users see only their rows",)

    , if user 2 later comes to edit this row -  we can not automatically change the user ID of that row from 1 to 2;

    unless if user 2 manually changes the user ID value to 2 on that row.

    -

    If you need something like that,

    At this time, we don't have any built-in solution to achieve this, but you can suggest it to our developers - they will do their best to make a solution in the future.

    Please feel free to search on our suggestions page

     to see if someone may be already suggested this feature. If you can't see it, feel free to add your suggestion there,  and as more people vote, the feature will move higher on the priority list.

    You can certainly follow our changeLog page if you'd like ( it is also available in the plugin dashboard), where we state any changes/new features/bug fixes during updates;

    and our newsletter, so you're informed about new features, bug fixes, freebies, etc.

    -

    At the moment, here is a custom workaround that you can try, if you have coding skills,

    for example, this is a custom solution to send an Email after a user edits a row with the data of this row.

    -

    For sending emails, you can use this:

    https://www.a2hosting.com/kb/installable-applications/optimization-and-configuration/wordpress2/sending-e-mail-in-wordpress#:~:text=To%20send%20an%20e%2Dmail,authentication%20settings%20you%20defined%20above

    And to take values after Apply is hit, there's this hook:

    wpdatatables_after_frontent_edit_row( $formdata, $rowId, $tableId ) This action is executed after editing action is applied.

    $formdata is the array of keys and values for editing.

    $rowId is the ID field of the row in MySQL table that was edited.

    $tableId is the table identifier from the MySQL plugin table (wp_wpdatatables).

    For example:

    function sendEmailAfterEdit( $formdata, $rowId, $tableId ){ 
    // create logic for sending emails
    }
    add_action('wpdatatables_after_frontent_edit_row', 'sendEmailAfterEdit',10,3);

    will be triggered in both cases when you edit or adding a new row in the table from front-end. Please note that data is already saved in database.

    -

    Please note that for solutions like this, we can not provide troubleshooting, it is just limited to advice.


    2.  In regards to setting a "time stamp",

    For example, If you need a simple auto pre-populate for the column Date and Time, to be the current Date Time,

    we have this placeholder,

    that you can use as a predefined editor value.

    -

    Here is how you can do it :

    Set column type to DateTime;

    9626039055.png

    Then, in the Editor Type, set as "one line edit",  and set the predefined editor value as the placeholder %CURRENT_DATETIME% :

    1626344206.png

    And then, if someone tries to add a new row,   this column's value will automatically be default as the current date and time :

    7417353783.png

    -

    2.

    There is also a custom SQL workaround, for SQL tables, if you need a timestamp :

    1. Create a column (for example "Updated") in your table

    2. In column settings set the type to be "DateTime" (in the "Data" tab), and in the "Editing" tab set the "Editor Input Type" to "none".

    3. In the database, run this query:

    ALTER TABLE `table_name` CHANGE `updated` `updated` DATETIME NULL DEFAULT CURRENT_TIMESTAMP ON UPDATE CURRENT_TIMESTAMP;
    

    Please note that you need to replace 'table_name' with the actual database table name. You can find the database name of the table in the Editing tab above the table, in the "MySQL query name for editing" field.

    -

    Let us know if this was helpful,

    or if you need something else, please elaborate a bit more on your use-case scenario, and what is the exact goal - then we can advise?smile.png Thank you


    Kind Regards, 

    Miloš Jovanović
    [email protected]

    Rate my support

    wpDataTables: FAQ | Facebook | Twitter | InstagramFront-end and back-end demo | Docs

    Amelia: FAQ | Facebook | Twitter | InstagramAmelia demo sites | Docs | Discord Community

    You can try wpDataTables add-ons before purchasing on these sandbox sites:

    Powerful Filters | Gravity Forms Integration for wpDataTables | Formidable Forms Integration for wpDataTables | Master-Detail Tables