autoloaders(); } return self::$_instance; } /** * Constructor */ public function __construct() { $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 ); require $this->plugin_path() . '/vendor/autoload.php'; // load the localisation & classes add_action( 'plugins_loaded', array( $this, 'translations' ) ); add_action( 'plugins_loaded', array( $this, 'load_classes' ), 9 ); 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, 'legacy_addon_notices' ) ); // deactivate legacy extensions if activated register_activation_hook( __FILE__, array( $this, 'deactivate_legacy_addons' ) ); } private function autoloaders() { // main plugin autoloader require plugin_dir_path( __FILE__ ) . 'vendor/autoload.php'; } /** * 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 functions include_once( $this->plugin_path() . '/includes/wcpdf-functions.php' ); // Third party compatibility $this->third_party_plugins = \WPO\WC\PDF_Invoices\Compatibility\Third_Party_Plugins::instance(); // WC OrderUtil compatibility $this->order_util = \WPO\WC\PDF_Invoices\Compatibility\Order_Util::instance(); // Plugin classes $this->settings = \WPO\WC\PDF_Invoices\Settings::instance(); $this->documents = \WPO\WC\PDF_Invoices\Documents::instance(); $this->main = \WPO\WC\PDF_Invoices\Main::instance(); $this->endpoint = \WPO\WC\PDF_Invoices\Endpoint::instance(); $this->assets = \WPO\WC\PDF_Invoices\Assets::instance(); $this->admin = \WPO\WC\PDF_Invoices\Admin::instance(); $this->frontend = \WPO\WC\PDF_Invoices\Frontend::instance(); $this->install = \WPO\WC\PDF_Invoices\Install::instance(); $this->font_synchronizer = \WPO\WC\PDF_Invoices\Font_Synchronizer::instance(); } /** * Instantiate classes when woocommerce is activated */ public function load_classes() { if ( $this->is_woocommerce_activated() === false ) { add_action( 'admin_notices', array ( $this, 'need_woocommerce' ) ); return; } if ( $this->is_woocommerce_version_supported() === false ) { add_action( 'admin_notices', array ( $this, 'need_woocommerce_3_0' ) ); return; } if ( version_compare( PHP_VERSION, '5.6', '<' ) ) { add_action( 'admin_notices', array ( $this, 'required_php_version' ) ); return; } // if ( version_compare( PHP_VERSION, '7.2', '<' ) ) { // add_action( 'admin_notices', array ( $this, 'next_php_version_bump' ) ); // } if ( has_filter( 'wpo_wcpdf_pdf_maker' ) === false && version_compare( PHP_VERSION, '7.2', '<' ) ) { 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(); } /** * Check if woocommerce version is supported */ public function is_woocommerce_version_supported() { if ( defined( 'WC_VERSION' ) && version_compare( WC_VERSION, '3.0', '>=' ) ) { return true; } else { return false; } } /** * Woocommerce version < 3.0 notice */ public function need_woocommerce_3_0() { /* translators: tags */ $error = sprintf( esc_html__( 'PDF Invoices & Packing Slips for WooCommerce requires %1$sWooCommerce%2$s version 3.0 or higher!' , 'woocommerce-pdf-invoices-packing-slips' ), '', '' ); $message = '

' . $error . '

'; echo $message; } /** * Check if woocommerce is activated */ public function is_woocommerce_activated() { $blog_plugins = get_option( 'active_plugins', array() ); $site_plugins = is_multisite() ? (array) maybe_unserialize( get_site_option('active_sitewide_plugins' ) ) : array(); if ( in_array( 'woocommerce/woocommerce.php', $blog_plugins ) || isset( $site_plugins['woocommerce/woocommerce.php'] ) ) { $is_wc_activated = true; } else { $is_wc_activated = false; } return apply_filters( 'wpo_wcpdf_is_woocommerce_activated', $is_wc_activated ); } /** * WooCommerce not active notice. * * @return void */ public function need_woocommerce() { /* translators: tags */ $error = sprintf( esc_html__( 'PDF Invoices & Packing Slips for WooCommerce requires %1$sWooCommerce%2$s to be installed & activated!' , 'woocommerce-pdf-invoices-packing-slips' ), '', '' ); $message = '

' . $error . '

'; echo $message; } /** * Declares WooCommerce HPOS compatibility. * * @return void */ public function woocommerce_hpos_compatible() { if ( class_exists( '\Automattic\WooCommerce\Utilities\FeaturesUtil' ) ) { \Automattic\WooCommerce\Utilities\FeaturesUtil::declare_compatibility( 'custom_order_tables', __FILE__, true ); } } /** * PHP version requirement notice */ public function required_php_version() { $error_message = __( 'PDF Invoices & Packing Slips for WooCommerce requires PHP 7.2 (7.4 or higher recommended).', 'woocommerce-pdf-invoices-packing-slips' ); /* translators: tags */ $php_message = __( 'We strongly recommend to %1$supdate your PHP version%2$s.', 'woocommerce-pdf-invoices-packing-slips' ); /* translators: tags */ $add_on_message = __( 'If you cannot upgrade your PHP version, you can download %1$sthis addon%2$s to enable backwards compatibility with PHP5.6.', 'woocommerce-pdf-invoices-packing-slips' ); $message = '
'; $message .= sprintf( '

%s

', $error_message ); $message .= sprintf( '

'.$php_message.'

', '
', '' ); if ( version_compare( PHP_VERSION, '5.6', '>' ) ) { $message .= sprintf( '

'.$add_on_message.'

', '', '' ); } $message .= '
'; echo wp_kses_post( $message ); } /** * Next PHP version bump requirement notice */ public function next_php_version_bump() { $error_message = sprintf( /* translators: tags */ __( 'PDF Invoices & Packing Slips for WooCommerce will require PHP 7.2 soon for future releases. Please %1$supdate your PHP version%2$s so that you will be able to use our plugin in the future.', 'woocommerce-pdf-invoices-packing-slips' ), '', '' ); $message = '
'; $message .= sprintf( '

%s

', $error_message ); $message .= '
'; echo wp_kses_post( $message ); } /** * Show plugin changes. Code adapted from W3 Total Cache. */ public function in_plugin_update_message( $args ) { $transient_name = 'wpo_wcpdf_upgrade_notice_' . $args['Version']; if ( false === ( $upgrade_notice = get_transient( $transient_name ) ) ) { $response = wp_safe_remote_get( 'https://plugins.svn.wordpress.org/woocommerce-pdf-invoices-packing-slips/trunk/readme.txt' ); if ( ! is_wp_error( $response ) && ! empty( $response['body'] ) ) { $upgrade_notice = self::parse_update_notice( $response['body'], $args['new_version'] ); set_transient( $transient_name, $upgrade_notice, DAY_IN_SECONDS ); } } echo wp_kses_post( $upgrade_notice ); } /** * Parse update notice from readme file. * * @param string $content * @param string $new_version * @return string */ private function parse_update_notice( $content, $new_version ) { // Output Upgrade Notice. $matches = null; $regexp = '~==\s*Upgrade Notice\s*==\s*=\s*(.*)\s*=(.*)(=\s*' . preg_quote( $new_version ) . '\s*=|$)~Uis'; $upgrade_notice = ''; if ( preg_match( $regexp, $content, $matches ) ) { $notices = (array) preg_split( '~[\r\n]+~', trim( $matches[2] ) ); // Convert the full version strings to minor versions. $notice_version_parts = explode( '.', trim( $matches[1] ) ); $current_version_parts = explode( '.', $this->version ); if ( 3 !== sizeof( $notice_version_parts ) ) { return $upgrade_notice; } $notice_version = $notice_version_parts[0] . '.' . $notice_version_parts[1]; $current_version = $current_version_parts[0] . '.' . $current_version_parts[1]; // Check the latest stable version and ignore trunk. if ( version_compare( $current_version, $notice_version, '<' ) ) { $upgrade_notice .= '

'; 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(); ?>

NGINX.', 'woocommerce-pdf-invoices-packing-slips' ), '' . $tmp_path . '' ); ?>

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(); ?>
" style="margin-top:10px;">

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' ); ?>

1369572703 so we do array_keys to make the array // compatible with $active_plugins $active_sitewide_plugins = (array) array_keys( get_site_option( 'active_sitewide_plugins', array() ) ); // merge arrays and remove doubles $active_plugins = (array) array_unique( array_merge( $active_plugins, $active_sitewide_plugins ) ); } return $active_plugins; } public function deactivate_legacy_addons() { foreach ( $this->legacy_addons as $filename => $name ) { $legacy_addon = $this->legacy_addon_detected( $filename ); if ( ! empty( $legacy_addon ) ) { deactivate_plugins( $legacy_addon ); $transient_name = $this->get_legacy_addon_transient_name( $filename ); set_transient( $transient_name, 'yes', DAY_IN_SECONDS ); } } } public function legacy_addon_detected( $filename ) { $active_plugins = $this->get_active_plugins(); $legacy_addon = ''; foreach ( $active_plugins as $plugin ) { if ( false !== strpos( $plugin, $filename ) ) { $legacy_addon = $plugin; break; } } return $legacy_addon; } public function get_legacy_addon_transient_name( $filename ) { $filename_without_ext = basename( $filename, '.php' ); $legacy_addon_name = str_replace( '-', '_', $filename_without_ext ); return "wpo_wcpdf_legacy_addon_{$legacy_addon_name}"; } public function legacy_addon_notices() { foreach ( $this->legacy_addons as $filename => $name ) { $transient_name = $this->get_legacy_addon_transient_name( $filename ); $query_arg = "{$transient_name}_notice"; if ( get_transient( $transient_name ) ) { ob_start(); ?>

' . esc_attr( $name ) . '' ); ?>

version; } } new WooCommerce_PDF_Invoices(); }