WP Data Access classes in your own PHP code
As a PHP programmer you can use the WP Data Access classes to add full CRUD table pages to your own dashboard menus. Read the example code below to learn how.
<?php
/*
Plugin Name: wpda test
*/
/*
* This is a mini plugin showing how to use Wp Data Access directly from your php code.
*
* Following these steps:
* (1) Copy this example file to your plugin folder and remove the .txt file extention.
* (2) Make sure WP Data Access plugin is installed and activated.
* (3) Grant access to a table you like to use for this test: Wp Data Access > Manage Plugin > Back-end Settings.
* (4) Change 'your-table-name' (table_name) to the name of the table you selected in the previous step.
* (5) Activate wpda test plugin.
* (6) Check your WP Data Access menu (or other menu if you changed the code below).
* (7) Sub menu "Added by code" should be available with list table and simple form (if activated).
*/
function add_wpda_menu() {
// (2) Add your menu
add_action('admin_menu', 'add_app_menu');
}
function add_app_menu(){
if (!class_exists('WPDataAccess\List_Table\WPDA_List_View')) {
// Is WP Data Access deactivated or uninstalled?
return;
}
// (3) Create a (sub) menu handle
$wpda_table_list_menu = add_submenu_page(
'wpda', // Set to your own menu slug
'WPDA menu added by code', // Your page title
'Added by code', // Your menu title
'manage_options', // Set your authorization here
'wpda_test', // Menu slug of your page
'show_page' // Calls function below
);
global $wpda_table_list_view;
// (4) Add Instantiate class WPDA_List_View
// This allows you to set screen options
// If screen options are not available, something went wrong here...
$wpda_table_list_view = new WPDataAccess\List_Table\WPDA_List_View(
[
'page_hook_suffix' => $wpda_table_list_menu, // Handle to (sub)
'table_name' => 'your-table-name' // Database table in your wordpress schema (CHECK!!!)
]
);
}
function show_page(){
global $wpda_table_list_view;
// (5) Show menu page
$wpda_table_list_view->show();
}
// (1) Wait untill all plugins are loaded
// You need to do this to get access to WP Data Access classes
add_action('plugins_loaded', 'add_wpda_menu');
Peter
I am struggling to publish any part of the WP DATA ACCESS derived tables or projects etc. to the front end website.
I recognize the importance of security and have been working with data for 25+ years. I am completely stuck.
Hi Simon,
WP Data Access projects and publications can be added to web pages with shortcodes:
wpdadiehard (for projects)
wpdataaccess (for publications)
More information about these shortcodes can be found here:
https://wpdataaccess.com/docs/documentation/shortcodes/
Hope this helps!
Best regards,
Peter
I want to display the data only when it is searched and I want to blank it when the document loaded.
Please have a look at this page Nishant:
https://wpdataaccess.com/2020/03/25/action-hooks-to-add-search-actions-and-filters/
You can use this filter to influence the search strategy. When no filter is added you can return a where clause like:
where 1=2
You might also want to have a look at the search extention written by Charles Godwin:
https://github.com/CharlesGodwin/wpda-cwg-extensions
Finally you could promote me and buy the premium version! 🙂 The premium version contains a number of search features including your requirement. See:
https://wpdataaccess.com/pricing/
Hope this helps,
Peter