PluginProbe
Depicter — Popup & Slider Builder / 1.3.8
Depicter — Popup & Slider Builder v1.3.8
4.8.1 trunk 1.0.0 1.1.0 1.1.2 1.1.4 1.1.6 1.1.7 1.1.8 1.1.9 1.2.0 1.3.0 1.3.1 1.3.2 1.3.3 1.3.5 1.3.8 1.5.0 1.5.1 1.5.2 1.5.5 1.6.0 1.6.1 1.6.2 1.7.0 All 76 releases
depicter / app / src / Dashboard / DashboardPage.php

DashboardPage.php in Depicter — Popup & Slider Builder 1.3.8, at app/src/Dashboard/DashboardPage.php

201 lines 5.3 KB
No matching file
Up and down to move Enter to open Esc to close
Raw Download Zip
1 <?php
2 namespace Depicter\Dashboard;
3
4 use Averta\Core\Utility\Arr;
5 use Averta\WordPress\Utility\Escape;
6 use Averta\WordPress\Utility\JSON;
7 use Averta\WordPress\Utility\Plugin;
8 use Depicter\Security\CSRF;
9 use Depicter\WordPress\Settings\Settings;
10
11 class DashboardPage
12 {
13
14 const HOOK_SUFFIX = 'toplevel_page_depicter-dashboard';
15 const PAGE_ID = 'depicter-dashboard';
16
17 /**
18 * @var string
19 */
20 var $hook_suffix = '';
21
22 public function bootstrap(){
23 add_action( 'admin_menu', [ $this, 'registerPage' ] );
24 add_action( 'admin_enqueue_scripts', [ $this, 'enqueueScripts' ] );
25 add_action( 'admin_head', array( $this, 'disable_admin_notices' ) );
26 add_action( 'admin_init', [ $this, 'externalPageRedirect' ] );
27
28 $this->settingsPage();
29 }
30
31 /**
32 * Register admin pages.
33 *
34 * @return void
35 */
36 public function registerPage() {
37 $this->hook_suffix = add_menu_page(
38 __('Depicter', 'depicter'),
39 __('Depicter', 'depicter'),
40 'manage_options',
41 self::PAGE_ID,
42 [ $this, 'render' ], // called to output the content for this page
43 \Depicter::core()->assets()->getUrl() . '/resources/images/svg/wp-logo.svg'
44 );
45
46 add_submenu_page(
47 self::PAGE_ID,
48 __( 'Dashboard', 'depicter' ),
49 __( 'Dashboard', 'depicter' ),
50 'manage_options',
51 self::PAGE_ID
52 );
53
54 add_submenu_page(
55 self::PAGE_ID,
56 __( 'Add New', 'depicter' ),
57 __( 'Add New', 'depicter' ),
58 'manage_options',
59 self::PAGE_ID . '-create-slider',
60 [ $this, 'externalPageRedirect' ]
61 );
62
63 add_submenu_page(
64 self::PAGE_ID,
65 __( 'Support', 'depicter' ),
66 __( 'Support', 'depicter' ),
67 'manage_options',
68 self::PAGE_ID . '-goto-support',
69 [ $this, 'externalPageRedirect' ]
70 );
71
72 add_action( 'admin_print_scripts-' . $this->hook_suffix, [ $this, 'printScripts' ] );
73 }
74
75 /**
76 * Process redirect after clicking on Depicter admin menu
77 *
78 * @return void
79 */
80 public function externalPageRedirect(){
81 if ( empty( $_GET['page'] ) ) {
82 return;
83 }
84
85 if ( self::PAGE_ID . '-create-slider' === $_GET['page'] ) {
86 wp_redirect( menu_page_url( self::PAGE_ID, false ) . '#/templates/custom' );
87 die;
88 }
89
90 if ( self::PAGE_ID . '-goto-support' === $_GET['page'] ) {
91 wp_redirect( 'https://depicter.com/?utm_source=wp-submenu#support' );
92 die;
93 }
94 }
95
96 /**
97 * Settings page markup
98 *
99 * @return void
100 */
101 public function settingsPage() {
102
103 $settings = new Settings(__('Settings', 'depicter'), 'depicter-settings');
104 $settings->set_option_name('depicter_options');
105 $settings->set_menu_parent_slug( self::PAGE_ID );
106
107 $settings->add_tab(__( 'General', 'depicter' ));
108 $settings->add_section( __( 'General Settings', 'depicter' ) );
109 $settings->add_option('checkbox', [
110 'name' => 'always_load_assets',
111 'label' => __( 'Load assets on all pages?', 'depicter' ),
112 'description' => __( 'By default, Depicter will load corresponding JavaScript and CSS files on demand. but if you need to load assets on all pages, check this option. <br>( For example, if you plan to load Depicter via Ajax, you need to enable this option )', 'depicter' ),
113 ]);
114
115 $settings->make();
116
117 }
118
119 /**
120 * Disable all admin notices in dashboard page
121 *
122 * @return void
123 */
124 public function disable_admin_notices() {
125 $screen = get_current_screen();
126 if ( $screen->id == $this->hook_suffix ) {
127 remove_all_actions( 'admin_notices' );
128 }
129 }
130
131 public function render(){
132 echo Escape::content( \Depicter::view( 'admin/dashboard/index.php' )->toString() );
133 }
134
135 /**
136 * Load dashboard scripts
137 *
138 * @param string $hook_suffix
139 */
140 public function enqueueScripts( $hook_suffix = '' ){
141
142 if( $hook_suffix !== $this->hook_suffix ){
143 return;
144 }
145
146 // Enqueue scripts.
147 \Depicter::core()->assets()->enqueueScript(
148 'depicter--dashboard',
149 \Depicter::core()->assets()->getUrl() . '/resources/scripts/dashboard/depicter-dashboard.js',
150 [],
151 true
152 );
153
154 // Enqueue styles.
155 \Depicter::core()->assets()->enqueueStyle(
156 'depicter-dashboard',
157 \Depicter::core()->assets()->getUrl() . '/resources/styles/dashboard/index.css'
158 );
159 }
160
161 /**
162 * Print required scripts in Dashboard page
163 *
164 * @return void
165 */
166 public function printScripts()
167 {
168 global $wp_version;
169 $currentUser = wp_get_current_user();
170
171 wp_add_inline_script('depicter--dashboard', 'window.depicterEnv = '. JSON::encode(
172 [
173 'wpVersion' => $wp_version,
174 "scriptsPath" => \Depicter::core()->assets()->getUrl(). '/resources/scripts/dashboard/',
175 'clientKey' => \Depicter::options()->get( 'client_key', 'anon' ),
176 'csrfToken' => \Depicter::csrf()->getToken( CSRF::DASHBOARD_ACTION ),
177 'updateInfo' => [
178 'from' => \Depicter::options()->get('version_previous') ?: null,
179 'to' => \Depicter::options()->get('version')
180 ],
181 "assetsAPI" => Escape::url('https://wp-api.depicter.com/' ),
182 "wpRestApi" => Escape::url( get_rest_url() ),
183 "pluginAPI" => admin_url( 'admin-ajax.php' ),
184 "editorPath" => \Depicter::editor()->getEditUrl( '__id__' ),
185 "documentPreviewPath" => \Depicter::editor()->getEditUrl( '__id__' ),
186 'user' => [
187 'tier' => \Depicter::options()->get('user_plan', 'free-user'),
188 'name' => Escape::html( $currentUser->display_name ),
189 'email' => Escape::html( $currentUser->user_email ),
190 'joinedNewsletter' => !! \Depicter::options()->get('has_subscribed')
191 ],
192 'integrations' => [
193 'woocommerce' => Plugin::isActive( 'woocommerce/woocommerce.php' )
194 ]
195 ]
196 ), 'before' );
197
198 }
199
200 }
201