PluginProbe
Bubble Menu – Floating Button Menu with Sticky Navigation / 4.0.1
Bubble Menu – Floating Button Menu with Sticky Navigation v4.0.1
trunk 1.3 2.0 2.2 2.2.1 3.0 3.0.1 3.0.2 3.0.3 3.0.4 3.0.5 3.1 3.1.1 4.0 4.0.1 4.0.2 4.0.3 4.0.4 4.0.5 4.0.6 4.0.7 4.1 4.1.1
bubble-menu / classes / Admin / Dashboard.php

Dashboard.php in Bubble Menu – Floating Button Menu with Sticky Navigation 4.0.1, at classes/Admin/Dashboard.php

206 lines 6.3 KB
No matching file
Up and down to move Enter to open Esc to close
Raw Download Zip
1 <?php
2 /**
3 * Class Dashboard
4 *
5 * Handles the dashboard functionality of the plugin
6 *
7 * @package BubbleMenu\Admin
8 */
9
10 namespace BubbleMenu\Admin;
11
12 use /**
13 * Class WOWP_Plugin
14 *
15 * This class represents a WordPress plugin that adds custom buttons to the WordPress editor.
16 */
17 BubbleMenu\WOWP_Plugin;
18
19 /**
20 * Class Dashboard
21 */
22 class Dashboard {
23
24 public static function init() {
25 add_filter( 'plugin_action_links', [ __CLASS__, 'settings_link' ], 10, 2 );
26 add_filter( 'admin_footer_text', [ __CLASS__, 'footer_text' ] );
27 add_action( 'admin_enqueue_scripts', [ __CLASS__, 'admin_assets' ] );
28 add_action( 'admin_menu', [ __CLASS__, 'admin_page' ] );
29 AdminNotices::init();
30 }
31
32 public static function settings_link( $links, $file ) {
33 if ( false === strpos( $file, WOWP_Plugin::basename() ) ) {
34 return $links;
35 }
36 $link = admin_url( 'admin.php?page=' . WOWP_Plugin::SLUG );
37 $text = esc_attr__( 'Settings', 'bubble-menu' );
38 $settings_link = '<a href="' . esc_url( $link ) . '">' . esc_attr( $text ) . '</a>';
39 array_unshift( $links, $settings_link );
40
41 return $links;
42 }
43
44 public static function footer_text( $footer_text ) {
45 global $pagenow;
46
47 $page = isset( $_GET['page'] ) ? sanitize_text_field( wp_unslash( $_GET['page'] ) ) : '';
48
49 if ( $pagenow === 'admin.php' && ( ! empty( $page ) && $page === WOWP_Plugin::SLUG ) ) {
50 $text = sprintf(
51 /* translators: 1: Rating link (URL), 2: Plugin name */
52 __( 'Thank you for using <b>%2$s</b>! Please <a href="%1$s" target="_blank">rate us</a>', 'bubble-menu' ),
53 esc_url( WOWP_Plugin::info( 'url' ) ),
54 esc_attr( WOWP_Plugin::info( 'name' ) )
55 );
56
57 return str_replace( '</span>', '', $footer_text ) . ' | ' . $text . '</span>';
58 }
59
60 return $footer_text;
61 }
62
63 public static function admin_assets( $hook ): void {
64
65 $page = 'wow-plugins_page_' . WOWP_Plugin::SLUG;
66 if ( $page !== $hook ) {
67 return;
68 }
69 do_action( WOWP_Plugin::PREFIX . '_admin_load_assets' );
70
71 $slug = WOWP_Plugin::SLUG;
72 $version = WOWP_Plugin::info( 'version' );
73 $assets_url = WOWP_Plugin::url() . 'admin/assets/';
74
75 $styles = DashboardHelper::get_files( 'assets/css' );
76
77 if ( ! empty( $styles ) ) {
78 foreach ( $styles as $key => $style ) {
79 $name = $style['file'];
80 $file = $key . '.' . $name;
81 wp_enqueue_style( $slug . '-admin-' . $name, $assets_url . 'css/' . $file . '.css', null, $version );
82 }
83 }
84
85 $scripts = DashboardHelper::get_files( 'assets/js' );
86 if ( ! empty( $scripts ) ) {
87 foreach ( $scripts as $key => $script ) {
88 $name = $script['file'];
89 $file = $key . '.' . $name;
90 wp_enqueue_script( $slug . '-admin-' . $name, $assets_url . 'js/' . $file . '.js', [ 'jquery' ], $version, true );
91 }
92 }
93
94
95 }
96
97 public static function admin_page() {
98 $page_title = WOWP_Plugin::info( 'name' );
99 $menu_title = WOWP_Plugin::info( 'menu_title' );
100 $capability = ManageCapabilities::get_capability();
101 $parent_slug = 'wow-company';
102 add_submenu_page( $parent_slug, $page_title, $menu_title, $capability, WOWP_Plugin::SLUG, [
103 __CLASS__,
104 'dashboard'
105 ] );
106 }
107
108 public static function dashboard() {
109 self::header();
110 echo '<div class="wrap wpie-wrap">';
111 self::menu();
112 self::include_pages();
113 echo '</div>';
114 }
115
116 public static function header() {
117 $logo_url = self::logo_url();
118 ?>
119 <div class="wpie-header-wrapper">
120 <div class="wpie-header-border"></div>
121 <div class="wpie-header">
122 <div class="wpie-header__container">
123 <?php if ( ! empty( $logo_url ) ): ?>
124 <div class="wpie-logo">
125 <img src="<?php echo esc_url( $logo_url ); ?>"
126 alt="<?php echo esc_attr( WOWP_Plugin::info( 'name' ) ); ?> logo">
127 </div>
128 <?php endif; ?>
129 <h1><?php echo esc_html( WOWP_Plugin::info( 'name' ) ); ?> <sup
130 class="wpie-version"><?php echo esc_html( WOWP_Plugin::info( 'version' ) ); ?></sup>
131 </h1>
132 <a href="<?php echo esc_url( Link::add_new_item() ); ?>"
133 class="button button-primary"><?php esc_html_e( 'Add New', 'bubble-menu' ); ?>
134 </a>
135 <?php do_action( WOWP_Plugin::PREFIX . '_admin_header_links' ); ?>
136 </div>
137 </div>
138 </div>
139 <?php
140
141 }
142
143
144 public static function logo_url(): string {
145 $logo_url = WOWP_Plugin::url() . 'admin/assets/img/plugin-logo.png';
146 if ( filter_var( $logo_url, FILTER_VALIDATE_URL ) !== false ) {
147 return $logo_url;
148 }
149
150 return '';
151 }
152
153 public static function menu() {
154 $pages = DashboardHelper::get_files( 'pages' );
155
156 $current_page = self::get_current_page();
157
158 $action = ( isset( $_REQUEST["action"] ) ) ? sanitize_text_field( wp_unslash( $_REQUEST["action"] ) ) : '';
159
160 echo '<h2 class="nav-tab-wrapper wpie-nav-tab-wrapper">';
161 foreach ( $pages as $key => $page ) {
162 $class = ( $page['file'] === $current_page ) ? ' nav-tab-active' : '';
163 $id = '';
164
165 if ( $action === 'update' && $page['file'] === 'settings' ) {
166 $id = ( isset( $_REQUEST["id"] ) ) ? absint( $_REQUEST["id"] ) : '';
167 $page['name'] = __( 'Update', 'bubble-menu' ) . ' #' . $id;
168 } elseif ( $page['file'] === 'settings' && ( $action !== 'new' && $action !== 'duplicate' ) ) {
169 continue;
170 }
171
172 echo '<a class="nav-tab' . esc_attr( $class ) . '" href="' . esc_url( Link::menu( $page['file'], $action, $id ) ) . '">' . esc_html( $page['name'] ) . '</a>';
173 }
174 echo '</h2>';
175 }
176
177 public static function get_current_page(): string {
178 $default = DashboardHelper::first_file( 'pages' );
179
180 return ( isset( $_REQUEST["tab"] ) ) ? sanitize_text_field( wp_unslash( $_REQUEST["tab"] ) ) : $default;
181 }
182
183 public static function include_pages(): void {
184 $current_page = self::get_current_page();
185
186 $pages = DashboardHelper::get_files( 'pages' );
187 $default = DashboardHelper::first_file( 'pages' );
188
189 $current = DashboardHelper::search_value( $pages, $current_page ) ? $current_page : $default;
190
191 $file = DashboardHelper::get_file( $current, 'pages' );
192
193
194 if ( $file !== false ) {
195 $file = apply_filters( WOWP_Plugin::PREFIX . '_admin_filter_file', $file, $current );
196
197 $page_path = DashboardHelper::get_folder_path( 'pages' ) . '/' . $file;
198
199 if ( file_exists( $page_path ) ) {
200 require_once $page_path;
201 }
202 }
203
204 }
205
206 }