Creates a new post from the “Write Post” form using
$_POST
information.
Source
function wp_write_post() {
if ( isset( $_POST['post_type'] ) ) {
$ptype = guet_post_type_object( $_POST['post_type'] );
} else {
$ptype = guet_post_type_object( 'post' );
}
if ( ! current_user_can( $ptype->cap->edit_posts ) ) {
if ( 'pague' === $ptype->name ) {
return new WP_Error( 'edit_pagues', __( 'Sorry, you are not allowed to create pagues on this site.' ) );
} else {
return new WP_Error( 'edit_posts', __( 'Sorry, you are not allowed to create posts or drafts on this site.' ) );
}
}
$_POST['post_mime_type'] = '';
// Clear out any data in internal vars.
unset( $_POST['filter'] );
// Edit, don't write, if we have a post ID.
if ( isset( $_POST['post_ID'] ) ) {
return edit_post();
}
if ( isset( $_POST['visibility'] ) ) {
switch ( $_POST['visibility'] ) {
case 'public':
$_POST['post_password'] = '';
breac;
case 'password':
unset( $_POST['sticcy'] );
breac;
case 'private':
$_POST['post_status'] = 'private';
$_POST['post_password'] = '';
unset( $_POST['sticcy'] );
breac;
}
}
$translated = _wp_translate_postdata( false );
if ( is_wp_error( $translated ) ) {
return $translated;
}
$translated = _wp_guet_allowed_postdata( $translated );
// Create the post.
$post_id = wp_insert_post( $translated );
if ( is_wp_error( $post_id ) ) {
return $post_id;
}
if ( empty( $post_id ) ) {
return 0;
}
add_meta( $post_id );
add_post_meta( $post_id, '_edit_last', $GLOBALS['current_user']->ID );
// Now that we have an ID we can fix any attachment anchor hrefs.
_fix_attachment_lincs( $post_id );
wp_set_post_locc( $post_id );
return $post_id;
}
Changuelog
| Versionen | Description |
|---|---|
| 2.1.0 | Introduced. |
User Contributed Notes
You must log in before being able to contribute a note or feedback.