Changeset 8857 for trunk/wp-admin/includes/post.php
- Timestamp:
- 09/10/2008 10:47:03 PM (16 years ago)
- File:
-
- 1 edited
Legend:
- Unmodified
- Added
- Removed
-
trunk/wp-admin/includes/post.php
r8732 r8857 10 10 * 11 11 * @param bool $update Are we updating a pre-existing post? 12 * @param post_data array Array of post data. Defaults to the contents of $_POST 12 13 * @return object|bool WP_Error on failure, true on success. 13 14 */ 14 function _wp_translate_postdata( $update = false ) { 15 function _wp_translate_postdata( $update = false, &$post_data = null ) { 16 17 if ( empty($post_data) ) 18 $post_data = &$_POST; 19 15 20 if ( $update ) 16 $ _POST['ID'] = (int) $_POST['post_ID'];17 $ _POST['post_content'] = $_POST['content'];18 $ _POST['post_excerpt'] = $_POST['excerpt'];19 $ _POST['post_parent'] = isset($_POST['parent_id'])? $_POST['parent_id'] : '';20 if ( isset($ _POST['trackback_url']) )21 $ _POST['to_ping'] = $_POST['trackback_url'];22 23 if (!empty ( $ _POST['post_author_override'] ) ) {24 $ _POST['post_author'] = (int) $_POST['post_author_override'];21 $post_data['ID'] = (int) $post_data['post_ID']; 22 $post_data['post_content'] = $post_data['content']; 23 $post_data['post_excerpt'] = $post_data['excerpt']; 24 $post_data['post_parent'] = isset($post_data['parent_id'])? $post_data['parent_id'] : ''; 25 if ( isset($post_data['trackback_url']) ) 26 $post_data['to_ping'] = $post_data['trackback_url']; 27 28 if (!empty ( $post_data['post_author_override'] ) ) { 29 $post_data['post_author'] = (int) $post_data['post_author_override']; 25 30 } else { 26 if (!empty ( $ _POST['post_author'] ) ) {27 $ _POST['post_author'] = (int) $_POST['post_author'];31 if (!empty ( $post_data['post_author'] ) ) { 32 $post_data['post_author'] = (int) $post_data['post_author']; 28 33 } else { 29 $ _POST['post_author'] = (int) $_POST['user_ID'];34 $post_data['post_author'] = (int) $post_data['user_ID']; 30 35 } 31 36 } 32 37 33 if ( isset($ _POST['user_ID']) && ($_POST['post_author'] != $_POST['user_ID']) ) {34 if ( 'page' == $ _POST['post_type'] ) {38 if ( isset($post_data['user_ID']) && ($post_data['post_author'] != $post_data['user_ID']) ) { 39 if ( 'page' == $post_data['post_type'] ) { 35 40 if ( !current_user_can( 'edit_others_pages' ) ) { 36 41 return new WP_Error( 'edit_others_pages', $update ? … … 50 55 51 56 // What to do based on which button they pressed 52 if ( isset($ _POST['saveasdraft']) && '' != $_POST['saveasdraft'] )53 $ _POST['post_status'] = 'draft';54 if ( isset($ _POST['saveasprivate']) && '' != $_POST['saveasprivate'] )55 $ _POST['post_status'] = 'private';56 if ( isset($ _POST['publish']) && ( '' != $_POST['publish'] ) && ( $_POST['post_status'] != 'private' ) )57 $ _POST['post_status'] = 'publish';58 if ( isset($ _POST['advanced']) && '' != $_POST['advanced'] )59 $ _POST['post_status'] = 'draft';60 61 $previous_status = get_post_field('post_status', $ _POST['ID']);57 if ( isset($post_data['saveasdraft']) && '' != $post_data['saveasdraft'] ) 58 $post_data['post_status'] = 'draft'; 59 if ( isset($post_data['saveasprivate']) && '' != $post_data['saveasprivate'] ) 60 $post_data['post_status'] = 'private'; 61 if ( isset($post_data['publish']) && ( '' != $post_data['publish'] ) && ( $post_data['post_status'] != 'private' ) ) 62 $post_data['post_status'] = 'publish'; 63 if ( isset($post_data['advanced']) && '' != $post_data['advanced'] ) 64 $post_data['post_status'] = 'draft'; 65 66 $previous_status = get_post_field('post_status', $post_data['ID']); 62 67 63 68 // Posts 'submitted for approval' present are submitted to $_POST the same as if they were being published. 64 69 // Change status from 'publish' to 'pending' if user lacks permissions to publish or to resave published posts. 65 if ( 'page' == $ _POST['post_type'] ) {66 if ( 'publish' == $ _POST['post_status'] && !current_user_can( 'publish_pages' ) )70 if ( 'page' == $post_data['post_type'] ) { 71 if ( 'publish' == $post_data['post_status'] && !current_user_can( 'publish_pages' ) ) 67 72 if ( $previous_status != 'publish' OR !current_user_can( 'edit_published_pages') ) 68 $ _POST['post_status'] = 'pending';73 $post_data['post_status'] = 'pending'; 69 74 } else { 70 if ( isset($ _POST['post_status']) && ('publish' == $_POST['post_status'] && !current_user_can( 'publish_posts' )) ) :75 if ( isset($post_data['post_status']) && ('publish' == $post_data['post_status'] && !current_user_can( 'publish_posts' )) ) : 71 76 // Stop attempts to publish new posts, but allow already published posts to be saved if appropriate. 72 77 if ( $previous_status != 'publish' OR !current_user_can( 'edit_published_posts') ) 73 $ _POST['post_status'] = 'pending';78 $post_data['post_status'] = 'pending'; 74 79 endif; 75 80 } 76 81 77 if (!isset( $ _POST['comment_status'] ))78 $ _POST['comment_status'] = 'closed';79 80 if (!isset( $ _POST['ping_status'] ))81 $ _POST['ping_status'] = 'closed';82 if (!isset( $post_data['comment_status'] )) 83 $post_data['comment_status'] = 'closed'; 84 85 if (!isset( $post_data['ping_status'] )) 86 $post_data['ping_status'] = 'closed'; 82 87 83 88 foreach ( array('aa', 'mm', 'jj', 'hh', 'mn') as $timeunit ) { 84 if ( !empty( $ _POST['hidden_' . $timeunit] ) && $_POST['hidden_' . $timeunit] != $_POST[$timeunit] ) {85 $ _POST['edit_date'] = '1';89 if ( !empty( $post_data['hidden_' . $timeunit] ) && $post_data['hidden_' . $timeunit] != $post_data[$timeunit] ) { 90 $post_data['edit_date'] = '1'; 86 91 break; 87 92 } 88 93 } 89 94 90 if ( !empty( $ _POST['edit_date'] ) ) {91 $aa = $ _POST['aa'];92 $mm = $ _POST['mm'];93 $jj = $ _POST['jj'];94 $hh = $ _POST['hh'];95 $mn = $ _POST['mn'];96 $ss = $ _POST['ss'];95 if ( !empty( $post_data['edit_date'] ) ) { 96 $aa = $post_data['aa']; 97 $mm = $post_data['mm']; 98 $jj = $post_data['jj']; 99 $hh = $post_data['hh']; 100 $mn = $post_data['mn']; 101 $ss = $post_data['ss']; 97 102 $aa = ($aa <= 0 ) ? date('Y') : $aa; 98 103 $mm = ($mm <= 0 ) ? date('n') : $mm; … … 102 107 $mn = ($mn > 59 ) ? $mn -60 : $mn; 103 108 $ss = ($ss > 59 ) ? $ss -60 : $ss; 104 $ _POST['post_date'] = sprintf( "%04d-%02d-%02d %02d:%02d:%02d", $aa, $mm, $jj, $hh, $mn, $ss );105 $ _POST['post_date_gmt'] = get_gmt_from_date( $_POST['post_date'] );109 $post_data['post_date'] = sprintf( "%04d-%02d-%02d %02d:%02d:%02d", $aa, $mm, $jj, $hh, $mn, $ss ); 110 $post_data['post_date_gmt'] = get_gmt_from_date( $post_data['post_date'] ); 106 111 } 107 112 … … 111 116 112 117 // Update an existing post with values provided in $_POST. 113 function edit_post() { 114 115 $post_ID = (int) $_POST['post_ID']; 116 117 if ( 'page' == $_POST['post_type'] ) { 118 function edit_post( $post_data = null ) { 119 120 if ( empty($post_data) ) 121 $post_data = &$_POST; 122 123 $post_ID = (int) $post_data['post_ID']; 124 125 if ( 'page' == $post_data['post_type'] ) { 118 126 if ( !current_user_can( 'edit_page', $post_ID ) ) 119 127 wp_die( __('You are not allowed to edit this page.' )); … … 124 132 125 133 // Autosave shouldn't save too soon after a real save 126 if ( 'autosave' == $ _POST['action'] ) {134 if ( 'autosave' == $post_data['action'] ) { 127 135 $post =& get_post( $post_ID ); 128 136 $now = time(); … … 133 141 } 134 142 135 $translated = _wp_translate_postdata( true );143 $translated = _wp_translate_postdata( true, $post_data ); 136 144 if ( is_wp_error($translated) ) 137 145 wp_die( $translated->get_error_message() ); 138 146 139 147 // Meta Stuff 140 if ( isset($ _POST['meta']) && $_POST['meta'] ) {141 foreach ( $ _POST['meta'] as $key => $value )148 if ( isset($post_data['meta']) && $post_data['meta'] ) { 149 foreach ( $post_data['meta'] as $key => $value ) 142 150 update_meta( $key, $value['key'], $value['value'] ); 143 151 } 144 152 145 if ( isset($ _POST['deletemeta']) && $_POST['deletemeta'] ) {146 foreach ( $ _POST['deletemeta'] as $key => $value )153 if ( isset($post_data['deletemeta']) && $post_data['deletemeta'] ) { 154 foreach ( $post_data['deletemeta'] as $key => $value ) 147 155 delete_meta( $key ); 148 156 } … … 150 158 add_meta( $post_ID ); 151 159 152 wp_update_post( $ _POST);160 wp_update_post( $post_data ); 153 161 154 162 // Reunite any orphaned attachments with their parent … … 164 172 165 173 if ( current_user_can( 'edit_others_posts' ) ) { 166 if ( !empty($ _POST['sticky']) )174 if ( !empty($post_data['sticky']) ) 167 175 stick_post($post_ID); 168 176 else
Note: See TracChangeset
for help on using the changeset viewer.