X-Git-Url: https://scripts.mit.edu/gitweb/autoinstalls/wordpress.git/blobdiff_plain/6c8f14c09105d0afa4c1574215c59b5021040e76..5d244c8fd9a27c9f89dd08da2af6fbc67d4fce63:/wp-admin/includes/template.php diff --git a/wp-admin/includes/template.php b/wp-admin/includes/template.php index 788a4bd5..1087837c 100644 --- a/wp-admin/includes/template.php +++ b/wp-admin/includes/template.php @@ -13,53 +13,115 @@ // /** - * 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 - function start_lvl( &$output, $depth = 0, $args = array() ) { + /** + * Starts the list before the elements are added. + * + * @see Walker:start_lvl() + * + * @since 2.5.1 + * + * @param string $output Passed by reference. Used to append additional content. + * @param int $depth Depth of category. Used for tab indentation. + * @param array $args An array of arguments. @see wp_terms_checklist() + */ + public function start_lvl( &$output, $depth = 0, $args = array() ) { $indent = str_repeat("\t", $depth); $output .= "$indent\n"; } - function start_el( &$output, $category, $depth, $args, $id = 0 ) { - extract($args); - if ( empty($taxonomy) ) + /** + * Start the element output. + * + * @see Walker::start_el() + * + * @since 2.5.1 + * + * @param string $output Passed by reference. Used to append additional content. + * @param object $category The current term object. + * @param int $depth Depth of the term in reference to parents. Default 0. + * @param array $args An array of arguments. @see wp_terms_checklist() + * @param int $id ID of the current term. + */ + 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
  • " . + ''; } - function end_el( &$output, $category, $depth = 0, $args = array() ) { + /** + * Ends the element output, if needed. + * + * @see Walker::end_el() + * + * @since 2.5.1 + * + * @param string $output Passed by reference. Used to append additional content. + * @param object $category The current term object. + * @param int $depth Depth of the term in reference to parents. Default 0. + * @param array $args An array of arguments. @see wp_terms_checklist() + */ + 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. @@ -79,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, @@ -96,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 ); - if ( empty($walker) || !is_a($walker, 'Walker') ) + $r = wp_parse_args( $params, $defaults ); + + 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 ); @@ -143,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. * @@ -176,10 +266,6 @@ function wp_popular_terms_checklist( $taxonomy, $default = 0, $number = 10, $ech $terms = get_terms( $taxonomy, array( 'orderby' => 'count', 'order' => 'DESC', 'number' => $number, 'hierarchical' => false ) ); $tax = get_taxonomy($taxonomy); - if ( ! current_user_can($tax->cap->assign_terms) ) - $disabled = 'disabled="disabled"'; - else - $disabled = ''; $popular_ids = array(); foreach ( (array) $terms as $term ) { @@ -192,8 +278,11 @@ function wp_popular_terms_checklist( $taxonomy, $default = 0, $number = 10, $ech @@ -207,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; @@ -228,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 '"; @@ -240,19 +331,20 @@ 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); - if ( ! current_user_can($post_type_object->cap->edit_post, $post->ID) ) + if ( ! current_user_can( 'edit_post', $post->ID ) ) return; $title = esc_textarea( trim( $post->post_title ) ); + /** This filter is documented in wp-admin/edit-tag-form.php */ echo '
    'strong,em,link,block,del,ins,img,ul,ol,li,code,spell,close' ); + $quicktags_settings = array( 'buttons' => 'strong,em,link,block,del,ins,img,ul,ol,li,code,close' ); wp_editor( '', 'replycontent', array( 'media_buttons' => false, 'tinymce' => false, 'quicktags' => $quicktags_settings ) ); ?>
    @@ -408,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 @@ -451,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; @@ -473,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; } @@ -489,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" ) ); @@ -499,33 +617,49 @@ 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; } /** - * {@internal Missing Short Description}} + * Prints the form in the Custom Fields meta box. * * @since 1.2.0 + * + * @param WP_Post $post Optional. The post being edited. */ -function meta_form() { +function meta_form( $post = null ) { global $wpdb; - $limit = (int) apply_filters( 'postmeta_form_limit', 30 ); - $keys = $wpdb->get_col( " - SELECT meta_key + $post = get_post( $post ); + + /** + * 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'; + } ?>

    - + @@ -539,6 +673,8 @@ function meta_form() { ID, $key ) ) + continue; echo "\n"; } ?> @@ -567,14 +703,15 @@ function meta_form() { } /** - * {@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; @@ -587,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'); @@ -604,73 +742,78 @@ 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 input, 2: day input, 3: year input, 4: hour input, 5: minute input */ - printf(__('%1$s%2$s, %3$s @ %4$s : %5$s'), $month, $day, $year, $hour, $minute); + /* translators: 1: month, 2: day, 3: year, 4: hour, 5: minute */ + printf( __( '%1$s %2$s, %3$s @ %4$s : %5$s' ), $month, $day, $year, $hour, $minute ); echo '
    '; 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"; } ?>

    - +

    $template"; - 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; @@ -680,16 +823,13 @@ function parent_dropdown( $default = 0, $parent = 0, $level = 0 ) { if ( $items ) { foreach ( $items as $item ) { // A page cannot be its own parent. - if ( $post->ID && $item->ID == $post->ID ) + if ( $post && $post->ID && $item->ID == $post->ID ) 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 { @@ -698,58 +838,7 @@ function parent_dropdown( $default = 0, $parent = 0, $level = 0 ) { } /** - * {@internal Missing Short Description}} - * - * @since 2.0.0 - * - * @param unknown_type $id - * @return unknown - */ -function the_attachment_links( $id = false ) { - $id = (int) $id; - $post = get_post( $id ); - - if ( $post->post_type != 'attachment' ) - return false; - - $icon = wp_get_attachment_image( $post->ID, 'thumbnail', true ); - $attachment_data = wp_get_attachment_metadata( $id ); - $thumb = isset( $attachment_data['thumb'] ); -?> - -
    - - - - - - - - - - - - - - - - - - - - - - - - - -
    - - html elements for role selectors + * Print out option html elements for role selectors. * * @since 2.1.0 * @@ -759,7 +848,7 @@ function wp_dropdown_roles( $selected = false ) { $p = ''; $r = ''; - $editable_roles = get_editable_roles(); + $editable_roles = array_reverse( get_editable_roles() ); foreach ( $editable_roles as $role => $details ) { $name = translate_user_role($details['name'] ); @@ -779,15 +868,25 @@ 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 = wp_convert_bytes_to_hr( $bytes ); + $size = size_format( $bytes ); $upload_dir = wp_upload_dir(); if ( ! empty( $upload_dir['error'] ) ) : ?>

    -
    +

    () @@ -805,12 +904,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 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; @@ -839,23 +949,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]); } @@ -875,7 +992,8 @@ function add_meta_box( $id, $title, $callback, $screen = null, $context = 'advan * * @since 2.5.0 * - * @param string|object $screen Screen identifier + * @staticvar bool $already_sorted + * @param string|WP_Screen $screen Screen identifier * @param string $context box context * @param mixed $object gets passed to the box callback function as first parameter * @return int number of meta_boxes @@ -895,29 +1013,28 @@ function do_meta_boxes( $screen, $context, $object ) { printf('

    ', htmlspecialchars($context)); - $i = 0; - do { - // Grab the ones the user has manually sorted. Pull them out of their previous context/priority and into the one the user chose - if ( !$already_sorted && $sorted = get_user_option( "meta-box-order_$page" ) ) { - foreach ( $sorted as $box_context => $ids ) { - foreach ( explode(',', $ids ) as $id ) { - if ( $id && 'dashboard_browser_nag' !== $id ) - add_meta_box( $id, null, null, $screen, $box_context, 'sorted' ); + // Grab the ones the user has manually sorted. Pull them out of their previous context/priority and into the one the user chose + if ( ! $already_sorted && $sorted = get_user_option( "meta-box-order_$page" ) ) { + foreach ( $sorted as $box_context => $ids ) { + foreach ( explode( ',', $ids ) as $id ) { + if ( $id && 'dashboard_browser_nag' !== $id ) { + add_meta_box( $id, null, null, $screen, $box_context, 'sorted' ); } } } - $already_sorted = true; + } - if ( !isset($wp_meta_boxes) || !isset($wp_meta_boxes[$page]) || !isset($wp_meta_boxes[$page][$context]) ) - break; + $already_sorted = true; - foreach ( array('high', 'sorted', 'core', 'default', 'low') as $priority ) { - if ( isset($wp_meta_boxes[$page][$context][$priority]) ) { - foreach ( (array) $wp_meta_boxes[$page][$context][$priority] as $box ) { + $i = 0; + + if ( isset( $wp_meta_boxes[ $page ][ $context ] ) ) { + foreach ( array( 'high', 'sorted', 'core', 'default', 'low' ) as $priority ) { + if ( isset( $wp_meta_boxes[ $page ][ $context ][ $priority ]) ) { + foreach ( (array) $wp_meta_boxes[ $page ][ $context ][ $priority ] as $box ) { if ( false == $box || ! $box['title'] ) continue; $i++; - $style = ''; $hidden_class = in_array($box['id'], $hidden) ? ' hide-if-js' : ''; echo '
    ' . "\n"; if ( 'dashboard_browser_nag' != $box['id'] ) @@ -930,7 +1047,7 @@ function do_meta_boxes( $screen, $context, $object ) { } } } - } while(0); + } echo "
    "; @@ -968,6 +1085,80 @@ function remove_meta_box($id, $screen, $context) { $wp_meta_boxes[$page][$context][$priority][$id] = false; } +/** + * Meta Box Accordion Template Function + * + * Largely made up of abstracted code from {@link do_meta_boxes()}, this + * function serves to build meta boxes as list items for display as + * a collapsible accordion. + * + * @since 3.6.0 + * + * @uses global $wp_meta_boxes Used to retrieve registered meta boxes. + * + * @param string|object $screen The screen identifier. + * @param string $context The meta box context. + * @param mixed $object gets passed to the section callback function as first parameter. + * @return int number of meta boxes as accordion sections. + */ +function do_accordion_sections( $screen, $context, $object ) { + global $wp_meta_boxes; + + wp_enqueue_script( 'accordion' ); + + if ( empty( $screen ) ) + $screen = get_current_screen(); + elseif ( is_string( $screen ) ) + $screen = convert_to_screen( $screen ); + + $page = $screen->id; + + $hidden = get_hidden_meta_boxes( $screen ); + ?> +
    +
      + +
    • +

      + + +

      +
      +
      + +
      +
      +
    • + +
    +
    + $id, 'title' => $title, 'callback' => $callback); } @@ -1046,13 +1230,6 @@ function add_settings_field($id, $title, $callback, $page, $section = 'default', $page = 'reading'; } - if ( !isset($wp_settings_fields) ) - $wp_settings_fields = array(); - if ( !isset($wp_settings_fields[$page]) ) - $wp_settings_fields[$page] = array(); - if ( !isset($wp_settings_fields[$page][$section]) ) - $wp_settings_fields[$page][$section] = array(); - $wp_settings_fields[$page][$section][$id] = array('id' => $id, 'title' => $title, 'callback' => $callback, 'args' => $args); } @@ -1072,7 +1249,7 @@ function add_settings_field($id, $title, $callback, $page, $section = 'default', function do_settings_sections( $page ) { global $wp_settings_sections, $wp_settings_fields; - if ( ! isset( $wp_settings_sections ) || !isset( $wp_settings_sections[$page] ) ) + if ( ! isset( $wp_settings_sections[$page] ) ) return; foreach ( (array) $wp_settings_sections[$page] as $section ) { @@ -1102,16 +1279,16 @@ function do_settings_sections( $page ) { * @since 2.7.0 * * @param string $page Slug title of the admin page who's settings fields you want to show. - * @param section $section Slug title of the settings section who's fields you want to show. + * @param string $section Slug title of the settings section who's fields you want to show. */ function do_settings_fields($page, $section) { global $wp_settings_fields; - if ( !isset($wp_settings_fields) || !isset($wp_settings_fields[$page]) || !isset($wp_settings_fields[$page][$section]) ) + if ( ! isset( $wp_settings_fields[$page][$section] ) ) return; foreach ( (array) $wp_settings_fields[$page][$section] as $field ) { - echo ''; + echo ''; if ( !empty($field['args']['label_for']) ) echo ''; else @@ -1138,26 +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; - if ( !isset($wp_settings_errors) ) - $wp_settings_errors = array(); - - $new_error = array( + $wp_settings_errors[] = array( 'setting' => $setting, - 'code' => $code, + 'code' => $code, 'message' => $message, - 'type' => $type + 'type' => $type ); - $wp_settings_errors[] = $new_error; } /** @@ -1185,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 sanitizisation 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 ) { @@ -1215,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 * @@ -1262,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 = '') { ?> -