PluginProbe
WP Coder – Insert & Manage Code Snippets / 4.3
WP Coder – Insert & Manage Code Snippets v4.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 4.3, at classes/Dashboard/DashboardInitializer.php

119 lines 4.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\WPCoder;
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' => WPCoder::SLUG,
23 'tab' => 'settings',
24 'action' => 'new'
25 ], admin_url( 'admin.php' ) );
26 ?>
27
28 <div class="wowp-header">
29 <div class="wowp-header__logo">
30 <svg width="64" height="64" viewBox="0 0 512 512" xmlns="http://www.w3.org/2000/svg">
31 <path id="1728127909379-8007129Oval-Copy" fill="#2b7fff" fill-rule="evenodd" stroke="none" d="M 496 101 C 496 128.614227 473.614227 151 446 151 C 418.385773 151 396 128.614227 396 101 C 396 73.385773 418.385773 51 446 51 C 473.614227 51 496 73.385773 496 101 Z"/>
32 <g id="window-code">
33 <path id="Path" fill="#212121" stroke="none" d="M 245.714279 232.714294 L 74.285713 61.285736 C 60.571426 47.571411 40 47.571411 26.285713 61.285736 C 12.571427 75 12.571427 95.571442 26.285713 109.285706 L 173.714279 256.714294 L 26.285713 404.142853 C 12.571427 417.857147 12.571427 438.428589 26.285713 452.142853 C 33.142857 459 40 462.428558 50.285713 462.428558 C 60.571426 462.428558 67.428574 459 74.285713 452.142853 L 245.714279 280.714294 C 259.428589 267 259.428589 246.428558 245.714279 232.714294 Z"/>
34 <path id="Rounded-Rectangle" fill="#212121" fill-rule="evenodd" stroke="none" d="M 256 431 C 256 448.673096 270.326874 463 288 463 L 464 463 C 481.673096 463 496 448.673096 496 431 L 496 429 C 496 411.326904 481.673096 397 464 397 L 288 397 C 270.326874 397 256 411.326904 256 429 Z"/>
35 </g>
36 </svg>
37 </div>
38 <h1 class="wowp-header__title">
39 <?php echo esc_html( WPCoder::info( 'name' ) ); ?>
40 <sup class="wowp-header__title-version"><?php echo esc_html( WPCoder::info( 'version' ) ); ?></sup>
41 </h1>
42 <div class="wowp-header__links">
43 <?php do_action( WPCoder::PREFIX . '_admin_header_links' ); ?>
44 </div>
45 </div>
46
47
48 <?php
49 }
50
51 public static function logo_url(): string {
52 $logo_url = WPCoder::url() . 'assets/img/plugin-logo.png';
53 if ( filter_var( $logo_url, FILTER_VALIDATE_URL ) !== false ) {
54 return $logo_url;
55 }
56
57 return '';
58 }
59
60 public static function menu(): void {
61
62 $pages = DashboardHelper::get_files( 'pages' );
63 unset( $pages["3"], $pages["4"] );
64
65 $current_page = self::get_current_page();
66
67 $action = ( isset( $_REQUEST["action"] ) ) ? sanitize_text_field( $_REQUEST["action"] ) : '';
68
69 echo '<h2 class="nav-tab-wrapper wowp-nav-tab-wrapper">';
70 foreach ( $pages as $key => $page ) {
71 $class = ( $page['file'] === $current_page ) ? ' nav-tab-active' : '';
72 $id = '';
73
74 if ( $action === 'update' && $page['file'] === 'settings' ) {
75 $id = ( isset( $_REQUEST["id"] ) ) ? absint( $_REQUEST["id"] ) : '';
76 $page['name'] = __( 'Update', 'wp-coder' ) . ' #' . $id;
77 } elseif ( $page['file'] === 'settings' && ( $action !== 'new' && $action !== 'duplicate' ) ) {
78 continue;
79 }
80
81 echo '<a class="nav-tab' . esc_attr( $class ) . '" href="' . esc_url( Link::menu( $page['file'], $action, $id ) ) . '">' . esc_html( $page['name'] ) . '</a>';
82 }
83 echo '</h2>';
84
85
86 }
87
88 public static function include_pages(): void {
89 $current_page = self::get_current_page();
90
91 $pages = DashboardHelper::get_files( 'pages' );
92 $default = DashboardHelper::first_file( 'pages' );
93
94 $current = DashboardHelper::search_value( $pages, $current_page ) ? $current_page : $default;
95
96 $file = DashboardHelper::get_file( $current, 'pages' );
97
98
99 if ( $file !== false ) {
100 $file = apply_filters( WPCoder::PREFIX . '_admin_filter_file', $file, $current );
101
102 $page_path = DashboardHelper::get_folder_path( 'pages' ) . '/' . $file;
103
104 if ( file_exists( $page_path ) ) {
105 require_once $page_path;
106 }
107 }
108
109 }
110
111
112 public static function get_current_page(): string {
113 $default = DashboardHelper::first_file( 'pages' );
114
115 return ( isset( $_REQUEST["tab"] ) ) ? sanitize_text_field( $_REQUEST["tab"] ) : $default;
116 }
117
118
119 }