محمد
2 سال پیش توسط محمد مطرح شد
1 پاسخ

کامنت در پست تای صورت خودکار تایید بشه

سلام خسته نباشید ایا کدی هست بزارم تو فانکشن سایتم که نظر های پست تایپ رو خودکار منتشر کنه نیازی به تایید دستی مدیر سایت نباشه به صورت خودکار منتشر یا هنون تایید بشه خیلی فوریه واسم ممنون میشم کمکم کنید

function my_custom_post_product() {
$labels = array(
'name'               => __( 'محصولات'),
'singular_name'      => __( 'محصول' ),
'add_new'            => __( 'افزودن جدید'),
'add_new_item'       => __( 'افزودن محصول جدید' ),
'edit_item'          => __( 'ویرایش محصول' ),
'new_item'           => __( 'محصول جدید' ),
'all_items'          => __( 'همه محصولات' ),
'view_item'          => __( 'نمایش محصول' ),
'search_items'       => __( 'جست و جو محصول' ),
'not_found'          => __( 'محصولی یافت نشد' ),
'not_found_in_trash' => __( 'محصولی در زباله دان یافت نشد' ),
'parent_item_colon'  => '',
'menu_name'          => 'محصولات'
);
$args = array(
'labels'        => $labels,
'description'   => 'ذخیره اطلاعات مربوط به محصولات',
'public'        => true,
'supports'      => array( 'title', 'editor', 'thumbnail', 'excerpt', 'comments' ),
'has_archive'   => true,
);
register_post_type( 'product', $args );
}
add_action( 'init', 'my_custom_post_product' );

ثبت پرسش جدید
میلاد-م
تخصص : توسعه‌دهنده رابط کاربری - Fron...
@milad 2 سال پیش مطرح شد
1

این رو امتحان کنید:

//hook to do stuff with comments
add_action( 'wp_insert_comment', 'approve_comment', 99, 2 );

function approve_comment($comment_id, $comment_object) {
   //get id of the post that was commented
   $post_id = $comment_object->comment_post_ID;

   //approve comment for "product" type
    if( 'product' == get_post_type( $post_id )) {
       $retrieved_comment = get_comment( $comment_id, ARRAY_A );
       //approve comment    
       $commentarr = $retrieved_comment;
       $commentarr['comment_ID'] = $comment_id;
       $commentarr['comment_approved'] = 1;
       wp_update_comment( $commentarr );
   }
}

منبع: https://wordpress.stackexchange.com/questions/169921/allow-comments-without-approval-for-custom-content-type/170060


برای ارسال پاسخ لازم است وارد شده یا ثبت‌نام کنید

ورود یا ثبت‌نام