Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • SEARCH
  • Home
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 8938983
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 15, 20262026-06-15T10:44:37+00:00 2026-06-15T10:44:37+00:00

I need a table to log certain actions users make in WordPress. As of

  • 0

I need a table to log certain actions users make in WordPress.

As of now, this is the database schema I have camp up with:

id bigint(20) NOT NULL AUTO_INCREMENT,
uid bigint(20) NOT NULL,
type VARCHAR(256) NOT NULL,
data1 TEXT NOT NULL,
data2 TEXT NOT NULL,
data3 TEXT NOT NULL,
timestamp bigint(20) NOT NULL,
UNIQUE KEY id (id)

Let me clarify:

uid: User ID of the wordpress user
type: Type of action the user made (can be 'comment', 'new_post', 'login', etc)
data1/2/3: additional data (for example, ID of comment or post made)

To display the logs, I would query the database and run through a certain filter to get the text to display for that particular log. So it works something like this:

if( $type == 'comment') {
    $comment = get_comment( $data1 );
    $user = get_user($uid);
    echo "User {$user->name} has made a <a href='{$comment->permalink}'>comment</a>";
}

Is this the most efficient way of doing things? It seems quite fine to me as I do not want to just store HTML in the logs table to be outputted.

However, the problem comes where I want to hide a particular log entry when certain conditions are met. Like, for example, if a comment no longer exists, I want to hide that entry. This would pose some problems with pagination. Any suggestions on how I can overcome this?

Thanks!

EDIT:

myplugin_transactions
id bigint(20) NOT NULL AUTO_INCREMENT,
user_id bigint(20) NOT NULL,
type VARCHAR(256) NOT NULL,
timestamp bigint(20) NOT NULL,
UNIQUE KEY id (id)

myplugin_meta
id bigint(20) NOT NULL AUTO_INCREMENT,
txn_id bigint(20) NOT NULL,
key VARCHAR(256) NOT NULL,
data TEXT NOT NULL,
UNIQUE KEY id (id)

Lets say I want to select * from myplugin_transactions where data1 would usually have had been ‘x’ and data2 been ‘y’. How should I do it in this case?

SELECT * FROM myplugin_transactions LEFT JOIN myplugin_meta ON myplugin_transactions.id = myplugin_meta.txn_id WHERE ( ... ? )
  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-06-15T10:44:38+00:00Added an answer on June 15, 2026 at 10:44 am

    This answer is going to be very generic as it doesn’t provide any code, but it’s also too long for a comment.

    Firstly, you shouldn’t be storing additional data in those data1, data2, data3 fields. You’re using MySQL, so you’ve got the power of relational databases. Use them.

    You should simply have another table, which has an ID field (the ID of the action), and a data field. That way you can store 0 to as-many-items-as-you-want pieces of metadata. I mean, wordpress already does this with metadata right?

    Secondly, if a comment is deleted, do you simply want to delete the action related to it? If so, simply hook into the API. I believe there is a hook for delete_comment: http://codex.wordpress.org/Plugin_API/Action_Reference#Comment.2C_Ping.2C_and_Trackback_Actions

    Otherwise if you want to keep the action, you can either add an extra field or piece of metadata called, say, deleted. When a comment is deleted, as above: hook into the delete_comment call and update the action to deleted = true. Then when you run your query on all the actions, exclude the deleted statements, eg ... WHERE deleted = NULL ... etc.

    EDIT2:

    To answer your select statement, something like this could work:

    SELECT * FROM myplugin_transactions 
    LEFT JOIN myplugin_meta AS data1 
    ON ( myplugin_transactions.id = data1.txn_id AND data1.key = 'data1' )
    LEFT JOIN myplugin_meta AS data2 
    ON ( myplugin_transactions.id = data2.txn_id AND data2.key = 'data2' )
    WHERE data1.data = 'x'
    AND data2.data = 'y'
    

    Obviously replacing the data1 and data2 keywords with meaningful descriptions.

    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I need some advice... I have an application where users can do certain actions.
I have a log table with following schema: OperatorId - JobId - Status (
I have an sqlite table log that looks like this: ID p_id viewer ----------------------
I have a log table with a date field called logTime. I need to
I have a table I need to copy my data from (Log), into another
I have a table with log data, of this form: Date Time Device Configuration
I have a log table in SQL Server. Table is structured this way: Unique
I need to change table name from lowercase to uppercase but using this statement
I need a comparison table of some sort for database varieties (MySQL, SQLite etc.).
I have a really huge log file from which i need to search stuff.

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.