|
This is installed the same way all wordpress plugins:
Adding an interface
DB-Table Editor Interfaces are added by calling the
add_db_table_editor function in your theme’s
functions.php
file.
This supports
wp_parse_args
style arguments.
-
title
: what shows up in the H1 on the screen and in menues
-
ex:
title=>
"My Product Reports Page"
-
table
: the table we wish to display / edit
-
ex:
table=>
"wp_my_custom_table"
-
id
: the admin interface id (defaults to table)
-
ex:
id=>
"custom_table_interface_1"
-
id_column
: the column in each row that names the id for the row
-
dataFn
: a function that returns the data to be displayed /
edited, defaults to
select * from {table}
. This should return ARRAY_N
through wpdb->
get_results. Alternatively it may return a DBTE_DataTable.
dataFn is called with the arguemnts array to add_db_table_editor;
-
ex:
dataFn=>
"myCustomInterfaceFunction"
-
jsFile
: the name of a registered script that will be enqueued for
this interface
-
ex:
jsFile=>
"my-custom-interface-js"
-
cap
: the capability a user needs to view/edit this interface,
defaults to edit_others_posts
-
ex:
cap=>
"edit_others_posts"
-
editcap
: the capability required to edit the grid, if not set
all viewers are assumed to be editors
-
ex:
editcap=>
"edit_others_posts"
-
noedit
: turns off the editing abilities (same as editcap=nosuchcapability)
-
columnFilters
: Default column filters, this is an array of column->
val
to be applied as default column fitlers when the page is loaded
-
ex:
columnFilters=>
Array("Year"=>
"2017")
-
columnNameMap
: A map of actual column names to displayed label
-
Ex:
columnNameMap=>
Array('column_name'=>
'Column Alias')
-
noedit_columns
,
hide_columns
: You may wish to hide some columns
or prevent edit. You may do so by setting these fields to the name
of columns you wish hidden or uneditable (eg: the id)
-
Ex:
noedit_columns=>
"data,id"
or
noedit_columns=>
Array('data', 'id')
-
save_cb
,
delete_cb
: function names to be called with an array of data:
the dbte, update array, column array and modified indexes array
call_user_func($cur->
save_cb,Array(‘table’=>
$cur, ‘update’=>
$up,
‘columns’=>
$cols, ‘indexes’=>
$idxs, ‘id’=>
$id));
call_user_func($cur->
delete_cb,$cur,$id);
If your call back inserts data it should fill in $data[‘id’] and accept data
by reference
-
auto_date
: should columns that appear to be datetimes, be treated as such
This is based on the columns data type
-
Sort of buggy but allows some different date formats than iso8601
-
Ex:
auto_date=>
true
-
autoHeight
: passes the autoHeight option to slickgrid (makes
there not be a vertical scrollbar on the grid and instead in the
window)
-
async_data
: request data asyncronously instead of inlining
it. Makes slow queries “seem” faster.
-
default_values
: an a_array of default values that new rows should have
-
Ex:
default_values=>
Array("name"=>
"First M Last")
-
export_id_field
: the field to use when limiting the export results
-
some sql needs a specific field – defaults to
table
.
id_col
-
Ex:
"export_id_field"=>
"mytbl.fooid"
Example:
`
if(function_exists(‘add_db_table_editor’)){
add_db_table_editor(‘title=Employees&table=employees’);
add_db_table_editor(array(
‘title’=>
’Event Registrations’,
‘table’=>
’event_registrations’,
‘sql’=>
’SELECT * FROM event_registrations ORDER BY date_entered DESC’
));
}
`
Reasons and Expectations
Previously my company had been using DB-toolkit to provide minimal
database interfaces for custom tables through the WordPress admin.
While the configuration was cumbersome for what we were doing, it did
work and was easier than writing anything. However, when DB-Toolkit
stopped being maintained and I couldn’t find a simple, but suitable
replacement, I decided to tackle my goals more head on
Use of this plugin requires a basic knowledge of PHP, and SQL. It was
written by a programmer to help accomplish his work and does not
currently provide admin configuration screens (instead simple function
calls in your theme’s functions file are used to configure the
screens). This was preferable to me, because my configuration is
safely in source control (a problem I had when DB-toolkit would
upgrade and lose all configuration).
|