X-Git-Url: https://scripts.mit.edu/gitweb/autoinstalls/wordpress.git/blobdiff_plain/fa11948979fd6a4ea5705dc613b239699a459db3..refs/tags/wordpress-4.0:/wp-admin/includes/template.php diff --git a/wp-admin/includes/template.php b/wp-admin/includes/template.php index ad42074d..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,18 +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"' : ''; + + $args['selected_cats'] = empty( $args['selected_cats'] ) ? array() : $args['selected_cats']; - $class = in_array( $category->term_id, $popular_cats ) ? ' class="popular-category"' : ''; - $output .= "\n
  • " . ''; + /** This filter is documented in wp-includes/category-template.php */ + $output .= "\n
  • " . + ''; } /** @@ -95,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"; } } @@ -134,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, @@ -143,41 +154,66 @@ function wp_terms_checklist($post_id = 0, $args = array()) { 'taxonomy' => 'category', 'checked_ontop' => true ); - $args = apply_filters( 'wp_terms_checklist_args', $args, $post_id ); - extract( wp_parse_args($args, $defaults), EXTR_SKIP ); + /** + * Filter the taxonomy terms checklist arguments. + * + * @since 3.4.0 + * + * @see wp_terms_checklist() + * + * @param array $args An array of arguments. + * @param int $post_id The post ID. + */ + $params = apply_filters( 'wp_terms_checklist_args', $args, $post_id ); + + $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 ); @@ -190,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 ) ); } /** @@ -235,8 +271,11 @@ function wp_popular_terms_checklist( $taxonomy, $default = 0, $number = 10, $ech @@ -271,6 +310,8 @@ function wp_link_category_checklist( $link_id = 0 ) { foreach ( $categories as $category ) { $cat_id = $category->term_id; + + /** This filter is documented in wp-includes/category-template.php */ $name = esc_html( apply_filters( 'the_category', $category->name ) ); $checked = in_array( $cat_id, $checked_categories ) ? ' checked="checked"' : ''; echo '"; @@ -292,10 +333,11 @@ function get_inline_data($post) { $title = esc_textarea( trim( $post->post_title ) ); + /** This filter is documented in wp-admin/edit-tag-form.php */ echo ' @@ -516,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; } @@ -532,7 +599,7 @@ function _list_meta_row( $entry, &$count ) { $delete_nonce = wp_create_nonce( 'delete-meta_' . $entry['meta_id'] ); $r .= "\n\t"; - $r .= "\n\t\t"; + $r .= "\n\t\t"; $r .= "\n\t\t
    "; $r .= get_submit_button( __( 'Delete' ), 'deletemeta small', "deletemeta[{$entry['meta_id']}]", false, array( 'data-wp-lists' => "delete:the-list:meta-{$entry['meta_id']}::_ajax_nonce=$delete_nonce" ) ); @@ -542,7 +609,7 @@ function _list_meta_row( $entry, &$count ) { $r .= wp_nonce_field( 'change-meta', '_ajax_nonce', false, false ); $r .= ""; - $r .= "\n\t\t\n\t"; + $r .= "\n\t\t\n\t"; return $r; } @@ -556,22 +623,35 @@ function _list_meta_row( $entry, &$count ) { function meta_form( $post = null ) { global $wpdb; $post = get_post( $post ); - $limit = (int) apply_filters( 'postmeta_form_limit', 30 ); - $keys = $wpdb->get_col( " - SELECT meta_key + + /** + * Filter the number of custom fields to retrieve for the drop-down + * in the Custom Fields meta box. + * + * @since 2.1.0 + * + * @param int $limit Number of custom fields to retrieve. Default 30. + */ + $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" ); - if ( $keys ) - natcasesort($keys); + LIMIT %d"; + $keys = $wpdb->get_col( $wpdb->prepare( $sql, $wpdb->esc_like( '_' ) . '%', $limit ) ); + if ( $keys ) { + natcasesort( $keys ); + $meta_key_input_id = 'metakeyselect'; + } else { + $meta_key_input_id = 'metakeyinput'; + } ?>

    - + @@ -615,14 +695,15 @@ function meta_form( $post = null ) { } /** - * {@internal Missing Short Description}} + * Print out HTML form date elements for editing post or comment publish date. * * @since 0.71 * - * @param unknown_type $edit - * @param unknown_type $for_post - * @param unknown_type $tab_index - * @param unknown_type $multi + * @param int|bool $edit Accepts 1|true for editing the date, 0|false for adding the date. + * @param int|bool $for_post Accepts 1|true for applying the date to a post, 0|false for a comment. + * @param int|bool $tab_index The tabindex attribute to add. Default 0. + * @param int|bool $multi Optional. Whether the additional fields and buttons should be added. + * Default 0|false. */ function touch_time( $edit = 1, $for_post = 1, $tab_index = 0, $multi = 0 ) { global $wp_locale, $comment; @@ -635,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'); @@ -652,21 +734,19 @@ 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" . '\n"; + $month .= sprintf( __( '%1$s-%2$s' ), $monthnum, $wp_locale->get_month_abbrev( $wp_locale->get_month( $i ) ) ) . "\n"; } $month .= ''; - $day = ''; - $year = ''; - $hour = ''; - $minute = ''; + $day = ''; + $year = ''; + $hour = ''; + $minute = ''; echo '
    '; /* translators: 1: month, 2: day, 3: year, 4: hour, 5: minute */ @@ -677,48 +757,55 @@ function touch_time( $edit = 1, $for_post = 1, $tab_index = 0, $multi = 0 ) { if ( $multi ) return; echo "\n\n"; - foreach ( array('mm', 'jj', 'aa', 'hh', 'mn') as $timeunit ) { - echo '' . "\n"; + $map = array( + 'mm' => array( $mm, $cur_mm ), + 'jj' => array( $jj, $cur_jj ), + 'aa' => array( $aa, $cur_aa ), + 'hh' => array( $hh, $cur_hh ), + 'mn' => array( $mn, $cur_mn ), + ); + foreach ( $map as $timeunit => $value ) { + list( $unit, $curr ) = $value; + + echo '' . "\n"; $cur_timeunit = 'cur_' . $timeunit; - echo '' . "\n"; + echo '' . "\n"; } ?>

    - +

    HTML elements for the page templates drop-down. * * @since 1.5.0 * - * @param unknown_type $default + * @param string $default Optional. The template file name. Default empty. */ function page_template_dropdown( $default = '' ) { - $templates = get_page_templates(); + $templates = get_page_templates( get_post() ); ksort( $templates ); - foreach (array_keys( $templates ) as $template ) - : if ( $default == $templates[$template] ) - $selected = " selected='selected'"; - else - $selected = ''; - echo "\n\t"; - endforeach; + foreach ( array_keys( $templates ) as $template ) { + $selected = selected( $default, $templates[ $template ], false ); + echo "\n\t"; + } } /** - * {@internal Missing Short Description}} + * Print out "; + echo "\n\t"; parent_dropdown( $default, $item->ID, $level +1 ); } } else { @@ -776,6 +860,16 @@ function wp_dropdown_roles( $selected = false ) { * @param string $action The action attribute for the form. */ function wp_import_upload_form( $action ) { + + /** + * Filter the maximum allowed upload size for import files. + * + * @since 2.3.0 + * + * @see wp_max_upload_size() + * + * @param int $max_upload_size Allowed upload size. Default 1 MB. + */ $bytes = apply_filters( 'import_upload_size_limit', wp_max_upload_size() ); $size = size_format( $bytes ); $upload_dir = wp_upload_dir(); @@ -802,13 +896,23 @@ function wp_import_upload_form( $action ) { * * @since 2.5.0 * - * @param string $id String for use in the 'id' attribute of tags. - * @param string $title Title of the meta box. - * @param string $callback Function that fills the box with the desired content. The function should echo its output. - * @param string|object $screen Optional. The screen on which to show the box (post, page, link). Defaults to current screen. - * @param string $context Optional. The context within the page where the boxes should show ('normal', 'advanced'). - * @param string $priority Optional. The priority within the context where the boxes should show ('high', 'low'). - * @param array $callback_args Optional. Data that should be set as the "args" property of the box array (which is the second parameter passed to your callback). + * @param string $id String for use in the 'id' attribute of tags. + * @param string $title Title of the meta box. + * @param callback $callback Function that fills the box with the desired content. + * The function should echo its output. + * @param string|WP_Screen $screen Optional. The screen on which to show the box (like a post + * type, 'link', or 'comment'). Default is the current screen. + * @param string $context Optional. The context within the screen where the boxes + * should display. Available contexts vary from screen to + * screen. Post edit screen contexts include 'normal', 'side', + * and 'advanced'. Comments screen contexts include 'normal' + * and 'side'. Menus meta boxes (accordion sections) all use + * the 'side' context. Global default is 'advanced'. + * @param string $priority Optional. The priority within the context where the boxes + * should show ('high', 'low'). Default 'default'. + * @param array $callback_args Optional. Data that should be set as the $args property + * of the box array (which is the second parameter passed + * to your callback). Default null. */ function add_meta_box( $id, $title, $callback, $screen = null, $context = 'advanced', $priority = 'default', $callback_args = null ) { global $wp_meta_boxes; @@ -837,23 +941,30 @@ function add_meta_box( $id, $title, $callback, $screen = null, $context = 'advan // If core box previously deleted, don't add if ( false === $wp_meta_boxes[$page][$a_context][$a_priority][$id] ) return; - // If box was added with default priority, give it core priority to maintain sort order + + /* + * If box was added with default priority, give it core priority to + * maintain sort order. + */ if ( 'default' == $a_priority ) { $wp_meta_boxes[$page][$a_context]['core'][$id] = $wp_meta_boxes[$page][$a_context]['default'][$id]; unset($wp_meta_boxes[$page][$a_context]['default'][$id]); } return; } - // If no priority given and id already present, use existing priority + // If no priority given and id already present, use existing priority. if ( empty($priority) ) { $priority = $a_priority; - // else if we're adding to the sorted priority, we don't know the title or callback. Grab them from the previously added context/priority. + /* + * Else, if we're adding to the sorted priority, we don't know the title + * or callback. Grab them from the previously added context/priority. + */ } elseif ( 'sorted' == $priority ) { $title = $wp_meta_boxes[$page][$a_context][$a_priority][$id]['title']; $callback = $wp_meta_boxes[$page][$a_context][$a_priority][$id]['callback']; $callback_args = $wp_meta_boxes[$page][$a_context][$a_priority][$id]['args']; } - // An id can be in only one priority and one context + // An id can be in only one priority and one context. if ( $priority != $a_priority || $context != $a_context ) unset($wp_meta_boxes[$page][$a_context][$a_priority][$id]); } @@ -1019,7 +1130,10 @@ function do_accordion_sections( $screen, $context, $object ) { } ?>
  • -

    +

    + + +

    @@ -1167,7 +1281,7 @@ function do_settings_fields($page, $section) { return; foreach ( (array) $wp_settings_fields[$page][$section] as $field ) { - echo '
  • '; + echo ''; if ( !empty($field['args']['label_for']) ) echo ''; else @@ -1204,13 +1318,12 @@ function do_settings_fields($page, $section) { function add_settings_error( $setting, $code, $message, $type = 'error' ) { global $wp_settings_errors; - $new_error = array( + $wp_settings_errors[] = array( 'setting' => $setting, - 'code' => $code, + 'code' => $code, 'message' => $message, - 'type' => $type + 'type' => $type ); - $wp_settings_errors[] = $new_error; } /** @@ -1238,23 +1351,25 @@ function add_settings_error( $setting, $code, $message, $type = 'error' ) { function get_settings_errors( $setting = '', $sanitize = false ) { global $wp_settings_errors; - // If $sanitize is true, manually re-run the sanitization for this option - // This allows the $sanitize_callback from register_setting() to run, adding - // any settings errors you want to show by default. + /* + * If $sanitize is true, manually re-run the sanitization for this option + * This allows the $sanitize_callback from register_setting() to run, adding + * any settings errors you want to show by default. + */ if ( $sanitize ) sanitize_option( $setting, get_option( $setting ) ); - // If settings were passed back from options.php then use them + // If settings were passed back from options.php then use them. if ( isset( $_GET['settings-updated'] ) && $_GET['settings-updated'] && get_transient( 'settings_errors' ) ) { $wp_settings_errors = array_merge( (array) $wp_settings_errors, get_transient( 'settings_errors' ) ); delete_transient( 'settings_errors' ); } - // Check global in case errors have been added on this pageload + // Check global in case errors have been added on this pageload. if ( ! count( $wp_settings_errors ) ) return array(); - // Filter the results to those of a specific setting if one was set + // Filter the results to those of a specific setting if one was set. if ( $setting ) { $setting_errors = array(); foreach ( (array) $wp_settings_errors as $key => $details ) { @@ -1319,26 +1434,29 @@ function settings_errors( $setting = '', $sanitize = false, $hide_on_update = fa */ function find_posts_div($found_action = '') { ?> - 0, + 'type' => 'rating', + 'number' => 0, + ); + $r = wp_parse_args( $args, $defaults ); + + // Non-english decimal places when the $rating is coming from a string + $rating = str_replace( ',', '.', $r['rating'] ); + + // Convert Percentage to star rating, 0..5 in .5 increments + if ( 'percent' == $r['type'] ) { + $rating = round( $rating / 10, 0 ) / 2; + } + + // Calculate the number of each type of star needed + $full_stars = floor( $rating ); + $half_stars = ceil( $rating - $full_stars ); + $empty_stars = 5 - $full_stars - $half_stars; + + if ( $r['number'] ) { + /* translators: 1: The rating, 2: The number of ratings */ + $format = _n( '%1$s rating based on %2$s rating', '%1$s rating based on %2$s ratings', $r['number'] ); + $title = sprintf( $format, number_format_i18n( $rating, 1 ), number_format_i18n( $r['number'] ) ); + } else { + /* translators: 1: The rating */ + $title = sprintf( __( '%s rating' ), number_format_i18n( $rating, 1 ) ); + } + + echo '
    '; + echo '' . $title . ''; + echo str_repeat( '
    ', $full_stars ); + echo str_repeat( '
    ', $half_stars ); + echo str_repeat( '
    ', $empty_stars); + echo '
    '; +}