Last active
August 21, 2019 11:15
Revisions
-
tangrufus revised this gist
Aug 21, 2019 . 1 changed file with 3 additions and 2 deletions.There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters. Learn more about bidirectional Unicode charactersOriginal file line number Diff line number Diff line change @@ -15,9 +15,10 @@ $imageIds = $query->get_posts(); // Create csv file if not exists. $csvFilename = 'corrupted-wordpress-image-attachments.csv'; exec("touch $csvFilename"); $csvPath = realpath($csvFilename); WP_CLI::log("Exporting to $csvPath"); -
tangrufus revised this gist
Aug 21, 2019 . 1 changed file with 7 additions and 1 deletion.There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters. Learn more about bidirectional Unicode charactersOriginal file line number Diff line number Diff line change @@ -24,7 +24,13 @@ $fp = fopen($csvPath, 'wb'); // CSV header. fputcsv($fp, [ 'id', 'title', 'url', 'edit', 'path', ]); foreach ($imageIds as $id) { // Find local image path (non-offloaded). -
tangrufus revised this gist
Aug 21, 2019 . 1 changed file with 1 addition and 0 deletions.There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters. Learn more about bidirectional Unicode charactersOriginal file line number Diff line number Diff line change @@ -16,6 +16,7 @@ $imageIds = $query->get_posts(); $csvFilename = 'corrupted-wordpress-image-attachments.csv'; // Touch csv file. file_put_contents($csvFilename, ''); $csvPath = realpath($csvFilename); WP_CLI::log("Exporting to $csvPath"); -
tangrufus revised this gist
Aug 21, 2019 . 1 changed file with 5 additions and 3 deletions.There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters. Learn more about bidirectional Unicode charactersOriginal file line number Diff line number Diff line change @@ -15,10 +15,12 @@ $imageIds = $query->get_posts(); $csvFilename = 'corrupted-wordpress-image-attachments.csv'; file_put_contents($csvFilename, ''); $csvPath = realpath($csvFilename); WP_CLI::log("Exporting to $csvPath"); $fp = fopen($csvPath, 'wb'); // CSV header. echo "'id','title','url','edit','path'" . PHP_EOL; -
tangrufus revised this gist
Aug 21, 2019 . 1 changed file with 6 additions and 2 deletions.There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters. Learn more about bidirectional Unicode charactersOriginal file line number Diff line number Diff line change @@ -15,7 +15,10 @@ $imageIds = $query->get_posts(); $csv = realpath('corrupted-wordpress-image-attachments.csv'); WP_CLI::log("Exporting to $csv"); $fp = fopen($csv, 'wb'); // CSV header. echo "'id','title','url','edit','path'" . PHP_EOL; @@ -54,4 +57,5 @@ } fclose($fp); WP_CLI::success('Done!'); -
tangrufus revised this gist
Aug 21, 2019 . 1 changed file with 13 additions and 2 deletions.There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters. Learn more about bidirectional Unicode charactersOriginal file line number Diff line number Diff line change @@ -15,10 +15,12 @@ $imageIds = $query->get_posts(); $fp = fopen('corrupted-wordpress-image-attachments.csv', 'wb'); // CSV header. echo "'id','title','url','edit','path'" . PHP_EOL; foreach ($imageIds as $id) { // Find local image path (non-offloaded). $path = get_attached_file($id, true); @@ -42,5 +44,14 @@ $url = str_replace(WP_CONTENT_DIR, WP_CONTENT_URL, $path); $edit = admin_url("post.php?post=$id&action=edit"); fputcsv($fp, [ $id, $title, $url, $edit, $path, ]); } fclose($fp); echo 'Done!'; -
tangrufus created this gist
Aug 21, 2019 .There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters. Learn more about bidirectional Unicode charactersOriginal file line number Diff line number Diff line change @@ -0,0 +1,46 @@ <?php $mineTypes = get_allowed_mime_types(); $imageMineTypes = array_filter($mineTypes, function (string $type): bool { return '' !== 'image/' && 0 === strpos($type, 'image/'); }); $query = new WP_Query([ 'fields' => 'ids', 'post_type' => 'attachment', 'post_status' => 'inherit', 'post_mime_type' => $imageMineTypes, 'posts_per_page' => -1, ]); $imageIds = $query->get_posts(); // CSV header. echo "'id','title','url','edit','path'" . PHP_EOL; foreach($imageIds as $id) { // Find local image path (non-offloaded). $path = get_attached_file($id, true); if (! file_exists($path)) { continue; } $output = null; $statusCode = null; // Requires ImageMagick. // See: https://stackoverflow.com/a/46805566 exec("identify -regard-warnings -verbose ${path} > /dev/null 2>&1", $output, $statusCode); if (0 === $statusCode) { continue; } $title = get_the_title($id); // Find non-offloaded image URL. $url = str_replace(WP_CONTENT_DIR, WP_CONTENT_URL, $path); $edit = admin_url("post.php?post=$id&action=edit"); echo "'$id','$title','$url','$edit','$path'" . PHP_EOL; }