' . esc_html__('Elementor Advanced Gallery requires Elementor plugin to be active. Please activate Elementor to continue.', 'advanced-image-gallery') . '

' . esc_html__('Activate Elementor', 'advanced-image-gallery') . '

'); } } // Prevent plugin activation if Elementor is not active function zlfms_activate_plugin() { if (!did_action('elementor/loaded')) { deactivate_plugins(plugin_basename(__FILE__)); // Deactivate this plugin wp_die( esc_html__('Elementor Advanced Gallery requires Elementor to be installed and activated. The plugin has been deactivated.', 'advanced-image-gallery'), esc_html__('Plugin dependency check failed', 'advanced-image-gallery'), array('back_link' => true) ); } } register_activation_hook(__FILE__, 'zlfms_activate_plugin'); /** * Store the plugin installation time for later use. */ function zlfms_aig_set_install_time() { if (false === get_option('zlfms_aig_install_time')) { add_option('zlfms_aig_install_time', time()); } } register_activation_hook(__FILE__, 'zlfms_aig_set_install_time'); // Register the widget only if Elementor is active function zlfms_register_media_gallery($widgets_manager) { if (!did_action('elementor/loaded')) { return; // Stop if Elementor is not active } require_once plugin_dir_path(__FILE__) . 'widgets/class-image-gallery-widget.php'; $widgets_manager->register(new zlfms_advanced_image_gallery()); } add_action('elementor/widgets/register', 'zlfms_register_media_gallery'); /** * Parse video URL and return video details for embedding. * * @param string $video_url The video URL to parse * @return array|false Array with 'video_id', 'embed_url', 'video_type' or false on failure */ function zlfms_parse_video_url($video_url) { if (empty($video_url)) { return false; } $video_url = esc_url($video_url); $matches = []; // YouTube URL patterns if (preg_match('/(?:https?:\/\/)?(?:www\.)?(?:youtube\.com\/(?:[^\/\n\s]+\/\S+\/|(?:v|e(?:mbed)?)\/|\S*?[?&]v=)|youtu\.be\/)([a-zA-Z0-9_-]{11})/', $video_url, $matches)) { return [ 'video_id' => $matches[1], 'embed_url' => 'https://www.youtube.com/embed/' . esc_attr($matches[1]), 'video_type' => 'youtube' ]; } // Vimeo URL patterns if (preg_match('/(?:https?:\/\/)?(?:www\.)?(?:vimeo\.com\/(?:channels\/(?:\w+\/)?|groups\/(?:\w+\/)?videos\/|album\/(\d+)\/video\/|video\/|)(\d+)(?:$|\/|\?))/', $video_url, $matches)) { return [ 'video_id' => $matches[2], 'embed_url' => 'https://player.vimeo.com/video/' . esc_attr($matches[2]), 'video_type' => 'vimeo' ]; } return false; } add_action('admin_enqueue_scripts', 'zlfms_register_advanced_gallery_admin_assets'); function zlfms_register_advanced_gallery_admin_assets($hook_suffix) { // Register the style for the block editor. wp_register_style( 'zlfms-counter-block-gallery', plugins_url('assets/css/admin_gallery.css', __FILE__), // URL to the CSS file [], // Dependencies: WordPress block editor styles filemtime(plugin_dir_path(__FILE__) . 'assets/css/admin_gallery.css') // Version parameter: File modification time for cache-busting ); // Load assets only on the Plugins page. if ($hook_suffix === 'plugins.php') { // Enqueue the registered style wp_enqueue_style('zlfms-counter-block-gallery'); // Enqueue the script for the deactivation popup wp_enqueue_script( 'zlfms-admin', plugin_dir_url(__FILE__) . 'assets/js/deactivation-feedback.js', // URL to the JavaScript file array('jquery'), // Dependencies: jQuery filemtime(plugin_dir_path(__FILE__) . 'assets/js/deactivation-feedback.js'), // Version parameter: File modification time for cache-busting true // Load the script in the footer ); // Localize the script with necessary data wp_localize_script('zlfms-admin', 'zl_ajax_obj', array( 'ajax_url' => admin_url('admin-ajax.php'), // URL for AJAX requests 'nonce' => wp_create_nonce('zlfms_deactivation_nonce') // Nonce for security )); } } /** * Handle review notice actions. */ function zlfms_aig_handle_review_actions() { if (! isset($_GET['zlfms_aig_review_action']) || ! current_user_can('manage_options')) { return; } if (! isset($_GET['_wpnonce']) || ! wp_verify_nonce(sanitize_text_field(wp_unslash($_GET['_wpnonce'])), 'zlfms_aig_review_action')) { return; } $action = sanitize_text_field(wp_unslash($_GET['zlfms_aig_review_action'])); switch ($action) { case 'done': update_option('zlfms_aig_review_status', 'done'); wp_safe_redirect(remove_query_arg(array('zlfms_aig_review_action', '_wpnonce'))); exit; case 'review_now': $week_in_seconds = defined('WEEK_IN_SECONDS') ? WEEK_IN_SECONDS : 604800; update_option('zlfms_aig_review_dismissed_until', time() + $week_in_seconds); // Fixed, trusted wordpress.org URL; wp_safe_redirect() would reject this external host. wp_redirect('https://wordpress.org/support/plugin/advanced-image-gallery/reviews/#new-post'); // phpcs:ignore WordPress.Security.SafeRedirect.wp_redirect_wp_redirect exit; case 'later': $week_in_seconds = defined('WEEK_IN_SECONDS') ? WEEK_IN_SECONDS : 604800; update_option('zlfms_aig_review_dismissed_until', time() + $week_in_seconds); wp_safe_redirect(remove_query_arg(array('zlfms_aig_review_action', '_wpnonce'))); exit; } } add_action('admin_init', 'zlfms_aig_handle_review_actions'); /** * Display a review notice in the admin area after seven days. */ function zlfms_aig_review_notice() { if (! current_user_can('manage_options')) { return; } $status = get_option('zlfms_aig_review_status'); $install_time = (int) get_option('zlfms_aig_install_time', 0); $dismissed_until = (int) get_option('zlfms_aig_review_dismissed_until', 0); if ('done' === $status || ! $install_time) { return; } // Check if 7 days have passed since installation (7 * 24 * 60 * 60 = 604800 seconds) $week_in_seconds = defined('WEEK_IN_SECONDS') ? WEEK_IN_SECONDS : 604800; if (time() - $install_time < $week_in_seconds || time() < $dismissed_until) { return; } $base_url = remove_query_arg(array('zlfms_aig_review_action', '_wpnonce')); $did_url = wp_nonce_url(add_query_arg('zlfms_aig_review_action', 'done', $base_url), 'zlfms_aig_review_action'); $now_url = wp_nonce_url(add_query_arg('zlfms_aig_review_action', 'review_now', $base_url), 'zlfms_aig_review_action'); $later_url = wp_nonce_url(add_query_arg('zlfms_aig_review_action', 'later', $base_url), 'zlfms_aig_review_action'); echo '

' . esc_html__('Enjoying Advanced Image Gallery? Please consider leaving a review to support the project.', 'advanced-image-gallery') . '

' . esc_html__('I did', 'advanced-image-gallery') . ' | ' . esc_html__('Review now', 'advanced-image-gallery') . ' | ' . esc_html__('Later', 'advanced-image-gallery') . '

'; } add_action('admin_notices', 'zlfms_aig_review_notice');