PluginProbe
WP Coder – Insert & Manage Code Snippets / 3.0.3
WP Coder – Insert & Manage Code Snippets v3.0.3
4.5.1 1.1 2.3.1 2.3.2 2.4.1 2.5.1 2.5.2 2.5.3 2.5.4 2.5.5 2.5.6 3.0 3.0.1 3.0.2 3.0.3 3.0.4 3.0.5 3.1 3.1.1 3.2 3.2.1 3.3 3.4 3.5 3.5.1 All 39 releases
wp-coder / classes / Dashboard / DashboardInitializer.php

DashboardInitializer.php in WP Coder – Insert & Manage Code Snippets 3.0.3, at classes/Dashboard/DashboardInitializer.php

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