WordPress.org

Make WordPress Core

Ticket #13937: add_meta_box.2.diff

File add_meta_box.2.diff, 3.1 KB (added by scribu, 8 years ago)

Introduce wp_numeric_to_associative()

  • wp-includes/functions.php

     
    30173017}
    30183018
    30193019/**
     3020 * Convert a numeric array to an associative array, based on a list of keys.
     3021 *
     3022 * @since 3.1.0
     3023 *
     3024 * @param array $list Numeric array to be converted
     3025 * @param array $keys A list of keys
     3026 * @return array Resulting array
     3027 */
     3028function wp_numeric_to_associative( $vector, $keys ) {
     3029        $assoc = array();
     3030
     3031        foreach ( $keys as $i => $key ) {
     3032                if ( isset( $vector[ $i ] ) )
     3033                        $assoc[ $key ] = $vector[ $i ];
     3034                else
     3035                        break;
     3036        }
     3037
     3038        return $assoc;
     3039}
     3040
     3041/**
    30203042 * Determines if default embed handlers should be loaded.
    30213043 *
    30223044 * Checks to make sure that the embeds library hasn't already been loaded. If
  • wp-admin/includes/template.php

     
    27602760/**
    27612761 * Add a meta box to an edit form.
    27622762 *
     2763 * The list of arguments is below:
     2764 *              'id' (string) String for use in the 'id' attribute of tags.
     2765 *              'title' (string) Title of the meta box.
     2766 *              'callback' (callback) Function that fills the box with the desired content. The function should echo its output.
     2767 *              'callback_args' (array) A list of arguments to pass to the callback.
     2768 *              'page' (string) The type of edit page on which to show the box (post, page, link).
     2769 *              'context' (string) The context within the page where the boxes should show ('normal', 'advanced').
     2770 *              'priority' (string) The priority within the context where the boxes should show ('high', 'low').
     2771 *
    27632772 * @since 2.5.0
    27642773 *
    2765  * @param string $id String for use in the 'id' attribute of tags.
    2766  * @param string $title Title of the meta box.
    2767  * @param string $callback Function that fills the box with the desired content. The function should echo its output.
    2768  * @param string $page The type of edit page on which to show the box (post, page, link).
    2769  * @param string $context The context within the page where the boxes should show ('normal', 'advanced').
    2770  * @param string $priority The priority within the context where the boxes should show ('high', 'low').
     2774 * @param string|array $args List of arguments
    27712775 */
    2772 function add_meta_box($id, $title, $callback, $page, $context = 'advanced', $priority = 'default', $callback_args=null) {
     2776function add_meta_box( $args ) {
     2777        $argc = func_num_args();
     2778
     2779        if ( $argc > 1 ) {
     2780                _deprecated_argument( __FUNCTION__, '3.1', __('Passing individual arguments is deprecated. Use an associative array of arguments instead.') );
     2781
     2782                $argv = func_get_args();
     2783
     2784                $args = wp_numeric_to_associative( $argv, array( 'id', 'title', 'callback', 'page', 'context', 'priority', 'callback_args' ) );
     2785        }
     2786
     2787        $defaults = array(
     2788                'id' => '',
     2789                'title' => '',
     2790                'callback' => '',
     2791                'callback_args' => null,
     2792                'page' => '',
     2793                'context' => 'advanced',
     2794                'priority' => 'default',
     2795        );
     2796
     2797        extract( wp_parse_args( $args, $defaults ), EXTR_SKIP );
     2798
    27732799        global $wp_meta_boxes;
    27742800
    27752801        if ( !isset($wp_meta_boxes) )