altm-initialize-all-settings-values.php
5 months ago
altm-plugin-activation-flow.php
5 months ago
altm-supported-languages.php
5 months ago
altm-plugin-activation-flow.php
62 lines
| 1 | <?php |
| 2 | |
| 3 | // Ensure this file is not accessed directly |
| 4 | if (!defined('ABSPATH')) exit; |
| 5 | |
| 6 | |
| 7 | // Define the path to the main plugin file |
| 8 | define('ALT_MAGIC_PLUGIN_FILE', dirname(__DIR__) . '/altm-main-file.php'); |
| 9 | |
| 10 | // Hook into plugin activation |
| 11 | register_activation_hook(ALT_MAGIC_PLUGIN_FILE, 'alt_magic_activate'); |
| 12 | |
| 13 | function alt_magic_activate() { |
| 14 | // Set a transient to trigger the redirect |
| 15 | if (set_transient('_alt_magic_activation_redirect', true, 30)) { |
| 16 | //altm_log('Transient set successfully.'); |
| 17 | } |
| 18 | // else { |
| 19 | // altm_log('Failed to set transient.'); |
| 20 | // } |
| 21 | |
| 22 | // Trigger plugin activation event |
| 23 | do_action('alt_magic_plugin_activated'); |
| 24 | } |
| 25 | |
| 26 | // Hook into plugin deactivation |
| 27 | register_deactivation_hook(ALT_MAGIC_PLUGIN_FILE, 'alt_magic_deactivate'); |
| 28 | |
| 29 | function alt_magic_deactivate() { |
| 30 | // Trigger plugin deactivation event |
| 31 | do_action('alt_magic_plugin_deactivated'); |
| 32 | } |
| 33 | |
| 34 | // Hook into admin initialization to handle the redirect |
| 35 | add_action('admin_init', 'alt_magic_redirect_to_account_settings'); |
| 36 | |
| 37 | function alt_magic_redirect_to_account_settings() { |
| 38 | // Check if the transient is set |
| 39 | if (get_transient('_alt_magic_activation_redirect')) { |
| 40 | //altm_log('Transient found, redirecting...'); |
| 41 | // Delete the transient |
| 42 | delete_transient('_alt_magic_activation_redirect'); |
| 43 | |
| 44 | // Redirect to the account settings page |
| 45 | wp_safe_redirect(admin_url('admin.php?page=alt-magic')); |
| 46 | exit; |
| 47 | } |
| 48 | // else { |
| 49 | // altm_log('Transient not found.'); |
| 50 | // } |
| 51 | } |
| 52 | |
| 53 | // Add settings link on plugin page |
| 54 | add_filter('plugin_action_links_' . plugin_basename(ALT_MAGIC_PLUGIN_FILE), 'alt_magic_add_settings_link'); |
| 55 | |
| 56 | function alt_magic_add_settings_link($links) { |
| 57 | $settings_link = '<a href="' . admin_url('admin.php?page=alt-magic-ai-settings') . '">' . __('AI Settings', 'alt-magic-ai-powered-alt-texts') . '</a>'; |
| 58 | array_unshift($links, $settings_link); |
| 59 | return $links; |
| 60 | } |
| 61 | |
| 62 | ?> |