Developer hooks
PrintBlob's PHP filters and actions, and the designer's JavaScript filters on wp.hooks, for a plugin of your own: add a tool, a view or a section to the designer, price a side, lay its print in the cart's picture, and add to the order screen, each with its arguments.
Updated , for PrintBlob 1.8.6.
PrintBlob is extended from a plugin of your own, never by editing its files: an update replaces them. Its PHP hooks are WordPress filters and actions. The designer’s are JavaScript filters on wp.hooks, WordPress’s own hooks script, which the designer’s script loads, so a script that depends on wp-hooks adds to the same filters. PrintBlob Pro adds its 3D view, emoji, templates, clipart, quantity breaks and names and numbers through these same hooks.
The hooks have no version of their own: each passes what the PrintBlob you run passes. Read the changelog and test your plugin before you update a shop. To restyle the designer, see Restyle the designer, which covers the printblob_designer_styles filter.
Add to the designer
What another plugin adds to the designer is listed twice: in its configuration, on the PHP filter printblob_designer_config, and in the browser, on a JavaScript filter that registers what draws it. Both are needed; an addition listed in one and not the other is not shown.
| Configuration key | Each entry | Registered on | Registration |
|---|---|---|---|
tools |
key, label: a button beside Upload image and Add text |
printblob.designer.tools |
{ [key]: { Panel, Controls?, available? } } |
views |
key, label, initial (open the designer on it), badge: a button beside the sides |
printblob.designer.views |
{ [key]: { Component, available? } } |
sections |
key, slot: panel (before the price) or buy (after its breakdown) |
printblob.designer.sections |
{ [key]: { Component, Overlay?, available? } } |
available(), where given, answers whether the addition is offered in this browser. Each registered filter is run on its own: one that throws, answers something other than an object, or registers a part that is not a component is left out with one error in the browser console naming it, and the designer starts with the rest. Your script may load before or after the designer’s; the designer follows the filter as it changes.
What the designer hands each part:
- A tool’s Panel:
config(the configuration, your own keys included),addImage( src, { vector, asset, data } ), which adds an SVG, an image URL or a data URL to the side being edited, placed in its print area, saved with the design and printed in its print files (vector: truefor SVG, which has no resolution to warn about),close(),designed(whether the design has anything on it) andstartFrom( design ). A tool’s Controls show beside the controls of an image the tool added, withconfig,objectandchanged(). - A view’s Component:
config,mockups(each side’s photo),colorHex(the colour chosen),side,renderSide( key, width )(a promise of a side’s print area as the editor draws it, as a canvaswidthpixels wide) andrevisions(how many times each side’s design has changed, so the view draws a side again when its number grows). - A section’s Component:
config,side,quantity,unitPrice( quantity )(the lowest and highest price of one at that quantity, as[ low, high ]),disabled,stateandsetState( state )(its own state, kept with the design’s draft),setOrder( order )andshowSide( key ). Its Overlay is drawn over the product, withconfig,sideandstate. The actionprintblob_designer_section,( string $key, array $config, WC_Product $product ), draws a section’s first frame on the server, at its final size, so nothing moves when the designer starts.
Example: a tool that adds your shop’s logo
In your plugin’s PHP, list the tool and load its script where the designer is on the page:
add_filter(
'printblob_designer_config',
function ( array $config, WC_Product $product ): array {
$config['tools'][] = array(
'key' => 'shop-logo',
'label' => __( 'Our logo', 'my-plugin' ),
);
$config['myShopLogo'] = plugins_url( 'logo.svg', __FILE__ );
return $config;
},
10,
2
);
add_filter(
'render_block_printblob/designer',
function ( string $html ): string {
if ( '' !== $html ) {
wp_enqueue_script( 'my-plugin-logo-tool', plugins_url( 'logo-tool.js', __FILE__ ), array( 'wp-hooks', 'wp-element' ), '1.0.0', true );
}
return $html;
}
);
And logo-tool.js registers its panel:
( function ( hooks, element ) {
function LogoPanel( { config, addImage } ) {
return element.createElement(
'button',
{ type: 'button', onClick: () => addImage( config.myShopLogo, { vector: true } ) },
'Add our logo'
);
}
hooks.addFilter( 'printblob.designer.tools', 'my-plugin/shop-logo', ( tools ) => ( {
...tools,
'shop-logo': { Panel: LogoPanel },
} ) );
} )( window.wp.hooks, window.wp.element );
The panel is drawn inside the designer’s shadow root, where your page’s CSS does not reach: give its stylesheet on printblob_designer_styles (Restyle the designer). From PrintBlob 1.8.2, that one PHP filter styles the first frame and the running designer alike; a script that builds its rules as a CSSStyleSheet can also add it to the designer’s root on printblob.designer.styles, which takes and answers a list of sheets.
Prices
printblob_side_price (filter) is a side’s print price, in the cart and wherever PrintBlob prices a side: ( float $price, WC_Product $product, string $side, int $quantity ), where $side is a side’s key, or a print zone’s address on a side with zones, and $quantity is how many of the design, 1 or more. The designer asks printblob.designer.sidePrice the same, ( price, side, quantity, config ), so its prices match the cart’s: answer both alike. There side is the side itself, an object whose key is what PHP’s $side is: the side’s key, or the zone’s address.
printblob_cart_item_sides(filter): the sides a designed cart item is printed on and charged for,( string[] $sides, array $cart_item ). A side the product does not offer is left out whatever you answer.printblob_shown_priceis one to call, not to hook:apply_filters( 'printblob_shown_price', $price, $product )gives a price beside the product’s as your shop shows prices, with or without tax, as PrintBlob shows its print prices.
Sides and zones
printblob_side_label(filter): a side’s name, as customers and shop managers read it,( string $label, string $side ).printblob_side_defaults(filter): the print area (fractions of the photo:x,y,w,h) and print size in centimetres (print_cm:w,h) a side starts with,( array $defaults, string $side ).printblob_side_zones(filter): whether a side’s print zones are offered on a product,( bool $zoned, string $side, WC_Product $product ); false sells the side as its first zone. The designer asksprintblob.designer.sideZonesthe same,( offered, side, config ), wheresideis the side itself, with itskeyandzones, for a page whose configuration a cache kept from before: answer both alike.
The cart’s picture
printblob.designer.printPlacement lays a side’s print on its photo in the cart’s picture, and in every picture made from it, where it does not lie flat in its print area: ( placement, side, mockup, config ). Answer null to leave it flat, or { bounds, designAt }: bounds is the part of the photo the print covers, as fractions of its width and height (x, y, w, h), and designAt( x, y ) gives the point of the design (0 to 1 across and down) that the photo’s point shows. The stage keeps the flat print, so its handles stay on it, and the print file is the design alone. PrintBlob Pro wraps a mug’s or a cap’s print round it this way.
wp.hooks.addFilter( 'printblob.designer.printPlacement', 'my-plugin/rounded', ( placement, side, mockup, config ) => {
if ( placement || side.key !== 'front' || ! config.myRoundedProduct ) {
return placement;
}
const x = side.area.left / side.stage.width;
const y = side.area.top / side.stage.height;
const w = side.area.width / side.stage.width;
const h = side.area.height / side.stage.height;
const half = Math.sin( Math.PI / 4 );
return {
bounds: { x, y, w, h },
designAt: ( px, py ) => ( {
x: Math.asin( ( ( 2 * ( px - x ) ) / w - 1 ) * half ) / ( Math.PI / 2 ) + 0.5,
y: ( py - y ) / h,
} ),
};
} );
This one shows the front’s print round a quarter of a cylinder, its edges drawn closer together, on a product whose configuration sets myRoundedProduct (on printblob_designer_config).
Designs and orders
printblob_design_saved(filter): whether a design just saved is kept,( true|WP_Error $kept, int $post_id, WP_REST_Request $request, WC_Product $product ). Store what your part of the designer sent with the save and answertrue, or aWP_Error, and the design is deleted with everything stored for it.printblob_delete_design(action): fires before a design is deleted, its data still there, so you delete what you stored for it,( int $design_id ).printblob_order_item_design(action): fires on the order screen after a designed item’s previews and print file links,( WC_Order_Item_Product $item, int $design_id ).printblob_order_design_links(filter): links printed under a designed side on the order screen, or under each print zone, after its print files,( string[] $links, int $design_id, string $side, int $item_id ), where$sideis the zone’s address on a side with zones. Each link is anawithhref,downloadandclass, holding aspanicon withclassandaria-hidden; other markup is taken out.printblob_design_save_limits(filter): how many designs may be saved an hour,( array $limits ), withsession(per shopper),ip(per address) andshop(for a server that serves many shops; one WordPress site is one shop).
The admin and the page
-
printblob_admin_menu(action): fires after PrintBlob’s menu, its Overview and Settings are added, for your items under it,( string $parent_slug ):add_action( 'printblob_admin_menu', function ( string $parent_slug ): void { add_submenu_page( $parent_slug, __( 'Print partners', 'my-plugin' ), __( 'Print partners', 'my-plugin' ), 'manage_woocommerce', 'my-plugin-partners', 'my_plugin_partners_page' ); } ); -
printblob_notice_pages(filter): the pages under PrintBlob’s menu, by menu slug, that show its first steps and review request below their heading,( string[] $pages ). -
printblob_product_panel(action): fires at the end of the product’s PrintBlob designer tab, for your settings of the designer,( WC_Product|null $product_object ). -
printblob_designer_frame_declarative(filter): whether the designer’s first frame is printed as a declarative shadow root,( bool $declarative ): true for a page the browser parses, false for a REST or admin-ajax response whose HTML a script puts in a page, such as a page builder’s editor or a quick view.
PrintBlob Pro’s own settings, licence and features have hooks of their own, between PrintBlob Pro and PrintBlob; they are not listed here. To ask for a hook these do not cover, see Support.