WordPress.org

Plugin Directory

Changeset 635266


Ignore:
Timestamp:
12/07/12 08:21:14 (17 months ago)
Author:
coffee2code
Message:
  • Update to v3.3
  • Fix bug with partial username restriction
  • Add setting page tool for testing multiple usernames for validity
  • Add filter c2c_restrict_usernames-validate to allow adding custom restrictions
  • Add contextual help 'Advanced' tab to explain new filter
  • Add Filters section to readme
  • Use square bracket notation for string character index reference
  • Regenerate .pot
  • Re-license as GPLv2 or later (from X11)
  • Add 'License' and 'License URI' header tags to readme.txt and plugin file
  • Note compatibility through WP 3.5+
  • Remove ending PHP close tag
  • Create repo assets folder
  • Move screenshot into repo's assets folder
Location:
restrict-usernames
Files:
1 added
3 edited
1 moved

Legend:

Unmodified
Added
Removed
  • restrict-usernames/trunk/lang/restrict-usernames.pot

    r484647 r635266  
    1 # Translation of the WordPress plugin Restrict Usernames v3.2 by Scott Reilly. 
     1# Translation of the WordPress plugin Restrict Usernames v3.3 by Scott Reilly. 
    22# Copyright (C) 2011 Scott Reilly 
    33# This file is distributed under the same license as the Restrict Usernames plugin. 
    44msgid "" 
    55msgstr "" 
    6 "Project-Id-Version: Restrict Usernames 3.2\n" 
     6"Project-Id-Version: Restrict Usernames 3.3\n" 
    77"Report-Msgid-Bugs-To: http://wordpress.org/tag/restrict-usernames\n" 
    8 "POT-Creation-Date: 2012-01-04 18:59:50+00:00\n" 
     8"POT-Creation-Date: 2012-12-07 08:17:08+00:00\n" 
    99"MIME-Version: 1.0\n" 
    1010"Content-Type: text/plain; charset=UTF-8\n" 
     
    9090msgstr "" 
    9191 
    92 #. #-#-#-#-#  restrict-usernames.pot (Restrict Usernames 3.2)  #-#-#-#-# 
     92#. #-#-#-#-#  restrict-usernames.pot (Restrict Usernames 3.3)  #-#-#-#-# 
    9393#. Plugin Name of the plugin/theme 
    94 #: restrict-usernames.php:92 
     94#: restrict-usernames.php:96 
    9595msgid "Restrict Usernames" 
    9696msgstr "" 
    9797 
    98 #: restrict-usernames.php:93 
     98#: restrict-usernames.php:97 
    9999msgid "Name Restrictions" 
    100100msgstr "" 
    101101 
    102 #: restrict-usernames.php:99 
     102#: restrict-usernames.php:103 
    103103msgid "Don't allow spaces in usernames." 
    104104msgstr "" 
    105105 
    106 #: restrict-usernames.php:100 
     106#: restrict-usernames.php:104 
    107107msgid "" 
    108108"WordPress (single-site, not multisite) allows spaces in usernames.  Check " 
     
    110110msgstr "" 
    111111 
    112 #: restrict-usernames.php:103 
     112#: restrict-usernames.php:107 
    113113msgid "Restricted usernames" 
    114114msgstr "" 
    115115 
    116 #: restrict-usernames.php:104 
     116#: restrict-usernames.php:108 
    117117msgid "" 
    118118"List the usernames that newly-registering users cannot use.  Define one per " 
     
    120120msgstr "" 
    121121 
    122 #: restrict-usernames.php:107 
     122#: restrict-usernames.php:111 
    123123msgid "Restricted usernames (partial matching)" 
    124124msgstr "" 
    125125 
    126 #: restrict-usernames.php:108 
     126#: restrict-usernames.php:112 
    127127msgid "" 
    128128"These are partial text values that cannot appear in usernames requested by " 
     
    133133msgstr "" 
    134134 
    135 #: restrict-usernames.php:109 restrict-usernames.php:114 
     135#: restrict-usernames.php:113 restrict-usernames.php:118 
    136136msgid "" 
    137137"<strong>NOTE: Multisite only allows numbers and lowercase letters in " 
     
    139139msgstr "" 
    140140 
    141 #: restrict-usernames.php:112 
     141#: restrict-usernames.php:116 
    142142msgid "Required username substring" 
    143143msgstr "" 
    144144 
    145 #: restrict-usernames.php:113 
     145#: restrict-usernames.php:117 
    146146msgid "" 
    147147"These are partial text values, one of which MUST appear in any username " 
     
    158158msgstr "" 
    159159 
    160 #: restrict-usernames.php:144 
     160#: restrict-usernames.php:152 
    161161msgid "Restrict Usernames Settings" 
    162162msgstr "" 
    163163 
    164 #: restrict-usernames.php:145 
     164#: restrict-usernames.php:153 
    165165msgid "" 
    166166"If open registration is enabled for your site (via Settings &rarr; General " 
     
    172172msgstr "" 
    173173 
    174 #: restrict-usernames.php:146 
     174#: restrict-usernames.php:154 
    175175msgid "Possible reasons for wanting to restrict certain usernames:" 
    176176msgstr "" 
    177177 
    178 #: restrict-usernames.php:148 
     178#: restrict-usernames.php:156 
    179179msgid "" 
    180180"Prevent usernames that contain foul, offensive, or otherwise undesired words" 
    181181msgstr "" 
    182182 
    183 #: restrict-usernames.php:149 
     183#: restrict-usernames.php:157 
    184184msgid "" 
    185185"Prevent squatting on usernames that you may want to use in the future (but " 
     
    188188msgstr "" 
    189189 
    190 #: restrict-usernames.php:150 
     190#: restrict-usernames.php:158 
    191191msgid "" 
    192192"Prevent official-sounding usernames from being used (i.e. help, support, pr, " 
     
    194194msgstr "" 
    195195 
    196 #: restrict-usernames.php:151 
     196#: restrict-usernames.php:159 
    197197msgid "" 
    198198"Prevent official username syntax from being used (i.e. if all of your admins " 
     
    201201msgstr "" 
    202202 
    203 #: restrict-usernames.php:153 
     203#: restrict-usernames.php:161 
    204204msgid "" 
    205205"When attempting to register with a restricted username, the visitor will be " 
     
    207207msgstr "" 
    208208 
    209 #: restrict-usernames.php:155 restrict-usernames.php:295 
     209#: restrict-usernames.php:163 restrict-usernames.php:342 
    210210msgid "Sorry, this username is invalid. Please choose another." 
    211211msgstr "" 
    212212 
    213 #: restrict-usernames.php:157 
    214 msgid "ERROR: This username is invalid. Please enter a valid username." 
    215 msgstr "" 
    216  
    217 #: restrict-usernames.php:159 
     213#: restrict-usernames.php:165 
     214msgid "ERROR: This username is invalid. Please choose another." 
     215msgstr "" 
     216 
     217#: restrict-usernames.php:167 
    218218msgid "" 
    219219"NOTE: This plugin does not put any restrictions on usernames that the admin " 
     
    223223msgstr "" 
    224224 
    225 #: restrict-usernames.php:262 
     225#: restrict-usernames.php:168 
     226msgid "" 
     227"Use the <a href=\"#username_check\">namecheck tool</a> found below to test " 
     228"how the plugin would evaluate sample usernames." 
     229msgstr "" 
     230 
     231#: restrict-usernames.php:181 
     232msgid "Advanced" 
     233msgstr "" 
     234 
     235#: restrict-usernames.php:309 
    226236msgid "" 
    227237"<strong>ERROR</strong>: This username is invalid. Please choose another." 
     238msgstr "" 
     239 
     240#: restrict-usernames.php:358 
     241msgid "Results of username checks:" 
     242msgstr "" 
     243 
     244#: restrict-usernames.php:374 
     245msgid "" 
     246"Bear in mind that this only checks the syntax of the username. It does not " 
     247"test additional criteria (such as\n" 
     248"\t\t\t\tif the username already exists) that WordPress also checks for on " 
     249"registration." 
     250msgstr "" 
     251 
     252#: restrict-usernames.php:392 
     253msgid "Test Usernames" 
     254msgstr "" 
     255 
     256#: restrict-usernames.php:393 
     257msgid "" 
     258"Use the input field below to list usernames you'd like to test against the " 
     259"plugin's restrictions. Separate multiple usernames with commas." 
     260msgstr "" 
     261 
     262#: restrict-usernames.php:399 
     263msgid "Test" 
    228264msgstr "" 
    229265 
  • restrict-usernames/trunk/readme.txt

    r484647 r635266  
    33Donate link: http://coffee2code.com/donate 
    44Tags: registration, username, signup, users, restrictions, security, privacy, coffee2code, multisite, buddypress 
     5License: GPLv2 or later 
    56Requires at least: 3.1 
    6 Tested up to: 3.3.1 
    7 Stable tag: 3.2 
    8 Version: 3.2 
     7Tested up to: 3.4 
     8Stable tag: 3.3 
     9Version: 3.3 
    910 
    1011Restrict the usernames that new users may use when registering for your site. 
     
    7677 
    7778 
     79== Filters == 
     80 
     81The plugin exposes one filter for hooking.  Typically, customizations utilizing this hook would be put into your active theme's functions.php file, or used by another plugin. 
     82 
     83= c2c_restrict_usernames-validate (filter) = 
     84 
     85The 'c2c_restrict_usernames-validate' hook allows you to add your own customized checks for the username being registered. You can add additional restrictions or override the assessment performed by the plugin. 
     86 
     87Arguments: 
     88 
     89* $valid (boolean): The assessment by the plugin about the validity of the username based on settings. True means username can be used. 
     90* $username (string): The username being registered. 
     91* $settings (array): The plugin's settings. 
     92 
     93Example: 
     94 
     95` 
     96/** 
     97 * Add custom checks on usernames. 
     98 * 
     99 * Specifically, prevent use of usernames ending in numbers. 
     100 */ 
     101function my_restrict_usernames_check( $valid, $username, $options ) { 
     102    // Only do additional checking if the plugin has already performed its 
     103    // checks and deemed the username valid. 
     104    if ( $valid ) { 
     105        // Don't allow usernames to end in numbers. 
     106        if ( preg_match( '/[0-9]+$/', $username ) ) 
     107            $valid = false; 
     108    } 
     109    return $valid; 
     110} 
     111add_filter( 'c2c_restrict_usernames-validate', 'my_restrict_usernames_check', 10, 3 ); 
     112` 
     113 
    78114== Changelog == 
     115 
     116= 3.3 = 
     117* Fix bug with partial username restriction 
     118* Add setting page tool for testing multiple usernames for validity 
     119* Add filter c2c_restrict_usernames-validate to allow adding custom restrictions 
     120* Add contextual help 'Advanced' tab to explain new filter 
     121* Add Filters section to readme 
     122* Use square bracket notation for string character index reference 
     123* Regenerate .pot 
     124* Re-license as GPLv2 or later (from X11) 
     125* Add 'License' and 'License URI' header tags to readme.txt and plugin file 
     126* Note compatibility through WP 3.5+ 
     127* Remove ending PHP close tag 
     128* Move screenshot into repo's assets folder 
    79129 
    80130= 3.2 = 
     
    171221== Upgrade Notice == 
    172222 
     223= 3.3 = 
     224Recommended update. Fixed bug with partial username restrictions; added filter to allow adding custom restrictions; added tool to test username restrictions; noted compatibility through WP 3.5+; and more. 
     225 
    173226= 3.2 = 
    174227Recommended update. Added Multisite compatibility; noted WP 3.3 compatibility; dropped support for versions of WP older than 3.1; updated plugin framework; and more. 
  • restrict-usernames/trunk/restrict-usernames.php

    r484647 r635266  
    33 * @package Restrict_Usernames 
    44 * @author Scott Reilly 
    5  * @version 3.2 
     5 * @version 3.3 
    66 */ 
    77/* 
    88Plugin Name: Restrict Usernames 
    9 Version: 3.2 
     9Version: 3.3 
    1010Plugin URI: http://coffee2code.com/wp-plugins/restrict-usernames/ 
    1111Author: Scott Reilly 
     
    1313Text Domain: restrict-usernames 
    1414Domain Path: /lang/ 
     15License: GPLv2 or later 
     16License URI: http://www.gnu.org/licenses/gpl-2.0.html 
    1517Description: Restrict the usernames that new users may use when registering for your site. 
    1618 
    17 Compatible with WordPress 3.1+, 3.2+, 3.3+ and BuddyPress 1.2+, 1.3+. 
     19Compatible with WordPress 3.1 through 3.5+ and BuddyPress 1.2+, 1.3+. 
    1820 
    1921=>> Read the accompanying readme.txt file for instructions and documentation. 
     
    2325 
    2426/* 
    25 Copyright (c) 2008-2012 by Scott Reilly (aka coffee2code) 
    26  
    27 Permission is hereby granted, free of charge, to any person obtaining a copy of this software and associated documentation 
    28 files (the "Software"), to deal in the Software without restriction, including without limitation the rights to use, copy, 
    29 modify, merge, publish, distribute, sublicense, and/or sell copies of the Software, and to permit persons to whom the 
    30 Software is furnished to do so, subject to the following conditions: 
    31  
    32 The above copyright notice and this permission notice shall be included in all copies or substantial portions of the Software. 
    33  
    34 THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES 
    35 OF MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE 
    36 LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR 
    37 IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE. 
     27    Copyright (c) 2008-2013 by Scott Reilly (aka coffee2code) 
     28 
     29    This program is free software; you can redistribute it and/or 
     30    modify it under the terms of the GNU General Public License 
     31    as published by the Free Software Foundation; either version 2 
     32    of the License, or (at your option) any later version. 
     33 
     34    This program is distributed in the hope that it will be useful, 
     35    but WITHOUT ANY WARRANTY; without even the implied warranty of 
     36    MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the 
     37    GNU General Public License for more details. 
     38 
     39    You should have received a copy of the GNU General Public License 
     40    along with this program; if not, write to the Free Software 
     41    Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA  02110-1301, USA. 
    3842*/ 
    3943 
     
    6165            return; 
    6266 
    63         parent::__construct( '3.2', 'restrict-usernames', 'c2c', __FILE__, array( 'settings_page' => 'users' ) ); 
     67        parent::__construct( '3.3', 'restrict-usernames', 'c2c', __FILE__, array( 'settings_page' => 'users' ) ); 
    6468        register_activation_hook( __FILE__, array( __CLASS__, 'activation' ) ); 
    6569        self::$instance = $this; 
     
    127131            remove_action( 'admin_menu',          array( &$this, 'admin_menu' ) ); 
    128132        } 
    129         if ( ! is_admin() ) { 
     133 
     134        if ( is_admin() ) { 
     135            add_action( 'admin_init',                              array( &$this, 'maybe_test_usernames' ) ); 
     136            add_action( $this->get_hook( 'after_settings_form' ),  array( &$this, 'usernames_test_form' ) ); 
     137        } else { 
    130138            if ( is_multisite() || defined( 'BP_VERSION' ) ) 
    131139                add_filter( 'wpmu_validate_user_signup', array( &$this, 'bp_members_validate_user_signup' ) ); 
     
    155163            echo __( 'Sorry, this username is invalid. Please choose another.', $this->textdomain ); 
    156164        else 
    157             echo __( 'ERROR: This username is invalid. Please enter a valid username.', $this->textdomain ); 
     165            echo __( 'ERROR: This username is invalid. Please choose another.', $this->textdomain ); 
    158166        echo '</blockquote></p>'; 
    159167        echo '<p>' . __( 'NOTE: This plugin does not put any restrictions on usernames that the admin chooses for users when creating user accounts from within the WordPress admin.  This only restricts the names that users choose themselves when registering for your site.', $this->textdomain ) . '</p>'; 
     168        echo '<p>' . __( 'Use the <a href="#username_check">namecheck tool</a> found below to test how the plugin would evaluate sample usernames.' ) . '</p>'; 
     169    } 
     170 
     171    /** 
     172     * Configures help tabs content. 
     173     * 
     174     * @since 3.3 
     175     * 
     176     * @return void 
     177     */ 
     178    public function help_tabs_content( $screen ) { 
     179        $screen->add_help_tab( array( 
     180            'id'      => $this->id_base . '-' . 'advanced', 
     181            'title'   => __( 'Advanced', $this->textdomain ), 
     182            'content' => <<<HTML 
     183            <h4>Filter</h4> 
     184            <p>This plugin provides a filter that can be used to do your own customized username restriction checks. Here's an example:</p> 
     185            <p><pre>/** 
     186  * Add custom checks on usernames. 
     187  * 
     188  * Specifically, prevent use of usernames ending in numbers. 
     189  */ 
     190    function my_restrict_usernames_check( \$valid, \$username, \$options ) { 
     191        // Only do additional checking if the plugin has already performed its 
     192        // checks and deemed the username valid. 
     193        if ( \$valid ) { 
     194            // Don't allow usernames to end in numbers. 
     195            if ( preg_match( '/[0-9]+$/', \$username ) ) 
     196                \$valid = false; 
     197        } 
     198        return \$valid; 
     199    } 
     200 add_filter( 'c2c_restrict_usernames-validate', 'my_restrict_usernames_check', 10, 3 );<pre></p> 
     201HTML 
     202        ) ); 
     203        parent::help_tabs_content( $screen ); 
    160204    } 
    161205 
     
    173217            $contains = array(); 
    174218            foreach ( $options['required_partials'] as $partial ) { 
    175                 if ( $partial{0} == '^' ) 
     219                if ( $partial[0] == '^' ) 
    176220                    $starts[] = substr( $partial, 1 ); 
    177221                elseif ( substr( $partial, -1, 1 ) == '^' ) 
     
    204248     */ 
    205249    public function username_restrictor( $valid, $username ) { 
    206         if ( ! $valid || ( is_user_logged_in() && current_user_can( 'create_users' ) ) ) 
     250        if ( ! $valid || ( ! isset( $_POST['c2c_test_usernames'] ) && is_user_logged_in() && current_user_can( 'create_users' ) ) ) 
    207251            return $valid; 
    208252 
     
    218262        if ( $valid && $options['partial_usernames'] ) { 
    219263            foreach ( $options['partial_usernames'] as $partial ) { 
    220                 if ( strpos( $username, $partial ) !== false ) 
     264                if ( strpos( $username, $partial ) !== false ) { 
    221265                    $valid = false; 
    222266                    break; 
     267                } 
    223268            } 
    224269        } 
     
    227272            $valid = false; 
    228273            foreach ( $options['required_partials'] as $partial ) { 
    229                 if ( $partial{0} == '^' ) { 
     274                if ( $partial[0] == '^' ) { 
    230275                    $partial = substr( $partial, 1 ); 
    231276                    if ( ( $username != $partial ) && ( strpos( $username, $partial ) === 0 ) ) { 
     
    248293        } 
    249294 
     295        $valid = apply_filters( 'c2c_restrict_usernames-validate', $valid, $username, $options ); 
     296 
    250297        $this->got_restricted = !$valid; 
    251298        return $valid; 
     
    272319     * plugin normally hooks -- any failures reported trigger BP's generic 
    273320     * 'Only lowercase letters and numbers allowed' error message. It's just 
    274      * easier to let BP do its checks and at the very end so the username 
     321     * easier to let BP do its checks and at the very end do the username 
    275322     * restriction checks. 
    276323     * 
     
    300347    } 
    301348 
     349    /** 
     350     * Evaluates submitted usernames against the restrictions imposed by just 
     351     * this plugin. 
     352     * 
     353     * @since 3.3 
     354     */ 
     355    public function maybe_test_usernames() { 
     356        if ( isset( $_POST[$this->get_form_submit_name( 'submit_test_usernames' )] ) && isset( $_POST['c2c_test_usernames'] ) ) { 
     357            check_admin_referer( $this->nonce_field ); 
     358            $msg = __( 'Results of username checks:', $this->textdomain ); 
     359            $msg .= '<ul>'; 
     360            $unames= explode( ',', $_POST['c2c_test_usernames'] ); 
     361            // The filter isn't normally added in the admin, so do so. 
     362            add_filter( 'validate_username', array( &$this, 'username_restrictor' ), 10, 2 ); 
     363            $do_msg = false; 
     364            foreach ( $unames as $u ) { 
     365                $u = trim( $u ); 
     366                if ( $u === '' ) 
     367                    continue; 
     368                $msg .= '<li>' . esc_html( $u ) . ' : '; 
     369                $msg .= validate_username( $u ) ? 'valid' : 'invalid'; 
     370                $msg .= '</li>'; 
     371                $do_msg = true; 
     372            } 
     373            $msg .= '</ul>'; 
     374            $msg .= '<p>' . __( 'Bear in mind that this only checks the syntax of the username. It does not test additional criteria (such as 
     375                if the username already exists) that WordPress also checks for on registration.' ) . '</p>'; 
     376            if ( $do_msg ) 
     377                add_settings_error( 'general', 'usernames_tested', $msg, 'updated' ); 
     378        } 
     379    } 
     380 
     381    /* 
     382     * Outputs form to test usernames. 
     383     * 
     384     * @since 3.3 
     385     * 
     386     * @return void (Text will be echoed.) 
     387     */ 
     388    public function usernames_test_form() { 
     389        $user = wp_get_current_user(); 
     390        $email = $user->user_email; 
     391        $action_url = $this->form_action_url(); 
     392        echo '<div class="wrap"><h2><a name="username_check"></a>' . __( 'Test Usernames', $this->textdomain ) . "</h2>\n"; 
     393        echo '<p>' . __( 'Use the input field below to list usernames you\'d like to test against the plugin\'s restrictions. Separate multiple usernames with commas.', $this->textdomain ) . "</p>\n"; 
     394        echo '<p><em>You must save any changes to the form above before attempting to test usernames.</em></p>'; 
     395        echo "<form name='c2c_restrict_usernames' action='$action_url' method='post'>\n"; 
     396        wp_nonce_field( $this->nonce_field ); 
     397        echo '<input type="hidden" name="' . $this->get_form_submit_name( 'submit_test_usernames' ) .'" value="1" />'; 
     398        echo '<input type="text" size="80" name="c2c_test_usernames" />'; 
     399        echo '<div class="submit"><input type="submit" name="Submit" class="button-primary" value="' . esc_attr__( 'Test', $this->textdomain ) . '" /></div>'; 
     400        echo '</form></div>'; 
     401    } 
     402 
    302403} // end c2c_RestrictUsernames 
    303404 
     
    306407 
    307408endif; // end if !class_exists() 
    308  
    309 ?> 
Note: See TracChangeset for help on using the changeset viewer.