Dashboard.php
3.77 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
<?php if ( ! defined( 'ABSPATH' ) ) exit;
final class NF_Admin_Menus_Dashboard extends NF_Abstracts_Submenu
{
public $parent_slug = 'ninja-forms';
public $page_title = 'Dashboard';
public $menu_slug = 'ninja-forms';
public $position = 1;
public function __construct()
{
parent::__construct();
add_action( 'admin_enqueue_scripts', array( $this, 'enqueue_dashboard_script' ) );
}
public function get_page_title()
{
if( isset( $_GET[ 'form_id' ] ) ) {
return esc_html__( 'Form Builder', 'ninja-forms' );
}
return esc_html__( 'Dashboard', 'ninja-forms' );
}
public function get_capability()
{
return apply_filters( 'ninja_forms_admin_all_forms_capabilities', $this->capability );
}
public function display()
{
// This section intentionally left blank.
}
/**
* Enqueue dashboard page elements
*/
public function enqueue_dashboard_script($page) {
// let's check and make sure we're on the dashboard page.
if( isset( $page ) && $page === "toplevel_page_ninja-forms") {
global $wp_version;
//Enqueue Dashboard element for dashboard
if( $wp_version >= "5.4" ){
//Get Dependencies and Version from build asset.php generated by wp-scripts
$dashboard_asset_php = [
"dependencies" => ['jquery'],
"version" => false
];
if( file_exists( Ninja_Forms::$dir . "build/dashboard.asset.php" ) ){
$asset_php = include( Ninja_Forms::$dir . "build/dashboard.asset.php" );
$dashboard_asset_php["dependencies"] = array_merge( $dashboard_asset_php["dependencies"], $asset_php["dependencies"]);
$dashboard_asset_php["version"] = $asset_php["version"];
}
//Get JS dashboard assets details
if( file_exists( Ninja_Forms::$dir . "build/dashboard.scss.asset.php" ) ){
$asset_scss = include( Ninja_Forms::$dir . "build/dashboard.scss.asset.php" );
}
$dashboard_asset_scss_version = isset($asset_scss) ? $asset_scss["version"] : Ninja_Forms::VERSION;
//Register Dashboard script
wp_register_script( 'ninja_forms_admin_dashboard', Ninja_Forms::$url . 'build/dashboard.js', $dashboard_asset_php["dependencies"], $dashboard_asset_php["version"], false );
wp_enqueue_script( 'ninja_forms_admin_dashboard' );
wp_set_script_translations( "ninja_forms_admin_dashboard", "ninja-forms-user-management", Ninja_Forms::$dir . 'lang' );
//Enqueue dashboard style
wp_enqueue_style( 'ninja_forms_admin_dashboard_style', Ninja_Forms::$url . 'build/dashboard.scss.css', [], $dashboard_asset_scss_version );
wp_localize_script('ninja_forms_admin_dashboard', 'ninja_forms_admin_dashboard_data', [
'siteUrl' => esc_url_raw( site_url() ),
'adminUrl' => esc_url_raw( admin_url() ),
'restUrl' => esc_url_raw( get_rest_url() ),
'ajaxUrl' => esc_url_raw( admin_url( 'admin-ajax.php' ) ),
'pluginDir' => plugin_dir_url('ninja-forms.php'),
'token' => wp_create_nonce( 'wp_rest' ),
'load_user_management' => !in_array('ninja-forms-user-management/ninja-forms-user-management.php', get_option('active_plugins'))
]);
}
}
}
} // End Class NF_Admin_Dashboard