PluginProbe
BerqWP – All-In-One Optimization for Core Web Vitals, Cache, CDN, Images, CSS & JavaScript / 1.9.4
BerqWP – All-In-One Optimization for Core Web Vitals, Cache, CDN, Images, CSS & JavaScript v1.9.4
4.1.16 4.1.15 4.1.14 4.1.13 4.1.12 4.1.11 4.1.10 4.0.30 4.0.29 4.0.28 4.0.27 4.0.26 4.0.24 4.0.25 4.0.23 4.0.22 4.0.21 4.0.19 4.0.18 4.0.17 4.0.16 1.9.3 1.9.4 1.9.5 1.9.6 All 170 releases
searchpro / api / get_media_ids.php

get_media_ids.php in BerqWP – All-In-One Optimization for Core Web Vitals, Cache, CDN, Images, CSS & JavaScript 1.9.4, at api/get_media_ids.php

36 lines 925 B
No matching file
Up and down to move Enter to open Esc to close
Raw Download Zip
1 <?php
2 if (!defined('ABSPATH')) exit;
3
4 $args = array(
5 'post_type' => 'attachment',
6 'post_mime_type' => 'image',
7 'post_status' => 'inherit',
8 'posts_per_page' => -1,
9 );
10
11 $attachments = get_posts($args);
12 $ids = [
13 'optimized' => [],
14 'unoptimized' => [],
15 ];
16
17 foreach ($attachments as $attachment) {
18 $file = get_attached_file($attachment->ID);
19 $file_info = pathinfo($file);
20
21 // Check if the uploaded image is in a supported format
22 $supported_formats = array('jpg', 'jpeg', 'png');
23 if (in_array(strtolower($file_info['extension']), $supported_formats)) {
24 $webp_file_original = $file_info['dirname'] . '/' . $file_info['filename'] . '.webp';
25
26 if (file_exists($webp_file_original)) {
27 $ids['optimized'][] = $attachment->ID;
28 } else {
29 $ids['unoptimized'][] = $attachment->ID;
30 }
31 }
32 }
33
34 echo json_encode($ids);
35
36 unset($attachments, $ids);