Make WordPress Core

Changeset 6418 for trunk/xmlrpc.php


Ignore:
Timestamp:
12/19/2007 09:07:38 PM (19 years ago)
Author:
ryan
Message:

Custom fields support for xmlrpc from josephscott. fixes #5148

File:
1 edited

Legend:

Unmodified
Added
Removed
  • trunk/xmlrpc.php

    r6417 r6418  
    172172                }
    173173        }
     174
     175        function get_custom_fields($post_id) {
     176                $post_id = (int) $post_id;
     177
     178                $custom_fields = array();
     179
     180                foreach ( (array) has_meta($post_id) as $meta ) {
     181                        // Don't expose protected fields.
     182                        if ( strpos($meta['meta_key'], '_wp_') === 0 ) {
     183                                continue;
     184                        }
     185
     186                        $custom_fields[] = array(
     187                                "id"    => $meta['meta_id'],
     188                                "key"   => $meta['meta_key'],
     189                                "value" => $meta['meta_value']
     190                        );
     191                }
     192
     193                return $custom_fields;
     194        }
     195
     196        function set_custom_fields($post_id, $fields) {
     197                $post_id = (int) $post_id;
     198
     199                foreach ( (array) $fields as $meta ) {
     200                        if ( isset($meta['id']) ) {
     201                                $meta['id'] = (int) $meta['id'];
     202
     203                                if ( isset($meta['key']) ) {
     204                                        update_meta($meta['id'], $meta['key'], $meta['value']);
     205                                }
     206                                else {
     207                                        delete_meta($meta['id']);
     208                                }
     209                        }
     210                        else {
     211                                $_POST['metakeyinput'] = $meta['key'];
     212                                $_POST['metavalue'] = $meta['value'];
     213                                add_meta($post_id);
     214                        }
     215                }
     216        }
    174217
    175218        /**
     
    244287                                "wp_author_id"                  => $author->ID,
    245288                                "wp_author_display_name"        => $author->display_name,
    246                                 "date_created_gmt"              => new IXR_Date($page_date_gmt)
     289                                "date_created_gmt"              => new IXR_Date($page_date_gmt),
     290                                "custom_fields"                 => $this->get_custom_fields($page_id)
    247291                        );
    248292
     
    11131157                        return new IXR_Error(500, __('Sorry, your entry could not be posted. Something wrong happened.'));
    11141158                }
     1159
     1160                if ( isset($content_struct['custom_fields']) ) {
     1161                        $this->set_custom_fields($post_ID, $content_struct['custom_fields']);
     1162                }
    11151163               
    11161164                $this->attach_uploads( $post_ID, $post_content );
     
    13331381                        return new IXR_Error(500, __('Sorry, your entry could not be edited. Something wrong happened.'));
    13341382                }
     1383
     1384                if ( isset($content_struct['custom_fields']) ) {
     1385                        $this->set_custom_fields($post_ID, $content_struct['custom_fields']);
     1386                }
     1387
    13351388                $this->attach_uploads( $ID, $post_content );
    13361389               
     
    14051458                                'wp_author_display_name'        => $author->display_name,
    14061459                                'date_created_gmt' => new IXR_Date($post_date_gmt),
    1407                                 'post_status' => $postdata['post_status']
     1460                                'post_status' => $postdata['post_status'],
     1461                                'custom_fields' => $this->get_custom_fields($post_ID)
    14081462                        );
    14091463                       
     
    14881542                                'wp_author_display_name' => $author->display_name,
    14891543                                'date_created_gmt' => new IXR_Date($post_date_gmt),
    1490                                 'post_status' => $entry['post_status']
     1544                                'post_status' => $entry['post_status'],
     1545                                'custom_fields' => $this->get_custom_fields($entry['ID'])
    14911546                        );
    14921547
Note: See TracChangeset for help on using the changeset viewer.