%s

', esc_html__( 'ProofKit requires WooCommerce to be installed and active.', 'proofkit' ) ); } ); return; } Install::maybe_upgrade(); Admin::init(); Product::init(); Cart::init(); Order::init(); Rest::init(); Frontend::init(); Privacy::init(); // WooCommerce defines WC_Email lazily, when WC_Emails is first // constructed. Register through a closure so class-emails.php is only // autoloaded from inside that filter, after WC_Email exists. Calling // Emails::init() here would autoload the subclass too early and fatal. add_filter( 'woocommerce_email_classes', static function ( array $emails ): array { if ( ! class_exists( '\WC_Email' ) ) { return $emails; } $emails['proofkit_proof_ready'] = new Emails(); return $emails; } ); add_action( 'proofkit_daily', array( Install::class, 'run_maintenance' ) ); } /** * Send the proof-ready email, loading WooCommerce's email base first. * * The Emails class extends WC_Email, so it must not be autoloaded before * WooCommerce has created its mailer. This is the safe entry point. * * @param \WC_Order $order Order. * @param object $proof Proof record. * @param string $url Tokenised proof URL. * @return bool */ public static function send_proof_email( \WC_Order $order, object $proof, string $url ): bool { self::ensure_email_class(); if ( ! class_exists( '\WC_Email' ) ) { return false; } return Emails::send_proof_ready( $order, $proof, $url ); } /** * Construct WooCommerce's mailer once so WC_Email is defined. */ private static function ensure_email_class(): void { if ( class_exists( '\WC_Email' ) || ! function_exists( 'WC' ) ) { return; } $woocommerce = WC(); if ( is_object( $woocommerce ) && method_exists( $woocommerce, 'mailer' ) ) { $woocommerce->mailer(); } } /** * Returns the main plugin file path. * * @return string */ public function file(): string { return PROOFKIT_FILE; } /** * Returns the plugin directory with a trailing slash. * * @return string */ public function dir(): string { return PROOFKIT_DIR; } /** * Returns the plugin URL with a trailing slash. * * @return string */ public function url(): string { return PROOFKIT_URL; } }