get_default_comment_status example

$post                 = new stdClass();
        $post->ID             = 0;
        $post->post_author    = '';
        $post->post_date      = '';
        $post->post_date_gmt  = '';
        $post->post_password  = '';
        $post->post_name      = '';
        $post->post_type      = $post_type;
        $post->post_status    = 'draft';
        $post->to_ping        = '';
        $post->pinged         = '';
        $post->comment_status = get_default_comment_status( $post_type );
        $post->ping_status    = get_default_comment_status( $post_type, 'pingback' );
        $post->post_pingback  = get_option( 'default_pingback_flag' );
        $post->post_category  = get_option( 'default_category' );
        $post->page_template  = 'default';
        $post->post_parent    = 0;
        $post->menu_order     = 0;
        $post                 = new WP_Post( $post );
    }

    /** * Filters the default post content initially used in the "Write Post" form. * * @since 1.5.0 * * @param string $post_content Default post content. * @param WP_Post $post Post object. */
if ( isset( $content_struct['mt_allow_comments'] ) ) {
            if ( ! is_numeric( $content_struct['mt_allow_comments'] ) ) {
                switch ( $content_struct['mt_allow_comments'] ) {
                    case 'closed':
                        $comment_status = 'closed';
                        break;
                    case 'open':
                        $comment_status = 'open';
                        break;
                    default:
                        $comment_status = get_default_comment_status( $post_type );
                        break;
                }
            } else {
                switch ( (int) $content_struct['mt_allow_comments'] ) {
                    case 0:
                    case 2:
                        $comment_status = 'closed';
                        break;
                    case 1:
                        $comment_status = 'open';
                        break;
                    
if ( strtotime( $post_date_gmt ) - strtotime( $now ) < MINUTE_IN_SECONDS ) {
                $post_status = 'publish';
            }
        }
    }

    // Comment status.     if ( empty( $postarr['comment_status'] ) ) {
        if ( $update ) {
            $comment_status = 'closed';
        } else {
            $comment_status = get_default_comment_status( $post_type );
        }
    } else {
        $comment_status = $postarr['comment_status'];
    }

    // These variables are needed by compact() later.     $post_content_filtered = $postarr['post_content_filtered'];
    $post_author           = isset( $postarr['post_author'] ) ? $postarr['post_author'] : $user_id;
    $ping_status           = empty( $postarr['ping_status'] ) ? get_default_comment_status( $post_type, 'pingback' ) : $postarr['ping_status'];
    $to_ping               = isset( $postarr['to_ping'] ) ? sanitize_trackback_urls( $postarr['to_ping'] ) : '';
    $pinged                = isset( $postarr['pinged'] ) ? $postarr['pinged'] : '';
    
if ( ! current_user_can( get_post_type_object( 'post' )->cap->create_posts ) ) {
            exit;
        }

        if ( $error_msg ) {
            return wp_dashboard_quick_press( $error_msg );
        }

        $post = get_post( $_REQUEST['post_ID'] );
        check_admin_referer( 'add-' . $post->post_type );

        $_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();
        
Home | Imprint | This part of the site doesn't use cookies.