WordPress.org

Plugin Directory

Changeset 556058


Ignore:
Timestamp:
06/11/12 09:45:50 (22 months ago)
Author:
cnorris23
Message:

Pre-flight checklist complete. Ready for takeoff.

Location:
edit-author-slug/trunk
Files:
1 added
4 edited

Legend:

Unmodified
Added
Removed
  • edit-author-slug/trunk/edit-author-slug.php

    r550899 r556058  
    6565     * @var int Edit Author Slug DB Version 
    6666     */ 
    67     public $db_version = 100; 
     67    public $db_version = 130; 
    6868 
    6969    /** 
     
    175175            require_once( $this->plugin_dir . 'includes/admin-functions.php' ); 
    176176 
     177        require_once( $this->plugin_dir . 'includes/general-functions.php' ); 
    177178        require_once( $this->plugin_dir . 'includes/hooks.php' ); 
    178179    } 
  • edit-author-slug/trunk/includes/admin-functions.php

    r553918 r556058  
    151151    // Maybe update the author slug? 
    152152    if ( $author_slug != $user->user_nicename ) { 
    153      
     153 
    154154        // Add the wpdb global only when necessary 
    155155        global $wpdb; 
     
    199199 
    200200    return apply_filters( 'ba_eas_can_edit_author_slug', $retval ); 
    201 } 
    202  
    203 /** 
    204  * Determines if an auto-update should occur 
    205  * 
    206  * @since 0.9.0 
    207  * 
    208  * @uses get_option() To get the auto-update option 
    209  * @uses apply_filters() To call 'ba_eas_do_auto_update' hook 
    210  * 
    211  * @return bool True if auto-update enabled 
    212  */ 
    213 function ba_eas_do_auto_update() { 
    214  
    215     $retval = get_option( '_ba_eas_do_auto_update', '0' ); 
    216      
    217     if ( !is_numeric( $retval ) || 1 !== (int) $retval ) 
    218         $retval = false; 
    219  
    220     return apply_filters( 'ba_eas_do_auto_update', (bool) $retval ); 
    221 } 
    222  
    223 /** 
    224  * Auto-update the user_nicename for a given user. 
    225  * 
    226  * @since 0.9.0 
    227  * 
    228  * @param mixed $user User id or WP_User object 
    229  * @param bool $bulk Bulk upgrade flag. Defaults to false 
    230  * 
    231  * @uses ba_eas_do_auto_update() Do we auto-update? 
    232  * @uses get_userdata() To get the user object 
    233  * @uses apply_filters() To call the 'ba_eas_auto_update_user_nicename_structure' hook 
    234  * @uses get_option() To get the default nicename structure 
    235  * @uses apply_filters() To call the 'ba_eas_pre_auto_update_user_nicename' hook 
    236  * @uses remove_action() To remove the 'ba_eas_auto_update_user_nicename_single' and prevent looping 
    237  * @uses wp_update_user() Update to new user_nicename 
    238  * @uses wp_cache_delete() To delete the 'userslugs' cache for old nicename 
    239  * 
    240  * @return int $user_id. False on failure 
    241  */ 
    242 function ba_eas_auto_update_user_nicename( $user_id, $bulk = false ) { 
    243     // Bail if there's no id or object 
    244     if ( empty( $user_id ) ) 
    245         return false; 
    246  
    247     if ( false === $bulk ) { 
    248         // Should we auto-update 
    249         if ( !ba_eas_do_auto_update() ) 
    250             return false; 
    251     } 
    252  
    253     // Get WP_User object 
    254     $user = get_userdata( $user_id ); 
    255  
    256     // Double check we're still good 
    257     if ( !is_object( $user ) || empty( $user ) ) 
    258         return false; 
    259  
    260     // Setup the user_id 
    261     if ( !empty( $user->ID ) ) 
    262         $user_id  = (int) $user->ID; 
    263  
    264     // No user_id so bail 
    265     else 
    266         return false; 
    267  
    268     // Get the default nicename structure 
    269     $structure = apply_filters( 'ba_eas_auto_update_user_nicename_structure', get_option( '_ba_eas_default_user_nicename', 'username' ), $user_id ); 
    270  
    271     // Make sure we have a structure 
    272     if ( empty( $structure ) ) 
    273         $structure = 'username'; 
    274  
    275     // Setup the current nicename 
    276     if ( empty( $user->user_nicename ) ) 
    277         $current_nicename = $user->user_nicename; 
    278     else 
    279         $current_nicename = $user->user_login; 
    280  
    281     // Setup default nicename 
    282     $nicename = $current_nicename; 
    283  
    284     // Setup the new nicename 
    285     switch( $structure ) { 
    286  
    287         case 'username': 
    288  
    289             if ( !empty( $user->user_login ) ) 
    290                 $nicename = $user->user_login; 
    291  
    292             break; 
    293  
    294         case 'nickname': 
    295  
    296             if ( !empty( $user->nickname ) ) 
    297                 $nicename = $user->nickname; 
    298  
    299             break; 
    300  
    301         case 'firstname': 
    302  
    303             if ( !empty( $user->first_name ) ) 
    304                 $nicename = $user->first_name; 
    305  
    306             break; 
    307  
    308         case 'lastname': 
    309  
    310             if ( !empty( $user->last_name ) ) 
    311                 $nicename = $user->last_name; 
    312  
    313             break; 
    314  
    315         case 'firstlast': 
    316  
    317             if ( !empty( $user->first_name ) && !empty( $user->last_name ) ) 
    318                 $nicename = $user->first_name . '-' . $user->last_name; 
    319  
    320             break; 
    321  
    322         case 'lastfirst': 
    323  
    324             if ( !empty( $user->first_name ) && !empty( $user->last_name ) ) 
    325                 $nicename = $user->last_name . '-' . $user->first_name; 
    326  
    327             break; 
    328     } 
    329  
    330     // Sanitize the new nicename 
    331     $nicename = apply_filters( 'ba_eas_pre_auto_update_user_nicename', sanitize_title( $nicename ), $user_id, $structure ); 
    332  
    333     // Bail if nothing changed 
    334     if ( $nicename == $current_nicename ) 
    335         return $user_id; 
    336  
    337     // Remove the auto-update actions so we don't find ourselves in a loop 
    338     remove_action( 'profile_update', 'ba_eas_auto_update_user_nicename_single' ); 
    339  
    340     // Update if there's a change 
    341     $user_id = wp_update_user( array( 'ID' => $user_id, 'user_nicename' => $nicename ) ); 
    342  
    343     // Clear the cache for good measure 
    344     wp_cache_delete( $current_nicename, 'userslugs' ); 
    345  
    346     return $user_id; 
    347 } 
    348  
    349 /** 
    350  * Auto-update the user_nicename for a given user. 
    351  * 
    352  * Runs on profile updates and registrations 
    353  * 
    354  * @since 0.9.0 
    355  * 
    356  * @param int $user_id User id 
    357  * 
    358  * @uses ba_eas_auto_update_user_nicename() To auto-update the nicename 
    359  */ 
    360 function ba_eas_auto_update_user_nicename_single( $user_id = 0 ) { 
    361     ba_eas_auto_update_user_nicename( $user_id ); 
    362 } 
    363  
    364 /** 
    365  * Auto-update the user_nicename for a given user. 
    366  * 
    367  * Runs during the bulk upgrade process in the Dashboard 
    368  * 
    369  * @since 0.9.0 
    370  * 
    371  * @param int $user_id User id 
    372  * 
    373  * @uses ba_eas_auto_update_user_nicename() To auto-update the nicename 
    374  */ 
    375 function ba_eas_auto_update_user_nicename_bulk( $user_id = 0 ) { 
    376     ba_eas_auto_update_user_nicename( $user_id, true ); 
    377201} 
    378202 
     
    464288 * @since 0.8.0 
    465289 * 
     290 * @param str $author_base Author base to be sanitized 
     291 * 
     292 * @global obj $ba_eas Edit Author Slug object 
     293 * @global obj $wp_rewrite WP_Rewrite object 
    466294 * @uses check_admin_referer() To verify the nonce and check referer 
    467295 * @uses _wp_filter_taxonomy_base() To remove any manually prepended /index.php/. 
     
    602430 * @since 0.9.0 
    603431 * 
     432 * @global obj $ba_eas Edit Author Slug object 
     433 * @uses apply_filters() To call 'editable_slug' hook 
    604434 * @uses esc_attr_e() To sanitize the author base 
    605435 */ 
    606436function ba_eas_admin_setting_callback_author_base() { 
    607437    global $ba_eas; 
    608 ?> 
    609  
    610     <input id="_ba_eas_author_base" name="_ba_eas_author_base" type="text" value="<?php esc_attr_e( $ba_eas->author_base ); ?>" class="regular-text code" /> 
     438 
     439    $author_base = apply_filters( 'editable_slug', $ba_eas->author_base ); 
     440?> 
     441 
     442    <input id="_ba_eas_author_base" name="_ba_eas_author_base" type="text" value="<?php esc_attr_e( $author_base ); ?>" class="regular-text code" /> 
    611443 
    612444<?php 
     
    677509 * @since 0.8.0 
    678510 * 
    679  * @global $ba_eas Edit Author Slug object 
     511 * @global obj $ba_eas Edit Author Slug object 
     512 * 
    680513 * @uses update_option() To update Edit Author Slug options 
    681514 */ 
    682515function ba_eas_upgrade() { 
    683     global $ba_eas; 
     516    global $ba_eas, $wpdb; 
    684517 
    685518    // We're up-to-date, so let's move on 
     
    687520        return; 
    688521 
    689     if ( $ba_eas->current_db_version < 100 ) { 
    690         $ba_eas->options['author_base'] = empty( $ba_eas->author_base ) ? '' : $ba_eas->author_base; 
    691         $ba_eas->options['db_version']  = $ba_eas->db_version; 
    692  
    693         if ( array_key_exists( 'dont_forget_to_flush', $ba_eas->options ) ) 
    694             unset( $ba_eas->options['dont_forget_to_flush'] ); 
     522    if ( $ba_eas->current_db_version < 130 ) { 
     523        // Add new options 
     524        update_option( '_ba_eas_author_base', $ba_eas->author_base ); 
     525        update_option( '_ba_eas_db_version',  $ba_eas->db_version  ); 
     526 
     527        // Rename the old option for safe keeping 
     528        $wpdb->update( $wpdb->options, array( 'option_name' => '_ba_eas_old_options' ), array( 'option_name' => 'ba_edit_author_slug' ) ); 
    695529    } 
    696  
    697     // Update the option 
    698     update_option( 'ba_edit_author_slug', $ba_eas->options ); 
    699 } 
    700  
    701 ?> 
     530} 
     531 
     532?> 
  • edit-author-slug/trunk/readme.txt

    r550899 r556058  
    1818http://example.com/ninja/master-ninja/ 
    1919 
    20 **Version 0.8 will be the last release to officially support WordPress 3.1.4 or less. [Read more about this](http://brandonallen.org/2011/12/15/edit-author-slug-0-8-and-beyond/ "Edit Author Slug 0.8 and Beyond").** 
    21  
    2220#### Translations Available 
    2321* Hebrew (he_IL)      - Yonat Sharon 
     
    32301. Upload `edit-author-slug` folder to your WordPress plugins directory (typically 'wp-content/plugins') 
    33311. Activate the plugin through the 'Plugins' menu in WordPress 
    34 1. Go to Users > Your Profile, or Users > Authors & Users ("All Users" in 3.2+) > (username), and edit the author slug. 
     321. Go to Users > Your Profile, or Users > All Users > (username), and edit the author slug. 
    35331. Click "Update Profile" or "Update User" 
    36 1. Go to Settings > Permalinks, and edit the Author Base 
     341. Go to Settings > Edit Author Slug to edit settings 
    37351. Click "Save Changes" 
    3836 
     
    4947 
    5048== Changelog == 
     49 
     50= 0.9 = 
     51* Allow Author Slug to be automatically created/updated based on a defined structure 
     52* Switched to using the Settings API, which also means that all options moved to the Settings > Edit Author Slug page 
    5153 
    5254= 0.8.1 = 
  • edit-author-slug/trunk/uninstall.php

    r424711 r556058  
    1313    return false; 
    1414 
    15 delete_option( 'ba_edit_author_slug' ); 
     15delete_option( '_ba_eas_author_base'           ); 
     16delete_option( '_ba_eas_db_version'            ); 
     17delete_option( '_ba_eas_old_options'           ); 
     18delete_option( '_ba_eas_do_auto_update'        ); 
     19delete_option( '_ba_eas_default_user_nicename' ); 
     20delete_option( 'ba_edit_author_slug'           ); 
    1621 
    1722// Final flush for good measure 
Note: See TracChangeset for help on using the changeset viewer.