' ); // phpcs:ignore WordPress.PHP.DiscouragedPHPFunctions.obfuscation_base64_encode
$dashboard = add_menu_page(
__( 'Texty', 'texty' ),
__( 'Texty', 'texty' ),
$capability,
$slug,
[ $this, 'render_page' ],
$menu_icon,
$menu_position
);
$submenus = apply_filters(
'texty_admin_menu',
[
[
'path' => 'dashboard',
'title' => __( 'Dashboard', 'texty' ),
],
[
'path' => 'gateway',
'title' => __( 'Gateway', 'texty' ),
],
[
'path' => 'notifications',
'title' => __( 'Notifications', 'texty' ),
],
[
'path' => 'logs',
'title' => __( 'Logs', 'texty' ),
],
],
$capability,
$slug
);
foreach ( $submenus as $item ) {
$path = 'admin.php?page=' . $slug . '#/' . $item['path'];
if ( filter_var( $item['path'], FILTER_VALIDATE_URL ) ) {
$path = $item['path'];
}
$submenu[ $slug ][] = [ // phpcs:ignore WordPress.WP.GlobalVariablesOverride.Prohibited
$item['title'],
$capability,
$path,
];
}
do_action( 'texty_admin_menu', $capability, $menu_position );
add_action( 'admin_print_scripts-' . $dashboard, [ $this, 'enqueue_scripts' ] );
}
/**
* Render the page
*
* @return void
*/
public function render_page() {
echo '';
}
/**
* Enqueue JS and CSS
*
* @return void
*/
public function enqueue_scripts() {
$asset_file = include TEXTY_DIR . '/dist/index.asset.php';
wp_register_script(
'texty-admin',
TEXTY_URL . '/dist/index.js',
$asset_file['dependencies'],
$asset_file['version'],
true
);
wp_localize_script( 'texty-admin', 'texty', $this->localize_script() );
wp_register_style(
'texty-vendor-css',
TEXTY_URL . '/dist/style-index.css',
[ 'wp-components' ],
$asset_file['version']
);
wp_register_style(
'texty-css',
TEXTY_URL . '/dist/index.css',
[ 'texty-vendor-css' ],
$asset_file['version']
);
wp_enqueue_script( 'texty-admin' );
wp_enqueue_style( 'texty-css' );
}
/**
* Get the localize script
*
* @return array
*/
public function localize_script() {
$i18n = [
'asset_url' => trailingslashit( TEXTY_URL ) . 'assets/',
'site_name' => get_bloginfo( 'name' ),
'rest_url' => esc_url_raw( rest_url() ),
'ajax_url' => esc_url_raw( admin_url( 'admin-ajax.php' ) ),
'nonce' => wp_create_nonce( 'wp_rest' ),
'version' => [
'lite' => TEXTY_VERSION,
],
];
return apply_filters( 'texty_localize_script', $i18n );
}
}