Getting Started
Getting started with the DataKit WordPress plugin
Installing from source
To install the WordPress plugin, follow these instructions:
-
Clone the repository. You can do this directly into your WordPress's
wp-content/pluginsfolder, or somewhere else and symlink the folder.git clone git@github.com:UseDataKit/DataKit.git DataKit -
Symlink your repository to your WordPress'
wp-content/pluginsfolder (Not required if you cloned it there directly)cd </Your/WP-site/>wp-contents/plugins
ln -s <Location-Of-DataKit> DataKit -
Go into the folder and perform a Composer install
composer install --no-dev -
Go to your WordPress installation, and activate the DataKit plugin.
Creating a DataView
In order to register the DataView, you need to wait until the datakit/loaded action hook was dispatched. After this,
you can be certain DataKit was loaded and the default data sources and fields are available to use.
add_action( 'datakit/loaded', function () {
// Create your DataView here.
} );
DataKit provides a fluent PHP API for creating DataView objects. A DataView consists of a DataSource and a set of
Fields. To learn more about the different field types, please see our Documentation.
- First create a
DataSourceof your preferred type, for example aGravityFormsDataSource.use DataKit\Plugin\Data\GravityFormsDataSource;
$datasource = new GravityFormsDataSource( 10 ); // A Gravity Forms data source for form ID 10. - Next you create a
DataViewinstance. Currently, we only support the table view.use DataKit\DataViews\DataView\DataView;
use DataKit\DataViews\Field\ImageField;
use DataKit\DataViews\Field\HtmlField;
use DataKit\DataViews\Field\TextField;
$dataview = DataView::table(
'my-dataview', // This is a unique ID we need to reference and differentiate the DataView.
$datasource, // The data source we just created.
[ // Add an array of fields to show on the DataView.
TextField::create( '1', 'Name' )->sortable()->always_visible(),
ImageField::create( '2', 'Profile Image' )->not_sortable()->alt( 'Profile picture' ),
HtmlField::create( '3', 'About' )->not_sortable(),
]
); - Register your
DataViewwith the repository.do_action( 'datakit/dataview/register', $dataview ); - Show off your
DataView! You can use the[dataview id="my-dataview"]shortcode to display yourDataViewanywhere.