plugin_path() . '/config/constants.php'; if ( file_exists( $constants_path ) ) { require $constants_path; } $this->plugin_basename = plugin_basename( TWINCAAF_WC_ADVANCED_ATTRIBUTE_FILTERS_PATH ); if ( defined( 'TWINCAAF_ADVANCED_ATTRIBUTE_FILTERS_CONSTANTS' ) ) { $this->constants = TWINCAAF_ADVANCED_ATTRIBUTE_FILTERS_CONSTANTS; } add_action( 'init', array( $this, 'load_classes' ), 9 ); add_action( 'init', array( $this, 'twincaaf_register_gutenberg_block' ), 20 ); } /** * Get the plugin path. * * @return string */ public function plugin_path() { return untrailingslashit( plugin_dir_path( TWINCAAF_WC_ADVANCED_ATTRIBUTE_FILTERS_PATH ) ); } /** * Installs Shortcode as Gutenberg Block. */ public function twincaaf_register_gutenberg_block() { register_block_type( 'twincaaf-attribute-filters/advanced-filters', array( 'api_version' => 2, 'title' => 'Advanced Attribute Filters', 'icon' => 'filter', 'category' => 'woocommerce', 'render_callback' => array( '\TwinCart\WC\AdvancedAttributeFilters\Shortcode', 'render_filters' ), 'attributes' => array( 'className' => array( 'type' => 'string', 'default' => '', ), ), 'example' => array(), ) ); } /** * Instantiate classes when woocommerce is activated. */ public function load_classes() { if ( ! $this->dependencies_are_ready() ) { return; } $this->includes(); } /** * Check if WooCommerce and PHP dependencies are met. * * @return bool */ public function dependencies_are_ready(): bool { if ( ! $this->is_woocommerce_activated() ) { add_action( 'admin_notices', array( $this, 'need_woocommerce' ) ); return false; } return true; } /** * Check if WooCommerce is active. * * @return bool */ public function is_woocommerce_activated() { return class_exists( 'WooCommerce' ); } /** * Display WooCommerce required notice. */ public function need_woocommerce() { $error_message = sprintf( /* translators: 1. open anchor tag, 2. close anchor tag */ esc_html__( 'Advanced Attribute Filters for WooCommerce requires %1$sWooCommerce%2$s to be installed & activated!', 'advanced-attribute-filters' ), '', '' ); echo '
' . wp_kses_post( $error_message ) . '