PluginProbe
aBlocks – Gutenberg Blocks, User Dashboard Builder, Popup Builder, Form Builder & Animation Builder / trunk
aBlocks – Gutenberg Blocks, User Dashboard Builder, Popup Builder, Form Builder & Animation Builder vtrunk
2.12.0 2.11.1 2.11.0 2.10.0 2.9.0 2.7.4 2.7.5 2.7.6 2.7.7 2.8.0 2.8.1 2.9.1 trunk 1.0 1.0-beta1 1.0-beta2 1.0-beta3 1.0.1 1.0.2 1.0.3 1.1.0 1.1.1 1.1.2 1.2.0 1.2.1 All 78 releases
ablocks / includes / admin / menu.php

menu.php in aBlocks – Gutenberg Blocks, User Dashboard Builder, Popup Builder, Form Builder & Animation Builder trunk, at includes/admin/menu.php

109 lines 3.6 KB
No matching file
Up and down to move Enter to open Esc to close
Raw Download Zip
1 <?php
2 namespace ABlocks\Admin;
3
4 if ( ! defined( 'ABSPATH' ) ) {
5 exit;
6 }
7
8 use ABlocks\Helper;
9 use ABlocks\Permissions;
10
11 class Menu {
12
13 public static function init() {
14 $self = new self();
15 add_action( 'admin_menu', array( $self, 'admin_menu' ) );
16 add_action( 'admin_head', array( $self, 'add_admin_menu_css' ) );
17 }
18
19 /**
20 * Add admin menu page
21 *
22 * @return void
23 */
24 public function admin_menu() {
25 $icon_url = $this->get_toplevel_menu_icon_url();
26 $page_title = $this->get_toplevel_menu_title();
27 add_menu_page( $page_title, $page_title, Permissions::ACCESS, ABLOCKS_PLUGIN_SLUG, [ $this, 'load_main_template' ], $icon_url, 30 );
28 foreach ( Helper::get_admin_menu_list() as $item_key => $item ) {
29 add_submenu_page( $item['parent_slug'], $item['title'], $item['title'], $item['capability'], $item_key, [ $this, 'load_main_template' ] );
30 }
31
32 $this->register_theme_demo_importer_menu();
33 }
34 public function get_toplevel_menu_icon_url() {
35 // phpcs:disable
36 if ( isset( $_GET['page'] ) && 'ablocks' === $_GET['page'] ) {
37 $icon_url = 'data:image/svg+xml;base64, ' . base64_encode( file_get_contents( ABLOCKS_ASSETS_PATH . 'images/menu-icon-expand.svg' ) );
38 return apply_filters( 'ablocks/admin/toplevel_active_menu_icon', $icon_url );
39 }
40 $icon_url = 'data:image/svg+xml;base64, ' . base64_encode( file_get_contents( ABLOCKS_ASSETS_PATH . 'images/menu-icon.svg' ) );
41 return apply_filters( 'ablocks/admin/toplevel_inactive_menu_icon', $icon_url );
42 }
43 public function load_main_template() {
44 $preloader_html = apply_filters( 'ablocks/preloader', Helper::get_preloader_html() );
45 echo '<div id="ablockswrap" class="ablockswrap">' . wp_kses_post( $preloader_html ) . '</div>';
46 }
47 public function get_toplevel_menu_title() {
48 return apply_filters( 'ablocks/admin/toplevel_menu_title', __( 'aBlocks', 'ablocks' ) );
49 }
50
51 /**
52 * Register sub-menu for theme based demo-import.
53 *
54 * @return void
55 */
56 public function register_theme_demo_importer_menu() {
57 $demo_config = Helper::get_theme_demo_config();
58 if ( empty($demo_config['demos']) && !$demo_config['preloaded_demo']) {
59 return;
60 }
61
62 add_submenu_page(
63 'themes.php',
64 $demo_config['page_title'],
65 $demo_config['menu_title'],
66 'ablocks_import_templates',
67 $demo_config['menu_slug'],
68 [ $this, 'load_demo_importer_template' ]
69 );
70 }
71
72 public function load_demo_importer_template() {
73 echo '<div id="ablocks-theme-demo-importer"></div>';
74 }
75
76 function add_admin_menu_css() {
77 echo '<style>
78 #adminmenu li.toplevel_page_ablocks a.toplevel_page_ablocks > .wp-menu-image {
79 display: flex;
80 justify-content: center;
81 align-items: center;
82 }
83 #adminmenu li.toplevel_page_ablocks a.toplevel_page_ablocks > .wp-menu-image img {
84 max-width: 20px;
85 height: auto;
86 padding: 0 !important;
87 }
88 #adminmenu li.toplevel_page_ablocks ul li a, #adminmenu li.toplevel_page_ablocks .wp-submenu > li > a {
89 padding: 7px 12px;
90 }
91
92 #adminmenu li.toplevel_page_ablocks ul.wp-submenu li {
93 clear: both;
94 }
95 #adminmenu li.toplevel_page_ablocks ul.wp-submenu li.wp-first-item a[href^="admin.php?page=ablocks"]:after,
96 #adminmenu li.toplevel_page_ablocks ul.wp-submenu li.wp-first-item a[href*="admin.php?page=ablocks"]:after,
97 #adminmenu li.toplevel_page_ablocks ul.wp-submenu li a[href*="admin.php?page=ablocks-tools"]:after,
98 #adminmenu li.toplevel_page_ablocks ul.wp-submenu li a[href^="admin.php?page=ablocks-tools"]:after {
99 border-bottom: 1px solid hsla(0,0%,100%,.2);
100 display: block;
101 float: left;
102 margin: 15px -15px 7px;
103 content: "";
104 width: calc(100% + 26px);
105 }
106 </style>';
107 }
108 }
109