'fail', 'code' => 'error:url', 'message' => 'This domain is blacklisted', 'errorCode' => '403', ); } // Add admin page to handle blacklist management function better_blacklist_add_admin_page() { yourls_register_plugin_page( 'better_blacklist_domain', 'Blacklist Domains', 'better_blacklist_admin_page' ); } // Display the blacklist admin page function better_blacklist_admin_page() { if ( $_SERVER['REQUEST_METHOD'] === 'POST' && isset($_POST['action']) && $_POST['action'] === 'blacklist_domain' ) { better_blacklist_process_form(); } else { better_blacklist_display_form(); } } // Display the form to update the blacklist function better_blacklist_display_form() { $nonce = yourls_create_nonce( 'blacklist_domain' ); $blacklist_domains = yourls_get_option( 'better_blacklist_domain_list', 'Enter domain addresses here, one per line' ); if ( $blacklist_domains !== 'Enter domain addresses here, one per line' ) { $blacklist_domains = implode( "\r\n", unserialize( $blacklist_domains ) ); } echo <<Blacklist Domains

Enter domains to blacklist (one per line):

Advanced Usage (Regex)

You can use regular expressions (Regex) to define more complex patterns for blacklisting domains.
To use Regex, enter your pattern between slashes (/).
For example, to block all subdomains of example.com, you could enter /\.example\.com$/i.
The i flag at the end makes the match case-insensitive. Usually you want to use this flag.

Further examples:
/.*\.xxx$/i - Blocks all domains ending with .xxx

Be cautious when using Regex, as incorrect patterns can lead to unintended blocking of domains.
Always test your Regex patterns to ensure they work as expected.


HTML; } // Process the blacklist form submission function better_blacklist_process_form() { // Verify nonce for security yourls_verify_nonce( 'blacklist_domain' ); // Sanitize and process the form input $blacklist_form = array_filter( array_map( 'trim', explode( "\r\n", $_POST['blacklist_form'] ) ) ); // Alphabetize the blacklist sort($blacklist_form, SORT_STRING | SORT_FLAG_CASE); // Update the option with serialized data yourls_update_option( 'better_blacklist_domain_list', serialize( $blacklist_form ) ); echo "

Blacklist updated!

"; if ( empty( $blacklist_form ) ) { echo "

The blacklist is currently empty.

"; } else { echo "

Current blacklisted domains:

"; } }