NEXT craftinamerica.org. Base setup for headless wordpress https://www.craftinamerica.org
Du kan inte välja fler än 25 ämnen Ämnen måste starta med en bokstav eller siffra, kan innehålla bindestreck ('-') och vara max 35 tecken långa.

reformat-blocks.php 1.3KB

123456789101112131415161718192021222324252627282930313233343536
  1. <?php
  2. function get_ids_from_gallery_block($blocks){
  3. $parsed_blocks = array();
  4. foreach ($blocks as $block) {
  5. if($block[blockName] === "core/gallery") {
  6. array_push($parsed_blocks, $block[attrs]);
  7. } elseif ($block[blockName] === "core/image") {
  8. $ids = [];
  9. $galleryFormat = [];
  10. array_push($ids, $block[attrs][id]);
  11. $galleryFormat[ids] = $ids;
  12. $galleryFormat[columns] = 1;
  13. $galleryFormat[linkTo] = 'none';
  14. array_push($parsed_blocks, $galleryFormat);
  15. }
  16. }
  17. return $parsed_blocks;
  18. }
  19. function get_images_from_content($content) {
  20. $parse_images = array();
  21. $dom = new DOMDocument();
  22. @ $dom->loadHTML($content);
  23. $images = $dom->getElementsByTagName('img');
  24. foreach ($images as $image) {
  25. if($image->getAttribute('data-id')) {
  26. $parse_images[$image->getAttribute('data-id')] = $image->getAttribute('src');
  27. } else {
  28. $class_pieces = explode("-", $image->getAttribute('class'));
  29. $parse_images[end($class_pieces)] = $image->getAttribute('src');
  30. }
  31. }
  32. return $parse_images;
  33. }
  34. ?>