Okay
  Public Ticket #1036710
including update datetime and username
Closed

Comments

  •  2
    BryGuy91 started the conversation

    In regards to creating a manual table through wpdatatables. How can I include the update datetime and userid.

    I know I can add a datetime and userid column, but I want it to update this field automatically when the a new record is added, or when a user updates a record. Just adding the column requires the user to enter the  information manually.  Is there a native field that can be included with a condition or shortcode? Is there a way to do this programmatically through wpdatatables?

    I understand it may not be possible with the userid, but I would think you could grab the update date time from mysql when the record is updated?

  • [deleted] replied

    Hi BryGuy91,

    We do not have that option built in but you can add it with our built in hooks. One simplify solution could be function that will set user_id and current time upon saving table from frontend:

    function update_time( $formdata, $table_id ) {
       if ($table_id == 121 ) {
          $time                = time();
          $get_current_user_id = get_current_user_id();
          $formdata['userid']  = "$get_current_user_id";
          $formdata['time']    = "$time";
       }
       return $formdata;
    }
    add_filter('wpdatatables_filter_formdata_before_save', 'update_time', 10, 2);

    In this example we have table with id 121 and in it columns named userid and time. These columns could be hidden but they need to have editor input type set to be able to write into database. If you do not want users to see inputs for those columns just remove it with CSS or disable it with JS.

  •  2
    BryGuy91 replied

    Excellent thanks for the info Miljko. This is very helpful.

  •  11
    Issac replied

    Hi Miljko,

    I came across this post and I find it very useful with the help of hooks. I really love you guys for being so helpful in so many ways. 

    By the way, how do I hide this row in the edit popup dialog? I couldn't find a css class name or id to hide about. Can you enlighten me? Thanks!

  • [deleted] replied

    Hi Issacchua,

    Thank you for your kind words. 

    You can use CSS code like this:

    div#table_1_edit_dialog tr:nth-child(1) {
        display: none;
    }
    

    and instead of 1 use number of input that you want to hide (zero-based numbering) and instead of

    #table_1_edit_dialog

    appropriate id of edit dialog if you have more than one table on that page.