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.


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?

	// (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


// (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 Schulz is a lecturer in information technology at the HAN university of applied sciences. He is an experienced programmer with more than 25 years experience in Oracle databases and tools. Peter is the developer of WordPress plugin WP Data Access.

4 Replies to “WP Data Access classes in your own PHP code”

  1. 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.

  2. I want to display the data only when it is searched and I want to blank it when the document loaded.

    1. Please have a look at this page Nishant:
      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:

      Finally you could promote me and buy the premium version! 🙂 The premium version contains a number of search features including your requirement. See:

      Hope this helps,

Leave a Reply

Your email address will not be published.