shopp_themeapi_object

filters the Object that will be the subject of a theme api call.

add_filter( 'shopp_themeapi_object', [callback] )

@param Object $Object the Object that will be the subject of a theme api call.
@param string $context the object context name

Description

filters the Object that will be the subject of a theme api call.

This filter can be used to replace the Object subject of a theme api call before the theme api call happens. This can be also be used as an alternative way to pass a user-defined Object for a custom context.

Example

Override a built-in Object

// register filter callback
// use later priority (11 or higher) to override Shopp
add_filter('shopp_themeapi_object', 'shopp_themeapi_object_fltr', 11, 2);

// create filter function
function shopp_themeapi_object_fltr( $Object, $context ) {
    // set a different Product Object
    if ( $context == 'product' ) {
        $Object = shopp_product(1); // product 1
    }

    return $Object;
}

Custom Object shopp() handling

// register filter callback
// use later priority (11 or higher) to override Shopp
add_filter('shopp_themeapi_object', 'my_themeapi_object_fltr', 11, 2);

// Set my custom object for shopp('myobject') calls
function my_themeapi_object_fltr ( $Object, $context ) {
    if ( $context == 'myobject' ) {
        $Object = new MyObject();
    }
    return $Object;
}

class MyObject {
    // my object has a tag
    // shopp('myobject', 'mytag', $options)
    function mytag ( $options ) {
        return "my tag output";
    }
}


add_filter('shopp_themeapi_myobject', 10, 4);

function myobject_tag ( $result, $options, $tag, $Object ) {
    if ( is_a( $Object, 'MyObject' ) && method_exists( $Object, $tag ) ) {
        $result = $Object->$tag( $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