Skip to content

Commit 2964663

Browse files
davefxDavid Marín
authored andcommitted
Adding notice explaining what the plugin has done
1 parent b430a0b commit 2964663

File tree

1 file changed

+54
-1
lines changed

1 file changed

+54
-1
lines changed

dfx-random-user-id.php

Lines changed: 54 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -8,7 +8,7 @@
88
Author URI: https://davefx.com
99
License: GPL3
1010
License URI: https://www.gnu.org/licenses/gpl-3.0.html
11-
Text Domain: davefx
11+
Text Domain: dfx-random-user-id
1212
Domain Path: /languages
1313
*/
1414

@@ -57,6 +57,7 @@ function dfx_random_user_randomize_first_user() {
5757
// Check that user with ID=1 exists
5858
$user = get_userdata( 1 );
5959
if ( ! $user ) {
60+
6061
return;
6162
}
6263

@@ -80,8 +81,60 @@ function dfx_random_user_randomize_first_user() {
8081
// Hook to allow other plugins to update their tables
8182
do_action( 'dfx_randomuserid_first_user_id_changed', 1, $new_id );
8283

84+
update_option('dfx_randomuserid_first_user_moved_to', $new_id, false );
85+
86+
delete_option( 'dfx_randomuserid_activation_notice_dismissed' );
87+
8388
}
8489

8590
}
8691

8792
register_activation_hook( __FILE__, 'dfx_random_user_randomize_first_user' );
93+
94+
if ( ! function_exists( 'dfx_random_user_show_activation_msg') ) {
95+
function dfx_random_user_show_activation_msg() {
96+
97+
if ( ! get_option( 'dfx_randomuserid_activation_notice_dismissed' ) ) {
98+
99+
$first_user_new_id = get_option( 'dfx_randomuserid_first_user_moved_to' );
100+
101+
$message = '<p>' . __( 'Random User IDs plugin has been successfully activated.', 'dfx-random-user-id' ) . '</p>';
102+
103+
if ( ! $first_user_new_id ) {
104+
$message .= '<p>' . __( 'There was no user with ID=1 already, so no user ID has been randomized.', 'dfx-random-user-id' ) . '</p>';
105+
} else {
106+
107+
$admin_user = get_userdata( $first_user_new_id );
108+
109+
$message .= sprintf( '<p>' . __( 'The ID for user `%s` has been moved from 1 to %d.', 'dfx-random-user-id' ) . '</p>', $admin_user->nickname, $first_user_new_id );
110+
111+
$message .= '<p>' . __( 'This plugin is designed to better being activated in first place, before any other plugin or theme', 'dfx-random-user-id' ) . '</p>';
112+
113+
$message .= '<p>' . sprintf( __( 'If there are any previously installed theme or plugin that added tables to the database, you should check if any field in these tables includes user_ids, and manually replace all the rows referencing user_id 1 with the new user_id %d', 'dfx-random-user-id' ), $first_user_new_id ) . '</p>';
114+
115+
}
116+
117+
?>
118+
<div class="updated notice is-dismissible" data-notice="dfx_random_user_activation_msg">
119+
<p><?= $message ?></p>
120+
<p style="text-align: right;"><a href="?dfx_randomuserid_dismiss_notice"><?= __( 'Dismiss', 'dfx-random-user-id' ) ?></a></p>
121+
</div>
122+
<?php
123+
}
124+
}
125+
}
126+
127+
add_action( 'admin_notices', 'dfx_random_user_show_activation_msg' );
128+
129+
if ( ! function_exists( 'dfx_random_user_dismissed_activation_msg') ) {
130+
function dfx_random_user_dismissed_activation_msg() {
131+
132+
if (isset($_GET['dfx_randomuserid_dismiss_notice'])) {
133+
134+
update_option( 'dfx_randomuserid_activation_notice_dismissed', 'true', true );
135+
136+
}
137+
}
138+
}
139+
140+
add_action( 'admin_init', 'dfx_random_user_dismissed_activation_msg' );

0 commit comments

Comments
 (0)