PluginProbe
BlockSpare – Gutenberg Blocks for News, Magazine, Blog & Business Websites / 4.1.0
BlockSpare – Gutenberg Blocks for News, Magazine, Blog & Business Websites v4.1.0
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 4.1.0, at admin/index.php

170 lines 6.4 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-upgrade.php';
32 include_once BLOCKSPARE_PLUGIN_DIR . 'admin/notice-review.php';
33 }
34
35 public function plugin_action_links($links)
36 {
37 $settings_link = sprintf('<a href="%1$s">%2$s</a>', admin_url('admin.php?page=blockspare'), esc_html__('Templates Library', 'blockspare'));
38
39 array_unshift($links, $settings_link);
40
41 $links['bspro'] = sprintf('<a href="%1$s" target="_blank" class="blockspare-pro-link">%2$s</a>', 'https://www.blockspare.com/', esc_html__('Get Blockspare Pro', 'blockspare'));
42
43 return $links;
44 }
45 public function plugin_row_meta($plugin_meta, $plugin_file)
46 {
47 if (BLOCKSPARE_PLUGIN_BASE === $plugin_file) {
48 $row_meta = [
49 'starter' => '<a href="https://www.blockspare.com/starter-templates/" aria-label="' . esc_attr(esc_html__('View Blockspare Templates Library', 'blockspare')) . '" target="_blank">' . esc_html__('Demos', 'blockspare') . '</a>',
50 '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>',
51 'video' => '<a href="https://afthemes.com/all-themes-plan/" aria-label="' . esc_attr(esc_html__('Access All Themes and Plugins', 'blockspare')) . '" target="_blank">' . esc_html__('All Themes & Plugins', 'blockspare') . '</a>',
52 '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>',
53 ];
54
55 $plugin_meta = array_merge($plugin_meta, $row_meta);
56 }
57
58 return $plugin_meta;
59 }
60
61 public function add_dashboard_page()
62 {
63
64 // @see images/blockspare-icon.svg
65 $svg = <<< SVG
66 <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"
67 viewBox="0 0 40 40" style="enable-background:new 0 0 40 40;" xml:space="preserve">
68 <g>
69 <g>
70 <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"/>
71 <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 "/>
72 </g>
73 <g>
74 <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
75 29.2,19.7 26,18.4 26,3.1 "/>
76 <polygon id="XMLID_1_" class="st1" points="17,38.4 19.9,40 38.4,30.7 35.3,29 "/>
77 </g>
78 </g>
79 </svg>
80 SVG;
81
82 add_menu_page(
83 __('Blockspare', 'blockspare'), // Page Title.
84 __('Blockspare', 'blockspare'), // Menu Title.
85 'edit_posts', // Capability.
86 'blockspare', // Menu slug.
87 array($this, 'blockspare_admin_dashboard'), // Action.
88 'data:image/svg+xml;base64,' . base64_encode($svg), // Blockspare icon.
89 25
90 );
91
92 // Our getting started page.
93 add_submenu_page(
94 'blockspare', // Parent slug.
95 __('Starter Templates', 'blockspare'), // Page title.
96 __('Starter Templates', '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 add_submenu_page(
104 'blockspare', // Parent slug.
105 __('Saved Templates', 'blockspare'), // Page title.
106 __('Saved Templates', 'blockspare'), // Menu title.
107 'manage_options', // Capability.
108 'edit.php?post_type=bs_templates', // Menu slug.
109
110 );
111 }
112
113 public function enqueue_dashboard_script($hook)
114 {
115 wp_enqueue_style('blockspare-admin', BLOCKSPARE_PLUGIN_URL . 'admin/assets/css/style.css', '', '');
116 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');
117 wp_enqueue_style('blockspare-admin-css', BLOCKSPARE_PLUGIN_URL . 'dist/dashboard_css.css');
118 $blockspare_dashboard_logo = BLOCKSPARE_PLUGIN_URL . 'admin/assets/images/blockspare-logo.png';
119 wp_localize_script(
120 'blockspare_dashboard_js',
121 'blockspare_dashboard',
122 array(
123
124 'logo' => $blockspare_dashboard_logo,
125 "imagePath" => "https://raw.githubusercontent.com/afthemes/blockspare-demo-data/master/blocks/new/",
126 "static_img" => BLOCKSPARE_PLUGIN_URL,
127 'newPageUrl' => admin_url('post-new.php?post_type=page&blockspare_create_block'),
128 'adminPath' => admin_url('post-new.php?post_type=page&blockspare_show_intro=true'),
129 'pluginVesion' => BLOCKSPARE_VERSION,
130
131 )
132 );
133 }
134
135 public function blockspare_admin_dashboard()
136 {
137 ?>
138 <div id="bs-dashboard"></div>
139
140 <?php
141 }
142
143 /**
144 * Adds a marker to remember to redirect after activation.
145 * Redirecting right away will not work.
146 */
147 public static function start_redirect_to_blockspare_page()
148 {
149 update_option('blockspare_redirect_to_welcome', '1');
150 }
151
152 /**
153 * Redirect to the welcome screen if our marker exists.
154 */
155 public function redirect_to_blockspare_page()
156 {
157 if (get_option('blockspare_redirect_to_welcome')) {
158 delete_option('blockspare_redirect_to_welcome');
159 wp_redirect(esc_url(admin_url('admin.php?page=blockspare')));
160 die();
161 }
162 }
163 }
164
165 new Blockspare_Admin_Dashboard();
166 }
167
168 // Redirect to the welcome screen.
169 register_activation_hook(BLOCKSPARE_BASE_FILE, array('Blockspare_Admin_Dashboard', 'start_redirect_to_blockspare_page'));
170