Skip to content

Commit e3220cc

Browse files
authored
Add domain blocklist importer (#2589)
1 parent 83d654b commit e3220cc

File tree

6 files changed

+822
-1
lines changed

6 files changed

+822
-1
lines changed
Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,4 @@
1+
Significance: minor
2+
Type: added
3+
4+
Add domain blocklist importer for bulk importing blocked domains.

includes/class-moderation.php

Lines changed: 32 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -223,6 +223,38 @@ public static function add_site_block( $type, $value ) {
223223
return true; // Already blocked.
224224
}
225225

226+
/**
227+
* Add multiple site-wide blocks at once.
228+
*
229+
* More efficient than calling add_site_block() in a loop as it
230+
* performs a single database update.
231+
*
232+
* @param string $type The block type (domain or keyword only).
233+
* @param array $values Array of values to block.
234+
*/
235+
public static function add_site_blocks( $type, $values ) {
236+
if ( ! in_array( $type, array( self::TYPE_DOMAIN, self::TYPE_KEYWORD ), true ) ) {
237+
return;
238+
}
239+
240+
if ( empty( $values ) ) {
241+
return;
242+
}
243+
244+
foreach ( $values as $value ) {
245+
/**
246+
* Fired when a domain or keyword is blocked site-wide.
247+
*
248+
* @param string $value The blocked domain or keyword.
249+
* @param string $type The block type (actor, domain, keyword).
250+
*/
251+
\do_action( 'activitypub_add_site_block', $value, $type );
252+
}
253+
254+
$existing = \get_option( self::OPTION_KEYS[ $type ], array() );
255+
\update_option( self::OPTION_KEYS[ $type ], array_unique( array_merge( $existing, $values ) ) );
256+
}
257+
226258
/**
227259
* Remove a site-wide block.
228260
*

includes/wp-admin/class-settings-fields.php

Lines changed: 5 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -59,7 +59,11 @@ public static function register_settings_fields() {
5959
'activitypub_moderation',
6060
\esc_html__( 'Moderation', 'activitypub' ),
6161
array( self::class, 'render_moderation_section_description' ),
62-
'activitypub_settings'
62+
'activitypub_settings',
63+
array(
64+
'before_section' => '<div id="moderation">',
65+
'after_section' => '</div>',
66+
)
6367
);
6468

6569
// Add settings fields.

0 commit comments

Comments
 (0)