PluginProbe
WP Data Access – App Builder for Tables, Forms, Charts, Maps & Dashboards / 2.0.13
WP Data Access – App Builder for Tables, Forms, Charts, Maps & Dashboards v2.0.13
5.5.83 5.5.82 5.5.81 5.5.80 5.5.79 5.5.77 5.5.76 5.5.75 5.5.73 5.5.72 5.5.22 5.5.23 5.5.29 5.5.3 5.5.31 5.5.32 5.5.34 5.5.35 5.5.36 5.5.37 5.5.4 5.5.40 5.5.41 5.5.42 5.5.43 All 159 releases
wp-data-access / tutorials / wpda-test.php.txt

wpda-test.php.txt in WP Data Access – App Builder for Tables, Forms, Charts, Maps & Dashboards 2.0.13, at tutorials/wpda-test.php.txt

69 lines 2.1 KB
No matching file
Up and down to move Enter to open Esc to close
Raw Download Zip
1 <?php
2
3 /*
4 Plugin Name: wpda test
5 */
6
7 /*
8 * This is a mini plugin showing how to use Wp Data Access directly from your php code.
9 *
10 * Following these steps:
11 * (1) Copy this example file to your plugin folder and remove the .txt file extention.
12 * (2) Make sure WP Data Access plugin is installed and activated.
13 * (3) Grant access to a table you like to use for this test: Wp Data Access > Manage Plugin > Back-end Settings.
14 * (4) Change 'wp_customers' (table_name) to the name of the table you selected in the previous step.
15 * (5) Activate wpda test plugin.
16 * (6) Check your WP Data Access menu (or other menu if you changed the code below).
17 * (7) Sub menu "Added by code" should be available with list table and simple form (if activated).
18 */
19
20 function add_wpda_menu() {
21
22 // (2) Add your menu
23 add_action('admin_menu', 'add_app_menu');
24
25 }
26
27 function add_app_menu(){
28
29 if (!class_exists('WPDataAccess\List_Table\WPDA_List_View')) {
30 // Is WP Data Access deactivated or uninstalled?
31 return;
32 }
33
34 // (3) Create a (sub) menu handle
35 // Works for add_menu_page and add_submenu_page equally
36 $wpda_table_list_menu = add_submenu_page(
37 'wpda', // Set to your own menu slug
38 'WPDA menu added by code', // Your page title
39 'Added by code', // Your menu title
40 'manage_options', // Set your authorization here
41 'wpda_test', // Menu slug of your page
42 'show_page' // Calls function below
43 );
44
45 global $wpda_table_list_view;
46 // (4) Add Instantiate class WPDA_List_View
47 // This allows you to set screen options
48 // If screen options are not available, something went wrong here...
49 $wpda_table_list_view = new WPDataAccess\List_Table\WPDA_List_View(
50 [
51 'page_hook_suffix' => $wpda_table_list_menu, // Handle to (sub)
52 'table_name' => 'wp_customers' // Database table in your wordpress schema (CHECK!!!)
53 ]
54 );
55
56 }
57
58 function show_page(){
59
60 global $wpda_table_list_view;
61 // (5) Show menu page
62 $wpda_table_list_view->show();
63
64 }
65
66 // (1) Wait untill all plugins are loaded
67 // You need to do this to get access to WP Data Access classes
68 add_action('plugins_loaded', 'add_wpda_menu');
69