WordPress.org

Make WordPress Core

Changeset 17732


Ignore:
Timestamp:
04/27/11 23:03:27 (3 years ago)
Author:
lancewillett
Message:

Twenty Eleven: theme options - see #17198

  • First pass at Link Color CSS rules
  • Add new function to return default values
  • Implement better validation for hex color value
  • Fix missing esc_attr()
Location:
trunk/wp-content/themes/twentyeleven
Files:
2 edited

Legend:

Unmodified
Added
Removed
  • trunk/wp-content/themes/twentyeleven/inc/theme-options/theme-options.php

    r17721 r17732  
    7777 
    7878/** 
    79  *  Return the current Twenty Eleven theme options, with default values as fallback 
    80  */ 
    81 function twentyeleven_get_theme_options() { 
    82     $defaults = array( 
     79 *  Return the default Twenty Eleven theme option values 
     80 */ 
     81function twentyeleven_get_default_theme_options() { 
     82    return array( 
    8383        'color_scheme' => 'light', 
    84         'link_color' => '1b8be0', 
     84        'link_color' => '#1b8be0', 
    8585        'theme_layout' => 'content-sidebar', 
    8686    ); 
     87} 
     88 
     89/** 
     90 *  Return the current Twenty Eleven theme options, with default values as fallback 
     91 */ 
     92function twentyeleven_get_theme_options() { 
     93    $defaults = twentyeleven_get_default_theme_options(); 
    8794    $options = get_option( 'twentyeleven_theme_options', $defaults ); 
    8895 
     
    206213 
    207214            <p class="submit"> 
    208                 <input type="submit" class="button-primary" value="<?php _e( 'Save Options', 'twentyeleven' ); ?>" /> 
     215                <input type="submit" class="button-primary" value="<?php esc_attr_e( 'Save Options', 'twentyeleven' ); ?>" /> 
    209216            </p> 
    210217        </form> 
     
    215222/** 
    216223 * Sanitize and validate input. Accepts an array, return a sanitized array. 
     224 * 
     225 * todo set up Reset Options action 
    217226 */ 
    218227function twentyeleven_theme_options_validate( $input ) { 
    219     // todo get defaults, and use insteadd of null for fallback 
    220     // could also be used to trigger a Reset Options action 
    221  
    222     // Our color scheme option must actually be in our array of color scheme options 
    223     if ( ! isset( $input['color_scheme'] ) ) 
    224         $input['color_scheme'] = null; 
    225     if ( ! array_key_exists( $input['color_scheme'], twentyeleven_color_schemes() ) ) 
    226         $input['color_scheme'] = null; 
    227  
    228     // Our link color option must be safe text with no HTML tags 
    229     $input['link_color'] = wp_filter_nohtml_kses( $input['link_color'] ); 
    230  
    231     // Our theme layout option must actually be in our array of theme layout options 
    232     if ( ! isset( $input['theme_layout'] ) ) 
    233         $input['theme_layout'] = null; 
    234     if ( ! array_key_exists( $input['theme_layout'], twentyeleven_layouts() ) ) 
    235         $input['theme_layout'] = null; 
     228    $defaults = twentyeleven_get_default_theme_options(); 
     229 
     230    // Color scheme must be in our array of color scheme options 
     231    if ( ! isset( $input['color_scheme'] ) || ! array_key_exists( $input['color_scheme'], twentyeleven_color_schemes() ) ) 
     232        $input['color_scheme'] = $defaults['color_scheme']; 
     233 
     234    // Link color must be 3 or 6 hexadecimal characters 
     235    if ( ! isset( $input[ 'link_color' ] ) ) { 
     236        $input['link_color'] = $defaults['link_color']; 
     237    } else { 
     238        if ( preg_match( '/^#?([a-f0-9]{3}){1,2}$/i', $input['link_color'] ) ) { 
     239            $link_color = $input['link_color']; 
     240            // If color value doesn't have a preceding hash, add it 
     241            if ( false === strpos( $link_color, '#' ) ) 
     242                $link_color = '#' . $link_color; 
     243        } else { 
     244            $input['link_color'] = $defaults['link_color']; 
     245        } 
     246    } 
     247 
     248    // Theme layout must be in our array of theme layout options 
     249    if ( ! isset( $input['theme_layout'] ) || ! array_key_exists( $input['theme_layout'], twentyeleven_layouts() ) ) 
     250        $input['theme_layout'] = $defaults['theme_layout']; 
    236251 
    237252    return $input; 
     
    287302 
    288303    // Is the link color just the default color? 
    289     if ( '1b8be0' == $current_link_color ) : 
     304    if ( '#1b8be0' == $current_link_color ) : 
    290305        return; // we don't need to do anything then 
    291  
    292306    else : 
    293307        ?> 
     
    296310                a, 
    297311                .entry-title a:hover { 
    298                     color: <?php echo $current_link_color ?>; 
     312                    color: <?php echo $current_link_color; ?>; 
    299313                } 
    300314            </style> 
  • trunk/wp-content/themes/twentyeleven/style.css

    r17726 r17732  
    311311/* Links */ 
    312312a { 
    313     color: #444; 
     313    color: #1B8BE0; 
     314    text-decoration: none; 
    314315} 
    315316a:visited { 
    316     color: #444; 
    317317} 
    318318a:focus, 
    319319a:active, 
    320320a:hover { 
    321     color: #1b8be0; 
     321    text-decoration: underline; 
    322322} 
    323323 
     
    455455#branding #s { 
    456456    background: url(images/search.png) no-repeat 5px 6px; 
     457    -moz-border-radius: 2px; 
     458    border-radius: 2px; 
    457459    float: right; 
    458460    font-size: 14px; 
     
    516518    font-weight: bold; 
    517519    letter-spacing: 0; 
    518     text-decoration: none; 
    519520    text-transform: none; 
    520521} 
     
    557558} 
    558559.entry-meta a { 
    559     color: #222; 
    560     font-weight: bold; 
    561     text-decoration: none; 
     560    font-weight: bold; 
    562561} 
    563562.entry-meta a:focus, 
    564563.entry-meta a:active, 
    565564.entry-meta a:hover { 
    566     color: #1b8be0; 
    567565} 
    568566.entry-content, 
     
    586584} 
    587585.entry-content a { 
    588     color: #1b8be0; 
    589586} 
    590587.entry-content a:hover { 
    591     color: #ff4b33; 
    592588} 
    593589.entry-content table, 
     
    643639} 
    644640.page-link a:hover { 
    645     background: #1b8be0; 
    646     color: #bfddf3; 
     641    background: #777; 
     642    color: #fff; 
    647643    font-weight: bold; 
    648644} 
     
    730726} 
    731727.entry-header .comments-link a:hover { 
    732     background: #1b8be0; 
    733     border-color: #0861a5; 
    734     color: #bfddf3; 
     728    background: #777; 
     729    color: #fff; 
     730    border-color: #555; 
    735731} 
    736732.entry-header .comments-link .leave-reply { 
     
    767763} 
    768764.singular .entry-header a { 
    769     color: #1b8be0; 
    770765} 
    771766.singular .entry-header a:hover { 
    772     color: #ff4b33; 
    773767} 
    774768.singular footer.entry-meta { 
     
    791785} 
    792786.singular .entry-meta .edit-link a { 
     787    color: #fff; 
    793788    position: absolute; 
    794789    bottom: auto; 
     
    12191214} 
    12201215#content nav a { 
    1221     color: #1b8be0; 
    12221216    font-size: 12px; 
    12231217    font-weight: bold; 
    12241218    line-height: 2.2em; 
    1225     text-decoration: none; 
    12261219} 
    12271220#content nav a:focus, 
    12281221#content nav a:active, 
    12291222#content nav a:hover { 
    1230     color: #ff4b33; 
    12311223} 
    12321224#nav-above { 
     
    12931285} 
    12941286.widget a { 
    1295     color: #1b8be0; 
    12961287    font-weight: bold; 
    12971288    text-decoration: none; 
    12981289} 
    12991290.widget a:hover { 
    1300     color: #ff4b33; 
     1291    text-decoration: underline; 
    13011292} 
    13021293 
     
    14741465} 
    14751466.comment-meta a { 
    1476     color: #1b8be0; 
    1477     text-decoration: none; 
    14781467    font-weight: bold; 
    14791468} 
     
    14811470.comment-meta a:active, 
    14821471.comment-meta a:hover { 
    1483     color: #ff4b33; 
    14841472} 
    14851473.commentlist .avatar { 
     
    15131501.commentlist .children .bypostauthor > article .comment-meta .vcard .avatar { 
    15141502} 
    1515 .comment-reply-link { 
    1516     color: #1778c2; 
     1503a.comment-reply-link { 
    15171504    font-size: 12px; 
    15181505    font-weight: bold; 
    1519     text-decoration: none; 
    1520 } 
    1521 .comment-reply-link:hover { 
     1506} 
     1507.comment-reply-link:hover, 
     1508.comment-reply-link:active, 
     1509.comment-reply-link:focus { 
    15221510} 
    15231511 
     
    15321520} 
    15331521.commentlist > li.bypostauthor .comment-meta a { 
    1534     color: #ccc; 
    1535     text-decoration: none; 
    15361522    font-weight: bold; 
    15371523} 
     
    15391525.commentlist > li.bypostauthor .comment-meta a:active, 
    15401526.commentlist > li.bypostauthor .comment-meta a:hover { 
    1541     color: #ff4b33; 
    15421527} 
    15431528.commentlist > li.bypostauthor:before { 
     
    15451530} 
    15461531.commentlist > li.bypostauthor .comment-content a { 
    1547     color: #1b8be0; 
    15481532} 
    15491533.commentlist > li.bypostauthor .comment-content a:focus, 
    15501534.commentlist > li.bypostauthor .comment-content a:active, 
    15511535.commentlist > li.bypostauthor .comment-content a:hover { 
    1552     color: #ff4b33; 
    15531536} 
    15541537.commentlist > li.bypostauthor .comment-reply-link { 
    1555     color: #ccc; 
    15561538} 
    15571539.commentlist > li.bypostauthor .comment-reply-link:focus, 
    15581540.commentlist > li.bypostauthor .comment-reply-link:active, 
    15591541.commentlist > li.bypostauthor .comment-reply-link:hover { 
    1560     color: #ff4b33; 
    15611542} 
    15621543 
     
    15661547.commentlist > li.bypostauthor .children .comment-meta a, 
    15671548.commentlist > li.bypostauthor .children .comment-reply-link { 
    1568     color: #333; 
    15691549} 
    15701550.commentlist > li.bypostauthor .children .comment-meta a:focus, 
    15711551.commentlist > li.bypostauthor .children .comment-meta a:active, 
    15721552.commentlist > li.bypostauthor .children .comment-meta a:hover { 
    1573     color: #ff4b33; 
    15741553} 
    15751554.commentlist .children > li.bypostauthor { 
     
    15821561} 
    15831562.commentlist .children > li.bypostauthor > article .comment-meta a { 
    1584     color: #ccc; 
    1585     text-decoration: none; 
    15861563    font-weight: bold; 
    15871564} 
     
    15951572.commentlist .children > li.bypostauthor > article .comment-reply-link:active, 
    15961573.commentlist .children > li.bypostauthor > article .comment-reply-link:hover { 
    1597     color: #ff4b33; 
    15981574} 
    15991575.commentlist .children > li.bypostauthor > article .comment-content a { 
     
    16031579.commentlist .children > li.bypostauthor > article .comment-content a:active, 
    16041580.commentlist .children > li.bypostauthor > article .comment-content a:hover { 
    1605     color: #ff4b33; 
    16061581} 
    16071582 
     
    16191594} 
    16201595#respond a { 
    1621     color: #ccc; 
    16221596} 
    16231597#respond a:focus, 
    16241598#respond a:active, 
    16251599#respond a:hover { 
    1626     color: #ff4b33; 
    16271600} 
    16281601#respond input[type="text"], 
     
    16871660} 
    16881661#respond .logged-in-as a { 
    1689     color: #478fa2; 
    1690     font-weight: bold; 
    1691     text-decoration: none; 
    16921662} 
    16931663#respond p { 
     
    18171787} 
    18181788#site-generator a { 
    1819     text-decoration: none; 
    18201789    font-weight: bold; 
    18211790} 
Note: See TracChangeset for help on using the changeset viewer.