PluginProbe ʕ •ᴥ•ʔ
Admin Columns / 7.1.4
Admin Columns v7.1.4
7.1.4 7.0.19 2.3.5 2.4 2.4.1 2.4.10 2.4.2 2.4.3 2.4.4 2.4.5 2.4.6 2.4.7 2.4.8 2.4.9 2.5.2 2.5.3 2.5.4 2.5.5 2.5.6 2.5.6.1 2.5.6.2 2.5.6.3 2.5.6.4 3.0 3.0.1 3.0.2 3.0.3 3.0.5 3.0.7 3.1 3.1.1 3.1.10 3.1.2 3.1.3 3.1.5 3.2.3 3.2.7 3.3.1 3.4.1 3.4.6 3.4.8 4.0.1 4.0.3 4.1.6 4.2.2 4.2.5 4.3 4.3.2 4.4.1 4.4.4 4.4.5 4.5.5 4.6.1 4.7.18 4.7.19 4.7.20 4.7.7 7.0.13 7.0.14 7.0.16 trunk 1.0 1.1 1.1.3 1.2 1.2.1 1.3 1.3.1 1.4 1.4.1 1.4.2 1.4.3 1.4.4 1.4.5 1.4.5.1 1.4.6 1.4.6.1 1.4.6.2 1.4.6.3 1.4.6.4 1.4.7 1.4.8 1.4.9 2.0.0 2.0.1 2.0.2 2.0.3 2.1.0 2.1.1 2.1.2 2.1.3 2.1.4 2.1.5 2.2 2.2.1 2.2.1.1 2.2.2 2.2.3 2.2.4 2.2.5 2.2.5.1 2.2.6 2.2.6.1 2.2.6.2 2.2.6.3 2.2.6.4 2.2.7 2.2.8 2.2.8.1 2.2.9 2.3.1 2.3.2 2.3.3
codepress-admin-columns / classes / Helper / LocalFile.php
codepress-admin-columns / classes / Helper Last commit date
Image 1 day ago Select 1 day ago Arrays.php 1 day ago AvailableTranslations.php 1 day ago Creatable.php 1 day ago Dashicon.php 1 day ago Date.php 1 day ago Html.php 1 day ago Icon.php 1 day ago Image.php 1 day ago LocalFile.php 1 day ago Mbstring.php 1 day ago MediaIdResolver.php 1 day ago Menu.php 1 day ago Network.php 1 day ago Post.php 1 day ago Strings.php 1 day ago Taxonomy.php 1 day ago User.php 1 day ago UserRoles.php 1 day ago WpDateFormat.php 1 day ago
LocalFile.php
65 lines
1 <?php
2
3 declare(strict_types=1);
4
5 namespace AC\Helper;
6
7 class LocalFile extends Creatable
8 {
9 public function url_to_path(string $url): string
10 {
11 // Normalize the scheme (http vs https) to WP_CONTENT_URL's so a local URL isn't mistaken for an external one.
12 $url = set_url_scheme($url, wp_parse_url(WP_CONTENT_URL, PHP_URL_SCHEME) ?: null);
13
14 return (string)str_replace(WP_CONTENT_URL, WP_CONTENT_DIR, $url);
15 }
16
17 public function path_to_url(string $path): string
18 {
19 return (string)str_replace(WP_CONTENT_DIR, WP_CONTENT_URL, $path);
20 }
21
22 public function get_path(string $url): ?string
23 {
24 $path = $this->url_to_path($url);
25
26 if (! file_exists($path)) {
27 return null;
28 }
29
30 return $path;
31 }
32
33 public function get_size(string $url): ?int
34 {
35 $path = $this->get_path($url);
36
37 if ($path === null) {
38 return null;
39 }
40
41 $size = filesize($path);
42
43 return $size === false
44 ? null
45 : $size;
46 }
47
48 public function get_file_name(int $attachment_id): ?string
49 {
50 $file = get_post_meta($attachment_id, '_wp_attached_file', true);
51
52 if (! $file) {
53 return null;
54 }
55
56 return basename((string)$file);
57 }
58
59 public function get_file_extension(int $attachment_id): string
60 {
61 return (string)pathinfo($this->get_file_name($attachment_id) ?? '', PATHINFO_EXTENSION);
62 }
63
64 }
65