version = ABFW_VERSION; } else { $this->version = '1.0.0'; } $this->plugin_name = 'abfw'; $this->load_dependencies(); $this->set_locale(); $this->define_admin_hooks(); $this->define_public_hooks(); $this->define_paid_hooks(); } /** * Run the loader to execute all of the hooks with WordPress. * * @since 1.0.0 */ public function run() { $this->loader->run(); } /** * The name of the plugin used to uniquely identify it within the context of * WordPress and to define internationalization functionality. * * @since 1.0.0 * @return string The name of the plugin. */ public function get_plugin_name() { return $this->plugin_name; } /** * The reference to the class that orchestrates the hooks with the plugin. * * @since 1.0.0 * @return Loader Orchestrates the hooks of the plugin. */ public function get_loader() { return $this->loader; } /** * Retrieve the version number of the plugin. * * @since 1.0.0 * @return string The version number of the plugin. */ public function get_version() { return $this->version; } /** * Load the required dependencies for this plugin. * * Classes are loaded through Composer's PSR-4 autoloader, so no manual * require_once calls are needed here. * * @since 1.0.0 * @access private */ private function load_dependencies() { $this->loader = new Loader(); } /** * Define the locale for this plugin for internationalization. * * @since 1.0.0 * @access private */ private function set_locale() { $plugin_i18n = new I18n(); $this->loader->add_action( 'init', $plugin_i18n, 'load_plugin_textdomain' ); } /** * Register all of the hooks related to the admin area functionality * of the plugin. * * @since 1.0.0 * @access private */ private function define_admin_hooks() { $plugin_admin = new Admin( $this->get_plugin_name(), $this->get_version() ); $this->loader->add_action( 'admin_enqueue_scripts', $plugin_admin, 'enqueue_styles' ); $this->loader->add_action( 'admin_enqueue_scripts', $plugin_admin, 'enqueue_scripts' ); $this->loader->add_action( 'admin_menu', $plugin_admin, 'add_admin_menu' ); $this->loader->add_action( 'admin_init', Installer::class, 'maybe_update' ); $notices = new Notices(); $this->loader->add_action( 'admin_init', $notices, 'handle' ); $this->loader->add_action( 'admin_notices', $notices, 'show' ); $this->loader->add_action( 'woocommerce_order_status_changed', $notices, 'recheck_review' ); $product_panel = new ProductPanel(); $this->loader->add_filter( 'woocommerce_product_data_tabs', $product_panel, 'add_tab' ); $this->loader->add_action( 'woocommerce_product_data_panels', $product_panel, 'render_panel' ); $this->loader->add_action( 'woocommerce_process_product_meta', $product_panel, 'save' ); $variation_panel = new VariationPanel(); $this->loader->add_action( 'woocommerce_product_after_variable_attributes', $variation_panel, 'render', 10, 3 ); $this->loader->add_action( 'woocommerce_save_product_variation', $variation_panel, 'save', 10, 2 ); $order_dates = new OrderDates( new Bookings(), new Cart() ); $this->loader->add_action( 'woocommerce_before_order_itemmeta', $order_dates, 'render', 10, 2 ); $this->loader->add_filter( 'woocommerce_hidden_order_itemmeta', $order_dates, 'hide_raw_dates' ); $this->loader->add_action( 'woocommerce_saved_order_items', $order_dates, 'save', 10, 2 ); } /** * Register all of the hooks related to the public-facing functionality * of the plugin. * * @since 1.0.0 * @access private */ private function define_public_hooks() { $plugin_public = new Frontend( $this->get_plugin_name(), $this->get_version() ); $this->loader->add_action( 'wp_enqueue_scripts', $plugin_public, 'enqueue_styles' ); $this->loader->add_action( 'wp_enqueue_scripts', $plugin_public, 'enqueue_scripts' ); $product_form = new ProductForm(); $cart = new Cart(); $bookings = new Bookings(); $shop = new Shop(); $this->loader->add_filter( 'woocommerce_product_add_to_cart_text', $shop, 'button_text', 10, 2 ); $this->loader->add_filter( 'woocommerce_product_add_to_cart_url', $shop, 'button_url', 10, 2 ); $this->loader->add_filter( 'woocommerce_loop_add_to_cart_args', $shop, 'button_args', 10, 2 ); $this->loader->add_action( 'woocommerce_before_add_to_cart_button', $product_form, 'render' ); $this->loader->add_action( 'woocommerce_before_add_to_cart_button', $product_form, 'render_grouped' ); $this->loader->add_filter( 'woocommerce_available_variation', $product_form, 'variation_rules', 10, 3 ); $this->loader->add_filter( 'woocommerce_add_to_cart_validation', $cart, 'validate', 10, 4 ); $this->loader->add_action( 'woocommerce_store_api_validate_add_to_cart', $cart, 'validate_store_api' ); $this->loader->add_filter( 'woocommerce_add_cart_item_data', $cart, 'add_cart_item_data', 10, 3 ); // Early, so anything else adding to a line keeps its amount on top of the stay. $this->loader->add_action( 'woocommerce_before_calculate_totals', $cart, 'set_prices', 5 ); $this->loader->add_filter( 'woocommerce_get_item_data', $cart, 'display', 10, 2 ); $this->loader->add_action( 'woocommerce_checkout_create_order_line_item', $cart, 'save_order_item', 10, 3 ); $this->loader->add_action( 'woocommerce_checkout_order_processed', $bookings, 'record' ); $this->loader->add_action( 'woocommerce_store_api_checkout_order_processed', $bookings, 'record' ); $this->loader->add_action( 'woocommerce_order_status_changed', $bookings, 'follow_order_status', 10, 3 ); $this->loader->add_action( Activator::STATUS_EVENT, Statuses::class, 'sweep' ); $this->loader->add_action( 'init', Activator::class, 'schedule_status_sweep' ); } /** * Register the hooks of the paid features, when the licence allows them. * * @since 1.1.0 * @access private */ private function define_paid_hooks() { // The free archive carries no paid code, so the class may be missing. if ( is_premium() && class_exists( Pro\Pro::class ) ) { ( new Pro\Pro() )->register( $this->loader ); return; } $locked = new Locked(); $this->loader->add_filter( 'abfw_locked_tabs', $locked, 'settings_tabs' ); $this->loader->add_action( 'abfw_bookings_actions', $locked, 'bookings_actions' ); $this->loader->add_action( 'abfw_product_panel', $locked, 'product_panel' ); } }