Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Binary file added languages/brave-hooks-nl_NL.mo
Binary file not shown.
11 changes: 11 additions & 0 deletions languages/brave-hooks-nl_NL.po
Original file line number Diff line number Diff line change
@@ -0,0 +1,11 @@
msgid "Focus point of the featured image"
msgstr "Focuspunt van de uitgelichte afbeelding"

msgid "Reassign Posts"
msgstr "Berichten opnieuw toewijzen"

msgid "Select a user to reassign posts to (optional):"
msgstr "Selecteer een gebruiker om berichten aan toe te wijzen (optioneel):"

msgid "-- No reassignment --"
msgstr "-- Geen hertoekenning --"
29 changes: 29 additions & 0 deletions languages/brave-hooks.pot
Original file line number Diff line number Diff line change
@@ -0,0 +1,29 @@
msgid ""
msgstr ""
"Project-Id-Version: \n"
"Report-Msgid-Bugs-To: \n"
"Last-Translator: FULL NAME <EMAIL@ADDRESS>\n"
"Language-Team: LANGUAGE <LL@li.org>\n"
"MIME-Version: 1.0\n"
"Content-Type: text/plain; charset=UTF-8\n"
"Content-Transfer-Encoding: 8bit\n"
"POT-Creation-Date: 2025-12-09T14:48:38+00:00\n"
"PO-Revision-Date: YEAR-MO-DA HO:MI+ZONE\n"
"X-Generator: WP-CLI 2.11.0\n"
"X-Domain: brave-hooks\n"

#: src/Theme.php:102
msgid "Focuspunt van de uitgelichte afbeelding"
msgstr ""

#: src/User.php:128
msgid "Reassign Posts"
msgstr ""

#: src/User.php:129
msgid "Select a user to reassign posts to (optional):"
msgstr ""

#: src/User.php:133
msgid "-- No reassignment --"
msgstr ""
2 changes: 2 additions & 0 deletions src/HookServiceProvider.php
Original file line number Diff line number Diff line change
Expand Up @@ -28,6 +28,8 @@ public function packageRegistered(): void

public function packageBooted(): void
{
load_textdomain('brave-hooks', __DIR__ . '/../languages/brave-hooks-' . determine_locale() . '.mo');

app(Registrar::class)->registerHooks();
}
}
2 changes: 1 addition & 1 deletion src/Theme.php
Original file line number Diff line number Diff line change
Expand Up @@ -99,7 +99,7 @@ public function registerFeaturedImageFocalPoint(): void
{
register_post_meta('', 'featured_image_focal_point', [
'type' => 'object',
'description' => __('Focuspunt van de uitgelichte afbeelding', 'sage'),
'description' => __('Focus point of the featured image', 'brave-hooks'),
'single' => true,
'show_in_rest' => [
'schema' => [
Expand Down
100 changes: 100 additions & 0 deletions src/User.php
Original file line number Diff line number Diff line change
Expand Up @@ -17,6 +17,74 @@ public function scheduleDeleteNetworkUser(int $userID): void
\wp_schedule_single_event(time() + 5, self::DELETE_NETWORK_USER_CRON_HOOK, [$userID]);
}

#[Action('remove_user_from_blog')]
public function handleRemoveUserFromBlog(int $userId, int $blogId): void
{
if (! is_admin() || get_current_blog_id() !== $blogId) {
return;
}

$userPosts = get_posts([
'author' => $userId,
'post_type' => 'any',
'posts_per_page' => 1,
'fields' => 'ids',
]);

if ($userPosts) {
wp_safe_redirect(admin_url('users.php?action=remove&user=' . $userId));
exit;
}
}

#[Action('all_admin_notices')]
public function showReassignPostsNotice(): void
{
if (! $this->shouldDisplay()) {
return;
}

$userId = (int) sanitize_text_field($_GET['user']);
$userPosts = get_posts([
'author' => $userId,
'post_type' => 'any',
'posts_per_page' => 1,
'fields' => 'ids',
]);

if ($userPosts && empty($_POST['reassign_user'])) {
Comment thread
hnccox-yard marked this conversation as resolved.
$users = get_users(['exclude' => [$userId]]);
$this->renderReassignUserSelect($users, $userId);
}
}

#[Action('admin_init')]
Comment thread
hnccox-yard marked this conversation as resolved.
public function handleAdminInit(): void
{
if (! $this->shouldDisplay()) {
return;
}

if (! isset($_POST['submit']) || empty($_POST['reassign_user'])) {
return;
}

$userId = (int) sanitize_text_field($_GET['user']);
if (get_user($userId) === false) {
return;
}

$reassignUserId = (int) sanitize_text_field($_POST['reassign_user']);
if (get_user($reassignUserId) === false) {
return;
}

remove_user_from_blog($userId, get_current_blog_id(), $reassignUserId);

wp_redirect(admin_url('users.php?message=removed'));
exit;
}

#[Filter(self::DELETE_NETWORK_USER_CRON_HOOK)]
public function deleteNetworkUser(int $id): void
{
Expand Down Expand Up @@ -44,4 +112,36 @@ public function setLoginUrl(string $url, string $path, ?string $scheme): string

return site_url($path, $scheme);
}

protected function shouldDisplay(): bool
{
if (! isset($_GET['action'], $_GET['user'])) {
return false;
}

if ('remove' !== $_GET['action']) {
return false;
}

if (! current_user_can('remove_user', (int) $_GET['user'])) {
return false;
}

return true;
}

protected function renderReassignUserSelect(array $users, int $userId): void
{
echo '<div class="notice notice-warning">
<h2>' . esc_html__('Reassign Posts', 'brave-hooks') . '</h2>
<p>' . esc_html__('Select a user to reassign posts to (optional):', 'brave-hooks') . '</p>';
wp_dropdown_users([
'exclude' => [$userId],
'name' => 'reassign_user',
'show_option_none' => esc_html__('-- No reassignment --', 'brave-hooks'),
'option_none_value' => -1,
'selected' => -1,
]);
echo '<br><br></div>';
}
}