Make WordPress Core

Ticket #13098: 13098.diff

File 13098.diff, 1.8 KB (added by mdawaffe, 15 years ago)
  • wp-includes/bookmark.php

     
    309309 * @return mixed The filtered value
    310310 */
    311311function sanitize_bookmark_field($field, $value, $bookmark_id, $context) {
    312         $int_fields = array('link_id', 'link_rating');
    313         if ( in_array($field, $int_fields) )
     312        switch ( $field ) {
     313        case 'link_id' : // ints
     314        case 'link_rating' :
    314315                $value = (int) $value;
    315 
    316         // Fields which contain arrays of ints.
    317         $array_int_fields = array( 'link_category' );
    318         if ( in_array($field, $array_int_fields) ) {
    319                 $value = array_map( 'absint', $value);
     316                break;
     317        case 'link_category' : // array( ints )
     318                $value = array_map('absint', (array) $value);
     319                // We return here so that the categories aren't filtered.
     320                // The 'link_category' filter is for the name of a link category, not an array of a link's link categories
    320321                return $value;
    321         }
    322 
    323         $yesno = array('link_visible');
    324         if ( in_array($field, $yesno) )
     322                break;
     323        case 'link_visible' : // bool stored as Y|N
    325324                $value = preg_replace('/[^YNyn]/', '', $value);
    326 
    327         if ( 'link_target' == $field ) {
     325                break;
     326        case 'link_target' : // "enum"
    328327                $targets = array('_top', '_blank');
    329328                if ( ! in_array($value, $targets) )
    330329                        $value = '';
     330                break;
    331331        }
    332332
    333333        if ( 'raw' == $context )
     
    347347        } else {
    348348                // Use display filters by default.
    349349                $value = apply_filters($field, $value, $bookmark_id, $context);
     350
     351                if ( 'attribute' == $context )
     352                        $value = esc_attr($value);
     353                else if ( 'js' == $context )
     354                        $value = esc_js($value);
    350355        }
    351356
    352         if ( 'attribute' == $context )
    353                 $value = esc_attr($value);
    354         else if ( 'js' == $context )
    355                 $value = esc_js($value);
    356 
    357357        return $value;
    358358}
    359359