diff options
| author | Murilo Ijanc <[email protected]> | 2026-07-26 16:41:48 -0300 |
|---|---|---|
| committer | Murilo Ijanc <[email protected]> | 2026-07-26 16:47:14 -0300 |
| commit | 535dbda6b48171f8115b455e54790de94d97d42a (patch) | |
| tree | 5c0410011e61a883bdf063ee612875a637fb1d22 /cepis-woocommerce.php | |
| download | woocommerce-535dbda6b48171f8115b455e54790de94d97d42a.tar.gz | |
Initial importv0.1.0
Diffstat (limited to 'cepis-woocommerce.php')
| -rw-r--r-- | cepis-woocommerce.php | 100 |
1 files changed, 100 insertions, 0 deletions
diff --git a/cepis-woocommerce.php b/cepis-woocommerce.php new file mode 100644 index 0000000..b9ae502 --- /dev/null +++ b/cepis-woocommerce.php @@ -0,0 +1,100 @@ +<?php +/** + * Plugin Name: CEP Autofill for WooCommerce + * Plugin URI: https://cep.is + * Description: Fills the WooCommerce checkout address from the CEP the shopper types, with official Correios data (DNE) from cep.is. + * Version: 0.1.0 + * Requires at least: 6.9 + * Tested up to: 7.0 + * Requires PHP: 8.1 + * Requires Plugins: woocommerce + * Author: Murilo Ijanc + * Author URI: https://ijanc.org + * License: ISC + * License URI: https://opensource.org/licenses/ISC + * Text Domain: cepis-woocommerce + * Domain Path: /languages + * + * @package CepisWooCommerce + */ + +declare(strict_types=1); + +defined( 'ABSPATH' ) || exit; + +define( 'CEPIS_WOO_VERSION', '0.1.0' ); +define( 'CEPIS_WOO_FILE', __FILE__ ); +define( 'CEPIS_WOO_DIR', plugin_dir_path( __FILE__ ) ); +define( 'CEPIS_WOO_URL', plugin_dir_url( __FILE__ ) ); + +/** + * Autoload the bundled `Cepis\` PHP client. + * + * The library is vendored under `lib/cepis/` rather than installed with + * Composer, because a WordPress site is deployed by copying files and never + * runs `composer install`. Registration is appended, so a Composer autoloader + * already in play on the site keeps precedence and only one copy of the + * classes is ever declared. + * + * @param string $class_name Fully qualified class name being resolved. + */ +function cepis_woo_autoload( string $class_name ): void { + if ( ! str_starts_with( $class_name, 'Cepis\\' ) ) { + return; + } + + $relative = substr( $class_name, 6 ); + if ( str_contains( $relative, '\\' ) || ! preg_match( '/^[A-Za-z0-9_]+$/', $relative ) ) { + return; + } + + $file = CEPIS_WOO_DIR . 'lib/cepis/' . $relative . '.php'; + if ( is_readable( $file ) ) { + require_once $file; + } +} + +spl_autoload_register( 'cepis_woo_autoload' ); + +require_once CEPIS_WOO_DIR . 'includes/class-cepis-woo-options.php'; +require_once CEPIS_WOO_DIR . 'includes/class-cepis-woo-messages.php'; +require_once CEPIS_WOO_DIR . 'includes/class-cepis-woo-token.php'; +require_once CEPIS_WOO_DIR . 'includes/class-cepis-woo-transport.php'; +require_once CEPIS_WOO_DIR . 'includes/class-cepis-woo-lookup.php'; +require_once CEPIS_WOO_DIR . 'includes/class-cepis-woo-rest.php'; +require_once CEPIS_WOO_DIR . 'includes/class-cepis-woo-assets.php'; +require_once CEPIS_WOO_DIR . 'includes/class-cepis-woo-admin.php'; + +/** + * Boot the plugin once WordPress has loaded its own translations. + * + * Every hook registered here fires at or after `init`, which is what keeps + * translation calls out of the `_load_textdomain_just_in_time` notice. + */ +function cepis_woo_init(): void { + load_plugin_textdomain( 'cepis-woocommerce', false, dirname( plugin_basename( CEPIS_WOO_FILE ) ) . '/languages' ); + + Cepis_Woo_Assets::init(); + Cepis_Woo_Rest::init(); + + if ( is_admin() ) { + Cepis_Woo_Admin::init(); + } +} + +add_action( 'init', 'cepis_woo_init' ); + +/** + * Declare compatibility with WooCommerce High-Performance Order Storage. + * + * The plugin never reads or writes an order, so the declaration is honest and + * keeps the store owner from seeing an "incompatible plugin" warning. + */ +function cepis_woo_declare_hpos(): void { + if ( class_exists( \Automattic\WooCommerce\Utilities\FeaturesUtil::class ) ) { + \Automattic\WooCommerce\Utilities\FeaturesUtil::declare_compatibility( 'custom_order_tables', CEPIS_WOO_FILE, true ); + \Automattic\WooCommerce\Utilities\FeaturesUtil::declare_compatibility( 'cart_checkout_blocks', CEPIS_WOO_FILE, true ); + } +} + +add_action( 'before_woocommerce_init', 'cepis_woo_declare_hpos' ); |