PluginProbe
wpDataTables – WordPress Data Table, Dynamic Tables & Table Charts Plugin / trunk
wpDataTables – WordPress Data Table, Dynamic Tables & Table Charts Plugin vtrunk
6.5.1.7 6.5.1.6 6.5.1.5 6.5.1.4 6.5.1.3 6.5.1.2 6.5.1.1 6.5.0.9 6.5.0.8 6.5.0.7 6.5.0.6 trunk 3.4.2.40 3.4.2.41 3.4.2.42 3.4.2.43 3.4.2.44 3.4.2.45 3.4.2.46 3.4.2.47 3.4.2.48 3.4.2.49 3.4.2.50 6.3.2 6.3.3.1 All 47 releases
wpdatatables / Infrastructure / WP / MCP / Abilities / list-tables.php

list-tables.php in wpDataTables – WordPress Data Table, Dynamic Tables & Table Charts Plugin trunk, at Infrastructure/WP/MCP/Abilities/list-tables.php

116 lines 5.5 KB
No matching file
Up and down to move Enter to open Esc to close
Raw Download Zip
1 <?php
2 /**
3 * Ability: wpdatatables/list-tables
4 *
5 * Lists all wpDataTables tables with summary metadata.
6 * Uses wpDataTable::getAllTables() to stay in sync with the parent plugin.
7 *
8 * @package wpDataTables_MCP_Server
9 */
10
11 defined( 'ABSPATH' ) or die('Access denied.');
12
13 add_action( 'wp_abilities_api_init', 'wdtmcp_register_list_tables_ability' );
14
15 function wdtmcp_register_list_tables_ability() {
16 wp_register_ability(
17 'wpdatatables/list-tables',
18 array(
19 'label' => __( 'List wpDataTables', 'wpdatatables' ),
20 'description' => __( 'Returns a list of all tables created in wpDataTables, including each table\'s ID, title, source type (SQL, CSV, Excel, Google Sheets, JSON, XML, serialized PHP array, simple, manual), database connection identifier, and whether server-side processing is enabled. Use this to discover available tables before inspecting or querying their data. WHEN TO CALL: start here whenever you need to find tables on this WordPress site, look up a table ID by title, or decide which table to inspect next. No parameters are required — pass an empty object {}. RETURNS: { tables: [{ id, title, table_type, connection, server_side }], count }. TYPICAL NEXT STEPS: call get-table-info with the chosen table_id to see columns and settings, then get-table-data to read rows. If you already know the table_id, you may skip straight to get-table-info or get-table-data.', 'wpdatatables' ),
21 'category' => 'wpdatatables-data',
22
23 'input_schema' => array(
24 'type' => 'object',
25 'properties' => array(),
26 'required' => array(),
27 ),
28
29 'output_schema' => array(
30 'type' => 'object',
31 'properties' => array(
32 'tables' => array(
33 'type' => 'array',
34 'description' => 'Array of table summaries.',
35 'items' => array(
36 'type' => 'object',
37 'properties' => array(
38 'id' => array(
39 'type' => 'integer',
40 'description' => 'The unique table ID.',
41 ),
42 'title' => array(
43 'type' => 'string',
44 'description' => 'The table title.',
45 ),
46 'table_type' => array(
47 'type' => 'string',
48 'description' => 'The table source type (SQL, csv, xls, google_spreadsheet, json, xml, serialized, simple, manual).',
49 ),
50 'connection' => array(
51 'type' => 'string',
52 'description' => 'The database connection identifier used by this table (empty string for the default WordPress connection).',
53 ),
54 'server_side' => array(
55 'type' => 'boolean',
56 'description' => 'Whether server-side processing is enabled.',
57 ),
58 ),
59 ),
60 ),
61 'count' => array(
62 'type' => 'integer',
63 'description' => 'Total number of tables.',
64 ),
65 ),
66 ),
67
68 'execute_callback' => function () {
69 if ( ! class_exists( 'WPDataTable' ) ) {
70 return new \WP_Error(
71 'wdtmcp_missing_class',
72 __( 'wpDataTables core class WPDataTable is not available.', 'wpdatatables' )
73 );
74 }
75
76 $rows = \WPDataTable::getAllTables();
77
78 if ( ! is_array( $rows ) ) {
79 return new \WP_Error(
80 'wdtmcp_query_failed',
81 __( 'Failed to retrieve tables from wpDataTables.', 'wpdatatables' )
82 );
83 }
84
85 $tables = array_map( static function ( $row ) {
86 return array(
87 'id' => (int) $row['id'],
88 'title' => (string) $row['title'],
89 'table_type' => (string) $row['table_type'],
90 'connection' => isset( $row['connection'] ) ? (string) $row['connection'] : '',
91 'server_side' => ! empty( $row['server_side'] ),
92 );
93 }, $rows );
94
95 return array(
96 'tables' => $tables,
97 'count' => count( $tables ),
98 );
99 },
100
101 'permission_callback' => function () {
102 return current_user_can( 'manage_options' );
103 },
104
105 'meta' => array(
106 'annotations' => array(
107 'instructions' => __( 'Call with an empty object {}. Use the returned table id with get-table-info or get-table-data. Start here when you do not yet know which tables exist.', 'wpdatatables' ),
108 'readonly' => true,
109 'destructive' => false,
110 'idempotent' => true,
111 ),
112 ),
113 )
114 );
115 }
116