Task-oriented recipes: Display Data with Shortcodes.
Syntax
Three names register the same handler with identical attributes:
| Shortcode | Status |
|---|---|
HuxxConnect: "api_id" attribute is required. | Preferred short form (mirrors huxx_api()) |
HuxxConnect: "api_id" attribute is required. | Long form (mirrors huxx_connect_api()) |
HuxxConnect: "api_id" attribute is required. | Legacy alias |
Source: src/Frontend/Shortcodes.php (all attributes verified against shortcode_atts() in render()).
Attributes
| Name | Type | Default | Since | Description |
|---|---|---|---|---|
api_id | string | "" | 1.1.0 | Required. The API slug id. |
endpoint_id | string | "" | 1.1.0 | Required. The endpoint slug id. |
api | string | "" | 0.1.0 | Fallback alias for api_id; used only when api_id is empty. |
endpoint | string | "" | 0.1.0 | Fallback alias for endpoint_id; used only when endpoint_id is empty. |
debug | string | "false" | 0.1.0 | "true" renders error details on failure — only for users with the manage_huxx_connect capability (see Output rules). Any other value is treated as false. |
endpoint_variables | string | "" | 0.1.0 | Path variable values. Indexed: "123,456" maps by position. Named: "post_id=123,cid=5" maps by name. Auto-detected: any = in any segment switches to named mode. |
query_variables | string | "" | 0.1.0 | key=value pairs, comma-separated. Merged over saved query parameters; runtime wins. |
body_variables | string | "" | 0.1.0 | key=value pairs, comma-separated. Colon namespacing sets multipart file metadata: "avatar:filename=a.jpg,avatar:is_file=true". A flat entry for the same field becomes its value property. |
body_json | string | "" | 0.5.0 | A complete JSON object for the request body. Takes precedence over body_variables. Ignored if it does not decode to an array/object. |
keys | string | "" | 0.1.0 | Extraction path(s) applied to array responses. The [] wildcard cannot be used here — WordPress ends the shortcode at the first ]; use huxx_api() in PHP for wildcard paths. See keys Syntax Reference. |
format | string | "" | 0.1.0 | "no_display": execute the request, render nothing. With Pro: "html" and "number_format(N)" (see below). Any other value falls through to default rendering. |
Parsing notes:
endpoint_variables,query_variables, andbody_variablessplit pairs on,— values cannot contain commas. Keys cannot contain=; values may (the split on=keeps the remainder intact).- Pairs without an
=inquery_variables/body_variablesare dropped. endpoint_variables,query_variables,body_variables,body_json, andkeyspass throughsanitize_text_field()before parsing; the other attributes are not sanitized by the handler.
One example per attribute
| Attribute | Example |
|---|---|
api_id / endpoint_id | |
api / endpoint | |
debug | |
endpoint_variables | |
query_variables | |
body_variables | |
body_json | |
keys | |
format | |
Pro formatter attributes
Pro passthrough attributes — declared by the free shortcode, acted on by HuxxConnect Pro’s huxx_connect/shortcode/format_output filter (Pro source: src/Features/HtmlFormatter/). Without Pro active they have no effect. html_*/img_* apply when format="html" and the result is an array.
| Name | Type | Default | Since | Description |
|---|---|---|---|---|
html_tag | string | "" | 1.0.0 | Wrapper element per value: div, li, or span (whitelist; empty or anything else renders as div). li values get an outer <ul>; others an outer <div>. Both outers carry class="huxx-connect-html huxx-connect-outer-wrap". |
html_labels | string | "" | 1.0.0 | "true", "1", or "yes" renders each string key as a <span class="huxx-connect-label"> label, title-cased (user_name → User Name). Off by default; numeric keys never get labels. |
html_url | string | "" | 1.0.0 | Dot path to the URL value used for link rendering (commas are converted to dots for WPGetAPI-style paths). |
html_to_link | string | "" | 1.0.0 | Key whose value is wrapped in <a> using the html_url value. |
img_key | string | "" | 1.0.0 | Key whose value is rendered as an <img>. |
img_prepend | string | "" | 1.0.0 | URL prefix prepended to img_key values (for APIs returning relative image paths). |
img_link | string | "" | 1.0.0 | Dot path to the URL for wrapping the <img> in <a> (commas converted to dots). |
format values handled by Pro:
| Value | Effect |
|---|---|
html | Array result rendered as nested HTML per the attributes above. |
number_format(N) | Numeric result rendered with N decimal places (e.g. number_format(2)). |
Example — product_detail is a GET endpoint with the path /products/{0}:
Output (whitespace added for readability):
<ul class="huxx-connect-html huxx-connect-outer-wrap">
<li class="huxx-connect-title"><span class="huxx-connect-label">Title</span> Essence Mascara Lash Princess</li>
<li class="huxx-connect-price"><span class="huxx-connect-label">Price</span> 9.99</li>
</ul>
Output rules
Applied in order after the request completes:
- Missing ids — the shortcode returns the literal text
HuxxConnect: "api_id" attribute is required.orHuxxConnect: "endpoint_id" attribute is required. format="no_display"— request executes; output is an empty string.- Error,
debug="false"— empty string. - Error,
debug="true"— anErrorResponserenders as pretty-printed JSON in<pre class="huxx-connect-error">only for users with themanage_huxx_connectcapability; every other visitor gets an empty string. Exception: when the HTTP request itself fails, the executor’s debug mode converts theErrorResponseto an array before the shortcode sees it, so it renders through rule 6 instead — publicly. Do not leavedebug="true"on published pages. keysextraction — applied only when the response is an array.- Array result — pretty-printed JSON in
<pre class="huxx-connect-response">. - String result — HTML-escaped in
<pre class="huxx-connect-response">. Thehuxx_connect/shortcode/allow_raw_htmlfilter (defaultfalse) switches towp_kses_post()sanitized output instead. - Scalar/null result from
keys— JSON-encoded in the same<pre>block (so anullmiss is visible). - Anything else — empty string.
Filters
All receive the parsed attribute array $a. Defined in src/Frontend/Shortcodes.php:
| Filter | Signature | Purpose |
|---|---|---|
huxx_connect/shortcode/attributes | `( array $a, array | string $atts ) : array` |
huxx_connect/shortcode/can_execute | ( bool $can_execute, array $a ) : bool | Return false to suppress execution (e.g. logged-in visitors only). Default true. |
huxx_connect/shortcode/format_output | ( ?string $output, mixed $result, array $a ) : ?string | Return a non-null string to replace default rendering (used by Pro’s formatter). |
huxx_connect/shortcode/allow_raw_html | ( bool $allow_raw, array $a ) : bool | Allow sanitized HTML for string results. Default false. |
Request-lifecycle hooks fired during execution are documented separately: huxx_connect/request/before, huxx_connect/request/args, huxx_connect/request/after.
Notes
- Requests triggered by any of the three shortcode names are tagged
shortcodein the request log. - The
shortcode_atts()filter hook name isshortcode_atts_huxx_connectfor all three registered names.