is_compatible() ) { add_action( 'elementor/init', array( $this, 'init' ) ); } } /** * Compatibility Checks * * Checks whether the site meets the addon requirement. */ public function is_compatible() { // Check if Elementor installed and activated. if ( ! did_action( 'elementor/loaded' ) ) { add_action( 'admin_notices', array( $this, 'admin_notice_missing_main_plugin' ) ); return false; } // Check for required Elementor version. if ( ! version_compare( ELEMENTOR_VERSION, self::MINIMUM_ELEMENTOR_VERSION, '>=' ) ) { add_action( 'admin_notices', array( $this, 'admin_notice_minimum_elementor_version' ) ); return false; } // Check for required PHP version. if ( version_compare( PHP_VERSION, self::MINIMUM_PHP_VERSION, '<' ) ) { add_action( 'admin_notices', array( $this, 'admin_notice_minimum_php_version' ) ); return false; } /** * Check if WooCommerce is activated */ if ( ! class_exists( 'WooCommerce' ) ) { add_action( 'admin_notices', array( $this, 'admin_notice_missing_woocommerce' ) ); return false; } return true; } /** * Initialize the plugin. */ public function init() { add_action( 'elementor/frontend/after_register_styles', array( $this, 'register_frontend_styles' ) ); add_action( 'elementor/widgets/register', array( $this, 'register_widgets' ) ); add_filter( 'wc_add_to_cart_params', function ( $params ) { // if we're on a WooCommerce page. if ( is_woocommerce() ) { return $params; } // Set the 'View cart' text. $params['i18n_view_cart'] = __( 'Go to cart', 'alpha-single-product-for-elementor' ); // Set the 'View cart' URL. $params['cart_url'] = esc_url( wc_get_cart_url() ); return $params; } ); } /** * Admin notice * * Warning when the site doesn't have Elementor installed or activated. */ public function admin_notice_missing_main_plugin() { if ( ! current_user_can( 'activate_plugins' ) ) { return; } $message = sprintf( /* translators: 1: Plugin name 2: Elementor */ __( '"%1$s" requires "%2$s" to be installed and activated.', 'alpha-single-product-for-elementor' ), '' . __( 'Alpha Single Product Widget for Elementor', 'alpha-single-product-for-elementor' ) . '', '' . __( 'Elementor', 'alpha-single-product-for-elementor' ) . '' ); $elementor = 'elementor/elementor.php'; $pathpluginurl = \WP_PLUGIN_DIR . '/' . $elementor; $isinstalled = file_exists( $pathpluginurl ); // If installed but not activated. if ( $isinstalled && ! did_action( 'elementor/loaded' ) ) { $activation_url = wp_nonce_url( self_admin_url( 'plugins.php?action=activate&plugin=' . $elementor . '&plugin_status=all&paged=1&s' ), 'activate-plugin_' . $elementor ); $button_text = __( 'Activate Elementor', 'alpha-single-product-for-elementor' ); } else { // If not installed. $activation_url = wp_nonce_url( self_admin_url( 'update.php?action=install-plugin&plugin=elementor' ), 'install-plugin_elementor' ); $button_text = __( 'Install Elementor', 'alpha-single-product-for-elementor' ); } // Prepare button HTML. $button = sprintf( '
', esc_url( $activation_url ), esc_html( $button_text ) ); // Allowed HTML tags. $allowed_html = array( 'strong' => array(), 'p' => array(), 'a' => array( 'href' => array(), 'class' => array(), ), 'div' => array( 'class' => array(), ), ); // Output the notice. printf( '' . $message . '
', $allowed_html ), wp_kses( $button, $allowed_html ) ); } /** * Admin notice * * Warning when the site doesn't have WooCommerce installed or activated. */ public function admin_notice_missing_woocommerce() { if ( ! current_user_can( 'activate_plugins' ) ) { return; } $message = sprintf( /* translators: 1: Plugin name 2: WooCommerce */ __( '"%1$s" requires "%2$s" to be installed and activated.', 'alpha-single-product-for-elementor' ), '' . __( 'Alpha Single Product Widget for Elementor', 'alpha-single-product-for-elementor' ) . '', '' . __( 'WooCommerce', 'alpha-single-product-for-elementor' ) . '' ); $woocommerce = 'woocommerce/woocommerce.php'; $pathpluginurl = \WP_PLUGIN_DIR . '/' . $woocommerce; $isinstalled = file_exists( $pathpluginurl ); if ( $isinstalled && ! class_exists( 'woocommerce' ) ) { // WooCommerce is installed but not activated. $activation_url = wp_nonce_url( self_admin_url( 'plugins.php?action=activate&plugin=' . $woocommerce . '&plugin_status=all&paged=1&s' ), 'activate-plugin_' . $woocommerce ); $button_text = __( 'Activate WooCommerce', 'alpha-single-product-for-elementor' ); } else { // WooCommerce is not installed. $activation_url = wp_nonce_url( self_admin_url( 'update.php?action=install-plugin&plugin=woocommerce' ), 'install-plugin_woocommerce' ); $button_text = __( 'Install WooCommerce', 'alpha-single-product-for-elementor' ); } // Prepare button HTML. $button = sprintf( '', esc_url( $activation_url ), esc_html( $button_text ) ); // Allowed HTML tags. $allowed_html = array( 'strong' => array(), 'p' => array(), 'a' => array( 'href' => array(), 'class' => array(), ), 'div' => array( 'class' => array(), ), ); // Output the notice. printf( '' . $message . '
', $allowed_html ), wp_kses( $button, $allowed_html ) ); } /** * Admin notice * * Warning when the site doesn't have a minimum required Elementor version. */ public function admin_notice_minimum_elementor_version() { $message = sprintf( /* translators: 1: Plugin name, 2: Elementor, 3: Required Elementor version */ __( '"%1$s" requires the "%2$s" plugin version %3$s or greater.', 'alpha-single-product-for-elementor' ), '' . __( 'Alpha Single Product Widget for Elementor', 'alpha-single-product-for-elementor' ) . '', '' . __( 'Elementor', 'alpha-single-product-for-elementor' ) . '', esc_html( self::MINIMUM_ELEMENTOR_VERSION ) ); // Allowed HTML tags. $allowed_html = array( 'strong' => array(), 'p' => array(), 'div' => array( 'class' => array(), ), ); // Output the notice. printf( '' . $message . '
', $allowed_html ) ); } /** * Admin notice * * Warning when the site doesn't have a minimum required PHP version. */ public function admin_notice_minimum_php_version() { $message = sprintf( /* translators: 1: Plugin name, 2: PHP, 3: Required PHP version */ __( '"%1$s" requires "%2$s" version %3$s or greater.', 'alpha-single-product-for-elementor' ), '' . __( 'Alpha Single Product Widget for Elementor', 'alpha-single-product-for-elementor' ) . '', '' . __( 'PHP', 'alpha-single-product-for-elementor' ) . '', esc_html( self::MINIMUM_PHP_VERSION ) ); // Allowed HTML tags. $allowed_html = array( 'strong' => array(), 'p' => array(), 'div' => array( 'class' => array(), ), ); // Output the notice. printf( '' . $message . '
', $allowed_html ) ); } /** * Register plugin styles for Elementor widgets. */ public function register_frontend_styles() { wp_register_style( 'alphasp-widget', ALPHASP_PLUGIN_ASSETS . 'css/alpha-sp-widget.css', array(), ALPHASP_VERSION ); } /** * Register Widgets * * Load widgets files and register new Elementor widgets. * * Fired by `elementor/widgets/register` action hook. * * @param \Elementor\Widgets_Manager $widgets_manager Elementor widgets manager. */ public function register_widgets( $widgets_manager ) { // Include Widget files. include_once ALPHASP_PLUGIN_INCLUDE . '/class-alpha-single-product-widget.php'; // Register widget. $widgets_manager->register( new \Elementor_Alpha_Single_Product_Addon\Alpha_SP_Widget() ); } }