plugin_path() . '/vendor/autoload.php'; $this->plugin_basename = plugin_basename(__FILE__); $this->legacy_addons = apply_filters( 'wpo_wcpdf_legacy_addons', array( 'ubl-woocommerce-pdf-invoices.php' => 'UBL Invoices for WooCommerce', 'woocommerce-pdf-ips-number-tools.php' => 'PDF Invoices & Packing Slips for WooCommerce - Number Tools', ) ); $this->define( 'WPO_WCPDF_VERSION', $this->version ); // load the localisation & classes add_action( 'init', array( $this, 'translations' ), 8 ); add_action( 'init', array( $this, 'load_classes' ), 9 ); // Pro runs on default 10, if this runs after it will not work add_action( 'in_plugin_update_message-'.$this->plugin_basename, array( $this, 'in_plugin_update_message' ) ); add_action( 'before_woocommerce_init', array( $this, 'woocommerce_hpos_compatible' ) ); add_action( 'admin_notices', array( $this, 'nginx_detected' ) ); add_action( 'admin_notices', array( $this, 'mailpoet_mta_detected' ) ); add_action( 'admin_notices', array( $this, 'rtl_detected' ) ); add_action( 'admin_notices', array( $this, 'yearly_reset_action_missing_notice' ) ); add_action( 'admin_notices', array( $this, 'legacy_addon_notices' ) ); add_action( 'init', array( '\\WPO\\IPS\\Semaphore', 'init_cleanup' ), 999 ); // wait AS to initialize // deactivate legacy extensions if activated register_activation_hook( __FILE__, array( $this, 'deactivate_legacy_addons' ) ); } public function is_dependency_version_supported( $dependency ) { switch ( $dependency ) { case 'php': return defined( 'PHP_VERSION' ) && version_compare( PHP_VERSION, $this->version_php, '>=' ); case 'woo': return defined( 'WC_VERSION' ) && version_compare( WC_VERSION, $this->version_woo, '>=' ); case 'wp': global $wp_version; return version_compare( $wp_version, $this->version_wp, '>=' ); } return false; } /** * Define constant if not already set * @param string $name * @param string|bool $value */ private function define( $name, $value ) { if ( ! defined( $name ) ) { define( $name, $value ); } } /** * Load the translation / textdomain files * * Note: the first-loaded translation file overrides any following ones if the same translation is present */ public function translations() { $locale = $this->determine_locale(); $dir = trailingslashit( WP_LANG_DIR ); $textdomains = array( 'woocommerce-pdf-invoices-packing-slips' ); /** * Frontend/global Locale. Looks in: * * - WP_LANG_DIR/woocommerce-pdf-invoices-packing-slips/woocommerce-pdf-invoices-packing-slips-LOCALE.mo * - WP_LANG_DIR/plugins/woocommerce-pdf-invoices-packing-slips-LOCALE.mo * - woocommerce-pdf-invoices-packing-slips/languages/woocommerce-pdf-invoices-packing-slips-LOCALE.mo (which if not found falls back to:) * - WP_LANG_DIR/plugins/woocommerce-pdf-invoices-packing-slips-LOCALE.mo */ foreach ( $textdomains as $textdomain ) { unload_textdomain( $textdomain ); load_textdomain( $textdomain, $dir . 'woocommerce-pdf-invoices-packing-slips/woocommerce-pdf-invoices-packing-slips-' . $locale . '.mo' ); load_textdomain( $textdomain, $dir . 'plugins/woocommerce-pdf-invoices-packing-slips-' . $locale . '.mo' ); load_plugin_textdomain( $textdomain, false, dirname( plugin_basename(__FILE__) ) . '/languages' ); } } /** * Load the main plugin classes and functions */ public function includes() { // plugin legacy class mapping include_once $this->plugin_path() . '/wpo-ips-legacy-class-alias-mapping.php'; // plugin functions include_once $this->plugin_path() . '/wpo-ips-functions.php'; include_once $this->plugin_path() . '/wpo-ips-functions-ubl.php'; // Third party compatibility $this->third_party_plugins = \WPO\IPS\Compatibility\ThirdPartyPlugins::instance(); // WC OrderUtil compatibility $this->order_util = \WPO\IPS\Compatibility\OrderUtil::instance(); // Plugin classes $this->settings = \WPO\IPS\Settings::instance(); $this->documents = \WPO\IPS\Documents::instance(); $this->main = \WPO\IPS\Main::instance(); $this->endpoint = \WPO\IPS\Endpoint::instance(); $this->assets = \WPO\IPS\Assets::instance(); $this->admin = \WPO\IPS\Admin::instance(); $this->frontend = \WPO\IPS\Frontend::instance(); $this->install = \WPO\IPS\Install::instance(); $this->font_synchronizer = \WPO\IPS\FontSynchronizer::instance(); } /** * Instantiate classes when woocommerce is activated */ public function load_classes() { if ( ! $this->is_woocommerce_activated() || ! $this->is_dependency_version_supported( 'woo' ) ) { add_action( 'admin_notices', array ( $this, 'need_woocommerce' ) ); return; } if ( ! has_filter( 'wpo_wcpdf_pdf_maker' ) && ! $this->is_dependency_version_supported( 'php' ) ) { add_filter( 'wpo_wcpdf_document_is_allowed', '__return_false', 99999 ); add_action( 'admin_notices', array ( $this, 'required_php_version' ) ); } add_action( 'admin_init', array( $this, 'deactivate_legacy_addons') ); // all systems ready - GO! $this->includes(); } /** * WooCommerce notice. * * @return void */ public function need_woocommerce() { $error_message = sprintf( /* translators: 1. open anchor tag, 2. close anchor tag, 3. Woo version */ esc_html__( 'PDF Invoices & Packing Slips for WooCommerce requires %1$sWooCommerce%2$s version %3$s or higher to be installed & activated!' , 'woocommerce-pdf-invoices-packing-slips' ), '', '', esc_attr( $this->version_woo ) ); $message = '
%s
', $error_message ); $message .= '%s
', $error_message ); $message .= sprintf( '%s
', $php_message ); $message .= ''; foreach ( $notices as $index => $line ) { if ( empty( $line ) ) { continue; } $upgrade_notice .= preg_replace( '~\[([^\]]*)\]\(([^\)]*)\)~', '${1}', $line ); } } } return wp_kses_post( $upgrade_notice ); } public function nginx_detected() { if ( empty( $this->main ) ) { return; } $tmp_path = $this->main->get_tmp_path( 'attachments' ); $server_software = isset( $_SERVER['SERVER_SOFTWARE'] ) ? sanitize_text_field( wp_unslash( $_SERVER['SERVER_SOFTWARE'] ) ) : ''; $random_string = $this->main->get_random_string(); if ( stristr( $server_software, 'nginx' ) && $this->settings->user_can_manage_settings() && ! get_option( 'wpo_wcpdf_hide_nginx_notice' ) && ! $random_string ) { ob_start(); ?>
main->generate_random_string(); $old_path = $this->main->get_tmp_base( false ); $new_path = $this->main->get_tmp_base(); $this->main->copy_directory( $old_path, $new_path ); // save option to hide nginx notice update_option( 'wpo_wcpdf_hide_nginx_notice', true ); wp_redirect( 'admin.php?page=wpo_wcpdf_options_page' ); exit; } } // save option to hide nginx notice if ( isset( $_REQUEST['wpo_wcpdf_hide_nginx_notice'] ) && isset( $_REQUEST['_wpnonce'] ) ) { // validate nonce if ( ! wp_verify_nonce( $_REQUEST['_wpnonce'], 'hide_nginx_notice_nonce' ) ) { wcpdf_log_error( 'You do not have sufficient permissions to perform this action: wpo_wcpdf_hide_nginx_notice' ); wp_redirect( 'admin.php?page=wpo_wcpdf_options_page' ); exit; } else { update_option( 'wpo_wcpdf_hide_nginx_notice', true ); wp_redirect( 'admin.php?page=wpo_wcpdf_options_page' ); exit; } } } /** * Detect MailPoet. * @return void */ public function mailpoet_mta_detected() { if( is_callable( array( '\\MailPoet\\Settings\\SettingsController', 'getInstance' ) ) ) { $settings = \MailPoet\Settings\SettingsController::getInstance(); if( empty($settings) ) return; $send_transactional = $settings->get( 'send_transactional_emails', false ); if( $send_transactional && ! get_option('wpo_wcpdf_hide_mailpoet_notice') ) { ob_start(); ?>MailPoet Sending Service or Your web host / web server, MailPoet does not include the PDF Invoices & Packing Slips for WooCommerce attachments in the emails.', 'woocommerce-pdf-invoices-packing-slips' ); ?>
The default WordPress sending method (default) on the Advanced tab.', 'woocommerce-pdf-invoices-packing-slips' ); ?>