← Back
Editing: class-launch-integration.php
<?php namespace WPaaS; if ( ! defined( 'ABSPATH' ) ) { exit; } /** * Feeds unified-plan publish decisions into the bundled godaddy-launch plugin. * * On the new "unified hosting" plan the Coming Soon gate is driven solely by the * GD_UNIFIED_PUBLISHED gd-config constant instead of the gdl_site_published WP * option, and godaddy-launch's launch action redirects the customer to the Airo * builder to publish (publishing is owned by Airo, not WordPress). Both behaviors * are exposed to godaddy-launch through filters so untargeted plans are completely * unaffected. */ final class Launch_Integration { /** * Option holding the launch state the caches were last invalidated for. * * @var string */ const MIRROR_OPTION = 'wpaas_unified_published_mirror'; /** * Class constructor. */ public function __construct() { // Drive the Coming Soon gate off GD_UNIFIED_PUBLISHED on unified plans only. add_filter( 'gdl_site_published_state', [ $this, 'filter_site_published_state' ] ); // Tell godaddy-launch to run in "unified" mode (redirect the launch action to // Airo, skip the auto-publish safety net and the NUX publish milestone). add_filter( 'gdl_uses_unified_publish', [ $this, 'filter_uses_unified_publish' ] ); // Give godaddy-launch the Airo builder deep link its launch action redirects // to: publishing on unified plans happens in Airo, not in WordPress. add_filter( 'gdl_unified_publish_url', [ $this, 'filter_unified_publish_url' ] ); add_action( 'init', [ $this, 'reconcile_cache_with_launch_state' ] ); } /** * Ban the page cache when the delivered launch state no longer matches the one * the caches were built against. * * Nothing else invalidates it on these plans: the gate is a constant in a file, * so the `gdl_site_published` write that used to trigger a ban never happens and * the constant changing under a running site is invisible to WordPress. The * mirror option is what makes this idempotent -- the ban happens on the first * request after a change, not on every request while the state holds. * * @return void */ public function reconcile_cache_with_launch_state() { if ( ! Plugin::is_unified_plan() ) { return; } $current = Plugin::is_unified_published() ? '1' : '0'; $mirror = get_option( self::MIRROR_OPTION, null ); if ( $current === $mirror ) { return; } update_option( self::MIRROR_OPTION, $current ); // A site seeing this for the first time has nothing to compare against, so a // ban would only evict a cache that already agrees with the constant. if ( null === $mirror ) { return; } if ( isset( $GLOBALS['wpaas_cache_class'] ) ) { // After the option write, so the generic option-change handler cannot // downgrade this to the no-flush variant. $GLOBALS['wpaas_cache_class']->do_ban(); } } /** * Override the published-state read inside godaddy-launch's is_restricted() * for unified plans. Returns a truthy timestamp (mirroring the option's * true-as-timestamp semantics) when published, or false for Coming Soon. * * @param mixed $published The raw gdl_site_published option value. * * @return mixed */ public function filter_site_published_state( $published ) { if ( ! Plugin::is_unified_plan() ) { // Untargeted plans: unchanged. return $published; } return Plugin::is_unified_published() ? time() : false; } /** * Tell godaddy-launch whether this site uses the unified (platform-owned) * publish flow. * * @param bool $val Incoming value from other filter callbacks. * * @return bool */ public function filter_uses_unified_publish( $val ) { return Plugin::is_unified_plan() ? true : $val; } /** * Give godaddy-launch the Airo builder deep link its launch action redirects to. * * On unified plans the "Launch My Site" action does not publish from WordPress; it * sends the customer to the Airo builder with the publish flow open, where the * publish (and its per-plan limit) is owned. Untargeted plans are left untouched. * * @param mixed $val Incoming value from other filter callbacks. * * @return mixed The deep link on unified plans, otherwise $val untouched. */ public function filter_unified_publish_url( $val ) { if ( ! Plugin::is_unified_plan() ) { return $val; } return self::airo_builder_publish_url(); } /** * Build the Airo builder "open publish" deep link for this site. * * The app id is the one the platform renders into gd-config as GD_ACCOUNT_UID; the * host is environment-specific. Returns an empty string when the app id is unknown, * so the launch action has nothing to redirect to rather than a broken link. * * @return string */ public static function airo_builder_publish_url() { $app_id = defined( 'GD_ACCOUNT_UID' ) ? (string) GD_ACCOUNT_UID : ''; if ( '' === $app_id ) { return ''; } $host = Plugin::is_env( [ 'dev', 'test', 'myh.test' ] ) ? 'https://airo-builder.test-godaddy.com' : 'https://airo-builder.godaddy.com'; return sprintf( '%s/develop/%s?openPublish=true', $host, rawurlencode( $app_id ) ); } }
Save File
Cancel