PluginProbe
Plugin Check (PCP) / 1.5.0
Plugin Check (PCP) v1.5.0
2.1.0 trunk 0.1 0.2.0 0.2.1 0.2.2 0.2.3 1.0.0 1.0.1 1.0.2 1.1.0 1.2.0 1.3.0 1.3.1 1.4.0 1.5.0 1.6.0 1.7.0 1.8.0 1.9.0 2.0.0 ci-artifacts
plugin-check / includes / Traits / Find_Readme.php

Find_Readme.php in Plugin Check (PCP) 1.5.0, at includes/Traits/Find_Readme.php

55 lines 1.4 KB
No matching file
Up and down to move Enter to open Esc to close
Raw Download Zip
1 <?php
2 /**
3 * Trait WordPress\Plugin_Check\Traits\Find_Readme
4 *
5 * @package plugin-check
6 */
7
8 namespace WordPress\Plugin_Check\Traits;
9
10 /**
11 * Trait for find readme.
12 *
13 * @since 1.0.0
14 */
15 trait Find_Readme {
16
17 /**
18 * Filter the given array of files for readme files (readme.txt or readme.md).
19 *
20 * @since 1.0.0
21 *
22 * @param array $files Array of file files to be filtered.
23 * @param string $plugin_relative_path Plugin relative path.
24 * @return array An array containing readme.txt or readme.md files, or an empty array if none are found.
25 */
26 protected function filter_files_for_readme( array $files, $plugin_relative_path ) {
27 // Find the readme file.
28 $readme_list = preg_grep( '/\/readme\.(txt|md)$/i', $files );
29
30 // Filter the readme files located at root.
31 $potential_readme_files = array_filter(
32 $readme_list,
33 function ( $file ) use ( $plugin_relative_path ) {
34 $file = str_replace( $plugin_relative_path, '', $file );
35 return ! str_contains( $file, '/' );
36 }
37 );
38
39 // If the readme file does not exist, then return empty array.
40 if ( empty( $potential_readme_files ) ) {
41 return array();
42 }
43
44 // Find the .txt versions of the readme files.
45 $readme_txt = array_filter(
46 $potential_readme_files,
47 function ( $file ) {
48 return preg_match( '/^readme\.txt$/i', basename( $file ) );
49 }
50 );
51
52 return $readme_txt ? $readme_txt : $potential_readme_files;
53 }
54 }
55