shopp_themeapi_{object}_{tag}

filters specific theme api results for a particular object context and a particular tag.

add_filter( 'shopp_themeapi_{object}_{tag}', [callback] )

@param mixed $result the theme api calls
@param array $options the options array passed to the theme api call
@param Object $Object the Object subject of the theme api call

Description

filters specific theme api results for a particular object context and a particular tag.

This dynamic filter is very similar to shopp_themeapi_{object}, except that it is more specific. shopp_themeapi_{object} filters all theme api calls for a particular object context, but shopp_themeapi_{object}_{tag} filters one specific object context and one specific tag.

The object portion of the shopp_themeapi_{object}_{tag} dynamic filter is set by the string passed as the first argument to the shopp() theme api call. So in addition to the above built-in calls, you can specify your own object context name, for your own custom theme api context.

The first argument to the shopp() api call can be an Object, in which case the object context name for this filter will be set by either a public api property of your object, or by the lower-case classname of the object.

The tag portion of this dynamic filters is set by the second argument of the shopp() theme api call.

To illustrate, say you would like to filter the results of the shopp(‘customer’,’receipt’) theme api call, the shopp_themeapi_{object}_{tag} filter would be in the form of shopp_themeapi_customer_receipt.

This filter is useful for overriding the results for an existing theme api call, or for extended the theme api for your own tags on Shopp objects, or tags on custom objects.

If you only need to override all tags calls for a particular object, and not just one, you can also use the shopp_themeapi_{object} dynamic filter.

Tag name normalization

Note that the tag name is normalized by stripping hyphenation.

Example hyphenated theme api tag name:

shopp('object','tag-name-hyphenated');

Corresponding filter call:

add_filter('shopp_themeapi_object_tagnamehyphenated', 'my_fltr');

// not
// add_filter('shopp_themeapi_object_tag-name-hyphenated', 'my_fltr');

Example

// register filter callback
// add_filter('shopp_themeapi_{object}_{tag}', 'my_fltr');

// if your theme api filter needs to override the default result
// set the priority of your filter lower (11 or bigger), so that it will run *after* Shopp's
// filter to override the shopp('product','image') theme api call 
add_filter('shopp_themeapi_product_image', 'my_product_img_themeapi_fltr', 11, 3);

function my_product_img_themeapi_fltr( $result, $options, $Product ) {
    // Say I want to override the shopp('product', 'image') theme api call
    // for only Product 10, to display a random image
    if ( 10 == $Product->id ) {     
        if ( ! isset($options['src']) ) return $result;
        $i = rand(0, count($Product->images));
        $id = $Product->images[$i]->id;
        $options['id'] = $id;

        // the get- prefix in the tag is Shopp 1.2 short-hand for the return=true option
        return shopp('product', 'get-image', $options);
    }
    return $result;
}

See Also

You must be logged in to post a comment.

© Ingenesis Limited. Shopp™ is a registered trademark of Ingenesis Limited.

Skip to toolbar