Create Gutenberg block for the [camptix] shortcode#1683
Conversation
Adds a wordcamp/camptix block that provides a visual editor interface for the CampTix ticket purchase form with configurable options: - Select specific tickets to display - Set max tickets per order (1-10) - Auto-apply a coupon code on page load - Customize "No tickets available" and "Event closed" messages The block uses server-side rendering via the existing shortcode pipeline. Block attributes are parsed during template_redirect() and applied to the CampTix rendering flow. The shortcode continues to work unchanged for backward compatibility. Closes WordPress#1675 Co-Authored-By: Claude Opus 4.6 (1M context) <noreply@anthropic.com>
Co-Authored-By: Claude Opus 4.6 (1M context) <noreply@anthropic.com>
form_start() returns HTML via ob_get_contents() internally, it does not echo directly. Co-Authored-By: Claude Opus 4.6 (1M context) <noreply@anthropic.com>
Co-Authored-By: Claude Opus 4.6 (1M context) <noreply@anthropic.com>
Co-Authored-By: Claude Opus 4.6 (1M context) <noreply@anthropic.com>
Pass formattedPrice from PHP using CampTix append_currency() which respects the configured currency and locale settings. Co-Authored-By: Claude Opus 4.6 (1M context) <noreply@anthropic.com>
- showRemainingTickets (boolean, default true): toggle the "Remaining" column in the ticket table - showCouponField (auto/show/hide, default auto): control coupon input visibility. "auto" hides when no valid coupons exist on the site. Adds camptix_have_coupons filter to have_coupons() method. - showSoldOut (boolean, default false): show sold-out tickets with a "Sold out" label instead of hiding them All three settings are exposed in the block sidebar under Settings, with live preview updates in the editor. Co-Authored-By: Claude Opus 4.6 (1M context) <noreply@anthropic.com>
Replace the two IN (SELECT ...) subqueries with a single LEFT JOIN on the parent post, making the SQL more readable and efficient. Co-Authored-By: Claude Opus 4.6 (1M context) <noreply@anthropic.com>
…bqueries" This reverts commit cbd76ef.
There was a problem hiding this comment.
Pull request overview
Adds a new wordcamp/camptix Gutenberg block to provide a visual editor interface for the CampTix ticket purchase form, while keeping the existing [camptix] shortcode flow for rendering/purchase.
Changes:
- Integrates block attribute parsing into CampTix’s
template_redirect()flow and applies attributes to ticket/coupon/visibility behavior. - Registers a new
wordcamp/camptixblock (metadata + controller) and editor UI (Inspector controls + preview styles). - Adds PHPUnit coverage for key block behaviors (attribute parsing, messages, max quantity, coupon injection).
Reviewed changes
Copilot reviewed 9 out of 9 changed files in this pull request and generated 8 comments.
Show a summary per file
| File | Description |
|---|---|
| public_html/wp-content/plugins/camptix/camptix.php | Adds block attribute support in template_redirect()/form_start() and introduces camptix_have_coupons filter. |
| public_html/wp-content/plugins/camptix/tests/test-camptix-block.php | New tests covering block-related behavior and some compatibility checks. |
| public_html/wp-content/mu-plugins/blocks/blocks.php | Loads the new Camptix block controller when CampTix is available. |
| public_html/wp-content/mu-plugins/blocks/source/blocks/index.js | Registers the new Camptix block module in the JS bundle. |
| public_html/wp-content/mu-plugins/blocks/source/blocks/camptix/index.js | Block module entry exporting NAME/SETTINGS. |
| public_html/wp-content/mu-plugins/blocks/source/blocks/camptix/edit.js | Editor UI controls and a static preview table for configured settings. |
| public_html/wp-content/mu-plugins/blocks/source/blocks/camptix/edit.scss | Editor-only styling for the preview table and coupon notice. |
| public_html/wp-content/mu-plugins/blocks/source/blocks/camptix/controller.php | Registers the dynamic block, renders via shortcode pipeline, and injects editor script data (tickets + coupon existence). |
| public_html/wp-content/mu-plugins/blocks/source/blocks/camptix/block.json | Block metadata and attribute schema (including supports.multiple=false). |
💡 Add Copilot custom instructions for smarter, more guided reviews. Learn how to get started.
There was a problem hiding this comment.
Pull request overview
Copilot reviewed 12 out of 12 changed files in this pull request and generated 4 comments.
💡 Add Copilot custom instructions for smarter, more guided reviews. Learn how to get started.
There was a problem hiding this comment.
Pull request overview
Copilot reviewed 12 out of 12 changed files in this pull request and generated 3 comments.
💡 Add Copilot custom instructions for smarter, more guided reviews. Learn how to get started.
…675-camptix-block
- Drop the dead-code optimization in the block render() that reached for $camptix->shortcode_contents (protected — empty() returned true silently, so the cache-skip branch never fired and the shortcode ran twice). do_shortcode( '[camptix]' ) already returns the cached contents via shortcode_callback(), so the optimization was redundant. - Rewrite test_auto_coupon_injection and test_manual_coupon_overrides_auto_coupon so they actually exercise CampTix_Plugin::template_redirect() against a page containing the block, instead of re-implementing the auto-coupon logic inline (which left the production code path untested). Co-Authored-By: Claude Opus 4.7 (1M context) <noreply@anthropic.com>
|
Addressed the rest of the review feedback in This commit
Already addressed in earlier commits on this branch
Deliberate non-change
|
Calling template_redirect() in the coupon tests reaches the get_coupon_by_code() path which still uses get_page_by_title() (deprecated in WP 6.2). Match the existing pattern in test-camptix-admin.php and declare the expected deprecation on these tests so the WP test framework no longer treats it as an unexpected notice. Co-Authored-By: Claude Opus 4.7 (1M context) <noreply@anthropic.com>
When the editor opted into a specific ticket selection, an "all values invalid" outcome (e.g. every referenced ticket has been deleted) now narrows the tickets list to zero rather than silently falling back to showing every ticket. Less surprising than appearing to recover. Co-Authored-By: Claude Opus 4.7 (1M context) <noreply@anthropic.com>
… it. The filter used to default to `true` (hide sold-out), which forced every WordCamp site to register a `__return_false` override in camptix-tweaks just to get the project-wide "show sold-out tickets" behavior. The Tickets block then had to opt back in with another `__return_false` and out with `__return_true`, and the block UI default (showSoldOut: false) silently disagreed with the actual frontend default. Flip the input passed to apply_filters() so the new default is `false` (show sold-out), drop the redundant `__return_false` override in camptix-tweaks, and switch the block default to `showSoldOut: true`. The block now only needs to register a single `__return_true` when the editor opts in to hiding sold-out tickets. Tests cover both "no attribute, filter stays at default false" and "showSoldOut: false flips it to true". Co-Authored-By: Claude Opus 4.7 (1M context) <noreply@anthropic.com>
Now that camptix_hide_empty_tickets defaults to false (show sold-out tickets) and there are no project-wide overrides, the block does not need its own per-instance toggle. Remove the attribute from block.json, the toggle and destructured variable from edit.js, the filter wiring in template_redirect(), and the showSoldOut-specific tests. Co-Authored-By: Claude Opus 4.7 (1M context) <noreply@anthropic.com>
The shortcode search returns a numerically-indexed array from get_posts(). Assigning the block search results back into it with `$posts[ $post->ID ] = $post` could overwrite real entries when a block page ID happened to match a low numeric index (any of 0-49, since posts_per_page is 50). Build the merged set as an ID-keyed array from both result lists so neither side can clobber the other. Co-Authored-By: Claude Opus 4.7 (1M context) <noreply@anthropic.com>
|
|
||
| if ( | ||
| apply_filters( 'camptix_hide_empty_tickets', true ) && | ||
| apply_filters( 'camptix_hide_empty_tickets', false ) && |
There was a problem hiding this comment.
This is intentional; A filter on WordCamp was forcing this to false, this PR has removed that filter and set this to false
Adds a
wordcamp/camptixGutenberg block that provides a visual editor interface for the CampTix ticket purchase form. This replaces the need to use the[camptix]shortcode directly while offering configurable options that were previously hidden or unavailable.Features
How it works
post_contentduringtemplate_redirect()and applied to the CampTix rendering flow[camptix]shortcode continues to work unchanged for backward compatibility"multiple": false), matching the shortcode constraintcamptix_have_couponsfilter tohave_coupons()for coupon field controlappend_currency()for proper locale supportcamptix_hide_empty_ticketsfilter default tofalse(show sold-out tickets) so the WordCamp.org behavior is the upstream default, removing the now-redundant__return_falseoverride incamptix-tweaksCloses #1675
Test plan
[camptix]shortcode on a different page — verify unchanged behavior🤖 Generated with Claude Code