PluginProbe
Floating Button – Easily Create Sticky, Fixed & Floating Buttons / 6.0.6
Floating Button – Easily Create Sticky, Fixed & Floating Buttons v6.0.6
trunk 2.0.2 3.0 4.0 4.1.2 4.3 5.0 5.0.1 5.1 5.1.1 5.2 5.3 5.3.1 6.0 6.0.1 6.0.10 6.0.11 6.0.12 6.0.13 6.0.2 6.0.3 6.0.4 6.0.5 6.0.6 6.0.7 All 31 releases
floating-button / classes / Dashboard / DashboardInitializer.php

DashboardInitializer.php in Floating Button – Easily Create Sticky, Fixed & Floating Buttons 6.0.6, at classes/Dashboard/DashboardInitializer.php

114 lines 3.3 KB
No matching file
Up and down to move Enter to open Esc to close
Raw Download Zip
1 <?php
2
3 namespace FloatingButton\Dashboard;
4
5 defined( 'ABSPATH' ) || exit;
6
7 use FloatingButton\WOW_Plugin;
8
9 class DashboardInitializer {
10
11 public static function init(): void {
12 self::header();
13 echo '<div class="wrap wowp-wrap">';
14 self::menu();
15 self::include_pages();
16 echo '</div>';
17 }
18
19 public static function header(): void {
20 $logo_url = self::logo_url();
21 $add_url = add_query_arg( [
22 'page' => WOW_Plugin::SLUG,
23 'tab' => 'settings',
24 'action' => 'new'
25 ], admin_url( 'admin.php' ) );
26 ?>
27 <div class="wowp-header-wrapper">
28 <div class="wowp-header-border"></div>
29 <div class="wowp-header">
30 <div class="wowp-logo">
31 <img src="<?php
32 echo esc_url( $logo_url ); ?>" alt="<?php
33 echo esc_attr( WOW_Plugin::info( 'name' ) ); ?> logo">
34 </div>
35 <h1><?php
36 echo esc_html( WOW_Plugin::info( 'name' ) ); ?> <sup class="wowp-version"><?php
37 echo esc_html( WOW_Plugin::info( 'version' ) ); ?></sup></h1>
38 <a href="<?php
39 echo esc_url( $add_url ); ?>" class="button"><?php
40 esc_html_e( 'Add New', 'floating-button' ); ?>
41 </a>
42 <?php
43 do_action( WOW_Plugin::PREFIX . '_admin_header_links' ); ?>
44 </div>
45 </div>
46
47 <?php
48 }
49
50 public static function logo_url(): string {
51 $logo_url = WOW_Plugin::url() . 'assets/img/plugin-logo.png';
52 if ( filter_var( $logo_url, FILTER_VALIDATE_URL ) !== false ) {
53 return $logo_url;
54 }
55
56 return '';
57 }
58
59 public static function menu(): void {
60 $pages = DashboardHelper::get_files( 'pages' );
61
62 $current_page = self::get_current_page();
63
64 $action = ( isset( $_REQUEST["action"] ) ) ? sanitize_text_field( wp_unslash( $_REQUEST["action"] ) ) : '';
65
66 echo '<h2 class="nav-tab-wrapper wowp-nav-tab-wrapper">';
67 foreach ( $pages as $key => $page ) {
68 $class = ( $page['file'] === $current_page ) ? ' nav-tab-active' : '';
69 $id = '';
70
71 if ( $action === 'update' && $page['file'] === 'settings' ) {
72 $id = ( isset( $_REQUEST["id"] ) ) ? absint( $_REQUEST["id"] ) : '';
73 $page['name'] = __( 'Update', 'floating-button' ) . ' #' . $id;
74 } elseif ( $page['file'] === 'settings' && ( $action !== 'new' && $action !== 'duplicate' ) ) {
75 continue;
76 }
77
78 echo '<a class="nav-tab' . esc_attr( $class ) . '" href="' . esc_url( Link::menu( $page['file'], $action,
79 $id ) ) . '">' . esc_html( $page['name'] ) . '</a>';
80 }
81 echo '</h2>';
82 }
83
84 public static function include_pages(): void {
85 $current_page = self::get_current_page();
86
87 $pages = DashboardHelper::get_files( 'pages' );
88 $default = DashboardHelper::first_file( 'pages' );
89
90 $current = DashboardHelper::search_value( $pages, $current_page ) ? $current_page : $default;
91
92 $file = DashboardHelper::get_file( $current, 'pages' );
93
94
95 if ( $file !== false ) {
96 $file = apply_filters( WOW_Plugin::PREFIX . '_admin_filter_file', $file, $current );
97
98 $page_path = DashboardHelper::get_folder_path( 'pages' ) . '/' . $file;
99
100 if ( file_exists( $page_path ) ) {
101 require_once $page_path;
102 }
103 }
104 }
105
106
107 public static function get_current_page(): string {
108 $default = DashboardHelper::first_file( 'pages' );
109
110 return ( isset( $_REQUEST["tab"] ) ) ? sanitize_text_field( wp_unslash( $_REQUEST["tab"] ) ) : $default;
111 }
112
113
114 }