VersionPress\Utils\WordPressMissingFunctions::renderShortcode PHP Метод

renderShortcode() публичный статический Метод

public static renderShortcode ( $shortcodeTag, $attributes )
    public static function renderShortcode($shortcodeTag, $attributes)
    {
        $renderedAttributes = [];
        foreach ($attributes as $attribute => $value) {
            $renderedAttributes[] = sprintf('%s="%s"', $attribute, $value);
        }
        return sprintf('[%s %s]', $shortcodeTag, join(' ', $renderedAttributes));
    }

Usage Example

 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);
     };
 }
All Usage Examples Of VersionPress\Utils\WordPressMissingFunctions::renderShortcode