The Code Manager integrates very well with WP Data Access and lets WP Data Access users write their own code and use it in their own projects and publications.
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?
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.
IMPORTANT message for free users with version 5.3.9 installed
WP Data Access version 5.3.9 is not seeing new updates in the plugin page. The latest version is currently 5.3.15.
To download the latest update, please follow these steps:
Deactivate and delete version 5.3.9. This will NOT delete your data, but if you’re worried, you can also simply deactivate version 5.3.9, and then rename the plugin folder temporarily via FTP.
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