Skip to Main

Task-oriented recipes: Display Data with Shortcodes.

Syntax


Three names register the same handler with identical attributes:

ShortcodeStatus
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

NameTypeDefaultSinceDescription
api_idstring""1.1.0Required. The API slug id.
endpoint_idstring""1.1.0Required. The endpoint slug id.
apistring""0.1.0Fallback alias for api_id; used only when api_id is empty.
endpointstring""0.1.0Fallback alias for endpoint_id; used only when endpoint_id is empty.
debugstring"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_variablesstring""0.1.0Path 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_variablesstring""0.1.0key=value pairs, comma-separated. Merged over saved query parameters; runtime wins.
body_variablesstring""0.1.0key=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_jsonstring""0.5.0A complete JSON object for the request body. Takes precedence over body_variables. Ignored if it does not decode to an array/object.
keysstring""0.1.0Extraction 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.
formatstring""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, and body_variables split pairs on , — values cannot contain commas. Keys cannot contain =; values may (the split on = keeps the remainder intact).
  • Pairs without an = in query_variables/body_variables are dropped.
  • endpoint_variables, query_variables, body_variables, body_json, and keys pass through sanitize_text_field() before parsing; the other attributes are not sanitized by the handler.

One example per attribute

AttributeExample
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.

NameTypeDefaultSinceDescription
html_tagstring""1.0.0Wrapper 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_labelsstring""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_urlstring""1.0.0Dot path to the URL value used for link rendering (commas are converted to dots for WPGetAPI-style paths).
html_to_linkstring""1.0.0Key whose value is wrapped in <a> using the html_url value.
img_keystring""1.0.0Key whose value is rendered as an <img>.
img_prependstring""1.0.0URL prefix prepended to img_key values (for APIs returning relative image paths).
img_linkstring""1.0.0Dot path to the URL for wrapping the <img> in <a> (commas converted to dots).

format values handled by Pro:

ValueEffect
htmlArray 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:

  1. Missing ids — the shortcode returns the literal text HuxxConnect: "api_id" attribute is required. or HuxxConnect: "endpoint_id" attribute is required.
  2. format="no_display" — request executes; output is an empty string.
  3. Error, debug="false" — empty string.
  4. Error, debug="true" — an ErrorResponse renders as pretty-printed JSON in <pre class="huxx-connect-error"> only for users with the manage_huxx_connect capability; every other visitor gets an empty string. Exception: when the HTTP request itself fails, the executor’s debug mode converts the ErrorResponse to an array before the shortcode sees it, so it renders through rule 6 instead — publicly. Do not leave debug="true" on published pages.
  5. keys extraction — applied only when the response is an array.
  6. Array result — pretty-printed JSON in <pre class="huxx-connect-response">.
  7. String result — HTML-escaped in <pre class="huxx-connect-response">. The huxx_connect/shortcode/allow_raw_html filter (default false) switches to wp_kses_post() sanitized output instead.
  8. Scalar/null result from keys — JSON-encoded in the same <pre> block (so a null miss is visible).
  9. Anything else — empty string.

Filters

All receive the parsed attribute array $a. Defined in src/Frontend/Shortcodes.php:

FilterSignaturePurpose
huxx_connect/shortcode/attributes`( array $a, arraystring $atts ) : array`
huxx_connect/shortcode/can_execute( bool $can_execute, array $a ) : boolReturn false to suppress execution (e.g. logged-in visitors only). Default true.
huxx_connect/shortcode/format_output( ?string $output, mixed $result, array $a ) : ?stringReturn a non-null string to replace default rendering (used by Pro’s formatter).
huxx_connect/shortcode/allow_raw_html( bool $allow_raw, array $a ) : boolAllow 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 shortcode in the request log.
  • The shortcode_atts() filter hook name is shortcode_atts_huxx_connect for all three registered names.