Make WordPress Core

Changeset 27373


Ignore:
Timestamp:
03/03/2014 04:20:12 PM (11 years ago)
Author:
markjaquith
Message:

Eliminate some of our last remaining create_function() instances

  • Moved some into private function callbacks
  • Eliminated some that weren't necessary anymore

props obenland, markjaquith, nacin. fixes #14424

Location:
trunk
Files:
6 edited

Legend:

Unmodified
Added
Removed
  • trunk/src/wp-admin/import.php

    r27036 r27373  
    7575    echo '<p>' . __('No importers are available.') . '</p>'; // TODO: make more helpful
    7676} else {
    77     uasort($importers, create_function('$a, $b', 'return strnatcasecmp($a[0], $b[0]);'));
     77    uasort( $importers, '_uasort_by_first_member' );
    7878?>
    7979<table class="widefat importers">
  • trunk/src/wp-admin/includes/import.php

    r25441 r27373  
    1616function get_importers() {
    1717    global $wp_importers;
    18     if ( is_array($wp_importers) )
    19         uasort($wp_importers, create_function('$a, $b', 'return strcmp($a[0], $b[0]);'));
     18    if ( is_array( $wp_importers ) ) {
     19        uasort( $wp_importers, '_uasort_by_first_member' );
     20    }
    2021    return $wp_importers;
     22}
     23
     24/**
     25 * Sorts a multidimensional array by first member of each top level member
     26 *
     27 * Used by uasort() as a callback, should not be used directly.
     28 *
     29 * @since 2.9.0
     30 * @access private
     31 *
     32 * @param array $a
     33 * @param array $b
     34 * @return int
     35 */
     36function _uasort_by_first_member( $a, $b ) {
     37    return strnatcasecmp( $a[0], $b[0] );
    2138}
    2239
  • trunk/src/wp-admin/includes/media.php

    r27369 r27373  
    22562256        $form_class .= ' html-uploader';
    22572257
    2258     $_GET['paged'] = isset( $_GET['paged'] ) ? intval($_GET['paged']) : 0;
    2259     if ( $_GET['paged'] < 1 )
    2260         $_GET['paged'] = 1;
    2261     $start = ( $_GET['paged'] - 1 ) * 10;
    2262     if ( $start < 1 )
    2263         $start = 0;
    2264     add_filter( 'post_limits', create_function( '$a', "return 'LIMIT $start, 10';" ) );
    2265 
    2266     list($post_mime_types, $avail_post_mime_types) = wp_edit_attachments_query();
     2258    $q = $_GET;
     2259    $q['posts_per_page'] = 10;
     2260    $q = isset( $q['paged'] ) ? intval( $q['paged'] ) : 0;
     2261    if ( $q['paged'] < 1 ) {
     2262        $q['paged'] = 1;
     2263    }
     2264    $q['offset'] = ( $q['paged'] - 1 ) * 10;
     2265    if ( $q['offset'] < 1 ) {
     2266        $q['offset'] = 0;
     2267    }
     2268
     2269    list($post_mime_types, $avail_post_mime_types) = wp_edit_attachments_query( $q );
    22672270
    22682271?>
  • trunk/src/wp-admin/includes/post.php

    r27261 r27373  
    935935
    936936    if ( isset($q['detached']) )
    937         add_filter('posts_where', '_edit_attachments_query_helper');
     937        $q['post_parent'] = 0;
    938938
    939939    wp( $q );
    940940
    941     if ( isset($q['detached']) )
    942         remove_filter('posts_where', '_edit_attachments_query_helper');
    943 
    944941    return array($post_mime_types, $avail_post_mime_types);
    945 }
    946 
    947 function _edit_attachments_query_helper($where) {
    948     global $wpdb;
    949     return $where .= " AND {$wpdb->posts}.post_parent < 1";
    950942}
    951943
  • trunk/src/wp-includes/category-template.php

    r27329 r27373  
    623623
    624624    if ( !isset( $args['topic_count_text_callback'] ) && isset( $args['single_text'] ) && isset( $args['multiple_text'] ) ) {
    625         $body = 'return sprintf (
    626             _n(' . var_export($args['single_text'], true) . ', ' . var_export($args['multiple_text'], true) . ', $count),
    627             number_format_i18n( $count ));';
    628         $args['topic_count_text_callback'] = create_function('$count', $body);
     625        $args['topic_count_text_callback'] = '_plugin_topic_count';
    629626    }
    630627
     
    724721function _wp_object_count_sort_cb( $a, $b ) {
    725722    return ( $a->count > $b->count );
     723}
     724
     725/**
     726 * Default text for tooltip for tag links
     727 *
     728 * @since 3.9.0
     729 * @access private
     730 *
     731 * @param integer $count Number of posts with that tag.
     732 * @param object  $tag   Tag object.
     733 * @param array   $args  Arguments for the tag cloud.
     734 * @return string Text for the tooltip of a tag link.
     735 */
     736function _plugin_topic_count( $count, $tag, $args ) {
     737    return sprintf( 1 == $count? $args['single_text'] : $args['multiple_text'], number_format_i18n( $count ) );
    726738}
    727739
  • trunk/tests/phpunit/tests/import/import.php

    r27349 r27373  
    228228    }
    229229
     230    function test_ordering_of_importers() {
     231        global $wp_importers;
     232        $_wp_importers = $wp_importers; // Preserve global state
     233        $wp_importers = array(
     234            'xyz1' => array( 'xyz1' ),
     235            'XYZ2' => array( 'XYZ2' ),
     236            'abc2' => array( 'abc2' ),
     237            'ABC1' => array( 'ABC1' ),
     238            'def1' => array( 'def1' ),
     239        );
     240        $this->assertEquals( array(
     241            'ABC1' => array( 'ABC1' ),
     242            'abc2' => array( 'abc2' ),
     243            'def1' => array( 'def1' ),
     244            'xyz1' => array( 'xyz1' ),
     245            'XYZ2' => array( 'XYZ2' ),
     246        ), get_importers() );
     247        $wp_importers = $_wp_importers; // Restore global state
     248    }
     249
    230250    // function test_menu_import
    231251}
Note: See TracChangeset for help on using the changeset viewer.