edit_post example

// If the post is an autodraft, save the post as a draft and then attempt to save the meta.         if ( 'auto-draft' === $post->post_status ) {
            $post_data                = array();
            $post_data['action']      = 'draft'; // Warning fix.             $post_data['post_ID']     = $pid;
            $post_data['post_type']   = $post->post_type;
            $post_data['post_status'] = 'draft';
            $now                      = time();
            /* translators: 1: Post creation date, 2: Post creation time. */
            $post_data['post_title'] = sprintf( __( 'Draft created on %1$s at %2$s' )gmdate( __( 'F j, Y' )$now )gmdate( __( 'g:i a' )$now ) );

            $pid = edit_post( $post_data );

            if ( $pid ) {
                if ( is_wp_error( $pid ) ) {
                    $x = new WP_Ajax_Response(
                        array(
                            'what' => 'meta',
                            'data' => $pid,
                        )
                    );
                    $x->send();
                }

                
$_POST['comment_status'] = get_default_comment_status( $post->post_type );
        $_POST['ping_status']    = get_default_comment_status( $post->post_type, 'pingback' );

        // Wrap Quick Draft content in the Paragraph block.         if ( ! str_contains( $_POST['content'], '<!-- wp:paragraph -->' ) ) {
            $_POST['content'] = sprintf(
                '<!-- wp:paragraph -->%s<!-- /wp:paragraph -->',
                str_replace( array( "\r\n", "\r", "\n" ), '<br />', $_POST['content'] )
            );
        }

        edit_post();
        wp_dashboard_quick_press();
        exit;

    case 'postajaxpost':
    case 'post':
        check_admin_referer( 'add-' . $post_type );
        $post_id = 'postajaxpost' === $action ? edit_post() : write_post();
        redirect_post( $post_id );
        exit;

    case 'edit':
        
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'] = '';
                break;
            case 'password':
                unset( $_POST['sticky'] );
                break;
            case 'private':
                
Home | Imprint | This part of the site doesn't use cookies.