* Initialize the WooCommerce specific classes. */ public function init_local_seo_woocommerce() { // Check if WooCommerce is active. $active_plugins = apply_filters( 'active_plugins', get_option( 'active_plugins' ) ); if ( in_array( 'woocommerce/woocommerce.php', $active_plugins, true ) ) { $version = $this->get_woocommerce_version_number(); if ( version_compare( $version, $this->min_woocommerce_version, '>=' ) ) { /* * We have the right WooCommerce version, go gadget go... * @todo: We can do better than all these 'requires' <= +1 from JRF. * @todo: Refactor this to auto loading. */ require_once WPSEO_LOCAL_PATH . 'woocommerce/includes/class-wc-post-types.php'; $wpseo_local_woocommerce_post_types = new Yoast_WCSEO_Local_Post_Types(); $wpseo_local_woocommerce_post_types->init(); require_once WPSEO_LOCAL_PATH . 'woocommerce/shipping/class-wc-shipping.php'; require_once WPSEO_LOCAL_PATH . 'woocommerce/shipping/class-wc-shipping-method.php'; $wpseo_local_woocommerce_shipping = new Yoast_WCSEO_Local_Shipping(); $wpseo_local_woocommerce_shipping->init(); require_once WPSEO_LOCAL_PATH . 'woocommerce/admin/class-wc-transport.php'; require_once WPSEO_LOCAL_PATH . 'woocommerce/admin/class-wc-transport-list.php'; $wpseo_local_woocommerce_transport = new Yoast_WCSEO_Local_Transport(); $wpseo_local_woocommerce_transport->init(); require_once WPSEO_LOCAL_PATH . 'woocommerce/admin/class-admin-columns.php'; require_once WPSEO_LOCAL_PATH . 'woocommerce/emails/class-wc-emails.php'; require_once WPSEO_LOCAL_PATH . 'woocommerce/includes/wpseo-local-woocommerce-functions.php'; require_once WPSEO_LOCAL_PATH . 'woocommerce/admin/class-woocommerce-settings.php'; new WPSEO_Local_Admin_Woocommerce_Settings(); if ( is_admin() ) { new Yoast_WCSEO_Local_Admin_Columns(); } } else { // User has an old WooCommerce version. add_action( 'all_admin_notices', [ $this, 'error_outdated_woocommerce' ] ); } } } /** * Retrieves the version number of the active WooCommerce plugin. * * @return string|null The version number or null if it couldn't be determined. */ private function get_woocommerce_version_number() { // If get_plugins() isn't available, require it. if ( ! function_exists( 'get_plugins' ) ) { require_once ABSPATH . 'wp-admin/includes/plugin.php'; } // Create the plugins folder and file variables. $plugin_folder = get_plugins( '/woocommerce' ); $plugin_file = 'woocommerce.php'; // If the plugin version number is set, return it. if ( isset( $plugin_folder[ $plugin_file ]['Version'] ) ) { return $plugin_folder[ $plugin_file ]['Version']; } else { // Otherwise return null. return null; } } /** * Throw an error if WooCommerce is out of date. */ public function error_outdated_woocommerce() { $this->admin_message( sprintf( /* translators: %s expands to "Yoast SEO: Local for WooCommerce". */ __( 'Please upgrade the WooCommerce plugin to the latest version to allow the "%s" plugin to work.', 'yoast-local-seo' ), $this->_plugin_name ), 'error' ); } /** * Displays a generic admin message. * * @param string $message Admin message text. * @param string $class CSS class name for the admin notice. */ private function admin_message( $message, $class ) { echo '

' . $message . '

'; } }