NEXT craftinamerica.org. Base setup for headless wordpress https://www.craftinamerica.org
Você não pode selecionar mais de 25 tópicos Os tópicos devem começar com uma letra ou um número, podem incluir traços ('-') e podem ter até 35 caracteres.

reformat-blocks.php 1.3KB

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