register(); ( new OrderCTRL_Bridge_SSO() )->register(); ( new OrderCTRL_Bridge_Protection() )->register(); ( new OrderCTRL_Bridge_Blocks() )->register(); if ( is_admin() ) { ( new OrderCTRL_Bridge_Admin() )->register(); } add_filter( 'http_request_host_is_external', array( __CLASS__, 'allow_local_app_host' ), 10, 3 ); } /** * On local or development sites the OrderCtrl app may run on a local host (e.g. *.test), which * wp_safe_remote_*() rejects. Allow exactly the configured app host there, nowhere else. * * @param bool $external Whether the host is allowed. * @param string $host Requested host. * @param string $url Requested URL. * @return bool */ public static function allow_local_app_host( $external, $host, $url ) { if ( $external || ! OrderCTRL_Bridge_Config::is_local_environment() ) { return $external; } $app_host = wp_parse_url( OrderCTRL_Bridge_Config::app_url(), PHP_URL_HOST ); return $app_host && strtolower( (string) $host ) === strtolower( $app_host ); } /** * Settings migrations between plugin versions. */ public static function maybe_upgrade() { $installed = (string) get_option( self::VERSION_OPTION, '' ); if ( ORDERCTRL_BRIDGE_VERSION === $installed ) { return; } OrderCTRL_Bridge_Config::migrate_legacy_options(); if ( '' === $installed || version_compare( $installed, '2.1.0', '<' ) ) { // Before 2.1, activation turned package protection on with default fees. It now stays // off until the merchant turns it on in OrderCtrl. if ( 'yes' !== OrderCTRL_Bridge_Protection_Settings::get( 'orderctrl_synced' ) ) { update_option( OrderCTRL_Bridge_Protection_Settings::PREFIX . 'enabled', 'no' ); } // Fee type names now match the app. $type = get_option( OrderCTRL_Bridge_Protection_Settings::PREFIX . 'fee_type', '' ); if ( '' !== $type ) { update_option( OrderCTRL_Bridge_Protection_Settings::PREFIX . 'fee_type', OrderCTRL_Bridge_Fee::normalize_type( $type ), false ); } // Stored as true by older versions. if ( get_option( OrderCTRL_Bridge_Config::OPTION_AUTO_CONFIGURED ) ) { update_option( OrderCTRL_Bridge_Config::OPTION_AUTO_CONFIGURED, 'yes', false ); } delete_option( OrderCTRL_Bridge_Protection_Settings::PREFIX . 'meta_key' ); delete_option( OrderCTRL_Bridge_Protection_Settings::PREFIX . 'checkout_type' ); } update_option( self::VERSION_OPTION, ORDERCTRL_BRIDGE_VERSION ); } /** * Shown when WooCommerce isn't active (WordPress 6.5+ also enforces "Requires Plugins"). */ public static function woocommerce_missing_notice() { if ( ! current_user_can( 'activate_plugins' ) ) { return; } printf( '
%s