session = new Session(); $this->list = new QuoteList( $this->session ); new QuoteCPT(); new Shortcodes( $this->list ); new RestController( $this->list ); new SubmitHandler( $this->list ); new Privacy(); new Blocks(); if ( is_admin() ) { new Admin(); new GettingStarted(); } // is_admin() is also true in admin-ajax.php, where themes render products (filters, quick view). if ( ! is_admin() || wp_doing_ajax() ) { $this->frontend = new Frontend( $this->list ); } add_filter( 'woocommerce_email_classes', array( $this, 'register_emails' ) ); add_action( 'bbquote_cleanup_sessions', array( Session::class, 'cleanup' ) ); } /** * Register plugin emails within the WooCommerce mailer. * * @param array $emails Registered WC emails. * @return array */ public function register_emails( $emails ) { $emails['BBQUOTE_Email_New_Request'] = new Emails\NewRequestEmail(); $emails['BBQUOTE_Email_Customer_Confirm'] = new Emails\CustomerConfirmEmail(); return $emails; } /** * CSS classes for front-end buttons. Block themes style `wp-element-button`, classic themes `.button`. * * @param string $extra Extra classes. * @return string */ public static function button_class( $extra = '' ) { return trim( 'button ' . $extra . ' ' . wc_wp_theme_get_element_class_name( 'button' ) ); } /** * URL of the quote request page. * * @return string */ public static function get_page_url() { $page_id = self::get_page_id(); // get_permalink( 0 ) would return the CURRENT post's URL - guard against a missing page. $url = $page_id ? (string) get_permalink( $page_id ) : ''; return apply_filters( 'bbquote_page_url', $url ); } /** * ID of the quote request page. * * @return int */ public static function get_page_id() { return (int) apply_filters( 'wpml_object_id', get_option( 'bbquote_page_id' ), 'post', true ); // phpcs:ignore WordPress.NamingConventions.PrefixAllGlobals.NonPrefixedHooknameFound -- WooCommerce/WPML hook. } /** * Read one setting with default. * * @param string $key Setting key. * @param mixed $fallback Default value. * @return mixed */ public static function setting( $key, $fallback = '' ) { $settings = (array) get_option( 'bbquote_settings', array() ); return array_key_exists( $key, $settings ) ? $settings[ $key ] : $fallback; } }