Skip to content
Merged
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
4 changes: 4 additions & 0 deletions .github/changelog/2589-from-description
Original file line number Diff line number Diff line change
@@ -0,0 +1,4 @@
Significance: minor
Type: added

Add domain blocklist importer for bulk importing blocked domains.
32 changes: 32 additions & 0 deletions includes/class-moderation.php
Original file line number Diff line number Diff line change
Expand Up @@ -223,6 +223,38 @@ public static function add_site_block( $type, $value ) {
return true; // Already blocked.
}

/**
* Add multiple site-wide blocks at once.
*
* More efficient than calling add_site_block() in a loop as it
* performs a single database update.
*
* @param string $type The block type (domain or keyword only).
* @param array $values Array of values to block.
*/
public static function add_site_blocks( $type, $values ) {
if ( ! in_array( $type, array( self::TYPE_DOMAIN, self::TYPE_KEYWORD ), true ) ) {
return;
}

if ( empty( $values ) ) {
return;
}

foreach ( $values as $value ) {
/**
* Fired when a domain or keyword is blocked site-wide.
*
* @param string $value The blocked domain or keyword.
* @param string $type The block type (actor, domain, keyword).
*/
\do_action( 'activitypub_add_site_block', $value, $type );
}

$existing = \get_option( self::OPTION_KEYS[ $type ], array() );
\update_option( self::OPTION_KEYS[ $type ], array_unique( array_merge( $existing, $values ) ) );
}

/**
* Remove a site-wide block.
*
Expand Down
6 changes: 5 additions & 1 deletion includes/wp-admin/class-settings-fields.php
Original file line number Diff line number Diff line change
Expand Up @@ -59,7 +59,11 @@ public static function register_settings_fields() {
'activitypub_moderation',
\esc_html__( 'Moderation', 'activitypub' ),
array( self::class, 'render_moderation_section_description' ),
'activitypub_settings'
'activitypub_settings',
array(
'before_section' => '<div id="moderation">',
'after_section' => '</div>',
)
);

// Add settings fields.
Expand Down
Loading