Allow only specific usernames
-
Hi, I am trying to set up a website for my minecraft server. I want to set up the buddypress registration to only allow users to register if their username reads as a premium account on the minecraft.net server. I found a plugin that was meant to do that, but it hasn’t been updated for a long time, and it no longer works. I have been trying to alter the plugin, but so far, it hasn’t shown any results. As far as I can tell, the plugin is not blocking users, and that is all. Could someone tell me if I have done something wrong?
I have changed the code a lot from the original, but I don’t think that I have damaged anything, let me know if you need the original, and I will post it.EDIT: It turns out that I did damage some of the code, I was getting a very small error on the wordpress plugin page, I fixed that, and upaded the code below.
Here is the plugin’s code:
<?php /* Plugin Name: Minecraft Validator Description: Simple plugin to verify new WordPress accounts against the Minecraft user database. If the username doesn't show up as a valid Minecraft player, it won't let them register. Version: 1.4 Author: Ghost1227 Author URI: https://www.ghost1227.com */ /* Run activation hook when plugin is activated */ register_activation_hook(__FILE__, 'get_wp_version'); /* Rewrite registration form */ function mcv_registration_form() { wp_enqueue_script( 'login_form', plugins_url() . '/minecraft-validator/usernamerewrite.js', array('jquery'), false, false ); } add_action('login_head', 'mcv_registration_form'); /* Get WordPress version */ function get_wp_version() { global $wp_version; if ( version_compare ( $wp_version, '3.1', '<')) { exit ( "<div style='font-size: 13px; font-family: 'HelveticaNeue-Light', 'Helvetica Neue Light', 'Helvetica Neue', sans-serif;'><strong>Attention:</strong> This plugin will not work with your version of WordPress.</div>" ); } } /* Register actions */ add_action('register_post', 'verify_mc_account', 10, 3); add_action('admin_menu', 'add_mcval_options'); /* Check account on minecraft.net */ function verify_mc_account($login, $email, $errors) { $user_info = get_userdata(1); $options = array( 'timeout' => 5, ); $mcacct = wp_remote_get('https://www.minecraft.net/haspaid.jsp?user='.$user_info->user_login); if ( $mcacct == 'false' ) { if ( $mcacct == 'false' ) { $errors->add('mc_error',__('<strong>ERROR:</strong> Minecraft account is invalid.')); return $errors; } else { $errors->add('mc_error',__('<strong>ERROR:</strong> Unable to contact minecraft.net.')); return $errors; } add_filter('registration_errors', 'verify_mc_account', 10, 3); } } /* Activation/Deactivation */ function set_mcval_options() { add_option('hide_me', 'false'); } function unset_mcval_options() { delete_option('hide_me'); } register_activation_hook(__FILE__, 'set_mcval_options'); register_deactivation_hook(__FILE__, 'unset_mcval_options'); /* Add admin menu */ function add_mcval_options() { if ( get_option('hide_me') != "true" ) { add_options_page('Minecraft Validator Options', 'Minecraft Validator', 8, 'mcval-options', 'mcval_options'); } } /* Display options page */ function mcval_options() { ?> <div class="wrap"> <h2>Minecraft Validator</h2> <?php if ( $_REQUEST['submit'] ) { update_mcval_options(); ?> <script type="text/javascript"> <!-- window.location = <?php echo "'options-general.php'"; ?> //--> </script> <?php } print_mcval_form(); ?> </div> <?php } function update_mcval_options() { update_option( 'hide_me', 'true' ); } function print_mcval_form() { ?> <?php }
- The topic ‘Allow only specific usernames’ is closed to new replies.