| 1 |
<?php |
| 2 |
/** |
| 3 |
* Welcome screen. |
| 4 |
*/ |
| 5 |
|
| 6 |
// Exit if accessed directly. |
| 7 |
if (!defined('ABSPATH')) { |
| 8 |
exit; |
| 9 |
} |
| 10 |
|
| 11 |
if (!class_exists('Blockspare_Admin_Dashboard')) { |
| 12 |
class Blockspare_Admin_Dashboard |
| 13 |
{ |
| 14 |
public function __construct() |
| 15 |
{ |
| 16 |
add_action('admin_menu', array($this, 'add_dashboard_page')); |
| 17 |
|
| 18 |
add_action('admin_enqueue_scripts', array($this, 'enqueue_dashboard_script')); |
| 19 |
|
| 20 |
add_action('admin_init', array($this, 'redirect_to_blockspare_page')); |
| 21 |
|
| 22 |
//add_action( 'init', array($this,'blockspare_load_api_files')); |
| 23 |
|
| 24 |
add_filter('plugin_row_meta', [$this, 'plugin_row_meta'], 10, 2); |
| 25 |
|
| 26 |
add_filter('plugin_action_links_' . BLOCKSPARE_PLUGIN_BASE, [$this, 'plugin_action_links']); |
| 27 |
} |
| 28 |
|
| 29 |
public function plugin_action_links($links) |
| 30 |
{ |
| 31 |
$settings_link = sprintf('<a href="%1$s">%2$s</a>', admin_url('admin.php?page=blockspare'), esc_html__('Patterns Library', 'blockspare')); |
| 32 |
|
| 33 |
array_unshift($links, $settings_link); |
| 34 |
|
| 35 |
$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')); |
| 36 |
|
| 37 |
return $links; |
| 38 |
} |
| 39 |
public function plugin_row_meta($plugin_meta, $plugin_file) |
| 40 |
{ |
| 41 |
if (BLOCKSPARE_PLUGIN_BASE === $plugin_file) { |
| 42 |
$row_meta = [ |
| 43 |
'starter' => '<a href="https://www.blockspare.com/starter-templates/" aria-label="' . esc_attr(esc_html__('View Blockspare Patterns Library', 'blockspare')) . '" target="_blank">' . esc_html__('Demos', 'blockspare') . '</a>', |
| 44 |
'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>', |
| 45 |
'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>', |
| 46 |
'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>', |
| 47 |
]; |
| 48 |
|
| 49 |
$plugin_meta = array_merge($plugin_meta, $row_meta); |
| 50 |
} |
| 51 |
|
| 52 |
return $plugin_meta; |
| 53 |
} |
| 54 |
|
| 55 |
public function add_dashboard_page() |
| 56 |
{ |
| 57 |
|
| 58 |
// @see images/blockspare-icon.svg |
| 59 |
$svg = <<< SVG |
| 60 |
<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" |
| 61 |
viewBox="0 0 40 40" style="enable-background:new 0 0 40 40;" xml:space="preserve"> |
| 62 |
<g> |
| 63 |
<g> |
| 64 |
<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"/> |
| 65 |
<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 "/> |
| 66 |
</g> |
| 67 |
<g> |
| 68 |
<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 |
| 69 |
29.2,19.7 26,18.4 26,3.1 "/> |
| 70 |
<polygon id="XMLID_1_" class="st1" points="17,38.4 19.9,40 38.4,30.7 35.3,29 "/> |
| 71 |
</g> |
| 72 |
</g> |
| 73 |
</svg> |
| 74 |
SVG; |
| 75 |
|
| 76 |
add_menu_page( |
| 77 |
__('Blockspare', 'blockspare'), // Page Title. |
| 78 |
__('Blockspare', 'blockspare'), // Menu Title. |
| 79 |
'edit_posts', // Capability. |
| 80 |
'blockspare', // Menu slug. |
| 81 |
array($this, 'blockspare_admin_dashboard'), // Action. |
| 82 |
'data:image/svg+xml;base64,' . base64_encode($svg), // Blockspare icon. |
| 83 |
25 |
| 84 |
); |
| 85 |
|
| 86 |
// Our getting started page. |
| 87 |
add_submenu_page( |
| 88 |
'blockspare', // Parent slug. |
| 89 |
__('Patterns Library', 'blockspare'), // Page title. |
| 90 |
__('Patterns Library', 'blockspare'), // Menu title. |
| 91 |
'manage_options', // Capability. |
| 92 |
'blockspare', // Menu slug. |
| 93 |
array($this, 'blockspare_admin_dashboard'), // Callback function. |
| 94 |
1// Position |
| 95 |
); |
| 96 |
|
| 97 |
add_submenu_page( |
| 98 |
'blockspare', // Parent slug. |
| 99 |
__('My Patterns', 'blockspare'), // Page title. |
| 100 |
__('My Patterns', 'blockspare'), // Menu title. |
| 101 |
'manage_options', // Capability. |
| 102 |
'edit.php?post_type=bs_templates', // Menu slug. |
| 103 |
|
| 104 |
); |
| 105 |
} |
| 106 |
|
| 107 |
public function enqueue_dashboard_script($hook) |
| 108 |
{ |
| 109 |
wp_enqueue_style('blockspare-admin', BLOCKSPARE_PLUGIN_URL . 'admin/assets/css/style.css', '', ''); |
| 110 |
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'); |
| 111 |
wp_enqueue_style('blockspare-admin-css', BLOCKSPARE_PLUGIN_URL . 'dist/style-block_admin_dashboard.css'); |
| 112 |
$blockspare_dashboard_logo = BLOCKSPARE_PLUGIN_URL . 'admin/assets/images/blockspare-logo.png'; |
| 113 |
wp_localize_script( |
| 114 |
'blockspare_dashboard_js', |
| 115 |
'blockspare_dashboard', |
| 116 |
array( |
| 117 |
|
| 118 |
'logo' => $blockspare_dashboard_logo, |
| 119 |
"imagePath" => "https://raw.githubusercontent.com/afthemes/blockspare-demo-data/master/blocks/", |
| 120 |
"static_img" => BLOCKSPARE_PLUGIN_URL, |
| 121 |
'newPageUrl' => admin_url('post-new.php?post_type=page&blockspare_create_block'), |
| 122 |
'adminPath' => admin_url('post-new.php?post_type=page&blockspare_show_intro=true'), |
| 123 |
'pluginVesion' => BLOCKSPARE_VERSION, |
| 124 |
|
| 125 |
) |
| 126 |
); |
| 127 |
} |
| 128 |
|
| 129 |
public function blockspare_admin_dashboard() |
| 130 |
{ |
| 131 |
?> |
| 132 |
<div id="bs-dashboard"></div> |
| 133 |
|
| 134 |
<?php |
| 135 |
} |
| 136 |
|
| 137 |
/** |
| 138 |
* Adds a marker to remember to redirect after activation. |
| 139 |
* Redirecting right away will not work. |
| 140 |
*/ |
| 141 |
public static function start_redirect_to_blockspare_page() |
| 142 |
{ |
| 143 |
update_option('blockspare_redirect_to_welcome', '1'); |
| 144 |
} |
| 145 |
|
| 146 |
/** |
| 147 |
* Redirect to the welcome screen if our marker exists. |
| 148 |
*/ |
| 149 |
public function redirect_to_blockspare_page() |
| 150 |
{ |
| 151 |
if (get_option('blockspare_redirect_to_welcome')) { |
| 152 |
delete_option('blockspare_redirect_to_welcome'); |
| 153 |
wp_redirect(esc_url(admin_url('admin.php?page=blockspare'))); |
| 154 |
die(); |
| 155 |
} |
| 156 |
} |
| 157 |
|
| 158 |
} |
| 159 |
|
| 160 |
new Blockspare_Admin_Dashboard(); |
| 161 |
} |
| 162 |
|
| 163 |
// Redirect to the welcome screen. |
| 164 |
register_activation_hook(BLOCKSPARE_BASE_FILE, array('Blockspare_Admin_Dashboard', 'start_redirect_to_blockspare_page')); |