injectDependency();
}
if ( $this->is_compatible() ) {
add_action( 'elementor/init', [ $this, 'init' ] );
if ( defined( 'ATCPRO_DIR_FILE' ) ) {
if ( ! class_exists( \ATCPRO\Services\ATCWidgetPro::class ) ) {
require_once ATCPRO_DIR_PATH . 'App/Services/ATCWidgetPro.php';
}
}
}
}
/**
* Notify the user about the Advanced Pricing Table dependency and instructs to install it.
*/
protected function injectDependency()
{
add_action('admin_notices', function () {
$pluginInfo = $this->getInstallationDetails();
$class = 'notice notice-error';
$install_url_text = 'Click Here to Install the Plugin';
if ($pluginInfo->action == 'activate') {
$install_url_text = 'Click Here to Activate the Plugin';
}
$message = 'Advanced Testimonial Carousel For Elementor Add-On Requires Elementor Base Plugin, ' . $install_url_text . '';
printf('
', esc_attr($class), wp_kses_post($message));
});
}
/**
* Get the Advanced Pricing Table plugin installation information e.g. the URL to install.
*
* @return \stdClass $activation
*/
protected function getInstallationDetails()
{
$activation = (object)[
'action' => 'install',
'url' => ''
];
$allPlugins = get_plugins();
if (isset($allPlugins['elementor/elementor.php'])) {
$url = wp_nonce_url(
self_admin_url('plugins.php?action=activate&plugin=elementor/elementor.php'),
'activate-plugin_elementor/elementor.php'
);
$activation->action = 'activate';
} else {
$api = (object)[
'slug' => 'elementor'
];
$url = wp_nonce_url(
self_admin_url('update.php?action=install-plugin&plugin=' . $api->slug),
'install-plugin_' . $api->slug
);
}
$activation->url = $url;
return $activation;
}
public function atcPluginAction($links) {
$newLink = [
'' .esc_html__('Settings', 'advanced-testimonial-carousel-for-elementor'). ''
];
if (!defined('ATCPRO')) {
$goPro = wp_kses_post('' .esc_html__('Go Pro', 'advanced-testimonial-carousel-for-elementor'). '');
array_push($newLink, $goPro);
}
return array_merge($links, $newLink);
}
/**
* Compatibility Checks
*
* Checks if the installed version of Elementor meets the plugin's minimum requirement.
* Checks if the installed PHP version meets the plugin's minimum requirement.
*
* @since 4.0.0
*
* @access public
*/
public function is_compatible() {
// Check if Elementor installed and activated
if ( ! did_action( 'elementor/loaded' ) ) {
add_action( 'admin_notices', [ $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', [ $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', [ $this, 'admin_notice_minimum_php_version' ] );
return false;
}
return true;
}
/**
* Initialize the plugin
*
* Load the plugin only after Elementor (and other plugins) are loaded.
* Load the files required to run the plugin.
*
* Fired by `plugins_loaded` action hook.
*
* @since 4.0.0
*
* @access public
*/
public function init() {
$this->loadTextDomain();
if ( is_admin() ) {
$this->adminHooks();
}
// Add Plugin actions
add_action( 'elementor/widgets/widgets_registered', [ $this, 'init_widgets' ] );
add_action('elementor/frontend/after_enqueue_styles', function() {
wp_enqueue_style( 'atc-swiper-css', plugin_dir_url( __FILE__ ). 'assets/css/atc-testimonial.css', array(), ATCFE_PLUGIN_VERSION);
});
add_filter( 'plugin_action_links_'.ATCFE_PLUGIN_FILE_PATH, [$this, 'atcPluginAction'], 10, 1 );
add_action('elementor/editor/after_enqueue_styles', function() {
wp_enqueue_style( 'atc-editor-css', plugin_dir_url( __FILE__ ). 'assets/css/atc-editor.css', array(), ATCFE_PLUGIN_VERSION);
});
// after_enqueue_scripts
add_action('elementor/frontend/after_enqueue_scripts', function() {
wp_enqueue_script( 'atc-swiper-js', plugin_dir_url( __FILE__ ). 'assets/js/atc-testimonial.js', array('jquery'), ATCFE_PLUGIN_VERSION, true);
wp_localize_script('atc-swiper-js', 'atcSwiperVar', array(
'has_pro' => defined('ATCPRO')
));
});
}
public function adminHooks(){
if ( defined('ATCPRO') && class_exists( \ATCPRO\Classes\LicenseController::class ) ) {
$licenseController = new \ATCPRO\Classes\LicenseController();
$licenseController->handleAjaxCalls();
}
$setupController = new ATCFE\Http\Controllers\SetupController();
$setupController->register();
$googleReviewsSettingsController = new ATCFE\Http\Controllers\GoogleReviewsSettingsController();
$googleReviewsSettingsController->register();
if (defined('ELEMENTOR_VERSION')) {
add_action('admin_init', [new ATCFE\Handlers\AdminPageHandler(), 'initialLoad']);
}
add_action( 'admin_notices', [$this, 'atc_admin_notice'] );
add_action( 'admin_init', [$this, 'atc_notice_dismissed'] );
}
public function atc_admin_notice() {
$screen = get_current_screen();
$user_id = get_current_user_id();
$nonce = wp_create_nonce('atc_dismiss_notice_nonce');
// Ensure user meta exists
if (!get_user_meta($user_id, 'atc-notice-dismissed', true)) {
add_user_meta($user_id, 'atc-notice-dismissed', 'active');
}
// Show notice only on specific screens
if ($screen && in_array($screen->id, ['dashboard', 'plugins'], true)) {
if (get_user_meta($user_id, 'atc-notice-dismissed', true) === 'active') {
?>
widgets_manager->register_widget_type( new ATCFE\Classes\Widgets\ATCTestimonialWidget() );
}
public function loadTextDomain()
{
}
/**
* Admin notice
*
* Warning when the site doesn't have Elementor installed or activated.
*
* @since 4.0.0
*
* @access public
*/
public function admin_notice_missing_main_plugin() {
// phpcs:ignore WordPress.Security.NonceVerification.Recommended -- WordPress activation parameter.
if ( isset( $_GET['activate'] ) ) {
unset( $_GET['activate'] );
}
$message = sprintf(
/* translators: 1: Plugin name 2: Elementor */
esc_html__( '"%1$s" requires "%2$s" to be installed and activated.', 'advanced-testimonial-carousel-for-elementor' ),
'' . esc_html__( 'Advanced Testimonial Carousel', 'advanced-testimonial-carousel-for-elementor' ) . '',
'' . esc_html__( 'Elementor', 'advanced-testimonial-carousel-for-elementor' ) . ''
);
printf( '', wp_kses_post($message) );
}
/**
* Admin notice
*
* Warning when the site doesn't have a minimum required Elementor version.
*
* @since 4.0.0
*
* @access public
*/
public function admin_notice_minimum_elementor_version() {
// phpcs:ignore WordPress.Security.NonceVerification.Recommended -- WordPress activation parameter.
if ( isset($_GET['activate']) ) {
unset( $_GET['activate'] );
}
$message = sprintf(
/* translators: 1: Plugin name 2: Elementor 3: Required Elementor version */
esc_html__( '"%1$s" requires "%2$s" version %3$s or greater.', 'advanced-testimonial-carousel-for-elementor' ),
'' . esc_html__( 'Advanced Testimonial Carousel', 'advanced-testimonial-carousel-for-elementor' ) . '',
self::MINIMUM_ELEMENTOR_VERSION
);
printf( '', wp_kses_post($message) );
}
/**
* Admin notice
*
* Warning when the site doesn't have a minimum required PHP version.
*
* @since 4.0.0
*
* @access public
*/
public function admin_notice_minimum_php_version() {
// phpcs:ignore WordPress.Security.NonceVerification.Recommended -- WordPress activation parameter.
if ( isset($_GET['activate']) ) {
unset( $_GET['activate'] );
}
$message = sprintf(
/* translators: 1: Plugin name 2: PHP 3: Required PHP version */
esc_html__( '"%1$s" requires "%2$s" version %3$s or greater.', 'advanced-testimonial-carousel-for-elementor' ),
'' . esc_html__( 'Advanced Testimonial Carousel', 'advanced-testimonial-carousel-for-elementor' ) . '',
'' . esc_html__( 'PHP', 'advanced-testimonial-carousel-for-elementor' ) . '',
self::MINIMUM_PHP_VERSION
);
printf( '', wp_kses_post($message) );
}
}
AdvancedTestimonialCarousel::instance();
register_activation_hook(__FILE__, function ($network_wide) {
require_once(ATCFE_PLUGIN_DIR_PATH . 'app/Handlers/ActivationHandler.php');
ATCFE\Handlers\ActivationHandler::activate($network_wide);
});
register_deactivation_hook(__FILE__, function ($network_wide) {
$user_id = get_current_user_id();
update_user_meta($user_id, 'atc-notice-dismissed', 'active');
require_once(ATCFE_PLUGIN_DIR_PATH . 'app/Handlers/DeactivationHandler.php');
ATCFE\Handlers\DeactivationHandler::deActivate($network_wide);
});