PluginProbe
Bubble Menu – Floating Button Menu with Sticky Navigation / 4.0
Bubble Menu – Floating Button Menu with Sticky Navigation v4.0
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, at classes/Admin/Dashboard.php

205 lines 6.2 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($_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></h1>
131 <a href="<?php echo esc_url( Link::add_new_item() ); ?>"
132 class="button button-primary"><?php esc_html_e( 'Add New', 'bubble-menu' ); ?>
133 </a>
134 <?php do_action( WOWP_Plugin::PREFIX . '_admin_header_links' ); ?>
135 </div>
136 </div>
137 </div>
138 <?php
139
140 }
141
142
143 public static function logo_url(): string {
144 $logo_url = WOWP_Plugin::url() . 'admin/assets/img/plugin-logo.png';
145 if ( filter_var( $logo_url, FILTER_VALIDATE_URL ) !== false ) {
146 return $logo_url;
147 }
148
149 return '';
150 }
151
152 public static function menu() {
153 $pages = DashboardHelper::get_files( 'pages' );
154
155 $current_page = self::get_current_page();
156
157 $action = ( isset( $_REQUEST["action"] ) ) ? sanitize_text_field( $_REQUEST["action"] ) : '';
158
159 echo '<h2 class="nav-tab-wrapper wpie-nav-tab-wrapper">';
160 foreach ( $pages as $key => $page ) {
161 $class = ( $page['file'] === $current_page ) ? ' nav-tab-active' : '';
162 $id = '';
163
164 if ( $action === 'update' && $page['file'] === 'settings' ) {
165 $id = ( isset( $_REQUEST["id"] ) ) ? absint( $_REQUEST["id"] ) : '';
166 $page['name'] = __( 'Update', 'bubble-menu' ) . ' #' . $id;
167 } elseif ( $page['file'] === 'settings' && ( $action !== 'new' && $action !== 'duplicate' ) ) {
168 continue;
169 }
170
171 echo '<a class="nav-tab' . esc_attr( $class ) . '" href="' . esc_url( Link::menu( $page['file'], $action, $id ) ) . '">' . esc_html( $page['name'] ) . '</a>';
172 }
173 echo '</h2>';
174 }
175
176 public static function get_current_page(): string {
177 $default = DashboardHelper::first_file( 'pages' );
178
179 return ( isset( $_REQUEST["tab"] ) ) ? sanitize_text_field( $_REQUEST["tab"] ) : $default;
180 }
181
182 public static function include_pages(): void {
183 $current_page = self::get_current_page();
184
185 $pages = DashboardHelper::get_files( 'pages' );
186 $default = DashboardHelper::first_file( 'pages' );
187
188 $current = DashboardHelper::search_value( $pages, $current_page ) ? $current_page : $default;
189
190 $file = DashboardHelper::get_file( $current, 'pages' );
191
192
193 if ( $file !== false ) {
194 $file = apply_filters( WOWP_Plugin::PREFIX . '_admin_filter_file', $file, $current );
195
196 $page_path = DashboardHelper::get_folder_path( 'pages' ) . '/' . $file;
197
198 if ( file_exists( $page_path ) ) {
199 require_once $page_path;
200 }
201 }
202
203 }
204
205 }