private function createReplaceCallback($idProvider) { $shortcodesInfo = $this->shortcodesInfo; return function ($m) use($shortcodesInfo, $idProvider) { // allow [[foo]] syntax for escaping a tag - code adopted from WP function `do_shortcode_tag` if ($m[1] == '[' && $m[6] == ']') { return substr($m[0], 1, -1); } $shortcodeTag = $m[2]; $shortcodeInfo = $shortcodesInfo->getShortcodeInfo($shortcodeTag); $attributes = shortcode_parse_atts($m[3]); foreach ($attributes as $attribute => $value) { if (isset($shortcodeInfo[$attribute])) { $ids = explode(',', $value); $entityName = $shortcodeInfo[$attribute]; $attributes[$attribute] = join(',', array_map(function ($id) use($entityName, $idProvider) { return $idProvider($entityName, $id); }, $ids)); } } return WordPressMissingFunctions::renderShortcode($shortcodeTag, $attributes); }; }
private function createPostWithShortcode() { $author = EntityUtils::prepareUser(); self::$authorVpId = $author['vp_id']; $this->userStorage->save($author); $post = EntityUtils::preparePost(null, self::$authorVpId); self::$vpId = $post['vp_id']; $post['post_content'] = WordPressMissingFunctions::renderShortcode('gallery', ['id' => self::$vpId]); $this->storage->save($post); return [['vp_id' => self::$authorVpId, 'parent' => self::$authorVpId], ['vp_id' => self::$vpId, 'parent' => self::$vpId]]; }