@@ -57,8 +57,21 @@ public function process_action() {
57
57
return ;
58
58
}
59
59
60
+ if ( ! $ this ->current_action () ) {
61
+ return ;
62
+ }
63
+
64
+ $ redirect_to = \add_query_arg (
65
+ array (
66
+ 'settings-updated ' => true , // Tell WordPress to load settings errors transient.
67
+ 'action ' => false , // Remove action parameter to prevent redirect loop.
68
+ )
69
+ );
70
+
60
71
switch ( $ this ->current_action () ) {
61
72
case 'delete ' :
73
+ $ redirect_to = \remove_query_arg ( array ( 'follower ' , 'following ' ), $ redirect_to );
74
+
62
75
// Handle single follower deletion.
63
76
if ( isset ( $ _GET ['follower ' ], $ _GET ['_wpnonce ' ] ) ) {
64
77
$ follower = \absint ( $ _GET ['follower ' ] );
@@ -67,13 +80,7 @@ public function process_action() {
67
80
if ( \wp_verify_nonce ( $ nonce , 'delete-follower_ ' . $ follower ) ) {
68
81
Following_Collection::unfollow ( $ follower , $ this ->user_id );
69
82
70
- $ redirect_args = array (
71
- 'updated ' => 'true ' ,
72
- 'action ' => 'deleted ' ,
73
- );
74
-
75
- \wp_safe_redirect ( \add_query_arg ( $ redirect_args , \remove_query_arg ( array ( 'follower ' ) ) ) );
76
- exit ;
83
+ \add_settings_error ( 'activitypub ' , 'follower_deleted ' , \__ ( 'Account unfollowed. ' , 'activitypub ' ), 'success ' );
77
84
}
78
85
}
79
86
@@ -88,52 +95,31 @@ public function process_action() {
88
95
Following_Collection::unfollow ( $ post_id , $ this ->user_id );
89
96
}
90
97
91
- $ redirect_args = array (
92
- 'updated ' => 'true ' ,
93
- 'action ' => 'all_deleted ' ,
94
- 'count ' => \count ( $ following ),
95
- );
98
+ $ count = \count ( $ following );
99
+ /* translators: %d: Number of accounts unfollowed. */
100
+ $ message = \_n ( '%d account unfollowed. ' , '%d accounts unfollowed. ' , $ count , 'activitypub ' );
101
+ $ message = \sprintf ( $ message , \number_format_i18n ( $ count ) );
96
102
97
- \wp_safe_redirect ( \add_query_arg ( $ redirect_args , \remove_query_arg ( array ( 'following ' ) ) ) );
98
- exit ;
103
+ \add_settings_error ( 'activitypub ' , 'followers_deleted ' , $ message , 'success ' );
99
104
}
100
105
}
101
106
break ;
102
107
103
108
default :
104
109
break ;
105
110
}
111
+
112
+ \set_transient ( 'settings_errors ' , get_settings_errors (), 30 ); // 30 seconds.
113
+
114
+ \wp_safe_redirect ( $ redirect_to );
115
+ exit ;
106
116
}
107
117
108
118
/**
109
119
* Process admin notices based on query parameters.
110
120
*/
111
121
public function process_admin_notices () {
112
- if ( isset ( $ _REQUEST ['updated ' ] ) && 'true ' === $ _REQUEST ['updated ' ] && ! empty ( $ _REQUEST ['action ' ] ) ) { // phpcs:ignore WordPress.Security.NonceVerification
113
- $ message = '' ;
114
- switch ( $ _REQUEST ['action ' ] ) { // phpcs:ignore WordPress.Security.NonceVerification
115
- case 'deleted ' :
116
- $ message = \__ ( 'Account unfollowed. ' , 'activitypub ' );
117
- break ;
118
- case 'all_deleted ' :
119
- $ count = \absint ( $ _REQUEST ['count ' ] ?? 0 ); // phpcs:ignore WordPress.Security.NonceVerification
120
- /* translators: %d: Number of accounts unfollowed. */
121
- $ message = \_n ( '%d account unfollowed. ' , '%d accounts unfollowed. ' , $ count , 'activitypub ' );
122
- $ message = \sprintf ( $ message , \number_format_i18n ( $ count ) );
123
- break ;
124
- }
125
-
126
- if ( ! empty ( $ message ) ) {
127
- \wp_admin_notice (
128
- $ message ,
129
- array (
130
- 'type ' => 'success ' ,
131
- 'dismissible ' => true ,
132
- 'id ' => 'message ' ,
133
- )
134
- );
135
- }
136
- }
122
+ \settings_errors ( 'activitypub ' );
137
123
}
138
124
139
125
/**
0 commit comments