PHP code example of matterwp / admin-ui
1. Go to this page and download the library: Download matterwp/admin-ui library . Choose the download type require .
2. Extract the ZIP file and open the index.php.
3. Add this code to the index.php.
<?php
require_once('vendor/autoload.php');
/* Start to develop here. Best regards https://php-download.com/ */
matterwp / admin-ui example snippets
use MTWP\ADMIN\V130\Assets;
use MTWP\ADMIN\V130\UI;
add_action(
'admin_enqueue_scripts',
static function (): void {
Assets::enqueueBuiltStyle( 'my-plugin-admin-ui' );
Assets::enqueueBuiltScript( 'my-plugin-admin-ui' );
}
);
echo UI::attrs(
array(
'class' => 'plugin-custom-control',
'data-plugin-control' => 'logo',
'aria-live' => 'polite',
)
);
UI::section(
array(
'title' => __( 'Stats', 'plugin' ),
'section_variant' => 'minimal',
),
static function (): void {
UI::grid(
array(
'columns' => 4,
'min_width' => '160px',
'density' => 'comfortable',
),
static function (): void {
// Render stat cards or other direct content.
}
);
}
);
UI::option(
array(
'title' => __( 'Status', 'plugin' ),
'description' => __( 'Full-width label with a divided control area.', 'plugin' ),
'layout' => 'divided',
'label_width' => 'full',
'input_label' => true,
'input_id' => 'plugin-status',
),
static function (): void {
UI::select(
array(
'id' => 'plugin-status',
'value' => 'queued',
'options' => array(
'queued' => __( 'Queued', 'plugin' ),
'done' => __( 'Done', 'plugin' ),
),
)
);
}
);
UI::section(
array(
'title' => __( 'Entries', 'plugin' ),
'section_variant' => 'minimal',
),
static function (): void {
UI::paginatedTable(
array(
'columns' => array( 'name' => __( 'Name', 'plugin' ) ),
'rows' => $rows,
'per_page' => 10,
)
);
}
);
UI::schemaOption(
array(
'name' => 'plugin_limit',
'label' => __( 'Limit', 'plugin' ),
'description' => __( 'Maximum items to process.', 'plugin' ),
'type' => 'number',
'min' => 1,
'max' => 100,
'step' => 1,
),
10,
array(
'option' => array( 'control_width' => 'narrow' ),
)
);
UI::option(
array(
'title' => __( 'Activation Schedule', 'plugin' ),
'description' => __( 'Schedule when maintenance should begin and end.', 'plugin' ),
'layout' => 'column',
'control_width' => 'full',
),
static function () use ( $values ): void {
UI::fieldGrid(
array(
'columns' => 3,
'density' => 'compact',
),
static function () use ( $values ): void {
UI::input(
array(
'name' => 'schedule_start',
'type' => 'datetime-local',
'value' => $values['schedule_start'] ?? '',
)
);
UI::input(
array(
'name' => 'schedule_end',
'type' => 'datetime-local',
'value' => $values['schedule_end'] ?? '',
)
);
UI::select(
array(
'name' => 'schedule_timezone',
'value' => $values['schedule_timezone'] ?? wp_timezone_string(),
'options' => array_combine( timezone_identifiers_list(), timezone_identifiers_list() ),
)
);
}
);
}
);
UI::app(
array(
'brand' => __( 'Plugin Name', 'plugin' ),
'version' => '1.3.0',
'changelog_url' => 'https://example.com/changelog',
'navigation' => array(
'groups' => array(
array(
'label' => __( 'Main', 'plugin' ),
'alignment' => 'top',
'items' => array(
'general' => __( 'General', 'plugin' ),
),
),
array(
'label' => __( 'Support', 'plugin' ),
'alignment' => 'bottom',
'items' => array(
'logs' => __( 'Logs', 'plugin' ),
),
),
),
),
'form' => true,
),
static function (): void {
UI::panel( 'general', static function (): void {} );
UI::panel( 'logs', static function (): void {} );
}
);
UI::dataTable(
array(
'pagination_mode' => 'server',
'filter_mode' => 'server',
'endpoint' => admin_url( 'admin-ajax.php' ),
'action' => 'plugin_load_rows',
'nonce' => wp_create_nonce( 'plugin_admin' ),
'columns' => array(
'title' => array(
'label' => __( 'Title', 'plugin' ),
'type' => 'title',
'sortable' => true,
),
),
'filters' => array(
'type' => array(
'label' => __( 'Filter by type', 'plugin' ),
'row_key' => 'type_key',
'options' => array(
'all' => __( 'All', 'plugin' ),
'post' => __( 'Posts', 'plugin' ),
'page' => __( 'Pages', 'plugin' ),
),
),
),
'search' => array(
'label' => __( 'Search entries', 'plugin' ),
'placeholder' => __( 'Search...', 'plugin' ),
),
'rows' => $rows,
)
);
wp_send_json_success(
UI::dataTableResponse(
array(
'columns' => $columns,
'rows' => $page_rows,
'page' => $page,
'per_page' => $per_page,
'total' => $total,
'total_pages' => $total_pages,
'empty_state' => array( 'title' => __( 'No entries found', 'plugin' ) ),
)
)
);
UI::actionGroup(
array(
'actions' => array(
array(
'label' => __( 'Edit', 'plugin' ),
'icon' => 'edit',
'url' => $edit_url,
),
array(
'label' => __( 'Delete', 'plugin' ),
'icon' => 'delete',
'variant' => 'danger',
'confirm' => __( 'Delete this row?', 'plugin' ),
),
),
)
);
UI::modal(
array(
'id' => 'plugin-edit-modal',
'title' => __( 'Edit item', 'plugin' ),
'fields' => array(
array(
'name' => 'item_name',
'label' => __( 'Name', 'plugin' ),
'type' => 'text',
),
),
'footer_actions' => array(
array( 'label' => __( 'Save', 'plugin' ), 'type' => 'submit', 'variant' => 'primary' ),
),
),
static function (): void {}
);
## Theming
The package ships a token system under `resources/scss/matterwp/_tokens.scss`. All public surfaces (backgrounds, borders, text, action colors, focus rings, badges, log viewer, toasts, etc.) read from CSS custom properties, so consumers can override individual tokens without forking the stylesheet.
### Per-theme primary color
The light and dark blocks both anchor on `--mwp-ui-primary` (and `--mwp-ui-primary-hover` for the hover variant). To give dark mode a distinct primary, override this single token under `html[data-mwp-theme="dark"]` in your SCSS, layered after the admin-ui bundle:
UI::mediaField(
array(
'name' => 'plugin_logo_id',
'value' => $logo_id,
'mode' => 'logo',
'preview_height' => '80px',
'preview_ratio' => '1 / 1',
'button_text' => __( 'Choose Logo', 'plugin' ),
'remove_text' => __( 'Remove Logo', 'plugin' ),
'data_attributes' => array(
'plugin-logo-picker' => 'true',
),
)
);
UI::mediaField(
array(
'name' => 'plugin_image_id',
'preview' => static function ( array $args, string $uid, string $image_url ): void {
// Render custom preview markup. Include data-media-preview when using package JS.
},
'actions' => static function ( array $args, string $uid ): void {
// Render custom action markup. Include data-media-input, data-media-target, and data-media-remove when using package JS.
},
)
);