Changeset 16535 for trunk/wp-includes/post.php
- Timestamp:
- 11/22/2010 05:17:26 PM (14 years ago)
- File:
-
- 1 edited
Legend:
- Unmodified
- Added
- Removed
-
trunk/wp-includes/post.php
r16534 r16535 2318 2318 $post = get_post($postid, $mode); 2319 2319 2320 if ( 2320 if ( 2321 2321 ( OBJECT == $mode && empty( $post->ID ) ) || 2322 2322 ( OBJECT != $mode && empty( $post['ID'] ) ) … … 5039 5039 5040 5040 /** 5041 * Default post information to use when populating the "Write Post" form.5042 *5043 * @since 2.0.05044 *5045 * @param string $post_type A post type string, defaults to 'post'.5046 * @param bool $create_in_db If true then also insert an auto-draft into database5047 * @return object stdClass object containing all the default post data as attributes5048 */5049 function get_default_post_to_edit( $post_type = 'post', $create_in_db = false ) {5050 global $wpdb;5051 5052 $post_title = '';5053 if ( !empty( $_REQUEST['post_title'] ) )5054 $post_title = esc_html( stripslashes( $_REQUEST['post_title'] ));5055 5056 $post_content = '';5057 if ( !empty( $_REQUEST['content'] ) )5058 $post_content = esc_html( stripslashes( $_REQUEST['content'] ));5059 5060 $post_excerpt = '';5061 if ( !empty( $_REQUEST['excerpt'] ) )5062 $post_excerpt = esc_html( stripslashes( $_REQUEST['excerpt'] ));5063 5064 if ( $create_in_db ) {5065 // Cleanup old auto-drafts more than 7 days old5066 $old_posts = $wpdb->get_col( "SELECT ID FROM $wpdb->posts WHERE post_status = 'auto-draft' AND DATE_SUB( NOW(), INTERVAL 7 DAY ) > post_date" );5067 foreach ( (array) $old_posts as $delete )5068 wp_delete_post( $delete, true ); // Force delete5069 $post_id = wp_insert_post( array( 'post_title' => __( 'Auto Draft' ), 'post_type' => $post_type, 'post_status' => 'auto-draft' ) );5070 $post = get_post( $post_id );5071 } else {5072 $post->ID = 0;5073 $post->post_author = '';5074 $post->post_date = '';5075 $post->post_date_gmt = '';5076 $post->post_password = '';5077 $post->post_type = $post_type;5078 $post->post_status = 'draft';5079 $post->to_ping = '';5080 $post->pinged = '';5081 $post->comment_status = get_option( 'default_comment_status' );5082 $post->ping_status = get_option( 'default_ping_status' );5083 $post->post_pingback = get_option( 'default_pingback_flag' );5084 $post->post_category = get_option( 'default_category' );5085 $post->page_template = 'default';5086 $post->post_parent = 0;5087 $post->menu_order = 0;5088 }5089 5090 $post->post_content = apply_filters( 'default_content', $post_content, $post );5091 $post->post_title = apply_filters( 'default_title', $post_title, $post );5092 $post->post_excerpt = apply_filters( 'default_excerpt', $post_excerpt, $post );5093 $post->post_name = '';5094 5095 return $post;5096 }5097 5098 /**5099 * Returns or echos a form containing a post box.5100 *5101 * Used for the QuickPress dashboard module.5102 *5103 * @since 3.1.05104 *5105 * @param array $args Arguments.5106 * @param string $post_type Post type.5107 */5108 function wp_quickpress_form( $args = array(), $post_type = 'post'){5109 global $post_ID;5110 5111 $fields = array(5112 'title' => array(5113 'capability' => '', // Capability to check before outputing field5114 'output' => '<h4 id="%s-title"><label for="title">'. __('Title') .'</label></h4>5115 <div class="input-text-wrap">5116 <input type="text" name="post_title" id="%s-title" tabindex="%d" autocomplete="off" value="'. esc_attr( $post->post_title ).'" />5117 </div>'5118 ),5119 'media_buttons' => array(5120 'capability' => 'upload_files',5121 'output' => '<div id="%s-media-buttons" class="hide-if-no-js">'. get_media_buttons() .'</div>',5122 ),5123 'content' => array(5124 'capability' => '',5125 'output' => '<h4 id="%s-content-label"><label for="content">'. __('Content') .'</label></h4>5126 <div class="textarea-wrap">5127 <textarea name="content" id="%s-content" class="mceEditor" rows="3" cols="15" tabindex="%d">'. esc_textarea( $post->post_content ) .'</textarea>5128 </div>5129 '." <script type='text/javascript'>edCanvas = document.getElementById('content');edInsertContent = null;</script>5130 "5131 5132 ),5133 'tags' => array(5134 'capability' =>'',5135 'output' => '5136 <h4><label for="%s-tags-input">'. __('Tags') .'</label></h4>5137 <div class="input-text-wrap">5138 <input type="text" name="%s-tags_input" id="tags-input" tabindex="%d" value="'. get_tags_to_edit( $post->ID ) .'" />5139 </div>5140 '5141 ),5142 5143 );5144 5145 $hidden_fields = array(5146 'action' => '<input type="hidden" name="action" id="quickpost-action" value="'.$post_type.'-quickpress-save" />',5147 'post_id' => '<input type="hidden" name="quickpress_post_ID" value="'. $post_ID .'" />',5148 'post_type' => '<input type="hidden" name="post_type" value="'.$post_type.'" />',5149 );5150 5151 $submit_fields = array(5152 'save' => '<input type="submit" name="save" id="save-post" class="button" tabindex="%s" value="'. esc_attr('Save Draft') .'" />',5153 'reset' => '<input type="reset" tabindex="%s" value="'. esc_attr( 'Reset' ).'" class="button" />',5154 );5155 5156 $publishing_action = current_user_can('publish_posts') ? esc_attr('Publish') : esc_attr('Submit for Review');5157 5158 $publishing_fields = array(5159 'submit' => '<input type="submit" name="publish" id="publish" accesskey="p" tabindex="%s" class="button-primary" value="' . $publishing_action . '" />',5160 /*'test' => '<input type="submit" name="publish" id="publish" accesskey="p" tabindex="%n" class="button-primary" value="'. esc_attr('Publish') .'" />', */5161 5162 );5163 5164 $defaults = array(5165 'action' => admin_url( 'post.php' ),5166 'fields' => $fields,5167 'form_id' => '',5168 'default_cap' => 'edit_posts',5169 'tabindex_start' => '1',5170 'ajax' => true,5171 'hidden_fields' => $hidden_fields,5172 'submit_fields' => $submit_fields,5173 'publishing_fields' => $publishing_fields,5174 'submit_class' => 'submit',5175 'publish_action_container' => 'span',5176 'publish_action_id' => 'publishing-action',5177 'hidden_and_submit_fields_container' => 'p',5178 'hidden_and_submit_fields_container_class' => 'submit',5179 );5180 5181 $args = wp_parse_args($args, $defaults);5182 5183 $tabindex = apply_filters( 'quickpress_tabindex_start', $args['tabindex_start'], $args['form_id'] );5184 5185 if ( current_user_can( $args['default_cap'] ) ): ?>5186 <?php do_action('quickpress_form_before_form', $args['form_id'] ); ?>5187 <form name="post" action="<?php echo $args['action'] ?>" method="post" id="<?php echo $args['form_id']; ?>">5188 <?php do_action('quickpress_form_before_fields', $args['form_id']);5189 5190 $fields = apply_filters( 'quickpress_fields', $args['fields'], $args['form_id'] );5191 foreach ($fields as $title => $field){5192 if ( empty( $field['capability'] ) || current_user_can( $field['capability'] ) ){5193 printf( $field['output'], $args['form_id'], $args['form_id'], $tabindex );5194 $tabindex++;5195 }5196 }5197 //Hidden Fields5198 do_action('quickpress_form_after_fields', $args['form_id'] );5199 5200 echo "<{$args['hidden_and_submit_fields_container']} class='{$args['hidden_and_submit_fields_container_class']}'>";5201 5202 $hidden_fields = apply_filters( 'quickpress_hidden_fields', $args['hidden_fields'] , $args['form_id'] );5203 5204 foreach( $hidden_fields as $hidden_field )5205 echo $hidden_field;5206 5207 // nonce5208 wp_nonce_field('add-post');5209 5210 // submit5211 foreach( $args['submit_fields'] as $submit_field )5212 printf( $submit_field, $tabindex++ );5213 5214 // publish5215 echo "<{$args['publish_action_container']} id='{$args['publish_action_id']}'>";5216 5217 $publishing_fields = apply_filters( 'quickpress_publishing_fields', $args['publishing_fields'] , $args['form_id'] );5218 5219 foreach( $publishing_fields as $publishing_field) {5220 printf( $publishing_field, $tabindex );5221 $tabindex++;5222 }5223 5224 if ($args['ajax'] == true)5225 echo '<img class="waiting" src="'. esc_url( admin_url( 'images/wpspin_light.gif' ) ) .'" />';5226 5227 echo "</{$args['publish_action_container']}>";5228 echo "<br class='clear' />";5229 do_action( 'quickpress_form_after_submit_fields', $args['form_id']);5230 5231 echo "</{$args['hidden_and_submit_fields_container']}";5232 do_action( 'quickpress_form_after_form_content', $args['form_id']);5233 echo '</form>';5234 do_action('quickpress_form_after_form', $args['form_id'] );5235 else:5236 do_action( 'quickpress_form_no_form', $args['form_id'] );5237 endif;5238 }5239 5240 /**5241 5041 * Returns an array of post format slugs to their translated and pretty display versions 5242 5042 *
Note: See TracChangeset
for help on using the changeset viewer.