PluginProbe
WP Coder – Insert & Manage Code Snippets / 3.1.1
WP Coder – Insert & Manage Code Snippets v3.1.1
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 / DashboardHelper.php

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

85 lines 1.8 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 DashboardHelper {
10
11 public static function first_file( $folder ) {
12
13 $files = self::get_files( $folder );
14
15 return reset( $files )['file'];
16 }
17
18 public static function get_files( $folder ): array {
19 $scan_files = scandir( self::get_folder_path( $folder ) );
20 $files = [];
21 foreach ( $scan_files as $file ) {
22 if ( $file === '.' || $file === '..' || $file === 'index.php' ) {
23 continue;
24 }
25 $extension = pathinfo( $file, PATHINFO_EXTENSION );
26
27 if ( $extension !== 'php' ) {
28 continue;
29 }
30 $matches = explode( '.', $file );
31 if ( ! is_numeric( $matches[0] ) ) {
32 continue;
33 }
34
35 $file_name = self::get_file_name( $file, $folder );
36
37 $files[ $matches[0] ] = [ 'file' => $matches[1], 'name' => $file_name ];
38 }
39
40 return $files;
41 }
42
43 public static function get_file_name( $file, $folder ): string {
44
45 $file_path = self::get_folder_path( $folder ) . '/' . $file;
46 $file_data = get_file_data( $file_path, array( 'name' => 'Page Name' ) );
47
48 return $file_data['name'];
49
50 }
51
52 public static function get_folder_path( $folder ): string {
53 return WPCoder::dir() . 'includes/' . $folder;
54 }
55
56 public static function get_file( $current, $folder ) {
57 $files = scandir( self::get_folder_path( $folder ) );
58 foreach ( $files as $file ) {
59 $matches = explode( '.', $file );
60 if ( isset( $matches[1] ) && $matches[1] === $current ) {
61 return $file;
62 }
63 }
64
65 return false;
66 }
67
68 public static function search_value( $array, $value ): bool {
69
70 foreach ( $array as $item ) {
71 if ( is_array( $item ) ) {
72 if ( self::search_value( $item, $value ) ) {
73 return true;
74 }
75 } else {
76 if ( $item === $value ) {
77 return true;
78 }
79 }
80 }
81
82 return false;
83 }
84
85 }