X-Git-Url: https://scripts.mit.edu/gitweb/autoinstalls/wordpress.git/blobdiff_plain/256a3b381f63716209b3527d0a14442ae570c283..5d244c8fd9a27c9f89dd08da2af6fbc67d4fce63:/wp-admin/includes/template.php diff --git a/wp-admin/includes/template.php b/wp-admin/includes/template.php index 07663826..1087837c 100644 --- a/wp-admin/includes/template.php +++ b/wp-admin/includes/template.php @@ -13,16 +13,17 @@ // /** - * Walker to output an unordered list of category checkbox elements. + * Walker to output an unordered list of category checkbox input elements. + * + * @since 2.5.1 * * @see Walker * @see wp_category_checklist() * @see wp_terms_checklist() - * @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 +36,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 +70,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,18 +107,21 @@ 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"; } } /** - * Output an unordered list of checkbox elements labelled + * Output an unordered list of checkbox input elements labelled * with category names. * - * @see wp_terms_checklist() * @since 2.5.1 * + * @todo Properly document optional arguments as such. + * + * @see wp_terms_checklist() + * * @param int $post_id Mark categories associated with this post as checked. $selected_cats must not be an array. * @param int $descendants_and_self ID of the category to output along with its descendents. * @param bool|array $selected_cats List of categories to mark as checked. @@ -126,15 +141,18 @@ function wp_category_checklist( $post_id = 0, $descendants_and_self = 0, $select } /** - * Output an unordered list of checkbox elements labelled - * with term names. Taxonomy independent version of wp_category_checklist(). + * Output an unordered list of checkbox input elements labelled with term names. + * + * Taxonomy independent version of {@see wp_category_checklist()}. * * @since 3.0.0 * - * @param int $post_id - * @param array $args + * @todo Properly document optional default arguments. + * + * @param int $post_id Post ID. + * @param array $args Arguments to form the terms checklist. */ -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 +161,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,17 +233,17 @@ 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 ) ); } /** * Retrieve a list of the most popular terms from the specified taxonomy. * * If the $echo argument is true then the elements for a list of checkbox - * elements labelled with the names of the selected terms is output. + * `` elements labelled with the names of the selected terms is output. * If the $post_ID global isn't empty then the terms associated with that * post will be marked as checked. * @@ -235,8 +278,11 @@ function wp_popular_terms_checklist( $taxonomy, $default = 0, $number = 10, $ech @@ -250,7 +296,7 @@ function wp_popular_terms_checklist( $taxonomy, $default = 0, $number = 10, $ech * * @since 2.5.1 * - * @param unknown_type $link_id + * @param int $link_id */ function wp_link_category_checklist( $link_id = 0 ) { $default = 1; @@ -271,6 +317,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 '"; @@ -283,7 +331,7 @@ function wp_link_category_checklist( $link_id = 0 ) { * * @since 2.7.0 * - * @param unknown_type $post + * @param WP_Post $post */ function get_inline_data($post) { $post_type_object = get_post_type_object($post->post_type); @@ -292,10 +340,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 ' @@ -451,7 +526,7 @@ function wp_comment_trashnotice() { * * @since 1.2.0 * - * @param unknown_type $meta + * @param array $meta */ function list_meta( $meta ) { // Exit if no meta @@ -494,9 +569,9 @@ function list_meta( $meta ) { * * @since 2.5.0 * - * @param unknown_type $entry - * @param unknown_type $count - * @return unknown + * @param array $entry + * @param int $count + * @return string */ function _list_meta_row( $entry, &$count ) { static $update_nonce = false; @@ -516,10 +591,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 +607,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 +617,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 +631,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 +703,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 $edit Accepts 1|true for editing the date, 0|false for adding the date. + * @param int $for_post Accepts 1|true for applying the date to a post, 0|false for a comment. + * @param int $tab_index The tabindex attribute to add. Default 0. + * @param int $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 +724,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 +742,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,10 +765,19 @@ 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"; } ?> @@ -692,33 +789,31 @@ function touch_time( $edit = 1, $for_post = 1, $tab_index = 0, $multi = 0 ) { } /** - * {@internal Missing Short Description}} + * Print out option 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 option HTML elements for the page parents drop-down. * * @since 1.5.0 * - * @param unknown_type $default - * @param unknown_type $parent - * @param unknown_type $level - * @return unknown + * @param int $default Optional. The default page ID to be pre-selected. Default 0. + * @param int $parent Optional. The parent page ID. Default 0. + * @param int $level Optional. Page depth level. Default 0. + * + * @return null|false Boolean False if page has no children, otherwise print out html elements */ function parent_dropdown( $default = 0, $parent = 0, $level = 0 ) { global $wpdb; @@ -732,12 +827,9 @@ function parent_dropdown( $default = 0, $parent = 0, $level = 0 ) { continue; $pad = str_repeat( ' ', $level * 3 ); - if ( $item->ID == $default) - $current = ' selected="selected"'; - else - $current = ''; + $selected = selected( $default, $item->ID, false ); - echo "\n\t"; + echo "\n\t"; parent_dropdown( $default, $item->ID, $level +1 ); } } else { @@ -746,7 +838,7 @@ function parent_dropdown( $default = 0, $parent = 0, $level = 0 ) { } /** - * Print out
    '; + echo ''; if ( !empty($field['args']['label_for']) ) echo ''; else @@ -1194,23 +1315,25 @@ function do_settings_fields($page, $section) { * * @since 3.0.0 * + * @todo Properly document optional arguments as such. + * * @global array $wp_settings_errors Storage array of errors registered during this pageload * * @param string $setting Slug title of the setting to which this error applies - * @param string $code Slug-name to identify the error. Used as part of 'id' attribute in HTML output. - * @param string $message The formatted message text to display to the user (will be shown inside styled
    and

    ) - * @param string $type The type of message it is, controls HTML class. Use 'error' or 'updated'. + * @param string $code Slug-name to identify the error. Used as part of 'id' attribute in HTML output. + * @param string $message The formatted message text to display to the user (will be shown inside styled + * `

    ` and `

    ` tags). + * @param string $type The type of message it is, controls HTML class. Use 'error' or 'updated'. */ 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 +1361,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 ) { @@ -1268,20 +1393,24 @@ function get_settings_errors( $setting = '', $sanitize = false ) { } /** - * Display settings errors registered by add_settings_error() + * Display settings errors registered by {@see add_settings_error()}. * - * Part of the Settings API. Outputs a

    for each error retrieved by get_settings_errors(). + * Part of the Settings API. Outputs a div for each error retrieved by + * {@see get_settings_errors()}. * - * This is called automatically after a settings page based on the Settings API is submitted. - * Errors should be added during the validation callback function for a setting defined in register_setting() + * This is called automatically after a settings page based on the + * Settings API is submitted. Errors should be added during the validation + * callback function for a setting defined in {@see register_setting()} * - * The $sanitize option is passed into get_settings_errors() and will re-run the setting sanitization + * The $sanitize option is passed into {@see get_settings_errors()} and will + * re-run the setting sanitization * on its current value. * - * The $hide_on_update option will cause errors to only show when the settings page is first loaded. - * if the user has already saved new values it will be hidden to avoid repeating messages already - * shown in the default error reporting after submission. This is useful to show general errors like missing - * settings when the user arrives at the settings page. + * The $hide_on_update option will cause errors to only show when the settings + * page is first loaded. if the user has already saved new values it will be + * hidden to avoid repeating messages already shown in the default error + * reporting after submission. This is useful to show general errors like + * missing settings when the user arrives at the settings page. * * @since 3.0.0 * @@ -1315,30 +1444,33 @@ function settings_errors( $setting = '', $sanitize = false, $hide_on_update = fa * * @since 2.7.0 * - * @param unknown_type $found_action + * @param string $found_action */ function find_posts_div($found_action = '') { ?> -