PluginProbe ʕ •ᴥ•ʔ
Download Manager / trunk
Download Manager vtrunk
3.3.61 3.3.60 3.3.59 3.3.58 3.3.57 3.3.56 trunk 2.1.3 2.3.0 2.5.96 2.5.97 2.6.2 2.6.96 2.8.3 2.9.99 3.0.4 3.1.05 3.1.07 3.1.08 3.1.11 3.1.12 3.1.14 3.1.17 3.1.18 3.1.22 3.1.23 3.1.24 3.1.25 3.1.26 3.1.27 3.1.28 3.2.04 3.2.13 3.2.14 3.2.16 3.2.18 3.2.19 3.2.21 3.2.22 3.2.23 3.2.24 3.2.25 3.2.27 3.2.28 3.2.29 3.2.30 3.2.31 3.2.32 3.2.33 3.2.34 3.2.35 3.2.37 3.2.38 3.2.39 3.2.40 3.2.41 3.2.42 3.2.43 3.2.44 3.2.45 3.2.46 3.2.47 3.2.48 3.2.49 3.2.50 3.2.51 3.2.52 3.2.53 3.2.54 3.2.55 3.2.56 3.2.57 3.2.58 3.2.59 3.2.60 3.2.61 3.2.63 3.2.64 3.2.65 3.2.66 3.2.67 3.2.68 3.2.69 3.2.70 3.2.71 3.2.72 3.2.73 3.2.74 3.2.75 3.2.76 3.2.77 3.2.78 3.2.79 3.2.80 3.2.81 3.2.82 3.2.83 3.2.84 3.2.85 3.2.86 3.2.87 3.2.88 3.2.89 3.2.90 3.2.91 3.2.92 3.2.93 3.2.94 3.2.95 3.2.96 3.2.97 3.2.98 3.2.99 3.3.00 3.3.01 3.3.02 3.3.03 3.3.04 3.3.05 3.3.06 3.3.07 3.3.08 3.3.09 3.3.10 3.3.11 3.3.12 3.3.13 3.3.14 3.3.15 3.3.16 3.3.17 3.3.18 3.3.19 3.3.20 3.3.21 3.3.22 3.3.23 3.3.24 3.3.25 3.3.26 3.3.27 3.3.28 3.3.29 3.3.30 3.3.31 3.3.32 3.3.33 3.3.34 3.3.35 3.3.36 3.3.37 3.3.38 3.3.39 3.3.40 3.3.41 3.3.42 3.3.43 3.3.44 3.3.45 3.3.46 3.3.47 3.3.48 3.3.49 3.3.50 3.3.51 3.3.52 3.3.53 3.3.54 3.3.55
download-manager / src / Admin / Menu / Welcome.php
download-manager / src / Admin / Menu Last commit date
AddOns.php 4 years ago Categories.php 3 years ago Packages.php 4 days ago Settings.php 5 months ago Stats.php 4 years ago Templates.php 2 years ago Welcome.php 5 months ago
Welcome.php
166 lines
1 <?php
2
3 namespace WPDM\Admin\Menu;
4
5 class Welcome
6 {
7 function __construct()
8 {
9 add_action('admin_menu', array($this, 'Menu'));
10 add_action('admin_init', array($this, 'maybeRedirect'), 1); // Priority 1 to run early
11 add_action('wp_ajax_wpdm_create_dashboard_page', array($this, 'createDashboardPage'));
12
13 // Handle immediate redirect after plugin activation (non-AJAX activations)
14 add_action('activated_plugin', array($this, 'activationRedirect'), 10, 2);
15 }
16
17 /**
18 * Immediate redirect after plugin activation (for non-AJAX activations)
19 */
20 function activationRedirect($plugin, $network_wide)
21 {
22 // Only for this plugin (WPDM_BASE_DIR already has trailing slash)
23 if ($plugin !== plugin_basename(WPDM_BASE_DIR . 'download-manager.php')) {
24 return;
25 }
26
27 // Skip for network activation
28 if ($network_wide) {
29 return;
30 }
31
32 // Skip for bulk activations (check both the action and the flag)
33 // During bulk activation, action is 'activate-selected', activate-multi is set after redirect
34 if (isset($_GET['activate-multi']) ||
35 (isset($_REQUEST['action']) && $_REQUEST['action'] === 'activate-selected') ||
36 (isset($_REQUEST['action2']) && $_REQUEST['action2'] === 'activate-selected') ||
37 (isset($_POST['checked']) && is_array($_POST['checked']) && count($_POST['checked']) > 1)) {
38 return;
39 }
40
41 // Skip for AJAX requests (will be handled by maybeRedirect on next page load)
42 if (wp_doing_ajax()) {
43 return;
44 }
45
46 // Skip if headers already sent
47 if (headers_sent()) {
48 return;
49 }
50
51 // Redirect immediately
52 wp_safe_redirect(admin_url('index.php?page=wpdm-welcome'));
53 exit;
54 }
55
56 /**
57 * AJAX handler to create dashboard page
58 */
59 function createDashboardPage()
60 {
61 if (!wp_verify_nonce($_POST['_wpnonce'] ?? '', 'wpdm_create_dashboard')) {
62 wp_send_json_error(__('Security check failed', 'download-manager'));
63 }
64
65 if (!current_user_can('publish_pages')) {
66 wp_send_json_error(__('Permission denied', 'download-manager'));
67 }
68
69 $page_id = wp_insert_post([
70 'post_title' => __('User Dashboard', 'download-manager'),
71 'post_content' => '[wpdm_user_dashboard]',
72 'post_status' => 'publish',
73 'post_type' => 'page',
74 ]);
75
76 if (is_wp_error($page_id)) {
77 wp_send_json_error($page_id->get_error_message());
78 }
79
80 update_option('__wpdm_user_dashboard', $page_id);
81
82 wp_send_json_success([
83 'page_id' => $page_id,
84 'title' => get_the_title($page_id),
85 'edit_url' => get_edit_post_link($page_id, 'raw'),
86 ]);
87 }
88
89 function Menu()
90 {
91 add_dashboard_page('Welcome', 'Welcome', 'read', 'wpdm-welcome', array($this, 'UI'));
92 }
93
94 function UI()
95 {
96 update_option('__wpdm_welcome', WPDM_VERSION, false);
97 delete_transient('wpdm_activation_redirect');
98 delete_option('__wpdm_activation_redirect');
99 //remove_submenu_page('index.php', 'wpdm-welcome');
100 include wpdm_admin_tpl_path('welcome.php', dirname(__DIR__) . '/views');
101 }
102
103 /**
104 * Redirect to welcome page if activation flag is set
105 * The flag is set in WordPressDownloadManager::install() via register_activation_hook
106 */
107 function maybeRedirect()
108 {
109 // Check for redirect flag (transient or option as backup)
110 $redirect_transient = get_transient('wpdm_activation_redirect');
111 $redirect_option = get_option('__wpdm_activation_redirect');
112
113 if ($redirect_transient !== 'yes' && $redirect_option !== 'yes') {
114 return;
115 }
116
117 // Delete the flags immediately to prevent redirect loops
118 delete_transient('wpdm_activation_redirect');
119 delete_option('__wpdm_activation_redirect');
120
121 // Skip for WP-CLI
122 if (defined('WP_CLI') && WP_CLI) {
123 return;
124 }
125
126 // Skip for bulk activations
127 if (isset($_GET['activate-multi'])) {
128 return;
129 }
130
131 // Skip for AJAX requests
132 if (wp_doing_ajax()) {
133 return;
134 }
135
136 // Skip for cron
137 if (wp_doing_cron()) {
138 return;
139 }
140
141 // Skip for REST API requests
142 if (defined('REST_REQUEST') && REST_REQUEST) {
143 return;
144 }
145
146 // Skip if user doesn't have capability
147 if (!current_user_can('manage_options')) {
148 return;
149 }
150
151 // Skip if headers already sent
152 if (headers_sent()) {
153 return;
154 }
155
156 // Skip if already on the welcome page
157 if (isset($_GET['page']) && $_GET['page'] === 'wpdm-welcome') {
158 return;
159 }
160
161 // Redirect to welcome page
162 wp_safe_redirect(admin_url('index.php?page=wpdm-welcome'));
163 exit;
164 }
165 }
166