To provide the best experiences, we use technologies like cookies to store and/or access device information. Consenting to these technologies will allow us to process data such as browsing behavior or unique IDs on this site. Not consenting or withdrawing consent, may adversely affect certain features and functions.
The technical storage or access is strictly necessary for the legitimate purpose of enabling the use of a specific service explicitly requested by the subscriber or user, or for the sole purpose of carrying out the transmission of a communication over an electronic communications network.
The technical storage or access is necessary for the legitimate purpose of storing preferences that are not requested by the subscriber or user.
The technical storage or access that is used exclusively for statistical purposes.
The technical storage or access that is used exclusively for anonymous statistical purposes. Without a subpoena, voluntary compliance on the part of your Internet Service Provider, or additional records from a third party, information stored or retrieved for this purpose alone cannot usually be used to identify you.
The technical storage or access is required to create user profiles to send advertising, or to track the user on a website or across several websites for similar marketing purposes.
Hello,
I want to keep records of the files downloaded from my site. For this, I want to create a new table with wp data access. There will be (user_id, media_id, datetime, user ip) fields in this table.
When the user wants to download a file, I will first check this table and if user has downloaded it, I will not allow again. Otherwise I want to add a row to this table after the download.
function isdownloaded (user_id, media_id)
function addnew (user_id, media_id, user_id)
How can I write these functions in wp code manager?
Hi Ali,
Good question! 🙂
You can write a PHP shortcode and access your table from your shortcode. If your table is stored in your WordPress database, you can use $wpdp to access the database. If your table is stored in another (remote) database, you can use WP Data Access class WPDADB like this:
$wpdadb = \WPDataAccess\Connection\WPDADB::get_db_connection( $database);
Where $database is the database where your table is stored. You can use $wpdadb just like you would use $wpdb. Class WPDADB is a sub class of WordPress class wpdb.
Hope this helps,
Peter