WordPress.org

Make WordPress Core

Ticket #24865: 24865-full.diff

File 24865-full.diff, 4.3 KB (added by nerrad, 7 years ago)

add in functionality for plugin metaboxes to add their data to the autosave package

  • wp-includes/js/autosave.js

     
    381381        if ( $('#auto_draft').val() == '1' )
    382382                data['auto_draft'] = '1';
    383383
     384        /**
     385         * add_meta_box allows for requesting autosave to include data.  Let's get our metabox ID list and add the serialized data.
     386         */
     387        if ( typeof WP_AUTOSAVE_METABOXES != 'undefined' ) {
     388                $.each( WP_AUTOSAVE_METABOXES, function(index,metaboxcssid) {
     389                        data[metaboxcssid] = $('#' + metaboxcssid).find(':input').serializeFullArray();
     390                });
     391        }
     392
    384393        return data;
    385394};
    386395
  • wp-includes/script-loader.php

     
    184184        $scripts->add( 'schedule', '/wp-includes/js/jquery/jquery.schedule.js', array('jquery'), '20m', 1 );
    185185        $scripts->add( 'jquery-query', "/wp-includes/js/jquery/jquery.query.js", array('jquery'), '2.1.7', 1 );
    186186        $scripts->add( 'jquery-serialize-object', "/wp-includes/js/jquery/jquery.serialize-object.js", array('jquery'), '0.2', 1 );
     187        $scripts->add( 'jquery-serialize-fullarray', '/wp-includes/js/jquery/jquery.serializefullarray.js', array('jquery'), '0.1', 1);
    187188        $scripts->add( 'jquery-hotkeys', "/wp-includes/js/jquery/jquery.hotkeys$suffix.js", array('jquery'), '0.0.2m', 1 );
    188189        $scripts->add( 'jquery-table-hotkeys', "/wp-includes/js/jquery/jquery.table-hotkeys$suffix.js", array('jquery', 'jquery-hotkeys'), false, 1 );
    189190        $scripts->add( 'jquery-touch-punch', "/wp-includes/js/jquery/jquery.ui.touch-punch.js", array('jquery-ui-widget', 'jquery-ui-mouse'), '0.2.2', 1 );
  • wp-admin/includes/template.php

     
    810810 * @param string $context Optional. The context within the page where the boxes should show ('normal', 'advanced').
    811811 * @param string $priority Optional. The priority within the context where the boxes should show ('high', 'low').
    812812 * @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).
     813 * @param bool $do_autosave Optional. If present then you can instruct wp autosave to include data from the fields in your metabox when saving.
    813814 */
    814 function add_meta_box( $id, $title, $callback, $screen = null, $context = 'advanced', $priority = 'default', $callback_args = null ) {
    815         global $wp_meta_boxes;
     815function add_meta_box( $id, $title, $callback, $screen = null, $context = 'advanced', $priority = 'default', $callback_args = null, $do_autosave = FALSE ) {
     816        global $wp_meta_boxes, $wp_autosave_metaboxes;
    816817
    817818        if ( empty( $screen ) )
    818819                $screen = get_current_screen();
     
    823824
    824825        if ( !isset($wp_meta_boxes) )
    825826                $wp_meta_boxes = array();
     827        if ( !isset( $wp_autosave_metaboxes) )
     828                $wp_autosave_metaboxes = array();
    826829        if ( !isset($wp_meta_boxes[$page]) )
    827830                $wp_meta_boxes[$page] = array();
    828831        if ( !isset($wp_meta_boxes[$page][$context]) )
     
    867870                $wp_meta_boxes[$page][$context][$priority] = array();
    868871
    869872        $wp_meta_boxes[$page][$context][$priority][$id] = array('id' => $id, 'title' => $title, 'callback' => $callback, 'args' => $callback_args);
     873        //if do_autosave add id to wp_autosave_metaboxes global
     874        if ( $do_autosave )
     875                $wp_autosave_metaboxes[] = $id;
    870876}
    871877
    872878/**
  • wp-admin/edit-form-advanced.php

     
    192192do_action('add_meta_boxes', $post_type, $post);
    193193do_action('add_meta_boxes_' . $post_type, $post);
    194194
     195//if we have $wp_autosave_metaboxes then we setup our WP_AUTOSAVE_METABOXES js obj
     196global $wp_autosave_metaboxes;
     197if ( !empty( $wp_autosave_metaboxes ) ) {
     198        wp_localize_script('autosave', 'WP_AUTOSAVE_METABOXES', $wp_autosave_metaboxes );
     199        wp_enqueue_script('jquery-serialize-fullarray');
     200}
     201
    195202do_action('do_meta_boxes', $post_type, 'normal', $post);
    196203do_action('do_meta_boxes', $post_type, 'advanced', $post);
    197204do_action('do_meta_boxes', $post_type, 'side', $post);