' . esc_html( sprintf( $text, '7.4', PHP_VERSION ) ) . '

'; }; add_action( 'admin_notices', $rtkt_php_notice ); return; } /* * --------------------------------------------------------------------------- * Constants * --------------------------------------------------------------------------- */ define( 'RTKT_VERSION', '1.0.1' ); define( 'RTKT_FILE', __FILE__ ); define( 'RTKT_DIR', plugin_dir_path( __FILE__ ) ); define( 'RTKT_URL', plugin_dir_url( __FILE__ ) ); define( 'RTKT_BASENAME', plugin_basename( __FILE__ ) ); define( 'RTKT_SLUG', 'returnkit' ); define( 'RTKT_MENU_SLUG', 'returnkit' ); define( 'RTKT_DOCS_URL', 'https://warcal.dev/wordpress/plugins/returnkit/docs' ); define( 'RTKT_SUPPORT_URL', 'https://warcal.dev/contact' ); /* * Freemius product credentials (public values, safe to ship). Fill both in * before building a release: Freemius dashboard → Product → Settings → Keys. * In development, RETURNKIT_FS_PLUGIN_ID / RETURNKIT_FS_PUBLIC_KEY constants * in wp-config.php take precedence. While empty, the SDK stays off and the * built-in stub is used: everything in the free plan keeps working. */ const RTKT_FS_PLUGIN_ID = '42098'; const RTKT_FS_PUBLIC_KEY = 'pk_941764f50fe7a607f76cf39206294'; /* * --------------------------------------------------------------------------- * Autoloader (PSR-4-ish for the ReturnKit\ namespace mapped to /includes) * --------------------------------------------------------------------------- */ $rtkt_composer = RTKT_DIR . 'vendor/autoload.php'; if ( is_readable( $rtkt_composer ) ) { require_once $rtkt_composer; } spl_autoload_register( static function ( $class ) { $prefix = 'ReturnKit\\'; if ( 0 !== strpos( $class, $prefix ) ) { return; } $relative = substr( $class, strlen( $prefix ) ); $path = RTKT_DIR . 'includes/' . str_replace( '\\', '/', $relative ) . '.php'; if ( is_readable( $path ) ) { require_once $path; } } ); if ( !function_exists( 'rtkt_asset_version' ) ) { /** * Cache-busting version for a plugin asset: the file's modification time. * * @param string $relative Path relative to the plugin folder. * @return string */ function rtkt_asset_version( $relative ) { $path = RTKT_DIR . ltrim( $relative, '/' ); return ( file_exists( $path ) ? RTKT_VERSION . '.' . filemtime( $path ) : RTKT_VERSION ); } } /* * --------------------------------------------------------------------------- * Freemius bootstrap * --------------------------------------------------------------------------- */ if ( !function_exists( 'rtkt_fs' ) ) { /** * Singleton accessor for the Freemius SDK instance (or stub). * * @return mixed */ function rtkt_fs() { global $rtkt_fs; if ( isset( $rtkt_fs ) ) { return $rtkt_fs; } $fs_id = ( defined( 'RETURNKIT_FS_PLUGIN_ID' ) && RETURNKIT_FS_PLUGIN_ID ? (string) RETURNKIT_FS_PLUGIN_ID : RTKT_FS_PLUGIN_ID ); $fs_key = ( defined( 'RETURNKIT_FS_PUBLIC_KEY' ) && RETURNKIT_FS_PUBLIC_KEY ? (string) RETURNKIT_FS_PUBLIC_KEY : RTKT_FS_PUBLIC_KEY ); if ( $fs_id && $fs_key && !function_exists( 'fs_dynamic_init' ) && is_readable( RTKT_DIR . 'vendor/freemius/wordpress-sdk/start.php' ) ) { require_once RTKT_DIR . 'vendor/freemius/wordpress-sdk/start.php'; } if ( $fs_id && $fs_key && function_exists( 'fs_dynamic_init' ) ) { try { $rtkt_fs = fs_dynamic_init( array( 'id' => $fs_id, 'slug' => 'returnkit', 'premium_slug' => 'returnkit-premium', 'type' => 'plugin', 'public_key' => $fs_key, 'is_premium' => false, 'premium_suffix' => 'Pro', 'has_addons' => false, 'has_paid_plans' => true, 'menu' => array( 'slug' => RTKT_MENU_SLUG, 'first-path' => 'admin.php?page=' . RTKT_MENU_SLUG, 'support' => false, ), 'is_live' => true, 'is_org_compliant' => true, ) ); $rtkt_fs->add_filter( 'plugin_icon', static function () { return RTKT_DIR . 'assets/img/icon.png'; } ); // The header's long name is for WordPress.org search; Freemius // screens (opt-in, account, checkout) read better with the short one. $rtkt_fs->add_filter( 'plugin_title', static function () { return 'ReturnKit'; } ); } catch ( \Throwable $e ) { // A licensing problem must never take the site down: run as the free plan. // phpcs:ignore WordPress.PHP.DevelopmentFunctions.error_log_error_log error_log( 'ReturnKit: Freemius failed to start, running as the free plan: ' . $e->getMessage() ); $rtkt_fs = null; } } if ( !$rtkt_fs ) { require_once RTKT_DIR . 'includes/Freemius/Stub.php'; $rtkt_fs = new \ReturnKit\Freemius\Stub(); } do_action( 'rtkt_fs_loaded' ); return $rtkt_fs; } } rtkt_fs(); /* * --------------------------------------------------------------------------- * WooCommerce feature compatibility (HPOS and the Cart/Checkout blocks) * --------------------------------------------------------------------------- */ add_action( 'before_woocommerce_init', static function () { if ( class_exists( \Automattic\WooCommerce\Utilities\FeaturesUtil::class ) ) { \Automattic\WooCommerce\Utilities\FeaturesUtil::declare_compatibility( 'custom_order_tables', __FILE__, true ); \Automattic\WooCommerce\Utilities\FeaturesUtil::declare_compatibility( 'cart_checkout_blocks', __FILE__, true ); } } ); /* * --------------------------------------------------------------------------- * Translations * --------------------------------------------------------------------------- * ReturnKit ships its own translations in languages/ (16 locales: German, * French, Spanish, Italian, Dutch, Polish, Swedish, Portuguese, Danish, Finnish, * Norwegian, Czech, Romanian, Greek, Hungarian), so they also reach Pro customers, who * never get WordPress.org language packs. They're registered as the fallback * location for just-in-time loading (WordPress 6.1+), so a WordPress.org * language pack for the same language still takes precedence, and locale * switches (customer emails) load the right file. */ add_action( 'init', static function () { global $wp_textdomain_registry; if ( $wp_textdomain_registry instanceof \WP_Textdomain_Registry ) { $wp_textdomain_registry->set_custom_path( 'returnkit', RTKT_DIR . 'languages' ); } }, 0 ); /* * --------------------------------------------------------------------------- * Activation / deactivation / uninstall * --------------------------------------------------------------------------- */ register_activation_hook( __FILE__, array('\\ReturnKit\\Core\\Installer', 'activate') ); register_deactivation_hook( __FILE__, array('\\ReturnKit\\Core\\Installer', 'deactivate') ); // Freemius owns the uninstall hook (so it can report the uninstall) and calls // this afterwards. Without the SDK the hook is registered on activation. if ( !rtkt_fs() instanceof \ReturnKit\Freemius\Stub ) { rtkt_fs()->add_action( 'after_uninstall', array('\\ReturnKit\\Core\\Uninstaller', 'run') ); } /* * --------------------------------------------------------------------------- * Boot * --------------------------------------------------------------------------- */ add_action( 'plugins_loaded', static function () { try { \ReturnKit\Core\Plugin::instance()->boot(); } catch ( \Throwable $e ) { \ReturnKit\Core\Safe::report( $e, 'boot' ); } }, 20 ); /* * Errors ReturnKit caught (see Core\Safe) are shown to store managers. * Registered here, outside boot, so it works even if booting itself failed. */ add_action( 'admin_init', static function () { if ( isset( $_GET['rtkt_dismiss_error'] ) && current_user_can( 'manage_woocommerce' ) && wp_verify_nonce( sanitize_key( wp_unslash( $_GET['rtkt_dismiss_error'] ) ), 'rtkt_dismiss_error' ) ) { \ReturnKit\Core\Safe::clear(); wp_safe_redirect( remove_query_arg( 'rtkt_dismiss_error' ) ); exit; } } ); add_action( 'admin_notices', static function () { // Only on ReturnKit's screens and the Plugins screen, not across wp-admin. $screen = ( function_exists( 'get_current_screen' ) ? get_current_screen() : null ); $ours = class_exists( '\\ReturnKit\\Admin\\Admin' ) && \ReturnKit\Admin\Admin::is_our_screen(); if ( !current_user_can( 'manage_woocommerce' ) || !($ours || $screen && 'plugins' === $screen->id) ) { return; } $error = \ReturnKit\Core\Safe::recent(); if ( !$error ) { return; } printf( '

%1$s %2$s

%3$s

%5$s · %7$s

', esc_html__( 'ReturnKit caught an error and kept your store running.', 'returnkit' ), esc_html__( 'Please send the details below to support so it can be fixed.', 'returnkit' ), esc_html( $error['message'] ), esc_url( wp_nonce_url( add_query_arg( 'rtkt_dismiss_error', '1' ), 'rtkt_dismiss_error', 'rtkt_dismiss_error' ) ), esc_html__( 'Dismiss', 'returnkit' ), esc_url( RTKT_SUPPORT_URL ), esc_html__( 'Contact support', 'returnkit' ) ); } );