PluginProbe
BlockSpare – Gutenberg Blocks for News, Magazine, Blog & Business Websites / trunk
BlockSpare – Gutenberg Blocks for News, Magazine, Blog & Business Websites vtrunk
4.1.0 trunk 1.0.0 1.0.1 1.0.2 1.0.3 1.0.4 1.0.5 1.1.0 1.1.1 1.1.2 1.2.0 1.2.1 1.2.2 1.2.3 1.3.0 1.3.1 1.3.2 1.3.3 1.3.4 1.3.5 2.1.2 2.5.0 2.5.3 2.6.1 All 38 releases
blockspare / admin / index.php

index.php in BlockSpare – Gutenberg Blocks for News, Magazine, Blog & Business Websites trunk, at admin/index.php

307 lines 10.5 KB
No matching file
Up and down to move Enter to open Esc to close
Raw Download Zip
1 <?php
2
3 /**
4 * Welcome screen.
5 */
6
7 // Exit if accessed directly.
8 if (!defined('ABSPATH')) {
9 exit;
10 }
11
12 if (!class_exists('Blockspare_Admin_Dashboard')) {
13 class Blockspare_Admin_Dashboard
14 {
15 public function __construct()
16 {
17 add_action('admin_menu', array($this, 'add_dashboard_page'));
18
19 add_action('admin_enqueue_scripts', array($this, 'enqueue_dashboard_script'));
20
21 add_action('admin_init', array($this, 'redirect_to_blockspare_page'));
22
23 //add_action('init', array($this, 'blockspare_load_api_files'));
24
25 add_filter('plugin_row_meta', [$this, 'plugin_row_meta'], 10, 2);
26
27 add_filter('plugin_action_links_' . BLOCKSPARE_PLUGIN_BASE, [$this, 'plugin_action_links']);
28
29 // include_once(BLOCKSPARE_PLUGIN_DIR . 'admin/notice-setup.php');
30 // include_once(BLOCKSPARE_PLUGIN_DIR . 'admin/notice-theme.php');
31 // include_once(BLOCKSPARE_PLUGIN_DIR . 'admin/notice-review.php');
32 // include_once BLOCKSPARE_PLUGIN_DIR . 'admin/notice-upgrade.php';
33 include_once(BLOCKSPARE_PLUGIN_DIR . 'admin/class-enable-disable-blocks.php');
34 }
35
36 public function plugin_action_links($links)
37 {
38 $settings_link = sprintf('<a href="%1$s">%2$s</a>', admin_url('admin.php?page=blockspare'), esc_html__('Get Started', 'blockspare'));
39
40 array_unshift($links, $settings_link);
41
42 $links['bspro'] = sprintf('<a href="%1$s" target="_blank" class="blockspare-pro-link">%2$s</a>', 'https://www.blockspare.com/', esc_html__('Upgrade', 'blockspare'));
43
44 return $links;
45 }
46 public function plugin_row_meta($plugin_meta, $plugin_file)
47 {
48 if (BLOCKSPARE_PLUGIN_BASE === $plugin_file) {
49 $row_meta = [
50 'starter' => '<a href="https://www.blockspare.com/starter-templates/" aria-label="' . esc_attr(esc_html__('View Blockspare Starter Templates', 'blockspare')) . '" target="_blank">' . esc_html__('Demos', 'blockspare') . '</a>',
51 'docs' => '<a href="https://www.blockspare.com/docs/" aria-label="' . esc_attr(esc_html__('View Blockspare Documentation', 'blockspare')) . '" target="_blank">' . esc_html__('Docs', 'blockspare') . '</a>',
52 'video' => '<a href="https://www.youtube.com/@blockspare" aria-label="' . esc_attr(esc_html__('View Blockspare Video Tutorials', 'blockspare')) . '" target="_blank">' . esc_html__('Videos', 'blockspare') . '</a>',
53 'support' => '<a href="https://afthemes.com/supports/" aria-label="' . esc_attr(esc_html__('Need help for Blockspare?', 'blockspare')) . '" target="_blank">' . esc_html__('Need help?', 'blockspare') . '</a>',
54 ];
55
56 $plugin_meta = array_merge($plugin_meta, $row_meta);
57 }
58
59 return $plugin_meta;
60 }
61
62 public function add_dashboard_page()
63 {
64
65 // @see images/blockspare-icon.svg
66 $svg = <<< SVG
67 <svg version="1.1" id="Layer_1" xmlns="http://www.w3.org/2000/svg" xmlns:xlink="http://www.w3.org/1999/xlink" x="0px" y="0px"
68 viewBox="0 0 40 40" style="enable-background:new 0 0 40 40;" xml:space="preserve">
69 <g>
70 <g>
71 <path class="st0" d="M1.6,9.2v21.4l18.3-9.2L20.2,0L1.6,9.2z M16.9,19.8L4.9,26V10.9l12-6.1V19.8z"/>
72 <polygon id="XMLID_3_" class="st1" points="19.9,21.4 16.9,23 26,27.7 13.8,33.8 4.9,29 1.6,30.7 13.9,36.9 32.4,27.7 "/>
73 </g>
74 <g>
75 <polygon id="XMLID_2_" class="st0" points="23,1.5 23,19.8 32.4,24.6 32.4,9.4 35.3,10.9 35.3,29 38.4,30.7 38.4,9.2 29.4,4.8
76 29.2,19.7 26,18.4 26,3.1 "/>
77 <polygon id="XMLID_1_" class="st1" points="17,38.4 19.9,40 38.4,30.7 35.3,29 "/>
78 </g>
79 </g>
80 </svg>
81 SVG;
82
83 add_menu_page(
84 __('Blockspare', 'blockspare'), // Page Title.
85 __('Blockspare', 'blockspare'), // Menu Title.
86 'edit_posts', // Capability.
87 'blockspare', // Menu slug.
88 array($this, 'blockspare_admin_dashboard'), // Action.
89 'data:image/svg+xml;base64,' . base64_encode($svg), // Blockspare icon.
90 25
91 );
92
93 add_submenu_page(
94 'blockspare', // Parent slug.
95 __('Home Dashboard', 'blockspare'), // Page title.
96 __('Home Dashboard', 'blockspare'), // Menu title.
97 'manage_options', // Capability.
98 'blockspare', // Menu slug.
99 array($this, 'blockspare_admin_dashboard'), // Callback function.
100 1 // Position
101 );
102
103 // Our getting started page.
104 add_submenu_page(
105 'blockspare', // Parent slug.
106 __('Starter Templates', 'blockspare'), // Page title.
107 __('Starter Templates', 'blockspare'), // Menu title.
108 'manage_options', // Capability.
109 'bspare-starter-sites', // Menu slug.
110 array($this, 'blockspare_admin_blocks'), // Callback function.
111 1 // Position
112 );
113
114 add_submenu_page(
115 'blockspare', // Parent slug.
116 __('Gutenberg Blocks', 'blockspare'), // Page title.
117 __('Gutenberg Blocks', 'blockspare'), // Menu title.
118 'manage_options', // Capability.
119 'bs-blocks', // Menu slug.
120 array($this, 'blockspare_admin_explore_more_blocks'), // Callback function.
121 2 // Position
122 );
123
124 add_submenu_page(
125 'blockspare', // Parent slug.
126 __('Saved Templates', 'blockspare'), // Page title.
127 __('Saved Templates', 'blockspare'), // Menu title.
128 'manage_options', // Capability.
129 'edit.php?post_type=bs_templates', // Menu slug.
130
131 );
132 add_submenu_page(
133 'blockspare', // Parent slug.
134 __('Compare Free & Pro', 'blockspare'), // Page title.
135 __('Compare Free & Pro', 'blockspare'), // Menu title.
136 'manage_options', // Capability.
137 'bs-free-pro', // Capability.
138 array($this, 'blockspare_admin_free_vs_pro'),
139 );
140
141 add_submenu_page(
142 'blockspare',
143 esc_html__('Documentation', 'blockspare'),
144 esc_html__('Documentation', 'blockspare'),
145 'manage_options',
146 esc_url('https://blockspare.com/docs/')
147
148 );
149
150 add_submenu_page(
151 'blockspare', // Parent slug.
152 __('Change Log', 'blockspare'), // Page title.
153 __('Change Log', 'blockspare'), // Menu title.
154 'manage_options', // Capability.
155 'bs-change-log', // Menu slug.
156 array($this, 'blockspare_admin_change_log'), // Callback function.
157
158 );
159
160 add_submenu_page(
161 'blockspare',
162 esc_html__('Explore More', 'blockspare'),
163 esc_html__('Explore More', 'blockspare'),
164 'manage_options',
165 esc_url('https://blockspare.com/')
166
167 );
168 add_submenu_page(
169 'blockspare',
170 esc_html__('Need a Website?', 'blockspare'),
171 esc_html__('Need a Website?', 'blockspare'),
172 'manage_options',
173 esc_url('https://afthemes.com/make-a-website/')
174
175 );
176 add_submenu_page(
177 'blockspare',
178 esc_html__('Power Bundle', 'blockspare'),
179 esc_html__('Power Bundle', 'blockspare'),
180 'manage_options',
181 esc_url('https://afthemes.com/all-themes-plan/')
182
183 );
184
185
186 add_submenu_page(
187 'blockspare',
188 esc_html__('Support', 'blockspare'),
189 esc_html__('Support', 'blockspare'),
190 'manage_options',
191 esc_url('https://afthemes.com/supports/')
192
193 );
194 }
195
196
197 public function enqueue_dashboard_script($hook)
198 {
199 wp_enqueue_style('blockspare-admin', BLOCKSPARE_PLUGIN_URL . 'admin/assets/css/style.css', '', '');
200 wp_enqueue_script('blockspare_dashboard_js', BLOCKSPARE_PLUGIN_URL . 'dist/block_admin_dashboard.js', array('react', 'react-dom', 'wp-components', 'wp-element', 'wp-api-fetch', 'wp-polyfill'), '1.0');
201 wp_enqueue_style('blockspare-admin-css', BLOCKSPARE_PLUGIN_URL . 'dist/dashboard_css.css');
202 wp_enqueue_script('wp-api');
203 $blockspare_dashboard_logo = BLOCKSPARE_PLUGIN_URL . 'admin/assets/images/blockspare-logo.png';
204 global $blockspare_block_manager;
205
206 wp_localize_script(
207 'blockspare_dashboard_js',
208 'blockspare_dashboard',
209 array(
210
211 'logo' => $blockspare_dashboard_logo,
212 "imagePath" => "https://raw.githubusercontent.com/afthemes/blockspare-demo-data/master/blocks/new/",
213 "static_img" => BLOCKSPARE_PLUGIN_URL,
214 'newPageUrl' => admin_url('post-new.php?post_type=page&blockspare_create_block'),
215 'adminPath' => admin_url('post-new.php?post_type=page&blockspare_show_intro=true'),
216 'pluginVesion' => BLOCKSPARE_VERSION,
217 'exploreUrl' => admin_url('admin.php?page=bs-blocks'),
218 'adminUrl' => admin_url('admin.php?page=blockspare'),
219 'templateUrl' => admin_url('edit.php?post_type=bs_templates'),
220 'starterUrl' => admin_url('admin.php?page=bspare-starter-sites'),
221 'blockUrl' => admin_url('admin.php?page=bs-blocks'),
222 'freevspro' => admin_url('admin.php?page=bs-free-pro'),
223 'changelogUrl' => admin_url('admin.php?page=bs-change-log'),
224 'docsUrl' => 'https://blockspare.com/docs/',
225 'channel' => 'https://www.youtube.com/@blockspare/videos',
226 'devChnagelog' => 'https://wordpress.org/plugins/blockspare/#developers',
227 'changelog' => blockspare_get_latest_change_log(),
228 'blocks' => $blockspare_block_manager->get_all_blocks(),
229 'disabledBlocks' => $blockspare_block_manager->get_disabled_blocks(),
230
231 )
232 );
233 }
234
235
236 public function blockspare_admin_blocks()
237 {
238 ?>
239 <div id="bs-starter-sites"></div>
240
241 <?php
242 }
243
244 public function blockspare_admin_dashboard()
245 {
246 ?>
247 <div id="bs-dashboard"></div>
248
249
250 <?php
251
252 }
253
254 public function blockspare_admin_explore_more_blocks()
255 {
256
257 ?>
258 <div id="bs-explore-more-dashboard"></div>
259
260
261 <?php
262 }
263
264 public function blockspare_admin_change_log()
265 {
266 ?>
267 <div id="bs-change-log"></div>
268 <?php
269
270 }
271
272 public function blockspare_admin_free_vs_pro()
273 {
274 ?>
275 <div id="bs-free-vs-pro"></div>
276 <?php
277
278 }
279
280 /**
281 * Adds a marker to remember to redirect after activation.
282 * Redirecting right away will not work.
283 */
284 public static function start_redirect_to_blockspare_page()
285 {
286 update_option('blockspare_redirect_to_welcome', '1');
287 }
288
289 /**
290 * Redirect to the welcome screen if our marker exists.
291 */
292 public function redirect_to_blockspare_page()
293 {
294 if (get_option('blockspare_redirect_to_welcome')) {
295 delete_option('blockspare_redirect_to_welcome');
296 wp_redirect(esc_url(admin_url('admin.php?page=blockspare')));
297 die();
298 }
299 }
300 }
301
302 new Blockspare_Admin_Dashboard();
303 }
304
305 // Redirect to the welcome screen.
306 register_activation_hook(BLOCKSPARE_BASE_FILE, array('Blockspare_Admin_Dashboard', 'start_redirect_to_blockspare_page'));
307