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

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