X-Git-Url: https://scripts.mit.edu/gitweb/autoinstalls/wordpress.git/blobdiff_plain/0461a5f2e55c8d5f1fde96ca2e83117152573c7d..9e77185fafaf4e60e2b73821e0e4b9b1a11fb85f:/wp-admin/includes/template.php?ds=sidebyside diff --git a/wp-admin/includes/template.php b/wp-admin/includes/template.php index fb581448..30dcf0fc 100644 --- a/wp-admin/includes/template.php +++ b/wp-admin/includes/template.php @@ -21,8 +21,8 @@ * @since 2.5.1 */ class Walker_Category_Checklist extends Walker { - var $tree_type = 'category'; - var $db_fields = array ('parent' => 'parent', 'id' => 'term_id'); //TODO: decouple this + public $tree_type = 'category'; + public $db_fields = array ('parent' => 'parent', 'id' => 'term_id'); //TODO: decouple this /** * Starts the list before the elements are added. @@ -35,7 +35,7 @@ class Walker_Category_Checklist extends Walker { * @param int $depth Depth of category. Used for tab indentation. * @param array $args An array of arguments. @see wp_terms_checklist() */ - function start_lvl( &$output, $depth = 0, $args = array() ) { + public function start_lvl( &$output, $depth = 0, $args = array() ) { $indent = str_repeat("\t", $depth); $output .= "$indent\n"; } @@ -69,20 +69,29 @@ class Walker_Category_Checklist extends Walker { * @param array $args An array of arguments. @see wp_terms_checklist() * @param int $id ID of the current term. */ - function start_el( &$output, $category, $depth = 0, $args = array(), $id = 0 ) { - extract($args); - if ( empty($taxonomy) ) + public function start_el( &$output, $category, $depth = 0, $args = array(), $id = 0 ) { + if ( empty( $args['taxonomy'] ) ) { $taxonomy = 'category'; + } else { + $taxonomy = $args['taxonomy']; + } - if ( $taxonomy == 'category' ) + if ( $taxonomy == 'category' ) { $name = 'post_category'; - else - $name = 'tax_input['.$taxonomy.']'; + } else { + $name = 'tax_input[' . $taxonomy . ']'; + } + $args['popular_cats'] = empty( $args['popular_cats'] ) ? array() : $args['popular_cats']; + $class = in_array( $category->term_id, $args['popular_cats'] ) ? ' class="popular-category"' : ''; - $class = in_array( $category->term_id, $popular_cats ) ? ' class="popular-category"' : ''; + $args['selected_cats'] = empty( $args['selected_cats'] ) ? array() : $args['selected_cats']; /** This filter is documented in wp-includes/category-template.php */ - $output .= "\n
  • " . ''; + $output .= "\n
  • " . + ''; } /** @@ -97,7 +106,7 @@ class Walker_Category_Checklist extends Walker { * @param int $depth Depth of the term in reference to parents. Default 0. * @param array $args An array of arguments. @see wp_terms_checklist() */ - function end_el( &$output, $category, $depth = 0, $args = array() ) { + public function end_el( &$output, $category, $depth = 0, $args = array() ) { $output .= "
  • \n"; } } @@ -136,7 +145,7 @@ function wp_category_checklist( $post_id = 0, $descendants_and_self = 0, $select * @param int $post_id * @param array $args */ -function wp_terms_checklist($post_id = 0, $args = array()) { +function wp_terms_checklist( $post_id = 0, $args = array() ) { $defaults = array( 'descendants_and_self' => 0, 'selected_cats' => false, @@ -156,41 +165,55 @@ function wp_terms_checklist($post_id = 0, $args = array()) { * @param array $args An array of arguments. * @param int $post_id The post ID. */ - $args = apply_filters( 'wp_terms_checklist_args', $args, $post_id ); + $params = apply_filters( 'wp_terms_checklist_args', $args, $post_id ); - extract( wp_parse_args($args, $defaults), EXTR_SKIP ); + $r = wp_parse_args( $params, $defaults ); - if ( empty($walker) || !is_a($walker, 'Walker') ) + if ( empty( $r['walker'] ) || ! is_a( $r['walker'], 'Walker' ) ) { $walker = new Walker_Category_Checklist; + } else { + $walker = $r['walker']; + } - $descendants_and_self = (int) $descendants_and_self; + $taxonomy = $r['taxonomy']; + $descendants_and_self = (int) $r['descendants_and_self']; - $args = array('taxonomy' => $taxonomy); + $args = array( 'taxonomy' => $taxonomy ); - $tax = get_taxonomy($taxonomy); - $args['disabled'] = !current_user_can($tax->cap->assign_terms); + $tax = get_taxonomy( $taxonomy ); + $args['disabled'] = ! current_user_can( $tax->cap->assign_terms ); - if ( is_array( $selected_cats ) ) - $args['selected_cats'] = $selected_cats; - elseif ( $post_id ) - $args['selected_cats'] = wp_get_object_terms($post_id, $taxonomy, array_merge($args, array('fields' => 'ids'))); - else + if ( is_array( $r['selected_cats'] ) ) { + $args['selected_cats'] = $r['selected_cats']; + } elseif ( $post_id ) { + $args['selected_cats'] = wp_get_object_terms( $post_id, $taxonomy, array_merge( $args, array( 'fields' => 'ids' ) ) ); + } else { $args['selected_cats'] = array(); - - if ( is_array( $popular_cats ) ) - $args['popular_cats'] = $popular_cats; - else - $args['popular_cats'] = get_terms( $taxonomy, array( 'fields' => 'ids', 'orderby' => 'count', 'order' => 'DESC', 'number' => 10, 'hierarchical' => false ) ); - + } + if ( is_array( $r['popular_cats'] ) ) { + $args['popular_cats'] = $r['popular_cats']; + } else { + $args['popular_cats'] = get_terms( $taxonomy, array( + 'fields' => 'ids', + 'orderby' => 'count', + 'order' => 'DESC', + 'number' => 10, + 'hierarchical' => false + ) ); + } if ( $descendants_and_self ) { - $categories = (array) get_terms($taxonomy, array( 'child_of' => $descendants_and_self, 'hierarchical' => 0, 'hide_empty' => 0 ) ); + $categories = (array) get_terms( $taxonomy, array( + 'child_of' => $descendants_and_self, + 'hierarchical' => 0, + 'hide_empty' => 0 + ) ); $self = get_term( $descendants_and_self, $taxonomy ); array_unshift( $categories, $self ); } else { - $categories = (array) get_terms($taxonomy, array('get' => 'all')); + $categories = (array) get_terms( $taxonomy, array( 'get' => 'all' ) ); } - if ( $checked_ontop ) { + if ( $r['checked_ontop'] ) { // Post process $categories rather than adding an exclude to the get_terms() query to keep the query the same across all posts (for any query cache) $checked_categories = array(); $keys = array_keys( $categories ); @@ -203,10 +226,10 @@ function wp_terms_checklist($post_id = 0, $args = array()) { } // Put checked cats on top - echo call_user_func_array(array(&$walker, 'walk'), array($checked_categories, 0, $args)); + echo call_user_func_array( array( $walker, 'walk' ), array( $checked_categories, 0, $args ) ); } // Then the rest of them - echo call_user_func_array(array(&$walker, 'walk'), array($categories, 0, $args)); + echo call_user_func_array( array( $walker, 'walk' ), array( $categories, 0, $args ) ); } /** @@ -341,11 +364,21 @@ function get_inline_data($post) { $taxonomy = get_taxonomy( $taxonomy_name ); if ( $taxonomy->hierarchical && $taxonomy->show_ui ) { - echo '
    ' - . implode( ',', wp_get_object_terms( $post->ID, $taxonomy_name, array( 'fields' => 'ids' ) ) ) . '
    '; + + $terms = get_object_term_cache( $post->ID, $taxonomy_name ); + if ( false === $terms ) { + $terms = wp_get_object_terms( $post->ID, $taxonomy_name ); + wp_cache_add( $post->ID, $terms, $taxonomy_name . '_relationships' ); + } + $term_ids = empty( $terms ) ? array() : wp_list_pluck( $terms, 'term_id' ); + + echo '
    ' . implode( ',', $term_ids ) . '
    '; + } elseif ( $taxonomy->show_ui ) { + echo '
    ' . esc_html( str_replace( ',', ', ', get_terms_to_edit( $post->ID, $taxonomy_name ) ) ) . '
    '; + } } @@ -419,7 +452,7 @@ function wp_comment_reply($position = '1', $checkbox = false, $mode = 'single',
    - +
    @@ -550,10 +583,10 @@ function _list_meta_row( $entry, &$count ) { if ( is_serialized( $entry['meta_value'] ) ) { if ( is_serialized_string( $entry['meta_value'] ) ) { - // this is a serialized string, so we should display it + // This is a serialized string, so we should display it. $entry['meta_value'] = maybe_unserialize( $entry['meta_value'] ); } else { - // this is a serialized array/object so we should NOT display it + // This is a serialized array/object so we should NOT display it. --$count; return; } @@ -599,14 +632,14 @@ function meta_form( $post = null ) { * * @param int $limit Number of custom fields to retrieve. Default 30. */ - $limit = (int) apply_filters( 'postmeta_form_limit', 30 ); - $keys = $wpdb->get_col( " - SELECT meta_key + $limit = apply_filters( 'postmeta_form_limit', 30 ); + $sql = "SELECT meta_key FROM $wpdb->postmeta GROUP BY meta_key - HAVING meta_key NOT LIKE '\_%' + HAVING meta_key NOT LIKE %s ORDER BY meta_key - LIMIT $limit" ); + LIMIT %d"; + $keys = $wpdb->get_col( $wpdb->prepare( $sql, $wpdb->esc_like( '_' ) . '%', $limit ) ); if ( $keys ) { natcasesort( $keys ); $meta_key_input_id = 'metakeyselect'; @@ -683,6 +716,7 @@ function touch_time( $edit = 1, $for_post = 1, $tab_index = 0, $multi = 0 ) { if ( (int) $tab_index > 0 ) $tab_index_attribute = " tabindex=\"$tab_index\""; + // todo: Remove this? // echo '
    '; $time_adj = current_time('timestamp'); @@ -700,7 +734,7 @@ function touch_time( $edit = 1, $for_post = 1, $tab_index = 0, $multi = 0 ) { $cur_hh = gmdate( 'H', $time_adj ); $cur_mn = gmdate( 'i', $time_adj ); - $month = "\n"; for ( $i = 1; $i < 13; $i = $i +1 ) { $monthnum = zeroise($i, 2); $month .= "\t\t\t" . '