RECORDGOD/wp-bridge/recordgod-bridge.php
type-two 5ad4de1d2c feat(bridge): RecordGod WP bridge plugin (WowPlatter successor) + thumb on browse/release
Thin WordPress/Woo bridge — RecordGod owns catalog/stock/pricing/shipping; the plugin is a storefront
skin + checkout adapter over /shop:
- storefront: SSR /records (browse) + /release/{id} inside the theme, with title/meta/JSON-LD MusicAlbum
- on-the-fly Woo product: /?rg_add=<sku> mints a hidden WC_Product_Simple from /shop/item (the WowPlatter
  trick — 25k catalog, only sold items become Woo products)
- shipping: WC_Shipping_Method quoting /shop/shipping/quote by cart item count (AusPost flat rate)
- orders: order_status_completed -> POST /shop/woo-order (X-Bridge-Key), idempotent, marks SKUs sold
- settings page: base URL + bridge key + store id
Backend: added thumb to /shop/browse + /shop/release so storefront pages have cover art.

Co-Authored-By: Claude Opus 4.8 <noreply@anthropic.com>
2026-06-24 01:43:30 +10:00

79 lines
3.2 KiB
PHP

<?php
/**
* Plugin Name: RecordGod Bridge
* Description: Thin bridge to RecordGod — RecordGod owns the catalog/stock/pricing/shipping; this plugin
* renders SEO storefront pages from its /shop API, mints Woo products on the fly at add-to-cart,
* injects postage, and posts completed orders back. Successor to WowPlatter.
* Version: 0.1.0
* Author: Monster Robot
* Requires Plugins: woocommerce
*/
if (!defined('ABSPATH')) exit;
define('RG_BRIDGE_VERSION', '0.1.0');
define('RG_BRIDGE_DIR', plugin_dir_path(__FILE__));
require_once RG_BRIDGE_DIR . 'includes/class-rg-api.php';
require_once RG_BRIDGE_DIR . 'includes/class-rg-cart.php';
require_once RG_BRIDGE_DIR . 'includes/class-rg-storefront.php';
require_once RG_BRIDGE_DIR . 'includes/class-rg-orders.php';
// Shipping method loads only once Woo's class exists.
add_action('woocommerce_shipping_init', function () {
require_once RG_BRIDGE_DIR . 'includes/class-rg-shipping.php';
});
add_filter('woocommerce_shipping_methods', function ($methods) {
$methods['recordgod'] = 'RG_Shipping';
return $methods;
});
// Wire the pieces.
add_action('plugins_loaded', function () {
RG_Cart::init();
RG_Storefront::init();
RG_Orders::init();
});
// --- Settings (Settings API): base URL + bridge key + store id ---------------
add_action('admin_menu', function () {
add_options_page('RecordGod Bridge', 'RecordGod Bridge', 'manage_options', 'rg-bridge', 'rg_bridge_settings_page');
});
add_action('admin_init', function () {
register_setting('rg_bridge', 'rg_base_url');
register_setting('rg_bridge', 'rg_bridge_key');
register_setting('rg_bridge', 'rg_store_id');
});
function rg_bridge_settings_page() {
?>
<div class="wrap">
<h1>RecordGod Bridge</h1>
<form method="post" action="options.php">
<?php settings_fields('rg_bridge'); ?>
<table class="form-table">
<tr><th>RecordGod base URL</th>
<td><input type="url" name="rg_base_url" class="regular-text"
value="<?php echo esc_attr(get_option('rg_base_url', 'https://recordgod.com')); ?>"
placeholder="https://recordgod.com"></td></tr>
<tr><th>Bridge key</th>
<td><input type="text" name="rg_bridge_key" class="regular-text"
value="<?php echo esc_attr(get_option('rg_bridge_key', '')); ?>">
<p class="description">Must match the <code>bridge_key</code> secret in RecordGod settings.</p></td></tr>
<tr><th>Store ID</th>
<td><input type="number" name="rg_store_id" class="small-text"
value="<?php echo esc_attr(get_option('rg_store_id', '1')); ?>"></td></tr>
</table>
<?php submit_button(); ?>
</form>
<p><a href="<?php echo esc_url(home_url('/records')); ?>">View storefront →</a></p>
</div>
<?php
}
// Storefront rewrite rules need flushing on (de)activate.
register_activation_hook(__FILE__, function () {
RG_Storefront::rewrites();
flush_rewrite_rules();
});
register_deactivation_hook(__FILE__, 'flush_rewrite_rules');